1 // File: VrmlData_IndexedFaceSet.hxx
2 // Created: 26.05.06 08:48:31
3 // Author: Alexander GRIGORIEV
4 // Copyright: Open Cascade 2006
7 #ifndef VrmlData_IndexedFaceSet_HeaderFile
8 #define VrmlData_IndexedFaceSet_HeaderFile
10 #include <VrmlData_Faceted.hxx>
11 #include <VrmlData_Coordinate.hxx>
12 #include <VrmlData_Normal.hxx>
13 #include <VrmlData_Color.hxx>
14 #include <VrmlData_TextureCoordinate.hxx>
16 #include <Quantity_Color.hxx>
19 * Implementation of IndexedFaceSet node
21 class VrmlData_IndexedFaceSet : public VrmlData_Faceted
24 // ---------- PUBLIC METHODS ----------
29 inline VrmlData_IndexedFaceSet ()
38 myNormalPerVertex (Standard_True),
39 myColorPerVertex (Standard_True)
45 inline VrmlData_IndexedFaceSet (const VrmlData_Scene& theScene,
47 const Standard_Boolean isCCW =Standard_True,
48 const Standard_Boolean isSolid =Standard_True,
49 const Standard_Boolean isConvex=Standard_True,
50 const Standard_Real theCreaseAngle = 0.)
51 : VrmlData_Faceted (theScene, theName, isCCW, isSolid, isConvex,
61 myNormalPerVertex (Standard_True),
62 myColorPerVertex (Standard_True)
68 inline const Handle(VrmlData_Normal)&
69 Normals () const { return myNormals; }
74 inline const Handle(VrmlData_Color)&
75 Colors () const { return myColors; }
78 * Query the Texture Coordinates.
80 inline const Handle(VrmlData_TextureCoordinate)&
81 TextureCoords () const { return myTxCoords; }
83 // ========================================================================
84 // =========================== TRIANGULATION GRID =========================
86 * Query the Coordinates.
88 inline const Handle(VrmlData_Coordinate)&
89 Coordinates () const { return myCoords; }
92 * Query the array of polygons
94 inline size_t Polygons (const Standard_Integer**& arrPolygons) const
95 { arrPolygons = myArrPolygons; return myNbPolygons; }
100 * rank of the polygon [0 .. N-1]
102 * <tt>[out]</tt> array of vertex indice
104 * number of vertice in the polygon - the dimension of outIndice array
106 inline Standard_Integer
107 Polygon (const Standard_Integer iFace,
108 const Standard_Integer *& outIndice)
109 { return * (outIndice = myArrPolygons[iFace])++; }
114 inline void SetCoordinates (const Handle(VrmlData_Coordinate)& theCoord)
115 { myCoords = theCoord; }
120 inline void SetPolygons (const Standard_Integer nPolygons,
121 const Standard_Integer ** thePolygons)
122 { myNbPolygons = nPolygons; myArrPolygons = thePolygons; }
124 // ========================================================================
125 // ================================ NORMALS ===============================
128 * Query the array of normal indice
129 * @param arrNormalInd
130 * <tt>[out]</tt> array of normalIndex as it is described in VRML2.0 spec
132 * Number of integers in the array arrNormalInd.
134 inline size_t ArrayNormalInd (const Standard_Integer**& arrNormalInd) const
135 { arrNormalInd = myArrNormalInd; return myNbNormals; }
138 * Query normals indice for one face. This method should be called after
139 * checking myArrNormalInd != NULL, otherwise exception will be thrown.
141 * rank of the face [0 .. N-1]
143 * <tt>[out]</tt> array of normals indice
145 * number of indice in the array - the dimension of outIndice array
147 inline Standard_Integer
148 IndiceNormals (const Standard_Integer iFace,
149 const Standard_Integer *& outIndice)
150 { return * (outIndice = myArrNormalInd[iFace])++; }
153 * Query a normal for one node in the given element. The normal is
154 * interpreted according to fields myNormals, myArrNormalInd,
155 * myNormalPerVertex, as defined in VRML 2.0.
157 * rank of the polygon [0 .. N-1]
159 * rank of the vertex in the polygon [0 .. M-1]. This parameter is ignored
160 * if (myNormalPerVertex == False)
162 * Normal vector; if the normal is indefinite then returns (0., 0., 0.)
164 Standard_EXPORT gp_XYZ
165 GetNormal (const Standard_Integer iFace,
166 const Standard_Integer iVertex);
169 * Set the normals array of indice
171 inline void SetNormalInd (const Standard_Integer nIndice,
172 const Standard_Integer ** theIndice)
173 { myNbNormals = nIndice; myArrNormalInd = theIndice; }
176 * Set the normals node
178 inline void SetNormals (const Handle(VrmlData_Normal)& theNormals)
179 { myNormals = theNormals; }
182 * Set the boolean value "normalPerVertex"
184 inline void SetNormalPerVertex (const Standard_Boolean isNormalPerVertex)
185 { myNormalPerVertex = isNormalPerVertex; }
187 // ========================================================================
188 // ================================ COLORS ================================
191 * Query the array of color indice
193 * <tt>[out]</tt> array of colorIndex as it is described in VRML2.0 spec
195 * Number of integers in the array arrColorInd.
197 inline size_t ArrayColorInd (const Standard_Integer**& arrColorInd) const
198 { arrColorInd = myArrColorInd; return myNbColors; }
201 * Query a color for one node in the given element. The color is
202 * interpreted according to fields myColors, myArrColorInd,
203 * myColorPerVertex, as defined in VRML 2.0.
205 * rank of the polygon [0 .. N-1]
207 * rank of the vertex in the polygon [0 .. M-1]. This parameter is ignored
208 * if (myColorPerVertex == False)
210 * Color value (RGB); if the color is indefinite then returns (0., 0., 0.)
212 Standard_EXPORT Quantity_Color
213 GetColor (const Standard_Integer iFace,
214 const Standard_Integer iVertex);
217 * Set the colors array of indice
219 inline void SetColorInd (const Standard_Integer nIndice,
220 const Standard_Integer ** theIndice)
221 { myNbColors = nIndice; myArrColorInd = theIndice; }
226 inline void SetColors (const Handle(VrmlData_Color)& theColors)
227 { myColors = theColors; }
230 * Set the boolean value "colorPerVertex"
232 inline void SetColorPerVertex (const Standard_Boolean isColorPerVertex)
233 { myColorPerVertex = isColorPerVertex; }
235 // ========================================================================
236 // ========================== TEXTURE COIRDINATES =========================
239 * Query the array of texture coordinate indice
240 * @param arrTextureCoordInd
241 * <tt>[out]</tt> array of texCoordIndex as it is described in VRML2.0 spec
243 * Number of integers in the array texCoordIndex.
245 inline size_t ArrayTextureCoordInd
246 (const Standard_Integer**& arrTextureCoordInd) const
247 { arrTextureCoordInd = myArrTextureInd; return myNbTextures; }
250 * Set the TexCoordiante array of indice
252 inline void SetTextureCoordInd (const Standard_Integer nIndice,
253 const Standard_Integer ** theIndice)
254 { myNbTextures = nIndice; myArrTextureInd = theIndice; }
257 * Set the Texture Coordinate node
259 inline void SetTextureCoords(const Handle(VrmlData_TextureCoordinate)& tc)
263 * Query the shape. This method checks the flag myIsModified; if True it
264 * should rebuild the shape presentation.
266 Standard_EXPORT virtual const Handle(TopoDS_TShape)& TShape ();
269 * Create a copy of this node.
270 * If the parameter is null, a new copied node is created. Otherwise new node
271 * is not created, but rather the given one is modified.
273 Standard_EXPORT virtual Handle(VrmlData_Node)
274 Clone (const Handle(VrmlData_Node)& theOther)const;
277 * Read the Node from input stream.
279 Standard_EXPORT virtual VrmlData_ErrorStatus
280 Read (VrmlData_InBuffer& theBuffer);
283 * Write the Node to output stream.
285 Standard_EXPORT virtual VrmlData_ErrorStatus
286 Write (const char * thePrefix) const;
289 * Returns True if the node is default, so that it should not be written.
291 Standard_EXPORT virtual Standard_Boolean
295 // ---------- PROTECTED METHODS ----------
298 // * If the normals are not defined, here we compute them from the polygons.
300 // * Array of float values having length:<ul>
301 // * <li>if myNormalPerVertex==TRUE : 3 * myCoords->Length()</li>
302 // * <li>if myNormalPerVertex==FALSE: 9 * number_of_triangles </li>
305 // Standard_EXPORT void
306 // computeNormals (Standard_ShortReal * theArray);
309 // ---------- PRIVATE FIELDS ----------
310 Handle(VrmlData_Coordinate) myCoords;
311 Handle(VrmlData_Normal) myNormals;
312 Handle(VrmlData_Color) myColors;
313 Handle(VrmlData_TextureCoordinate) myTxCoords;
314 const Standard_Integer ** myArrPolygons;
315 const Standard_Integer ** myArrNormalInd;
316 const Standard_Integer ** myArrColorInd;
317 const Standard_Integer ** myArrTextureInd;
318 Standard_Size myNbPolygons;
319 Standard_Size myNbNormals;
320 Standard_Size myNbColors;
321 Standard_Size myNbTextures;
322 Standard_Boolean myNormalPerVertex;
323 Standard_Boolean myColorPerVertex;
326 // Declaration of CASCADE RTTI
327 DEFINE_STANDARD_RTTI (VrmlData_IndexedFaceSet)
330 // Definition of HANDLE object using Standard_DefineHandle.hxx
331 DEFINE_STANDARD_HANDLE (VrmlData_IndexedFaceSet, VrmlData_Faceted)