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 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28 #include "egvtkobject.h"
29 #include "meshpartition.h"
30 #include "eghashset.h"
32 class PolyMesh
: public EgVtkObject
35 protected: // data types
42 int operator[](int i
);
43 bool operator<(const face_t
&F
) const;
44 bool operator==(const face_t
&F
) const;
46 face_t(int N
, int o
, int n
, vec3_t rv
, int b
= 0);
47 int hash() const { return node
.first(); }
51 QVector
<vtkIdType
> id
;
53 node_t(const QVector
<vtkIdType
> &ids
);
54 node_t(vtkIdType id1
);
55 node_t(vtkIdType id1
, vtkIdType id2
);
56 node_t(vtkIdType id1
, vtkIdType id2
, vtkIdType id3
);
57 node_t(vtkIdType id1
, vtkIdType id2
, vtkIdType id3
, vtkIdType id4
);
58 bool operator<(const node_t
&N
) const;
59 bool operator>(const node_t
&N
) const;
60 bool operator==(const node_t
&N
) const;
61 int hash() const { return id
.first(); }
65 protected: // attributes
67 vtkUnstructuredGrid
*m_Grid
;
69 QVector
<int> m_Cell2PCell
;
70 QVector
<int> m_Node2PCell
;
71 QList
<face_t
> m_Faces
;
73 EgHashSet
<node_t
> m_Nodes
;
74 QVector
<vec3_t
> m_Points
;
76 QVector
<double> m_PointWeights
;
77 QVector
<QList
<int> > m_Point2Face
;
78 QVector
<QList
<int> > m_PCell2Face
;
79 QVector
<vec3_t
> m_CellCentre
;
80 QVector
<bool> m_IsBadCell
;
82 double m_AttractorWeight
;
83 double m_PullInFactor
;
88 bool isHexCoreNode(vtkIdType
) { return false; }
89 bool isHexCoreCell(vtkIdType
) { return false; }
92 * Get internal indices of adjacent faces of an edge.
93 * See http://engits.eu/wiki/index.php/Manual/Element_Types for details about the internal indices.
94 * @param id_cell global id of the cell (only tetras allowed)
95 * @param id_node1 global id of the first node of the edge
96 * @param id_node2 global id of the second node of the edge
97 * @param face1 (return value) will hold the internal index of the first face (0,1,2,3)
98 * @param face2 (return value) will hold the internal index of the second face (0,1,2,3)
100 void getFacesOfEdgeInsideCell(vtkIdType id_cell
, vtkIdType id_node1
, vtkIdType id_node2
, int &face1
, int &face2
);
103 * Find all cells around an edge.
104 * This method will find all tetra cells around an edge in the mesh.
105 * It can either be a closed loop of tetras or a list which is terminated by surface elements.
106 * @param id_node1 first node of the edge
107 * @param id_node2 second node of the edge
108 * @param cells list of tetras/faces around the edge
110 void getSortedEdgeCells(vtkIdType id_node1
, vtkIdType id_node2
, QList
<vtkIdType
> &cells
, bool &is_loop
);
112 bool isDualFace(vtkIdType id_face
);
113 void getSortedPointFaces(vtkIdType id_node
, int bc
, QList
<vtkIdType
> &faces
, bool &is_loop
);
115 void findPolyCells();
116 void createFace(QList
<node_t
> nodes
, int owner
, int neighbour
, vec3_t ref_vec
, int bc
);
117 void createCornerFace(vtkIdType id_cell
, int i_face
, vtkIdType id_node
);
118 void createEdgeFace(vtkIdType id_node1
, vtkIdType id_node2
);
119 void createFaceFace(vtkIdType id_cell
, int i_face
);
120 void createPointFace(vtkIdType id_node
, int bc
);
121 void splitConcaveFaces();
122 void createNodesAndFaces();
123 void checkFaceOrientation();
124 void computePoints();
125 void buildPoint2Face();
126 void buildPCell2Face();
127 void triangulateBadFaces();
128 void splitConcaveCells();
130 vec3_t
faceNormal(int i
);
134 PolyMesh(vtkUnstructuredGrid
*grid
, bool dual_mesh
= true);
136 void setNodeVector(int i
, vec3_t x
) { m_Points
[i
] = x
; }
138 int totalNumNodes() const { return m_Points
.size(); }
139 vec3_t
nodeVector(int i
) const { return m_Points
[i
]; }
140 int numNodes(int i
) const { return m_Faces
[i
].node
.size(); }
141 int nodeIndex(int i
, int j
) const { return m_Faces
[i
].node
[j
]; }
142 int numFaces() const { return m_Faces
.size(); }
143 int owner(int i
) const { return m_Faces
[i
].owner
; }
144 int neighbour(int i
) const { return m_Faces
[i
].neighbour
; }
145 int boundaryCode(int i
) const { return m_Faces
[i
].bc
; }
146 int numBCs() const { return m_BCs
.size(); }
147 int numCells() const { return m_NumPolyCells
; }
148 int numFacesOfPCell(int i
) { return m_PCell2Face
[i
].size(); }
149 int pcell2Face(int i
, int j
) { return m_PCell2Face
[i
][j
]; }
156 inline int PolyMesh::face_t::operator[](int i
)
161 while (i
>= node
.size()) {
167 inline bool PolyMesh::face_t::operator<(const face_t
&F
) const
172 } else if (bc
== F
.bc
) {
173 if (owner
< F
.owner
) {
175 } else if (owner
== F
.owner
) {
176 if (neighbour
< F
.neighbour
) {
184 inline bool PolyMesh::face_t::operator==(const face_t
&F
) const
188 if (owner
== F
.owner
) {
189 if (neighbour
== F
.neighbour
) {