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 #include <Graphic3d_ArrayOfPrimitives.hxx>
16 #include <Standard_OutOfRange.hxx>
21 inline const Handle(Graphic3d_IndexBuffer)& Graphic3d_ArrayOfPrimitives::Indices() const
26 inline const Handle(Graphic3d_Buffer)& Graphic3d_ArrayOfPrimitives::Attributes() const
31 inline const Handle(Graphic3d_BoundBuffer)& Graphic3d_ArrayOfPrimitives::Bounds() const
36 inline Graphic3d_TypeOfPrimitiveArray Graphic3d_ArrayOfPrimitives::Type() const
41 inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexNormals() const
46 inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexColors() const
51 inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexTexels() const
56 inline Standard_Integer Graphic3d_ArrayOfPrimitives::VertexNumber() const
58 return !myAttribs.IsNull() ? myAttribs->NbElements : -1;
61 inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const gp_Pnt& theVertex)
63 return AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z());
66 inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const Graphic3d_Vec3& theVertex)
68 return AddVertex (theVertex.x(), theVertex.y(), theVertex.z());
71 inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const Standard_Real theX,
72 const Standard_Real theY,
73 const Standard_Real theZ)
75 return AddVertex (RealToShortReal (theX),
76 RealToShortReal (theY),
77 RealToShortReal (theZ));
80 inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const gp_Pnt& theVertex,
81 const gp_Dir& theNormal)
83 return AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z(),
84 theNormal.X(), theNormal.Y(), theNormal.Z());
87 inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
88 const Standard_Real theNX, const Standard_Real theNY, const Standard_Real theNZ)
90 return AddVertex (RealToShortReal (theX), RealToShortReal (theY), RealToShortReal (theZ),
91 Standard_ShortReal (theNX), Standard_ShortReal (theNY), Standard_ShortReal (theNZ));
94 inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const gp_Pnt& theVertex,
95 const gp_Pnt2d& theTexel)
97 return AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z(),
98 theTexel.X(), theTexel.Y());
101 inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
102 const Standard_Real theTX, const Standard_Real theTY)
104 return AddVertex (RealToShortReal (theX), RealToShortReal (theY), RealToShortReal (theZ),
105 Standard_ShortReal (theTX), Standard_ShortReal (theTY));
108 inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const gp_Pnt& theVertex,
109 const gp_Dir& theNormal,
110 const gp_Pnt2d& theTexel)
112 return AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z(),
113 theNormal.X(), theNormal.Y(), theNormal.Z(),
114 theTexel.X(), theTexel.Y());
117 inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
118 const Standard_Real theNX, const Standard_Real theNY, const Standard_Real theNZ,
119 const Standard_Real theTX, const Standard_Real theTY)
121 return AddVertex (RealToShortReal (theX), RealToShortReal (theY), RealToShortReal (theZ),
122 Standard_ShortReal (theNX), Standard_ShortReal (theNY), Standard_ShortReal (theNZ),
123 Standard_ShortReal (theTX), Standard_ShortReal (theTY));
126 inline void Graphic3d_ArrayOfPrimitives::SetVertice (const Standard_Integer theIndex,
127 const Standard_ShortReal theX,
128 const Standard_ShortReal theY,
129 const Standard_ShortReal theZ)
131 if (myAttribs.IsNull())
137 || theIndex > myMaxVertexs)
139 Standard_OutOfRange::Raise ("BAD VERTEX index");
142 Graphic3d_Vec3& aVec = myAttribs->ChangeValue<Graphic3d_Vec3> (theIndex - 1);
147 myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
150 inline void Graphic3d_ArrayOfPrimitives::SetVertexColor (const Standard_Integer theIndex,
151 const Standard_Real theR,
152 const Standard_Real theG,
153 const Standard_Real theB)
155 if (myAttribs.IsNull())
161 || theIndex > myMaxVertexs)
163 Standard_OutOfRange::Raise ("BAD VERTEX index");
168 Graphic3d_Vec4ub aColor (Standard_Byte(theR * 255.0),
169 Standard_Byte(theG * 255.0),
170 Standard_Byte(theB * 255.0), 0);
171 SetVertexColor (theIndex, *reinterpret_cast<Standard_Integer*>(&aColor));
173 myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
176 inline void Graphic3d_ArrayOfPrimitives::SetVertexNormal (const Standard_Integer theIndex,
177 const Standard_Real theNX,
178 const Standard_Real theNY,
179 const Standard_Real theNZ)
181 if (myAttribs.IsNull())
187 || theIndex > myMaxVertexs)
189 Standard_OutOfRange::Raise ("BAD VERTEX index");
194 Graphic3d_Vec3& aVec = *reinterpret_cast<Graphic3d_Vec3* >(myAttribs->changeValue (theIndex - 1) + size_t(myVNor));
195 aVec.x() = Standard_ShortReal (theNX);
196 aVec.y() = Standard_ShortReal (theNY);
197 aVec.z() = Standard_ShortReal (theNZ);
199 myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
202 inline void Graphic3d_ArrayOfPrimitives::SetVertexTexel (const Standard_Integer theIndex,
203 const Standard_Real theTX,
204 const Standard_Real theTY)
206 if (myAttribs.IsNull())
212 || theIndex > myMaxVertexs)
214 Standard_OutOfRange::Raise ("BAD VERTEX index");
219 Graphic3d_Vec2& aVec = *reinterpret_cast<Graphic3d_Vec2* >(myAttribs->changeValue (theIndex - 1) + size_t(myVTex));
220 aVec.x() = Standard_ShortReal (theTX);
221 aVec.y() = Standard_ShortReal (theTY);
223 myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
226 inline void Graphic3d_ArrayOfPrimitives::SetBoundColor (const Standard_Integer theIndex,
227 const Standard_Real theR,
228 const Standard_Real theG,
229 const Standard_Real theB)
231 if (myBounds.IsNull())
237 || theIndex > myMaxBounds)
239 Standard_OutOfRange::Raise ("BAD BOUND index");
242 Graphic3d_Vec4& aVec = myBounds->Colors[theIndex - 1];
243 aVec.r() = Standard_ShortReal (theR);
244 aVec.g() = Standard_ShortReal (theG);
245 aVec.b() = Standard_ShortReal (theB);
247 myBounds->NbBounds = Max (theIndex, myBounds->NbBounds);
250 inline void Graphic3d_ArrayOfPrimitives::Vertice (const Standard_Integer theIndex,
253 Standard_Real& theZ) const
255 theX = theY = theZ = 0.0;
256 if (myAttribs.IsNull())
262 || theIndex > myAttribs->NbElements)
264 Standard_OutOfRange::Raise ("BAD VERTEX index");
267 const Graphic3d_Vec3& aVec = myAttribs->Value<Graphic3d_Vec3> (theIndex - 1);
268 theX = Standard_Real(aVec.x());
269 theY = Standard_Real(aVec.y());
270 theZ = Standard_Real(aVec.z());
273 inline void Graphic3d_ArrayOfPrimitives::VertexColor (const Standard_Integer theIndex,
276 Standard_Real& theB) const
278 theR = theG = theB = 0.0;
279 if (myAttribs.IsNull())
285 || theIndex > myAttribs->NbElements)
287 Standard_OutOfRange::Raise ("BAD VERTEX index");
289 Standard_Integer aColorInt = 0;
290 VertexColor (theIndex, aColorInt);
291 const Graphic3d_Vec4ub& aColor = *reinterpret_cast<const Graphic3d_Vec4ub* >(&aColorInt);
292 theR = Standard_Real(aColor.r()) / 255.0;
293 theG = Standard_Real(aColor.g()) / 255.0;
294 theB = Standard_Real(aColor.b()) / 255.0;
297 inline void Graphic3d_ArrayOfPrimitives::VertexColor (const Standard_Integer theIndex,
298 Standard_Integer& theColor) const
302 theColor = *reinterpret_cast<const Standard_Integer* >(myAttribs->value (theIndex - 1) + size_t(myVCol));
306 inline void Graphic3d_ArrayOfPrimitives::VertexNormal (const Standard_Integer theIndex,
307 Standard_Real& theNX,
308 Standard_Real& theNY,
309 Standard_Real& theNZ) const
311 theNX = theNY = theNZ = 0.0;
312 if (myAttribs.IsNull())
318 || theIndex > myAttribs->NbElements)
320 Standard_OutOfRange::Raise ("BAD VERTEX index");
325 const Graphic3d_Vec3& aVec = *reinterpret_cast<const Graphic3d_Vec3* >(myAttribs->value (theIndex - 1) + size_t(myVNor));
326 theNX = Standard_Real(aVec.x());
327 theNY = Standard_Real(aVec.y());
328 theNZ = Standard_Real(aVec.z());
332 inline void Graphic3d_ArrayOfPrimitives::VertexTexel (const Standard_Integer theIndex,
333 Standard_Real& theTX,
334 Standard_Real& theTY) const
337 if (myAttribs.IsNull())
343 || theIndex > myAttribs->NbElements)
345 Standard_OutOfRange::Raise ("BAD VERTEX index");
350 const Graphic3d_Vec2& aVec = *reinterpret_cast<const Graphic3d_Vec2* >(myAttribs->value (theIndex - 1) + size_t(myVTex));
351 theTX = Standard_Real(aVec.x());
352 theTY = Standard_Real(aVec.y());
356 inline Standard_Integer Graphic3d_ArrayOfPrimitives::EdgeNumber() const
358 return !myIndices.IsNull() ? myIndices->NbElements : -1;
361 inline Standard_Integer Graphic3d_ArrayOfPrimitives::Edge (const Standard_Integer theIndex) const
363 if (myIndices.IsNull()
365 || theIndex > myIndices->NbElements)
367 Standard_OutOfRange::Raise ("BAD EDGE index");
369 return Standard_Integer(myIndices->Index (theIndex - 1) + 1);
372 inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasBoundColors() const
374 return !myBounds.IsNull() && myBounds->Colors != NULL;
377 inline Standard_Integer Graphic3d_ArrayOfPrimitives::BoundNumber() const
379 return !myBounds.IsNull() ? myBounds->NbBounds : -1;
382 inline Standard_Integer Graphic3d_ArrayOfPrimitives::Bound (const Standard_Integer theIndex) const
384 if (myBounds.IsNull()
386 || theIndex > myBounds->NbBounds)
388 Standard_OutOfRange::Raise ("BAD BOUND index");
390 return myBounds->Bounds[theIndex - 1];
393 inline void Graphic3d_ArrayOfPrimitives::BoundColor (const Standard_Integer theIndex,
396 Standard_Real& theB) const
398 if (myBounds.IsNull()
399 || myBounds->Colors == NULL
401 || theIndex > myBounds->NbBounds)
403 Standard_OutOfRange::Raise(" BAD BOUND index");
406 const Graphic3d_Vec4& aVec = myBounds->Colors[theIndex - 1];
407 theR = Standard_Real(aVec.r());
408 theG = Standard_Real(aVec.g());
409 theB = Standard_Real(aVec.b());