summaryrefslogtreecommitdiff
path: root/inc/VrmlData_IndexedFaceSet.hxx
blob: 3dfc40b5bc670ee0a21c20ae37ddd9bdcac9e34b (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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
// File:      VrmlData_IndexedFaceSet.hxx
// Created:   26.05.06 08:48:31
// Author:    Alexander GRIGORIEV
// Copyright: Open Cascade 2006


#ifndef VrmlData_IndexedFaceSet_HeaderFile
#define VrmlData_IndexedFaceSet_HeaderFile

#include <VrmlData_Faceted.hxx>
#include <VrmlData_Coordinate.hxx>
#include <VrmlData_Normal.hxx>
#include <VrmlData_Color.hxx>
#include <VrmlData_TextureCoordinate.hxx>
#include <gp_XYZ.hxx>
#include <Quantity_Color.hxx>

/**
 *  Implementation of IndexedFaceSet node
 */
class VrmlData_IndexedFaceSet : public VrmlData_Faceted 
{
 public:
  // ---------- PUBLIC METHODS ----------

  /**
   * Empty constructor
   */
  inline VrmlData_IndexedFaceSet ()
    : myArrPolygons     (0L),
      myArrNormalInd    (0L),
      myArrColorInd     (0L),
      myArrTextureInd   (0L),
      myNbPolygons      (0),
      myNbNormals       (0),
      myNbColors        (0),
      myNbTextures      (0),
      myNormalPerVertex (Standard_True),
      myColorPerVertex  (Standard_True)
  {}

  /**
   * Constructor
   */
  inline VrmlData_IndexedFaceSet (const VrmlData_Scene&  theScene,
                                  const char             * theName,
                                  const Standard_Boolean isCCW   =Standard_True,
                                  const Standard_Boolean isSolid =Standard_True,
                                  const Standard_Boolean isConvex=Standard_True,
                                  const Standard_Real    theCreaseAngle = 0.)
    : VrmlData_Faceted (theScene, theName, isCCW, isSolid, isConvex,
                        theCreaseAngle),
      myArrPolygons     (0L),
      myArrNormalInd    (0L),
      myArrColorInd     (0L),
      myArrTextureInd   (0L),
      myNbPolygons      (0),
      myNbNormals       (0),
      myNbColors        (0),
      myNbTextures      (0),
      myNormalPerVertex (Standard_True),
      myColorPerVertex  (Standard_True)
  {}

  /**
   * Query the Normals.
   */
  inline const Handle(VrmlData_Normal)&
                Normals         () const        { return myNormals; }

  /**
   * Query the Colors.
   */
  inline const Handle(VrmlData_Color)&
                Colors          () const        { return myColors; }

  /**
   * Query the Texture Coordinates.
   */
  inline const Handle(VrmlData_TextureCoordinate)&
                TextureCoords   () const      { return myTxCoords; }

  // ========================================================================
  // =========================== TRIANGULATION GRID =========================
  /**
   * Query the Coordinates.
   */
  inline const Handle(VrmlData_Coordinate)&
                Coordinates     () const        { return myCoords; }

  /**
   * Query the array of polygons
   */
  inline size_t Polygons        (const Standard_Integer**& arrPolygons) const
  { arrPolygons = myArrPolygons; return myNbPolygons; }

  /**
   * Query one polygon.
   * @param iFace
   *   rank of the polygon [0 .. N-1]
   * @param outIndice
   *   <tt>[out]</tt> array of vertex indice
   * @return
   *   number of vertice in the polygon - the dimension of outIndice array
   */
  inline Standard_Integer
                Polygon         (const Standard_Integer         iFace,
                                 const Standard_Integer *&      outIndice)
  { return * (outIndice = myArrPolygons[iFace])++; }

  /**
   * Set the nodes
   */
  inline void   SetCoordinates  (const Handle(VrmlData_Coordinate)& theCoord)
  { myCoords = theCoord; }

  /**
   * Set the polygons
   */
  inline void   SetPolygons     (const Standard_Integer nPolygons,
                                 const Standard_Integer ** thePolygons)
  { myNbPolygons = nPolygons; myArrPolygons = thePolygons; }

  // ========================================================================
  // ================================ NORMALS ===============================

  /**
   * Query the array of normal indice
   * @param arrNormalInd
   *   <tt>[out]</tt> array of normalIndex as it is described in VRML2.0 spec
   * @return
   *   Number of integers in the array arrNormalInd.
   */
  inline size_t ArrayNormalInd  (const Standard_Integer**& arrNormalInd) const
  { arrNormalInd = myArrNormalInd; return myNbNormals; }

  /**
   * Query normals indice for one face. This method should be called after
   * checking myArrNormalInd != NULL, otherwise exception will be thrown.
   * @param iFace
   *   rank of the face [0 .. N-1]
   * @param outIndice
   *   <tt>[out]</tt> array of normals indice
   * @return
   *   number of indice in the array - the dimension of outIndice array
   */
  inline Standard_Integer
                IndiceNormals   (const Standard_Integer         iFace,
                                 const Standard_Integer *&      outIndice)
  { return * (outIndice = myArrNormalInd[iFace])++; }

  /**
   * Query a normal for one node in the given element. The normal is
   * interpreted according to fields myNormals, myArrNormalInd,
   * myNormalPerVertex, as defined in VRML 2.0.
   * @param iFace
   *   rank of the polygon [0 .. N-1]
   * @param iVertex
   *   rank of the vertex in the polygon [0 .. M-1].  This parameter is ignored
   *   if (myNormalPerVertex == False)
   * @return
   *   Normal vector; if the normal is indefinite then returns (0., 0., 0.)
   */
  Standard_EXPORT gp_XYZ
                GetNormal       (const Standard_Integer         iFace,
                                 const Standard_Integer         iVertex);

  /**
   * Set the normals array of indice
   */
  inline void   SetNormalInd    (const Standard_Integer nIndice,
                                 const Standard_Integer ** theIndice)
  { myNbNormals = nIndice; myArrNormalInd = theIndice; }

  /**
   * Set the normals node
   */
  inline void   SetNormals      (const Handle(VrmlData_Normal)& theNormals)
  { myNormals = theNormals; }

  /**
   * Set the boolean value "normalPerVertex"
   */
  inline void   SetNormalPerVertex (const Standard_Boolean isNormalPerVertex)
  { myNormalPerVertex = isNormalPerVertex; }

  // ========================================================================
  // ================================ COLORS ================================

  /**
   * Query the array of color indice
   * @param arrColorInd
   *   <tt>[out]</tt> array of colorIndex as it is described in VRML2.0 spec
   * @return
   *   Number of integers in the array arrColorInd.
   */
  inline size_t ArrayColorInd   (const Standard_Integer**& arrColorInd) const
  { arrColorInd = myArrColorInd; return myNbColors; }

  /**
   * Query a color for one node in the given element. The color is
   * interpreted according to fields myColors, myArrColorInd,
   * myColorPerVertex, as defined in VRML 2.0.
   * @param iFace
   *   rank of the polygon [0 .. N-1]
   * @param iVertex
   *   rank of the vertex in the polygon [0 .. M-1]. This parameter is ignored
   *   if (myColorPerVertex == False)
   * @return
   *   Color value (RGB); if the color is indefinite then returns (0., 0., 0.)
   */
  Standard_EXPORT Quantity_Color
                GetColor        (const Standard_Integer         iFace,
                                 const Standard_Integer         iVertex);

  /**
   * Set the colors array of indice
   */
  inline void   SetColorInd     (const Standard_Integer nIndice,
                                 const Standard_Integer ** theIndice)
  { myNbColors = nIndice; myArrColorInd = theIndice; }

  /**
   * Set the Color node
   */
  inline void   SetColors       (const Handle(VrmlData_Color)& theColors)
  { myColors = theColors; }

  /**
   * Set the boolean value "colorPerVertex"
   */
  inline void   SetColorPerVertex (const Standard_Boolean isColorPerVertex)
  { myColorPerVertex = isColorPerVertex; }

  // ========================================================================
  // ========================== TEXTURE COIRDINATES =========================

  /**
   * Query the array of texture coordinate indice
   * @param arrTextureCoordInd
   *   <tt>[out]</tt> array of texCoordIndex as it is described in VRML2.0 spec
   * @return
   *   Number of integers in the array texCoordIndex.
   */
  inline size_t ArrayTextureCoordInd
                            (const Standard_Integer**& arrTextureCoordInd) const
  { arrTextureCoordInd = myArrTextureInd; return myNbTextures; }

  /**
   * Set the TexCoordiante array of indice
   */
  inline void   SetTextureCoordInd (const Standard_Integer nIndice,
                                    const Standard_Integer ** theIndice)
  { myNbTextures = nIndice; myArrTextureInd = theIndice; }

  /**
   * Set the Texture Coordinate node
   */
  inline void   SetTextureCoords(const Handle(VrmlData_TextureCoordinate)& tc)
  { myTxCoords = tc; }

  /**
   * Query the shape. This method checks the flag myIsModified; if True it
   * should rebuild the shape presentation.
   */
  Standard_EXPORT virtual const Handle(TopoDS_TShape)&  TShape ();

  /**
   * Create a copy of this node.
   * If the parameter is null, a new copied node is created. Otherwise new node
   * is not created, but rather the given one is modified.
   */
  Standard_EXPORT virtual Handle(VrmlData_Node)
                Clone              (const Handle(VrmlData_Node)& theOther)const;

  /**
   * Read the Node from input stream.
   */
  Standard_EXPORT virtual VrmlData_ErrorStatus
                Read               (VrmlData_InBuffer& theBuffer);

  /**
   * Write the Node to output stream.
   */
  Standard_EXPORT virtual VrmlData_ErrorStatus
                Write              (const char * thePrefix) const;

  /**
   * Returns True if the node is default, so that it should not be written.
   */
  Standard_EXPORT virtual Standard_Boolean
                IsDefault          () const;

 protected:
  // ---------- PROTECTED METHODS ----------

//   /**
//    * If the normals are not defined, here we compute them from the polygons.
//    * @param theArray
//    *   Array of float values having length:<ul>
//    *   <li>if myNormalPerVertex==TRUE : 3 * myCoords->Length()</li>
//    *   <li>if myNormalPerVertex==FALSE: 9 * number_of_triangles </li>
//    *   </ul>
//    */
//   Standard_EXPORT void
//                 computeNormals     (Standard_ShortReal * theArray);

 private:
  // ---------- PRIVATE FIELDS ----------
  Handle(VrmlData_Coordinate)           myCoords;
  Handle(VrmlData_Normal)               myNormals;
  Handle(VrmlData_Color)                myColors;
  Handle(VrmlData_TextureCoordinate)    myTxCoords;
  const Standard_Integer                ** myArrPolygons;
  const Standard_Integer                ** myArrNormalInd;
  const Standard_Integer                ** myArrColorInd;
  const Standard_Integer                ** myArrTextureInd;
  Standard_Size                         myNbPolygons;
  Standard_Size                         myNbNormals;
  Standard_Size                         myNbColors;
  Standard_Size                         myNbTextures;
  Standard_Boolean                      myNormalPerVertex;
  Standard_Boolean                      myColorPerVertex;

 public:
// Declaration of CASCADE RTTI
DEFINE_STANDARD_RTTI (VrmlData_IndexedFaceSet)
};

// Definition of HANDLE object using Standard_DefineHandle.hxx
DEFINE_STANDARD_HANDLE (VrmlData_IndexedFaceSet, VrmlData_Faceted)


#endif