1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #ifndef TRIANGULARCADINTERFACE_H
22 #define TRIANGULARCADINTERFACE_H
24 #include "cadinterface.h"
27 #include "facefinder.h"
28 #include "surfacealgorithm.h"
30 class TriangularCadInterface
: public CadInterface
36 void setBackgroundGrid_setupGrid(vtkUnstructuredGrid
* grid
, const C
& cells
); ///< copy the cells from grid to m_BGrid
38 void updateBackgroundGridInfo(); ///< Set up the background grid (triangles, bezier triangles, etc)
39 void computeSurfaceCurvature();
40 vtkIdType
getProjTriangle(vtkIdType id_node
);
41 void setProjTriangle(vtkIdType id_node
, vtkIdType proj_triangle
);
44 protected: // attributes
46 vtkUnstructuredGrid
* m_BGrid
; ///< the background grid defining the geometry
47 MeshPartition m_BPart
;
48 QVector
<vtkIdType
> m_Cells
;
49 QVector
<vtkIdType
> m_Nodes
;
50 QVector
<vec3_t
> m_NodeNormals
; ///< The surface normal at each node of m_BGrid
51 QVector
<Triangle
> m_Triangles
; ///< All triangles of m_BGrid. One for each triangle cell of m_BGrid.
52 QVector
<double> m_Radius
; ///< Surface radius for mesh resolution.
53 QVector
<QVector
<int> > m_N2N
;
54 double m_CritDistance
;
55 FaceFinder m_FaceFinder
;
56 QMap
<vtkIdType
,vtkIdType
> m_Pindex
;
58 static vtkIdType m_LastPindex
;
63 void searchNewTriangle(vec3_t xp
, vtkIdType
&id_tri
, vec3_t
&x_proj
, vec3_t
&r_proj
, bool &on_triangle
);
64 virtual vec3_t
correctCurvature(vtkIdType proj_triangle
, vec3_t x
);
69 TriangularCadInterface();
71 virtual vec3_t
snap(vec3_t x
, bool correct_curvature
= false);
72 virtual vec3_t
snapNode(vtkIdType id_node
, vec3_t x
, bool correct_curvature
= false);
73 virtual vec3_t
correctCurvature(vec3_t x
);
75 template <class C
> void setBackgroundGrid(vtkUnstructuredGrid
* grid
, const C
& cells
); ///< Set the background grid to use + set it up
80 void TriangularCadInterface::setBackgroundGrid(vtkUnstructuredGrid
* grid
, const C
& cells
)
82 QVector
<vtkIdType
> nodes
;
83 getNodesFromCells(cells
, nodes
, grid
);
84 int num_new_cells
= cells
.size();
85 foreach (vtkIdType id_cell
, cells
) {
86 vtkIdType type_cell
= grid
->GetCellType(id_cell
);
87 if (type_cell
== VTK_QUAD
) {
91 allocateGrid(m_BGrid
, num_new_cells
, nodes
.size());
93 QVector
<vtkIdType
> _nodes(grid
->GetNumberOfPoints());
94 vtkIdType id_new_node
= 0;
95 foreach (vtkIdType id_node
, nodes
) {
97 grid
->GetPoints()->GetPoint(id_node
, x
.data());
98 m_BGrid
->GetPoints()->SetPoint(id_new_node
, x
.data());
99 copyNodeData(grid
,id_node
,m_BGrid
,id_new_node
);
100 _nodes
[id_node
] = id_new_node
;
103 foreach (vtkIdType id_cell
, cells
) {
104 EG_GET_CELL(id_cell
, grid
);
105 QVector
<vtkIdType
> new_pts(3);
106 if (type_cell
== VTK_TRIANGLE
) {
107 new_pts
[0] = _nodes
[pts
[0]];
108 new_pts
[1] = _nodes
[pts
[1]];
109 new_pts
[2] = _nodes
[pts
[2]];
110 vtkIdType id_new_cell
= m_BGrid
->InsertNextCell(VTK_TRIANGLE
, 3, new_pts
.data());
111 copyCellData(grid
, id_cell
, m_BGrid
, id_new_cell
);
112 } else if (type_cell
== VTK_QUAD
) {
113 new_pts
[0] = _nodes
[pts
[0]];
114 new_pts
[1] = _nodes
[pts
[1]];
115 new_pts
[2] = _nodes
[pts
[2]];
116 vtkIdType id_new_cell1
= m_BGrid
->InsertNextCell(VTK_TRIANGLE
, 3, new_pts
.data());
117 copyCellData(grid
, id_cell
, m_BGrid
, id_new_cell1
);
118 new_pts
[0] = _nodes
[pts
[2]];
119 new_pts
[1] = _nodes
[pts
[3]];
120 new_pts
[2] = _nodes
[pts
[0]];
121 vtkIdType id_new_cell2
= m_BGrid
->InsertNextCell(VTK_TRIANGLE
, 3, new_pts
.data());
122 copyCellData(grid
, id_cell
, m_BGrid
, id_new_cell2
);
127 updateBackgroundGridInfo();
128 //m_FaceFinder.setMaxNumFaces(10);
129 m_FaceFinder
.setGrid(m_BGrid
);
132 #endif // TRIANGULARCADINTERFACE_H