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 "beziertriangle.h"
37 class SurfaceProjection
: public SurfaceAlgorithm
40 private: // data-types
50 private: // attributes
52 vtkUnstructuredGrid
* m_BGrid
; ///< background grid used for projection and interpolation of the bezier surface
53 vtkUnstructuredGrid
* m_InterpolationGrid
;
54 vtkUnstructuredGrid
* m_BezierGrid
;
59 vtkUnstructuredGrid
* getBGrid() { return m_BGrid
; }
61 /// get m_InterpolationGrid
62 vtkUnstructuredGrid
* getInterpolationGrid() { return m_InterpolationGrid
; }
65 vtkUnstructuredGrid
* getBezierGrid() { return m_BezierGrid
; }
68 /// A vector associating each node of m_FGrid with a Triangle (index for m_Triangles) on which it should be projected (closest triangle from m_Triangles).
69 QVector
<vtkIdType
> m_ProjTriangles
;
71 vtkUnstructuredGrid
* m_FGrid
; ///< The foreground grid to project.
72 QVector
<double> m_EdgeLength
;
73 QVector
<vtkIdType
> m_Cells
;
74 QVector
<vtkIdType
> m_Nodes
;
75 QVector
<vec3_t
> m_NodeNormals
; ///< The surface normal at each node of m_BGrid
76 QMap
< pair
<vtkIdType
, vtkIdType
>, vec3_t
> m_ControlPoints
;
77 QVector
<Triangle
> m_Triangles
; ///< All triangles of m_BGrid. One for each triangle cell of m_BGrid.
78 QVector
<BezierTriangle
> m_BezierTriangles
; ///< The bezier triangle corresponding to m_Triangles
79 QVector
<QVector
<int> > m_N2N
;
80 double m_RadiusFactor
;
84 bool m_correctCurvature
; ///< Should correctCurvature() be used?
88 void setCorrectCurvature(bool b
) { m_correctCurvature
= b
; }
89 bool getCorrectCurvature() { return m_correctCurvature
; }
91 // variables for exact projection surfaces
99 vec3_t
cylinder(vec3_t center
, double radius
, vec3_t g_M
);
100 vec3_t
cylinder(vec3_t center
, double radius
, int i_tri
, vec3_t r
);
101 vec3_t
ellipsoid(vec3_t M
);
102 vec3_t
ellipse(vec3_t M
);
103 vec3_t
rectangle(vec3_t M
);
104 vec3_t
cuboid(vec3_t M
);
105 vec3_t
cylinder(vec3_t M
);
110 void setBackgroundGrid_setupGrid(vtkUnstructuredGrid
* grid
, const C
& cells
); ///< copy the cells from grid to m_BGrid
112 void updateBackgroundGridInfo();///< Set up the background grid (triangles, bezier triangles, etc)
114 vec3_t
correctCurvature1(int i_tri
, vec3_t g_M
); ///< correct curvature by using double interpolation
115 vec3_t
correctCurvature2(int i_tri
, vec3_t g_M
); ///< correct curvature by using bezier surfaces
117 vec3_t
getEdgeNormal(vtkIdType id_node1
, vtkIdType id_node2
);
121 SurfaceProjection(); ///< Constructor
122 ~SurfaceProjection(); ///< Destructor
125 void setBackgroundGrid(vtkUnstructuredGrid
* grid
, const C
& cells
); ///< Set the background grid to use + set it up
127 void setForegroundGrid(vtkUnstructuredGrid
* grid
) {
129 m_ProjTriangles
.clear(); // this makes sure a full search is run everytime a new foreground grid is set.
132 vec3_t
project(vec3_t x
, vtkIdType id_node
= -1);
134 int getNumDirectProjections() { return m_NumDirect
; }
135 int getNumFullSearches() { return m_NumFull
; }
137 void writeGridWithNormals(QString filename
);
138 void writeInterpolationGrid(QString filename
);
139 void writeTriangleGrid(QString filename
);
141 int getControlPoints_orthogonal(Triangle T
, vec3_t
& X_011
, vec3_t
& X_101
, vec3_t
& X_110
, double Lmax
); ///< get the orthogonal control points
142 int getControlPoints_nonorthogonal(Triangle T
, vec3_t
& X_011
, vec3_t
& X_101
, vec3_t
& X_110
, double Lmax
); ///< get the non-orthogonal control points
143 int limitControlPoints(Triangle T
, vec3_t
& X_011
, vec3_t
& X_101
, vec3_t
& X_110
);
147 void SurfaceProjection::setBackgroundGrid(vtkUnstructuredGrid
* grid
, const C
& cells
)
149 setBackgroundGrid_setupGrid(grid
, cells
);
150 updateBackgroundGridInfo();
154 void SurfaceProjection::setBackgroundGrid_setupGrid(vtkUnstructuredGrid
* grid
, const C
& cells
)
156 QVector
<vtkIdType
> nodes
;
157 getNodesFromCells(cells
, nodes
, grid
);
158 allocateGrid(m_BGrid
, cells
.size(), nodes
.size());
160 QVector
<vtkIdType
> _nodes(grid
->GetNumberOfPoints());
161 vtkIdType id_new_node
= 0;
162 foreach (vtkIdType id_node
, nodes
) {
164 grid
->GetPoints()->GetPoint(id_node
, x
.data());
165 m_BGrid
->GetPoints()->SetPoint(id_new_node
, x
.data());
166 copyNodeData(grid
,id_node
,m_BGrid
,id_new_node
);
167 _nodes
[id_node
] = id_new_node
;
170 foreach (vtkIdType id_cell
, cells
) {
171 vtkIdType N_pts
, *pts
;
172 vtkIdType type_cell
= grid
->GetCellType(id_cell
);
173 grid
->GetCellPoints(id_cell
, N_pts
, pts
);
174 vtkIdType new_pts
[N_pts
];
175 for (int i
= 0; i
< N_pts
; ++i
) {
176 new_pts
[i
] = _nodes
[pts
[i
]];
178 vtkIdType id_new_cell
= m_BGrid
->InsertNextCell(type_cell
, N_pts
, new_pts
);
179 copyCellData(grid
,id_cell
,m_BGrid
,id_new_cell
);
183 #endif // SURFACEPROJECTION_H