1 // Created on: 2006-05-26
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2006-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef VrmlData_IndexedFaceSet_HeaderFile
17 #define VrmlData_IndexedFaceSet_HeaderFile
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>
25 #include <Quantity_Color.hxx>
28 * Implementation of IndexedFaceSet node
30 class VrmlData_IndexedFaceSet : public VrmlData_Faceted
33 // ---------- PUBLIC METHODS ----------
38 inline VrmlData_IndexedFaceSet ()
47 myNormalPerVertex (Standard_True),
48 myColorPerVertex (Standard_True)
54 inline VrmlData_IndexedFaceSet (const VrmlData_Scene& theScene,
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,
70 myNormalPerVertex (Standard_True),
71 myColorPerVertex (Standard_True)
77 inline const Handle(VrmlData_Normal)&
78 Normals () const { return myNormals; }
83 inline const Handle(VrmlData_Color)&
84 Colors () const { return myColors; }
87 * Query the Texture Coordinates.
89 inline const Handle(VrmlData_TextureCoordinate)&
90 TextureCoords () const { return myTxCoords; }
92 // ========================================================================
93 // =========================== TRIANGULATION GRID =========================
95 * Query the Coordinates.
97 inline const Handle(VrmlData_Coordinate)&
98 Coordinates () const { return myCoords; }
101 * Query the array of polygons
103 inline size_t Polygons (const Standard_Integer**& arrPolygons) const
104 { arrPolygons = myArrPolygons; return myNbPolygons; }
109 * rank of the polygon [0 .. N-1]
111 * <tt>[out]</tt> array of vertex indice
113 * number of vertice in the polygon - the dimension of outIndice array
115 inline Standard_Integer
116 Polygon (const Standard_Integer iFace,
117 const Standard_Integer *& outIndice)
118 { return * (outIndice = myArrPolygons[iFace])++; }
123 inline void SetCoordinates (const Handle(VrmlData_Coordinate)& theCoord)
124 { myCoords = theCoord; }
129 inline void SetPolygons (const Standard_Size nPolygons,
130 const Standard_Integer ** thePolygons)
131 { myNbPolygons = nPolygons; myArrPolygons = thePolygons; }
133 // ========================================================================
134 // ================================ NORMALS ===============================
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
141 * Number of integers in the array arrNormalInd.
143 inline size_t ArrayNormalInd (const Standard_Integer**& arrNormalInd) const
144 { arrNormalInd = myArrNormalInd; return myNbNormals; }
147 * Query normals indice for one face. This method should be called after
148 * checking myArrNormalInd != NULL, otherwise exception will be thrown.
150 * rank of the face [0 .. N-1]
152 * <tt>[out]</tt> array of normals indice
154 * number of indice in the array - the dimension of outIndice array
156 inline Standard_Integer
157 IndiceNormals (const Standard_Integer iFace,
158 const Standard_Integer *& outIndice)
159 { return * (outIndice = myArrNormalInd[iFace])++; }
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.
166 * rank of the polygon [0 .. N-1]
168 * rank of the vertex in the polygon [0 .. M-1]. This parameter is ignored
169 * if (myNormalPerVertex == False)
171 * Normal vector; if the normal is indefinite then returns (0., 0., 0.)
173 Standard_EXPORT gp_XYZ
174 GetNormal (const Standard_Integer iFace,
175 const Standard_Integer iVertex);
178 * Set the normals array of indice
180 inline void SetNormalInd (const Standard_Size nIndice,
181 const Standard_Integer ** theIndice)
182 { myNbNormals = nIndice; myArrNormalInd = theIndice; }
185 * Set the normals node
187 inline void SetNormals (const Handle(VrmlData_Normal)& theNormals)
188 { myNormals = theNormals; }
191 * Set the boolean value "normalPerVertex"
193 inline void SetNormalPerVertex (const Standard_Boolean isNormalPerVertex)
194 { myNormalPerVertex = isNormalPerVertex; }
196 // ========================================================================
197 // ================================ COLORS ================================
200 * Query the array of color indice
202 * <tt>[out]</tt> array of colorIndex as it is described in VRML2.0 spec
204 * Number of integers in the array arrColorInd.
206 inline size_t ArrayColorInd (const Standard_Integer**& arrColorInd) const
207 { arrColorInd = myArrColorInd; return myNbColors; }
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.
214 * rank of the polygon [0 .. N-1]
216 * rank of the vertex in the polygon [0 .. M-1]. This parameter is ignored
217 * if (myColorPerVertex == False)
219 * Color value (RGB); if the color is indefinite then returns (0., 0., 0.)
221 Standard_EXPORT Quantity_Color
222 GetColor (const Standard_Integer iFace,
223 const Standard_Integer iVertex);
226 * Set the colors array of indice
228 inline void SetColorInd (const Standard_Size nIndice,
229 const Standard_Integer ** theIndice)
230 { myNbColors = nIndice; myArrColorInd = theIndice; }
235 inline void SetColors (const Handle(VrmlData_Color)& theColors)
236 { myColors = theColors; }
239 * Set the boolean value "colorPerVertex"
241 inline void SetColorPerVertex (const Standard_Boolean isColorPerVertex)
242 { myColorPerVertex = isColorPerVertex; }
244 // ========================================================================
245 // ========================== TEXTURE COIRDINATES =========================
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
252 * Number of integers in the array texCoordIndex.
254 inline size_t ArrayTextureCoordInd
255 (const Standard_Integer**& arrTextureCoordInd) const
256 { arrTextureCoordInd = myArrTextureInd; return myNbTextures; }
259 * Set the TexCoordiante array of indice
261 inline void SetTextureCoordInd (const Standard_Size nIndice,
262 const Standard_Integer ** theIndice)
263 { myNbTextures = nIndice; myArrTextureInd = theIndice; }
266 * Set the Texture Coordinate node
268 inline void SetTextureCoords(const Handle(VrmlData_TextureCoordinate)& tc)
272 * Query the shape. This method checks the flag myIsModified; if True it
273 * should rebuild the shape presentation.
275 Standard_EXPORT virtual const Handle(TopoDS_TShape)& TShape () Standard_OVERRIDE;
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.
282 Standard_EXPORT virtual Handle(VrmlData_Node)
283 Clone (const Handle(VrmlData_Node)& theOther)const Standard_OVERRIDE;
286 * Read the Node from input stream.
288 Standard_EXPORT virtual VrmlData_ErrorStatus
289 Read (VrmlData_InBuffer& theBuffer) Standard_OVERRIDE;
292 * Write the Node to output stream.
294 Standard_EXPORT virtual VrmlData_ErrorStatus
295 Write (const char * thePrefix) const Standard_OVERRIDE;
298 * Returns True if the node is default, so that it should not be written.
300 Standard_EXPORT virtual Standard_Boolean
301 IsDefault () const Standard_OVERRIDE;
304 // ---------- PROTECTED METHODS ----------
307 // * If the normals are not defined, here we compute them from the polygons.
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>
314 // Standard_EXPORT void
315 // computeNormals (Standard_ShortReal * theArray);
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;
335 // Declaration of CASCADE RTTI
336 DEFINE_STANDARD_RTTIEXT(VrmlData_IndexedFaceSet,VrmlData_Faceted)
339 // Definition of HANDLE object using Standard_DefineHandle.hxx
340 DEFINE_STANDARD_HANDLE (VrmlData_IndexedFaceSet, VrmlData_Faceted)