TexGen
InterpolationBezier.cpp
Go to the documentation of this file.
1/*=============================================================================
2TexGen: Geometric textile modeller.
3Copyright (C) 2006 Martin Sherburn
4
5This program is free software; you can redistribute it and/or
6modify it under the terms of the GNU General Public License
7as published by the Free Software Foundation; either version 2
8of the License, or (at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18=============================================================================*/
19
20#include "PrecompiledHeaders.h"
21#include "InterpolationBezier.h"
22
23using namespace TexGen;
24CInterpolationBezier::CInterpolationBezier(bool bPeriodic, bool bForceInPlaneTangent, bool bForceMasterNodeTangent)
25: CInterpolation(bPeriodic, bForceInPlaneTangent, bForceMasterNodeTangent)
26{
27}
28
30{
31}
32
34: CInterpolation(Element)
35{
36 // TODO: IMPLEMENT ME
37}
38
39/*
40void CInterpolationBezier::PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType) const
41{
42}*/
43
44CSlaveNode CInterpolationBezier::GetNode(const vector<CNode> &MasterNodes, int iIndex, double t) const
45{
46 assert(iIndex >= 0 && iIndex < int(MasterNodes.size()-1));
47 // Errors may occur here if the Initialise function was not called before
48 // calling this function. For performance reasons it is necessary to call
49 // initialise once at the start before making calls to this function
50 if ( m_Tangents.empty() )
51 Initialise( MasterNodes );
52 assert(m_Tangents.size() == MasterNodes.size());
53
54 const CNode &Node1 = MasterNodes[iIndex];
55 const CNode &Node2 = MasterNodes[iIndex+1];
56
57 XYZ P1, P2, P3, P4;
58 XYZ T1, T2, U1, U2;
59 XYZ SlaveNodePos, SlaveTangent;
60 double dLength;
61
62 // This is a rather inefficient way of doing things, these points could be calculated
63 // in the initialise function (optimise if this becomes an issue)
64 P1 = Node1.GetPosition();
65 P4 = Node2.GetPosition();
66 T1 = m_Tangents[iIndex];
67 T2 = m_Tangents[iIndex+1];
68 dLength = ::GetLength(P1, P4)/3;
69 P2 = P1 + T1 * dLength;
70 P3 = P4 - T2 * dLength;
71/*
72// int iIters = 0;
73 double dMidLength, dMiddiff;
74 do
75 {
76 P2 = P1 + T1 * dLength;
77 P3 = P4 - T2 * dLength;
78 dMidLength = GetLength(P2, P3);
79 dMiddiff = dMidLength - dLength;
80 dLength += dMiddiff/3;
81// ++iIters;
82 } while(dMiddiff > 1e-12);
83// cout << "Frac: " << dLength/::GetLength(P1, P4) << ", Iters: " << iIters << endl;
84*/
85
86 SlaveNodePos = CalculateBezierPoint(P1, P2, P3, P4, t);
87 SlaveTangent = CalculateBezierTangent(P1, P2, P3, P4, t);
88
90 SlaveTangent.z = 0;
91
92 Normalise(SlaveTangent);
93
94 CSlaveNode NewNode(SlaveNodePos, SlaveTangent, XYZ());
95
96 InterpolateUp(Node1, Node2, NewNode, t);
97 InterpolateAngle(Node1, Node2, NewNode, t);
98
99 NewNode.SetIndex(iIndex);
100 NewNode.SetT(t);
101
102 return NewNode;
103}
104
105void CInterpolationBezier::Initialise(const vector<CNode> &MasterNodes) const
106{
108}
109
CSlaveNode GetNode(const vector< CNode > &MasterNodes, int iIndex, double t) const
Get a node from parametric function where t is specified.
CInterpolationBezier(bool bPeriodic=true, bool bForceInPlaneTangent=false, bool bForceMasterNodeTangent=false)
void Initialise(const vector< CNode > &MasterNodes) const
Calculate the node tangents (use node tangents of they exist) and store them in m_Tangents.
Abstract base class for describing the yarn path interpolations.
Definition: Interpolation.h:33
static void InterpolateUp(const CNode &Node1, const CNode &Node2, CSlaveNode &SlaveNode, double t)
static void InterpolateAngle(const CNode &Node1, const CNode &Node2, CSlaveNode &SlaveNode, double t)
void CalculateNodeCoordinateSystem(const vector< CNode > &MasterNodes, vector< XYZ > &Tangents) const
Represents a point on the centreline of a yarn.
Definition: Node.h:28
XYZ GetPosition() const
Definition: Node.h:57
A derivation of the CNode class which contains data specific to slave nodes such as sections.
Definition: SlaveNode.h:30
void SetT(double t)
Definition: SlaveNode.h:71
void SetIndex(int iIndex)
Definition: SlaveNode.h:73
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.
Definition: mymath.h:540
T CalculateBezierTangent(T p1, T p2, T p3, T p4, double mu)
Definition: mymath.h:1183
WXYZ & Normalise(WXYZ &Quaternion)
Normalise the quaternion and return it.
Definition: mymath.h:609
T CalculateBezierPoint(T p1, T p2, T p3, T p4, double mu)
Definition: mymath.h:1175
Struct for representing points in 3D space.
Definition: mymath.h:56
double z
Definition: mymath.h:57