TexGen
TextileDecoupledLToL.cpp
Go to the documentation of this file.
1/*=============================================================================
2TexGen: Geometric textile modeller.
3Copyright (C) 2021 Louise Brown
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License
6as published by the Free Software Foundation; either version 2
7of the License, or (at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17=============================================================================*/
18
19
20#include "PrecompiledHeaders.h"
22
23using namespace TexGen;
24
25CTextileDecoupledLToL::CTextileDecoupledLToL(int iNumXYarns, int iNumYYarns, double dXSpacing, double dYSpacing, double dXHeight, double dYHeight, int iNumBinderLayers, bool bShapeBinders)
26 : CTextileLayerToLayer(iNumXYarns, iNumYYarns, dXSpacing, dYSpacing, dXHeight, dYHeight, iNumBinderLayers, bShapeBinders)
27{
28
29}
30
32 : CTextileLayerToLayer(Element)
33{
34 //Element.Attribute("BinderLayers", &m_iNumBinderLayers);
35}
36
38{
39}
40
41void CTextileDecoupledLToL::PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType)
42{
44}
45
46void CTextileDecoupledLToL::SetBinderPosition(int x, int y, vector<int> zOffsets)
47{
48 vector<PATTERN3D> &Cell = GetCell(x, y);
49
50 vector<int> BinderPositions;
51 int size = Cell.size();
52 vector<int>::iterator itzOffsets;
53 int BinderPos;
54 int LastPos = size;
55
56 // Convert offsets into cell indices (cells numbered from bottom)
57 for (itzOffsets = zOffsets.begin(); itzOffsets != zOffsets.end(); itzOffsets++)
58 {
59 BinderPos = (size - 1) - *itzOffsets * 2;
60 if (BinderPos >= LastPos)
61 {
62 TGERROR("Binder offsets incorrectly ordered at position " << x <<", " << y << ", binder yarns positions not set");
63 return;
64 }
65 BinderPositions.push_back(BinderPos);
66 LastPos = BinderPos;
67 }
68
69 // Set cells to binder yarn to correspond to offsets
70 int BinderNum = 0;
71 for (int j = size-1; j >= 0; j -= 2)
72 {
73 if (BinderNum < m_iNumBinderLayers && BinderPositions[BinderNum] == j)
74 {
75 Cell[j] = PATTERN3D_XYARN;
76 BinderNum++;
77 }
78 else
79 {
80 Cell[j] = PATTERN3D_NOYARN;
81 }
82 }
83}
84
86{
88 return false;
89
93 return true;
94}
95
97{
98 for (int j = 0; j < m_iNumXYarns; ++j)
99 {
100 if (IsBinderYarn(j))
101 {
102 for (int Height = 0; Height < m_iNumBinderLayers; ++Height)
103 {
104 int CurrentNode = 0;
105 for (int i = 0; i < m_iNumYYarns; ++i)
106 {
107 CurrentNode = AddBinderNodes(CurrentNode, i, j, Height);
108 CurrentNode++;
109 }
110
111 }
112 }
113 }
114}
115
117{
118 vector<int> BinderIndices;
119 vector<int>::iterator itBinder;
120 int BinderIndex;
121
122 for (int j = 0; j < m_iNumXYarns; ++j)
123 {
124 if (IsBinderYarn(j))
125 {
126 for (int Height = 0; Height < m_iNumBinderLayers; ++Height)
127 {
128 const vector<PATTERN3D> &Cell = GetCell(0, j);
129 int iIndex = FindBinderHeight(Cell, Height);
130 BinderIndex = GetYarnIndex(0, j, iIndex);
131 BinderIndices.push_back(BinderIndex);
132 }
133 }
134 }
135
136 for (itBinder = BinderIndices.begin(); itBinder != BinderIndices.end(); itBinder++)
137 {
138 CTextileLayerToLayer::CheckUpVectors(*itBinder, true, true);
139 }
140}
141
142int CTextileDecoupledLToL::FindBinderHeight(const vector<PATTERN3D>& Cell, int Height) const
143{
144 int i = Cell.size() - 1;
145 int CurrentHeight = 0;
146 while (i > 0)
147 {
148 //finds top binder
149 if (Cell[i] == PATTERN3D_XYARN)
150 {
151 if (CurrentHeight == Height)
152 return i;
153 CurrentHeight++;
154 }
155 --i;
156 }
157 return i;
158}
#define TGERROR(MESSAGE)
Macros used to report the file name and line number to the TexGenError and TexGenLog functions.
Definition: Logger.h:29
int GetYarnIndex(int x, int y, int z) const
void CheckUpVectors(int WarpIndex, bool Yarn=PATTERN3D_XYARN, bool bYarnsIndex=false) const
bool IsBinderYarn(int index) const
Check if X yarn is binder or warp. Returns true if binder.
const vector< PATTERN3D > & GetCell(int x, int y) const
void ShapeBinderYarns() const
Add extra nodes to binder layers to conform to shape of adjacent weft yarns.
void CheckUpVectors() const
Ensure that up vectors are not coincident with tangent.
int FindBinderHeight(const vector< PATTERN3D > &Cell, int Height) const
Find cell index of a given binder yarn given its height.
void SetBinderPosition(int x, int y, vector< int > zOffsets)
Sets the vertical positions of the binder yarns.
virtual void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType)
Used for saving data to XML.
CTextileDecoupledLToL(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.
bool BuildTextile() const
Build the textile yarns from the cell data.
virtual void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType)
Used for saving data to XML.
int AddBinderNodes(int CurrentNode, int i, int j, int Height) const
Add extra nodes to binder yarns to match shape of adjacent weft yarns.
Namespace containing a series of customised math operations not found in the standard c++ library.
OUTPUT_TYPE
Definition: Misc.h:105
@ PATTERN3D_NOYARN
@ PATTERN3D_XYARN