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 TriangularCadInterface();
60 virtual HitType
shootRay(vec3_t x
, vec3_t v
, vec3_t
&x_hit
, vec3_t
&n_hit
, double &r
);
61 //virtual PositionType position(vec3_t x, vec3_t n);
63 template <class C
> void setBackgroundGrid(vtkUnstructuredGrid
* grid
, const C
& cells
); ///< Set the background grid to use + set it up
68 void TriangularCadInterface::setBackgroundGrid(vtkUnstructuredGrid
* grid
, const C
& cells
)
70 QVector
<vtkIdType
> nodes
;
71 getNodesFromCells(cells
, nodes
, grid
);
72 int num_new_cells
= cells
.size();
73 foreach (vtkIdType id_cell
, cells
) {
74 vtkIdType type_cell
= grid
->GetCellType(id_cell
);
75 if (type_cell
== VTK_QUAD
) {
79 allocateGrid(m_BGrid
, num_new_cells
, nodes
.size());
81 QVector
<vtkIdType
> _nodes(grid
->GetNumberOfPoints());
82 vtkIdType id_new_node
= 0;
83 foreach (vtkIdType id_node
, nodes
) {
85 grid
->GetPoints()->GetPoint(id_node
, x
.data());
86 m_BGrid
->GetPoints()->SetPoint(id_new_node
, x
.data());
87 copyNodeData(grid
,id_node
,m_BGrid
,id_new_node
);
88 _nodes
[id_node
] = id_new_node
;
91 foreach (vtkIdType id_cell
, cells
) {
92 vtkIdType N_pts
, *pts
;
93 vtkIdType type_cell
= grid
->GetCellType(id_cell
);
94 grid
->GetCellPoints(id_cell
, N_pts
, pts
);
95 QVector
<vtkIdType
> new_pts(3);
96 if (type_cell
== VTK_TRIANGLE
) {
97 new_pts
[0] = _nodes
[pts
[0]];
98 new_pts
[1] = _nodes
[pts
[1]];
99 new_pts
[2] = _nodes
[pts
[2]];
100 vtkIdType id_new_cell
= m_BGrid
->InsertNextCell(VTK_TRIANGLE
, 3, new_pts
.data());
101 copyCellData(grid
, id_cell
, m_BGrid
, id_new_cell
);
102 } else if (type_cell
== VTK_QUAD
) {
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_cell1
= m_BGrid
->InsertNextCell(VTK_TRIANGLE
, 3, new_pts
.data());
107 copyCellData(grid
, id_cell
, m_BGrid
, id_new_cell1
);
108 new_pts
[0] = _nodes
[pts
[2]];
109 new_pts
[1] = _nodes
[pts
[3]];
110 new_pts
[2] = _nodes
[pts
[0]];
111 vtkIdType id_new_cell2
= m_BGrid
->InsertNextCell(VTK_TRIANGLE
, 3, new_pts
.data());
112 copyCellData(grid
, id_cell
, m_BGrid
, id_new_cell2
);
117 updateBackgroundGridInfo();
118 m_FaceFinder
.setMaxNumFaces(10);
119 m_FaceFinder
.setGrid(m_BGrid
);
122 #endif // TRIANGULARCADINTERFACE_H