Welcome to mirror list, hosted at ThFree Co, Russian Federation.

IndexedFaceSet.h « scene_graph « intern « freestyle « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f8dd25913c1752389ef1c535adc069402607cf62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef __FREESTYLE_INDEXED_FACE_SET_H__
#define __FREESTYLE_INDEXED_FACE_SET_H__

/** \file
 * \ingroup freestyle
 * \brief A Set of indexed faces to represent a surface object
 */

#include <memory.h>
#include <stdio.h>

//! inherits from class Rep
#include "Rep.h"

#include "../system/FreestyleConfig.h"

namespace Freestyle {

class IndexedFaceSet : public Rep {
 public:
  /*! Triangles description style:*/
  enum TRIANGLES_STYLE {
    TRIANGLE_STRIP,
    TRIANGLE_FAN,
    TRIANGLES,
  };

  /*! User-specified face and edge marks for feature edge detection */
  /* XXX Why in hell not use an enum here too? */
  typedef unsigned char FaceEdgeMark;
  static const FaceEdgeMark FACE_MARK = 1 << 0;
  static const FaceEdgeMark EDGE_MARK_V1V2 = 1 << 1;
  static const FaceEdgeMark EDGE_MARK_V2V3 = 1 << 2;
  static const FaceEdgeMark EDGE_MARK_V3V1 = 1 << 3;

  /*! Builds an empty indexed face set  */
  IndexedFaceSet();

  /*! Builds an indexed face set
   *    iVertices
   *      The array of object vertices 3D coordinates (for all faces).
   *      If iCopy != 0, the array is copied; you must deallocate iVertices. Else you must not.
   *    iVSize
   *      The size of iVertices (must be a multiple of 3)
   *    iNormals
   *      The array of object normals 3D coordinates.
   *      If iCopy != 0, the array is copied; you must deallocate iNormals. Else you must not.
   *    iNSize
   *      The size of iNormals
   *    iMaterials
   *      The array of materials
   *    iMSize
   *      The size of iMaterials
   *    iTexCoords
   *      The array of texture coordinates.
   *    iTSize
   *      The size of iTexCoords (must be multiple of 2)
   *    iNumFaces
   *      The number of faces
   *    iNumVertexPerFace
   *      Array containing the number of vertices per face.
   *    iFaceStyle
   *      Array containing the description style of each faces.
   *      The style belongs to:
   *        - TRIANGLE_STRIP: the face indices describe a triangle strip
   *        - TRIANGLE_FAN  : the face indices describe a triangle fan
   *        - TRIANGLES     : the face indices describe single triangles
   *      If iCopy != 0, the array is copied; you must deallocate iFaceStyle. Else you must not.
   *    iVIndices,
   *      Array of vertices indices.
   *      The integers contained in this array must be multiple of 3.
   *      If iCopy != 0, the array is copied; you must deallocate iVIndices. Else you must not.
   *    iVISize
   *      The size of iVIndices.
   *    iNIndices
   *      Array of normals indices.
   *      The integers contained in this array must be multiple of 3.
   *      If iCopy != 0, the array is copied; you must deallocate iNIndices. Else you must not.
   *    iNISize
   *      The size of iNIndices
   *    iMIndices
   *      The Material indices (per vertex)
   *    iMISize
   *      The size of iMIndices
   *    iTIndices
   *      The Texture coordinates indices (per vertex). The integers contained in this array must
   * be multiple of 2. iTISize The size of iMIndices iCopy 0 : the arrays are not copied. The
   * pointers passed as arguments are used. IndexedFaceSet takes these arrays desallocation in
   * charge. 1 : the arrays are copied. The caller is in charge of the arrays, passed as arguments
   * desallocation.
   */
  IndexedFaceSet(float *iVertices,
                 unsigned iVSize,
                 float *iNormals,
                 unsigned iNSize,
                 FrsMaterial **iMaterials,
                 unsigned iMSize,
                 float *iTexCoords,
                 unsigned iTSize,
                 unsigned iNumFaces,
                 unsigned *iNumVertexPerFace,
                 TRIANGLES_STYLE *iFaceStyle,
                 FaceEdgeMark *iFaceEdgeMarks,
                 unsigned *iVIndices,
                 unsigned iVISize,
                 unsigned *iNIndices,
                 unsigned iNISize,
                 unsigned *iMIndices,
                 unsigned iMISize,
                 unsigned *iTIndices,
                 unsigned iTISize,
                 unsigned iCopy = 1);

