1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-06-10 11:34:06 +03:00
occt/src/Graphic3d/Graphic3d_ArrayOfPrimitives.lxx
vpa 53a701974a 0025935: Visualization, TKV3d, Exception when displaying shell in the viewer
Fixed processing of double precision numbers in Visual3d_View::MinMaxValues;
Test case for issue #25935.
2015-04-06 17:23:35 +03:00

411 lines
14 KiB
Plaintext

// Created on: 2000-06-16
// Copyright (c) 2000-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <Graphic3d_ArrayOfPrimitives.hxx>
#include <Standard_OutOfRange.hxx>
#include <gp_Dir.hxx>
#include <gp_Pnt.hxx>
inline const Handle(Graphic3d_IndexBuffer)& Graphic3d_ArrayOfPrimitives::Indices() const
{
return myIndices;
}
inline const Handle(Graphic3d_Buffer)& Graphic3d_ArrayOfPrimitives::Attributes() const
{
return myAttribs;
}
inline const Handle(Graphic3d_BoundBuffer)& Graphic3d_ArrayOfPrimitives::Bounds() const
{
return myBounds;
}
inline Graphic3d_TypeOfPrimitiveArray Graphic3d_ArrayOfPrimitives::Type() const
{
return myType;
}
inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexNormals() const
{
return myVNor != 0;
}
inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexColors() const
{
return myVCol != 0;
}
inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexTexels() const
{
return myVTex != 0;
}
inline Standard_Integer Graphic3d_ArrayOfPrimitives::VertexNumber() const
{
return !myAttribs.IsNull() ? myAttribs->NbElements : -1;
}
inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const gp_Pnt& theVertex)
{
return AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z());
}
inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const Graphic3d_Vec3& theVertex)
{
return AddVertex (theVertex.x(), theVertex.y(), theVertex.z());
}
inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const Standard_Real theX,
const Standard_Real theY,
const Standard_Real theZ)
{
return AddVertex (RealToShortReal (theX),
RealToShortReal (theY),
RealToShortReal (theZ));
}
inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const gp_Pnt& theVertex,
const gp_Dir& theNormal)
{
return AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z(),
theNormal.X(), theNormal.Y(), theNormal.Z());
}
inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
const Standard_Real theNX, const Standard_Real theNY, const Standard_Real theNZ)
{
return AddVertex (RealToShortReal (theX), RealToShortReal (theY), RealToShortReal (theZ),
Standard_ShortReal (theNX), Standard_ShortReal (theNY), Standard_ShortReal (theNZ));
}
inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const gp_Pnt& theVertex,
const gp_Pnt2d& theTexel)
{
return AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z(),
theTexel.X(), theTexel.Y());
}
inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
const Standard_Real theTX, const Standard_Real theTY)
{
return AddVertex (RealToShortReal (theX), RealToShortReal (theY), RealToShortReal (theZ),
Standard_ShortReal (theTX), Standard_ShortReal (theTY));
}
inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const gp_Pnt& theVertex,
const gp_Dir& theNormal,
const gp_Pnt2d& theTexel)
{
return AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z(),
theNormal.X(), theNormal.Y(), theNormal.Z(),
theTexel.X(), theTexel.Y());
}
inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
const Standard_Real theNX, const Standard_Real theNY, const Standard_Real theNZ,
const Standard_Real theTX, const Standard_Real theTY)
{
return AddVertex (RealToShortReal (theX), RealToShortReal (theY), RealToShortReal (theZ),
Standard_ShortReal (theNX), Standard_ShortReal (theNY), Standard_ShortReal (theNZ),
Standard_ShortReal (theTX), Standard_ShortReal (theTY));
}
inline void Graphic3d_ArrayOfPrimitives::SetVertice (const Standard_Integer theIndex,
const Standard_ShortReal theX,
const Standard_ShortReal theY,
const Standard_ShortReal theZ)
{
if (myAttribs.IsNull())
{
return;
}
if (theIndex < 1
|| theIndex > myMaxVertexs)
{
Standard_OutOfRange::Raise ("BAD VERTEX index");
}
Graphic3d_Vec3& aVec = myAttribs->ChangeValue<Graphic3d_Vec3> (theIndex - 1);
aVec.x() = theX;
aVec.y() = theY;
aVec.z() = theZ;
myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
}
inline void Graphic3d_ArrayOfPrimitives::SetVertexColor (const Standard_Integer theIndex,
const Standard_Real theR,
const Standard_Real theG,
const Standard_Real theB)
{
if (myAttribs.IsNull())
{
return;
}
if (theIndex < 1
|| theIndex > myMaxVertexs)
{
Standard_OutOfRange::Raise ("BAD VERTEX index");
}
if (myVCol != 0)
{
Graphic3d_Vec4ub aColor (Standard_Byte(theR * 255.0),
Standard_Byte(theG * 255.0),
Standard_Byte(theB * 255.0), 0);
SetVertexColor (theIndex, *reinterpret_cast<Standard_Integer*>(&aColor));
}
myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
}
inline void Graphic3d_ArrayOfPrimitives::SetVertexNormal (const Standard_Integer theIndex,
const Standard_Real theNX,
const Standard_Real theNY,
const Standard_Real theNZ)
{
if (myAttribs.IsNull())
{
return;
}
if (theIndex < 1
|| theIndex > myMaxVertexs)
{
Standard_OutOfRange::Raise ("BAD VERTEX index");
}
if (myVNor != 0)
{
Graphic3d_Vec3& aVec = *reinterpret_cast<Graphic3d_Vec3* >(myAttribs->changeValue (theIndex - 1) + size_t(myVNor));
aVec.x() = Standard_ShortReal (theNX);
aVec.y() = Standard_ShortReal (theNY);
aVec.z() = Standard_ShortReal (theNZ);
}
myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
}
inline void Graphic3d_ArrayOfPrimitives::SetVertexTexel (const Standard_Integer theIndex,
const Standard_Real theTX,
const Standard_Real theTY)
{
if (myAttribs.IsNull())
{
return;
}
if (theIndex < 1
|| theIndex > myMaxVertexs)
{
Standard_OutOfRange::Raise ("BAD VERTEX index");
}
if (myVTex != 0)
{
Graphic3d_Vec2& aVec = *reinterpret_cast<Graphic3d_Vec2* >(myAttribs->changeValue (theIndex - 1) + size_t(myVTex));
aVec.x() = Standard_ShortReal (theTX);
aVec.y() = Standard_ShortReal (theTY);
}
myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
}
inline void Graphic3d_ArrayOfPrimitives::SetBoundColor (const Standard_Integer theIndex,
const Standard_Real theR,
const Standard_Real theG,
const Standard_Real theB)
{
if (myBounds.IsNull())
{
return;
}
if (theIndex < 1
|| theIndex > myMaxBounds)
{
Standard_OutOfRange::Raise ("BAD BOUND index");
}
Graphic3d_Vec4& aVec = myBounds->Colors[theIndex - 1];
aVec.r() = Standard_ShortReal (theR);
aVec.g() = Standard_ShortReal (theG);
aVec.b() = Standard_ShortReal (theB);
aVec.a() = 1.0f;
myBounds->NbBounds = Max (theIndex, myBounds->NbBounds);
}
inline void Graphic3d_ArrayOfPrimitives::Vertice (const Standard_Integer theIndex,
Standard_Real& theX,
Standard_Real& theY,
Standard_Real& theZ) const
{
theX = theY = theZ = 0.0;
if (myAttribs.IsNull())
{
return;
}
if (theIndex < 1
|| theIndex > myAttribs->NbElements)
{
Standard_OutOfRange::Raise ("BAD VERTEX index");
}
const Graphic3d_Vec3& aVec = myAttribs->Value<Graphic3d_Vec3> (theIndex - 1);
theX = Standard_Real(aVec.x());
theY = Standard_Real(aVec.y());
theZ = Standard_Real(aVec.z());
}
inline void Graphic3d_ArrayOfPrimitives::VertexColor (const Standard_Integer theIndex,
Standard_Real& theR,
Standard_Real& theG,
Standard_Real& theB) const
{
theR = theG = theB = 0.0;
if (myAttribs.IsNull())
{
return;
}
if (theIndex < 1
|| theIndex > myAttribs->NbElements)
{
Standard_OutOfRange::Raise ("BAD VERTEX index");
}
Standard_Integer aColorInt = 0;
VertexColor (theIndex, aColorInt);
const Graphic3d_Vec4ub& aColor = *reinterpret_cast<const Graphic3d_Vec4ub* >(aColorInt);
theR = Standard_Real(aColor.r()) / 255.0;
theG = Standard_Real(aColor.g()) / 255.0;
theB = Standard_Real(aColor.b()) / 255.0;
}
inline void Graphic3d_ArrayOfPrimitives::VertexColor (const Standard_Integer theIndex,
Standard_Integer& theColor) const
{
if (myVCol != 0)
{
theColor = *reinterpret_cast<const Standard_Integer* >(myAttribs->value (theIndex - 1) + size_t(myVCol));
}
}
inline void Graphic3d_ArrayOfPrimitives::VertexNormal (const Standard_Integer theIndex,
Standard_Real& theNX,
Standard_Real& theNY,
Standard_Real& theNZ) const
{
theNX = theNY = theNZ = 0.0;
if (myAttribs.IsNull())
{
return;
}
if (theIndex < 1
|| theIndex > myAttribs->NbElements)
{
Standard_OutOfRange::Raise ("BAD VERTEX index");
}
if (myVNor != 0)
{
const Graphic3d_Vec3& aVec = *reinterpret_cast<const Graphic3d_Vec3* >(myAttribs->value (theIndex - 1) + size_t(myVNor));
theNX = Standard_Real(aVec.x());
theNY = Standard_Real(aVec.y());
theNZ = Standard_Real(aVec.z());
}
}
inline void Graphic3d_ArrayOfPrimitives::VertexTexel (const Standard_Integer theIndex,
Standard_Real& theTX,
Standard_Real& theTY) const
{
theTX = theTY = 0.0;
if (myAttribs.IsNull())
{
return;
}
if (theIndex < 1
|| theIndex > myAttribs->NbElements)
{
Standard_OutOfRange::Raise ("BAD VERTEX index");
}
if (myVTex != 0)
{
const Graphic3d_Vec2& aVec = *reinterpret_cast<const Graphic3d_Vec2* >(myAttribs->value (theIndex - 1) + size_t(myVTex));
theTX = Standard_Real(aVec.x());
theTY = Standard_Real(aVec.y());
}
}
inline Standard_Integer Graphic3d_ArrayOfPrimitives::EdgeNumber() const
{
return !myIndices.IsNull() ? myIndices->NbElements : -1;
}
inline Standard_Integer Graphic3d_ArrayOfPrimitives::Edge (const Standard_Integer theIndex) const
{
if (myIndices.IsNull()
|| theIndex <= 0
|| theIndex > myIndices->NbElements)
{
Standard_OutOfRange::Raise ("BAD EDGE index");
}
return Standard_Integer(myIndices->Index (theIndex - 1) + 1);
}
inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasBoundColors() const
{
return !myBounds.IsNull() && myBounds->Colors != NULL;
}
inline Standard_Integer Graphic3d_ArrayOfPrimitives::BoundNumber() const
{
return !myBounds.IsNull() ? myBounds->NbBounds : -1;
}
inline Standard_Integer Graphic3d_ArrayOfPrimitives::Bound (const Standard_Integer theIndex) const
{
if (myBounds.IsNull()
|| theIndex <= 0
|| theIndex > myBounds->NbBounds)
{
Standard_OutOfRange::Raise ("BAD BOUND index");
}
return myBounds->Bounds[theIndex - 1];
}
inline void Graphic3d_ArrayOfPrimitives::BoundColor (const Standard_Integer theIndex,
Standard_Real& theR,
Standard_Real& theG,
Standard_Real& theB) const
{
if (myBounds.IsNull()
|| myBounds->Colors == NULL
|| theIndex <= 0
|| theIndex > myBounds->NbBounds)
{
Standard_OutOfRange::Raise(" BAD BOUND index");
}
const Graphic3d_Vec4& aVec = myBounds->Colors[theIndex - 1];
theR = Standard_Real(aVec.r());
theG = Standard_Real(aVec.g());
theB = Standard_Real(aVec.b());
}