feature magic is an amplification factor for edge sharpening (not corners)
[engrid.git] / src / libengrid / polymesh.h
blob27b5011b171b059208f8818a538286b9f5a3414a
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 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 //
23 #ifndef polymesh_H
24 #define polymesh_H
26 class PolyMesh;
28 #include "egvtkobject.h"
29 #include "meshpartition.h"
30 #include "eghashset.h"
32 class PolyMesh : public EgVtkObject
35 protected: // data types
37 struct face_t {
38 QVector<int> node;
39 int owner, neighbour;
40 int bc;
41 vec3_t ref_vec;
42 int operator[](int i);
43 bool operator<(const face_t &F) const;
44 bool operator==(const face_t &F) const;
45 face_t() {}
46 face_t(int N, int o, int n, vec3_t rv, int b = 0);
47 int hash() const { return node.first(); }
50 struct node_t {
51 QVector<vtkIdType> id;
52 node_t() {}
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;
68 MeshPartition m_Part;
69 QVector<int> m_Cell2PCell;
70 QVector<int> m_Node2PCell;
71 QList<face_t> m_Faces;
72 int m_NumPolyCells;
73 EgHashSet<node_t> m_Nodes;
74 QVector<vec3_t> m_Points;
75 QVector<int> m_BCs;
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;
86 protected: // methods
88 bool isHexCoreNode(vtkIdType) { return false; }
89 bool isHexCoreCell(vtkIdType) { return false; }
91 /**
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);
132 public: // methods
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)
158 while (i < 0) {
159 i += node.size();
161 while (i >= node.size()) {
162 i -= node.size();
164 return node[i];
167 inline bool PolyMesh::face_t::operator<(const face_t &F) const
169 bool less = false;
170 if (bc < F.bc) {
171 less = true;
172 } else if (bc == F.bc) {
173 if (owner < F.owner) {
174 less = true;
175 } else if (owner == F.owner) {
176 if (neighbour < F.neighbour) {
177 less = true;
181 return less;
184 inline bool PolyMesh::face_t::operator==(const face_t &F) const
186 bool equal = false;
187 if (bc == F.bc) {
188 if (owner == F.owner) {
189 if (neighbour == F.neighbour) {
190 equal = true;
194 return equal;
197 #endif