1 // Created on: 2006-05-26
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2006-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15 
16 #ifndef VrmlData_IndexedFaceSet_HeaderFile
17 #define VrmlData_IndexedFaceSet_HeaderFile
18 
19 #include <VrmlData_Faceted.hxx>
20 #include <VrmlData_Coordinate.hxx>
21 #include <VrmlData_Normal.hxx>
22 #include <VrmlData_Color.hxx>
23 #include <VrmlData_TextureCoordinate.hxx>
24 #include <gp_XYZ.hxx>
25 #include <Quantity_Color.hxx>
26 
27 /**
28  *  Implementation of IndexedFaceSet node
29  */
30 class VrmlData_IndexedFaceSet : public VrmlData_Faceted
31 {
32  public:
33   // ---------- PUBLIC METHODS ----------
34 
35   /**
36    * Empty constructor
37    */
VrmlData_IndexedFaceSet()38   inline VrmlData_IndexedFaceSet ()
39     : myArrPolygons     (0L),
40       myArrNormalInd    (0L),
41       myArrColorInd     (0L),
42       myArrTextureInd   (0L),
43       myNbPolygons      (0),
44       myNbNormals       (0),
45       myNbColors        (0),
46       myNbTextures      (0),
47       myNormalPerVertex (Standard_True),
48       myColorPerVertex  (Standard_True)
49   {}
50 
51   /**
52    * Constructor
53    */
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.)54   inline VrmlData_IndexedFaceSet (const VrmlData_Scene&  theScene,
55                                   const char             * theName,
56                                   const Standard_Boolean isCCW   =Standard_True,
57                                   const Standard_Boolean isSolid =Standard_True,
58                                   const Standard_Boolean isConvex=Standard_True,
59                                   const Standard_Real    theCreaseAngle = 0.)
60     : VrmlData_Faceted (theScene, theName, isCCW, isSolid, isConvex,
61                         theCreaseAngle),
62       myArrPolygons     (0L),
63       myArrNormalInd    (0L),
64       myArrColorInd     (0L),
65       myArrTextureInd   (0L),
66       myNbPolygons      (0),
67       myNbNormals       (0),
68       myNbColors        (0),
69       myNbTextures      (0),
70       myNormalPerVertex (Standard_True),
71       myColorPerVertex  (Standard_True)
72   {}
73 
74   /**
75    * Query the Normals.
76    */
Handle(VrmlData_Normal)77   inline const Handle(VrmlData_Normal)&
78                 Normals         () const        { return myNormals; }
79 
80   /**
81    * Query the Colors.
82    */
Handle(VrmlData_Color)83   inline const Handle(VrmlData_Color)&
84                 Colors          () const        { return myColors; }
85 
86   /**
87    * Query the Texture Coordinates.
88    */
Handle(VrmlData_TextureCoordinate)89   inline const Handle(VrmlData_TextureCoordinate)&
90                 TextureCoords   () const      { return myTxCoords; }
91 
92   // ========================================================================
93   // =========================== TRIANGULATION GRID =========================
94   /**
95    * Query the Coordinates.
96    */
Handle(VrmlData_Coordinate)97   inline const Handle(VrmlData_Coordinate)&
98                 Coordinates     () const        { return myCoords; }
99 
100   /**
101    * Query the array of polygons
102    */
Polygons(const Standard_Integer ** & arrPolygons) const103   inline size_t Polygons        (const Standard_Integer**& arrPolygons) const
104   { arrPolygons = myArrPolygons; return myNbPolygons; }
105 
106   /**
107    * Query one polygon.
108    * @param iFace
109    *   rank of the polygon [0 .. N-1]
110    * @param outIndice
111    *   <tt>[out]</tt> array of vertex indice
112    * @return
113    *   number of vertice in the polygon - the dimension of outIndice array
114    */
115   inline Standard_Integer
Polygon(const Standard_Integer iFace,const Standard_Integer * & outIndice)116                 Polygon         (const Standard_Integer         iFace,
117                                  const Standard_Integer *&      outIndice)
118   { return * (outIndice = myArrPolygons[iFace])++; }
119 
120   /**
121    * Set the nodes
122    */
SetCoordinates(const Handle (VrmlData_Coordinate)& theCoord)123   inline void   SetCoordinates  (const Handle(VrmlData_Coordinate)& theCoord)
124   { myCoords = theCoord; }
125 
126   /**
127    * Set the polygons
128    */
SetPolygons(const Standard_Size nPolygons,const Standard_Integer ** thePolygons)129   inline void   SetPolygons     (const Standard_Size       nPolygons,
130                                  const Standard_Integer ** thePolygons)
131   { myNbPolygons = nPolygons; myArrPolygons = thePolygons; }
132 
133   // ========================================================================
134   // ================================ NORMALS ===============================
135 
136   /**
137    * Query the array of normal indice
138    * @param arrNormalInd
139    *   <tt>[out]</tt> array of normalIndex as it is described in VRML2.0 spec
140    * @return
141    *   Number of integers in the array arrNormalInd.
142    */
ArrayNormalInd(const Standard_Integer ** & arrNormalInd) const143   inline size_t ArrayNormalInd  (const Standard_Integer**& arrNormalInd) const
144   { arrNormalInd = myArrNormalInd; return myNbNormals; }
145 
146   /**
147    * Query normals indice for one face. This method should be called after
148    * checking myArrNormalInd != NULL, otherwise exception will be thrown.
149    * @param iFace
150    *   rank of the face [0 .. N-1]
151    * @param outIndice
152    *   <tt>[out]</tt> array of normals indice
153    * @return
154    *   number of indice in the array - the dimension of outIndice array
155    */
156   inline Standard_Integer
IndiceNormals(const Standard_Integer iFace,const Standard_Integer * & outIndice)157                 IndiceNormals   (const Standard_Integer         iFace,
158                                  const Standard_Integer *&      outIndice)
159   { return * (outIndice = myArrNormalInd[iFace])++; }
160 
161   /**
162    * Query a normal for one node in the given element. The normal is
163    * interpreted according to fields myNormals, myArrNormalInd,
164    * myNormalPerVertex, as defined in VRML 2.0.
165    * @param iFace
166    *   rank of the polygon [0 .. N-1]
167    * @param iVertex
168    *   rank of the vertex in the polygon [0 .. M-1].  This parameter is ignored
169    *   if (myNormalPerVertex == False)
170    * @return
171    *   Normal vector; if the normal is indefinite then returns (0., 0., 0.)
172    */
173   Standard_EXPORT gp_XYZ
174                 GetNormal       (const Standard_Integer         iFace,
175                                  const Standard_Integer         iVertex);
176 
177   /**
178    * Set the normals array of indice
179    */
SetNormalInd(const Standard_Size nIndice,const Standard_Integer ** theIndice)180   inline void   SetNormalInd    (const Standard_Size       nIndice,
181                                  const Standard_Integer ** theIndice)
182   { myNbNormals = nIndice; myArrNormalInd = theIndice; }
183 
184   /**
185    * Set the normals node
186    */
SetNormals(const Handle (VrmlData_Normal)& theNormals)187   inline void   SetNormals      (const Handle(VrmlData_Normal)& theNormals)
188   { myNormals = theNormals; }
189 
190   /**
191    * Set the boolean value "normalPerVertex"
192    */
SetNormalPerVertex(const Standard_Boolean isNormalPerVertex)193   inline void   SetNormalPerVertex (const Standard_Boolean isNormalPerVertex)
194   { myNormalPerVertex = isNormalPerVertex; }
195 
196   // ========================================================================
197   // ================================ COLORS ================================
198 
199   /**
200    * Query the array of color indice
201    * @param arrColorInd
202    *   <tt>[out]</tt> array of colorIndex as it is described in VRML2.0 spec
203    * @return
204    *   Number of integers in the array arrColorInd.
205    */
ArrayColorInd(const Standard_Integer ** & arrColorInd) const206   inline size_t ArrayColorInd   (const Standard_Integer**& arrColorInd) const
207   { arrColorInd = myArrColorInd; return myNbColors; }
208 
209   /**
210    * Query a color for one node in the given element. The color is
211    * interpreted according to fields myColors, myArrColorInd,
212    * myColorPerVertex, as defined in VRML 2.0.
213    * @param iFace
214    *   rank of the polygon [0 .. N-1]
215    * @param iVertex
216    *   rank of the vertex in the polygon [0 .. M-1]. This parameter is ignored
217    *   if (myColorPerVertex == False)
218    * @return
219    *   Color value (RGB); if the color is indefinite then returns (0., 0., 0.)
220    */
221   Standard_EXPORT Quantity_Color
222                 GetColor        (const Standard_Integer         iFace,
223                                  const Standard_Integer         iVertex);
224 
225   /**
226    * Set the colors array of indice
227    */
SetColorInd(const Standard_Size nIndice,const Standard_Integer ** theIndice)228   inline void   SetColorInd     (const Standard_Size       nIndice,
229                                  const Standard_Integer ** theIndice)
230   { myNbColors = nIndice; myArrColorInd = theIndice; }
231 
232   /**
233    * Set the Color node
234    */
SetColors(const Handle (VrmlData_Color)& theColors)235   inline void   SetColors       (const Handle(VrmlData_Color)& theColors)
236   { myColors = theColors; }
237 
238   /**
239    * Set the boolean value "colorPerVertex"
240    */
SetColorPerVertex(const Standard_Boolean isColorPerVertex)241   inline void   SetColorPerVertex (const Standard_Boolean isColorPerVertex)
242   { myColorPerVertex = isColorPerVertex; }
243 
244   // ========================================================================
245   // ========================== TEXTURE COIRDINATES =========================
246 
247   /**
248    * Query the array of texture coordinate indice
249    * @param arrTextureCoordInd
250    *   <tt>[out]</tt> array of texCoordIndex as it is described in VRML2.0 spec
251    * @return
252    *   Number of integers in the array texCoordIndex.
253    */
ArrayTextureCoordInd(const Standard_Integer ** & arrTextureCoordInd) const254   inline size_t ArrayTextureCoordInd
255                             (const Standard_Integer**& arrTextureCoordInd) const
256   { arrTextureCoordInd = myArrTextureInd; return myNbTextures; }
257 
258   /**
259    * Set the TexCoordiante array of indice
260    */
SetTextureCoordInd(const Standard_Size nIndice,const Standard_Integer ** theIndice)261   inline void   SetTextureCoordInd (const Standard_Size       nIndice,
262                                     const Standard_Integer ** theIndice)
263   { myNbTextures = nIndice; myArrTextureInd = theIndice; }
264 
265   /**
266    * Set the Texture Coordinate node
267    */
SetTextureCoords(const Handle (VrmlData_TextureCoordinate)& tc)268   inline void   SetTextureCoords(const Handle(VrmlData_TextureCoordinate)& tc)
269   { myTxCoords = tc; }
270 
271   /**
272    * Query the shape. This method checks the flag myIsModified; if True it
273    * should rebuild the shape presentation.
274    */
275   Standard_EXPORT virtual const Handle(TopoDS_TShape)&  TShape () Standard_OVERRIDE;
276 
277   /**
278    * Create a copy of this node.
279    * If the parameter is null, a new copied node is created. Otherwise new node
280    * is not created, but rather the given one is modified.
281    */
282   Standard_EXPORT virtual Handle(VrmlData_Node)
283                 Clone              (const Handle(VrmlData_Node)& theOther)const Standard_OVERRIDE;
284 
285   /**
286    * Read the Node from input stream.
287    */
288   Standard_EXPORT virtual VrmlData_ErrorStatus
289                 Read               (VrmlData_InBuffer& theBuffer) Standard_OVERRIDE;
290 
291   /**
292    * Write the Node to output stream.
293    */
294   Standard_EXPORT virtual VrmlData_ErrorStatus
295                 Write              (const char * thePrefix) const Standard_OVERRIDE;
296 
297   /**
298    * Returns True if the node is default, so that it should not be written.
299    */
300   Standard_EXPORT virtual Standard_Boolean
301                 IsDefault          () const Standard_OVERRIDE;
302 
303  protected:
304   // ---------- PROTECTED METHODS ----------
305 
306 //   /**
307 //    * If the normals are not defined, here we compute them from the polygons.
308 //    * @param theArray
309 //    *   Array of float values having length:<ul>
310 //    *   <li>if myNormalPerVertex==TRUE : 3 * myCoords->Length()</li>
311 //    *   <li>if myNormalPerVertex==FALSE: 9 * number_of_triangles </li>
312 //    *   </ul>
313 //    */
314 //   Standard_EXPORT void
315 //                 computeNormals     (Standard_ShortReal * theArray);
316 
317  private:
318   // ---------- PRIVATE FIELDS ----------
319   Handle(VrmlData_Coordinate)           myCoords;
320   Handle(VrmlData_Normal)               myNormals;
321   Handle(VrmlData_Color)                myColors;
322   Handle(VrmlData_TextureCoordinate)    myTxCoords;
323   const Standard_Integer                ** myArrPolygons;
324   const Standard_Integer                ** myArrNormalInd;
325   const Standard_Integer                ** myArrColorInd;
326   const Standard_Integer                ** myArrTextureInd;
327   Standard_Size                         myNbPolygons;
328   Standard_Size                         myNbNormals;
329   Standard_Size                         myNbColors;
330   Standard_Size                         myNbTextures;
331   Standard_Boolean                      myNormalPerVertex;
332   Standard_Boolean                      myColorPerVertex;
333 
334  public:
335 // Declaration of CASCADE RTTI
336 DEFINE_STANDARD_RTTIEXT(VrmlData_IndexedFaceSet,VrmlData_Faceted)
337 };
338 
339 // Definition of HANDLE object using Standard_DefineHandle.hxx
340 DEFINE_STANDARD_HANDLE (VrmlData_IndexedFaceSet, VrmlData_Faceted)
341 
342 
343 #endif
344