1 // Created on: 2000-06-16
2 // Copyright (c) 2000-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _Graphic3d_ArrayOfPrimitives_HeaderFile
16 #define _Graphic3d_ArrayOfPrimitives_HeaderFile
18 #include <Standard.hxx>
19 #include <Standard_Type.hxx>
21 #include <Graphic3d_IndexBuffer.hxx>
22 #include <Graphic3d_Buffer.hxx>
23 #include <Graphic3d_BoundBuffer.hxx>
24 #include <Graphic3d_TypeOfPrimitiveArray.hxx>
25 #include <Standard_Integer.hxx>
26 #include <Standard_Byte.hxx>
27 #include <MMgt_TShared.hxx>
28 #include <Standard_Boolean.hxx>
29 #include <Standard_Real.hxx>
30 #include <Standard_ShortReal.hxx>
31 #include <Standard_CString.hxx>
32 class Standard_OutOfRange;
33 class Graphic3d_Group;
40 class Graphic3d_ArrayOfPrimitives;
41 DEFINE_STANDARD_HANDLE(Graphic3d_ArrayOfPrimitives, MMgt_TShared)
43 //! This class furnish services to defined and fill an
44 //! array of primitives compatible with the use of
45 //! the OPENGl glDrawArrays() or glDrawElements() functions.
46 //! NOTE that the main goal of this kind of primitive
47 //! is to avoid multiple copies of datas between
48 //! each layer of the software.
49 //! So the array datas exist only one time and the use
50 //! of SetXxxxxx() methods enable to change dynamically
51 //! the aspect of this primitive.
54 //! 1) Decrease strongly the loading time.
55 //! 2) Decrease strongly the display time using optimized Opengl
57 //! 3) Enable to change dynamically the components of the primitive
58 //! (vertice,normal,color,texture coordinates).
59 //! 4) Add true triangle and quadrangle strips or fans capabilities.
60 class Graphic3d_ArrayOfPrimitives : public MMgt_TShared
66 Standard_EXPORT void Destroy();
67 ~Graphic3d_ArrayOfPrimitives()
72 //! Adds a vertice in the array.
73 //! returns the actual vertex number.
74 Standard_Integer AddVertex (const gp_Pnt& aVertice);
75 Standard_Integer AddVertex (const Graphic3d_Vec3& theVertex);
77 //! Adds a vertice in the array.
78 //! returns the actual vertex number.
79 Standard_Integer AddVertex (const Standard_Real X, const Standard_Real Y, const Standard_Real Z);
81 //! Adds a vertice in the array.
82 //! returns the actual vertex number.
83 Standard_EXPORT Standard_Integer AddVertex (const Standard_ShortReal X, const Standard_ShortReal Y, const Standard_ShortReal Z);
85 //! Adds a vertice and vertex color in the vertex array.
86 //! returns the actual vertex number.
87 //! Warning: <aColor> is ignored when the <hasVColors>
88 //! constructor parameter is FALSE
89 Standard_EXPORT Standard_Integer AddVertex (const gp_Pnt& aVertice, const Quantity_Color& aColor);
91 //! Adds a vertice and vertex color in the vertex array.
92 //! returns the actual vertex number.
93 //! Warning: <aColor> is ignored when the <hasVColors>
94 //! constructor parameter is FALSE
95 //! aColor = Alpha << 24 + Blue << 16 + Green << 8 + Red
96 //! On all architecture proccers type (x86 or SPARC) you can
97 //! use this byte order.
98 Standard_EXPORT Standard_Integer AddVertex (const gp_Pnt& aVertice, const Standard_Integer aColor);
100 //! Adds a vertice and vertex color in the vertex array.
101 //! returns the actual vertex number.
102 //! Warning: <theColor> is ignored when the <hasVColors>
103 //! constructor parameter is FALSE
104 Standard_Integer AddVertex (const gp_Pnt& theVertex,
105 const Graphic3d_Vec4ub& theColor);
107 //! Adds a vertice and vertex normal in the vertex array.
108 //! returns the actual vertex number.
109 //! Warning: <aNormal> is ignored when the <hasVNormals>
110 //! constructor parameter is FALSE.
111 Standard_Integer AddVertex (const gp_Pnt& aVertice, const gp_Dir& aNormal);
113 //! Adds a vertice and vertex normal in the vertex array.
114 //! returns the actual vertex number.
115 //! Warning: <aNormal> is ignored when the <hasVNormals>
116 //! constructor parameter is FALSE.
117 Standard_Integer AddVertex (const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Real NX, const Standard_Real NY, const Standard_Real NZ);
119 //! Adds a vertice and vertex normal in the vertex array.
120 //! returns the actual vertex number.
121 //! Warning: <aNormal> is ignored when the <hasVNormals>
122 //! constructor parameter is FALSE.
123 Standard_EXPORT Standard_Integer AddVertex (const Standard_ShortReal X, const Standard_ShortReal Y, const Standard_ShortReal Z, const Standard_ShortReal NX, const Standard_ShortReal NY, const Standard_ShortReal NZ);
125 //! Adds a vertice,vertex normal and color in the vertex array.
126 //! returns the actual vertex number.
127 //! Warning: <aNormal> is ignored when the <hasVNormals>
128 //! constructor parameter is FALSE.
129 //! <aColor> is ignored when the <hasVColors>
130 //! constructor parameter is FALSE
131 Standard_EXPORT Standard_Integer AddVertex (const gp_Pnt& aVertice, const gp_Dir& aNormal, const Quantity_Color& aColor);
133 //! Adds a vertice,vertex normal and color in the vertex array.
134 //! returns the actual vertex number.
135 //! Warning: <aNormal> is ignored when the <hasVNormals>
136 //! constructor parameter is FALSE.
137 //! <aColor> is ignored when the <hasVColors>
138 //! constructor parameter is FALSE
139 //! aColor = Alpha << 24 + Blue << 16 + Green << 8 + Red
140 //! On all architecture proccers type (x86 or SPARC) you can
141 //! use this byte order.
142 Standard_EXPORT Standard_Integer AddVertex (const gp_Pnt& aVertice, const gp_Dir& aNormal, const Standard_Integer aColor);
144 //! Adds a vertice and vertex texture in the vertex array.
145 //! returns the actual vertex number.
146 //! <aTexel> is ignored when the <hasVTexels>
147 //! constructor parameter is FALSE.
148 Standard_Integer AddVertex (const gp_Pnt& aVertice, const gp_Pnt2d& aTexel);
150 //! Adds a vertice and vertex texture coordinates in the vertex array.
151 //! returns the actual vertex number.
152 //! <aTexel> is ignored when the <hasVTexels>
153 //! constructor parameter is FALSE.
154 Standard_Integer AddVertex (const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Real TX, const Standard_Real TY);
156 //! Adds a vertice and vertex texture coordinates in the vertex array.
157 //! returns the actual vertex number.
158 //! <aTexel> is ignored when the <hasVTexels>
159 //! constructor parameter is FALSE.
160 Standard_EXPORT Standard_Integer AddVertex (const Standard_ShortReal X, const Standard_ShortReal Y, const Standard_ShortReal Z, const Standard_ShortReal TX, const Standard_ShortReal TY);
162 //! Adds a vertice,vertex normal and texture in the vertex array.
163 //! returns the actual vertex number.
164 //! Warning: <aNormal> is ignored when the <hasVNormals>
165 //! constructor parameter is FALSE.
166 //! <aTexel> is ignored when the <hasVTexels>
167 //! constructor parameter is FALSE.
168 Standard_Integer AddVertex (const gp_Pnt& aVertice, const gp_Dir& aNormal, const gp_Pnt2d& aTexel);
170 //! Adds a vertice,vertex normal and texture in the vertex array.
171 //! returns the actual vertex number.
172 //! Warning: <aNormal> is ignored when the <hasVNormals>
173 //! constructor parameter is FALSE.
174 //! <aTexel> is ignored when the <hasVTexels>
175 //! constructor parameter is FALSE.
176 Standard_Integer AddVertex (const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Real NX, const Standard_Real NY, const Standard_Real NZ, const Standard_Real TX, const Standard_Real TY);
178 //! Adds a vertice,vertex normal and texture in the vertex array.
179 //! returns the actual vertex number.
180 //! Warning: <aNormal> is ignored when the <hasVNormals>
181 //! constructor parameter is FALSE.
182 //! <aTexel> is ignored when the <hasVTexels>
183 //! constructor parameter is FALSE.
184 Standard_EXPORT Standard_Integer AddVertex (const Standard_ShortReal X, const Standard_ShortReal Y, const Standard_ShortReal Z, const Standard_ShortReal NX, const Standard_ShortReal NY, const Standard_ShortReal NZ, const Standard_ShortReal TX, const Standard_ShortReal TY);
186 //! Adds a bound of length <edgeNumber> in the bound array
187 //! returns the actual bounds number.
188 Standard_EXPORT Standard_Integer AddBound (const Standard_Integer edgeNumber);
190 //! Adds a bound of length <edgeNumber> and bound color
191 //! <aBColor> in the bound array.
192 //! returns the actual bounds number.
193 //! Warning: <aBColor> is ignored when the <hasBColors>
194 //! constructor parameter is FALSE
195 Standard_EXPORT Standard_Integer AddBound (const Standard_Integer edgeNumber, const Quantity_Color& aBColor);
197 //! Adds a bound of length <edgeNumber> and bound color
198 //! coordinates in the bound array.
199 //! returns the actual bounds number.
200 //! Warning: <R,G,B> are ignored when the <hasBColors>
201 //! constructor parameter is FALSE
202 Standard_EXPORT Standard_Integer AddBound (const Standard_Integer edgeNumber, const Standard_Real R, const Standard_Real G, const Standard_Real B);
204 //! Adds an edge in the range [1,VertexNumber()] in the array.
205 //! Returns the actual edges number.
206 Standard_EXPORT Standard_Integer AddEdge (const Standard_Integer vertexIndex);
208 //! Change the vertice of rank <anIndex> in the array.
209 Standard_EXPORT void SetVertice (const Standard_Integer anIndex, const gp_Pnt& aVertice);
211 //! Change the vertice of rank <anIndex> in the array.
212 void SetVertice (const Standard_Integer anIndex, const Standard_ShortReal X, const Standard_ShortReal Y, const Standard_ShortReal Z);
214 //! Change the vertex color of rank <anIndex> in the array.
215 Standard_EXPORT void SetVertexColor (const Standard_Integer anIndex, const Quantity_Color& aColor);
217 //! Change the vertex color of rank <anIndex> in the array.
218 void SetVertexColor (const Standard_Integer anIndex, const Standard_Real R, const Standard_Real G, const Standard_Real B);
220 //! Change the vertex color of rank <theIndex> in the array.
221 void SetVertexColor (const Standard_Integer theIndex,
222 const Graphic3d_Vec4ub& theColor);
224 //! Change the vertex color of rank <anIndex> in the array.
225 //! aColor = Alpha << 24 + Blue << 16 + Green << 8 + Red
226 //! On all architecture proccers type (x86 or SPARC) you can
227 //! use this byte order.
228 Standard_EXPORT void SetVertexColor (const Standard_Integer anIndex, const Standard_Integer aColor);
230 //! Change the vertex normal of rank <anIndex> in the array.
231 Standard_EXPORT void SetVertexNormal (const Standard_Integer anIndex, const gp_Dir& aNormal);
233 //! Change the vertex normal of rank <anIndex> in the array.
234 void SetVertexNormal (const Standard_Integer anIndex, const Standard_Real NX, const Standard_Real NY, const Standard_Real NZ);
236 //! Change the vertex texel of rank <anIndex> in the array.
237 Standard_EXPORT void SetVertexTexel (const Standard_Integer anIndex, const gp_Pnt2d& aTexel);
239 //! Change the vertex texel of rank <anIndex> in the array.
240 void SetVertexTexel (const Standard_Integer anIndex, const Standard_Real TX, const Standard_Real TY);
242 //! Change the bound color of rank <anIndex> in the array.
243 Standard_EXPORT void SetBoundColor (const Standard_Integer anIndex, const Quantity_Color& aColor);
245 //! Change the bound color of rank <anIndex> in the array.
246 void SetBoundColor (const Standard_Integer anIndex, const Standard_Real R, const Standard_Real G, const Standard_Real B);
248 //! Returns optional index buffer.
249 const Handle(Graphic3d_IndexBuffer)& Indices() const;
251 //! Returns vertex attributes buffer (colors, normals, texture coordinates).
252 const Handle(Graphic3d_Buffer)& Attributes() const;
254 //! Returns optional bounds buffer.
255 const Handle(Graphic3d_BoundBuffer)& Bounds() const;
257 //! Returns the type of this primitive
258 Graphic3d_TypeOfPrimitiveArray Type() const;
260 //! Returns the string type of this primitive
261 Standard_EXPORT Standard_CString StringType() const;
263 //! Returns TRUE when vertex normals array is defined.
264 Standard_Boolean HasVertexNormals() const;
266 //! Returns TRUE when vertex colors array is defined.
267 Standard_Boolean HasVertexColors() const;
269 //! Returns TRUE when vertex texels array is defined.
270 Standard_Boolean HasVertexTexels() const;
272 //! Returns the number of defined vertex
273 Standard_Integer VertexNumber() const;
275 //! Returns the vertice at rank <aRank>
276 //! from the vertex table if defined.
277 Standard_EXPORT gp_Pnt Vertice (const Standard_Integer aRank) const;
279 //! Returns the vertice coordinates at rank <aRank>
280 //! from the vertex table if defined.
281 void Vertice (const Standard_Integer aRank, Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const;
283 //! Returns the vertex color at rank <aRank>
284 //! from the vertex table if defined.
285 Standard_EXPORT Quantity_Color VertexColor (const Standard_Integer aRank) const;
287 //! Returns the vertex color values at rank <aRank>
288 //! from the vertex table if defined.
289 void VertexColor (const Standard_Integer aRank, Standard_Real& R, Standard_Real& G, Standard_Real& B) const;
291 //! Returns the vertex color values at rank <aRank>
292 //! from the vertex table if defined.
293 void VertexColor (const Standard_Integer aRank, Standard_Integer& aColor) const;
295 //! Returns the vertex normal at rank <aRank>
296 //! from the vertex table if defined.
297 Standard_EXPORT gp_Dir VertexNormal (const Standard_Integer aRank) const;
299 //! Returns the vertex normal coordinates at rank <aRank>
300 //! from the vertex table if defined.
301 void VertexNormal (const Standard_Integer aRank, Standard_Real& NX, Standard_Real& NY, Standard_Real& NZ) const;
303 //! Returns the vertex texture at rank <aRank>
304 //! from the vertex table if defined.
305 Standard_EXPORT gp_Pnt2d VertexTexel (const Standard_Integer aRank) const;
307 //! Returns the vertex texture coordinates at rank <aRank>
308 //! from the vertex table if defined.
309 void VertexTexel (const Standard_Integer aRank, Standard_Real& TX, Standard_Real& TY) const;
311 //! Returns the number of defined edges
312 Standard_Integer EdgeNumber() const;
314 //! Returns the vertex index at rank <aRank>
315 //! in the range [1,VertexNumber()]
316 Standard_Integer Edge (const Standard_Integer aRank) const;
318 //! Returns TRUE when bound colors array is defined.
319 Standard_Boolean HasBoundColors() const;
321 //! Returns the number of defined bounds
322 Standard_Integer BoundNumber() const;
324 //! Returns the edge number at rank <aRank>.
325 Standard_Integer Bound (const Standard_Integer aRank) const;
327 //! Returns the bound color at rank <aRank>
328 //! from the bound table if defined.
329 Standard_EXPORT Quantity_Color BoundColor (const Standard_Integer aRank) const;
331 //! Returns the bound color values at rank <aRank>
332 //! from the bound table if defined.
333 Standard_EXPORT void BoundColor (const Standard_Integer aRank, Standard_Real& R, Standard_Real& G, Standard_Real& B) const;
335 //! Returns the number of total items according to
337 Standard_EXPORT Standard_Integer ItemNumber() const;
339 //! Returns TRUE only when the contains of this array is
341 Standard_EXPORT Standard_Boolean IsValid();
343 friend class Graphic3d_Group;
346 DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfPrimitives,MMgt_TShared)
352 //! You must use a coherent set of AddVertex() methods according to the
353 //! <hasVNormals>,<hasVColors>,<hasVTexels>,<hasBColors>
354 //! User is responsible of confuse vertex and bad normal orientation.
355 //! You must use AddBound() method only if the <maxBounds>
356 //! constructor parameter is > 0.
357 //! You must use AddEdge() method only if the <maxEdges>
358 //! constructor parameter is > 0.
359 Standard_EXPORT Graphic3d_ArrayOfPrimitives(const Graphic3d_TypeOfPrimitiveArray aType, const Standard_Integer maxVertexs, const Standard_Integer maxBounds, const Standard_Integer maxEdges, const Standard_Boolean hasVNormals, const Standard_Boolean hasVColors, const Standard_Boolean hasBColors, const Standard_Boolean hasTexels);
366 Standard_EXPORT void ComputeVNormals (const Standard_Integer fromIndex, const Standard_Integer toIndex);
368 Handle(Graphic3d_IndexBuffer) myIndices;
369 Handle(Graphic3d_Buffer) myAttribs;
370 Handle(Graphic3d_BoundBuffer) myBounds;
371 Graphic3d_TypeOfPrimitiveArray myType;
372 Standard_Integer myMaxBounds;
373 Standard_Integer myMaxVertexs;
374 Standard_Integer myMaxEdges;
375 Standard_Byte myVNor;
376 Standard_Byte myVTex;
377 Standard_Byte myVCol;
383 #include <Graphic3d_ArrayOfPrimitives.lxx>
389 #endif // _Graphic3d_ArrayOfPrimitives_HeaderFile