25#include "../Triangle/triangle.h"
26#include "../Triangle/triangle_api.h"
46 pair<XYZ, XYZ> DomainAABB;
51 TGERROR(
"Error creating surface mesh. Cannot generate tetgen mesh");
59 m_in.facetlist =
new tetgenio::facet[
m_in.numberoffacets];
62 list<int>::const_iterator itIter;
69 for (itIter = Indices.begin(); itIter != Indices.end(); )
73 f = &
m_in.facetlist[i];
74 f->numberofpolygons = 1;
75 f->polygonlist =
new tetgenio::polygon[f->numberofpolygons];
78 p = &f->polygonlist[0];
79 p->numberofvertices = iNumNodes;
80 p->vertexlist =
new int[p->numberofvertices];
81 for (
int iNode = 0; iNode < iNumNodes; ++iNode )
83 p->vertexlist[iNode] = *(itIter++) + 1;
97 vector<CMesh>::iterator itTriangulatedMeshes;
100 const list<int> &TriIndices = itTriangulatedMeshes->GetIndices(
CMesh::TRI);
101 list<int>::const_iterator itTriIndices;
106 f = &
m_in.facetlist[i];
107 f->numberofpolygons = (int)TriIndices.size()/iNumNodes;
108 f->polygonlist =
new tetgenio::polygon[f->numberofpolygons];
109 f->numberofholes = 0;
115 for (itTriIndices = TriIndices.begin(); itTriIndices != TriIndices.end(); )
117 p = &f->polygonlist[PolyInd++];
118 p->numberofvertices = iNumNodes;
119 p->vertexlist =
new int[p->numberofvertices];
121 for (
int iNode = 0; iNode < p->numberofvertices; ++iNode )
123 XYZ Point = itTriangulatedMeshes->GetNode( *(itTriIndices++) );
131 p->vertexlist[iNode] = ind + 1;
140 vector<CMesh>::iterator itDomainMeshes;
143 const list<int> &QuadIndices = itDomainMeshes->GetIndices(
CMesh::QUAD);
144 const list<int> &PolygonIndices = itDomainMeshes->GetIndices(
CMesh::POLYGON);
145 list<int>::const_iterator itQuadIndices;
146 list<int>::const_iterator itPolygonIndices;
151 f = &
m_in.facetlist[i];
152 if ( PolygonIndices.empty() )
153 f->numberofpolygons = 1;
156 if (QuadIndices.empty())
161 f->polygonlist =
new tetgenio::polygon[f->numberofpolygons];
162 f->numberofholes = 0;
169 for (itQuadIndices = QuadIndices.begin(); itQuadIndices != QuadIndices.end(); )
171 p = &f->polygonlist[PolyInd++];
172 p->numberofvertices = 4;
173 p->vertexlist =
new int[p->numberofvertices];
175 for (
int iNode = 0; iNode < p->numberofvertices; ++iNode )
177 XYZ Point = itDomainMeshes->GetNode( *(itQuadIndices++) );
185 p->vertexlist[iNode] = ind + 1;
190 if ( !PolygonIndices.empty() )
193 for (itPolygonIndices = PolygonIndices.begin(); itPolygonIndices != PolygonIndices.end(); )
195 p = &f->polygonlist[PolyInd++];
196 p->numberofvertices = *(itNumVertices++);
197 p->vertexlist =
new int[p->numberofvertices];
199 for (
int iNode = 0; iNode < p->numberofvertices; ++iNode )
201 XYZ Point = itDomainMeshes->GetNode( *(itPolygonIndices++) );
209 p->vertexlist[iNode] = ind + 1;
221 m_in.firstnumber = 1;
222 m_in.numberofpoints = m_Mesh.GetNumNodes();
224 m_in.pointlist =
new REAL[m_in.numberofpoints * 3];
226 vector<XYZ>::iterator itNode;
228 for ( itNode = m_Mesh.NodesBegin(); itNode != m_Mesh.NodesEnd(); ++itNode )
230 m_in.pointlist[iNodeInd++] = (*itNode).x;
231 m_in.pointlist[iNodeInd++] = (*itNode).y;
232 m_in.pointlist[iNodeInd++] = (*itNode).z;
237 int size = (int)OutputFilename.length();
239 char* TetgenOutput =
new char[size];
240 char* TetgenInput =
new char[size+5];
245 strInput = strOutput +
"Input";
246 strcpy(TetgenOutput, strOutput.c_str());
247 strcpy( TetgenInput, strInput.c_str());
249 m_in.save_nodes(TetgenInput);
250 m_in.save_poly(TetgenInput);
251 delete [] TetgenInput;
256 tetrahedralize((
char *)
"d", &m_in, &m_out);
260 TGERROR(
"Tetrahedralize failed. Intersections in PLC");
266 tetrahedralize((
char*)Parameters.c_str(), &m_in, &m_out);
270 TGERROR(
"Tetrahedralize failed. No mesh generated");
276 m_out.save_nodes(TetgenOutput);
277 m_out.save_elements(TetgenOutput);
278 m_out.save_faces(TetgenOutput);
279 delete [] TetgenOutput;
283 SaveToAbaqus(OutputFilename, Textile);
285 SaveToVTK(OutputFilename);
293 for (
int i = 0; i <
m_out.numberofpoints * 3; )
296 Point.
x =
m_out.pointlist[i++];
297 Point.
y =
m_out.pointlist[i++];
298 Point.
z =
m_out.pointlist[i++];
303 int quad_tet_ind[10] = {0, 1, 2, 3, 6, 7, 9, 5, 8, 4};
305 for (
int i = 0; i <
m_out.numberoftetrahedra; i++)
308 for (
int j = 0; j <
m_out.numberofcorners; j++ )
312 Indices.push_back(
m_out.tetrahedronlist[i*
m_out.numberofcorners + j]-1 );
316 Indices.push_back(
m_out.tetrahedronlist[i*
m_out.numberofcorners + quad_tet_ind[j]] -1);
340 vector<POINT_INFO>::const_iterator itPointInfo;
343 YarnIndex.
m_Data.push_back(itPointInfo->iYarnIndex);
344 YarnTangent.
m_Data.push_back(itPointInfo->YarnTangent);
345 Location.
m_Data.push_back(itPointInfo->Location);
346 VolumeFraction.
m_Data.push_back(itPointInfo->dVolumeFraction);
347 SurfaceDistance.
m_Data.push_back(itPointInfo->dSurfaceDistance);
348 Orientation.
m_Data.push_back(itPointInfo->Orientation);
351 vector<CMeshDataBase*> MeshData;
353 MeshData.push_back(&YarnIndex);
354 MeshData.push_back(&YarnTangent);
355 MeshData.push_back(&Location);
356 MeshData.push_back(&VolumeFraction);
357 MeshData.push_back(&SurfaceDistance);
358 MeshData.push_back(&Orientation);
#define TGERROR(MESSAGE)
Macros used to report the file name and line number to the TexGenError and TexGenLog functions.
void MeshDomainPlanes(bool bPeriodic)
vector< vector< int > > m_PolygonNumVertices
Number of polygon vertices on each face. Number of outer vector members = number of faces.
vector< CMesh > m_DomainMeshes
Vector of meshes used to store domain plane meshes.
vector< CMesh > m_TriangulatedMeshes
Vector of triangulated domain plane meshes.
bool AddElement(ELEMENT_TYPE Type, const vector< int > &Indices)
Add an element to the mesh of given type with node number checking.
int GetNumNodes() const
Return the number of nodes.
void ConvertQuadstoTriangles(bool bQuality=true)
Convert the quad elements to triangles.
bool SaveToABAQUS(string Filename, const vector< POINT_INFO > *pElementInfo=NULL, bool bCreateStep=true, bool bCreateMaterial=true, int iElementType=0)
Save the mesh to ABAQUS input file format with information such as yarn tangents.
const int AddNode(XYZ Node)
Append a node to the list of nodes, the integer returns the index of the node
vector< XYZ > GetElementCenters() const
Get a vector of element centers, one entry for each element.
bool SaveToVTK(string Filename, const vector< CMeshDataBase * > *pMeshData=NULL) const
Save the mesh to VTK unstructured grid file format (.vtu)
static int GetNumNodes(ELEMENT_TYPE Type)
Get the number of nodes a particular element type contains.
const list< int > & GetIndices(ELEMENT_TYPE ElemType) const
Get the element indices of a given element type.
ELEMENT_TYPE
Each element type is represented by a unique integer value.
int GetNumElements(ELEMENT_TYPE Type) const
Get the number of elements of a given type.
int GetClosestNodeDistance(XYZ Position, double dTol) const
Get the index of the node within a given tolerance distance to the given position space.
void Clear()
Empty mesh nodes and indices.
CMesh m_Mesh
Mesh used to store input node points and elements.
void SaveToVTK(string Filename)
Save output mesh to VTK format.
tetgenio m_in
Tetgen input and output structures.
void SaveTetgenMesh(CTextile &Textile, string OutputFilename, string Parameters, bool bPeriodic, int FileType)
Save a textile as a tetrahedralized mesh using Tetgen.
vector< POINT_INFO > m_ElementsInfo
Element information for output mesh.
CMesh m_OutputMesh
Mesh used to store output nodes and elements.
void SaveToAbaqus(string Filename, CTextile &Textile)
Save output mesh to Abaqus export file.
virtual ~CTetgenMesh(void)
void SaveMesh(CTextile &Textile)
Save tetgenio data to CMesh.
Represents a textile cell containing yarns.
void AddSurfaceToMesh(CMesh &Mesh, bool bTrimToDomain=false)
Create surface mesh for this textile and add it to the mesh object.
void GetPointInformation(const vector< XYZ > &Points, vector< POINT_INFO > &PointsInfo, double dTolerance=1e-9)
Get useful information of a list of points.
Namespace containing a series of customised math operations not found in the standard c++ library.
std::string RemoveExtension(std::string &Filename, std::string Extension)
Strip the extension from the filename.
Struct for representing points in 3D space.