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 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #include "surfacemesher.h"
25 #include "insertpoints.h"
26 #include "removepoints.h"
27 #include "updatedesiredmeshdensity.h"
29 #include <vtkSmoothPolyDataFilter.h>
31 SurfaceMesher::SurfaceMesher() : SurfaceOperation()
34 getSet("surface meshing", "maximal number of iterations", 20, m_NumMaxIter
);
35 getSet("surface meshing", "number of smoothing steps", 1, m_NumSmoothSteps
);
38 void SurfaceMesher::computeMeshDensity()
40 ///@@@ TODO: Optimize by using only one loop through nodes!
41 UpdateDesiredMeshDensity update_desired_mesh_density
;
42 update_desired_mesh_density
.setGrid(grid
);
43 update_desired_mesh_density
.setVertexMeshDensityVector(VMDvector
);
44 update_desired_mesh_density();
47 void SurfaceMesher::updateNodeInfo(bool update_type
)
50 l2g_t nodes
= getPartNodes();
51 foreach(vtkIdType node
, nodes
) {
53 EG_VTKDCN(vtkCharArray
, node_type
, grid
, "node_type");//node type
54 node_type
->SetValue(node
, getNodeType(node
));
56 EG_VTKDCN(vtkDoubleArray
, node_meshdensity_current
, grid
, "node_meshdensity_current");//what we have
57 node_meshdensity_current
->SetValue(node
, CurrentMeshDensity(node
));
59 EG_VTKDCN(vtkIntArray
, node_specified_density
, grid
, "node_specified_density");//density index from table
60 VertexMeshDensity nodeVMD
= getVMD(node
);
61 int idx
=VMDvector
.indexOf(nodeVMD
);
62 node_specified_density
->SetValue(node
, idx
);
64 EG_VTKDCN(vtkDoubleArray
, node_meshdensity_desired
, grid
, "node_meshdensity_desired");//what we want
65 if(idx
!=-1) { //specified
66 //node_meshdensity_desired->SetValue(node, VMDvector[idx].density);
67 } else { //unspecified
68 //double D=DesiredMeshDensity(node);
69 //node_meshdensity_desired->SetValue(node, D);
74 void SurfaceMesher::swap()
78 swap
.setRespectBC(true);
79 swap
.setFeatureSwap(true);
81 GuiMainWindow::pointer()->getAllBoundaryCodes(rest_bcs
);
83 swap
.setBoundaryCodes(rest_bcs
);
87 void SurfaceMesher::smooth(int N_iter
)
91 QVector
<vtkIdType
> cls
;
92 getSurfaceCells(m_BCs
, cls
, grid
);
94 lap
.setNumberOfIterations(N_iter
);
98 int SurfaceMesher::insertNodes()
100 InsertPoints insert_points
;
101 insert_points
.setGrid(grid
);
102 insert_points
.setBCS(m_BCs
);
103 insert_points
.set_insert_FP(false);
104 insert_points
.set_insert_EP(true);
106 return insert_points
.getNumInserted();
109 int SurfaceMesher::deleteNodes()
111 RemovePoints remove_points
;
112 remove_points
.setGrid(grid
);
113 remove_points
.setBCS(m_BCs
);
114 remove_points
.set_remove_FP(true);
115 remove_points
.set_remove_EP(true);
117 return remove_points
.getNumRemoved();
120 void SurfaceMesher::operate()
122 EG_VTKDCN(vtkDoubleArray
, md
, grid
, "node_meshdensity_desired");
123 for (vtkIdType id_node
= 0; id_node
< grid
->GetNumberOfPoints(); ++id_node
) {
124 md
->SetValue(id_node
, 1e-6);
126 updateNodeInfo(true);
127 int num_inserted
= 0;
132 computeMeshDensity();
133 num_inserted
= insertNodes();
144 } while ((N > 0) && (count < 20));
147 for (int i
= 0; i
< 5; ++i
) {
149 smooth(m_NumSmoothSteps
);
152 done
= (iter
>= m_NumMaxIter
) || (num_inserted
- num_deleted
< grid
->GetNumberOfPoints()/100);
153 cout
<< "surface mesher iteration " << iter
<< ":" << endl
;
154 cout
<< " inserted nodes : " << num_inserted
<< endl
;
155 cout
<< " deleted nodes : " << num_deleted
<< endl
;
156 cout
<< " total nodes : " << grid
->GetNumberOfPoints() << endl
;
157 cout
<< " total cells : " << grid
->GetNumberOfCells() << endl
;
160 updateNodeInfo(true);
161 computeMeshDensity();