TexGen
Mesh.h
Go to the documentation of this file.
1/*=============================================================================
2TexGen: Geometric textile modeller.
3Copyright (C) 2006 Martin Sherburn
4
5This program is free software; you can redistribute it and/or
6modify it under the terms of the GNU General Public License
7as published by the Free Software Foundation; either version 2
8of the License, or (at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18=============================================================================*/
19
20#pragma once
21//#include "../tinyxml/tinyxml.h"
22#include "MeshData.h"
23
24//class TiXmlElement;
25namespace TexGen
26{
27 using namespace std;
28
30
58 {
59 public:
60 CMesh(void);
61 CMesh(TiXmlElement &Element);
62 ~CMesh(void);
63
66 {
77 NUM_ELEMENT_TYPES, // Note this should always be directly after the last valid element
78 };
79
81 static inline int GetNumNodes(ELEMENT_TYPE Type)
82 {
83 switch (Type)
84 {
85 case TRI:
86 return 3;
87 case QUAD:
88 return 4;
89 case TET:
90 return 4;
91 case PYRAMID:
92 return 5;
93 case WEDGE:
94 return 6;
95 case HEX:
96 return 8;
97 case LINE:
98 return 2;
99 case POLYLINE:
100 return 2;
101 case QUADRATIC_TET:
102 return 10;
103 case POLYGON:
104 return -1; // Closed polygon: start node = end node
105 }
106 return 0;
107 }
108
110 void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType) const;
111
113 // Methods to convert between element types //
115
117 list<int>::iterator ConvertQuadtoTriangles(list<int>::iterator itQuad);
118
120 void ConvertTrianglestoSegments();
121
123 void ConvertQuadstoTriangles(bool bQuality = true);
124
126 void ConvertHextoQuad();
127
129 void ConvertWedgeto2D();
130
132 void ConvertTettoTriangle();
133
135 void ConvertHextoWedge(bool bQuality = true);
136
138 void ConvertWedgetoTetandPyramid(bool bQuality = true);
139
141 void ConvertPyramidtoTet(bool bQuality = true);
142
144
148 void ConvertWedgetoTet(bool bQuality = true);
149
151
154 void ConvertHextoTet(bool bQuality = true);
155
157 void ConvertPyramidto2D();
158
160 void Convert3Dto2D();
161
163 void ConvertToSurfaceMesh();
164
167 void ConvertToTetMesh();
168
171 void ConvertToTriangleMesh();
172
174 void ConvertToSegmentMesh();
175
177
181 void ConvertTriToQuad( double Tolerance = 1e-6 );
182
184 // Various utility methods //
186
188 pair<XYZ, XYZ> GetAABB(double dGrowDistance = 0) const;
189
191
195 int MergeNodes(const double Tolerance = 1e-8);
196
198 int RemoveUnreferencedNodes();
199
201 void RemoveAllElementsExcept(ELEMENT_TYPE Type);
202
204 void RemoveElementType( ELEMENT_TYPE Type );
205
207 int DeleteNodes(const set<int> &Nodes);
208
210 void ChangeNodeIndices(int iChangeTo, int iChangeFrom);
211
213
219 void ChangeNodeIndices(int iChangeTo, int iChangeFrom, vector<vector<int*> > &References);
220
222 void RemoveOpposingTriangles();
223
225 void RemoveOpposingQuads();
226
228 void RemoveDegenerateTriangles();
229
230 // Remove triangles which have the same indices
231 void RemoveDuplicateTriangles();
232
234 void RemoveDuplicateSegments();
235
237
240 void RemoveDuplicateElements(CMesh::ELEMENT_TYPE ElementType);
241
243
246 void GetNodeElementReferences(vector<vector<int*> > &References);
247
249
254 int InsertNodes(const CMesh &Mesh, XYZ Offset = XYZ(0, 0, 0));
255
257
261 void InsertMesh(const CMesh &Mesh, XYZ Offset = XYZ(0, 0, 0));
262
264 void Rotate(WXYZ Rotation, XYZ Origin = XYZ(0,0,0));
265
267 void Translate(XYZ Vector);
268
270 void FlipNormals();
271
274
279 void MeshClosedLoop(const XYZ &Normal, const vector<int> &ClosedLoopVector, bool bQuality = false);
280
282
289 void MeshConvexHull();
290
292 void Clear();
293
295 void CopySelfToRange(XYZ Vector, int iLowerLimit, int iUpperLimit);
296
298
304 int OutputNodes(ostream &Output, int iStartIndex = 1, string Seperator = ", ", bool bSCIRun = false) const;
305
307
315 int OutputElements(ostream &Output, ELEMENT_TYPE ElementType, int iStartIndex = 1, int iIndexOffset = 1, string Seperator = ", ", bool bSCIRun = false) const;
316
318
325 double CalculateVolume() const;
326
328 vector<XYZ> GetElementCenters() const;
329
331 vector<XYZ> GetElementCenters( ELEMENT_TYPE type );
332
334
337 int CountInvertedElements() const;
338
340
343 int CountInvertedElements(ELEMENT_TYPE ElementType) const;
344
346
360 int IntersectLine(const XYZ &P1, const XYZ &P2, vector< pair<double, XYZ> > &IntersectionPoints, pair<bool, bool> TrimResults = make_pair(false, false), bool bForceFind = false/*, const CElementsOctree *pOctree = NULL*/) const;
361
363
371 void BuildGrid(XYZ Min, XYZ Max, int iNumX, int iNumY, int iNumZ);
372
374
380 void BuildGrid(XYZ Min, XYZ Max, double dPointsPerUnit);
381
383
388 vector<pair<int, int> > GetNodePairs(XYZ Vector, const double Tolerance = 1e-6) const;
389 void GetNodePairs(XYZ Vector, vector<pair<int, int> > &NodePairs, const double Tolerance = 1e-6) const;
390
392
396 int GetClosestNode(XYZ Position) const;
397
399
404 int GetClosestNodeDistance(XYZ Position, double dTol ) const;
405
407
411 void ConvertElementListToVector( ELEMENT_TYPE ElementType, vector<int> &Indices );
412
414 // Methods to output to various file formats //
416
418
423 bool SaveToSTL(string Filename, bool bBinary = true) const;
424
426
430 bool SaveToVTK(string Filename, const vector<CMeshDataBase*> *pMeshData = NULL) const;
431
433
446 bool SaveToABAQUS(string Filename, const vector<POINT_INFO> *pElementInfo = NULL, bool bCreateStep = true, bool bCreateMaterial = true, int iElementType = 0);
447
449 bool SaveToSMESH(string Filename) const;
450
452
455 bool SaveToSCIRun(string Filename);
456
457// bool ReadFromTetGen(string NodesFile, string ElementsFile, string FacesFile = "");
458
460 // Bunch of accessor methods to prevent direct access to underlying vector //
462
464 bool AddElement(ELEMENT_TYPE Type, const vector<int> &Indices);
465
467 int GetNumElements(ELEMENT_TYPE Type) const;
468
470 int GetNumElements() const;
471
472 vector<XYZ>::const_iterator NodesBegin() const;
473 vector<XYZ>::const_iterator NodesEnd() const;
474 vector<XYZ>::iterator NodesBegin();
475 vector<XYZ>::iterator NodesEnd();
476
478 const int AddNode(XYZ Node);
480 void SetNode(int iIndex, XYZ Node);
482 const XYZ& GetNode(int iIndex)const;
484 vector<XYZ>::iterator DeleteNode(vector<XYZ>::iterator it);
486 int GetNumNodes() const;
488 const bool NodesEmpty() const;
490 const vector<XYZ>& GetNodes() const;
491 vector<XYZ>& GetNodes();
493 void SetNumNodes(int NumNodes);
494
496 const list<int>& GetIndices(ELEMENT_TYPE ElemType) const;
497 list<int>& GetIndices(ELEMENT_TYPE ElemType);
498
499
500 protected:
502
505 static void AddOrCancel(list<pair<int, int> > &EdgeStack, pair<int, int> Edge);
506
507 static void WriteBinaryXYZ(ostream &Output, XYZ Vector);
508
509 int FillVTKPointData(TiXmlElement &Points) const;
510 int FillVTKCellData(TiXmlElement &Cells) const;
511
513 vector<XYZ> m_Nodes;
515 list<int> m_Indices[NUM_ELEMENT_TYPES];
516
517 };
518
519}; // namespace TexGen
520
521
522
523
#define CLASS_DECLSPEC
Definition: Misc.h:35
#define NULL
Definition: ShinyConfig.h:50
Defines the nodes and elements of a surface or volume mesh.
Definition: Mesh.h:58
static int GetNumNodes(ELEMENT_TYPE Type)
Get the number of nodes a particular element type contains.
Definition: Mesh.h:81
ELEMENT_TYPE
Each element type is represented by a unique integer value.
Definition: Mesh.h:66
@ NUM_ELEMENT_TYPES
Definition: Mesh.h:77
@ PYRAMID
Definition: Mesh.h:70
@ POLYLINE
Definition: Mesh.h:74
@ QUADRATIC_TET
Definition: Mesh.h:75
@ POLYGON
Definition: Mesh.h:76
vector< XYZ > m_Nodes
List of nodes.
Definition: Mesh.h:513
Namespace containing a series of customised math operations not found in the standard c++ library.
OUTPUT_TYPE
Definition: Misc.h:105
double Max(XYZ &Vector)
Get maximum element of vector and return it.
Definition: mymath.h:642
XYZ Min(const XYZ &P1, const XYZ &P2)
Given two points, return a new point who's coordinates are the smaller of the two.
Definition: mymath.h:1142
Struct for representing a quaternion.
Definition: mymath.h:38
Struct for representing points in 3D space.
Definition: mymath.h:56