TexGen
TextileWeave3D.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 "TextileWeave3D.h"
22using namespace TexGen;
23
24CTextileWeave3D::CTextileWeave3D(int iWidth, int iHeight, double dSpacing, double dThickness)
25: CTextileWeave(iWidth, iHeight, dSpacing, dThickness)
26{
27}
28
30{
31}
32
34: CTextileWeave(Element)
35{
36
37}
38
39void CTextileWeave3D::PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType)
40{
41 CTextileWeave::PopulateTiXmlElement(Element, OutputType);
42}
43
45{
46 return "3DWeave(W:" + stringify(m_iNumYYarns) + ",H:" + stringify(m_iNumXYarns) + ")";
47}
48
49void CTextileWeave3D::AddYLayers(int x, int iNumberLayers)
50{
51 if (x<0 || x>=m_iNumYYarns)
52 {
53 TGERROR("Unable to add yarn layer, index out of range: " << x);
54 return;
55 }
56 int i, j;
57 for (i=0; i<m_iNumXYarns; ++i)
58 {
59 for (j=0; j<iNumberLayers; ++j)
60 GetCell(x, i).push_back(PATTERN_YYARN);
61 }
62 m_bNeedsBuilding = true;
63}
64
65void CTextileWeave3D::AddXLayers(int y, int iNumberLayers)
66{
67 if (y<0 || y>=m_iNumXYarns)
68 {
69 TGERROR("Unable to add yarn layer, index out of range: " << y);
70 return;
71 }
72 int i, j;
73 for (i=0; i<m_iNumYYarns; ++i)
74 {
75 for (j=0; j<iNumberLayers; ++j)
76 GetCell(i, y).push_back(PATTERN_XYARN);
77 }
78 m_bNeedsBuilding = true;
79}
80
81void CTextileWeave3D::AddYLayers(int iNumberLayers)
82{
83 int i;
84 for (i=0; i<m_iNumYYarns; ++i)
85 {
86 AddYLayers(i, iNumberLayers);
87 }
88}
89
90void CTextileWeave3D::AddXLayers(int iNumberLayers)
91{
92 int i;
93 for (i=0; i<m_iNumXYarns; ++i)
94 {
95 AddXLayers(i, iNumberLayers);
96 }
97}
98
99void CTextileWeave3D::DeleteYLayers(int x, int iNumberLayers)
100{
101 if (x<0 || x>=m_iNumYYarns)
102 {
103 TGERROR("Unable to delete yarn layer, index out of range: " << x);
104 return;
105 }
106 int i, j;
107 vector<bool>::reverse_iterator itCell;
108 for (i=0; i<m_iNumXYarns; ++i)
109 {
110 for (j=0; j<iNumberLayers; ++j)
111 {
112 vector<bool> &Cell = GetCell(x, i);
113 itCell = find(Cell.rbegin(), Cell.rend(), (bool)PATTERN_YYARN);
114 if (itCell != Cell.rend())
115 {
116 Cell.erase(itCell.base()-1);
117 }
118 }
119 }
120 m_bNeedsBuilding = true;
121}
122
123void CTextileWeave3D::DeleteXLayers(int y, int iNumberLayers)
124{
125 if (y<0 || y>=m_iNumXYarns)
126 {
127 TGERROR("Unable to delete yarn layer, index out of range: " << y);
128 return;
129 }
130 int i, j;
131 vector<bool>::reverse_iterator itCell;
132 for (i=0; i<m_iNumYYarns; ++i)
133 {
134 for (j=0; j<iNumberLayers; ++j)
135 {
136 vector<bool> &Cell = GetCell(i, y);
137 itCell = find(Cell.rbegin(), Cell.rend(), (bool)PATTERN_XYARN);
138 if (itCell != Cell.rend())
139 {
140 Cell.erase(itCell.base()-1);
141 }
142 }
143 }
144 m_bNeedsBuilding = true;
145}
146
147void CTextileWeave3D::DeleteYLayers(int iNumberLayers)
148{
149 int i;
150 for (i=0; i<m_iNumYYarns; ++i)
151 {
152 DeleteYLayers(i, iNumberLayers);
153 }
154}
155
156void CTextileWeave3D::DeleteXLayers(int iNumberLayers)
157{
158 int i;
159 for (i=0; i<m_iNumXYarns; ++i)
160 {
161 DeleteXLayers(i, iNumberLayers);
162 }
163}
164
166{
167 const vector<bool> &Cell = GetCell(x, 0);
168 return count(Cell.begin(), Cell.end(), (bool)PATTERN_YYARN);
169}
170
172{
173 const vector<bool> &Cell = GetCell(0, y);
174 return count(Cell.begin(), Cell.end(), (bool)PATTERN_XYARN);
175}
176
178{
179 int i, j;
180 int iMaxLayers = 0;
181 for (i=0; i<m_iNumYYarns; ++i)
182 {
183 for (j=0; j<m_iNumXYarns; ++j)
184 {
185 iMaxLayers = max(iMaxLayers, (int)GetCell(i, j).size());
186 }
187 }
188 return iMaxLayers;
189}
190
191void CTextileWeave3D::PushDown(int x, int y, int iLevels)
192{
193 if (x<0 || x>=m_iNumYYarns || y<0 || y>=m_iNumXYarns)
194 {
195 TGERROR("Unable to push down, index out of range: " << x << ", " << y);
196 return;
197 }
198 vector<bool> &Cell = GetCell(x, y);
199 int i;
200 for (i=0; i<iLevels; ++i)
201 {
202 bool bBottom = *Cell.begin();
203 Cell.erase(Cell.begin());
204 Cell.push_back(bBottom);
205 }
206 m_bNeedsBuilding = true;
207}
208
209void CTextileWeave3D::PushUp(int x, int y, int iLevels)
210{
211 if (x<0 || x>=m_iNumYYarns || y<0 || y>=m_iNumXYarns)
212 {
213 TGERROR("Unable to push up, index out of range: " << x << ", " << y);
214 return;
215 }
216 vector<bool> &Cell = GetCell(x, y);
217 int i;
218 vector<bool>::iterator itTop;
219 for (i=0; i<iLevels; ++i)
220 {
221 bool bTop = Cell[Cell.size()-1];
222 Cell.pop_back();
223 Cell.insert(Cell.begin(), bTop);
224 }
225 m_bNeedsBuilding = true;
226}
227
228void CTextileWeave3D::PushYDown(int x, int iLevels)
229{
230 int i;
231 for (i=0; i<m_iNumXYarns; ++i)
232 {
233 PushDown(x, i, iLevels);
234 }
235}
236
237void CTextileWeave3D::PushYUp(int x, int iLevels)
238{
239 int i;
240 for (i=0; i<m_iNumXYarns; ++i)
241 {
242 PushUp(x, i, iLevels);
243 }
244}
245
246void CTextileWeave3D::PushXDown(int y, int iLevels)
247{
248 int i;
249 for (i=0; i<m_iNumYYarns; ++i)
250 {
251 PushDown(i, y, iLevels);
252 }
253}
254
255void CTextileWeave3D::PushXUp(int y, int iLevels)
256{
257 int i;
258 for (i=0; i<m_iNumYYarns; ++i)
259 {
260 PushUp(i, y, iLevels);
261 }
262}
263
264void CTextileWeave3D::SwapPosition(int x, int y, int iLevel1, int iLevel2)
265{
266 if (x<0 || x>=m_iNumYYarns || y<0 || y>=m_iNumXYarns)
267 {
268 TGERROR("Unable to swap position, index out of range: " << x << ", " << y);
269 return;
270 }
271 vector<bool> &Cell = GetCell(x, y);
272 if (iLevel1 < 0 || iLevel1 >= (int)Cell.size())
273 {
274 TGERROR("Unable to swap position, level out of range: " << iLevel1);
275 return;
276 }
277 if (iLevel2 < 0 || iLevel2 >= (int)Cell.size())
278 {
279 TGERROR("Unable to swap position, level out of range: " << iLevel2);
280 return;
281 }
282 bool bTemp;
283 bTemp = Cell[iLevel1];
284 Cell[iLevel1] = Cell[iLevel2];
285 Cell[iLevel2] = bTemp;
286 m_bNeedsBuilding = true;
287}
288
289
290
291
292
293
294
#define TGERROR(MESSAGE)
Macros used to report the file name and line number to the TexGenError and TexGenLog functions.
Definition: Logger.h:29
bool m_bNeedsBuilding
Variable which keeps track of wether the textile needs building or not.
Definition: Textile.h:330
int GetNumXLayers(int y) const
Retreive the number of yarns parallel to the X axis, with given index y.
void PushYUp(int x, int iLevels=1)
Push up all yarns parallel to the Y axis in the pattern by given number of levels with given index x.
void DeleteYLayers(int x, int iNumberLayers)
Delete given number of yarns parallel to the Y axis, with given index x.
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,...
int GetMaxNumLayers() const
Retreive the maximum number of layers at any crossover.
CTextileWeave3D(int iWidth, int iHeight, double dSpacing, double dThickness)
void PushXDown(int y, int iLevels=1)
Push down all yarns parallel to the X axis in the pattern by given number of levels with given index ...
void PushDown(int x, int y, int iLevels=1)
Push down all yarns in the pattern by given number of levels with given index x, y.
void DeleteXLayers(int y, int iNumberLayers)
Delete given number of yarns parallel to the X axis, with given index y.
void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType)
Used for saving data to XML.
void AddYLayers(int x, int iNumberLayers)
Add given number of yarns parallel to the Y axis, with given index x.
void PushYDown(int x, int iLevels=1)
Push down all yarns parallel to the Y axis in the pattern by given number of levels with given index ...
void PushXUp(int y, int iLevels=1)
Push up all yarns parallel to the X axis in the pattern by given number of levels with given index y.
void PushUp(int x, int y, int iLevels=1)
Push up all yarns in the pattern by given number of levels with given index x, y.
string GetDefaultName() const
Get the default name to assign to a textile.
void AddXLayers(int y, int iNumberLayers)
Add given number of yarns parallel to the X axis, with given index y.
int GetNumYLayers(int x) const
Retreive the number of yarns parallel to the Y axis, with given index x.
Represents a woven textile.
Definition: TextileWeave.h:41
const vector< PATTERN2D > & GetCell(int x, int y) const
virtual void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType)
Used for saving data to XML.
Namespace containing a series of customised math operations not found in the standard c++ library.
@ PATTERN_XYARN
Definition: TextileWeave.h:33
@ PATTERN_YYARN
Definition: TextileWeave.h:34
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