24CSectionMeshRectangular::CSectionMeshRectangular(
int iNumLayers,
bool bTriangleCorners)
25: m_iNumLayers(iNumLayers)
26, m_bTriangleCorners(bTriangleCorners)
28 if (iNumLayers != -1 && iNumLayers % 2 != 0)
31 TGERROR(
"Warning: Rectangular mesh specified with an odd number of layers: " << iNumLayers);
59 if (iNumLayers % 2 != 0)
62 TGERROR(
"Unable to create section mesh, the number of layers is odd: " << iNumLayers);
65 if (Section.size() % 2 != 0)
68 TGERROR(
"Unable to create section mesh, the number of sections points specified is odd: " << Section.size());
71 int iNumColumns = Section.size()/2-iNumLayers;
77 TGERROR(
"Unable to create section mesh, the number of columns is less than 1: " << iNumColumns);
81 int iPointIndex, iNumPoints = (int)Section.size();
90 for (i=0; i<iNumLayers+1; ++i)
95 Right.push_back(
XY());
100 iPointIndex = iNumPoints-iNumLayers/2+i;
102 iPointIndex = i-iNumLayers/2;
103 Right.push_back(Section[iPointIndex]);
105 iPointIndex = 3*(iNumLayers/2)+iNumColumns-i;
106 Left.push_back(Section[iPointIndex]);
113 for (i=0; i<iNumColumns+1; ++i)
119 Bottom.push_back(
XY());
122 iPointIndex = iNumLayers/2+iNumColumns-i;
123 Top.push_back(Section[iPointIndex]);
125 iPointIndex = 3*(iNumLayers/2)+iNumColumns+i;
126 Bottom.push_back(Section[iPointIndex]);
138 for (i=0; i<iNumLayers+1; ++i)
140 u = double(i) / double(iNumLayers);
141 for (j=0; j<iNumColumns+1; ++j)
143 v = double(j) / double(iNumColumns);
144 P1 = Left[i] + (Right[i] - Left[i])*v;
145 P2 = Bottom[j] + (Top[j] - Bottom[j])*u;
163 P = P1 * w1 + P2 * w2;
167 for (i=0; i<iNumLayers; ++i)
169 for (j=0; j<iNumColumns; ++j)
173 if ((i==0 || i==iNumLayers-1) && (j==0 || j==iNumColumns-1))
177 Indices.push_back((j+0)+(i+0)*(iNumColumns+1));
178 if (i!=0 || j!=iNumColumns-1)
179 Indices.push_back((j+1)+(i+0)*(iNumColumns+1));
180 if (i!=iNumLayers-1 || j!=iNumColumns-1)
181 Indices.push_back((j+1)+(i+1)*(iNumColumns+1));
182 if (i!=iNumLayers-1 || j!=0)
183 Indices.push_back((j+0)+(i+1)*(iNumColumns+1));
194 bool bSurfaceNodes =
true;
198 for ( j = 1; j < iNumColumns; ++j )
200 Indices.push_back(j);
202 for ( i = 1; i < iNumLayers; ++i )
204 Indices.push_back( iNumColumns + i * (iNumColumns+1) );
206 for ( j = iNumColumns-1; j > 0; --j )
208 Indices.push_back( j + iNumLayers * (iNumColumns+1) );
210 for ( i = iNumLayers-1; i > 0; --i )
212 Indices.push_back( i * (iNumColumns+1) );
214 Indices.push_back( Indices[0] );
222 assert(iRemoved == 4);
234 p2 = Section[Section.size()/2];
236 double dAngle = atan2( dp.
y, dp.
x );
238 vector<XY> RotatedSection;
239 for (
int i = 1; i <= (int)Section.size()/4+1; ++i )
242 RotPoint.
x = Section[i].x*cos(dAngle) + Section[i].y*sin(dAngle);
243 RotPoint.
y = Section[i].y*cos(dAngle) - Section[i].x*sin(dAngle);
244 RotatedSection.push_back(RotPoint);
251 vector<XY>::iterator itRotatedSection;
253 for ( i = 0; i < (int)RotatedSection.size()-1; ++i )
255 P1 = RotatedSection[i];
256 P2 = RotatedSection[i+1];
258 if (abs(DP.
x) > abs(DP.
y))
270 if (Section.size() % 2 != 0)
273 TGERROR(
"Unable to create section mesh, the number of sections points specified is odd: " << Section.size());
277 int iNumColumns = Section.size()/2;
281 for (i=0; i<(int)Section.size(); ++i)
288 for (j=0; j<iNumColumns; ++j)
294 Indices.push_back(0);
295 Indices.push_back(1);
296 Indices.push_back(Section.size()-1);
299 else if (j==iNumColumns-1)
303 Indices.push_back(iNumColumns-1);
304 Indices.push_back(iNumColumns);
305 Indices.push_back(iNumColumns+1);
312 Indices.push_back(j);
313 Indices.push_back(j+1);
314 Indices.push_back(Section.size()-j-1);
315 Indices.push_back(Section.size()-j);
320 bool bSurfaceNodes =
true;
324 for ( j = 0; j < (int)Section.size(); ++j )
326 Indices.push_back(j);
328 Indices.push_back(Indices[0]);
#define TGERROR(MESSAGE)
Macros used to report the file name and line number to the TexGenError and TexGenLog functions.
bool AddElement(ELEMENT_TYPE Type, const vector< int > &Indices)
Add an element to the mesh of given type with node number checking.
const int AddNode(XYZ Node)
Append a node to the list of nodes, the integer returns the index of the node
int RemoveUnreferencedNodes()
Remove nodes that are not referenced by any elements.
const list< int > & GetIndices(ELEMENT_TYPE ElemType) const
Get the element indices of a given element type.
void SetNode(int iIndex, XYZ Node)
Set the node at given index.
void SetNumNodes(int NumNodes)
Resize the vector size.
void Clear()
Empty mesh nodes and indices.
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.
bool CreateSingleLayerMesh(const vector< XY > &Section) const
bool CreateMesh(const vector< XY > &Section) const
Create a mesh out of given list of points representing the edge of the section.
void SetNumLayers(int iNum)
void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType) const
Used for saving data to XML.
~CSectionMeshRectangular(void)
CSectionMeshRectangular(int iNumLayers=-1, bool bTriangleCorners=true)
int CalculateNumberofLayers(const vector< XY > &Section) const
Namespace containing a series of customised math operations not found in the standard c++ library.
double GetLength(const XYZ &Point1, const XYZ &Point2)
Get the length between two points.
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 2D space.
Struct for representing points in 3D space.