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_all 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);
173 bool getNeighbours(vtkIdType Boss
, QVector
<vtkIdType
>& Peons
, int BC
);
175 int UpdateMeshDensity();
176 int UpdateNodeType_all();
177 int UpdateNodeType();
179 vtkIdType
FindSnapPoint(vtkUnstructuredGrid
*src
, vtkIdType DeadNode
,QSet
<vtkIdType
> & DeadCells
,QSet
<vtkIdType
> & MutatedCells
,QSet
<vtkIdType
> & MutilatedCells
, int& N_newpoints
, int& N_newcells
);
180 bool DeletePoint_2(vtkUnstructuredGrid
*src
, vtkIdType DeadNode
, int& N_newpoints
, int& N_newcells
);
181 bool DeleteSetOfPoints(vtkUnstructuredGrid
*src
, QSet
<vtkIdType
> DeadNodes
, int& N_newpoints
, int& N_newcells
);
183 void TxtSave(QString a_filename
);
184 void DualSave(QString a_filename
);
186 //Special for UpdateNodeType_all
187 void SetConvergence(double C
){Convergence
=C
;};
188 void SetNumberOfIterations(int N
){NumberOfIterations
=N
;};
189 void SetRelaxationFactor(double RF
){RelaxationFactor
=RF
;};
190 void SetFeatureEdgeSmoothing(int FES
){FeatureEdgeSmoothing
=FES
;};
191 void SetFeatureAngle(double FA
){FeatureAngle
=FA
;};
192 void SetEdgeAngle(double EA
){EdgeAngle
=EA
;};
193 void SetBoundarySmoothing(int BS
){BoundarySmoothing
=BS
;};
194 void SetGenerateErrorScalars(int GES
){GenerateErrorScalars
=GES
;};
195 void SetGenerateErrorVectors(int GEV
){GenerateErrorVectors
=GEV
;};
198 //End of class Operation
201 void Operation::setCells(const T
&cls
)
203 cells
.resize(cls
.size());
204 qCopy(cls
.begin(), cls
.end(), cells
.begin());
205 getNodesFromCells(cells
, nodes
, grid
);
206 createCellMapping(cells
, _cells
, grid
);
207 createNodeMapping(nodes
, _nodes
, grid
);
208 createNodeToCell(cells
, nodes
, _nodes
, n2c
, grid
);
209 createNodeToNode(cells
, nodes
, _nodes
, n2n
, grid
);
210 createCellToCell(cells
, c2c
, grid
);
211 node_fixed
.fill(nodes
.size(), false);
212 cell_fixed
.fill(cells
.size(), false);
217 void Operation::setNodes(const T
&nds
)
219 nodes
.resize(nds
.size());
220 qCopy(nds
.begin(), nds
.end(), nodes
.begin());
221 createNodeMapping(nodes
, _nodes
, grid
);
223 for (vtkIdType id_cell
= 0; id_cell
< grid
->GetNumberOfCells(); ++id_cell
) {
224 vtkIdType
*pts
, N_pts
;
225 grid
->GetCellPoints(id_cell
, N_pts
, pts
);
226 for (int i_pts
= 0; i_pts
< N_pts
; ++i_pts
) {
227 if (_nodes
[pts
[i_pts
]] >= 0) {
233 cells
.resize(cls
.size());
234 qCopy(cls
.begin(), cls
.end(), cells
.begin());
235 createCellMapping(cells
, _cells
, grid
);
236 createNodeToCell(cells
, nodes
, _nodes
, n2c
, grid
);
237 createNodeToNode(cells
, nodes
, _nodes
, n2n
, grid
);
238 createCellToCell(cells
, c2c
, grid
);
239 node_fixed
.fill(nodes
.size(), false);
240 cell_fixed
.fill(cells
.size(), false);
244 //////////////////////////////////////////////
245 double CurrentVertexAvgDist(vtkIdType a_vertex
,QVector
< QSet
< int > > &n2n
,vtkUnstructuredGrid
*a_grid
);
246 double CurrentMeshDensity(vtkIdType a_vertex
,QVector
< QSet
< int > > &n2n
,vtkUnstructuredGrid
*a_grid
);
247 double DesiredVertexAvgDist(vtkIdType a_vertex
,QVector
< QSet
< int > > &n2n
,vtkUnstructuredGrid
*a_grid
);
248 double DesiredMeshDensity(vtkIdType a_vertex
,QVector
< QSet
< int > > &n2n
,vtkUnstructuredGrid
*a_grid
);