0027860: Visualization - clean up Transformation Persistence API
[occt.git] / src / Graphic3d / Graphic3d_ArrayOfPrimitives.lxx
CommitLineData
b311480e 1// Created on: 2000-06-16
973c2be1 2// Copyright (c) 2000-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 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
973c2be1 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.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
7fd59977 14
15#include <Graphic3d_ArrayOfPrimitives.hxx>
16#include <Standard_OutOfRange.hxx>
17
b8ddfc2f 18#include <gp_Dir.hxx>
19#include <gp_Pnt.hxx>
7fd59977 20
871fa103 21inline const Handle(Graphic3d_IndexBuffer)& Graphic3d_ArrayOfPrimitives::Indices() const
22{
23 return myIndices;
24}
25
26inline const Handle(Graphic3d_Buffer)& Graphic3d_ArrayOfPrimitives::Attributes() const
b8ddfc2f 27{
871fa103 28 return myAttribs;
29}
30
31inline const Handle(Graphic3d_BoundBuffer)& Graphic3d_ArrayOfPrimitives::Bounds() const
32{
33 return myBounds;
7fd59977 34}
35
b8ddfc2f 36inline Graphic3d_TypeOfPrimitiveArray Graphic3d_ArrayOfPrimitives::Type() const
37{
871fa103 38 return myType;
7fd59977 39}
40
b8ddfc2f 41inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexNormals() const
42{
871fa103 43 return myVNor != 0;
7fd59977 44}
45
b8ddfc2f 46inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexColors() const
47{
871fa103 48 return myVCol != 0;
7fd59977 49}
50
b8ddfc2f 51inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexTexels() const
52{
871fa103 53 return myVTex != 0;
7fd59977 54}
55
b8ddfc2f 56inline Standard_Integer Graphic3d_ArrayOfPrimitives::VertexNumber() const
57{
871fa103 58 return !myAttribs.IsNull() ? myAttribs->NbElements : -1;
7fd59977 59}
60
871fa103 61inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const gp_Pnt& theVertex)
b8ddfc2f 62{
871fa103 63 return AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z());
b8ddfc2f 64}
65
a79f67f8 66inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const Graphic3d_Vec3& theVertex)
67{
68 return AddVertex (theVertex.x(), theVertex.y(), theVertex.z());
69}
70
dcc17419 71inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const gp_Pnt& theVertex,
72 const Graphic3d_Vec4ub& theColor)
73{
74 const Standard_Integer anIndex = AddVertex (theVertex);
75 SetVertexColor (anIndex, theColor);
76 return anIndex;
77}
78
871fa103 79inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const Standard_Real theX,
80 const Standard_Real theY,
81 const Standard_Real theZ)
b8ddfc2f 82{
53a70197 83 return AddVertex (RealToShortReal (theX),
84 RealToShortReal (theY),
85 RealToShortReal (theZ));
b8ddfc2f 86}
87
871fa103 88inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const gp_Pnt& theVertex,
89 const gp_Dir& theNormal)
b8ddfc2f 90{
871fa103 91 return AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z(),
92 theNormal.X(), theNormal.Y(), theNormal.Z());
b8ddfc2f 93}
94
871fa103 95inline 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)
b8ddfc2f 97{
53a70197 98 return AddVertex (RealToShortReal (theX), RealToShortReal (theY), RealToShortReal (theZ),
871fa103 99 Standard_ShortReal (theNX), Standard_ShortReal (theNY), Standard_ShortReal (theNZ));
b8ddfc2f 100}
101
871fa103 102inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const gp_Pnt& theVertex,
103 const gp_Pnt2d& theTexel)
b8ddfc2f 104{
871fa103 105 return AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z(),
106 theTexel.X(), theTexel.Y());
b8ddfc2f 107}
108
871fa103 109inline 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)
b8ddfc2f 111{
53a70197 112 return AddVertex (RealToShortReal (theX), RealToShortReal (theY), RealToShortReal (theZ),
871fa103 113 Standard_ShortReal (theTX), Standard_ShortReal (theTY));
b8ddfc2f 114}
115
871fa103 116inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const gp_Pnt& theVertex,
117 const gp_Dir& theNormal,
118 const gp_Pnt2d& theTexel)
b8ddfc2f 119{
871fa103 120 return AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z(),
121 theNormal.X(), theNormal.Y(), theNormal.Z(),
122 theTexel.X(), theTexel.Y());
b8ddfc2f 123}
124
871fa103 125inline 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)
b8ddfc2f 128{
53a70197 129 return AddVertex (RealToShortReal (theX), RealToShortReal (theY), RealToShortReal (theZ),
871fa103 130 Standard_ShortReal (theNX), Standard_ShortReal (theNY), Standard_ShortReal (theNZ),
131 Standard_ShortReal (theTX), Standard_ShortReal (theTY));
b8ddfc2f 132}
133
871fa103 134inline void Graphic3d_ArrayOfPrimitives::SetVertice (const Standard_Integer theIndex,
135 const Standard_ShortReal theX,
136 const Standard_ShortReal theY,
137 const Standard_ShortReal theZ)
b8ddfc2f 138{
871fa103 139 if (myAttribs.IsNull())
140 {
141 return;
142 }
7fd59977 143
871fa103 144 if (theIndex < 1
145 || theIndex > myMaxVertexs)
146 {
147 Standard_OutOfRange::Raise ("BAD VERTEX index");
7fd59977 148 }
871fa103 149
150 Graphic3d_Vec3& aVec = myAttribs->ChangeValue<Graphic3d_Vec3> (theIndex - 1);
151 aVec.x() = theX;
152 aVec.y() = theY;
153 aVec.z() = theZ;
154
155 myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
7fd59977 156}
157
871fa103 158inline void Graphic3d_ArrayOfPrimitives::SetVertexColor (const Standard_Integer theIndex,
159 const Standard_Real theR,
160 const Standard_Real theG,
161 const Standard_Real theB)
b8ddfc2f 162{
871fa103 163 if (myAttribs.IsNull())
164 {
165 return;
166 }
167
168 if (theIndex < 1
169 || theIndex > myMaxVertexs)
170 {
171 Standard_OutOfRange::Raise ("BAD VERTEX index");
7fd59977 172 }
173
871fa103 174 if (myVCol != 0)
175 {
176 Graphic3d_Vec4ub aColor (Standard_Byte(theR * 255.0),
177 Standard_Byte(theG * 255.0),
30c1ef75 178 Standard_Byte(theB * 255.0), 255);
871fa103 179 SetVertexColor (theIndex, *reinterpret_cast<Standard_Integer*>(&aColor));
6598416b 180 }
871fa103 181 myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
7fd59977 182}
183
dcc17419 184inline void Graphic3d_ArrayOfPrimitives::SetVertexColor (const Standard_Integer theIndex,
185 const Graphic3d_Vec4ub& theColor)
186{
187 SetVertexColor (theIndex, *reinterpret_cast<const Standard_Integer*> (&theColor));
188}
189
871fa103 190inline void Graphic3d_ArrayOfPrimitives::SetVertexNormal (const Standard_Integer theIndex,
191 const Standard_Real theNX,
192 const Standard_Real theNY,
193 const Standard_Real theNZ)
7fd59977 194{
871fa103 195 if (myAttribs.IsNull())
196 {
197 return;
7fd59977 198 }
199
871fa103 200 if (theIndex < 1
201 || theIndex > myMaxVertexs)
202 {
203 Standard_OutOfRange::Raise ("BAD VERTEX index");
204 }
7fd59977 205
871fa103 206 if (myVNor != 0)
7fd59977 207 {
871fa103 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);
7fd59977 212 }
871fa103 213 myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
7fd59977 214}
215
871fa103 216inline void Graphic3d_ArrayOfPrimitives::SetVertexTexel (const Standard_Integer theIndex,
217 const Standard_Real theTX,
218 const Standard_Real theTY)
b8ddfc2f 219{
871fa103 220 if (myAttribs.IsNull())
221 {
222 return;
7fd59977 223 }
224
871fa103 225 if (theIndex < 1
226 || theIndex > myMaxVertexs)
227 {
228 Standard_OutOfRange::Raise ("BAD VERTEX index");
7fd59977 229 }
871fa103 230
231 if (myVTex != 0)
232 {
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);
236 }
237 myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
7fd59977 238}
239
871fa103 240inline void Graphic3d_ArrayOfPrimitives::SetBoundColor (const Standard_Integer theIndex,
241 const Standard_Real theR,
242 const Standard_Real theG,
243 const Standard_Real theB)
b8ddfc2f 244{
871fa103 245 if (myBounds.IsNull())
246 {
247 return;
7fd59977 248 }
249
871fa103 250 if (theIndex < 1
251 || theIndex > myMaxBounds)
252 {
253 Standard_OutOfRange::Raise ("BAD BOUND index");
254 }
7fd59977 255
871fa103 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);
260 aVec.a() = 1.0f;
261 myBounds->NbBounds = Max (theIndex, myBounds->NbBounds);
7fd59977 262}
263
871fa103 264inline void Graphic3d_ArrayOfPrimitives::Vertice (const Standard_Integer theIndex,
265 Standard_Real& theX,
266 Standard_Real& theY,
267 Standard_Real& theZ) const
b8ddfc2f 268{
871fa103 269 theX = theY = theZ = 0.0;
270 if (myAttribs.IsNull())
271 {
272 return;
7fd59977 273 }
274
871fa103 275 if (theIndex < 1
276 || theIndex > myAttribs->NbElements)
277 {
278 Standard_OutOfRange::Raise ("BAD VERTEX index");
7fd59977 279 }
871fa103 280
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());
7fd59977 285}
286
871fa103 287inline void Graphic3d_ArrayOfPrimitives::VertexColor (const Standard_Integer theIndex,
288 Standard_Real& theR,
289 Standard_Real& theG,
290 Standard_Real& theB) const
b8ddfc2f 291{
871fa103 292 theR = theG = theB = 0.0;
293 if (myAttribs.IsNull())
294 {
295 return;
6598416b 296 }
871fa103 297
298 if (theIndex < 1
299 || theIndex > myAttribs->NbElements)
300 {
301 Standard_OutOfRange::Raise ("BAD VERTEX index");
7fd59977 302 }
871fa103 303 Standard_Integer aColorInt = 0;
304 VertexColor (theIndex, aColorInt);
9bfa28a7 305 const Graphic3d_Vec4ub& aColor = *reinterpret_cast<const Graphic3d_Vec4ub* >(&aColorInt);
871fa103 306 theR = Standard_Real(aColor.r()) / 255.0;
307 theG = Standard_Real(aColor.g()) / 255.0;
308 theB = Standard_Real(aColor.b()) / 255.0;
7fd59977 309}
310
871fa103 311inline void Graphic3d_ArrayOfPrimitives::VertexColor (const Standard_Integer theIndex,
312 Standard_Integer& theColor) const
7fd59977 313{
871fa103 314 if (myVCol != 0)
315 {
316 theColor = *reinterpret_cast<const Standard_Integer* >(myAttribs->value (theIndex - 1) + size_t(myVCol));
317 }
7fd59977 318}
319
871fa103 320inline void Graphic3d_ArrayOfPrimitives::VertexNormal (const Standard_Integer theIndex,
321 Standard_Real& theNX,
322 Standard_Real& theNY,
323 Standard_Real& theNZ) const
b8ddfc2f 324{
871fa103 325 theNX = theNY = theNZ = 0.0;
326 if (myAttribs.IsNull())
327 {
328 return;
329 }
330
331 if (theIndex < 1
332 || theIndex > myAttribs->NbElements)
333 {
334 Standard_OutOfRange::Raise ("BAD VERTEX index");
7fd59977 335 }
336
871fa103 337 if (myVNor != 0)
338 {
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());
7fd59977 343 }
344}
345
871fa103 346inline void Graphic3d_ArrayOfPrimitives::VertexTexel (const Standard_Integer theIndex,
347 Standard_Real& theTX,
348 Standard_Real& theTY) const
b8ddfc2f 349{
871fa103 350 theTX = theTY = 0.0;
351 if (myAttribs.IsNull())
352 {
353 return;
7fd59977 354 }
355
871fa103 356 if (theIndex < 1
357 || theIndex > myAttribs->NbElements)
358 {
359 Standard_OutOfRange::Raise ("BAD VERTEX index");
7fd59977 360 }
7fd59977 361
871fa103 362 if (myVTex != 0)
363 {
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());
367 }
7fd59977 368}
369
871fa103 370inline Standard_Integer Graphic3d_ArrayOfPrimitives::EdgeNumber() const
b8ddfc2f 371{
871fa103 372 return !myIndices.IsNull() ? myIndices->NbElements : -1;
7fd59977 373}
374
871fa103 375inline Standard_Integer Graphic3d_ArrayOfPrimitives::Edge (const Standard_Integer theIndex) const
b8ddfc2f 376{
871fa103 377 if (myIndices.IsNull()
378 || theIndex <= 0
379 || theIndex > myIndices->NbElements)
380 {
381 Standard_OutOfRange::Raise ("BAD EDGE index");
7fd59977 382 }
871fa103 383 return Standard_Integer(myIndices->Index (theIndex - 1) + 1);
7fd59977 384}
385
b8ddfc2f 386inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasBoundColors() const
387{
871fa103 388 return !myBounds.IsNull() && myBounds->Colors != NULL;
7fd59977 389}
390
b8ddfc2f 391inline Standard_Integer Graphic3d_ArrayOfPrimitives::BoundNumber() const
392{
871fa103 393 return !myBounds.IsNull() ? myBounds->NbBounds : -1;
7fd59977 394}
395
871fa103 396inline Standard_Integer Graphic3d_ArrayOfPrimitives::Bound (const Standard_Integer theIndex) const
b8ddfc2f 397{
871fa103 398 if (myBounds.IsNull()
399 || theIndex <= 0
400 || theIndex > myBounds->NbBounds)
401 {
402 Standard_OutOfRange::Raise ("BAD BOUND index");
7fd59977 403 }
871fa103 404 return myBounds->Bounds[theIndex - 1];
7fd59977 405}
406
871fa103 407inline void Graphic3d_ArrayOfPrimitives::BoundColor (const Standard_Integer theIndex,
408 Standard_Real& theR,
409 Standard_Real& theG,
410 Standard_Real& theB) const
b8ddfc2f 411{
871fa103 412 if (myBounds.IsNull()
413 || myBounds->Colors == NULL
414 || theIndex <= 0
415 || theIndex > myBounds->NbBounds)
416 {
7fd59977 417 Standard_OutOfRange::Raise(" BAD BOUND index");
418 }
871fa103 419
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());
7fd59977 424}