TexGen
SlaveNode.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 "SlaveNode.h"
22using namespace TexGen;
23
24CSlaveNode::CSlaveNode(XYZ Position, XYZ Tangent, XYZ Up)
25: CNode(Position, Tangent, Up)
26,m_T(0)
27,m_iIndex(0)
28,m_2DSectionMesh(NULL)
29,m_SectionMesh(NULL)
30{
31}
32
34{
35 if ( m_2DSectionMesh != NULL )
36 delete m_2DSectionMesh;
37 if ( m_SectionMesh != NULL )
38 delete m_SectionMesh;
39}
40
41CSlaveNode::CSlaveNode(TiXmlElement &Element)
42: CNode(Element)
43,m_2DSectionMesh(NULL)
44,m_SectionMesh(NULL)
45{
46 Element.Attribute("T", &m_T);
47 Element.Attribute("Index", &m_iIndex);
48 FOR_EACH_TIXMLELEMENT(pSectionPoint2D, Element, "SectionPoint2D")
49 {
50 m_2DSectionPoints.push_back(valueify<XY>(pSectionPoint2D->Attribute("value")));
51 }
52 FOR_EACH_TIXMLELEMENT(pSectionPoint, Element, "SectionPoint")
53 {
54 m_SectionPoints.push_back(valueify<XYZ>(pSectionPoint->Attribute("value")));
55 }
56 /*TiXmlElement *pSectionMesh2D = Element.FirstChildElement("SectionMesh2D");
57 if (pSectionMesh2D)
58 {
59 m_2DSectionMesh = CMesh(*pSectionMesh2D);
60 }
61 TiXmlElement *pSectionMesh = Element.FirstChildElement("SectionMesh");
62 if (pSectionMesh2D)
63 {
64 m_SectionMesh = CMesh(*pSectionMesh);
65 }*/
66}
67
68void CSlaveNode::PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType) const
69{
70 CNode::PopulateTiXmlElement(Element, OutputType);
71 Element.SetAttribute("T", stringify(m_T));
72 Element.SetAttribute("Index", m_iIndex);
73 vector<XY>::const_iterator itXY;
74 for (itXY = m_2DSectionPoints.begin(); itXY != m_2DSectionPoints.end(); ++itXY)
75 {
76 TiXmlElement SectionPoint2D("SectionPoint2D");
77 SectionPoint2D.SetAttribute("value", stringify(*itXY));
78 Element.InsertEndChild(SectionPoint2D);
79 }
80 vector<XYZ>::const_iterator itXYZ;
81 for (itXYZ = m_SectionPoints.begin(); itXYZ != m_SectionPoints.end(); ++itXYZ)
82 {
83 TiXmlElement SectionPoint("SectionPoint");
84 SectionPoint.SetAttribute("value", stringify(*itXYZ));
85 Element.InsertEndChild(SectionPoint);
86 }
87 /*TiXmlElement SectionMesh2D("SectionMesh2D");
88 m_2DSectionMesh.PopulateTiXmlElement(SectionMesh2D, OutputType);
89 Element.InsertEndChild(SectionMesh2D);
90 TiXmlElement SectionMesh("SectionMesh");
91 m_SectionMesh.PopulateTiXmlElement(SectionMesh, OutputType);
92 Element.InsertEndChild(SectionMesh);*/
93}
94
95void CSlaveNode::UpdateSectionPoints(const vector<XY> *p2DSectionPoints)
96{
97 if (p2DSectionPoints)
98 m_2DSectionPoints = *p2DSectionPoints;
99 // Clear any existing section before creating the new one
100 m_SectionPoints.clear();
101
102 vector<XY>::iterator it2DSectionPoint;
103 XYZ Pos;
104 XYZ Side = GetSide();
105 for (it2DSectionPoint = m_2DSectionPoints.begin(); it2DSectionPoint != m_2DSectionPoints.end(); ++it2DSectionPoint)
106 {
107 // Rotate the 2d section point to the global 3d coordinate system
108 Pos = Side * it2DSectionPoint->x;
109 Pos += m_Up * it2DSectionPoint->y;
110 // Translate the point to its global position
111 Pos += m_Position;
112 // Add the new 3d point to the list
113 m_SectionPoints.push_back(Pos);
114 }
115}
116
117XYZ CSlaveNode::GetPointOnSection(const XY &p2DSectionPoint)
118{
119 vector<XY>::const_iterator it2DSectionPoint;
120 XYZ Pos;
121 XYZ Side = GetSide();
122
123 // Rotate the 2d section point to the global 3d coordinate system
124 Pos = Side * p2DSectionPoint.x;
125 Pos += m_Up * p2DSectionPoint.y;
126 // Translate the point to its global position
127 Pos += m_Position;
128 // Add the new 3d point to the list
129 return Pos;
130}
131
132void CSlaveNode::UpdateSectionMesh(const CMesh *p2DSectionMesh)
133{
134 if (p2DSectionMesh)
135 {
136 if ( m_2DSectionMesh == NULL )
138 else
140 *m_2DSectionMesh = *p2DSectionMesh;
141 }
142 // Clear any existing section mesh before creating the new one
143 if ( m_SectionMesh == NULL )
144 m_SectionMesh = new CMesh;
145 else
147
148 vector<XYZ>::iterator itNode;
149 XYZ Pos;
150 XYZ Side = GetSide();
151 vector<XYZ> MeshNodes2D = m_2DSectionMesh->GetNodes();
152
153 for (itNode = MeshNodes2D.begin(); itNode != MeshNodes2D.end(); ++itNode)
154 {
155 // Rotate the 2d section point to the global 3d coordinate system
156 Pos = Side * itNode->x;
157 Pos += m_Up * itNode->y;
158 // Translate the point to its global position
159 Pos += m_Position;
161 }
162 int i;
163 for (i=0; i<CMesh::NUM_ELEMENT_TYPES; ++i)
164 {
166 }
167}
168
170{
171 CNode::Rotate(Rotation);
172 vector<XYZ>::iterator itSectionPoint;
173 for (itSectionPoint = m_SectionPoints.begin(); itSectionPoint != m_SectionPoints.end(); ++itSectionPoint)
174 {
175 (*itSectionPoint) = Rotation * (*itSectionPoint);
176 }
177 m_SectionMesh->Rotate(Rotation);
178}
179
181{
182 CNode::Translate(Vector);
183 vector<XYZ>::iterator itSectionPoint;
184 for (itSectionPoint = m_SectionPoints.begin(); itSectionPoint != m_SectionPoints.end(); ++itSectionPoint)
185 {
186 (*itSectionPoint) += Vector;
187 }
188 m_SectionMesh->Translate(Vector);
189}
190
191
192
193
194
195
196
197
198
199
200
201
#define FOR_EACH_TIXMLELEMENT(CHILDELEMENT, PARENTELEMENT, ELEMENTNAME)
Macro to enable looping over tinyxml easier.
Definition: Misc.h:45
#define NULL
Definition: ShinyConfig.h:50
Defines the nodes and elements of a surface or volume mesh.
Definition: Mesh.h:58
const vector< XYZ > & GetNodes() const
Get a const reference to the nodes.
Definition: Mesh.cpp:2656
const int AddNode(XYZ Node)
Append a node to the list of nodes, the integer returns the index of the node
Definition: Mesh.cpp:2624
void Translate(XYZ Vector)
Translate whole mesh by given vector.
Definition: Mesh.cpp:1139
const list< int > & GetIndices(ELEMENT_TYPE ElemType) const
Get the element indices of a given element type.
Definition: Mesh.cpp:2671
ELEMENT_TYPE
Each element type is represented by a unique integer value.
Definition: Mesh.h:66
@ NUM_ELEMENT_TYPES
Definition: Mesh.h:77
void Clear()
Empty mesh nodes and indices.
Definition: Mesh.cpp:1448
void Rotate(WXYZ Rotation, XYZ Origin=XYZ(0, 0, 0))
Rotate the whole mesh by given quaternion.
Definition: Mesh.cpp:1148
Represents a point on the centreline of a yarn.
Definition: Node.h:28
XYZ m_Up
Unit vector which represents the up direction (must be perpendicular to m_Tangent)
Definition: Node.h:73
virtual void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType) const
Used for saving data to XML.
Definition: Node.cpp:51
virtual void Translate(XYZ Vector)
Translate the Node by given vector.
Definition: Node.cpp:66
XYZ m_Position
Coordinates representing the position of the node.
Definition: Node.h:69
XYZ GetSide() const
Get the side vector.
Definition: Node.cpp:84
virtual void Rotate(WXYZ Rotation, XYZ Origin=XYZ(0, 0, 0))
Rotate the Node by given quaternion.
Definition: Node.cpp:59
void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType) const
Used for saving data to XML.
Definition: SlaveNode.cpp:68
void UpdateSectionMesh(const CMesh *p2DSectionMesh=NULL)
Populate m_SectionMesh from m_2DSectionMesh, Setting m_2DSectionMesh at the same time.
Definition: SlaveNode.cpp:132
XYZ GetPointOnSection(const XY &p2DSectionPoints)
Calculate the 3D coordinates of a point on the cross-section.
Definition: SlaveNode.cpp:117
CMesh * m_SectionMesh
Section mesh in 3D.
Definition: SlaveNode.h:92
CMesh * m_2DSectionMesh
Section mesh in 2D.
Definition: SlaveNode.h:90
vector< XYZ > m_SectionPoints
Coordinates of the cross-section edge points in 3D.
Definition: SlaveNode.h:88
double m_T
T is the parameter which varies from 0 to 1 which tells us how far along the link the node is.
Definition: SlaveNode.h:94
void Rotate(WXYZ Rotation)
Rotate the Node by given quaternion.
Definition: SlaveNode.cpp:169
vector< XY > m_2DSectionPoints
Coordinates of the cross-section edge points in 2D.
Definition: SlaveNode.h:86
CSlaveNode(XYZ Position=XYZ(), XYZ Tangent=XYZ(), XYZ Up=XYZ())
Definition: SlaveNode.cpp:24
int m_iIndex
Index which determines between which master nodes this slave node lies, varies from 0 to number of no...
Definition: SlaveNode.h:96
void Translate(XYZ Vector)
Translate the Node by given vector.
Definition: SlaveNode.cpp:180
void UpdateSectionPoints(const vector< XY > *p2DSectionPoints=NULL)
Populate m_SectionPoints from m_2DSectionPoints, Setting m_2DSectionPoints at the same time.
Definition: SlaveNode.cpp:95
Namespace containing a series of customised math operations not found in the standard c++ library.
OUTPUT_TYPE
Definition: Misc.h:105
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.
Definition: Misc.h:50
Struct for representing a quaternion.
Definition: mymath.h:38
Struct for representing points in 2D space.
Definition: mymath.h:103
double x
Definition: mymath.h:104
double y
Definition: mymath.h:104
Struct for representing points in 3D space.
Definition: mymath.h:56
double x
Definition: mymath.h:57
double y
Definition: mymath.h:57