0022092: Crash of application on attempt to load a VRML file with all degenerated...
[occt.git] / src / VrmlData / VrmlData_IndexedLineSet.hxx
1 // File:      VrmlData_IndexedLineSet.hxx
2 // Created:   01.08.07 09:06
3 // Author:    Alexander GRIGORIEV
4 // Copyright: Open Cascade 2007
5
6
7 #ifndef VrmlData_IndexedLineSet_HeaderFile
8 #define VrmlData_IndexedLineSet_HeaderFile
9
10 #include <VrmlData_Geometry.hxx>
11 #include <VrmlData_Coordinate.hxx>
12 #include <VrmlData_Color.hxx>
13 //#include <Quantity_Color.hxx>
14
15 /**
16  * Data type to store a set of polygons.
17  */
18
19 class VrmlData_IndexedLineSet : public VrmlData_Geometry
20 {
21  public:
22   // ---------- PUBLIC METHODS ----------
23
24
25   /**
26    * Empty constructor.
27    */
28   inline VrmlData_IndexedLineSet ()
29     : myArrPolygons     (0L),
30       myArrColorInd     (0L),
31       myNbPolygons      (0),
32       myNbColors        (0),
33       myColorPerVertex  (Standard_True)
34   {}
35
36   /**
37    * Constructor.
38    */
39   inline VrmlData_IndexedLineSet (const VrmlData_Scene&  theScene,
40                                   const char             * theName,
41                                   const Standard_Boolean isColorPerVertex
42                                                         = Standard_True)
43     : VrmlData_Geometry (theScene, theName),
44       myArrPolygons     (0L),
45       myArrColorInd     (0L),
46       myNbPolygons      (0),
47       myNbColors        (0),
48       myColorPerVertex  (isColorPerVertex)      
49   {}
50
51   /**
52    * Query the Coordinates.
53    */
54   inline const Handle(VrmlData_Coordinate)&
55                 Coordinates     () const        { return myCoords; }
56
57   /**
58    * Set the nodes
59    */
60   inline void   SetCoordinates  (const Handle(VrmlData_Coordinate)& theCoord)
61   { myCoords = theCoord; }
62
63   /**
64    * Query the Colors.
65    */
66   inline const Handle(VrmlData_Color)&
67                 Colors          () const        { return myColors; }
68
69   /**
70    * Set the Color node
71    */
72   inline void   SetColors       (const Handle(VrmlData_Color)& theColors)
73   { myColors = theColors; }
74
75   // ========================================================================
76   // =========================== POLYLINES  =================================
77   /**
78    * Query the array of polygons
79    */
80   inline size_t Polygons        (const Standard_Integer**& arrPolygons) const
81   { arrPolygons = myArrPolygons; return myNbPolygons; }
82
83   /**
84    * Query one polygon.
85    * @param iPolygon
86    *   rank of the polygon [0 .. N-1]
87    * @param outIndice
88    *   <tt>[out]</tt> array of vertex indice
89    * @return
90    *   number of vertice in the polygon - the dimension of outIndice array
91    */
92   inline Standard_Integer
93                 Polygon         (const Standard_Integer         iPolygon,
94                                  const Standard_Integer *&      outIndice)
95   { return * (outIndice = myArrPolygons[iPolygon])++; }
96
97   /**
98    * Set the polygons
99    */
100   inline void   SetPolygons     (const Standard_Integer nPolygons,
101                                  const Standard_Integer ** thePolygons)
102   { myNbPolygons = nPolygons; myArrPolygons = thePolygons; }
103
104   // ========================================================================
105   // ================================ COLORS ================================
106   /**
107    * Query the array of color indice
108    * @param arrColorInd
109    *   <tt>[out]</tt> array of colorIndex as it is described in VRML2.0 spec
110    * @return
111    *   Number of integers in the array arrColorInd.
112    */
113   inline size_t ArrayColorInd   (const Standard_Integer**& arrColorInd) const
114   { arrColorInd = myArrColorInd; return myNbColors; }
115
116   /**
117    * Query a color for one node in the given element. The color is
118    * interpreted according to fields myColors, myArrColorInd,
119    * myColorPerVertex, as defined in VRML 2.0.
120    * @param iFace
121    *   rank of the polygon [0 .. N-1]
122    * @param iVertex
123    *   rank of the vertex in the polygon [0 .. M-1]. This parameter is ignored
124    *   if (myColorPerVertex == False)
125    * @return
126    *   Color value (RGB); if the color is indefinite then returns (0., 0., 0.)
127    */
128   Standard_EXPORT Quantity_Color
129                 GetColor        (const Standard_Integer         iFace,
130                                  const Standard_Integer         iVertex);
131
132   /**
133    * Set the colors array of indice
134    */
135   inline void   SetColorInd     (const Standard_Integer nIndice,
136                                  const Standard_Integer ** theIndice)
137   { myNbColors = nIndice; myArrColorInd = theIndice; }
138
139   /**
140    * Set the boolean value "colorPerVertex"
141    */
142   inline void   SetColorPerVertex (const Standard_Boolean isColorPerVertex)
143   { myColorPerVertex = isColorPerVertex; }
144
145   /**
146    * Query the shape. This method checks the flag myIsModified; if True it
147    * should rebuild the shape presentation.
148    */
149   Standard_EXPORT virtual const Handle(TopoDS_TShape)&
150                 TShape          ();
151
152   /**
153    * Create a copy of this node.
154    * If the parameter is null, a new copied node is created. Otherwise new node
155    * is not created, but rather the given one is modified.
156    */
157   Standard_EXPORT virtual Handle(VrmlData_Node)
158                 Clone           (const Handle(VrmlData_Node)& theOther)const;
159
160   /**
161    * Read the Node from input stream.
162    */
163   Standard_EXPORT virtual VrmlData_ErrorStatus
164                 Read            (VrmlData_InBuffer& theBuffer);
165
166   /**
167    * Write the Node to output stream.
168    */
169   Standard_EXPORT virtual VrmlData_ErrorStatus
170                 Write           (const char * thePrefix) const;
171
172   /**
173    * Returns True if the node is default, so that it should not be written.
174    */
175   Standard_EXPORT virtual Standard_Boolean
176                 IsDefault       () const;
177
178
179  private:
180   // ---------- PRIVATE FIELDS ----------
181   Handle(VrmlData_Coordinate)           myCoords;
182   Handle(VrmlData_Color)                myColors;
183   const Standard_Integer                ** myArrPolygons;
184   const Standard_Integer                ** myArrColorInd;
185   Standard_Size                         myNbPolygons;
186   Standard_Size                         myNbColors;
187   Standard_Boolean                      myColorPerVertex;
188
189  public:
190 // Declaration of CASCADE RTTI
191 DEFINE_STANDARD_RTTI (VrmlData_IndexedLineSet)
192 };
193
194 // Definition of HANDLE object using Standard_DefineHandle.hxx
195 DEFINE_STANDARD_HANDLE (VrmlData_IndexedLineSet, VrmlData_Geometry)
196
197
198 #endif