Blender  V2.93
IndexedFaceSet.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
22 #include "IndexedFaceSet.h"
23 
24 namespace Freestyle {
25 
27 {
28  _Vertices = nullptr;
29  _Normals = nullptr;
30  _FrsMaterials = nullptr;
31  _TexCoords = nullptr;
32  _FaceEdgeMarks = nullptr;
33  _VSize = 0;
34  _NSize = 0;
35  _MSize = 0;
36  _TSize = 0;
37  _NumFaces = 0;
38  _NumVertexPerFace = nullptr;
39  _FaceStyle = nullptr;
40  _VIndices = nullptr;
41  _VISize = 0;
42  _NIndices = nullptr;
43  _NISize = 0;
44  _MIndices = nullptr;
45  _MISize = 0;
46  _TIndices = nullptr;
47  _TISize = 0;
48 }
49 
51  unsigned iVSize,
52  float *iNormals,
53  unsigned iNSize,
54  FrsMaterial **iMaterials,
55  unsigned iMSize,
56  float *iTexCoords,
57  unsigned iTSize,
58  unsigned iNumFaces,
59  unsigned *iNumVertexPerFace,
60  TRIANGLES_STYLE *iFaceStyle,
61  FaceEdgeMark *iFaceEdgeMarks,
62  unsigned *iVIndices,
63  unsigned iVISize,
64  unsigned *iNIndices,
65  unsigned iNISize,
66  unsigned *iMIndices,
67  unsigned iMISize,
68  unsigned *iTIndices,
69  unsigned iTISize,
70  unsigned iCopy)
71 {
72  if (1 == iCopy) {
73  _VSize = iVSize;
74  _Vertices = new float[_VSize];
75  memcpy(_Vertices, iVertices, iVSize * sizeof(float));
76 
77  _NSize = iNSize;
78  _Normals = new float[_NSize];
79  memcpy(_Normals, iNormals, iNSize * sizeof(float));
80 
81  _MSize = iMSize;
82  _FrsMaterials = nullptr;
83  if (iMaterials) {
85  for (unsigned int i = 0; i < _MSize; ++i) {
86  _FrsMaterials[i] = new FrsMaterial(*(iMaterials[i]));
87  }
88  }
89  _TSize = iTSize;
90  _TexCoords = nullptr;
91  if (_TSize) {
92  _TexCoords = new float[_TSize];
93  memcpy(_TexCoords, iTexCoords, iTSize * sizeof(float));
94  }
95 
96  _NumFaces = iNumFaces;
97  _NumVertexPerFace = new unsigned[_NumFaces];
98  memcpy(_NumVertexPerFace, iNumVertexPerFace, _NumFaces * sizeof(unsigned));
99 
101  memcpy(_FaceStyle, iFaceStyle, _NumFaces * sizeof(TRIANGLES_STYLE));
102 
104  memcpy(_FaceEdgeMarks, iFaceEdgeMarks, _NumFaces * sizeof(FaceEdgeMark));
105 
106  _VISize = iVISize;
107  _VIndices = new unsigned[_VISize];
108  memcpy(_VIndices, iVIndices, _VISize * sizeof(unsigned));
109 
110  _NISize = iNISize;
111  _NIndices = new unsigned[_NISize];
112  memcpy(_NIndices, iNIndices, _NISize * sizeof(unsigned));
113 
114  _MISize = iMISize;
115  _MIndices = nullptr;
116  if (iMIndices) {
117  _MIndices = new unsigned[_MISize];
118  memcpy(_MIndices, iMIndices, _MISize * sizeof(unsigned));
119  }
120  _TISize = iTISize;
121  _TIndices = nullptr;
122  if (_TISize) {
123  _TIndices = new unsigned[_TISize];
124  memcpy(_TIndices, iTIndices, _TISize * sizeof(unsigned));
125  }
126  }
127  else {
128  _VSize = iVSize;
129  _Vertices = iVertices;
130 
131  _NSize = iNSize;
132  _Normals = iNormals;
133 
134  _MSize = iMSize;
135  _FrsMaterials = nullptr;
136  if (iMaterials) {
137  _FrsMaterials = iMaterials;
138  }
139 
140  _TSize = iTSize;
141  _TexCoords = iTexCoords;
142 
143  _NumFaces = iNumFaces;
144  _NumVertexPerFace = iNumVertexPerFace;
145  _FaceStyle = iFaceStyle;
146  _FaceEdgeMarks = iFaceEdgeMarks;
147 
148  _VISize = iVISize;
149  _VIndices = iVIndices;
150 
151  _NISize = iNISize;
152  _NIndices = iNIndices;
153 
154  _MISize = iMISize;
155  _MIndices = nullptr;
156  if (iMISize) {
157  _MIndices = iMIndices;
158  }
159 
160  _TISize = iTISize;
161  _TIndices = iTIndices;
162  }
163 }
164 
166 {
167  _VSize = iBrother.vsize();
168  _Vertices = new float[_VSize];
169  memcpy(_Vertices, iBrother.vertices(), _VSize * sizeof(float));
170 
171  _NSize = iBrother.nsize();
172  _Normals = new float[_NSize];
173  memcpy(_Normals, iBrother.normals(), _NSize * sizeof(float));
174 
175  _MSize = iBrother.msize();
176  if (_MSize) {
178  for (unsigned int i = 0; i < _MSize; ++i) {
179  _FrsMaterials[i] = new FrsMaterial(*(iBrother._FrsMaterials[i]));
180  }
181  }
182  else {
183  _FrsMaterials = nullptr;
184  }
185 
186  _TSize = iBrother.tsize();
187  _TexCoords = nullptr;
188  if (_TSize) {
189  _TexCoords = new float[_TSize];
190  memcpy(_TexCoords, iBrother.texCoords(), _TSize * sizeof(float));
191  }
192 
193  _NumFaces = iBrother.numFaces();
194  _NumVertexPerFace = new unsigned[_NumFaces];
195  memcpy(_NumVertexPerFace, iBrother.numVertexPerFaces(), _NumFaces * sizeof(unsigned));
196 
198  memcpy(_FaceStyle, iBrother.trianglesStyle(), _NumFaces * sizeof(TRIANGLES_STYLE));
199 
201  memcpy(_FaceEdgeMarks, iBrother.faceEdgeMarks(), _NumFaces * sizeof(FaceEdgeMark));
202 
203  _VISize = iBrother.visize();
204  _VIndices = new unsigned[_VISize];
205  memcpy(_VIndices, iBrother.vindices(), _VISize * sizeof(unsigned));
206 
207  _NISize = iBrother.nisize();
208  _NIndices = new unsigned[_NISize];
209  memcpy(_NIndices, iBrother.nindices(), _NISize * sizeof(unsigned));
210 
211  _MISize = iBrother.misize();
212  if (_MISize) {
213  _MIndices = new unsigned[_MISize];
214  memcpy(_MIndices, iBrother.mindices(), _MISize * sizeof(unsigned));
215  }
216  else {
217  _MIndices = nullptr;
218  }
219 
220  _TISize = iBrother.tisize();
221  _TIndices = nullptr;
222  if (_TISize) {
223  _TIndices = new unsigned[_TISize];
224  memcpy(_TIndices, iBrother.tindices(), _TISize * sizeof(unsigned));
225  }
226 }
227 
229 {
230  if (nullptr != _Vertices) {
231  delete[] _Vertices;
232  _Vertices = nullptr;
233  }
234 
235  if (nullptr != _Normals) {
236  delete[] _Normals;
237  _Normals = nullptr;
238  }
239 
240  if (nullptr != _FrsMaterials) {
241  for (unsigned int i = 0; i < _MSize; ++i) {
242  delete _FrsMaterials[i];
243  }
244  delete[] _FrsMaterials;
245  _FrsMaterials = nullptr;
246  }
247 
248  if (nullptr != _TexCoords) {
249  delete[] _TexCoords;
250  _TexCoords = nullptr;
251  }
252 
253  if (nullptr != _NumVertexPerFace) {
254  delete[] _NumVertexPerFace;
255  _NumVertexPerFace = nullptr;
256  }
257 
258  if (nullptr != _FaceStyle) {
259  delete[] _FaceStyle;
260  _FaceStyle = nullptr;
261  }
262 
263  if (nullptr != _FaceEdgeMarks) {
264  delete[] _FaceEdgeMarks;
265  _FaceEdgeMarks = nullptr;
266  }
267 
268  if (nullptr != _VIndices) {
269  delete[] _VIndices;
270  _VIndices = nullptr;
271  }
272 
273  if (nullptr != _NIndices) {
274  delete[] _NIndices;
275  _NIndices = nullptr;
276  }
277 
278  if (nullptr != _MIndices) {
279  delete[] _MIndices;
280  _MIndices = nullptr;
281  }
282  if (nullptr != _TIndices) {
283  delete[] _TIndices;
284  _TIndices = nullptr;
285  }
286 }
287 
289 {
290  Rep::accept(v);
291  v.visitIndexedFaceSet(*this);
292 }
293 
295 {
296  float XMax = _Vertices[0];
297  float YMax = _Vertices[1];
298  float ZMax = _Vertices[2];
299 
300  float XMin = _Vertices[0];
301  float YMin = _Vertices[1];
302  float ZMin = _Vertices[2];
303 
304  // parse all the coordinates to find the Xmax, YMax, ZMax
305  float *v = _Vertices;
306 
307  for (unsigned int i = 0; i < (_VSize / 3); ++i) {
308  if (*v > XMax) {
309  XMax = *v;
310  }
311  if (*v < XMin) {
312  XMin = *v;
313  }
314  ++v;
315 
316  if (*v > YMax) {
317  YMax = *v;
318  }
319  if (*v < YMin) {
320  YMin = *v;
321  }
322  ++v;
323 
324  if (*v > ZMax) {
325  ZMax = *v;
326  }
327  if (*v < ZMin) {
328  ZMin = *v;
329  }
330  ++v;
331  }
332 
333  setBBox(BBox<Vec3f>(Vec3f(XMin, YMin, ZMin), Vec3f(XMax, YMax, ZMax)));
334 }
335 
336 } /* namespace Freestyle */
A Set of indexed faces to represent a surface object.
ATTR_WARN_UNUSED_RESULT const BMVert * v
virtual const unsigned nisize() const
virtual const unsigned * nindices() const
virtual const unsigned tisize() const
virtual const float * normals() const
virtual const unsigned vsize() const
virtual const float * texCoords() const
virtual const unsigned char * faceEdgeMarks() const
virtual void accept(SceneVisitor &v)
virtual const unsigned numFaces() const
virtual const unsigned * vindices() const
virtual const unsigned * mindices() const
virtual const unsigned tsize() const
FaceEdgeMark * _FaceEdgeMarks
FrsMaterial ** _FrsMaterials
virtual const unsigned * numVertexPerFaces() const
virtual const unsigned nsize() const
virtual const unsigned visize() const
virtual const unsigned * tindices() const
virtual const float * vertices() const
virtual const TRIANGLES_STYLE * trianglesStyle() const
virtual const unsigned misize() const
virtual const unsigned msize() const
TRIANGLES_STYLE * _FaceStyle
virtual void accept(SceneVisitor &v)
Definition: Rep.h:108
virtual void setBBox(const BBox< Vec3f > &iBox)
Definition: Rep.h:149
struct Vec3f Vec3f
inherits from class Rep
Definition: AppCanvas.cpp:32