2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008,2009 Oliver Gloth +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29 #include "egvtkobject.h"
31 #include <vtkUnstructuredGrid.h>
32 #include <vtkCellType.h>
33 #include <vtkSmartPointer.h>
37 #include <QListWidget>
41 class OperationThread
: public QThread
54 void setOperation(Operation
*an_op
) { op
= an_op
; };
64 ostream
& operator<<(ostream
&out
, stencil_t S
);
67 * This is the base class for all mesh operations.
68 * Operations will typically be triggered by a Qt event; the MainWindow
69 * object will call operator() with the current grid as parameter.
71 class Operation
: public EgVtkObject
74 friend class OperationThread
;
75 OperationThread thread
;
77 private: // static attributes
79 static QSet
<Operation
*> garbage_operations
;
81 private: // attributes
83 QVector
<vtkIdType
> nodes_map
;
84 QVector
<vtkIdType
> cells_map
;
93 protected: // attributes
95 vtkUnstructuredGrid
*grid
;
96 QVector
<vtkIdType
> cells
;
98 QVector
<vtkIdType
> nodes
;
100 QVector
<QSet
<int> > n2c
;
101 QVector
<QSet
<int> > n2n
;
102 QVector
<QVector
<int> > c2c
;
103 QVector
<bool> node_fixed
;
104 QVector
<bool> cell_fixed
;
106 //Special attributes for UpdateNodeType function
108 int NumberOfIterations
;
109 double RelaxationFactor
;
110 int FeatureEdgeSmoothing
;
113 int BoundarySmoothing
;
114 int GenerateErrorScalars
;
115 int GenerateErrorVectors
;
117 protected: // methods
121 GuiMainWindow
* mainWindow();
122 virtual void operate() = 0;
127 virtual ~Operation();
130 void setGrid(vtkUnstructuredGrid
*ug
) { grid
= ug
; };
132 void setAllVolumeCells();
133 void setAllSurfaceCells();
134 vtkIdType
getNewNode(vtkIdType id_old_node
) { return nodes_map
[_nodes
[id_old_node
]] ; };
135 vtkIdType
getNewCell(vtkIdType id_old_cell
) { return cells_map
[_cells
[id_old_cell
]] ; };
136 void setNewNode(vtkIdType id_old_node
, vtkIdType id_new_node
) { nodes_map
[_nodes
[id_old_node
]] = id_new_node
; };
137 void setNewCell(vtkIdType id_old_cell
, vtkIdType id_new_cell
) { cells_map
[_cells
[id_old_cell
]] = id_new_cell
; };
138 void setGui() { gui
= true; };
139 OperationThread
& getThread() { return thread
; };
140 void enableAutoSet() { autoset
= true; };
141 void disableAutoSet() { autoset
= false; };
144 * Fill a QListWidget with all available boundary codes from a grid.
145 * @param lw The QListWidget to fill.
146 * @param grid The grid to use.
148 void populateBoundaryCodes(QListWidget
*lw
);
150 virtual void operator()();
152 template <class T
> void setCells(const T
&cls
);
153 template <class T
> void setNodes(const T
&nds
);
155 static void collectGarbage();
156 stencil_t
getStencil(vtkIdType id_cell1
, int j1
);
158 vtkIdType
getClosestNode(vtkIdType a_id_node
,vtkUnstructuredGrid
* a_grid
);
159 vtkIdType
getFarthestNode(vtkIdType a_id_node
,vtkUnstructuredGrid
* a_grid
);
161 bool SwapCells(vtkUnstructuredGrid
* a_grid
, stencil_t S
);
162 void quad2triangle(vtkUnstructuredGrid
* src
,vtkIdType quadcell
);
163 void quad2triangle(vtkUnstructuredGrid
* src
,vtkIdType quadcell
,vtkIdType MovingPoint
);
165 bool DeletePoint(vtkUnstructuredGrid
*src
, vtkIdType DeadNode
);
166 int NumberOfCommonPoints(vtkIdType node1
, vtkIdType node2
, bool& IsTetra
);
167 // vtkIdType FindSnapPoint(vtkUnstructuredGrid *src, vtkIdType DeadNode);
168 bool EmptyVolume(vtkIdType DeadNode
, vtkIdType PSP
);
170 vec3_t
GetCenter(vtkIdType cellId
, double& R
);
172 bool getNeighbours(vtkIdType Boss
, vtkIdType
& Peon1
, vtkIdType
& Peon2
, int BC
);
174 int UpdateMeshDensity();
175 int UpdateNodeType();
176 vtkIdType
FindSnapPoint(vtkUnstructuredGrid
*src
, vtkIdType DeadNode
,QSet
<vtkIdType
> & DeadCells
,QSet
<vtkIdType
> & MutatedCells
,QSet
<vtkIdType
> & MutilatedCells
, int& N_newpoints
, int& N_newcells
);
177 bool DeletePoint_2(vtkUnstructuredGrid
*src
, vtkIdType DeadNode
, int& N_newpoints
, int& N_newcells
);
180 //End of class Operation
183 void Operation::setCells(const T
&cls
)
185 cells
.resize(cls
.size());
186 qCopy(cls
.begin(), cls
.end(), cells
.begin());
187 getNodesFromCells(cells
, nodes
, grid
);
188 createCellMapping(cells
, _cells
, grid
);
189 createNodeMapping(nodes
, _nodes
, grid
);
190 createNodeToCell(cells
, nodes
, _nodes
, n2c
, grid
);
191 createNodeToNode(cells
, nodes
, _nodes
, n2n
, grid
);
192 createCellToCell(cells
, c2c
, grid
);
193 node_fixed
.fill(nodes
.size(), false);
194 cell_fixed
.fill(cells
.size(), false);
199 void Operation::setNodes(const T
&nds
)
201 nodes
.resize(nds
.size());
202 qCopy(nds
.begin(), nds
.end(), nodes
.begin());
203 createNodeMapping(nodes
, _nodes
, grid
);
205 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
206 vtkIdType
*pts
, N_pts
;
207 grid
->GetCellPoints(id_cell
, N_pts
, pts
);
208 for (int i_pts
= 0; i_pts
< N_pts
; ++i_pts
) {
209 if (_nodes
[pts
[i_pts
]] >= 0) {
215 cells
.resize(cls
.size());
216 qCopy(cls
.begin(), cls
.end(), cells
.begin());
217 createCellMapping(cells
, _cells
, grid
);
218 createNodeToCell(cells
, nodes
, _nodes
, n2c
, grid
);
219 createNodeToNode(cells
, nodes
, _nodes
, n2n
, grid
);
220 createCellToCell(cells
, c2c
, grid
);
221 node_fixed
.fill(nodes
.size(), false);
222 cell_fixed
.fill(cells
.size(), false);
226 //////////////////////////////////////////////
227 double CurrentVertexAvgDist(vtkIdType a_vertex
,QVector
< QSet
< int > > &n2n
,vtkUnstructuredGrid
*a_grid
);
228 double CurrentMeshDensity(vtkIdType a_vertex
,QVector
< QSet
< int > > &n2n
,vtkUnstructuredGrid
*a_grid
);
229 double DesiredVertexAvgDist(vtkIdType a_vertex
,QVector
< QSet
< int > > &n2n
,vtkUnstructuredGrid
*a_grid
);
230 double DesiredMeshDensity(vtkIdType a_vertex
,QVector
< QSet
< int > > &n2n
,vtkUnstructuredGrid
*a_grid
);