performance tuning -- nit finished
[engrid.git] / src / libengrid / surfaceprojection.h
blob5b037852e120007f057a1e4bd6186ba0a423a1df
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 //
23 #ifndef SURFACEPROJECTION_H
24 #define SURFACEPROJECTION_H
26 class SurfaceProjection;
28 #include "egvtkobject.h"
29 #include "guimainwindow.h"
30 #include "geometrytools.h"
31 #include "vtkCharArray.h"
32 #include "surfaceoperation.h"
33 #include "surfacealgorithm.h"
34 #include "triangle.h"
35 #include "facefinder.h"
37 class SurfaceProjection : public SurfaceAlgorithm
40 private: // data-types
42 struct Edge
44 vec3_t a, b;
45 vec3_t v;
46 vec3_t na, nb;
47 double La, Lb;
50 private: // methods
52 template <class C>
53 void setBackgroundGrid_setupGrid(vtkUnstructuredGrid* grid, const C& cells); ///< copy the cells from grid to m_BGrid
55 protected: // attributes
57 vtkUnstructuredGrid* m_BGrid; ///< the background grid defining the geometry
58 MeshPartition m_BPart;
59 vtkUnstructuredGrid* m_FGrid; ///< the foreground grid to project
60 QVector<double> m_EdgeLength;
61 QVector<vtkIdType> m_Cells;
62 QVector<vtkIdType> m_Nodes;
63 QVector<vec3_t> m_NodeNormals; ///< The surface normal at each node of m_BGrid
64 QVector<Triangle> m_Triangles; ///< All triangles of m_BGrid. One for each triangle cell of m_BGrid.
65 QVector<double> m_Radius; ///< Surface radius for mesh resolution.
66 QVector<QVector<int> > m_N2N;
67 bool m_RestrictToTriangle;
68 double m_CritDistance;
69 QMap<vtkIdType,vtkIdType> m_Pindex;
70 FaceFinder m_FaceFinder;
71 vtkIdType m_LastProjTriangle;
73 protected: // static attributes
75 static vtkIdType m_LastPindex;
76 virtual vec3_t project(vec3_t x, vtkIdType id_node = -1, bool correct_curvature = false);
78 protected: // methods
80 virtual void updateBackgroundGridInfo(); ///< Set up the background grid (triangles, bezier triangles, etc)
82 void searchNewTriangle(vec3_t xp, vtkIdType &id_tri, vec3_t &x_proj, vec3_t &r_proj, bool neigh_mode, bool &on_triangle);
83 vtkIdType getProjTriangle(vtkIdType id_node);
84 void setProjTriangle(vtkIdType id_node, vtkIdType proj_triangle);
85 void computeSurfaceCurvature();
87 public: // methods
89 static long int Nfull;
90 static long int Nhalf;
92 SurfaceProjection();
93 ~SurfaceProjection();
95 template <class C> void setBackgroundGrid(vtkUnstructuredGrid* grid, const C& cells); ///< Set the background grid to use + set it up
97 void setForegroundGrid(vtkUnstructuredGrid* grid);
98 virtual vec3_t projectRestricted(vec3_t x, vtkIdType id_node = -1, bool correct_curvature = false);
99 virtual vec3_t projectFree(vec3_t x, vtkIdType id_node = -1, bool correct_curvature = false);
101 vtkUnstructuredGrid* getBGrid() { return m_BGrid; }
102 double getRadius(vtkIdType id_node);
104 vec3_t correctCurvature(vtkIdType proj_triangle, vec3_t x);
105 vtkIdType lastProjTriangle() { return m_LastProjTriangle; }
107 public: // static methods
109 static void resetPindex() { m_LastPindex = 0; }
114 template <class C>
115 void SurfaceProjection::setBackgroundGrid(vtkUnstructuredGrid* grid, const C& cells)
117 setBackgroundGrid_setupGrid(grid, cells);
118 updateBackgroundGridInfo();
119 setForegroundGrid(grid);
120 for (int i_cells = 0; i_cells < cells.size(); ++i_cells) {
121 vtkIdType id_cell = cells[i_cells];
123 for (vtkIdType id_cell = 0; id_cell < m_BGrid->GetNumberOfCells(); ++id_cell) {
124 vtkIdType N_pts, *pts;
125 m_BGrid->GetCellPoints(id_cell, N_pts, pts);
126 for (int i = 0; i < N_pts; ++i) {
127 setProjTriangle(pts[i], id_cell);
130 m_FaceFinder.setMaxNumFaces(10);
131 m_FaceFinder.setGrid(m_BGrid);
134 template <class C>
135 void SurfaceProjection::setBackgroundGrid_setupGrid(vtkUnstructuredGrid* grid, const C& cells)
137 QVector<vtkIdType> nodes;
138 getNodesFromCells(cells, nodes, grid);
139 allocateGrid(m_BGrid, cells.size(), nodes.size());
141 QVector<vtkIdType> _nodes(grid->GetNumberOfPoints());
142 vtkIdType id_new_node = 0;
143 foreach (vtkIdType id_node, nodes) {
144 vec3_t x;
145 grid->GetPoints()->GetPoint(id_node, x.data());
146 m_BGrid->GetPoints()->SetPoint(id_new_node, x.data());
147 copyNodeData(grid,id_node,m_BGrid,id_new_node);
148 _nodes[id_node] = id_new_node;
149 ++id_new_node;
151 foreach (vtkIdType id_cell, cells) {
152 vtkIdType N_pts, *pts;
153 vtkIdType type_cell = grid->GetCellType(id_cell);
154 grid->GetCellPoints(id_cell, N_pts, pts);
155 QVector<vtkIdType> new_pts(N_pts);
156 for (int i = 0; i < N_pts; ++i) {
157 new_pts[i] = _nodes[pts[i]];
159 vtkIdType id_new_cell = m_BGrid->InsertNextCell(type_cell, N_pts, new_pts.data());
160 copyCellData(grid,id_cell,m_BGrid,id_new_cell);
164 #endif // SURFACEPROJECTION_H