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