33CTextile3DWeave::CTextile3DWeave(
int iNumXYarns,
int iNumYYarns,
double dXSpacing,
double dYSpacing,
34 double dXHeight,
double dYHeight,
bool bRefine )
35: m_iNumXYarns(iNumXYarns)
36, m_iNumYYarns(iNumYYarns)
45, m_dMaxVolumeFraction(0.78)
80 TiXmlElement *pSectionMesh = Element.FirstChildElement(
"SectionMesh");
87 vector<PATTERN3D> Cell;
90 Cell.push_back(valueify<int>(pCell->Attribute(
"value")));
97 pYarnData->Attribute(
"Width", &YarnData.
dWidth);
98 pYarnData->Attribute(
"Height", &YarnData.
dHeight);
99 pYarnData->Attribute(
"Spacing", &YarnData.
dSpacing);
104 pYarnData->Attribute(
"Width", &YarnData.
dWidth);
105 pYarnData->Attribute(
"Height", &YarnData.
dHeight);
106 pYarnData->Attribute(
"Spacing", &YarnData.
dSpacing);
114 Indices.push_back(valueify<int>(pYarn->Attribute(
"yarnindex")));
123 Indices.push_back(valueify<int>(pYarn->Attribute(
"yarnindex")));
146 TiXmlElement SectionMesh(
"SectionMesh");
148 Element.InsertEndChild(SectionMesh);
153 TiXmlElement PatternCell(
"PatternCell");
155 PatternCell.SetAttribute(
"x", Coords.first);
156 PatternCell.SetAttribute(
"y", Coords.second);
158 for (j=0; j<(int)
m_Pattern[i].size(); ++j)
160 TiXmlElement PatternElement(
"PatternElement");
163 PatternCell.InsertEndChild(PatternElement);
165 Element.InsertEndChild(PatternCell);
169 TiXmlElement XYarnData(
"XYarnData");
170 XYarnData.SetAttribute(
"index", i);
174 Element.InsertEndChild(XYarnData);
178 TiXmlElement YYarnData(
"YYarnData");
179 YYarnData.SetAttribute(
"index", i);
183 Element.InsertEndChild(YYarnData);
188 for (i=0; i<(int)
m_XYarns.size(); ++i)
190 TiXmlElement XYarns(
"XYarns");
191 XYarns.SetAttribute(
"index", i);
192 for (j=0; j<(int)
m_XYarns[i].size(); ++j)
194 TiXmlElement XYarn(
"XYarn");
196 XYarn.SetAttribute(
"yarnindex",
m_XYarns[i][j]);
197 XYarns.InsertEndChild(XYarn);
199 Element.InsertEndChild(XYarns);
201 for (i=0; i<(int)
m_YYarns.size(); ++i)
203 TiXmlElement YYarns(
"YYarns");
204 YYarns.SetAttribute(
"index", i);
205 for (j=0; j<(int)
m_YYarns[i].size(); ++j)
207 TiXmlElement YYarn(
"YYarn");
209 YYarn.SetAttribute(
"yarnindex",
m_YYarns[i][j]);
210 YYarns.InsertEndChild(YYarn);
212 Element.InsertEndChild(YYarns);
240 int i, j, k, iNumYarns, iFirstNumYarns;
245 const vector<PATTERN3D> &Cell =
GetCell(j, i);
247 for (k=0; k<(int)Cell.size(); ++k)
254 iFirstNumYarns = iNumYarns;
258 if (iFirstNumYarns != iNumYarns)
268 const vector<PATTERN3D> &Cell =
GetCell(j, i);
270 for (k=0; k<(int)Cell.size(); ++k)
277 iFirstNumYarns = iNumYarns;
281 if (iFirstNumYarns != iNumYarns)
328 for (k=0; k<(int)Cell.size(); ++k)
342 for (k=0; k<(int)Cell.size(); ++k)
350 if ( (z - dHalfHeight) <
m_dMinZ )
366 else if ( ((k > 0 && k < (
int)Cell.size()-1) && bBinderYarns) || !bBinderYarns )
368 int CellType = NextCell[k];
375 CellType = FindCell[k];
409 for (i=0; i<=NumXYarns; ++i)
418 for (k=0; k<(int)Cell.size(); ++k)
424 if ( Count > iYCount )
434 for (k=0; k<(int)Cell.size(); ++k)
448 for (k=0; k<(int)Cell.size(); ++k)
463 else if ( ((k > 0 && k < (
int)Cell.size()-1) && bBinderYarns) || !bBinderYarns )
465 int CellType = NextCell[k];
472 CellType = FindCell[k];
497 vector<int>::iterator itpYarn;
498 double dWidth, dHeight;
508 for (itpYarn =
m_XYarns[i].begin(); itpYarn !=
m_XYarns[i].end(); ++itpYarn)
523 for (itpYarn =
m_YYarns[i].begin(); itpYarn !=
m_YYarns[i].end(); ++itpYarn)
535 vector<CYarn>::iterator itYarn;
540 itYarn->AddRepeat(
XYZ(dWidth, 0, 0));
542 itYarn->AddRepeat(
XYZ(0, dHeight, 0));
819 TGERROR(
"Unable to set yarn width, index out of range: " << iIndex);
830 TGERROR(
"Unable to set yarn width, index out of range: " << iIndex);
841 TGERROR(
"Unable to set yarn height, index out of range: " << iIndex);
852 TGERROR(
"Unable to set yarn height, index out of range: " << iIndex);
863 TGERROR(
"Unable to set yarn spacing, index out of range: " << iIndex);
874 TGERROR(
"Unable to set yarn spacing, index out of range: " << iIndex);
930 TGERROR(
"Unable to set yarn width, index out of range: " << iIndex);
940 TGERROR(
"Unable to get yarn width, index out of range: " << iIndex);
950 TGERROR(
"Unable to get yarn height, index out of range: " << iIndex);
960 TGERROR(
"Unable to get yarn height, index out of range: " << iIndex);
970 TGERROR(
"Unable to get yarn spacing, index out of range: " << iIndex);
980 TGERROR(
"Unable to get yarn spacing, index out of range: " << iIndex);
1030 TGERROR(
"Unable to get yarn spacing, index out of range: " << iIndex);
1046 TGERROR(
"Unable to get yarn spacing, index out of range: " << iIndex);
1334 dGap = 0.05 * (
Max.z -
Min.
z );
1356 if ( Domain && Domain->
GetType() ==
"CDomainPlanes" )
1424 vector<CYarn*> Yarns;
1429 TGERROR(
"Unable to get yarn, index out of range: " << iIndex);
1432 vector<int>::iterator itIndex;
1433 for (itIndex =
m_XYarns[iIndex].begin(); itIndex !=
m_XYarns[iIndex].end(); ++itIndex)
1435 Yarns.push_back(&
m_Yarns[*itIndex]);
1442 vector<CYarn*> Yarns;
1447 TGERROR(
"Unable to get yarn, index out of range: " << iIndex);
1449 vector<int>::iterator itIndex;
1450 for (itIndex =
m_YYarns[iIndex].begin(); itIndex !=
m_YYarns[iIndex].end(); ++itIndex)
1452 Yarns.push_back(&
m_Yarns[*itIndex]);
1459 int iXYarnCount = 0;
1460 int iYYarnCount = 0;
1461 vector<PATTERN3D> Pattern =
GetCell(x, y);
1483 TGERROR(
"Unable to add yarn layer, index out of range: " << x);
1489 for (j=0; j<iNumberLayers; ++j)
1499 TGERROR(
"Unable to add yarn layer, index out of range: " << y);
1505 for (j=0; j<iNumberLayers; ++j)
1515 TGERROR(
"Unable to add yarn layer, index out of range: " << y);
1521 GetCell(i, y).push_back( Pattern );
1530 TGERROR(
"Unable to add yarn layer, index out of range: " << x);
1536 GetCell(x,i).push_back( Pattern );
1604 TGERROR(
"Unable to delete yarn layer, index out of range: " << x);
1608 vector<PATTERN3D>::reverse_iterator itCell;
1611 for (j=0; j<iNumberLayers; ++j)
1613 vector<PATTERN3D> &Cell =
GetCell(x, i);
1615 if (itCell != Cell.rend())
1617 Cell.erase(itCell.base()-1);
1628 TGERROR(
"Unable to delete yarn layer, index out of range: " << y);
1632 vector<PATTERN3D>::reverse_iterator itCell;
1635 for (j=0; j<iNumberLayers; ++j)
1637 vector<PATTERN3D> &Cell =
GetCell(i, y);
1639 if (itCell != Cell.rend())
1641 Cell.erase(itCell.base()-1);
1668 const vector<PATTERN3D> &Cell =
GetCell(x, 0);
1674 const vector<PATTERN3D> &Cell =
GetCell(0, y);
1686 iMaxLayers = max(iMaxLayers, (
int)
GetCell(i, j).size());
1696 TGERROR(
"Unable to swap position, index out of range: " << x <<
", " << y);
1699 vector<PATTERN3D> &Cell =
GetCell(x, y);
1700 if (iLevel1 < 0 || iLevel1 >= (
int)Cell.size())
1702 TGERROR(
"Unable to swap position, level out of range: " << iLevel1);
1705 if (iLevel2 < 0 || iLevel2 >= (
int)Cell.size())
1707 TGERROR(
"Unable to swap position, level out of range: " << iLevel2);
1711 bTemp = Cell[iLevel1];
1712 Cell[iLevel1] = Cell[iLevel2];
1713 Cell[iLevel2] = bTemp;
1736 for (
int i = 0; i <
m_XYarns.size(); ++i )
1738 vector<int>::iterator itYarns;
1739 for ( itYarns =
m_XYarns[i].begin(); itYarns !=
m_XYarns[i].end(); ++itYarns )
1741 if ( *itYarns == YarnInd )
1766 if ( iBinderRatio < 1 )
1768 TGERROR(
"Binder ratio must be greater than 0");
1796 int i = StartIndex + 1;
1804 if ( StartIndex == 0 )
1821 const vector<PATTERN3D> &Cell =
GetCell( i, j );
1834 const vector<PATTERN3D> &Cell =
GetCell( i, j );
1852 const vector<PATTERN3D> &Cell =
GetCell( i, j );
1866 const vector<PATTERN3D> &Cell =
GetCell( i, j );
1878 dMinZ = dMaxZ = 0.0;
1888 for (
int k=0; k<(int)Cell.size(); ++k)
1893 double dHalfHeight =
m_XYarnData[i].dHeight / 2.0;
1899 if ( (z - dHalfHeight) < dMinZ )
1900 dMinZ = z - dHalfHeight;
1905 dHalfHeight =
m_XYarnData[NextCellIndex].dHeight / 2.0;
1919 else if ( k > 0 && k < (
int)Cell.size()-1)
1953 int iLastNode =
m_Yarns[BinderYarnIndex].GetNumNodes() - 1;
1954 XYZ LastNode =
m_Yarns[BinderYarnIndex].GetNode(iLastNode)->GetPosition();
1955 XYZ Offset = BinderNode - NewNode;
1958 m_Yarns[BinderYarnIndex].ReplaceNode( iLastNode, LastNode );
1963 if (
m_Yarns[WeftYarnIndex].GetYarnSection()->
GetType() !=
"CYarnSectionConstant")
1967 delete pYarnSection;
1974 string Type =
m_Yarns[YarnIndex].GetYarnSection()->GetType();
1976 if ( Type ==
"CYarnSectionConstant" )
1979 pSection = pYarnSection->
GetSection().Copy();
1980 delete pYarnSection;
1983 else if ( Type ==
"CYarnSectionInterpNode" )
1987 delete pYarnSection;
2001 vector<int> XNodes( iNumXYarns, 0 );
2004 int CurrentYNode = 0;
2005 for (
int j = 0; j < iNumXYarns; ++j )
2007 CurrentYNode =
AddWeftNodes( CurrentYNode, XNodes[j], i, j );
2008 if ( CurrentYNode >= 0 )
2020 int i = Cell.size() - 1;
2033 while ( iIndex < (
int)Cell.size() )
2045 while ( iIndex >= 0 )
2057 const vector<PATTERN3D> &Cell =
GetCell(i,j);
2078 const vector<PATTERN3D> &NextCell =
GetCell( i, NextCellIndex );
2079 const vector<PATTERN3D> &PrevCell =
GetCell( i, PrevCellIndex );
2084 int iMaxIndex = Cell.size() - 1;
2087 XYZ WarpBelowNode, WarpAboveNode;
2088 int iStartNode = CurrentNode;
2097 if ( WeftYarnIndex == -1 )
2099 int WarpAboveIndex, WarpBelowIndex;
2100 int WarpAboveCellIndex, WarpBelowCellIndex;
2103 if ( iIndex < (
int)Cell.size() - 1 )
2106 if ( WarpAboveCellIndex != -1 )
2108 WarpAboveIndex =
GetYarnIndex( i, j, WarpAboveCellIndex );
2109 if ( WarpAboveIndex >= 0 )
2110 WarpAboveNode =
m_Yarns[WarpAboveIndex].GetNode( XNode )->GetPosition();
2113 WarpAboveIndex = -1;
2116 WarpAboveIndex = -1;
2122 if ( WarpBelowCellIndex != -1 )
2124 WarpBelowIndex =
GetYarnIndex( i, j, WarpBelowCellIndex );
2125 if ( WarpBelowIndex >= 0 )
2126 WarpBelowNode =
m_Yarns[WarpBelowIndex].GetNode( XNode )->GetPosition();
2129 WarpBelowIndex = -1;
2132 WarpBelowIndex = -1;
2136 XYZ WeftNode =
m_Yarns[WeftYarnIndex].GetNode( CurrentNode )->GetPosition();
2137 if ( iIndex > 0 && iPrevIndex != -1 && iPrevIndex < iIndex-1 && PrevCell[iPrevIndex] ==
PATTERN3D_YYARN
2138 &&
GetYarnIndex( i,PrevCellIndex, iPrevIndex ) == WeftYarnIndex)
2141 if ( WarpBelowIndex == -1 )
2144 if ( YarnSection ==
NULL )
2148 XYZ NewNode = WarpBelowNode;
2150 if ( iIndex - iPrevIndex > 2 )
2152 SectionPoint = YarnSection->
GetPoint(0.5);
2153 NewNode.
y = NewNode.
y + SectionPoint.
x - dWeftOffset -
m_dGapSize;
2154 NewNode.
z = NewNode.
z + SectionPoint.
y;
2155 m_Yarns[WeftYarnIndex].InsertNode( NewNode, CurrentNode);
2161 if( !( iIndex < iMaxIndex && iNextIndex > iIndex && NextCell[iNextIndex] ==
PATTERN3D_YYARN
2162 &&
GetYarnIndex( i, NextCellIndex, iNextIndex ) == WeftYarnIndex ) )
2175 else if ( iIndex < iMaxIndex && iPrevIndex != -1 && iPrevIndex > iIndex+1 && PrevCell[iPrevIndex] ==
PATTERN3D_YYARN
2176 &&
GetYarnIndex( i, PrevCellIndex, iPrevIndex ) == WeftYarnIndex )
2178 if ( WarpAboveCellIndex != iIndex+1 )
2182 if ( YarnSection ==
NULL )
2185 XYZ NewNode = WarpAboveNode;
2187 if ( iPrevIndex - iIndex > 2 )
2189 SectionPoint = YarnSection->
GetPoint(0.5);
2190 NewNode.
y = NewNode.
y + SectionPoint.
x - dWeftOffset -
m_dGapSize;
2191 NewNode.
z = NewNode.
z + SectionPoint.
y;
2192 m_Yarns[WeftYarnIndex].InsertNode( NewNode, CurrentNode);
2196 NewNode = WarpAboveNode;
2201 if ( !( iIndex > 0 && iNextIndex < iIndex && NextCell[iNextIndex] ==
PATTERN3D_YYARN
2202 &&
GetYarnIndex( i, NextCellIndex, iNextIndex ) == WeftYarnIndex ) )
2209 &&
GetYarnIndex( i, NextCellIndex, iNextIndex ) == WeftYarnIndex )
2211 InsertWeftNode( YarnSection, 0.75, WarpAboveNode, CurrentNode, WeftYarnIndex, -(dWeftOffset +
m_dGapSize),
false );
2218 if ( iIndex > 0 && iNextIndex != -1 && iNextIndex < iIndex-1 && NextCell[iNextIndex] ==
PATTERN3D_YYARN
2219 &&
GetYarnIndex( i, NextCellIndex, iNextIndex ) == WeftYarnIndex )
2223 if ( YarnSection ==
NULL )
2227 &&
GetYarnIndex( i, PrevCellIndex, iPrevIndex ) == WeftYarnIndex )
2233 XYZ NewNode = WarpBelowNode;
2235 if ( !(iIndex < iMaxIndex && iPrevIndex > iIndex && PrevCell[iPrevIndex] ==
PATTERN3D_YYARN
2236 &&
GetYarnIndex( i, PrevCellIndex, iPrevIndex ) == WeftYarnIndex ) )
2245 if ( iIndex - iNextIndex > 2 )
2247 SectionPoint = YarnSection->
GetPoint(0);
2248 NewNode = WarpBelowNode;
2249 NewNode.
y = NewNode.
y + SectionPoint.
x + dWeftOffset +
m_dGapSize;
2250 NewNode.
z = NewNode.
z + SectionPoint.
y;
2251 m_Yarns[WeftYarnIndex].InsertNode( NewNode, CurrentNode+1 );
2257 else if( iIndex < iMaxIndex && iNextIndex != -1 && iNextIndex > iIndex+1 && NextCell[iNextIndex] ==
PATTERN3D_YYARN
2258 &&
GetYarnIndex( i, NextCellIndex, iNextIndex ) == WeftYarnIndex )
2260 if ( WarpAboveCellIndex != iIndex+1 )
2265 if ( YarnSection ==
NULL )
2269 &&
GetYarnIndex( i, PrevCellIndex, iPrevIndex ) == WeftYarnIndex )
2271 InsertWeftNode( YarnSection, 0.75, WarpAboveNode, CurrentNode, WeftYarnIndex, -(dWeftOffset +
m_dGapSize),
false );
2275 XYZ NewNode = WarpAboveNode;
2277 if ( !(iIndex > 0 && iPrevIndex < iIndex && PrevCell[iPrevIndex] ==
PATTERN3D_YYARN
2278 &&
GetYarnIndex( i, PrevCellIndex, iPrevIndex ) == WeftYarnIndex) )
2287 if ( iNextIndex - iIndex > 2 )
2289 SectionPoint = YarnSection->
GetPoint(0);
2290 NewNode = WarpAboveNode;
2291 NewNode.
y = NewNode.
y + SectionPoint.
x + dWeftOffset +
m_dGapSize;
2292 NewNode.
z = NewNode.
z + SectionPoint.
y;
2293 m_Yarns[WeftYarnIndex].InsertNode( NewNode, CurrentNode+1 );
2303 XYZ NewNode =
m_Yarns[WeftYarnIndex].GetNode(0)->GetPosition();
2316 if ( Index >
m_Yarns.size()-1 )
2336 vector<CNode> Nodes =
m_Yarns[YarnIndex].GetMasterNodes();
2337 vector<CNode>::iterator itNodes;
2340 XYZ UpVector, StartUp;
2341 int size = Nodes.size();
2344 for (
int i = 0; i < size-1; ++i)
2346 CheckNodes[1] = Nodes[i].GetPosition();
2349 CheckNodes[0] = CheckNodes[1];
2350 CheckNodes[2] = Nodes[i+1].GetPosition();
2354 CheckNodes[2] = Nodes[i+1].GetPosition();
2357 Nodes[i].SetUp( UpVector );
2359 Nodes[size-1].SetUp(UpVector);
2360 CheckNodes[0] = CheckNodes[1];
2362 m_Yarns[YarnIndex].SetNodes( Nodes );
2368 dz = CheckNodes[2].
z - CheckNodes[0].
z;
2371 dHorz = CheckNodes[2].
x - CheckNodes[0].
x;
2373 dHorz = CheckNodes[2].
y - CheckNodes[0].
y;
2376 if ( fabs(dz) > fabs(dHorz) )
2411 XYZ NewNode = WeftNode;
2413 NewNode.
x = NewNode.
x + SectionPoint.
x;
2414 NewNode.
z = NewNode.
z + SectionPoint.
y + Offset;
2417 m_Yarns[BinderYarnIndex].InsertNode( NewNode, CurrentNode);
2421 m_Yarns[BinderYarnIndex].ReplaceNode( CurrentNode, NewNode );
2427 string Type = YarnSection->
GetType();
2429 if ( Type ==
"CSectionPowerEllipse" )
2433 XYZ NewNode = WeftNode;
2435 NewNode.
x = NewNode.
x + SectionPoint.
x;
2436 NewNode.
z = NewNode.
z + SectionPoint.
y + Offset;
2439 m_Yarns[BinderYarnIndex].InsertNode( NewNode, CurrentNode);
2443 m_Yarns[BinderYarnIndex].ReplaceNode( CurrentNode, NewNode );
2450 string Type = YarnSection->
GetType();
2452 if ( Type ==
"CSectionPowerEllipse" )
2456 XYZ NewNode = WarpNode;
2458 NewNode.
y = NewNode.
y + SectionPoint.
x;
2459 NewNode.
z = NewNode.
z + SectionPoint.
y + Offset;
2462 m_Yarns[WeftYarnIndex].InsertNode( NewNode, CurrentNode);
2466 m_Yarns[WeftYarnIndex].ReplaceNode( CurrentNode, NewNode );
2473 double StartHeight = YarnSection->
GetHeight();
2474 double TargetHeight = StartHeight * HeightReduction;
2476 if ( fabs( 1 - HeightReduction ) >
TOL )
2477 NewWidth = YarnSection->
GetWidth() * 1.1 / HeightReduction;
2479 NewWidth = YarnSection->
GetWidth() * 1.1;
2481 if ( NewWidth > MaxWidth )
2482 NewWidth = MaxWidth;
2484 double dWidth = NewWidth - YarnSection->
GetWidth();
2488 if ( fabs(dWidth) <
TOL )
2490 *YarnSection = NewSection;
2497 bool bFoundRange =
false;
2499 while( fabs( Area - TargetArea ) >
TOL )
2501 if ( Area > TargetArea )
2507 else if ( Area < TargetArea )
2509 if ( NewWidth > MaxWidth )
2512 *YarnSection = Section;
2526 if ( NewWidth > MaxWidth )
2529 *YarnSection = NewSection;
2536 *YarnSection = Section;
2542 double NewHeight = MaxHeight;
2543 double StartHeight = NewHeight;
2544 double dHeight = StartHeight - YarnSection->
GetHeight();
2546 string Type = YarnSection->
GetType();
2551 if ( Area < TargetArea )
2553 *YarnSection = NewSection;
2557 while( fabs( Area - TargetArea ) >
TOL )
2559 if ( Area > TargetArea )
2562 NewHeight -= dHeight;
2564 else if ( Area < TargetArea )
2567 NewHeight += dHeight;
2575 *YarnSection = Section;
2580 double MaxPower = YarnSection->
GetPower();
2581 double TargetHeight = YarnSection->
GetHeight() * HeightReduction;
2582 double dWidth = YarnSection->
GetWidth();
2587 if ( Area < TargetArea )
2590 double MidPower = ( MaxPower + MinPower )/2.0;
2594 while ( fabs( MidArea - TargetArea ) >
TOL )
2596 if ( MidArea > TargetArea )
2598 MinPower = MidPower;
2602 MaxPower = MidPower;
2604 MidPower = ( MinPower + MaxPower ) / 2.0;
2609 *YarnSection = Section;
2616 if ( Area <= TargetArea )
2619 double MaxHeight = YarnSection->
GetHeight();
2620 double MinHeight = YarnSection->
GetHeight() / 2.0;
2621 double Width = YarnSection->
GetWidth();
2622 double MidHeight = ( MaxHeight + MinHeight )/2.0;
2623 double Power = YarnSection->
GetPower();
2628 while ( fabs( MidArea - TargetArea ) >
TOL )
2630 if ( MidArea > TargetArea )
2632 MaxHeight = MidHeight;
2636 MinHeight = MidHeight;
2638 MidHeight = ( MinHeight + MaxHeight ) / 2.0;
2643 *YarnSection = Section;
2663 double WarpWidth = 0.0;
2664 double BinderWidth = 0.0;
2665 double WarpHeight = 0.0;
2666 double BinderHeight = 0.0;
2668 iNumBinderYarns = 0;
2671 bool bRatioFound =
false;
2679 if ( iBinderRatio == 0 )
2700 if ( iNumWarpYarns )
2702 AveWarp.
dWidth = WarpWidth / iNumWarpYarns;
2703 AveWarp.
dHeight = WarpHeight / iNumWarpYarns;
2710 AveBinder.
dWidth = BinderWidth / iNumBinderYarns;
2711 AveBinder.
dHeight = BinderHeight / iNumBinderYarns;
2717 iNumWarpYarns += iNumBinderYarns;
2722 int NumLayers = *(max_element( Layers.begin(), Layers.end() )) + 1;
2724 vector<int>::iterator itWarp;
2725 vector<int>::iterator itLayers;
2727 if ( Layers.size() != Warp.size() )
2728 TGERROR(
"Can't add weft row, warp and layer sizes do not match");
2730 itWarp = Warp.begin();
2732 int PrevYCellIndex = -1;
2734 for ( itLayers = Layers.begin(); itLayers != Layers.end(); )
2736 vector<PATTERN3D> &Cell =
GetCell(Weft, j);
2741 if ( *itWarp == 0 && bFirst )
2744 if ( PrevYCellIndex != -1 && WarpIndex != -1 && PrevYCellIndex >= WarpIndex-1 )
2747 PrevYCellIndex = WarpIndex-1;
2752 PrevYCellIndex = NumLayers - (*itLayers);
2764 WarpIndex = NumLayers - (*itLayers);
2771 }
while ( itLayers != Layers.end() && *itLayers != 1 );
2775 PrevYCellIndex = NumLayers - *(itLayers-1)-1;
2791 vector<PATTERN3D> &Cell =
GetCell(i, j);
2794 bool bWeftSet =
false;
2795 for (
int k = Cell.size()-1; k > 0; --k )
2831 for (
int i = 0; i < Cell.size(); ++i )
2841 vector<int> LayerInfo;
2842 double dReedWidth = 0;
2843 double dMaxWarpWidth = 0.0;
2847 vector<PATTERN3D> &Cell =
GetCell(0, j);
2848 for (
int k = Cell.size()-1; k >= 0; --k )
2853 LayerInfo.push_back( Layers );
2859 double dDentWidth = 1.0/dReedDensity;
2860 double dToothSize = 0.2 * dDentWidth;
2865 double dDentGap = dDentWidth - dToothSize;
2866 if ( dMaxWarpWidth/3.0 > dDentGap )
2868 TGERROR(
"Yarn width greater than dent gap. Compressed yarn width = " << dMaxWarpWidth <<
", Dent gap = " << dDentGap );
2871 double dWeftWidth = 0;
2876 double dWeftDensity = (
m_iNumYYarns / dWeftWidth) * 10.0;
2879 ofstream Output(Filename.c_str());
2881 Output <<
"Reed width: " << dReedWidth <<
"mm" << endl;
2882 Output <<
"Reed density: " << dReedDensity * 10.0 <<
" dents/cm" << endl;
2883 Output <<
"Tooth thickness: " << dToothSize <<
"mm" << endl;
2884 Output <<
"Weft density: " << dWeftDensity <<
" wefts/cm" << endl;
2885 Output <<
"Number of used dents: " <<
m_iNumXYarns << endl;
2887 Output <<
"Dent Number of ends" << endl;
2889 for (
int i = 0; i < LayerInfo.size(); ++i )
2892 Output << std::left << i+1;
2894 Output << std::left << LayerInfo[i] << endl;
2904 const vector<PATTERN3D> &Cell =
GetCell(j, i);
2905 if ( Cell.size() == 0 )
#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.
#define FOR_EACH_TIXMLELEMENT(CHILDELEMENT, PARENTELEMENT, ELEMENTNAME)
Macro to enable looping over tinyxml easier.
Abstract base class representing the domain in which a textile cell may lie.
virtual string GetType() const =0
Derived class should return the class name.
Domain implementation described using planes, the simplest of which would be a box.
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.
int GetFibresPerYarn() const
double GetYarnLinearDensity(string Units="kg/m") const
void SetFibreArea(double dValue, string Units="m^2")
Set the area occupied by fibres in a yarn cross-section.
double GetFibreDiameter(string Units="m") const
void SetFibresPerYarn(int iValue)
Set the number of fibres in a yarn.
void SetYarnLinearDensity(double dValue, string Units="kg/m")
Set the fibre linear density, i.e. the mass per unit length of fibre.
void SetFibreDiameter(double dValue, string Units="m")
Set the fibre diameter.
void SetFibreDensity(double dValue, string Units="kg/m^3")
Set the fibre density, i.e. the mass per unit volume of fibre.
double GetFibreArea(string Units="m^2") const
Get the area occupied by fibres given fibre diameter and number of fibres.
double GetFibreDensity(string Units="kg/m^3") const
double GetClosestReedThickness(double dThickness)
Abstract base class respresenting a yarn cross-section.
virtual CSection * Copy() const =0
Create a copy of the derived section and return a pointer to the newly created instance.
void AssignSectionMesh(const CSectionMesh &SectionMesh)
Assign a mesh to the section.
virtual string GetType() const =0
Derived class should return the class name.
static double GetArea(const vector< XY > &Section)
Get the area of a section.
virtual const vector< XY > & GetPoints(int iNumPoints, bool bEquiSpaced=false) const
Get a section with given number of points on the perimeter.
virtual XY GetPoint(double t) const =0
Get a point lying on the perimeter correspending to parametric value t.
Hybrid of any number of other sections.
Abstract base class to create a 2D mesh of a section.
static CObjectContainer< CSectionMesh > CreateSectionMesh(TiXmlElement &Element)
Create a section from TiXmlElement.
string GetType() const
Derived class should return the class name.
void SetWidth(double dWidth)
XY GetPoint(double t) const
Get a point lying on the perimeter correspending to parametric value t.
void AddNoYarnLayer()
Add empty layer.
void ShapeWeftYarns() const
void SetYarnSpacings(double dSpacing)
Set the spacing of all the yarns in the textile.
void SetWarpYarnWidths(double dWidth)
Set the width of yarns parallel to the X axis in warp yarn positions.
void ReplaceLastNode(int BinderYarnIndex, XYZ &NewNode, XYZ &BinderNode) const
Replace last node with node offset to match node 0.
double GetYYarnGapSize(int iIndex) const
Get the gap size between two yarns parallel to the Y axis, with given index.
void AddXYarn(int y, PATTERN3D Pattern)
Add yarn of type XYARN or NOYARN parallel to the X axis.
vector< YARNDATA > m_XYarnData
vector< vector< int > > m_XYarns
virtual int GetNumBinderLayers() const
Retrieve the number of binder layers.
void AssignSectionMesh(const CSectionMesh &SectionMesh)
Assign a section mesh to the weave.
double m_dFabricThickness
int FindWarpBelowIndex(const vector< PATTERN3D > &Cell, int iIndex) const
int GetMaxNumLayers() const
Retreive the maximum number of layers at any crossover.
double GetYYarnSpacings(int iIndex) const
Get the spacing of the yarn parallel to the Y axis, with given index.
int GetYarnIndex(int x, int y, int z) const
void FindPowerEllipseSectionHeight(double &MaxHeight, double &TargetArea, CSectionPowerEllipse *YarnSection) const
void SetYarnProperties(CYarn &Yarn, int iType) const
CDomainPlanes GetDefaultDomain(bool bAddedDomainHeight=true)
Get a domain which describes 6 planes triming the textile to a unit cell.
void SetFibreDiameter(int iYarnType, double dValue, string Units="m")
void CheckUpVectors(int WarpIndex, bool Yarn=PATTERN3D_XYARN, bool bYarnsIndex=false) const
void AddYYarn(int x, PATTERN3D Pattern)
Add yarn of type XYARN or NOTYARN parallel to the Y axis.
void AssignDefaultDomain(bool bAddedDomainHeight=true)
Get the default domain and assign it as the domain.
void CalculateReedDesign(string Filename)
XYZ GetUpVector(XYZ CheckNodes[], bool bYarn) const
Gets an up vector for a pair of nodes.
int FindWarpAboveIndex(const vector< PATTERN3D > &Cell, int iIndex) const
virtual void SetupLayers(int iNumWarpLayers, int iNumWeftLayers, int iNumBinderLayers=1)
Setup the layers given a specified number of layers.
double GetYYarnHeights(int iIndex) const
Get the height of the yarn parallel to the Y axis, with given index.
void SetFibreDensity(int iYarnType, double dValue, string Units="kg/m^3")
Set the fibre density, i.e. the mass per unit volume of fibre.
void DeleteXLayers(int y, int iNumberLayers)
Delete given number of yarns parallel to the X axis, with given index y.
bool AdjustPowerEllipseSectionWidth(double &HeightReduction, double &MaxWidth, double TargetArea, CSectionPowerEllipse *YarnSection) const
Adjust section to target height whilst maintaining cross-sectional area.
bool CheckCells() const
Check that all cells are populated.
double GetAverageWeftYarnHeight() const
virtual ~CTextile3DWeave(void)
bool Valid() const
Check that the weave pattern contained in m_Pattern is valid.
void SetXYarnHeights(int iIndex, double dHeight)
Set the height of the yarn parallel to the X axis, with given index.
double GetHeight() const
Get the height of the unit cell.
void SetBinderYarnHeights(double dHeight)
Set the height of yarns parallel to the X axis in binder yarn positions.
void SwapPosition(int x, int y, int iLevel1, int iLevel2)
Swap the positions of two yarns in the patter with given index x, y and level iLevel1,...
virtual void ConvertToPatternDraft(int iWeftOrder=BOTTOM_TO_TOP)
void SetBinderYarnSpacings(double dWidth)
Set the spacing of yarns parallel to the X axis in binder yarn positions.
pair< int, int > GetCellCoordinates(int iIndex) const
virtual void FindMinMaxZ(double &dMinZ, double &dMaxZ)
Find max and min Z values for textile.
virtual string GetType() const
Derived class should return the class name.
double GetAverageYarnWidth() const
void SetYarnLinearDensity(int iYarnType, double dValue, string Units="kg/m")
Set the fibre linear density, i.e. the mass per unit length of fibre.
int GetNumYLayers(int x) const
Retreive the number of yarns parallel to the Y axis, with given index x.
double GetXYarnSpacings(int iIndex) const
Get the spacing of the yarn parallel to the X axis, with given index.
vector< CYarn * > GetYYarns(int iIndex)
int FindPrevYCellIndex(int Starti, int j, int k) const
Find next cell in x direction which isn't a noyarn, searching backwards.
CProperties m_Properties[3]
int FindWeftHeight(const vector< PATTERN3D > &Cell) const
CSectionPowerEllipse * GetWeftCrossSection(int WeftYarnIndex) const
Adjust cross section shapes to correct interference.
double GetYYarnWidths(int iIndex) const
Get the width of the yarn parallel to the Y axis, with given index.
double m_dMaxVolumeFraction
vector< bool > m_BinderPattern
virtual string GetDefaultName() const
Get the default name to assign to a textile.
void SetMaxVolFraction(double dVolFraction)
Set the maximum yarn volume fraction for use in refinement.
void SetBinderYarnWidths(double dWidth)
Set the width of yarns parallel to the X axis in binder yarn positions.
bool BinderYarns() const
Check if any binder yarns in weave.
double GetXYarnHeights(int iIndex) const
Get the height of the yarn parallel to the X axis, with given index.
void SetBinderRatio(int iBinderRatio)
Set the number of binder yarns grouped together.
void SetFibresPerYarn(int iYarnType, int iNumFibres)
Set the number of fibres per yarn.
int FindNextCellIndex(int index) const
Find next cell in y direction which isn't a binder yarn.
int GetNumXLayers(int y) const
Retreive the number of yarns parallel to the X axis, with given index y.
void SetWarpRatio(int iWarpRatio)
Set the number of warp yarns grouped together.
int FindNextYCellIndex(int Starti, int j, int k) const
Find next cell in x direction which isn't a noyarn.
void SetYYarnWidths(int iIndex, double dWidth)
Set the width of the yarn parallel to the Y axis, with given index.
double GetAverageWeftYarnWidth() const
virtual void SetupWeftRow(vector< int > &Layers, vector< int > &Row, int NumWarps, int Weft)
Set up row of pattern cells for one weft pattern using one row of weave pattern data and the layers p...
bool NoYarnCell(vector< PATTERN3D > &Cell)
vector< CYarn * > GetXYarns(int iIndex)
void SetXYarnWidths(int iIndex, double dWidth)
Set the width of the yarn parallel to the X axis, with given index.
void SetXYarnSpacings(int iIndex, double dSpacing)
Set the spacing of the yarn parallel to the X axis, with given index.
void SetThickness(double dThickness)
Set the thickness of the fabric.
bool IsBinderYarn(int index) const
Check if X yarn is binder or warp. Returns true if binder.
void SetWarpYarnHeights(double dHeight)
Set the height of yarns parallel to the X axis in warp yarn positions.
vector< YARNDATA > m_YYarnData
void AddBinderLayer()
Add yarns parallel to the X axis in binder yarn positions, no yarns in warp positions.
vector< vector< PATTERN3D > > m_Pattern
void SetYYarnHeights(int iIndex, double dHeight)
Set the height of the yarn parallel to the Y axis, with given index.
void SetWarpYarnSpacings(double dWidth)
Set the spacing of yarns parallel to the X axis in warp yarn positions.
CSection * GetCrossSection(int YarnIndex, int Node=-1) const
Gets the cross-section of a yarn, either constant or interp node, power elliptical sections.
void AddWarpLayer()
Add yarns parallel to the X axis in warp yarn positions, no yarns in binder positions.
void InsertWeftNode(CSection *YarnSection, double t, XYZ &WarpNode, int &CurrentNode, int WeftYarnIndex, double Offset, bool bInsert=true) const
void SetBinderPattern()
Setup the binder pattern from the warp and binder ratios.
CTextile3DWeave(int iNumXYarns, int iNumYYarns, double dXSpacing, double dYSpacing, double dXHeight, double dYHeight, bool bRefine=false)
Build a weave unit cell of given width, height, yarn spacing and fabric thickness.
void AddXLayers(int y, int iNumberLayers)
Add given number of yarns parallel to the X axis, with given index y.
void ReducePowerEllipseHeight(double &TargetArea, CSectionPowerEllipse *YarnSection) const
double GetXYarnGapSize(int iIndex) const
Get the gap size between two yarns parallel to the X axis, with given index.
void GetWarpYarnInfo(int &iNumBinderYarns, int &iNumWarpYarns, int &iBinderRatio, int &iWarpRatio, YARNDATA &AveWarp, YARNDATA &AveBinder) const
Retrieve number of warp and binder yarns and ratios.
void RemoveCell(int x, int y)
void SetFibreArea(int iYarnType, double dValue, string Units="m^2")
Set the area occupied by fibres in a yarn cross-section.
int GetXYarnIndex(int YarnInd)
Get the XYarn index (ie the y position) of a yarn given the yarn index.
void SetYarnHeights(double dHeight)
Set the height of all the yarns in the textile.
bool AdjustPowerEllipsePower(double &HeightReduction, double TargetArea, CSectionPowerEllipse *YarnSection, double MinPower) const
double GetXYarnWidths(int iIndex) const
Get the width of the yarn parallel to the X axis, with given index.
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.
virtual bool BuildTextile() const
Build the textile.
void DeleteYLayers(int x, int iNumberLayers)
Delete given number of yarns parallel to the Y axis, with given index x.
CPatternDraft m_PatternDraft
Class for generating pattern draft from weave pattern.
int AddWeftNodes(int CurrentNode, int XNode, int i, int j) const
const vector< PATTERN3D > & GetCell(int x, int y) const
void SetYarnWidths(double dWidth)
Set the width of all the yarns in the textile.
void SetResolution(int iResolution)
Set the resolution of the yarns.
CObjectContainer< CSectionMesh > m_pSectionMesh
double GetFibreArea(int iYarnType, string Units)
Get the area occupied by fibres given fibre diameter and number of fibres.
void SetGapSize(double dGapSize)
Set the size of the gap to leave between yarns when correcting interference.
void SetYYarnSpacings(int iIndex, double dSpacing)
Set the spacing of the yarn parallel to the Y axis, with given index.
Represents a textile cell containing yarns.
void RemoveDomain()
Remove the domain.
const CDomain * GetDomain() const
bool BuildTextileIfNeeded() const
Build the textile only if needed.
vector< CYarn > m_Yarns
Vector of yarns contained within this cell.
void AssignDomain(const CDomain &Domain)
Assign a domain to the textile, will be used by default to trim the domain.
string GetName() const
Get the name associated with this textile.
virtual void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType)
Used for saving data to XML.
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.
Represents a yarn consisting of master nodes, section and interpolation function.
Creates a section which is constant all along the yarn.
vector< XY > GetSection(const YARN_POSITION_INFORMATION PositionInfo, int iNumPoints, bool bEquiSpaced=false) const
This function must be implemented by derived classes.
Creates a section which is linearly interpolated between sections defined at the nodes.
const CSection & GetNodeSection(int iIndex) const
Namespace containing a series of customised math operations not found in the standard c++ library.
double Max(XYZ &Vector)
Get maximum element of vector and return it.
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.
XYZ Min(const XYZ &P1, const XYZ &P2)
Given two points, return a new point who's coordinates are the smaller of the two.
void AddExtensionIfMissing(std::string &Filename, std::string Extension)
Adds an extension to the filename if it is missing otherwise do nothing (e.g. picture -> picture....
Struct for representing points in 2D space.
Struct for representing points in 3D space.
Data structure to keep track of yarn parameters.