2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008-2013 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 TRIANGULARCADINTERFACE_H
24 #define TRIANGULARCADINTERFACE_H
26 #include "cadinterface.h"
28 #include "facefinder.h"
29 #include "surfacealgorithm.h"
31 class TriangularCadInterface
: public CadInterface
, public SurfaceAlgorithm
37 void setBackgroundGrid_setupGrid(vtkUnstructuredGrid
* grid
, const C
& cells
); ///< copy the cells from grid to m_BGrid
39 void updateBackgroundGridInfo(); ///< Set up the background grid (triangles, bezier triangles, etc)
40 void computeSurfaceCurvature();
42 protected: // attributes
44 vtkUnstructuredGrid
* m_BGrid
; ///< the background grid defining the geometry
45 MeshPartition m_BPart
;
46 QVector
<vtkIdType
> m_Cells
;
47 QVector
<vtkIdType
> m_Nodes
;
48 QVector
<vec3_t
> m_NodeNormals
; ///< The surface normal at each node of m_BGrid
49 QVector
<Triangle
> m_Triangles
; ///< All triangles of m_BGrid. One for each triangle cell of m_BGrid.
50 QVector
<double> m_Radius
; ///< Surface radius for mesh resolution.
51 QVector
<QVector
<int> > m_N2N
;
52 double m_CritDistance
;
53 FaceFinder m_FaceFinder
;
58 void searchNewTriangle(vec3_t xp
, vtkIdType
&id_tri
, vec3_t
&x_proj
, vec3_t
&r_proj
, bool neigh_mode
, bool &on_triangle
);
59 virtual vec3_t
correctCurvature(vtkIdType proj_triangle
, vec3_t x
);
64 TriangularCadInterface();
66 virtual vec3_t
snap(vec3_t x
, bool correct_curvature
= false);
67 virtual vec3_t
correctCurvature(vec3_t x
);
69 template <class C
> void setBackgroundGrid(vtkUnstructuredGrid
* grid
, const C
& cells
); ///< Set the background grid to use + set it up
74 void TriangularCadInterface::setBackgroundGrid(vtkUnstructuredGrid
* grid
, const C
& cells
)
76 QVector
<vtkIdType
> nodes
;
77 getNodesFromCells(cells
, nodes
, grid
);
78 int num_new_cells
= cells
.size();
79 foreach (vtkIdType id_cell
, cells
) {
80 vtkIdType type_cell
= grid
->GetCellType(id_cell
);
81 if (type_cell
== VTK_QUAD
) {
85 allocateGrid(m_BGrid
, num_new_cells
, nodes
.size());
87 QVector
<vtkIdType
> _nodes(grid
->GetNumberOfPoints());
88 vtkIdType id_new_node
= 0;
89 foreach (vtkIdType id_node
, nodes
) {
91 grid
->GetPoints()->GetPoint(id_node
, x
.data());
92 m_BGrid
->GetPoints()->SetPoint(id_new_node
, x
.data());
93 copyNodeData(grid
,id_node
,m_BGrid
,id_new_node
);
94 _nodes
[id_node
] = id_new_node
;
97 foreach (vtkIdType id_cell
, cells
) {
98 vtkIdType N_pts
, *pts
;
99 vtkIdType type_cell
= grid
->GetCellType(id_cell
);
100 grid
->GetCellPoints(id_cell
, N_pts
, pts
);
101 QVector
<vtkIdType
> new_pts(3);
102 if (type_cell
== VTK_TRIANGLE
) {
103 new_pts
[0] = _nodes
[pts
[0]];
104 new_pts
[1] = _nodes
[pts
[1]];
105 new_pts
[2] = _nodes
[pts
[2]];
106 vtkIdType id_new_cell
= m_BGrid
->InsertNextCell(VTK_TRIANGLE
, 3, new_pts
.data());
107 copyCellData(grid
, id_cell
, m_BGrid
, id_new_cell
);
108 } else if (type_cell
== VTK_QUAD
) {
109 new_pts
[0] = _nodes
[pts
[0]];
110 new_pts
[1] = _nodes
[pts
[1]];
111 new_pts
[2] = _nodes
[pts
[2]];
112 vtkIdType id_new_cell1
= m_BGrid
->InsertNextCell(VTK_TRIANGLE
, 3, new_pts
.data());
113 copyCellData(grid
, id_cell
, m_BGrid
, id_new_cell1
);
114 new_pts
[0] = _nodes
[pts
[2]];
115 new_pts
[1] = _nodes
[pts
[3]];
116 new_pts
[2] = _nodes
[pts
[0]];
117 vtkIdType id_new_cell2
= m_BGrid
->InsertNextCell(VTK_TRIANGLE
, 3, new_pts
.data());
118 copyCellData(grid
, id_cell
, m_BGrid
, id_new_cell2
);
123 updateBackgroundGridInfo();
124 m_FaceFinder
.setMaxNumFaces(10);
125 m_FaceFinder
.setGrid(m_BGrid
);
128 #endif // TRIANGULARCADINTERFACE_H