added methods to convert between Cartesian and spherical coordinates
[engrid-github.git] / src / libengrid / triangularcadinterface.h
blob14b54a0df58b6e74d5aabd0df70db92c666fe697
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008-2013 enGits GmbH +
7 // + +
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. +
12 // + +
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. +
17 // + +
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/>. +
20 // + +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #ifndef TRIANGULARCADINTERFACE_H
24 #define TRIANGULARCADINTERFACE_H
26 #include "cadinterface.h"
27 #include "triangle.h"
28 #include "facefinder.h"
29 #include "surfacealgorithm.h"
31 class TriangularCadInterface : public CadInterface, public SurfaceAlgorithm
34 private: // methods
36 template <class C>
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;
56 public:
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
67 template <class C>
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) {
76 ++num_new_cells;
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) {
84 vec3_t x;
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;
89 ++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);
113 } else {
114 EG_BUG;
117 updateBackgroundGridInfo();
118 m_FaceFinder.setMaxNumFaces(10);
119 m_FaceFinder.setGrid(m_BGrid);
122 #endif // TRIANGULARCADINTERFACE_H