27CTextileLayerToLayer::CTextileLayerToLayer(
int iNumXYarns,
int iNumYYarns,
double dXSpacing,
double dYSpacing,
double dXHeight,
double dYHeight,
int iNumBinderLayers,
bool bShapeBinders)
28:
CTextile3DWeave( iNumXYarns, iNumYYarns, dXSpacing, dYSpacing, dXHeight, dYHeight)
52 vector<PATTERN3D> &Cell =
GetCell(x, y);
53 int size = Cell.size();
54 int MaxBinderPos = (size - 1) - (zOffset * 2);
56 if ( MinBinderPos < 0 )
58 TGERROR(
"Unable to set binder positions, lowest binder position too low for number of weft yarns");
61 if ( MaxBinderPos > size - 1 )
63 TGERROR(
"Unable to set binder positions, upper binder position too high for number of weft yarns");
68 for (
int j = 0; j < size; j+=2 )
70 if ( j >= MinBinderPos && j <= MaxBinderPos )
83 vector<PATTERN3D> &Cell =
GetCell(x, y);
85 int iOffset = ((Cell.size()-1) - iTopBinder) / 2;
87 if ( iLevel1 < iLevel2 )
99 int i = Cell.size() - 1;
112 vector<PATTERN3D> &Cell =
GetCell(x, y);
114 int iOffset = ((Cell.size()-1) - iTopBinder) / 2;
120 if ( iNumWarpLayers != iNumWeftLayers-1 )
122 TGERROR(
"Unable to set up layers, number of warp layers should be one less than weft layers: warp layers " << iNumWarpLayers <<
", weft layers " << iNumWeftLayers);
126 int iWarpOnlyLayers = iNumWarpLayers - iNumBinderLayers + 1;
129 while( iNumWeftLayers > 0 )
132 if ( iNumWarpLayers > 0 )
134 if ( iWarpOnlyLayers > 0 )
163 TGERROR(
"Cannot build textile - incorrect yarn setup");
190 for (k = 0; k < (int)Cell.size(); ++k)
204 for (k = 0; k < (int)Cell.size(); ++k)
214 if ((z - dHalfHeight) <
m_dMinZ)
221 dHalfHeight =
m_XYarnData[NextCellIndex].dHeight / 2.0;
286 for (k = 0; k < (int)Cell.size(); ++k)
299 for (k = 0; k < (int)Cell.size(); ++k)
356 vector<int>::iterator itpYarn;
357 double dWidth, dHeight;
365 for (itpYarn =
m_XYarns[i].begin(); itpYarn !=
m_XYarns[i].end(); ++itpYarn)
377 for (itpYarn =
m_YYarns[i].begin(); itpYarn !=
m_YYarns[i].end(); ++itpYarn)
388 vector<CYarn>::iterator itYarn;
393 itYarn->AddRepeat(
XYZ(dWidth, 0, 0));
394 itYarn->AddRepeat(
XYZ(0, dHeight, 0));
436 const vector<PATTERN3D> &Cell =
GetCell(i,j);
446 int iMaxIndex = Cell.size() - 1;
449 XYZ WeftBelowNode, WeftAboveNode;
450 int iStartNode = CurrentNode;
458 if ( BinderYarnIndex == -1 )
461 int WeftAboveIndex, WeftBelowIndex;
464 if ( iIndex < (
int)Cell.size() - 1 )
467 WeftAboveNode =
m_Yarns[WeftAboveIndex].GetNode( j )->GetPosition();
475 WeftBelowNode =
m_Yarns[WeftBelowIndex].GetNode( j )->GetPosition();
480 XYZ BinderNode =
m_Yarns[BinderYarnIndex].GetNode( CurrentNode )->GetPosition();
482 if ( iIndex > 0 && iPrevIndex < iIndex && PrevCell[iPrevIndex] ==
PATTERN3D_XYARN
483 &&
GetYarnIndex( PrevCellIndex, j, iPrevIndex ) == BinderYarnIndex)
487 if ( YarnSection ==
NULL )
491 XYZ NewNode = WeftBelowNode;
494 int PrevWeftAboveIndex =
GetYarnIndex( PrevCellIndex, j, iPrevIndex+1 );
495 XYZ PrevWeftAboveNode =
m_Yarns[PrevWeftAboveIndex].GetNode(j)->GetPosition();
497 XY PrevSectionPoint = PrevYarnSection->
GetPoint(0.0);
503 XYZ PrevEndPoint = PrevWeftAboveNode;
504 PrevEndPoint.
x = PrevWeftAboveNode.
x + PrevSectionPoint.
x + dBinderOffset +
m_dGapSize;
505 XYZ PrevPoint = PrevWeftAboveNode;
506 PrevSectionPoint = PrevYarnSection->
GetPoint(0.95);
507 PrevPoint.
x = PrevWeftAboveNode.
x + PrevSectionPoint.
x;
508 PrevPoint.
z = PrevWeftAboveNode.
z + PrevSectionPoint.
y - (dBinderOffset +
m_dGapSize);
510 SectionPoint = YarnSection->
GetPoint(0.5);
511 NewNode.
x = NewNode.
x + SectionPoint.
x - dBinderOffset -
m_dGapSize;
512 NewNode.
z = NewNode.
z + SectionPoint.
y;
513 SectionPoint = YarnSection->
GetPoint(0.45);
514 XYZ NewNodePoint = WeftBelowNode;
515 NewNodePoint.
x = NewNodePoint.
x + SectionPoint.
x;
516 NewNodePoint.
z = NewNodePoint.
z + SectionPoint.
y + dBinderOffset +
m_dGapSize;
518 double EndBinderAngle = atan2( NewNode.
z - PrevEndPoint.
z, NewNode.
x - PrevEndPoint.
x );
519 double dBinderAngle = atan2( NewNodePoint.
z - PrevPoint.
z, NewNodePoint.
x - PrevPoint.
x );
521 if ( EndBinderAngle > dBinderAngle )
523 m_Yarns[BinderYarnIndex].InsertNode( NewNode, CurrentNode);
529 if( !( iIndex < iMaxIndex && iNextIndex > iIndex && NextCell[iNextIndex] ==
PATTERN3D_XYARN
530 &&
GetYarnIndex( NextCellIndex, j, iNextIndex ) == BinderYarnIndex ) )
537 &&
GetYarnIndex( NextCellIndex, j, iNextIndex ) == BinderYarnIndex)
543 else if ( iIndex < iMaxIndex && iPrevIndex > iIndex && PrevCell[iPrevIndex] ==
PATTERN3D_XYARN
544 &&
GetYarnIndex( PrevCellIndex, j, iPrevIndex ) == BinderYarnIndex )
548 if ( YarnSection ==
NULL )
551 XYZ NewNode = WeftAboveNode;
553 int PrevWeftBelowIndex =
GetYarnIndex( PrevCellIndex, j, iPrevIndex-1 );
554 XYZ PrevWeftBelowNode =
m_Yarns[PrevWeftBelowIndex].GetNode(j)->GetPosition();
556 XY PrevSectionPoint = PrevYarnSection->
GetPoint(0.0);
562 XYZ PrevEndPoint = PrevWeftBelowNode;
563 PrevEndPoint.
x = PrevWeftBelowNode.
x + PrevSectionPoint.
x + dBinderOffset +
m_dGapSize;
564 XYZ PrevPoint = PrevWeftBelowNode;
565 PrevSectionPoint = PrevYarnSection->
GetPoint(0.05);
566 PrevPoint.
x = PrevWeftBelowNode.
x + PrevSectionPoint.
x;
567 PrevPoint.
z = PrevWeftBelowNode.
z + PrevSectionPoint.
y + dBinderOffset +
m_dGapSize;
569 SectionPoint = YarnSection->
GetPoint(0.5);
570 NewNode.
x = NewNode.
x + SectionPoint.
x - dBinderOffset -
m_dGapSize;
571 NewNode.
z = NewNode.
z + SectionPoint.
y;
572 SectionPoint = YarnSection->
GetPoint(0.55);
573 XYZ NewNodePoint = WeftAboveNode;
574 NewNodePoint.
x = NewNodePoint.
x + SectionPoint.
x;
575 NewNodePoint.
z = NewNodePoint.
z + SectionPoint.
y - (dBinderOffset +
m_dGapSize);
577 double EndBinderAngle = atan2( NewNode.
z - PrevEndPoint.
z, NewNode.
x - PrevEndPoint.
x );
578 double dBinderAngle = atan2( NewNodePoint.
z - PrevPoint.
z, NewNodePoint.
x - PrevPoint.
x );
580 if ( EndBinderAngle < dBinderAngle )
582 m_Yarns[BinderYarnIndex].InsertNode( NewNode, CurrentNode);
587 NewNode = WeftAboveNode;
592 if ( !( iIndex > 0 && iNextIndex < iIndex && NextCell[iNextIndex] ==
PATTERN3D_XYARN
593 &&
GetYarnIndex( NextCellIndex, j, iNextIndex ) == BinderYarnIndex ) )
600 &&
GetYarnIndex( NextCellIndex, j, iNextIndex ) == BinderYarnIndex )
609 if ( iIndex > 0 && iNextIndex < iIndex && NextCell[iNextIndex] ==
PATTERN3D_XYARN
610 &&
GetYarnIndex( NextCellIndex, j, iNextIndex ) == BinderYarnIndex )
615 if ( YarnSection ==
NULL )
619 &&
GetYarnIndex( PrevCellIndex, j, iPrevIndex ) == BinderYarnIndex )
625 XYZ NewNode = WeftBelowNode;
627 if ( !(iIndex < iMaxIndex && iPrevIndex > iIndex && PrevCell[iPrevIndex] ==
PATTERN3D_XYARN
628 &&
GetYarnIndex( PrevCellIndex, j, iPrevIndex ) == BinderYarnIndex ) )
637 int NextWeftAboveIndex =
GetYarnIndex( NextCellIndex, j, iNextIndex+1 );
638 XYZ NextWeftAboveNode =
m_Yarns[NextWeftAboveIndex].GetNode(j)->GetPosition();
640 XY NextSectionPoint = NextYarnSection->
GetPoint(0.5);
646 XYZ NextEndPoint = NextWeftAboveNode;
647 NextEndPoint.
x = NextWeftAboveNode.
x + NextSectionPoint.
x - (dBinderOffset +
m_dGapSize);
648 XYZ NextPoint = NextWeftAboveNode;
649 NextSectionPoint = NextYarnSection->
GetPoint(0.55);
650 NextPoint.
x = NextWeftAboveNode.
x + NextSectionPoint.
x;
651 NextPoint.
z = NextWeftAboveNode.
z + NextSectionPoint.
y - (dBinderOffset +
m_dGapSize);
653 SectionPoint = YarnSection->
GetPoint(0.0);
654 NewNode.
x = NewNode.
x + SectionPoint.
x + dBinderOffset +
m_dGapSize;
655 NewNode.
z = NewNode.
z + SectionPoint.
y;
656 SectionPoint = YarnSection->
GetPoint(0.05);
657 XYZ NewNodePoint = WeftBelowNode;
658 NewNodePoint.
x = NewNodePoint.
x + SectionPoint.
x;
659 NewNodePoint.
z = NewNodePoint.
z + SectionPoint.
y + dBinderOffset +
m_dGapSize;
661 double EndBinderAngle = atan2( NewNode.
z - NextEndPoint.
z, NewNode.
x - NextEndPoint.
x );
662 double dBinderAngle = atan2( NewNodePoint.
z - NextPoint.
z, NewNodePoint.
x - NextPoint.
x );
664 if ( EndBinderAngle < dBinderAngle )
666 m_Yarns[BinderYarnIndex].InsertNode( NewNode, CurrentNode+1);
672 else if( iIndex < iMaxIndex && iNextIndex > iIndex && NextCell[iNextIndex] ==
PATTERN3D_XYARN
673 &&
GetYarnIndex( NextCellIndex, j, iNextIndex ) == BinderYarnIndex )
677 if ( YarnSection ==
NULL )
681 &&
GetYarnIndex( PrevCellIndex, j, iPrevIndex ) == BinderYarnIndex )
687 XYZ NewNode = WeftAboveNode;
689 if ( !(iIndex > 0 && iPrevIndex < iIndex && PrevCell[iPrevIndex] ==
PATTERN3D_XYARN
690 &&
GetYarnIndex( PrevCellIndex, j, iPrevIndex ) == BinderYarnIndex) )
699 int NextWeftBelowIndex =
GetYarnIndex( NextCellIndex, j, iNextIndex-1 );
700 XYZ NextWeftBelowNode =
m_Yarns[NextWeftBelowIndex].GetNode(j)->GetPosition();
702 XY NextSectionPoint = NextYarnSection->
GetPoint(0.5);
708 XYZ NextEndPoint = NextWeftBelowNode;
709 NextEndPoint.
x = NextWeftBelowNode.
x + NextSectionPoint.
x - (dBinderOffset +
m_dGapSize);
710 XYZ NextPoint = NextWeftBelowNode;
711 NextSectionPoint = NextYarnSection->
GetPoint(0.45);
712 NextPoint.
x = NextWeftBelowNode.
x + NextSectionPoint.
x;
713 NextPoint.
z = NextWeftBelowNode.
z + NextSectionPoint.
y + dBinderOffset +
m_dGapSize;
715 SectionPoint = YarnSection->
GetPoint(0.0);
716 NewNode.
x = NewNode.
x + SectionPoint.
x + dBinderOffset +
m_dGapSize;
717 NewNode.
z = NewNode.
z + SectionPoint.
y;
718 SectionPoint = YarnSection->
GetPoint(0.95);
719 XYZ NewNodePoint = WeftAboveNode;
720 NewNodePoint.
x = NewNodePoint.
x + SectionPoint.
x;
721 NewNodePoint.
z = NewNodePoint.
z + SectionPoint.
y - (dBinderOffset +
m_dGapSize);
723 double EndBinderAngle = atan2( NextEndPoint.
z - NewNode.
z, NextEndPoint.
x - NewNode.
x );
724 double dBinderAngle = atan2( NextPoint.
z - NewNodePoint.
z, NextPoint.
x - NewNodePoint.
x );
726 if ( EndBinderAngle > dBinderAngle )
728 m_Yarns[BinderYarnIndex].InsertNode( NewNode, CurrentNode+1);
736 if ( iStartNode == 0 )
738 XYZ NewNode =
m_Yarns[BinderYarnIndex].GetNode(0)->GetPosition();
747 int i = Cell.size() - 1;
762 int iNumWefts = (int)
m_YYarns[i].size();
764 Rows.resize(iNumWefts);
768 vector<PATTERN3D> &Cell =
GetCell(i, j);
771 vector<bool> bWeftSet(iNumWefts,
false);
772 int iWeft = iNumWefts-1;
774 for (
int k = (
int)Cell.size()-1; k >= 0; --k )
779 for (
int iW = 0; iW < iNumWefts; ++iW )
782 Rows[iW].push_back(
'1');
784 Rows[iW].push_back(
'0');
788 bWeftSet[iWeft] =
true;
801 for (
int iW = iNumWefts-1 ; iW >=0; --iW )
807 for (
int iW = 0 ; iW < iNumWefts; ++iW )
#define TGLOGINDENT(MESSAGE)
Combines the TGLOG macro and TGLOGAUTOINDENT macro in one.
#define TGERROR(MESSAGE)
Macros used to report the file name and line number to the TexGenError and TexGenLog functions.
Bezier interpolation for yarn paths.
Represents a point on the centreline of a yarn.
void AddRow(string Row)
Add a row representing one weft insertion '1' indicates warp up, '0' warp down and '2' no yarn.
void AssignSectionMesh(const CSectionMesh &SectionMesh)
Assign a mesh to the section.
XY GetPoint(double t) const
Get a point lying on the perimeter correspending to parametric value t.
Represents a 3D woven textile.
void AddNoYarnLayer()
Add empty layer.
void ReplaceLastNode(int BinderYarnIndex, XYZ &NewNode, XYZ &BinderNode) const
Replace last node with node offset to match node 0.
vector< YARNDATA > m_XYarnData
vector< vector< int > > m_XYarns
int GetYarnIndex(int x, int y, int z) const
void CheckUpVectors(int WarpIndex, bool Yarn=PATTERN3D_XYARN, bool bYarnsIndex=false) const
bool CheckCells() const
Check that all cells are populated.
bool Valid() const
Check that the weave pattern contained in m_Pattern is valid.
double GetHeight() const
Get the height of the unit cell.
CSectionPowerEllipse * GetWeftCrossSection(int WeftYarnIndex) const
Adjust cross section shapes to correct interference.
int FindNextCellIndex(int index) const
Find next cell in y direction which isn't a binder yarn.
bool NoYarnCell(vector< PATTERN3D > &Cell)
bool IsBinderYarn(int index) const
Check if X yarn is binder or warp. Returns true if binder.
vector< YARNDATA > m_YYarnData
void AddBinderLayer()
Add yarns parallel to the X axis in binder yarn positions, no yarns in warp positions.
void AddWarpLayer()
Add yarns parallel to the X axis in warp yarn positions, no yarns in binder positions.
void AddXLayers(int y, int iNumberLayers)
Add given number of yarns parallel to the X axis, with given index y.
vector< vector< int > > m_YYarns
virtual double GetWidth() const
Get the width of the unit cell.
void AddYLayers(int x, int iNumberLayers)
Add given number of yarns parallel to the Y axis, with given index x.
void InsertBinderNode(CSectionPowerEllipse *YarnSection, double t, XYZ &WeftNode, int &CurrentNode, int BinderYarnIndex, double Offset, bool bInsert=true) const
Calculates a point at given point on power ellipse cross section and inserts into binder yarn.
virtual void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType)
Used for saving data to XML.
CPatternDraft m_PatternDraft
Class for generating pattern draft from weave pattern.
const vector< PATTERN3D > & GetCell(int x, int y) const
CObjectContainer< CSectionMesh > m_pSectionMesh
vector< CYarn > m_Yarns
Vector of yarns contained within this cell.
string GetName() const
Get the name associated with this textile.
int AddYarn(const CYarn &Yarn)
Add a Yarn to the textile.
bool m_bNeedsBuilding
Variable which keeps track of wether the textile needs building or not.
virtual void SetupLayers(int iNumWarpLayers, int iNumWeftLayers, int iNumBinderLayers=1)
Set up the sequence of layers in the textile for the required number of warp, weft and binder yarn la...
virtual void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType)
Used for saving data to XML.
bool BuildLayerToLayerTextile() const
virtual ~CTextileLayerToLayer(void)
CTextileLayerToLayer(int iNumXYarns, int iNumYYarns, double dXSpacing, double dYSpacing, double dXHeight, double dYHeight, int iNumBinderLayers, bool bShapeBinders=true)
Build a weave unit cell of given width, height, yarn spacing and fabric thickness.
int FindTopBinderYarn(vector< PATTERN3D > &Cell)
Finds cell index of the top binder yarn.
virtual void ConvertToPatternDraft(int iWeftOrder=BOTTOM_TO_TOP)
int AddBinderNodes(int CurrentNode, int i, int j, int Height) const
Add extra nodes to binder yarns to match shape of adjacent weft yarns.
virtual bool BuildTextile() const
Build the textile.
virtual int FindBinderHeight(const vector< PATTERN3D > &Cell, int Height) const
void ShapeBinderYarns() const
Shape the binder yarns around the adjacent weft yarns.
virtual int GetNumBinderLayers() const
Returns number of binder layers in textile.
int GetBinderOffset(int x, int y)
Finds the offset position of the top binder yarn at the given x,y position.
void SetBinderPosition(int x, int y, int zOffset)
Sets the vertical positions of the binder yarns.
void MoveBinderYarns(int x, int y, int iLevel1, int iLevel2)
Move the stack of binder yarns by one position.
Represents a yarn consisting of master nodes, section and interpolation function.
Creates a section which is constant all along the yarn.
Namespace containing a series of customised math operations not found in the standard c++ library.
Struct for representing points in 2D space.
Struct for representing points in 3D space.