39 m_bEquiSpaced = valueify<bool>(Element.Attribute(
"EquiSpaced"));
42 m_EdgePoints.push_back(valueify<XY>(pEdgePoint->Attribute(
"value")));
44 TiXmlElement *pSectionMesh = Element.FirstChildElement(
"SectionMesh");
53 Element.SetAttribute(
"type",
GetType());
56 TiXmlElement SectionMesh(
"SectionMesh");
58 Element.InsertEndChild(SectionMesh);
63 vector<XY>::const_iterator itPoint;
66 TiXmlElement EdgePoint(
"EdgePoint");
67 EdgePoint.SetAttribute(
"value",
stringify(*itPoint));
68 Element.InsertEndChild(EdgePoint);
80 const string* pType = Element.Attribute(
string(
"type"));
83 if (*pType ==
"CSectionBezier")
85 else if (*pType ==
"CSectionEllipse")
87 else if (*pType ==
"CSectionHybrid")
89 else if (*pType ==
"CSectionLenticular")
91 else if (*pType ==
"CSectionPolygon")
93 else if (*pType ==
"CSectionPowerEllipse")
95 else if (*pType ==
"CSectionRotated")
97 else if (*pType ==
"CSectionScaled")
99 else if (*pType ==
"CSectionRectangle")
112 static CMesh EmptyMesh;
115 const vector<XY> &Section =
GetPoints(iNumPoints, bEquiSpaced);
136 for (i=0; i<iNumPoints; ++i)
138 t = (double)i/(
double)iNumPoints;
147 int iMaxIterations = 1000;
148 double dStdDevTolerance = 1E-12;
153 int IncreaseStdDevCount = 0;
154 double PrevStdDev = 0.0;
155 double MinDouble = std::numeric_limits<double>::min();
156 vector<double> dLengths;
157 dLengths.resize(iNumPoints);
163 vector<double> Spacing;
164 t = 1/double(iNumPoints);
165 Spacing.resize(iNumPoints, t);
167 for (j=0; j<iMaxIterations; ++j)
170 for (i=0, t=0; i<iNumPoints; t+=Spacing[i], ++i)
176 for (i=0; i<iNumPoints; ++i)
179 if ( dLengths[i] < MinDouble )
182 TGERROR(
"Unable to create equispaced points, Length = " +
stringify(dLength) );
185 dAvgLength += dLengths[i];
187 dAvgLength /= iNumPoints;
192 for (i=0; i<iNumPoints; ++i)
194 dStdDev += (dLengths[i]-dAvgLength)*(dLengths[i]-dAvgLength);
195 Spacing[i] *= dAvgLength/dLengths[i];
197 dStdDev /= iNumPoints;
198 if (dStdDev > PrevStdDev )
199 ++IncreaseStdDevCount;
200 PrevStdDev = dStdDev;
202 if (dStdDev < dStdDevTolerance)
206 if ( IncreaseStdDevCount > 200 )
214 for (i=0; i<iNumPoints; ++i)
218 for (i=0; i<iNumPoints; ++i)
223 TGERROR(
"Unable to create equispaced section points, maximum iterations exceeded: " +
GetDefaultName());
246 if ( type ==
"CSectionMeshRectangular" )
252 else if ( type ==
"CSectionMeshRectangleSection" )
265 for (i=0; i<(int)Section.size(); ++i)
267 dArea += Section[i].x*Section[(i+1)%Section.size()].y - Section[(i+1)%Section.size()].x*Section[i].y;
276 double dCircumference = 0;
277 for (i=0; i<(int)Section.size(); ++i)
279 dCircumference +=
::GetLength(Section[i], Section[(i+1)%Section.size()]);
281 return dCircumference;
#define TGERROR(MESSAGE)
Macros used to report the file name and line number to the TexGenError and TexGenLog functions.
#define FOR_EACH_TIXMLELEMENT(CHILDELEMENT, PARENTELEMENT, ELEMENTNAME)
Macro to enable looping over tinyxml easier.
Defines the nodes and elements of a surface or volume mesh.
Object container to help handle memory management issues.
Section made up of bezier curves.
virtual void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType) const
Used for saving data to XML.
vector< XY > m_EdgePoints
List of 2d points creating the outline of the cross-section.
const CMesh & GetMesh(int iNumPoints, bool bEquiSpaced=true) const
friend class CSectionRotated
static CObjectContainer< CSection > CreateSection(TiXmlElement &Element)
Create a section from TiXmlElement.
void AssignSectionMesh(const CSectionMesh &SectionMesh)
Assign a mesh to the section.
bool m_bEquiSpaced
Keep this variable to determine whether the section was created with equidistant points or not.
virtual string GetType() const =0
Derived class should return the class name.
void SetSectionMeshLayers(int iNum)
Specify number of layers for associated section mesh.
static double GetArea(const vector< XY > &Section)
Get the area of a section.
virtual string GetDefaultName() const =0
Get the default name to assign to a section.
virtual const vector< XY > & GetPoints(int iNumPoints, bool bEquiSpaced=false) const
Get a section with given number of points on the perimeter.
virtual XY GetPoint(double t) const =0
Get a point lying on the perimeter correspending to parametric value t.
CObjectContainer< CSectionMesh > m_pSectionMesh
Pointer to a derived class of SectionMesh, this class is in charge of creating the section mesh.
friend class CSectionHybrid
friend class CSectionScaled
bool CreateEquiSpacedSection(int iNumPoints) const
Same as CreateSection except all the points will be spaced the same distance apart.
static double GetCircumference(const vector< XY > &Section)
Get the circumference of a section.
int GetSectionMeshLayers()
Get the number of layers for associated section mesh.
Abstract base class to create a 2D mesh of a section.
static CObjectContainer< CSectionMesh > CreateSectionMesh(TiXmlElement &Element)
Create a section from TiXmlElement.
Create a rectangular mesh, the number of layers can be specified or set as -1 for automatic determina...
Create a rectangular mesh, the number of layers can be specified or set as -1 for automatic determina...
Creates a polygonal section, where a list of points are given to form the closed polygon.
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.