performance tuning -- nit finished
[engrid.git] / src / libengrid / surfacemesher.cpp
blob6a2cbc9a23b0012c35e9bf336d8afd95b55b90e8
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008-2012 enGits GmbH +
7 // + +
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. +
12 // + +
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. +
17 // + +
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/>. +
20 // + +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 //
24 #include "surfacemesher.h"
25 #include "guimainwindow.h"
27 #include "laplacesmoother.h"
29 SurfaceMesher::SurfaceMesher() : SurfaceAlgorithm()
31 EG_TYPENAME;
32 m_PerformGeometricTests = true;
33 getSet("surface meshing", "use surface projection for smoothing", true, m_UseProjectionForSmoothing);
34 getSet("surface meshing", "use normal correction for smoothing", false, m_UseNormalCorrectionForSmoothing);
35 getSet("surface meshing", "allow feature edge swapping", false, m_AllowFeatureEdgeSwapping);
36 getSet("surface meshing", "correct curvature", false, m_CorrectCurvature);
37 m_EdgeAngle = m_FeatureAngle;
40 void SurfaceMesher::operate()
42 if (!GuiMainWindow::pointer()->checkSurfProj()) {
43 GuiMainWindow::pointer()->storeSurfaceProjection();
45 prepare();
46 //computeMeshDensity(); //!!
47 //prepare(); //!!
48 if (m_BoundaryCodes.size() == 0) {
49 return;
51 EG_VTKDCN(vtkDoubleArray, characteristic_length_desired, m_Grid, "node_meshdensity_desired");
52 for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
53 characteristic_length_desired->SetValue(id_node, 1e-6);
55 updateNodeInfo(true);
56 int num_inserted = 0;
57 int num_deleted = 0;
58 int iter = 0;
59 bool done = (iter >= m_NumMaxIter);
60 //int Nfull = 0;
61 //int Nhalf = 0;
62 while (!done) {
63 ++iter;
64 cout << "surface mesher iteration " << iter << ":" << endl;
65 computeMeshDensity();
66 //return;
67 num_inserted = insertNodes();
68 cout << " inserted nodes : " << num_inserted << endl;
69 updateNodeInfo();
70 swap();
71 //computeMeshDensity(); //!!
72 num_deleted = deleteNodes();
73 cout << " deleted nodes : " << num_deleted << endl;
74 //computeMeshDensity(); // !!
75 for (int i = 0; i < m_NumSmoothSteps; ++i) {
76 SurfaceProjection::Nfull = 0;
77 SurfaceProjection::Nhalf = 0;
78 smooth(1, m_CorrectCurvature);
79 swap();
81 //int N_crit = m_Grid->GetNumberOfPoints()/100;
82 done = (iter >= m_NumMaxIter);
83 cout << " total nodes : " << m_Grid->GetNumberOfPoints() << endl;
84 cout << " total cells : " << m_Grid->GetNumberOfCells() << endl;
85 double change_ratio = 0;
86 double fluctuation_ratio = 0;
88 double N_new = m_Grid->GetNumberOfPoints();
89 double N_chg = num_inserted - num_deleted;
90 double N_max = max(num_inserted, num_deleted);
91 double N_old = N_new - N_chg;
92 change_ratio = 0.1*int(1000*N_chg/N_old);
93 fluctuation_ratio = 0.1*int(1000*N_max/N_old);
95 cout << " change ratio : " << change_ratio << "%" << endl;
96 cout << " fluctuation ratio : " << fluctuation_ratio << "%" << endl;
98 createIndices(m_Grid);
99 updateNodeInfo(false);
100 //computeMeshDensity(); //!!
102 QVector<int> bcs;
103 GuiMainWindow::pointer()->getAllBoundaryCodes(bcs);
104 foreach (int bc, bcs) {
105 SurfaceProjection* proj = GuiMainWindow::pointer()->getSurfProj(bc);