29CInterpolation::CInterpolation(
bool bPeriodic,
bool bForceInPlaneTangent,
bool bForceMasterNodeTangent)
30: m_bPeriodic(bPeriodic)
31, m_bForceInPlaneTangent(bForceInPlaneTangent)
32, m_bForceMasterNodeTangent(bForceMasterNodeTangent)
42, m_bForceInPlaneTangent(false)
43, m_bForceMasterNodeTangent(false)
45 const string* pPeriodic = Element.Attribute(
string(
"Periodic"));
48 const string* pForceInPlaneTangent = Element.Attribute(
string(
"ForceInPlaneTangent"));
49 if (pForceInPlaneTangent)
51 const string* pForceMasterNodeTangent = Element.Attribute(
string(
"ForceMasterNodeTangent"));
52 if (pForceMasterNodeTangent)
61 Element.SetAttribute(
"type",
GetType());
66 const string* pType = Element.Attribute(
string(
"type"));
69 if (*pType ==
"CInterpolationBezier")
71 else if (*pType ==
"CInterpolationCubic")
73 else if (*pType ==
"CInterpolationAdjusted")
75 else if (*pType ==
"CInterpolationLinear")
92 SlaveUp = U1 + (U2-U1) * t;
94 SlaveNode.
SetUp(SlaveUp);
100 double A1, A2, SlaveA;
103 if ( A1 == 0.0 && A2 == 0.0 )
106 SlaveA = A1 + (A2-A1) * t;
134 int iNumSections = (int)MasterNodes.size()-1;
138 if (iIndex >= iNumSections)
140 iIndex = iNumSections-1;
143 return GetNode(MasterNodes, iIndex, t);
148 vector<CSlaveNode> SlaveNodes;
160 for (i=0; i<iNumPoints; ++i)
162 t = double(i)/double(iNumPoints-1);
163 SlaveNodes.push_back(
GetNode(MasterNodes, t));
171 TGERROR(
"Unable to create equispaced slave nodes, not enough points: " << iNumPoints);
178 vector<double> SectionLengths;
180 int iNumNodes = (int)MasterNodes.size();
182 for (i=0; i<iNumNodes-1; ++i)
184 dLength =
GetLength(MasterNodes[i+1].GetPosition() - MasterNodes[i].GetPosition());
185 SectionLengths.push_back(dLength);
187 double dTotalLength = accumulate(SectionLengths.begin(), SectionLengths.end(), 0.0);
193 vector<double> LValues;
194 vector<double> TValues;
197 double dt = 1/double(iNumNodes-1);
198 for (i=0, t=0, L=0; i<iNumNodes; ++i, t+=dt)
200 TValues.push_back(t);
201 LValues.push_back(L);
203 L+=SectionLengths[i];
208 double dl = dTotalLength/double(iNumPoints-1);
217 SectionLengths.clear();
218 SectionLengths.resize(iNumNodes-1);
221 for (i=0; i<iNumNodes-1; ++i)
223 SectionLengths[i] = 0;
224 PrevPos = MasterNodes[i].GetPosition();
225 for (j=0; j<int(SlaveNodes.size()); ++j)
227 if (SlaveNodes[j].GetIndex() == i)
229 SectionLengths[i] +=
GetLength(PrevPos, SlaveNodes[j].GetPosition());
230 PrevPos = SlaveNodes[j].GetPosition();
233 SectionLengths[i] +=
GetLength(PrevPos, MasterNodes[i+1].GetPosition());
235 double dNewTotalLength = accumulate(SectionLengths.begin(), SectionLengths.end(), 0.0);
238 if ( fabs( (dNewTotalLength - dTotalLength)/dTotalLength ) > 0.05 )
243 for (i=0, t=0, L=0; i<iNumNodes; ++i, t+=dt)
245 TValues.push_back(t);
246 LValues.push_back(L);
248 L+=SectionLengths[i];
253 double dl = dNewTotalLength/double(iNumPoints-1);
263 int i, iNumNodes = (int)MasterNodes.size();
264 Tangents.resize(iNumNodes,
XYZ());
268 TGERROR(
"Unable to calculate node coordinate system, not enough master nodes specified");
273 XYZ PrevPos, NextPos;
275 YarnRepeat = MasterNodes[iNumNodes-1].GetPosition() - MasterNodes[0].GetPosition();
276 for (i=0; i<iNumNodes; ++i)
283 PrevPos = MasterNodes[iNumNodes-2].GetPosition() - YarnRepeat;
285 PrevPos = MasterNodes[0].GetPosition();
288 PrevPos = MasterNodes[i-1].GetPosition();
294 NextPos = MasterNodes[1].GetPosition() + YarnRepeat;
296 NextPos = MasterNodes[iNumNodes-1].GetPosition();
299 NextPos = MasterNodes[i+1].GetPosition();
302 Tangent = NextPos - PrevPos;
306 if (MasterNodes[i].GetTangent())
307 Tangents[i] = MasterNodes[i].GetTangent();
309 Tangents[i] = Tangent;
318 vector<CSlaveNode> SlaveNodes;
321 for (i=0, L=0.0; i<iNumPoints; ++i, L += dL)
328 else if (L > LValues[iNumNodes-1])
334 while ( j < iNumNodes-1 )
336 if (LValues[j] <= L && L <= LValues[j+1])
338 u = (L-LValues[j])/(LValues[j+1]-LValues[j]);
339 t = TValues[j] + u*(TValues[j+1]-TValues[j]);
346 SlaveNodes.push_back(SlaveNode);
#define TGERROR(MESSAGE)
Macros used to report the file name and line number to the TexGenError and TexGenLog functions.
Bezier interpolation for yarn paths.
Bezier interpolation for yarn paths.
Cubic spline interpolation for yarn paths.
virtual string GetType() const =0
Derived class should return the class name.
static void InterpolateUp(const CNode &Node1, const CNode &Node2, CSlaveNode &SlaveNode, double t)
void CreateSlaveNodes(vector< CSlaveNode > &SlaveNodes, const vector< CNode > &MasterNodes, int iNumPoints) const
Create slave nodes with specified number of points between master nodes.
virtual void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType) const
Used for saving data to XML.
virtual void Initialise(const vector< CNode > &MasterNodes) const
virtual CSlaveNode GetNode(const vector< CNode > &MasterNodes, int iIndex, double t) const =0
Get a node from parametric function. Initialise should be called first.
static void InterpolateAngle(const CNode &Node1, const CNode &Node2, CSlaveNode &SlaveNode, double t)
vector< CSlaveNode > GetSlaveNodes(const vector< CNode > &MasterNodes, int iNumPoints, bool bEquiSpaced=true) const
Get a list of nodes along the centre line of the yarn.
virtual ~CInterpolation(void)
bool CreateEquiSpacedSlaveNodes(vector< CSlaveNode > &SlaveNodes, const vector< CNode > &MasterNodes, int iNumPoints) const
Create slave nodes equispaced with total specified number of points.
vector< CSlaveNode > CalcSlaveNodePositions(const vector< CNode > &MasterNodes, vector< double > &LValues, vector< double > &TValues, double dL, int iNumNodes, int iNumPoints) const
bool m_bForceInPlaneTangent
void CalculateNodeCoordinateSystem(const vector< CNode > &MasterNodes, vector< XYZ > &Tangents) const
static CObjectContainer< CInterpolation > CreateInterpolation(TiXmlElement &Element)
Create an interpolation from TiXmlElement.
bool m_bForceMasterNodeTangent
CInterpolation(bool bPeriodic, bool bForceInPlaneTangent, bool bForceMasterNodeTangent)
Bezier interpolation for yarn paths.
Represents a point on the centreline of a yarn.
void ProjectUp()
Project the Up vector such that it is perpendicular to the tangent.
void SetAngle(double Angle)
Object container to help handle memory management issues.
A derivation of the CNode class which contains data specific to slave nodes such as sections.
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.
WXYZ & Normalise(WXYZ &Quaternion)
Normalise the quaternion and return it.
Struct for representing points in 3D space.