2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008-2010 enGits GmbH +
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 #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"
35 #include "facefinder.h"
37 class SurfaceProjection
: public SurfaceAlgorithm
40 private: // data-types
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_correctCurvature
; ///< Should correctCurvature() be used?
69 bool m_RestrictToTriangle
;
70 double m_CritDistance
;
71 QMap
<vtkIdType
,vtkIdType
> m_Pindex
;
72 FaceFinder m_FaceFinder
;
74 protected: // static attributes
76 static vtkIdType m_LastPindex
;
77 virtual vec3_t
project(vec3_t x
, vtkIdType id_node
= -1);
81 virtual void updateBackgroundGridInfo();///< Set up the background grid (triangles, bezier triangles, etc)
82 virtual vec3_t
correctCurvature(int, vec3_t g_M
);
83 void searchNewTriangle(vec3_t xp
, vtkIdType
&id_tri
, vec3_t
&x_proj
, vec3_t
&r_proj
, bool &on_triangle
);
84 vtkIdType
getProjTriangle(vtkIdType id_node
);
85 void setProjTriangle(vtkIdType id_node
, vtkIdType proj_triangle
);
86 void computeSurfaceCurvature();
90 static long int Nfull
;
91 static long int Nhalf
;
93 SurfaceProjection(int bc
= 0);
96 template <class C
> void setBackgroundGrid(vtkUnstructuredGrid
* grid
, const C
& cells
); ///< Set the background grid to use + set it up
98 void setForegroundGrid(vtkUnstructuredGrid
* grid
);
99 virtual vec3_t
projectRestricted(vec3_t x
, vtkIdType id_node
= -1);
100 virtual vec3_t
projectFree(vec3_t x
, vtkIdType id_node
= -1);
102 vtkUnstructuredGrid
* getBGrid() { return m_BGrid
; }
103 double getRadius(vtkIdType id_node
);
105 void setCorrectCurvature(bool b
) { m_correctCurvature
= b
; }
106 bool getCorrectCurvature() { return m_correctCurvature
; }
108 public: // static methods
110 static void resetPindex() { m_LastPindex
= 0; }
116 void SurfaceProjection::setBackgroundGrid(vtkUnstructuredGrid
* grid
, const C
& cells
)
118 setBackgroundGrid_setupGrid(grid
, cells
);
119 updateBackgroundGridInfo();
120 setForegroundGrid(grid
);
121 for (int i_cells
= 0; i_cells
< cells
.size(); ++i_cells
) {
122 vtkIdType id_cell
= cells
[i_cells
];
124 for (vtkIdType id_cell
= 0; id_cell
< m_BGrid
->GetNumberOfCells(); ++id_cell
) {
125 vtkIdType N_pts
, *pts
;
126 m_BGrid
->GetCellPoints(id_cell
, N_pts
, pts
);
127 for (int i
= 0; i
< N_pts
; ++i
) {
128 setProjTriangle(pts
[i
], id_cell
);
131 m_FaceFinder
.setMaxNumFaces(100);
132 m_FaceFinder
.setGrid(m_BGrid
);
136 void SurfaceProjection::setBackgroundGrid_setupGrid(vtkUnstructuredGrid
* grid
, const C
& cells
)
138 QVector
<vtkIdType
> nodes
;
139 getNodesFromCells(cells
, nodes
, grid
);
140 allocateGrid(m_BGrid
, cells
.size(), nodes
.size());
142 QVector
<vtkIdType
> _nodes(grid
->GetNumberOfPoints());
143 vtkIdType id_new_node
= 0;
144 foreach (vtkIdType id_node
, nodes
) {
146 grid
->GetPoints()->GetPoint(id_node
, x
.data());
147 m_BGrid
->GetPoints()->SetPoint(id_new_node
, x
.data());
148 copyNodeData(grid
,id_node
,m_BGrid
,id_new_node
);
149 _nodes
[id_node
] = id_new_node
;
152 foreach (vtkIdType id_cell
, cells
) {
153 vtkIdType N_pts
, *pts
;
154 vtkIdType type_cell
= grid
->GetCellType(id_cell
);
155 grid
->GetCellPoints(id_cell
, N_pts
, pts
);
156 vtkIdType new_pts
[N_pts
];
157 for (int i
= 0; i
< N_pts
; ++i
) {
158 new_pts
[i
] = _nodes
[pts
[i
]];
160 vtkIdType id_new_cell
= m_BGrid
->InsertNextCell(type_cell
, N_pts
, new_pts
);
161 copyCellData(grid
,id_cell
,m_BGrid
,id_new_cell
);
165 #endif // SURFACEPROJECTION_H