Blender V4.3
IndexedFaceSet.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10#include "IndexedFaceSet.h"
11
12#include "BLI_sys_types.h"
13
14namespace Freestyle {
15
17{
18 _Vertices = nullptr;
19 _Normals = nullptr;
20 _FrsMaterials = nullptr;
21 _TexCoords = nullptr;
22 _FaceEdgeMarks = nullptr;
23 _VSize = 0;
24 _NSize = 0;
25 _MSize = 0;
26 _TSize = 0;
27 _NumFaces = 0;
28 _NumVertexPerFace = nullptr;
29 _FaceStyle = nullptr;
30 _VIndices = nullptr;
31 _VISize = 0;
32 _NIndices = nullptr;
33 _NISize = 0;
34 _MIndices = nullptr;
35 _MISize = 0;
36 _TIndices = nullptr;
37 _TISize = 0;
38}
39
41 uint iVSize,
42 float *iNormals,
43 uint iNSize,
44 FrsMaterial **iMaterials,
45 uint iMSize,
46 float *iTexCoords,
47 uint iTSize,
48 uint iNumFaces,
49 uint *iNumVertexPerFace,
50 TRIANGLES_STYLE *iFaceStyle,
51 FaceEdgeMark *iFaceEdgeMarks,
52 uint *iVIndices,
53 uint iVISize,
54 uint *iNIndices,
55 uint iNISize,
56 uint *iMIndices,
57 uint iMISize,
58 uint *iTIndices,
59 uint iTISize,
60 uint iCopy)
61{
62 if (1 == iCopy) {
63 _VSize = iVSize;
64 _Vertices = new float[_VSize];
65 memcpy(_Vertices, iVertices, iVSize * sizeof(float));
66
67 _NSize = iNSize;
68 _Normals = new float[_NSize];
69 memcpy(_Normals, iNormals, iNSize * sizeof(float));
70
71 _MSize = iMSize;
72 _FrsMaterials = nullptr;
73 if (iMaterials) {
75 for (uint i = 0; i < _MSize; ++i) {
76 _FrsMaterials[i] = new FrsMaterial(*(iMaterials[i]));
77 }
78 }
79 _TSize = iTSize;
80 _TexCoords = nullptr;
81 if (_TSize) {
82 _TexCoords = new float[_TSize];
83 memcpy(_TexCoords, iTexCoords, iTSize * sizeof(float));
84 }
85
86 _NumFaces = iNumFaces;
88 memcpy(_NumVertexPerFace, iNumVertexPerFace, _NumFaces * sizeof(uint));
89
91 memcpy(_FaceStyle, iFaceStyle, _NumFaces * sizeof(TRIANGLES_STYLE));
92
94 memcpy(_FaceEdgeMarks, iFaceEdgeMarks, _NumFaces * sizeof(FaceEdgeMark));
95
96 _VISize = iVISize;
97 _VIndices = new uint[_VISize];
98 memcpy(_VIndices, iVIndices, _VISize * sizeof(uint));
99
100 _NISize = iNISize;
101 _NIndices = new uint[_NISize];
102 memcpy(_NIndices, iNIndices, _NISize * sizeof(uint));
103
104 _MISize = iMISize;
105 _MIndices = nullptr;
106 if (iMIndices) {
107 _MIndices = new uint[_MISize];
108 memcpy(_MIndices, iMIndices, _MISize * sizeof(uint));
109 }
110 _TISize = iTISize;
111 _TIndices = nullptr;
112 if (_TISize) {
113 _TIndices = new uint[_TISize];
114 memcpy(_TIndices, iTIndices, _TISize * sizeof(uint));
115 }
116 }
117 else {
118 _VSize = iVSize;
119 _Vertices = iVertices;
120
121 _NSize = iNSize;
122 _Normals = iNormals;
123
124 _MSize = iMSize;
125 _FrsMaterials = nullptr;
126 if (iMaterials) {
127 _FrsMaterials = iMaterials;
128 }
129
130 _TSize = iTSize;
131 _TexCoords = iTexCoords;
132
133 _NumFaces = iNumFaces;
134 _NumVertexPerFace = iNumVertexPerFace;
135 _FaceStyle = iFaceStyle;
136 _FaceEdgeMarks = iFaceEdgeMarks;
137
138 _VISize = iVISize;
139 _VIndices = iVIndices;
140
141 _NISize = iNISize;
142 _NIndices = iNIndices;
143
144 _MISize = iMISize;
145 _MIndices = nullptr;
146 if (iMISize) {
147 _MIndices = iMIndices;
148 }
149
150 _TISize = iTISize;
151 _TIndices = iTIndices;
152 }
153}
154
156{
157 _VSize = iBrother.vsize();
158 _Vertices = new float[_VSize];
159 memcpy(_Vertices, iBrother.vertices(), _VSize * sizeof(float));
160
161 _NSize = iBrother.nsize();
162 _Normals = new float[_NSize];
163 memcpy(_Normals, iBrother.normals(), _NSize * sizeof(float));
164
165 _MSize = iBrother.msize();
166 if (_MSize) {
168 for (uint i = 0; i < _MSize; ++i) {
169 _FrsMaterials[i] = new FrsMaterial(*(iBrother._FrsMaterials[i]));
170 }
171 }
172 else {
173 _FrsMaterials = nullptr;
174 }
175
176 _TSize = iBrother.tsize();
177 _TexCoords = nullptr;
178 if (_TSize) {
179 _TexCoords = new float[_TSize];
180 memcpy(_TexCoords, iBrother.texCoords(), _TSize * sizeof(float));
181 }
182
183 _NumFaces = iBrother.numFaces();
185 memcpy(_NumVertexPerFace, iBrother.numVertexPerFaces(), _NumFaces * sizeof(uint));
186
188 memcpy(_FaceStyle, iBrother.trianglesStyle(), _NumFaces * sizeof(TRIANGLES_STYLE));
189
191 memcpy(_FaceEdgeMarks, iBrother.faceEdgeMarks(), _NumFaces * sizeof(FaceEdgeMark));
192
193 _VISize = iBrother.visize();
194 _VIndices = new uint[_VISize];
195 memcpy(_VIndices, iBrother.vindices(), _VISize * sizeof(uint));
196
197 _NISize = iBrother.nisize();
198 _NIndices = new uint[_NISize];
199 memcpy(_NIndices, iBrother.nindices(), _NISize * sizeof(uint));
200
201 _MISize = iBrother.misize();
202 if (_MISize) {
203 _MIndices = new uint[_MISize];
204 memcpy(_MIndices, iBrother.mindices(), _MISize * sizeof(uint));
205 }
206 else {
207 _MIndices = nullptr;
208 }
209
210 _TISize = iBrother.tisize();
211 _TIndices = nullptr;
212 if (_TISize) {
213 _TIndices = new uint[_TISize];
214 memcpy(_TIndices, iBrother.tindices(), _TISize * sizeof(uint));
215 }
216}
217
219{
220 if (nullptr != _Vertices) {
221 delete[] _Vertices;
222 _Vertices = nullptr;
223 }
224
225 if (nullptr != _Normals) {
226 delete[] _Normals;
227 _Normals = nullptr;
228 }
229
230 if (nullptr != _FrsMaterials) {
231 for (uint i = 0; i < _MSize; ++i) {
232 delete _FrsMaterials[i];
233 }
234 delete[] _FrsMaterials;
235 _FrsMaterials = nullptr;
236 }
237
238 if (nullptr != _TexCoords) {
239 delete[] _TexCoords;
240 _TexCoords = nullptr;
241 }
242
243 if (nullptr != _NumVertexPerFace) {
244 delete[] _NumVertexPerFace;
245 _NumVertexPerFace = nullptr;
246 }
247
248 if (nullptr != _FaceStyle) {
249 delete[] _FaceStyle;
250 _FaceStyle = nullptr;
251 }
252
253 if (nullptr != _FaceEdgeMarks) {
254 delete[] _FaceEdgeMarks;
255 _FaceEdgeMarks = nullptr;
256 }
257
258 if (nullptr != _VIndices) {
259 delete[] _VIndices;
260 _VIndices = nullptr;
261 }
262
263 if (nullptr != _NIndices) {
264 delete[] _NIndices;
265 _NIndices = nullptr;
266 }
267
268 if (nullptr != _MIndices) {
269 delete[] _MIndices;
270 _MIndices = nullptr;
271 }
272 if (nullptr != _TIndices) {
273 delete[] _TIndices;
274 _TIndices = nullptr;
275 }
276}
277
279{
280 Rep::accept(v);
281 v.visitIndexedFaceSet(*this);
282}
283
285{
286 float XMax = _Vertices[0];
287 float YMax = _Vertices[1];
288 float ZMax = _Vertices[2];
289
290 float XMin = _Vertices[0];
291 float YMin = _Vertices[1];
292 float ZMin = _Vertices[2];
293
294 // parse all the coordinates to find the Xmax, YMax, ZMax
295 float *v = _Vertices;
296
297 for (uint i = 0; i < (_VSize / 3); ++i) {
298 if (*v > XMax) {
299 XMax = *v;
300 }
301 if (*v < XMin) {
302 XMin = *v;
303 }
304 ++v;
305
306 if (*v > YMax) {
307 YMax = *v;
308 }
309 if (*v < YMin) {
310 YMin = *v;
311 }
312 ++v;
313
314 if (*v > ZMax) {
315 ZMax = *v;
316 }
317 if (*v < ZMin) {
318 ZMin = *v;
319 }
320 ++v;
321 }
322
323 setBBox(BBox<Vec3f>(Vec3f(XMin, YMin, ZMin), Vec3f(XMax, YMax, ZMax)));
324}
325
326} /* namespace Freestyle */
unsigned int uint
A Set of indexed faces to represent a surface object.
ATTR_WARN_UNUSED_RESULT const BMVert * v
virtual const uint tisize() const
virtual const uint vsize() const
virtual const uint misize() const
virtual const uint visize() const
virtual const float * vertices() const
virtual const uint * tindices() const
virtual const uchar * faceEdgeMarks() const
virtual const TRIANGLES_STYLE * trianglesStyle() const
virtual void accept(SceneVisitor &v)
virtual const uint * mindices() const
virtual const uint numFaces() const
virtual const float * texCoords() const
virtual const float * normals() const
virtual const uint msize() const
virtual const uint nsize() const
virtual const uint nisize() const
virtual const uint * numVertexPerFaces() const
virtual const uint * nindices() const
virtual const uint * vindices() const
virtual const uint tsize() const
TRIANGLES_STYLE * _FaceStyle
virtual void accept(SceneVisitor &v)
Definition Rep.h:96
virtual void setBBox(const BBox< Vec3f > &iBox)
Definition Rep.h:137
VecMat::Vec3< float > Vec3f
Definition Geom.h:28
inherits from class Rep
Definition AppCanvas.cpp:20