TexGen
Yarn.h
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#pragma once
21
22#include "Node.h"
23#include "YarnSection.h"
24#include "YarnSectionConstant.h"
27#include "YarnSectionAdjusted.h"
28#include "Interpolation.h"
29#include "InterpolationBezier.h"
30#include "InterpolationCubic.h"
31#include "InterpolationLinear.h"
33#include "FibreDistribution.h"
36#include "Mesh.h"
37#include "Domain.h"
38#include "PropertiesYarn.h"
39
40namespace TexGen
41{
42 class CDomain;
43 class CTextile;
44
45 using namespace std;
46
49 {
50 friend class CTextile;
51 public:
52 CYarn(void);
53 CYarn(TiXmlElement &Element);
54 ~CYarn(void);
55
57 {
58 NONE = 0,
59 LINE = 1<<0,
60 SURFACE = 1<<1,
61 VOLUME = 1<<2,
62 ALL = LINE | SURFACE | VOLUME,
63 CENTRE_PLANE = 1<<3,
64 };
65
67 void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType);
68
70
73 void AddNode(const CNode &Node);
74
76
81 bool InsertNode(const CNode &Node, const CNode* pBefore);
82
84
89 bool InsertNode(const CNode &Node, int iIndex);
90
92
97 bool ReplaceNode(int iIndex, CNode NewNode);
98
100
104 bool DeleteNode(int iIndex);
105
107 const CNode* GetNode(int iIndex) const;
108
110 void SetNodes(const vector<CNode> &Nodes);
111
113
117 void AssignInterpolation(const CInterpolation &Interpolation);
118
120 void AssignFibreDistribution(const CFibreDistribution &Distribution);
121
123
127 void SetResolution(int iNumSlaveNodes, int iNumSectionPoints);
128
130
137 bool SetResolution(int iNumSectionPoints);
138
140
146 void SetEquiSpacedSectionMesh(bool bEquiSpacedSectionMesh);
147
149 void AssignSection(const CYarnSection &YarnSection);
150
152 void Rotate(WXYZ Rotation, XYZ Origin = XYZ(0,0,0));
153
155 void Translate(XYZ Vector);
156
158 bool AddAABBToMesh(CMesh &Mesh) const;
159
161 bool AddAABBToMesh(CMesh &Mesh, const vector<pair<int, int> > &RepeatLimits) const;
162
164 bool AddNodesToMesh(CMesh &Mesh) const;
165
167 bool AddPathToMesh(CMesh &Mesh) const;
168
170
174 bool AddSurfaceToMesh(CMesh &Mesh, bool bAddEndCaps = true) const;
175
177
182 bool AddSurfaceToMesh(CMesh &Mesh, const vector<pair<int, int> > &RepeatLimits) const;
183
185
190 bool AddSurfaceToMesh(CMesh &Mesh, const vector<XYZ> &TranslationVectors, bool bAddEndCaps = true) const;
191
193
198 bool AddSurfaceToMesh(CMesh &Mesh, const CDomain &Domain, bool bAddEndCaps = true, bool bFillGaps = true) const;
199
202
206 bool AddSurfaceToMesh( CMesh &Mesh, const CDomain &Domain, vector<CMesh> &DomainMeshes ) const;
207
209
212 bool AddVolumeToMesh(CMesh &Mesh) const;
213
215
220 bool AddVolumeToMesh(CMesh &Mesh, const vector<pair<int, int> > &RepeatLimits) const;
221
223
227 bool AddVolumeToMesh(CMesh &Mesh, const vector<XYZ> &TranslationVectors) const;
228
230
234 bool AddVolumeToMesh(CMesh &Mesh, const CDomain &Domain) const;
235
237
240 bool AddCentrePlaneToMesh(CMesh &Mesh) const;
241
243
247 bool AddCentrePlaneToMesh(CMesh &Mesh, const vector<XYZ> &TranslationVectors) const;
248
250
254 bool AddCentrePlaneToMesh(CMesh &Mesh, const CDomain &Domain) const;
255
257 void AddRepeat(XYZ Repeat);
258
260 void ClearRepeats();
261
263 void SetRepeats(const vector<XYZ> &Repeats);
264
266
270 bool RepeatMatchesEnds(XYZ Repeat) const;
271
273 void ClearMasterNodeOrientations();
274
276
281 bool PointInsideYarn( const XYZ &Point, XYZ *pTangent = NULL, XY *pLoc = NULL, double *pVolumeFraction = NULL, double* pDistanceToSurface = NULL, double dTolerance = 1e-9, XYZ *pOrientation = NULL, XYZ *pUp = NULL, bool bSurface = false ) const;
282
284
295 bool PointInsideYarn(const XYZ &Point, const vector<XYZ> &Translations, XYZ *pTangent = NULL, XY* pLoc = NULL, double* pVolumeFraction = NULL, double* pDistanceToSurface = NULL, double dTolerance = 1e-9, XYZ *pOrientation = NULL, XYZ *pUp = NULL, bool bSurface = false) const;
296
298
303 bool FindPlaneContainingPoint( const XYZ &Point, double &u, double dTolerance, int iSeg) const;
304
306
314 double FindClosestSurfacePoint(const XYZ &Point, XYZ &SurfacePoint, int iNumSectionPoints, double dTolerance = 1e-9);
315
317
326 bool FindClosestSurfacePoint(const XYZ &Point, const vector<XYZ> &Translations, XYZ &SurfacePoint, int iNumSectionPoints, double dTolerance = 1e-9);
327
329
336 void StraightenYarn(double dStraightness = 1);
337
339 pair<XYZ, XYZ> GetAABB() const;
340
342 pair<XYZ, XYZ> GetSectionAABB(int iIndex) const;
343
345
348 double GetRawYarnLength() const;
349
351
354 double GetRawYarnSectionLength(int iIndex) const;
355
357
360 double GetRawYarnVolume() const;
361
363
368 double GetRawRepeatArea() const;
369
371 vector<double> GetYarnSectionLengths() const;
372
374
380 const vector<CSlaveNode> &GetSlaveNodes(BUILD_TYPE Usage) const;
381
382
384
389 double GetRealYarnLength(string Units = "m") const;
390
392
397 double GetYarnLengthPerUnitArea(string Units = "/m") const;
398
400
405 double GetRealYarnVolume(string Units = "m^3") const;
406
408
415 double GetYarnVolumePerUnitArea(string Units = "m") const;
416
421 double GetFibreVolume(string Units = "m^3") const;
422
428 double GetFibreVolumePerUnitArea(string Units = "m") const;
429
434 double GetFibreYarnVolumeFraction() const;
435
437 int GetNumSectionPoints() const { return m_iNumSectionPoints; }
438
440 int GetNumSlaveNodes() const { return m_iNumSlaveNodes; }
441
444 bool ConvertToInterpNodes();
445
446 // Accessor methods
447 const vector<CNode> &GetMasterNodes() const { return m_MasterNodes; }
448 const vector<XYZ> &GetRepeats() const { return m_Repeats; }
449 const CYarnSection* GetYarnSection() const { return m_pYarnSection; }
450 const CInterpolation* GetInterpolation() const { return m_pInterpolation; }
451 const CFibreDistribution* GetFibreDistribution() const { return m_pFibreDistribution;}
452 int GetNumNodes() const { return (int)m_MasterNodes.size(); }
453 vector<double> GetSectionLengths() const { return m_SectionLengths; }
454
455 CMesh::ELEMENT_TYPE GetMeshPoint( CMesh &Mesh, const XY &Point, int &Index ) const;
456
457 //int GetMeshPoint( const XY &Point, int& Index );
458
459 protected:
461
479 bool BuildYarnIfNeeded(int iBuildType) const;
480
481 bool BuildSlaveNodes() const;
482 bool BuildSections() const;
483 bool BuildSectionMeshes() const;
484
486 void AddEndCapsToMesh(CMesh &Mesh) const;
487
489 void CreateSectionAABBs() const;
490
492 void SetParent(const CTextile *pParent);
493
494 vector<CNode> m_MasterNodes;
498
499 vector<XYZ> m_Repeats;
503
505 double FindClosestEdgeDistance( XY &Loc, const vector<XY> &SectionPoints, double dTolerance ) const;
506
507 mutable int m_iNeedsBuilding;
508 mutable vector<CSlaveNode> m_SlaveNodes;
509
511
514 mutable pair<XYZ, XYZ> m_AABB;
515
517
523 mutable vector<pair<XYZ, XYZ> > m_SectionAABBs;
524
526
529 mutable vector<double> m_SectionLengths;
530
532
537 // Copy constructer for the yarn may be needed which sets this value to
538 // NULL on the copied yarn
540// CTextile* m_pParent;
541
542 private:
543 void AssignDefaults();
544 };
545
546
547}; // namespace TexGen
548
549
#define CLASS_DECLSPEC
Definition: Misc.h:35
#define NULL
Definition: ShinyConfig.h:50
Abstract base class representing the domain in which a textile cell may lie.
Definition: Domain.h:34
Abstract base class that defines how the fibres are distributed within a yarn.
Abstract base class for describing the yarn path interpolations.
Definition: Interpolation.h:33
Defines the nodes and elements of a surface or volume mesh.
Definition: Mesh.h:58
ELEMENT_TYPE
Each element type is represented by a unique integer value.
Definition: Mesh.h:66
Represents a point on the centreline of a yarn.
Definition: Node.h:28
Object container to help handle memory management issues.
Class to store properties related to a textile.
Represents a textile cell containing yarns.
Definition: Textile.h:39
Weak pointer that acts as normal pointer except when copied.
Represents a yarn consisting of master nodes, section and interpolation function.
Definition: Yarn.h:49
bool m_bEquiSpacedSectionMesh
Whether or not volume meshes of the yarn should be equispaced.
Definition: Yarn.h:502
vector< XYZ > m_Repeats
List of infinite repeat vectors, yarns will be repeated to infinite displaced by the specified vector...
Definition: Yarn.h:499
CWeakPointer< const CTextile > m_pParent
Stores a pointer to the CTextile it belongs to.
Definition: Yarn.h:539
const CInterpolation * GetInterpolation() const
Definition: Yarn.h:450
vector< CNode > m_MasterNodes
Ordered list of nodes belonging to this Yarn.
Definition: Yarn.h:494
int m_iNumSlaveNodes
Number of slave nodes to create.
Definition: Yarn.h:500
int m_iNeedsBuilding
Variable used to keep track of wether the yarn needs to be rebuilt or not and what part needs rebuild...
Definition: Yarn.h:507
CObjectContainer< CInterpolation > m_pInterpolation
Interpolation applied to smooth the yarn paths.
Definition: Yarn.h:495
vector< double > m_SectionLengths
The length of each of the sections in the yarn.
Definition: Yarn.h:529
const CFibreDistribution * GetFibreDistribution() const
Definition: Yarn.h:451
CObjectContainer< CYarnSection > m_pYarnSection
Section applied to this yarn, with possibility of a varying cross-section.
Definition: Yarn.h:496
int GetNumSlaveNodes() const
Get number of slave nodes.
Definition: Yarn.h:440
vector< pair< XYZ, XYZ > > m_SectionAABBs
An axis aligned bounding box containing each section of the yarn.
Definition: Yarn.h:523
int GetNumNodes() const
Definition: Yarn.h:452
const CYarnSection * GetYarnSection() const
Definition: Yarn.h:449
CObjectContainer< CFibreDistribution > m_pFibreDistribution
Fibre distribution given to the yarn, used for getting Fibre Volume Fraction.
Definition: Yarn.h:497
pair< XYZ, XYZ > m_AABB
An axis aligned bounding box containing the full unrepeated yarn.
Definition: Yarn.h:514
const vector< XYZ > & GetRepeats() const
Definition: Yarn.h:448
vector< CSlaveNode > m_SlaveNodes
Ordered list of interpolated slave nodes belonging to this Yarn.
Definition: Yarn.h:508
int m_iNumSectionPoints
Number of section points to create.
Definition: Yarn.h:501
const vector< CNode > & GetMasterNodes() const
Definition: Yarn.h:447
vector< double > GetSectionLengths() const
Definition: Yarn.h:453
int GetNumSectionPoints() const
Get number of section points.
Definition: Yarn.h:437
Abstract base class used to define the sections along the length of a yarn.
Definition: YarnSection.h:58
Namespace containing a series of customised math operations not found in the standard c++ library.
OUTPUT_TYPE
Definition: Misc.h:105
Struct for representing a quaternion.
Definition: mymath.h:38
Struct for representing points in 2D space.
Definition: mymath.h:103
Struct for representing points in 3D space.
Definition: mymath.h:56