36 TiXmlElement* pMesh = Element.FirstChildElement(
"Mesh");
45 Element.SetAttribute(
"type",
GetType());
48 TiXmlElement Mesh(
"Mesh");
50 Element.InsertEndChild(Mesh);
61 vector<pair<int, int> > IntRepeatLimits;
62 vector<pair<double, double> >::const_iterator itRepeatLimits;
63 for (itRepeatLimits = RepeatLimits.begin(); itRepeatLimits != RepeatLimits.end(); ++itRepeatLimits)
65 IntRepeatLimits.push_back(pair<int, int>((
int)ceil(itRepeatLimits->first), (
int)floor(itRepeatLimits->second)));
67 return IntRepeatLimits;
78 pair<XYZ, XYZ> MeshAABB = Mesh.
GetAABB();
80 return BoundingBoxIntersect(DomainAABB.first, DomainAABB.second, MeshAABB.first, MeshAABB.second);
85 vector<XYZ> AllRepeats;
86 vector<XYZ> FiniteRepeats;
87 const vector<XYZ> &YarnRepeats = Yarn.
GetRepeats();
89 vector<XYZ>::const_iterator itRepeat;
90 vector<pair<int, int> >::const_iterator itLimits;
91 AllRepeats.push_back(
XYZ());
92 for (itRepeat = YarnRepeats.begin(), itLimits = RepeatLimits.begin(); itRepeat != YarnRepeats.end() && itLimits != RepeatLimits.end(); ++itRepeat, ++itLimits)
94 CopyToRange(AllRepeats, *itRepeat, itLimits->first, itLimits->second);
98 for (itRepeat = AllRepeats.begin(); itRepeat != AllRepeats.end(); ++itRepeat)
100 CMesh RepeatedMesh = Mesh;
103 FiniteRepeats.push_back(*itRepeat);
105 return FiniteRepeats;
110 pair<double, double> DomainLimits = make_pair(0.0, 0.0);
111 pair<double, double> MeshLimits = make_pair(0.0, 0.0);
112 pair<double, double> Limits = make_pair(0.0, 0.0);
114 vector<XYZ>::const_iterator itNode;
117 double dRepeatLength =
GetLength(RepeatVector);
118 RepeatVector /= dRepeatLength;
120 for (itNode = MeshNodes.begin(); itNode != MeshNodes.end(); ++itNode)
122 dPointDist =
DotProduct(*itNode, RepeatVector);
124 if (itNode == MeshNodes.begin())
125 DomainLimits = make_pair(dPointDist, dPointDist);
126 else if (DomainLimits.first > dPointDist)
127 DomainLimits.first = dPointDist;
128 else if (DomainLimits.second < dPointDist)
129 DomainLimits.second = dPointDist;
134 dPointDist =
DotProduct(*itNode, RepeatVector);
137 MeshLimits = make_pair(dPointDist, dPointDist);
138 else if (MeshLimits.first > dPointDist)
139 MeshLimits.first = dPointDist;
140 else if (MeshLimits.second < dPointDist)
141 MeshLimits.second = dPointDist;
143 Limits.first = (DomainLimits.first - MeshLimits.second) / dRepeatLength;
144 Limits.second = (DomainLimits.second - MeshLimits.first) / dRepeatLength;
152 vector<pair<double, double> > AllRepeatLimitsPrevious;
153 vector<pair<double, double> > AllRepeatLimits;
154 AllRepeatLimits.resize(Yarn.
GetRepeats().size(), pair<double, double>(0, 0));
155 vector<XYZ>::const_iterator itRepeat;
156 vector<PLANE>::const_iterator itPlane;
158 int iIterations = 0, iMaxIterations = 100;
168 return vector<pair<int, int> >();
174 AllRepeatLimitsPrevious = AllRepeatLimits;
176 for (itRepeat = Yarn.
GetRepeats().begin(), i = 0; itRepeat != Yarn.
GetRepeats().end(); ++itRepeat, ++i)
178 AllRepeatLimits[i] = pair<double, double>(0, 0);
183 TGERROR(
"Unable to calculate repeat limits");
188 AllRepeatLimits[i] =
GetLimits(*itRepeat, Mesh);
192 }
while (AllRepeatLimitsPrevious != AllRepeatLimits && iIterations < iMaxIterations);
193 if (iIterations >= iMaxIterations)
195 TGERROR(
"Unable to find yarn repeat limits, stopped after " << iIterations <<
" iterations");
196 return vector<pair<int, int> >();
#define TGERROR(MESSAGE)
Macros used to report the file name and line number to the TexGenError and TexGenLog functions.
CDomainPrism * GetPrismDomain()
pair< double, double > GetLimits(XYZ RepeatVector, const CMesh &Mesh) const
Get the limits for a single given repeat vector and surface mesh.
virtual string GetType() const =0
Derived class should return the class name.
virtual double GetVolume() const
Get the volume of the domain.
virtual void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType=OUTPUT_STANDARD) const
Used for saving data to XML.
bool MeshIntersectsDomain(const CMesh &Mesh) const
Determine if a mesh intersects with the domain.
CMesh m_Mesh
A mesh representing the domain as a surface mesh.
vector< XYZ > GetTranslations(const CYarn &Yarn) const
Get the translation vectors necessary to fully fill the domain.
vector< pair< int, int > > GetRepeatLimits(const CYarn &Yarn) const
static vector< pair< int, int > > ConvertLimitsToInt(const vector< pair< double, double > > &RepeatLimits)
Domain implementation described using extrusion of a polygon outline.
Defines the nodes and elements of a surface or volume mesh.
const vector< XYZ > & GetNodes() const
Get a const reference to the nodes.
void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType) const
Used for saving data to XML.
void Translate(XYZ Vector)
Translate whole mesh by given vector.
double CalculateVolume() const
Calculate the volume of the mesh.
pair< XYZ, XYZ > GetAABB(double dGrowDistance=0) const
Get an axis aligned bounding box for the mesh.
vector< XYZ >::const_iterator NodesBegin() const
vector< XYZ >::const_iterator NodesEnd() const
Represents a yarn consisting of master nodes, section and interpolation function.
const vector< XYZ > & GetRepeats() const
bool AddAABBToMesh(CMesh &Mesh) const
Add the axis aligned bounding box of the yarn to the Mesh.
Namespace containing a series of customised math operations not found in the standard c++ library.
void CopyToRange(vector< XYZ > &Offsets, XYZ Vector, int iLowerLimit, int iUpperLimit)
double GetLength(const XYZ &Point1, const XYZ &Point2)
Get the length between two points.
bool BoundingBoxIntersect(const XYZ &BBox1Min, const XYZ &BBox1Max, const XYZ &BBox2Min, const XYZ &BBox2Max, double dTolerance=0)
Find if two AABBs intersect with given tolerance.
double DotProduct(const XYZ &left, const XYZ &right)
Get the dot product of two vectors.
Struct for representing points in 3D space.