rsvs3D  0.0.0
Codes for the c++ implementation of the 3D RSVS
triangulate.hpp
Go to the documentation of this file.
1 
10 //===============================================
11 // Include Guards
12 #ifndef TRIANGULATE_H_INCLUDED
13 #define TRIANGULATE_H_INCLUDED
14 
15 //===============================================
16 // Levels of debuging Guards
17 #ifdef DEBUGLVL2 // All Debugging calls
18 #define DEBUGLVL1
19 #define TEST_ALL
20 #endif
21 
22 #ifdef DEBUGLVL1
23 
24 #endif
25 
26 //========================================
27 // Forward declared dependencies
28 class RSVScalc;
29 class SurfCentroid;
30 
31 //=================================
32 // included dependencies
33 #include <vector>
34 
35 #include "arraystructures.hpp"
36 #include "mesh.hpp"
37 #include "snake.hpp"
38 
39 //==================================
40 // Code
41 // NOTE: function in a class definition are IMPLICITELY INLINED
42 // ie replaced by their code at compile time
43 
44 template <class T> class TriStruct;
45 
46 class triangle;
47 class trianglepoint;
48 class trianglesurf;
49 class tecplotfile;
50 
51 // typedef TriStruct<triangle> triarray;
52 // typedef TriStruct<trianglepoint> tripointarray;
53 // typedef TriStruct<trianglesurf> trisurfarray;
54 
55 // Template Class
56 namespace rsvs3d
57 {
58 namespace constants
59 {
60 namespace meshtypes
61 {
62 static const int mesh = 1;
63 static const int snake = 2;
64 static const int triangulation = 3;
65 } // namespace meshtypes
66 } // namespace constants
67 } // namespace rsvs3d
68 template <class T> class TriStruct : public SnakStruct<T>
69 {
70  friend class triangulation;
71 };
72 
73 class triarray : public TriStruct<triangle>
74 {
75 };
76 class tripointarray : public TriStruct<trianglepoint>
77 {
78 };
79 class trisurfarray : public TriStruct<trianglesurf>
80 {
81 };
82 
83 // Base classes
85 {
86  public:
87  std::vector<int> acttri; //
88  triarray stattri;
89  triarray dynatri;
90  triarray intertri;
91 
92  tripointarray trivert;
93  trisurfarray trisurf;
94 
95  snake *snakeDep = NULL; // Pointer to the Snake referred to in triangles
96  mesh *meshDep = NULL; // Pointer to the Mesh referred to in triangles
97 
98  void disp() const;
99  void PrepareForUse();
100  void CleanDynaTri();
101  void CalcTriVertPosDyna(int ii);
102  void CalcTriVertPosDyna();
103  void CalcTriVertPos(int ii);
104  void CalcTriVertPos();
105  void SetActiveStaticTri();
106 
107  void SetConnectivity();
108  void SetConnectivityStat(int ii);
109  void SetConnectivityInter(int ii);
110  void SetConnectivityDyna(int ii);
111  void clear();
112 
113  triangulation()
114  {
115  meshDep = NULL;
116  snakeDep = NULL;
117  }
118  explicit triangulation(mesh &meshin)
119  {
120  meshDep = &meshin;
121  snakeDep = NULL;
122  }
123 };
124 
125 class tri2mesh
126 {
127  public:
128  std::vector<int> celltarg; // cell need to be indexed in a support array
129  // which maps to constraints etc
130  std::vector<double> constrinfluence; // +1 -1 to indicate
131 };
132 
133 class triangle : public ArrayStructpart, public snakpart
134 {
135  private:
136  bool isTriangleReady = false;
137 
138  public:
139  std::vector<int> pointtype; // 1=mesh vertex 2=snaxel 3=trianglepoint
140  std::vector<int> pointind;
141  int parentsurf = 0; // Surface in the snakemesh() needs to be converted to constr
142  int parenttype = 0;
143 
144  // double constrinfluence=0; //usually 1 or -1 to do with the ordering
145  tri2mesh connec;
146 
147  // interface functions
148  void disp() const override;
149  int Key() const override
150  {
151  return (index);
152  };
153  int KeyParent() const override
154  {
155  return (parentsurf);
156  };
157  void ChangeIndices(int nVert, int nEdge, int nSurf, int nVolu) override;
158  void PrepareForUse() override{};
159 #pragma GCC diagnostic push
160 #pragma GCC diagnostic ignored "-Wunused-parameter"
161  bool isready(bool isInMesh) const override
162  {
163  return (isTriangleReady);
164  }
165  void SwitchIndex(int typeInd, int oldInd, int newInd)
166  {
167  }
168 #pragma GCC diagnostic pop
169  void read(FILE *fid) override;
170  void write(FILE *fid) const override;
171  void TightenConnectivity() override
172  {
173  }
174  void SetPointType(int a, int b, int c)
175  {
176  pointtype[0] = a;
177  pointtype[1] = b;
178  pointtype[2] = c;
179  }
180  triangle()
181  { // Constructor
182  index = 0;
183 
184  pointtype.assign(3, 0);
185  pointind.assign(3, 0);
186  isTriangleReady = false;
187  }
188 };
189 
190 class trianglepoint : public ArrayStructpart, public snakpart
191 {
192  public:
193  coordvec coord;
194  int parentsurf = 0;
195  int parentType = 0;
196  int nInfluences = 0;
197 
198  // interface functions
199  void disp() const override;
200  int Key() const override
201  {
202  return (index);
203  };
204  int KeyParent() const override
205  {
206  return (parentsurf);
207  };
208  void ChangeIndices(int nVert, int nEdge, int nSurf, int nVolu) override;
209  void ChangeIndicesSnakeMesh(int nVert, int nEdge, int nSurf, int nVolu);
210  void PrepareForUse() override{};
211 #pragma GCC diagnostic push
212 #pragma GCC diagnostic ignored "-Wunused-parameter"
213  bool isready(bool isInMesh) const override
214  {
215  return (true);
216  }
217  void SwitchIndex(int typeInd, int oldInd, int newInd)
218  {
219  }
220 #pragma GCC diagnostic pop
221  void read(FILE *fid) override;
222  void write(FILE *fid) const override;
223  void TightenConnectivity() override
224  {
225  }
226 };
227 
228 class trianglesurf : public ArrayStructpart, public snakpart
229 {
230  public:
231  std::vector<int> indvert;
232  std::vector<int> typevert;
233  std::vector<int> voluind;
234  int parentsurfmesh = 0;
235 
236  // interface functions
237  void disp() const override;
238  int Key() const override
239  {
240  return (index);
241  };
242  int KeyParent() const override
243  {
244  return (parentsurfmesh);
245  };
246  void ChangeIndices(int nVert, int nEdge, int nSurf, int nVolu) override;
247  void ChangeIndicesSnakeMesh(int nVert, int nEdge, int nSurf, int nVolu);
248  void PrepareForUse() override{};
249 #pragma GCC diagnostic push
250 #pragma GCC diagnostic ignored "-Wunused-parameter"
251  bool isready(bool isInMesh) const override
252  {
253  return (true);
254  }
255  void SwitchIndex(int typeInd, int oldInd, int newInd)
256  {
257  }
258 #pragma GCC diagnostic pop
259  void read(FILE *fid) override;
260  void write(FILE *fid) const override;
261  void TightenConnectivity() override
262  {
263  }
264 };
265 
266 void CalculateSnakeVel(snake &snakein);
267 void CalculateSnakeVelRand(snake &snakein);
268 void CalculateSnakeVelUnit(snake &snakein);
269 void CalculateSnakeVelUnitReflect(snake &snakein);
270 void CalculateSnakeVelFast(snake &snakein);
271 void CalculateNoNanSnakeVel(snake &snakein, double deltaStep = 0.01);
272 void TriangulateSurface(const surf &surfin, const mesh &meshin, triarray &triangul, tripointarray &trivert,
273  const int typeMesh, int trivertMaxInd);
274 void TriangulateTriSurface(const trianglesurf &surfin, triarray &triangul, tripointarray &trivert, const int typeMesh,
275  int trivertMaxInd);
276 void TriangulateContainer(const mesh &meshin, triangulation &triangleRSVS, const int typeMesh,
277  const std::vector<int> &subList = {});
278 void TriangulateSnake(snake &snakein, triangulation &triangleRSVS);
279 void TriangulateMesh(mesh &meshin, triangulation &triangleRSVS);
280 void MeshTriangulation(mesh &meshout, const mesh &meshin, triarray &triangul, tripointarray &trivert);
281 void MaintainTriangulateSnake(triangulation &triangleRSVS);
282 void SnakeSurfaceCentroid_fun(coordvec &coord, const surf &surfin, const mesh &meshin);
283 void HybridSurfaceCentroid_fun(coordvec &coord, const trianglesurf &surfin, const mesh &meshin, const mesh &snakeconn);
284 
285 void Test_stepalgoRSVS(snake &testSnake, triangulation &RSVStri, std::vector<double> &dt, std::vector<int> &isImpact,
286  RSVScalc &calcObj, tecplotfile &outSnake2, double totT);
287 void BuildTriSurfGridSnakeIntersect(triangulation &triangleRSVS);
288 int FollowVertexConnection(int actVert, int prevEdge, const HashedVector<int, int> &edgeSurfInd,
289  const HashedVector<int, int> &vertSurfInd, const snake &snakeRSVS, const mesh &meshRSVS,
290  int &returnIndex, int &returnType, int &nextEdge);
291 int FollowSnaxelDirection(int actSnax, const snake &snakeRSVS, int &returnIndex, int &returnType, int &actEdge);
292 bool FollowSnaxEdgeConnection(int actSnax, int actSurf, int followSnaxEdge, const snake &snakeRSVS,
293  std::vector<bool> &isSnaxEdgeDone, int &returnIndex);
294 mesh TriarrayToMesh(const triangulation &triangul, const triarray &triin);
295 void FlattenBoundaryFaces(mesh &meshin);
296 SurfCentroid SurfaceCentroid_TriangleSurf(const trianglesurf &surfin, const mesh &meshin, const mesh &snakeconn);
297 SurfCentroid SurfaceCentroid_SnakeSurf(const surf &surfin, const mesh &meshin);
298 
299 int Test_snakeRSVS();
300 int Test_surfcentre();
301 int Test_snakeRSVS_singlevol();
302 int Test_MeshOrient();
303 int Test_RSVSalgo_singlevol(int sparseCuttoff);
304 int Test_RSVSalgo_singlevol_fullmath();
305 int Test_RSVSalgo_singlevol_sparse();
306 #endif // TRIANGULATE_H_INCLUDED
Provide std::vector container with hashed index mapping.
Class to handle the RSVS calculation.
Definition: RSVScalc.hpp:130
Handles the use and norm of a vector for which the norm and the unit value might be needed.
Definition: mesh.hpp:114
Class for mesh handling.
Definition: mesh.hpp:592
Definition: snake.hpp:83
Class for surface object in a mesh.
Definition: mesh.hpp:267
void clear()
Clears the contents of the triangulation making sure we can restart the process.
Provides all the mesh tools used for the generation of 3D grids and geometries.
Namespace for general purpose tools of the RSVS project.
Definition: snake.cpp:1464
Provides the core restricted surface snake container.