fixed edge display for volume cells
[engrid-github.git] / src / libengrid / triangularcadinterface.h
blob5f1f5df644b1219f263642d20a8e7f9c61018caa
1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 // + +
3 // + This file is part of enGrid. +
4 // + +
5 // + Copyright 2008-2014 enGits GmbH +
6 // + +
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. +
11 // + +
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. +
16 // + +
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/>. +
19 // + +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #ifndef TRIANGULARCADINTERFACE_H
22 #define TRIANGULARCADINTERFACE_H
24 #include "cadinterface.h"
25 #include "triangle.h"
26 #include "facefinder.h"
27 #include "surfacealgorithm.h"
29 class TriangularCadInterface : public CadInterface
32 private: // methods
34 template <class C>
35 void setBackgroundGrid_setupGrid(vtkUnstructuredGrid* grid, const C& cells); ///< copy the cells from grid to m_BGrid
37 void updateBackgroundGridInfo(); ///< Set up the background grid (triangles, bezier triangles, etc)
38 void computeSurfaceCurvature();
39 vtkIdType getProjTriangle(vtkIdType id_node);
40 void setProjTriangle(vtkIdType id_node, vtkIdType proj_triangle);
43 protected: // attributes
45 vtkUnstructuredGrid* m_BGrid; ///< the background grid defining the geometry
46 MeshPartition m_BPart;
47 QVector<vtkIdType> m_Cells;
48 QVector<vtkIdType> m_Nodes;
49 QVector<vec3_t> m_NodeNormals; ///< The surface normal at each node of m_BGrid
50 QVector<Triangle> m_Triangles; ///< All triangles of m_BGrid. One for each triangle cell of m_BGrid.
51 QVector<double> m_Radius; ///< Surface radius for mesh resolution.
52 QVector<QVector<int> > m_N2N;
53 double m_CritDistance;
54 FaceFinder m_FaceFinder;
55 QMap<vtkIdType,vtkIdType> m_Pindex;
57 static vtkIdType m_LastPindex;
60 protected: // methods
62 void searchNewTriangle(vec3_t xp, vtkIdType &id_tri, vec3_t &x_proj, vec3_t &r_proj, bool &on_triangle);
63 virtual vec3_t correctCurvature(vtkIdType proj_triangle, vec3_t x);
66 public:
68 TriangularCadInterface();
70 virtual vec3_t snap(vec3_t x, bool correct_curvature = false);
71 virtual vec3_t snapNode(vtkIdType id_node, vec3_t x, bool correct_curvature = false);
72 virtual vec3_t correctCurvature(vec3_t x);
74 template <class C> void setBackgroundGrid(vtkUnstructuredGrid* grid, const C& cells); ///< Set the background grid to use + set it up
78 template <class C>
79 void TriangularCadInterface::setBackgroundGrid(vtkUnstructuredGrid* grid, const C& cells)
81 QVector<vtkIdType> nodes;
82 getNodesFromCells(cells, nodes, grid);
83 int num_new_cells = cells.size();
84 foreach (vtkIdType id_cell, cells) {
85 vtkIdType type_cell = grid->GetCellType(id_cell);
86 if (type_cell == VTK_QUAD) {
87 ++num_new_cells;
90 allocateGrid(m_BGrid, num_new_cells, nodes.size());
92 QVector<vtkIdType> _nodes(grid->GetNumberOfPoints());
93 vtkIdType id_new_node = 0;
94 foreach (vtkIdType id_node, nodes) {
95 vec3_t x;
96 grid->GetPoints()->GetPoint(id_node, x.data());
97 m_BGrid->GetPoints()->SetPoint(id_new_node, x.data());
98 copyNodeData(grid,id_node,m_BGrid,id_new_node);
99 _nodes[id_node] = id_new_node;
100 ++id_new_node;
102 foreach (vtkIdType id_cell, cells) {
103 vtkIdType N_pts, *pts;
104 vtkIdType type_cell = grid->GetCellType(id_cell);
105 grid->GetCellPoints(id_cell, N_pts, pts);
106 QVector<vtkIdType> new_pts(3);
107 if (type_cell == VTK_TRIANGLE) {
108 new_pts[0] = _nodes[pts[0]];
109 new_pts[1] = _nodes[pts[1]];
110 new_pts[2] = _nodes[pts[2]];
111 vtkIdType id_new_cell = m_BGrid->InsertNextCell(VTK_TRIANGLE, 3, new_pts.data());
112 copyCellData(grid, id_cell, m_BGrid, id_new_cell);
113 } else if (type_cell == VTK_QUAD) {
114 new_pts[0] = _nodes[pts[0]];
115 new_pts[1] = _nodes[pts[1]];
116 new_pts[2] = _nodes[pts[2]];
117 vtkIdType id_new_cell1 = m_BGrid->InsertNextCell(VTK_TRIANGLE, 3, new_pts.data());
118 copyCellData(grid, id_cell, m_BGrid, id_new_cell1);
119 new_pts[0] = _nodes[pts[2]];
120 new_pts[1] = _nodes[pts[3]];
121 new_pts[2] = _nodes[pts[0]];
122 vtkIdType id_new_cell2 = m_BGrid->InsertNextCell(VTK_TRIANGLE, 3, new_pts.data());
123 copyCellData(grid, id_cell, m_BGrid, id_new_cell2);
124 } else {
125 EG_BUG;
128 updateBackgroundGridInfo();
129 //m_FaceFinder.setMaxNumFaces(10);
130 m_FaceFinder.setGrid(m_BGrid);
133 #endif // TRIANGULARCADINTERFACE_H