  /*! Builds an indexed face set from an other indexed face set */
  IndexedFaceSet(const IndexedFaceSet &iBrother);

  void swap(IndexedFaceSet &ioOther)
  {
    std::swap(_Vertices, ioOther._Vertices);
    std::swap(_Normals, ioOther._Normals);
    std::swap(_FrsMaterials, ioOther._FrsMaterials);
    std::swap(_TexCoords, ioOther._TexCoords);
    std::swap(_FaceEdgeMarks, ioOther._FaceEdgeMarks);

    std::swap(_VSize, ioOther._VSize);
    std::swap(_NSize, ioOther._NSize);
    std::swap(_MSize, ioOther._MSize);
    std::swap(_TSize, ioOther._TSize);

    std::swap(_NumFaces, ioOther._NumFaces);
    std::swap(_NumVertexPerFace, ioOther._NumVertexPerFace);
    std::swap(_FaceStyle, ioOther._FaceStyle);

    std::swap(_VIndices, ioOther._VIndices);
    std::swap(_NIndices, ioOther._NIndices);
    std::swap(_MIndices, ioOther._MIndices);  // Material Indices
    std::swap(_TIndices, ioOther._TIndices);

    std::swap(_VISize, ioOther._VISize);
    std::swap(_NISize, ioOther._NISize);
    std::swap(_MISize, ioOther._MISize);
    std::swap(_TISize, ioOther._TISize);

    Rep::swap(ioOther);
  }

  IndexedFaceSet &operator=(const IndexedFaceSet &iBrother)
  {
    IndexedFaceSet tmp(iBrother);
    swap(tmp);
    return *this;
  }

  /*! Destructor
   *  deallocates all the resources
   */
  virtual ~IndexedFaceSet();

  /*! Accept the corresponding visitor */
  virtual void accept(SceneVisitor &v);

  /*! Compute the Bounding Box */
  virtual void ComputeBBox();

  /*! Accessors */
  virtual const float *vertices() const
  {
    return _Vertices;
  }

  virtual const float *normals() const
  {
    return _Normals;
  }

  virtual const FrsMaterial *const *frs_materials() const
  {
    return _FrsMaterials;
  }

  virtual const float *texCoords() const
  {
    return _TexCoords;
  }

  virtual const unsigned vsize() const
  {
    return _VSize;
  }

  virtual const unsigned nsize() const
  {
    return _NSize;
  }

  virtual const unsigned msize() const
  {
    return _MSize;
  }

  virtual const unsigned tsize() const
  {
    return _TSize;
  }

  virtual const unsigned numFaces() const
  {
    return _NumFaces;
  }

  virtual const unsigned *numVertexPerFaces() const
  {
    return _NumVertexPerFace;
  }

  virtual const TRIANGLES_STYLE *trianglesStyle() const
  {
    return _FaceStyle;
  }

  virtual const unsigned char *faceEdgeMarks() const
  {
    return _FaceEdgeMarks;
  }

  virtual const unsigned *vindices() const
  {
    return _VIndices;
  }

  virtual const unsigned *nindices() const
  {
    return _NIndices;
  }

  virtual const unsigned *mindices() const
  {
    return _MIndices;
  }

  virtual const unsigned *tindices() const
  {
    return _TIndices;
  }

  virtual const unsigned visize() const
  {
    return _VISize;
  }

  virtual const unsigned nisize() const
  {
    return _NISize;
  }

  virtual const unsigned misize() const
  {
    return _MISize;
  }

  virtual const unsigned tisize() const
  {
    return _TISize;
  }

 protected:
  float *_Vertices;
  float *_Normals;
  FrsMaterial **_FrsMaterials;
  float *_TexCoords;

  unsigned _VSize;
  unsigned _NSize;
  unsigned _MSize;
  unsigned _TSize;

  unsigned _NumFaces;
  unsigned *_NumVertexPerFace;
  TRIANGLES_STYLE *_FaceStyle;
  FaceEdgeMark *_FaceEdgeMarks;

  unsigned *_VIndices;
  unsigned *_NIndices;
  unsigned *_MIndices;  // Material Indices
  unsigned *_TIndices;  // Texture coordinates Indices

  unsigned _VISize;
  unsigned _NISize;
  unsigned _MISize;
  unsigned _TISize;

#ifdef WITH_CXX_GUARDEDALLOC
  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:IndexedFaceSet")
#endif
};

} /* namespace Freestyle */

#endif  // __FREESTYLE_INDEXED_FACE_SET_H__