26#include "../Triangle/triangle.h"
27#include "../Triangle/triangle_api.h"
32CSectionMeshTriangulate::CSectionMeshTriangulate(
double dMinAngle,
double dMaxArea)
33: m_dMinAngle(dMinAngle)
58 stringstream Switches;
69 Switches <<
"pzAPBq" << setiosflags(ios::fixed) << setprecision(20) <<
m_dMinAngle <<
"a" << dMaxArea;
71 triangleio TriangleInput, TriangleOutput;
74 ctx = triangle_context_create();
76 triangle_context_options(ctx, (
char*)Switches.str().c_str());
78 memset(&TriangleInput, 0,
sizeof(TriangleInput));
79 memset(&TriangleOutput, 0,
sizeof(TriangleOutput));
82 TriangleInput.pointlist =
new REAL [Section.size()*2];
83 TriangleInput.numberofpoints = (int)Section.size();
86 for (i=0; i<(int)Section.size(); ++i)
88 TriangleInput.pointlist[i*2] = Section[i].x;
89 TriangleInput.pointlist[i*2+1] = Section[i].y;
93 TriangleInput.segmentlist =
new int [Section.size()*2];
94 TriangleInput.numberofsegments = (int)Section.size();
96 for (i=0; i<(int)Section.size(); ++i)
98 TriangleInput.segmentlist[i*2] = i;
99 TriangleInput.segmentlist[i*2+1] = (i+1)%Section.size();
102 triangle_mesh_create(ctx, &TriangleInput);
104 delete [] TriangleInput.pointlist;
105 delete [] TriangleInput.segmentlist;
109 triangle_mesh_copy(ctx, &TriangleOutput, 1, 1);
112 for (i=0; i<TriangleOutput.numberofpoints; ++i)
114 Point.
x = TriangleOutput.pointlist[i*2];
115 Point.
y = TriangleOutput.pointlist[i*2+1];
119 for (i=0; i<TriangleOutput.numberoftriangles; ++i)
126 triangle_free(TriangleOutput.pointlist);
127 triangle_free(TriangleOutput.trianglelist);
128 triangle_context_destroy(ctx);
135 stringstream Switches;
139 double dMaxArea = dSectionArea * 0.5;
140 double dMinAngle = 20;
147 Switches <<
"pzAPBq" << setiosflags(ios::fixed) << setprecision(20) << dMinAngle <<
"a" << dMaxArea;
149 triangleio TriangleInput, TriangleOutput;
152 ctx = triangle_context_create();
154 triangle_context_options(ctx, (
char*)Switches.str().c_str());
156 memset(&TriangleInput, 0,
sizeof(TriangleInput));
157 memset(&TriangleOutput, 0,
sizeof(TriangleOutput));
160 TriangleInput.pointlist =
new REAL[Section.size() * 2];
161 TriangleInput.numberofpoints = (int)Section.size();
164 for (i = 0; i < (int)Section.size(); ++i)
166 TriangleInput.pointlist[i * 2] = Section[i].x;
167 TriangleInput.pointlist[i * 2 + 1] = Section[i].y;
171 TriangleInput.segmentlist =
new int[Section.size() * 2];
172 TriangleInput.numberofsegments = (int)Section.size();
174 for (i = 0; i < (int)Section.size(); ++i)
176 TriangleInput.segmentlist[i * 2] = i;
177 TriangleInput.segmentlist[i * 2 + 1] = (i + 1) % Section.size();
180 triangle_mesh_create(ctx, &TriangleInput);
182 delete[] TriangleInput.pointlist;
183 delete[] TriangleInput.segmentlist;
187 triangle_mesh_copy(ctx, &TriangleOutput, 1, 1);
190 for (i = 0; i < TriangleOutput.numberofpoints; ++i)
192 Point.
x = TriangleOutput.pointlist[i * 2];
193 Point.
y = TriangleOutput.pointlist[i * 2 + 1];
197 for (i = 0; i < TriangleOutput.numberoftriangles; ++i)
204 triangle_free(TriangleOutput.pointlist);
205 triangle_free(TriangleOutput.trianglelist);
206 triangle_context_destroy(ctx);
215 vector<int> ClosedLoop;
217 vector<XY>::const_iterator itPoint;
219 for (i=0, itPoint = Section.begin(); itPoint != Section.end(); ++itPoint, ++i)
222 ClosedLoop.push_back(i);
Defines the nodes and elements of a surface or volume mesh.
const int AddNode(XYZ Node)
Append a node to the list of nodes, the integer returns the index of the node
const list< int > & GetIndices(ELEMENT_TYPE ElemType) const
Get the element indices of a given element type.
void MeshClosedLoop(const XYZ &Normal, const vector< int > &ClosedLoopVector, bool bQuality=false)
void Clear()
Empty mesh nodes and indices.
static double GetArea(const vector< XY > &Section)
Get the area of a section.
CMesh m_Mesh
Used to cache the result of the previous mesh for efficiency.
virtual void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType) const
Used for saving data to XML.
static CMesh GetSimpleMesh(const vector< XY > &Section)
~CSectionMeshTriangulate(void)
void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType) const
Used for saving data to XML.
bool CreateMesh(const vector< XY > &Section) const
Create a mesh out of given list of points representing the edge of the section.
CSectionMeshTriangulate(double dMinAngle=20, double dMaxArea=1)
Set the mesh quality parameters.
static CMesh GetTriangleMesh(const vector< XY > &Section)
Namespace containing a series of customised math operations not found in the standard c++ library.
std::string stringify(const T &x, int iPrecision=12, bool bScientific=true)
Function to convert a value (e.g. int, double, etc...) to a string.
Struct for representing points in 3D space.