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 gp_Pnt& theVertex,
72 const Graphic3d_Vec4ub& theColor)
74 const Standard_Integer anIndex = AddVertex (theVertex);
75 SetVertexColor (anIndex, theColor);
79 inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const Standard_Real theX,
80 const Standard_Real theY,
81 const Standard_Real theZ)
83 return AddVertex (RealToShortReal (theX),
84 RealToShortReal (theY),
85 RealToShortReal (theZ));
88 inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const gp_Pnt& theVertex,
89 const gp_Dir& theNormal)
91 return AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z(),
92 theNormal.X(), theNormal.Y(), theNormal.Z());
95 inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
96 const Standard_Real theNX, const Standard_Real theNY, const Standard_Real theNZ)
98 return AddVertex (RealToShortReal (theX), RealToShortReal (theY), RealToShortReal (theZ),
99 Standard_ShortReal (theNX), Standard_ShortReal (theNY), Standard_ShortReal (theNZ));
102 inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const gp_Pnt& theVertex,
103 const gp_Pnt2d& theTexel)
105 return AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z(),
106 theTexel.X(), theTexel.Y());
109 inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
110 const Standard_Real theTX, const Standard_Real theTY)
112 return AddVertex (RealToShortReal (theX), RealToShortReal (theY), RealToShortReal (theZ),
113 Standard_ShortReal (theTX), Standard_ShortReal (theTY));
116 inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const gp_Pnt& theVertex,
117 const gp_Dir& theNormal,
118 const gp_Pnt2d& theTexel)
120 return AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z(),
121 theNormal.X(), theNormal.Y(), theNormal.Z(),
122 theTexel.X(), theTexel.Y());
125 inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
126 const Standard_Real theNX, const Standard_Real theNY, const Standard_Real theNZ,
127 const Standard_Real theTX, const Standard_Real theTY)
129 return AddVertex (RealToShortReal (theX), RealToShortReal (theY), RealToShortReal (theZ),
130 Standard_ShortReal (theNX), Standard_ShortReal (theNY), Standard_ShortReal (theNZ),
131 Standard_ShortReal (theTX), Standard_ShortReal (theTY));
134 inline void Graphic3d_ArrayOfPrimitives::SetVertice (const Standard_Integer theIndex,
135 const Standard_ShortReal theX,
136 const Standard_ShortReal theY,
137 const Standard_ShortReal theZ)
139 if (myAttribs.IsNull())
145 || theIndex > myMaxVertexs)
147 Standard_OutOfRange::Raise ("BAD VERTEX index");
150 Graphic3d_Vec3& aVec = myAttribs->ChangeValue<Graphic3d_Vec3> (theIndex - 1);
155 myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
158 inline void Graphic3d_ArrayOfPrimitives::SetVertexColor (const Standard_Integer theIndex,
159 const Standard_Real theR,
160 const Standard_Real theG,
161 const Standard_Real theB)
163 if (myAttribs.IsNull())
169 || theIndex > myMaxVertexs)
171 Standard_OutOfRange::Raise ("BAD VERTEX index");
176 Graphic3d_Vec4ub aColor (Standard_Byte(theR * 255.0),
177 Standard_Byte(theG * 255.0),
178 Standard_Byte(theB * 255.0), 0);
179 SetVertexColor (theIndex, *reinterpret_cast<Standard_Integer*>(&aColor));
181 myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
184 inline void Graphic3d_ArrayOfPrimitives::SetVertexColor (const Standard_Integer theIndex,
185 const Graphic3d_Vec4ub& theColor)
187 SetVertexColor (theIndex, *reinterpret_cast<const Standard_Integer*> (&theColor));
190 inline void Graphic3d_ArrayOfPrimitives::SetVertexNormal (const Standard_Integer theIndex,
191 const Standard_Real theNX,
192 const Standard_Real theNY,
193 const Standard_Real theNZ)
195 if (myAttribs.IsNull())
201 || theIndex > myMaxVertexs)
203 Standard_OutOfRange::Raise ("BAD VERTEX index");
208 Graphic3d_Vec3& aVec = *reinterpret_cast<Graphic3d_Vec3* >(myAttribs->changeValue (theIndex - 1) + size_t(myVNor));
209 aVec.x() = Standard_ShortReal (theNX);
210 aVec.y() = Standard_ShortReal (theNY);
211 aVec.z() = Standard_ShortReal (theNZ);
213 myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
216 inline void Graphic3d_ArrayOfPrimitives::SetVertexTexel (const Standard_Integer theIndex,
217 const Standard_Real theTX,
218 const Standard_Real theTY)
220 if (myAttribs.IsNull())
226 || theIndex > myMaxVertexs)
228 Standard_OutOfRange::Raise ("BAD VERTEX index");
233 Graphic3d_Vec2& aVec = *reinterpret_cast<Graphic3d_Vec2* >(myAttribs->changeValue (theIndex - 1) + size_t(myVTex));
234 aVec.x() = Standard_ShortReal (theTX);
235 aVec.y() = Standard_ShortReal (theTY);
237 myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
240 inline void Graphic3d_ArrayOfPrimitives::SetBoundColor (const Standard_Integer theIndex,
241 const Standard_Real theR,
242 const Standard_Real theG,
243 const Standard_Real theB)
245 if (myBounds.IsNull())
251 || theIndex > myMaxBounds)
253 Standard_OutOfRange::Raise ("BAD BOUND index");
256 Graphic3d_Vec4& aVec = myBounds->Colors[theIndex - 1];
257 aVec.r() = Standard_ShortReal (theR);
258 aVec.g() = Standard_ShortReal (theG);
259 aVec.b() = Standard_ShortReal (theB);
261 myBounds->NbBounds = Max (theIndex, myBounds->NbBounds);
264 inline void Graphic3d_ArrayOfPrimitives::Vertice (const Standard_Integer theIndex,
267 Standard_Real& theZ) const
269 theX = theY = theZ = 0.0;
270 if (myAttribs.IsNull())
276 || theIndex > myAttribs->NbElements)
278 Standard_OutOfRange::Raise ("BAD VERTEX index");
281 const Graphic3d_Vec3& aVec = myAttribs->Value<Graphic3d_Vec3> (theIndex - 1);
282 theX = Standard_Real(aVec.x());
283 theY = Standard_Real(aVec.y());
284 theZ = Standard_Real(aVec.z());
287 inline void Graphic3d_ArrayOfPrimitives::VertexColor (const Standard_Integer theIndex,
290 Standard_Real& theB) const
292 theR = theG = theB = 0.0;
293 if (myAttribs.IsNull())
299 || theIndex > myAttribs->NbElements)
301 Standard_OutOfRange::Raise ("BAD VERTEX index");
303 Standard_Integer aColorInt = 0;
304 VertexColor (theIndex, aColorInt);
305 const Graphic3d_Vec4ub& aColor = *reinterpret_cast<const Graphic3d_Vec4ub* >(&aColorInt);
306 theR = Standard_Real(aColor.r()) / 255.0;
307 theG = Standard_Real(aColor.g()) / 255.0;
308 theB = Standard_Real(aColor.b()) / 255.0;
311 inline void Graphic3d_ArrayOfPrimitives::VertexColor (const Standard_Integer theIndex,
312 Standard_Integer& theColor) const
316 theColor = *reinterpret_cast<const Standard_Integer* >(myAttribs->value (theIndex - 1) + size_t(myVCol));
320 inline void Graphic3d_ArrayOfPrimitives::VertexNormal (const Standard_Integer theIndex,
321 Standard_Real& theNX,
322 Standard_Real& theNY,
323 Standard_Real& theNZ) const
325 theNX = theNY = theNZ = 0.0;
326 if (myAttribs.IsNull())
332 || theIndex > myAttribs->NbElements)
334 Standard_OutOfRange::Raise ("BAD VERTEX index");
339 const Graphic3d_Vec3& aVec = *reinterpret_cast<const Graphic3d_Vec3* >(myAttribs->value (theIndex - 1) + size_t(myVNor));
340 theNX = Standard_Real(aVec.x());
341 theNY = Standard_Real(aVec.y());
342 theNZ = Standard_Real(aVec.z());
346 inline void Graphic3d_ArrayOfPrimitives::VertexTexel (const Standard_Integer theIndex,
347 Standard_Real& theTX,
348 Standard_Real& theTY) const
351 if (myAttribs.IsNull())
357 || theIndex > myAttribs->NbElements)
359 Standard_OutOfRange::Raise ("BAD VERTEX index");
364 const Graphic3d_Vec2& aVec = *reinterpret_cast<const Graphic3d_Vec2* >(myAttribs->value (theIndex - 1) + size_t(myVTex));
365 theTX = Standard_Real(aVec.x());
366 theTY = Standard_Real(aVec.y());
370 inline Standard_Integer Graphic3d_ArrayOfPrimitives::EdgeNumber() const
372 return !myIndices.IsNull() ? myIndices->NbElements : -1;
375 inline Standard_Integer Graphic3d_ArrayOfPrimitives::Edge (const Standard_Integer theIndex) const
377 if (myIndices.IsNull()
379 || theIndex > myIndices->NbElements)
381 Standard_OutOfRange::Raise ("BAD EDGE index");
383 return Standard_Integer(myIndices->Index (theIndex - 1) + 1);
386 inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasBoundColors() const
388 return !myBounds.IsNull() && myBounds->Colors != NULL;
391 inline Standard_Integer Graphic3d_ArrayOfPrimitives::BoundNumber() const
393 return !myBounds.IsNull() ? myBounds->NbBounds : -1;
396 inline Standard_Integer Graphic3d_ArrayOfPrimitives::Bound (const Standard_Integer theIndex) const
398 if (myBounds.IsNull()
400 || theIndex > myBounds->NbBounds)
402 Standard_OutOfRange::Raise ("BAD BOUND index");
404 return myBounds->Bounds[theIndex - 1];
407 inline void Graphic3d_ArrayOfPrimitives::BoundColor (const Standard_Integer theIndex,
410 Standard_Real& theB) const
412 if (myBounds.IsNull()
413 || myBounds->Colors == NULL
415 || theIndex > myBounds->NbBounds)
417 Standard_OutOfRange::Raise(" BAD BOUND index");
420 const Graphic3d_Vec4& aVec = myBounds->Colors[theIndex - 1];
421 theR = Standard_Real(aVec.r());
422 theG = Standard_Real(aVec.g());
423 theB = Standard_Real(aVec.b());