From: kgv Date: Sun, 14 Oct 2018 11:00:46 +0000 (+0300) Subject: 0030239: Visualization, Graphic3d_ArrayOfPrimitives - pass Graphic3d_ArrayFlags bitma... X-Git-Tag: V7_4_0_beta~369 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=34253146da74767b53970591f5aada9e187aeb13 0030239: Visualization, Graphic3d_ArrayOfPrimitives - pass Graphic3d_ArrayFlags bitmask instead of dedicated Boolean flags to constructor --- diff --git a/src/Graphic3d/FILES b/src/Graphic3d/FILES index 9cbee62227..c0f5472815 100755 --- a/src/Graphic3d/FILES +++ b/src/Graphic3d/FILES @@ -1,4 +1,5 @@ Graphic3d_AlphaMode.hxx +Graphic3d_ArrayFlags.hxx Graphic3d_ArrayOfPoints.hxx Graphic3d_ArrayOfPolygons.hxx Graphic3d_ArrayOfPolylines.hxx @@ -25,6 +26,7 @@ Graphic3d_BndBox4f.hxx Graphic3d_BoundBuffer.hxx Graphic3d_BSDF.cxx Graphic3d_BSDF.hxx +Graphic3d_Buffer.cxx Graphic3d_Buffer.hxx Graphic3d_BufferType.hxx Graphic3d_Camera.cxx diff --git a/src/Graphic3d/Graphic3d_ArrayFlags.hxx b/src/Graphic3d/Graphic3d_ArrayFlags.hxx new file mode 100644 index 0000000000..f2e70b9921 --- /dev/null +++ b/src/Graphic3d/Graphic3d_ArrayFlags.hxx @@ -0,0 +1,30 @@ +// Copyright (c) 2018 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. + +#ifndef _Graphic3d_ArrayFlags_HeaderFile +#define _Graphic3d_ArrayFlags_HeaderFile + +//! Bitmask for primitive array creation. +typedef Standard_Integer Graphic3d_ArrayFlags; + +//! Graphic3d_ArrayFlags bitmask values. +enum +{ + Graphic3d_ArrayFlags_None = 0x00, //!< no flags + Graphic3d_ArrayFlags_VertexNormal = 0x01, //!< per-vertex normal attribute + Graphic3d_ArrayFlags_VertexColor = 0x02, //!< per-vertex color attribute + Graphic3d_ArrayFlags_VertexTexel = 0x04, //!< per-vertex texel coordinates (UV) attribute + Graphic3d_ArrayFlags_BoundColor = 0x10, +}; + +#endif // _Graphic3d_ArrayFlags_HeaderFile diff --git a/src/Graphic3d/Graphic3d_ArrayOfPoints.hxx b/src/Graphic3d/Graphic3d_ArrayOfPoints.hxx index 99c5ae0b88..d43905ce41 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfPoints.hxx +++ b/src/Graphic3d/Graphic3d_ArrayOfPoints.hxx @@ -23,14 +23,25 @@ class Graphic3d_ArrayOfPoints : public Graphic3d_ArrayOfPrimitives DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfPoints, Graphic3d_ArrayOfPrimitives) public: - //! Creates an array of points, a single pixel point is drawn at each vertex. + //! Creates an array of points (Graphic3d_TOPA_POINTS). //! The array must be filled using the AddVertex(Point) method. + //! @param theMaxVertexs maximum number of points + //! @param theArrayFlags array flags + Graphic3d_ArrayOfPoints (Standard_Integer theMaxVertexs, + Graphic3d_ArrayFlags theArrayFlags) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POINTS, theMaxVertexs, 0, 0, theArrayFlags) {} + + //! Creates an array of points (Graphic3d_TOPA_POINTS). + //! The array must be filled using the AddVertex(Point) method. + //! @param theMaxVertexs maximum number of points //! @param theHasVColors when TRUE, AddVertex(Point,Color) should be used for specifying vertex color //! @param theHasVNormals when TRUE, AddVertex(Point,Normal) should be used for specifying vertex normal - Graphic3d_ArrayOfPoints (const Standard_Integer theMaxVertexs, - const Standard_Boolean theHasVColors = Standard_False, - const Standard_Boolean theHasVNormals = Standard_False) - : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POINTS, theMaxVertexs, 0, 0, theHasVNormals, theHasVColors, Standard_False, Standard_False) {} + Graphic3d_ArrayOfPoints (Standard_Integer theMaxVertexs, + Standard_Boolean theHasVColors = Standard_False, + Standard_Boolean theHasVNormals = Standard_False) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POINTS, theMaxVertexs, 0, 0, + (theHasVColors ? Graphic3d_ArrayFlags_VertexColor : Graphic3d_ArrayFlags_None) + | (theHasVNormals ? Graphic3d_ArrayFlags_VertexNormal : Graphic3d_ArrayFlags_None)) {} }; diff --git a/src/Graphic3d/Graphic3d_ArrayOfPolygons.hxx b/src/Graphic3d/Graphic3d_ArrayOfPolygons.hxx index 7459670e84..58c2adb645 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfPolygons.hxx +++ b/src/Graphic3d/Graphic3d_ArrayOfPolygons.hxx @@ -25,7 +25,7 @@ class Graphic3d_ArrayOfPolygons : public Graphic3d_ArrayOfPrimitives DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfPolygons, Graphic3d_ArrayOfPrimitives) public: - //! Creates an array of polygons, a polygon can be filled as: + //! Creates an array of polygons (Graphic3d_TOPA_POLYGONS), a polygon can be filled as: //! 1) Creating a single polygon defined with his vertexes, i.e: //! @code //! myArray = Graphic3d_ArrayOfPolygons (7); @@ -89,6 +89,17 @@ public: //! @param theMaxVertexs defines the maximum allowed vertex number in the array //! @param theMaxBounds defines the maximum allowed bound number in the array //! @param theMaxEdges defines the maximum allowed edge number in the array + //! @param theArrayFlags array flags + Graphic3d_ArrayOfPolygons (Standard_Integer theMaxVertexs, + Standard_Integer theMaxBounds, + Standard_Integer theMaxEdges, + Graphic3d_ArrayFlags theArrayFlags) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POLYGONS, theMaxVertexs, theMaxBounds, theMaxEdges, theArrayFlags) {} + + //! Creates an array of polygons (Graphic3d_TOPA_POLYGONS): + //! @param theMaxVertexs defines the maximum allowed vertex number in the array + //! @param theMaxBounds defines the maximum allowed bound number in the array + //! @param theMaxEdges defines the maximum allowed edge number in the array Graphic3d_ArrayOfPolygons (const Standard_Integer theMaxVertexs, const Standard_Integer theMaxBounds = 0, const Standard_Integer theMaxEdges = 0, @@ -96,7 +107,11 @@ public: const Standard_Boolean theHasVColors = Standard_False, const Standard_Boolean theHasBColors = Standard_False, const Standard_Boolean theHasVTexels = Standard_False) - : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POLYGONS, theMaxVertexs, theMaxBounds, theMaxEdges, theHasVNormals, theHasVColors, theHasBColors, theHasVTexels) {} + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POLYGONS, theMaxVertexs, theMaxBounds, theMaxEdges, + (theHasVNormals ? Graphic3d_ArrayFlags_VertexNormal : Graphic3d_ArrayFlags_None) + | (theHasVColors ? Graphic3d_ArrayFlags_VertexColor : Graphic3d_ArrayFlags_None) + | (theHasBColors ? Graphic3d_ArrayFlags_BoundColor : Graphic3d_ArrayFlags_None) + | (theHasVTexels ? Graphic3d_ArrayFlags_VertexTexel : Graphic3d_ArrayFlags_None)) {} }; diff --git a/src/Graphic3d/Graphic3d_ArrayOfPolylines.hxx b/src/Graphic3d/Graphic3d_ArrayOfPolylines.hxx index e7aed22903..786ff9ecc1 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfPolylines.hxx +++ b/src/Graphic3d/Graphic3d_ArrayOfPolylines.hxx @@ -23,7 +23,7 @@ class Graphic3d_ArrayOfPolylines : public Graphic3d_ArrayOfPrimitives DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfPolylines, Graphic3d_ArrayOfPrimitives) public: - //! Creates an array of polylines, a polyline can be filled as: + //! Creates an array of polylines (Graphic3d_TOPA_POLYLINES), a polyline can be filled as: //! 1) Creating a single polyline defined with his vertexes, i.e: //! @code //! myArray = Graphic3d_ArrayOfPolylines (7); @@ -87,14 +87,27 @@ public: //! @param theMaxVertexs defines the maximum allowed vertex number in the array //! @param theMaxBounds defines the maximum allowed bound number in the array //! @param theMaxEdges defines the maximum allowed edge number in the array + //! @param theArrayFlags array flags + Graphic3d_ArrayOfPolylines (Standard_Integer theMaxVertexs, + Standard_Integer theMaxBounds, + Standard_Integer theMaxEdges, + Graphic3d_ArrayFlags theArrayFlags) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POLYLINES, theMaxVertexs, theMaxBounds, theMaxEdges, theArrayFlags) {} + + //! Creates an array of polylines (Graphic3d_TOPA_POLYLINES). + //! @param theMaxVertexs defines the maximum allowed vertex number in the array + //! @param theMaxBounds defines the maximum allowed bound number in the array + //! @param theMaxEdges defines the maximum allowed edge number in the array //! @param theHasVColors when TRUE AddVertex(Point,Color) or AddVertex(Point,Normal,Color) should be used to specify per-vertex color values //! @param theHasBColors when TRUE AddBound(number,Color) should be used to specify sub-group color - Graphic3d_ArrayOfPolylines (const Standard_Integer theMaxVertexs, - const Standard_Integer theMaxBounds = 0, - const Standard_Integer theMaxEdges = 0, - const Standard_Boolean theHasVColors = Standard_False, - const Standard_Boolean theHasBColors = Standard_False) - : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POLYLINES, theMaxVertexs, theMaxBounds, theMaxEdges, Standard_False, theHasVColors, theHasBColors, Standard_False) {} + Graphic3d_ArrayOfPolylines (Standard_Integer theMaxVertexs, + Standard_Integer theMaxBounds = 0, + Standard_Integer theMaxEdges = 0, + Standard_Boolean theHasVColors = Standard_False, + Standard_Boolean theHasBColors = Standard_False) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POLYLINES, theMaxVertexs, theMaxBounds, theMaxEdges, + (theHasVColors ? Graphic3d_ArrayFlags_VertexColor : Graphic3d_ArrayFlags_None) + | (theHasBColors ? Graphic3d_ArrayFlags_BoundColor : Graphic3d_ArrayFlags_None)) {} }; diff --git a/src/Graphic3d/Graphic3d_ArrayOfPrimitives.cxx b/src/Graphic3d/Graphic3d_ArrayOfPrimitives.cxx index 2e9ccce9e2..4be17047b7 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfPrimitives.cxx +++ b/src/Graphic3d/Graphic3d_ArrayOfPrimitives.cxx @@ -43,25 +43,23 @@ IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ArrayOfQuadrangleStrips, Graphic3d_ArrayOfP IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ArrayOfPolygons, Graphic3d_ArrayOfPrimitives) // ======================================================================= -// function : Graphic3d_ArrayOfPrimitives +// function : init // purpose : // ======================================================================= -Graphic3d_ArrayOfPrimitives::Graphic3d_ArrayOfPrimitives (const Graphic3d_TypeOfPrimitiveArray theType, - const Standard_Integer theMaxVertexs, - const Standard_Integer theMaxBounds, - const Standard_Integer theMaxEdges, - const Standard_Boolean theHasVNormals, - const Standard_Boolean theHasVColors, - const Standard_Boolean theHasFColors, - const Standard_Boolean theHasVTexels) -: myType (theType), - myMaxBounds (0), - myMaxVertexs (0), - myMaxEdges (0), - myVNor (0), - myVTex (0), - myVCol (0) +void Graphic3d_ArrayOfPrimitives::init (Graphic3d_TypeOfPrimitiveArray theType, + Standard_Integer theMaxVertexs, + Standard_Integer theMaxBounds, + Standard_Integer theMaxEdges, + Graphic3d_ArrayFlags theArrayOptions) { + myType = theType; + myVNor = 0; + myVTex = 0; + myVCol = 0; + myAttribs.Nullify(); + myIndices.Nullify(); + myBounds.Nullify(); + Handle(NCollection_AlignedAllocator) anAlloc = new NCollection_AlignedAllocator (16); myAttribs = new Graphic3d_Buffer (anAlloc); if (theMaxVertexs < 1) @@ -96,19 +94,19 @@ Graphic3d_ArrayOfPrimitives::Graphic3d_ArrayOfPrimitives (const Graphic3d_TypeOf anAttribs[aNbAttribs].Id = Graphic3d_TOA_POS; anAttribs[aNbAttribs].DataType = Graphic3d_TOD_VEC3; ++aNbAttribs; - if (theHasVNormals) + if ((theArrayOptions & Graphic3d_ArrayFlags_VertexNormal) != 0) { anAttribs[aNbAttribs].Id = Graphic3d_TOA_NORM; anAttribs[aNbAttribs].DataType = Graphic3d_TOD_VEC3; ++aNbAttribs; } - if (theHasVTexels) + if ((theArrayOptions & Graphic3d_ArrayFlags_VertexTexel) != 0) { anAttribs[aNbAttribs].Id = Graphic3d_TOA_UV; anAttribs[aNbAttribs].DataType = Graphic3d_TOD_VEC2; ++aNbAttribs; } - if (theHasVColors) + if ((theArrayOptions & Graphic3d_ArrayFlags_VertexColor) != 0) { anAttribs[aNbAttribs].Id = Graphic3d_TOA_COLOR; anAttribs[aNbAttribs].DataType = Graphic3d_TOD_VEC4UB; @@ -121,12 +119,13 @@ Graphic3d_ArrayOfPrimitives::Graphic3d_ArrayOfPrimitives (const Graphic3d_TypeOf myIndices.Nullify(); return; } - memset (myAttribs->ChangeData (0), 0, size_t(myAttribs->Stride) * size_t(myAttribs->NbElements)); + myAttribs->NbElements = 0; + memset (myAttribs->ChangeData (0), 0, size_t(myAttribs->Stride) * size_t(myAttribs->NbMaxElements())); if (theMaxBounds > 0) { myBounds = new Graphic3d_BoundBuffer (anAlloc); - if (!myBounds->Init (theMaxBounds, theHasFColors)) + if (!myBounds->Init (theMaxBounds, (theArrayOptions & Graphic3d_ArrayFlags_BoundColor) != 0)) { myAttribs.Nullify(); myIndices.Nullify(); @@ -161,11 +160,6 @@ Graphic3d_ArrayOfPrimitives::Graphic3d_ArrayOfPrimitives (const Graphic3d_TypeOf } } } - - myAttribs->NbElements = 0; - myMaxVertexs = theMaxVertexs; - myMaxBounds = theMaxBounds; - myMaxEdges = theMaxEdges; } // ======================================================================= @@ -188,19 +182,9 @@ Graphic3d_ArrayOfPrimitives::~Graphic3d_ArrayOfPrimitives() // ======================================================================= Standard_Integer Graphic3d_ArrayOfPrimitives::AddBound (const Standard_Integer theEdgeNumber) { - if (myBounds.IsNull()) - { - return 0; - } - Standard_Integer anIndex = myBounds->NbBounds; - if (anIndex >= myMaxBounds) - { - throw Standard_OutOfRange("TOO many BOUNDS"); - } - - myBounds->Bounds[anIndex] = theEdgeNumber; - myBounds->NbBounds = ++anIndex; - return anIndex; + Standard_OutOfRange_Raise_if (myBounds.IsNull() || myBounds->NbBounds >= myBounds->NbMaxBounds, "TOO many BOUND"); + myBounds->Bounds[myBounds->NbBounds] = theEdgeNumber; + return ++myBounds->NbBounds; } // ======================================================================= @@ -212,20 +196,11 @@ Standard_Integer Graphic3d_ArrayOfPrimitives::AddBound (const Standard_Integer t const Standard_Real theG, const Standard_Real theB) { - if (myBounds.IsNull()) - { - return 0; - } - Standard_Integer anIndex = myBounds->NbBounds; - if (anIndex >= myMaxBounds) - { - throw Standard_OutOfRange("TOO many BOUND"); - } - - myBounds->Bounds[anIndex] = theEdgeNumber; - myBounds->NbBounds = ++anIndex; - SetBoundColor (anIndex, theR, theG, theB); - return anIndex; + Standard_OutOfRange_Raise_if (myBounds.IsNull() || myBounds->NbBounds >= myBounds->NbMaxBounds, "TOO many BOUND"); + myBounds->Bounds[myBounds->NbBounds] = theEdgeNumber; + ++myBounds->NbBounds; + SetBoundColor (myBounds->NbBounds, theR, theG, theB); + return myBounds->NbBounds; } // ======================================================================= @@ -234,27 +209,11 @@ Standard_Integer Graphic3d_ArrayOfPrimitives::AddBound (const Standard_Integer t // ======================================================================= Standard_Integer Graphic3d_ArrayOfPrimitives::AddEdge (const Standard_Integer theVertexIndex) { - if (myIndices.IsNull()) - { - return 0; - } - - Standard_Integer anIndex = myIndices->NbElements; - if (anIndex >= myMaxEdges) - { - throw Standard_OutOfRange("TOO many EDGE"); - } - - Standard_Integer aVertIndex = theVertexIndex - 1; - if (theVertexIndex <= 0 - || aVertIndex >= myMaxVertexs) - { - throw Standard_OutOfRange("BAD EDGE vertex index"); - } - - myIndices->SetIndex (anIndex, aVertIndex); - myIndices->NbElements = ++anIndex; - return anIndex; + Standard_OutOfRange_Raise_if (myIndices.IsNull() || myIndices->NbElements >= myIndices->NbMaxElements(), "TOO many EDGE"); + Standard_OutOfRange_Raise_if (theVertexIndex < 1 || theVertexIndex > myAttribs->NbElements, "BAD VERTEX index"); + const Standard_Integer aVertIndex = theVertexIndex - 1; + myIndices->SetIndex (myIndices->NbElements, aVertIndex); + return ++myIndices->NbElements; } // ======================================================================= diff --git a/src/Graphic3d/Graphic3d_ArrayOfPrimitives.hxx b/src/Graphic3d/Graphic3d_ArrayOfPrimitives.hxx index 490574872a..86a79ae8c0 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfPrimitives.hxx +++ b/src/Graphic3d/Graphic3d_ArrayOfPrimitives.hxx @@ -16,6 +16,7 @@ #define _Graphic3d_ArrayOfPrimitives_HeaderFile #include +#include #include #include #include @@ -58,7 +59,6 @@ DEFINE_STANDARD_HANDLE(Graphic3d_ArrayOfPrimitives, Standard_Transient) //! This is useful only in two cases - for specifying per-group color and for restarting Primitive Strips. //! WARNING! Bounds within Primitive Array break rendering batches into parts (additional for loops), //! affecting rendering performance negatively (increasing CPU load). - class Graphic3d_ArrayOfPrimitives : public Standard_Transient { DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfPrimitives, Standard_Transient) @@ -86,10 +86,10 @@ public: Standard_Boolean HasVertexTexels() const { return myVTex != 0; } //! Returns the number of defined vertex - Standard_Integer VertexNumber() const { return !myAttribs.IsNull() ? myAttribs->NbElements : -1; } + Standard_Integer VertexNumber() const { return myAttribs->NbElements; } //! Returns the number of allocated vertex - Standard_Integer VertexNumberAllocated() const { return myMaxVertexs; } + Standard_Integer VertexNumberAllocated() const { return myAttribs->NbMaxElements(); } //! Returns the number of total items according to the array type. Standard_EXPORT Standard_Integer ItemNumber() const; @@ -116,10 +116,6 @@ public: //! @return the actual vertex number. Standard_Integer AddVertex (const Standard_ShortReal theX, const Standard_ShortReal theY, const Standard_ShortReal theZ) { - if (myAttribs.IsNull()) - { - return 0; - } const Standard_Integer anIndex = myAttribs->NbElements + 1; SetVertice (anIndex, theX, theY, theZ); return anIndex; @@ -184,10 +180,6 @@ public: Standard_Integer AddVertex (const Standard_ShortReal theX, const Standard_ShortReal theY, const Standard_ShortReal theZ, const Standard_ShortReal theNX, const Standard_ShortReal theNY, const Standard_ShortReal theNZ) { - if (myAttribs.IsNull()) - { - return 0; - } const Standard_Integer anIndex = myAttribs->NbElements + 1; SetVertice (anIndex, theX, theY, theZ); SetVertexNormal (anIndex, theNX, theNY, theNZ); @@ -244,10 +236,6 @@ public: Standard_Integer AddVertex (const Standard_ShortReal theX, const Standard_ShortReal theY, const Standard_ShortReal theZ, const Standard_ShortReal theTX, const Standard_ShortReal theTY) { - if (myAttribs.IsNull()) - { - return 0; - } const Standard_Integer anIndex = myAttribs->NbElements + 1; SetVertice (anIndex, theX, theY, theZ); SetVertexTexel (anIndex, theTX, theTY); @@ -286,10 +274,6 @@ public: const Standard_ShortReal theNX, const Standard_ShortReal theNY, const Standard_ShortReal theNZ, const Standard_ShortReal theTX, const Standard_ShortReal theTY) { - if (myAttribs.IsNull()) - { - return 0; - } const Standard_Integer anIndex = myAttribs->NbElements + 1; SetVertice (anIndex, theX, theY, theZ); SetVertexNormal(anIndex, theNX, theNY, theNZ); @@ -306,16 +290,7 @@ public: //! Change the vertice of rank theIndex in the array. void SetVertice (const Standard_Integer theIndex, const Standard_ShortReal theX, const Standard_ShortReal theY, const Standard_ShortReal theZ) { - if (myAttribs.IsNull()) - { - return; - } - else if (theIndex < 1 - || theIndex > myMaxVertexs) - { - throw Standard_OutOfRange ("BAD VERTEX index"); - } - + Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > myAttribs->NbMaxElements(), "BAD VERTEX index"); Graphic3d_Vec3& aVec = myAttribs->ChangeValue (theIndex - 1); aVec.x() = theX; aVec.y() = theY; @@ -335,16 +310,7 @@ public: //! Change the vertex color of rank theIndex in the array. void SetVertexColor (const Standard_Integer theIndex, const Standard_Real theR, const Standard_Real theG, const Standard_Real theB) { - if (myAttribs.IsNull()) - { - return; - } - else if (theIndex < 1 - || theIndex > myMaxVertexs) - { - throw Standard_OutOfRange ("BAD VERTEX index"); - } - + Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > myAttribs->NbMaxElements(), "BAD VERTEX index"); if (myVCol != 0) { Graphic3d_Vec4ub *aColorPtr = @@ -360,16 +326,7 @@ public: void SetVertexColor (const Standard_Integer theIndex, const Graphic3d_Vec4ub& theColor) { - if (myAttribs.IsNull()) - { - return; - } - else if (theIndex < 1 - || theIndex > myMaxVertexs) - { - throw Standard_OutOfRange ("BAD VERTEX index"); - } - + Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > myAttribs->NbMaxElements(), "BAD VERTEX index"); if (myVCol != 0) { Graphic3d_Vec4ub *aColorPtr = @@ -385,16 +342,7 @@ public: //! @endcode void SetVertexColor (const Standard_Integer theIndex, const Standard_Integer theColor32) { - if (myAttribs.IsNull()) - { - return; - } - else if (theIndex < 1 - || theIndex > myMaxVertexs) - { - throw Standard_OutOfRange ("BAD VERTEX index"); - } - + Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > myAttribs->NbMaxElements(), "BAD VERTEX index"); if (myVCol != 0) { *reinterpret_cast(myAttribs->changeValue (theIndex - 1) + size_t(myVCol)) = theColor32; @@ -410,16 +358,7 @@ public: //! Change the vertex normal of rank theIndex in the array. void SetVertexNormal (const Standard_Integer theIndex, const Standard_Real theNX, const Standard_Real theNY, const Standard_Real theNZ) { - if (myAttribs.IsNull()) - { - return; - } - else if (theIndex < 1 - || theIndex > myMaxVertexs) - { - throw Standard_OutOfRange("BAD VERTEX index"); - } - + Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > myAttribs->NbMaxElements(), "BAD VERTEX index"); if (myVNor != 0) { Graphic3d_Vec3& aVec = *reinterpret_cast(myAttribs->changeValue (theIndex - 1) + size_t(myVNor)); @@ -439,16 +378,7 @@ public: //! Change the vertex texel of rank theIndex in the array. void SetVertexTexel (const Standard_Integer theIndex, const Standard_Real theTX, const Standard_Real theTY) { - if (myAttribs.IsNull()) - { - return; - } - else if (theIndex < 1 - || theIndex > myMaxVertexs) - { - throw Standard_OutOfRange("BAD VERTEX index"); - } - + Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > myAttribs->NbMaxElements(), "BAD VERTEX index"); if (myVTex != 0) { Graphic3d_Vec2& aVec = *reinterpret_cast(myAttribs->changeValue (theIndex - 1) + size_t(myVTex)); @@ -470,16 +400,7 @@ public: void Vertice (const Standard_Integer theRank, Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ) const { theX = theY = theZ = 0.0; - if (myAttribs.IsNull()) - { - return; - } - else if (theRank < 1 - || theRank > myAttribs->NbElements) - { - throw Standard_OutOfRange ("BAD VERTEX index"); - } - + Standard_OutOfRange_Raise_if (theRank < 1 || theRank > myAttribs->NbElements, "BAD VERTEX index"); const Graphic3d_Vec3& aVec = myAttribs->Value (theRank - 1); theX = Standard_Real(aVec.x()); theY = Standard_Real(aVec.y()); @@ -498,18 +419,7 @@ public: void VertexColor (const Standard_Integer theIndex, Graphic3d_Vec4ub& theColor) const { - if (myAttribs.IsNull() - || myVCol == 0) - { - throw Standard_OutOfRange ("Primitive array does not define color attribute"); - } - - if (theIndex < 1 - || theIndex > myAttribs->NbElements) - { - throw Standard_OutOfRange ("BAD VERTEX index"); - } - + Standard_OutOfRange_Raise_if (myVCol == 0 || theIndex < 1 || theIndex > myAttribs->NbElements, "BAD VERTEX index"); theColor = *reinterpret_cast(myAttribs->value (theIndex - 1) + size_t(myVCol)); } @@ -517,17 +427,11 @@ public: void VertexColor (const Standard_Integer theRank, Standard_Real& theR, Standard_Real& theG, Standard_Real& theB) const { theR = theG = theB = 0.0; - if (myAttribs.IsNull() - || myVCol == 0) + Standard_OutOfRange_Raise_if (theRank < 1 || theRank > myAttribs->NbElements, "BAD VERTEX index"); + if (myVCol == 0) { return; } - else if (theRank < 1 - || theRank > myAttribs->NbElements) - { - throw Standard_OutOfRange ("BAD VERTEX index"); - } - const Graphic3d_Vec4ub& aColor = *reinterpret_cast(myAttribs->value (theRank - 1) + size_t(myVCol)); theR = Standard_Real(aColor.r()) / 255.0; theG = Standard_Real(aColor.g()) / 255.0; @@ -537,6 +441,7 @@ public: //! Returns the vertex color values at rank theRank from the vertex table if defined. void VertexColor (const Standard_Integer theRank, Standard_Integer& theColor) const { + Standard_OutOfRange_Raise_if (theRank < 1 || theRank > myAttribs->NbElements, "BAD VERTEX index"); if (myVCol != 0) { theColor = *reinterpret_cast(myAttribs->value (theRank - 1) + size_t(myVCol)); @@ -555,16 +460,7 @@ public: void VertexNormal (const Standard_Integer theRank, Standard_Real& theNX, Standard_Real& theNY, Standard_Real& theNZ) const { theNX = theNY = theNZ = 0.0; - if (myAttribs.IsNull()) - { - return; - } - else if (theRank < 1 - || theRank > myAttribs->NbElements) - { - throw Standard_OutOfRange ("BAD VERTEX index"); - } - + Standard_OutOfRange_Raise_if (theRank < 1 || theRank > myAttribs->NbElements, "BAD VERTEX index"); if (myVNor != 0) { const Graphic3d_Vec3& aVec = *reinterpret_cast(myAttribs->value (theRank - 1) + size_t(myVNor)); @@ -586,16 +482,7 @@ public: void VertexTexel (const Standard_Integer theRank, Standard_Real& theTX, Standard_Real& theTY) const { theTX = theTY = 0.0; - if (myAttribs.IsNull()) - { - return; - } - else if (theRank < 1 - || theRank > myAttribs->NbElements) - { - throw Standard_OutOfRange ("BAD VERTEX index"); - } - + Standard_OutOfRange_Raise_if (theRank < 1 || theRank > myAttribs->NbElements, "BAD VERTEX index"); if (myVTex != 0) { const Graphic3d_Vec2& aVec = *reinterpret_cast(myAttribs->value (theRank - 1) + size_t(myVTex)); @@ -613,17 +500,12 @@ public: //! @name optional array of Indices/Edges for using shared Vertex data Standard_Integer EdgeNumber() const { return !myIndices.IsNull() ? myIndices->NbElements : -1; } //! Returns the number of allocated edges - Standard_Integer EdgeNumberAllocated() const { return myMaxEdges; } + Standard_Integer EdgeNumberAllocated() const { return !myIndices.IsNull() ? myIndices->NbMaxElements() : 0; } //! Returns the vertex index at rank theRank in the range [1,EdgeNumber()] Standard_Integer Edge (const Standard_Integer theRank) const { - if (myIndices.IsNull() - || theRank <= 0 - || theRank > myIndices->NbElements) - { - throw Standard_OutOfRange ("BAD EDGE index"); - } + Standard_OutOfRange_Raise_if (myIndices.IsNull() || theRank < 1 || theRank > myIndices->NbElements, "BAD EDGE index"); return Standard_Integer(myIndices->Index (theRank - 1) + 1); } @@ -676,17 +558,12 @@ public: //! @name optional array of Bounds/Subgroups within primitive array (e.g Standard_Integer BoundNumber() const { return !myBounds.IsNull() ? myBounds->NbBounds : -1; } //! Returns the number of allocated bounds - Standard_Integer BoundNumberAllocated() const { return myMaxBounds; } + Standard_Integer BoundNumberAllocated() const { return !myBounds.IsNull() ? myBounds->NbMaxBounds : 0; } //! Returns the edge number at rank theRank. Standard_Integer Bound (const Standard_Integer theRank) const { - if (myBounds.IsNull() - || theRank <= 0 - || theRank > myBounds->NbBounds) - { - throw Standard_OutOfRange ("BAD BOUND index"); - } + Standard_OutOfRange_Raise_if (myBounds.IsNull() || theRank < 1 || theRank > myBounds->NbBounds, "BAD BOUND index"); return myBounds->Bounds[theRank - 1]; } @@ -701,14 +578,7 @@ public: //! @name optional array of Bounds/Subgroups within primitive array (e.g //! Returns the bound color values at rank theRank from the bound table if defined. void BoundColor (const Standard_Integer theRank, Standard_Real& theR, Standard_Real& theG, Standard_Real& theB) const { - if (myBounds.IsNull() - || myBounds->Colors == NULL - || theRank <= 0 - || theRank > myBounds->NbBounds) - { - throw Standard_OutOfRange (" BAD BOUND index"); - } - + Standard_OutOfRange_Raise_if (myBounds.IsNull() || myBounds->Colors == NULL || theRank < 1 || theRank > myBounds->NbBounds, "BAD BOUND index"); const Graphic3d_Vec4& aVec = myBounds->Colors[theRank - 1]; theR = Standard_Real(aVec.r()); theG = Standard_Real(aVec.g()); @@ -745,12 +615,7 @@ public: //! @name optional array of Bounds/Subgroups within primitive array (e.g { return; } - else if (theIndex < 1 - || theIndex > myMaxBounds) - { - throw Standard_OutOfRange("BAD BOUND index"); - } - + Standard_OutOfRange_Raise_if (myBounds.IsNull() || myBounds->Colors == NULL || theIndex < 1 || theIndex > myBounds->NbMaxBounds, "BAD BOUND index"); Graphic3d_Vec4& aVec = myBounds->Colors[theIndex - 1]; aVec.r() = Standard_ShortReal (theR); aVec.g() = Standard_ShortReal (theG); @@ -761,19 +626,28 @@ public: //! @name optional array of Bounds/Subgroups within primitive array (e.g protected: //! @name protected constructors - //! Warning - //! You must use a coherent set of AddVertex() methods according to the theHasVNormals,theHasVColors,theHasVTexels,theHasBColors. - //! User is responsible of confuse vertex and bad normal orientation. - //! You must use AddBound() method only if the theMaxBounds constructor parameter is > 0. - //! You must use AddEdge() method only if the theMaxEdges constructor parameter is > 0. - Standard_EXPORT Graphic3d_ArrayOfPrimitives (const Graphic3d_TypeOfPrimitiveArray theType, - const Standard_Integer theMaxVertexs, - const Standard_Integer theMaxBounds, - const Standard_Integer theMaxEdges, - const Standard_Boolean theHasVNormals, - const Standard_Boolean theHasVColors, - const Standard_Boolean theHasBColors, - const Standard_Boolean theHasVTexels); + //! Main constructor. + //! @param theType type of primitive + //! @param theMaxVertexs length of vertex attributes buffer to be allocated (maximum number of vertexes, @sa ::AddVertex()) + //! @param theMaxBounds length of bounds buffer to be allocated (maximum number of bounds, @sa ::AddBound()) + //! @param theMaxEdges length of edges (index) buffer to be allocated (maximum number of indexes @sa ::AddEdge()) + //! @param theArrayFlags array flags + Graphic3d_ArrayOfPrimitives (Graphic3d_TypeOfPrimitiveArray theType, + Standard_Integer theMaxVertexs, + Standard_Integer theMaxBounds, + Standard_Integer theMaxEdges, + Graphic3d_ArrayFlags theArrayFlags) + : myType (Graphic3d_TOPA_UNDEFINED), myVNor (0), myVTex (0), myVCol (0) + { + init (theType, theMaxVertexs, theMaxBounds, theMaxEdges, theArrayFlags); + } + + //! Array constructor. + Standard_EXPORT void init (Graphic3d_TypeOfPrimitiveArray theType, + Standard_Integer theMaxVertexs, + Standard_Integer theMaxBounds, + Standard_Integer theMaxEdges, + Graphic3d_ArrayFlags theArrayFlags); private: //! @name private fields @@ -781,9 +655,6 @@ private: //! @name private fields Handle(Graphic3d_Buffer) myAttribs; Handle(Graphic3d_BoundBuffer) myBounds; Graphic3d_TypeOfPrimitiveArray myType; - Standard_Integer myMaxBounds; - Standard_Integer myMaxVertexs; - Standard_Integer myMaxEdges; Standard_Byte myVNor; Standard_Byte myVTex; Standard_Byte myVCol; diff --git a/src/Graphic3d/Graphic3d_ArrayOfQuadrangleStrips.hxx b/src/Graphic3d/Graphic3d_ArrayOfQuadrangleStrips.hxx index 8f6fbac071..039a7c6a98 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfQuadrangleStrips.hxx +++ b/src/Graphic3d/Graphic3d_ArrayOfQuadrangleStrips.hxx @@ -25,7 +25,7 @@ class Graphic3d_ArrayOfQuadrangleStrips : public Graphic3d_ArrayOfPrimitives DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfQuadrangleStrips, Graphic3d_ArrayOfPrimitives) public: - //! Creates an array of quadrangle strips, a polygon can be filled as: + //! Creates an array of quadrangle strips (Graphic3d_TOPA_QUADRANGLESTRIPS), a polygon can be filled as: //! 1) Creating a single strip defined with his vertexes, i.e: //! @code //! myArray = Graphic3d_ArrayOfQuadrangleStrips (7); @@ -45,16 +45,31 @@ public: //! .... //! myArray->AddVertex (x8, y8, z8); //! @endcode + //! The number of quadrangle really drawn is: VertexNumber()/2 - Min(1, BoundNumber()). //! @param theMaxVertexs defines the maximum allowed vertex number in the array //! @param theMaxStrips defines the maximum allowed strip number in the array - //! The number of quadrangle really drawn is: VertexNumber()/2 - Min(1, BoundNumber()). - Graphic3d_ArrayOfQuadrangleStrips (const Standard_Integer theMaxVertexs, - const Standard_Integer theMaxStrips = 0, - const Standard_Boolean theHasVNormals = Standard_False, - const Standard_Boolean theHasVColors = Standard_False, - const Standard_Boolean theHasSColors = Standard_False, - const Standard_Boolean theHasVTexels = Standard_False) - : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_QUADRANGLESTRIPS, theMaxVertexs, theMaxStrips, 0, theHasVNormals, theHasVColors, theHasSColors, theHasVTexels) {} + //! @param theArrayFlags array flags + Graphic3d_ArrayOfQuadrangleStrips (Standard_Integer theMaxVertexs, + Standard_Integer theMaxStrips, + Graphic3d_ArrayFlags theArrayFlags) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_QUADRANGLESTRIPS, theMaxVertexs, theMaxStrips, 0, theArrayFlags) {} + + //! Creates an array of quadrangle strips (Graphic3d_TOPA_QUADRANGLESTRIPS). + //! @param theMaxVertexs defines the maximum allowed vertex number in the array + //! @param theMaxStrips defines the maximum allowed strip number in the array + Graphic3d_ArrayOfQuadrangleStrips (Standard_Integer theMaxVertexs, + Standard_Integer theMaxStrips = 0, + Standard_Boolean theHasVNormals = Standard_False, + Standard_Boolean theHasVColors = Standard_False, + Standard_Boolean theHasSColors = Standard_False, + Standard_Boolean theHasVTexels = Standard_False) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_QUADRANGLESTRIPS, theMaxVertexs, theMaxStrips, 0, + (theHasVNormals ? Graphic3d_ArrayFlags_VertexNormal : Graphic3d_ArrayFlags_None) + | (theHasVColors ? Graphic3d_ArrayFlags_VertexColor : Graphic3d_ArrayFlags_None) + | (theHasVTexels ? Graphic3d_ArrayFlags_VertexTexel : Graphic3d_ArrayFlags_None) + | (theHasSColors ? Graphic3d_ArrayFlags_BoundColor : Graphic3d_ArrayFlags_None)) {} + + }; diff --git a/src/Graphic3d/Graphic3d_ArrayOfQuadrangles.hxx b/src/Graphic3d/Graphic3d_ArrayOfQuadrangles.hxx index eb6671b454..e99be7239f 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfQuadrangles.hxx +++ b/src/Graphic3d/Graphic3d_ArrayOfQuadrangles.hxx @@ -25,7 +25,7 @@ class Graphic3d_ArrayOfQuadrangles : public Graphic3d_ArrayOfPrimitives DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfQuadrangles, Graphic3d_ArrayOfPrimitives) public: - //! Creates an array of quadrangles, a quadrangle can be filled as: + //! Creates an array of quadrangles (Graphic3d_TOPA_QUADRANGLES), a quadrangle can be filled as: //! 1) Creating a set of quadrangles defined with his vertexes, i.e: //! @code //! myArray = Graphic3d_ArrayOfQuadrangles (8); @@ -39,23 +39,29 @@ public: //! myArray->AddVertex (x1, y1, z1); //! .... //! myArray->AddVertex (x6, y6, z6); - //! myArray->AddEdge (1); - //! myArray->AddEdge (2); - //! myArray->AddEdge (3); - //! myArray->AddEdge (4); - //! myArray->AddEdge (3); - //! myArray->AddEdge (4); - //! myArray->AddEdge (5); - //! myArray->AddEdge (6); + //! myArray->AddEdges (1, 2, 3, 4); + //! myArray->AddEdges (3, 4, 5, 6); //! @endcode //! @param theMaxVertexs defines the maximum allowed vertex number in the array //! @param theMaxEdges defines the maximum allowed edge number in the array (for indexed array) - Graphic3d_ArrayOfQuadrangles (const Standard_Integer theMaxVertexs, - const Standard_Integer theMaxEdges = 0, - const Standard_Boolean theHasVNormals = Standard_False, - const Standard_Boolean theHasVColors = Standard_False, - const Standard_Boolean theHasVTexels = Standard_False) - : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_QUADRANGLES, theMaxVertexs, 0, theMaxEdges, theHasVNormals, theHasVColors, Standard_False, theHasVTexels) {} + //! @param theArrayFlags array flags + Graphic3d_ArrayOfQuadrangles (Standard_Integer theMaxVertexs, + Standard_Integer theMaxEdges, + Graphic3d_ArrayFlags theArrayFlags) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_QUADRANGLES, theMaxVertexs, 0, theMaxEdges, theArrayFlags) {} + + //! Creates an array of quadrangles (Graphic3d_TOPA_QUADRANGLES). + //! @param theMaxVertexs defines the maximum allowed vertex number in the array + //! @param theMaxEdges defines the maximum allowed edge number in the array (for indexed array) + Graphic3d_ArrayOfQuadrangles (Standard_Integer theMaxVertexs, + Standard_Integer theMaxEdges = 0, + Standard_Boolean theHasVNormals = Standard_False, + Standard_Boolean theHasVColors = Standard_False, + Standard_Boolean theHasVTexels = Standard_False) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_QUADRANGLES, theMaxVertexs, 0, theMaxEdges, + (theHasVNormals ? Graphic3d_ArrayFlags_VertexNormal : Graphic3d_ArrayFlags_None) + | (theHasVColors ? Graphic3d_ArrayFlags_VertexColor : Graphic3d_ArrayFlags_None) + | (theHasVTexels ? Graphic3d_ArrayFlags_VertexTexel : Graphic3d_ArrayFlags_None)) {} }; diff --git a/src/Graphic3d/Graphic3d_ArrayOfSegments.hxx b/src/Graphic3d/Graphic3d_ArrayOfSegments.hxx index 07750ff7fb..2059c9587a 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfSegments.hxx +++ b/src/Graphic3d/Graphic3d_ArrayOfSegments.hxx @@ -23,7 +23,7 @@ class Graphic3d_ArrayOfSegments : public Graphic3d_ArrayOfPrimitives DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfSegments, Graphic3d_ArrayOfPrimitives) public: - //! Creates an array of segments, a segment can be filled as: + //! Creates an array of segments (Graphic3d_TOPA_SEGMENTS), a segment can be filled as: //! 1) Creating a set of segments defined with his vertexes, i.e: //! @code //! myArray = Graphic3d_ArrayOfSegments (4); @@ -33,26 +33,32 @@ public: //! @endcode //! 2) Creating a set of indexed segments defined with his vertex and edges, i.e: //! @code - //! myArray = Graphic3d_ArrayOfSegments (4, 0, 8); + //! myArray = Graphic3d_ArrayOfSegments (4, 8); //! myArray->AddVertex (x1, y1, z1); //! .... //! myArray->AddVertex (x4, y4, z4); - //! myArray->AddEdge (1); - //! myArray->AddEdge (2); - //! myArray->AddEdge (3); - //! myArray->AddEdge (4); - //! myArray->AddEdge (2); - //! myArray->AddEdge (4); - //! myArray->AddEdge (1); - //! myArray->AddEdge (3); + //! myArray->AddEdges (1, 2); + //! myArray->AddEdges (3, 4); + //! myArray->AddEdges (2, 4); + //! myArray->AddEdges (1, 3); //! @endcode //! @param theMaxVertexs defines the maximum allowed vertex number in the array //! @param theMaxEdges defines the maximum allowed edge number in the array + //! @param theArrayFlags array flags + Graphic3d_ArrayOfSegments (Standard_Integer theMaxVertexs, + Standard_Integer theMaxEdges, + Graphic3d_ArrayFlags theArrayFlags) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_SEGMENTS, theMaxVertexs, 0, theMaxEdges, theArrayFlags) {} + + //! Creates an array of segments (Graphic3d_TOPA_SEGMENTS). + //! @param theMaxVertexs defines the maximum allowed vertex number in the array + //! @param theMaxEdges defines the maximum allowed edge number in the array //! @param theHasVColors when TRUE, AddVertex(Point,Color) should be used for specifying vertex color - Graphic3d_ArrayOfSegments (const Standard_Integer theMaxVertexs, - const Standard_Integer theMaxEdges = 0, - const Standard_Boolean theHasVColors = Standard_False) - : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_SEGMENTS, theMaxVertexs, 0, theMaxEdges, Standard_False, theHasVColors, Standard_False, Standard_False) {} + Graphic3d_ArrayOfSegments (Standard_Integer theMaxVertexs, + Standard_Integer theMaxEdges = 0, + Standard_Boolean theHasVColors = Standard_False) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_SEGMENTS, theMaxVertexs, 0, theMaxEdges, theHasVColors ? Graphic3d_ArrayFlags_VertexColor : Graphic3d_ArrayFlags_None) {} + }; diff --git a/src/Graphic3d/Graphic3d_ArrayOfTriangleFans.hxx b/src/Graphic3d/Graphic3d_ArrayOfTriangleFans.hxx index 366d781133..bbd2f8ed3a 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfTriangleFans.hxx +++ b/src/Graphic3d/Graphic3d_ArrayOfTriangleFans.hxx @@ -23,7 +23,7 @@ class Graphic3d_ArrayOfTriangleFans : public Graphic3d_ArrayOfPrimitives DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfTriangleFans, Graphic3d_ArrayOfPrimitives) public: - //! Creates an array of triangle fans, a polygon can be filled as: + //! Creates an array of triangle fans (Graphic3d_TOPA_TRIANGLEFANS), a polygon can be filled as: //! 1) Creating a single fan defined with his vertexes, i.e: //! @code //! myArray = Graphic3d_ArrayOfTriangleFans (7); @@ -43,16 +43,29 @@ public: //! .... //! myArray->AddVertex (x8, y8, z8); //! @endcode + //! The number of triangle really drawn is: VertexNumber() - 2 * Min(1, BoundNumber()) //! @param theMaxVertexs defines the maximum allowed vertex number in the array //! @param theMaxFans defines the maximum allowed fan number in the array - //! The number of triangle really drawn is: VertexNumber() - 2 * Min(1, BoundNumber()) - Graphic3d_ArrayOfTriangleFans (const Standard_Integer theMaxVertexs, - const Standard_Integer theMaxFans = 0, - const Standard_Boolean theHasVNormals = Standard_False, - const Standard_Boolean theHasVColors = Standard_False, - const Standard_Boolean theHasBColors = Standard_False, - const Standard_Boolean theHasVTexels = Standard_False) - : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLEFANS, theMaxVertexs, theMaxFans, 0, theHasVNormals, theHasVColors, theHasBColors, theHasVTexels) {} + //! @param theArrayFlags array flags + Graphic3d_ArrayOfTriangleFans (Standard_Integer theMaxVertexs, + Standard_Integer theMaxFans, + Graphic3d_ArrayFlags theArrayFlags) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLEFANS, theMaxVertexs, theMaxFans, 0, theArrayFlags) {} + + //! Creates an array of triangle fans (Graphic3d_TOPA_TRIANGLEFANS). + //! @param theMaxVertexs defines the maximum allowed vertex number in the array + //! @param theMaxFans defines the maximum allowed fan number in the array + Graphic3d_ArrayOfTriangleFans (Standard_Integer theMaxVertexs, + Standard_Integer theMaxFans = 0, + Standard_Boolean theHasVNormals = Standard_False, + Standard_Boolean theHasVColors = Standard_False, + Standard_Boolean theHasBColors = Standard_False, + Standard_Boolean theHasVTexels = Standard_False) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLEFANS, theMaxVertexs, theMaxFans, 0, + (theHasVNormals ? Graphic3d_ArrayFlags_VertexNormal : Graphic3d_ArrayFlags_None) + | (theHasVColors ? Graphic3d_ArrayFlags_VertexColor : Graphic3d_ArrayFlags_None) + | (theHasVTexels ? Graphic3d_ArrayFlags_VertexTexel : Graphic3d_ArrayFlags_None) + | (theHasBColors ? Graphic3d_ArrayFlags_BoundColor : Graphic3d_ArrayFlags_None)) {} }; diff --git a/src/Graphic3d/Graphic3d_ArrayOfTriangleStrips.hxx b/src/Graphic3d/Graphic3d_ArrayOfTriangleStrips.hxx index e1a05e470a..5b399671ad 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfTriangleStrips.hxx +++ b/src/Graphic3d/Graphic3d_ArrayOfTriangleStrips.hxx @@ -23,7 +23,7 @@ class Graphic3d_ArrayOfTriangleStrips : public Graphic3d_ArrayOfPrimitives DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfTriangleStrips, Graphic3d_ArrayOfPrimitives) public: - //! Creates an array of triangle strips, a polygon can be filled as: + //! Creates an array of triangle strips (Graphic3d_TOPA_TRIANGLESTRIPS), a polygon can be filled as: //! 1) Creating a single strip defined with his vertexes, i.e: //! @code //! myArray = Graphic3d_ArrayOfTriangleStrips (7); @@ -46,18 +46,32 @@ public: //! @param theMaxVertexs defines the maximum allowed vertex number in the array //! @param theMaxStrips defines the maximum allowed strip number in the array; //! the number of triangle really drawn is: VertexNumber() - 2 * Min(1, BoundNumber()) + //! @param theArrayFlags array flags + Graphic3d_ArrayOfTriangleStrips (Standard_Integer theMaxVertexs, + Standard_Integer theMaxStrips, + Graphic3d_ArrayFlags theArrayFlags) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLESTRIPS, theMaxVertexs, theMaxStrips, 0, theArrayFlags) {} + + //! Creates an array of triangle strips (Graphic3d_TOPA_TRIANGLESTRIPS). + //! @param theMaxVertexs defines the maximum allowed vertex number in the array + //! @param theMaxStrips defines the maximum allowed strip number in the array; + //! the number of triangle really drawn is: VertexNumber() - 2 * Min(1, BoundNumber()) //! @param theHasVNormals when TRUE, AddVertex(Point,Normal), AddVertex(Point,Normal,Color) or AddVertex(Point,Normal,Texel) should be used to specify vertex normal; //! vertex normals should be specified coherent to triangle orientation (defined by order of vertexes within triangle) for proper rendering //! @param theHasVColors when TRUE, AddVertex(Point,Color) or AddVertex(Point,Normal,Color) should be used to specify vertex color //! @param theHasBColors when TRUE, AddBound(number,Color) should be used to specify sub-group color //! @param theHasVTexels when TRUE, AddVertex(Point,Texel) or AddVertex(Point,Normal,Texel) should be used to specify vertex UV coordinates - Graphic3d_ArrayOfTriangleStrips (const Standard_Integer theMaxVertexs, - const Standard_Integer theMaxStrips = 0, - const Standard_Boolean theHasVNormals = Standard_False, - const Standard_Boolean theHasVColors = Standard_False, - const Standard_Boolean theHasBColors = Standard_False, - const Standard_Boolean theHasVTexels = Standard_False) - : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLESTRIPS, theMaxVertexs, theMaxStrips, 0, theHasVNormals, theHasVColors, theHasBColors, theHasVTexels) {} + Graphic3d_ArrayOfTriangleStrips (Standard_Integer theMaxVertexs, + Standard_Integer theMaxStrips = 0, + Standard_Boolean theHasVNormals = Standard_False, + Standard_Boolean theHasVColors = Standard_False, + Standard_Boolean theHasBColors = Standard_False, + Standard_Boolean theHasVTexels = Standard_False) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLESTRIPS, theMaxVertexs, theMaxStrips, 0, + (theHasVNormals ? Graphic3d_ArrayFlags_VertexNormal : Graphic3d_ArrayFlags_None) + | (theHasVColors ? Graphic3d_ArrayFlags_VertexColor : Graphic3d_ArrayFlags_None) + | (theHasVTexels ? Graphic3d_ArrayFlags_VertexTexel : Graphic3d_ArrayFlags_None) + | (theHasBColors ? Graphic3d_ArrayFlags_BoundColor : Graphic3d_ArrayFlags_None)) {} }; diff --git a/src/Graphic3d/Graphic3d_ArrayOfTriangles.hxx b/src/Graphic3d/Graphic3d_ArrayOfTriangles.hxx index e4035a7450..526e497849 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfTriangles.hxx +++ b/src/Graphic3d/Graphic3d_ArrayOfTriangles.hxx @@ -23,7 +23,7 @@ class Graphic3d_ArrayOfTriangles : public Graphic3d_ArrayOfPrimitives DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfTriangles, Graphic3d_ArrayOfPrimitives) public: - //! Creates an array of triangles, a triangle can be filled as: + //! Creates an array of triangles (Graphic3d_TOPA_TRIANGLES), a triangle can be filled as: //! 1) Creating a set of triangles defined with his vertexes, i.e: //! @code //! myArray = Graphic3d_ArrayOfTriangles (6); @@ -37,25 +37,33 @@ public: //! myArray->AddVertex (x1, y1, z1); //! .... //! myArray->AddVertex (x4, y4, z4); - //! myArray->AddEdge (1); - //! myArray->AddEdge (2); - //! myArray->AddEdge (3); - //! myArray->AddEdge (2); - //! myArray->AddEdge (3); - //! myArray->AddEdge (4); + //! myArray->AddEdges (1, 2, 3); + //! myArray->AddEdges (2, 3, 4); //! @endcode //! @param theMaxVertexs defines the maximum allowed vertex number in the array //! @param theMaxEdges defines the maximum allowed edge number in the array + //! @param theArrayFlags array flags + Graphic3d_ArrayOfTriangles (Standard_Integer theMaxVertexs, + Standard_Integer theMaxEdges, + Graphic3d_ArrayFlags theArrayFlags) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLES, theMaxVertexs, 0, theMaxEdges, theArrayFlags) {} + + //! Creates an array of triangles (Graphic3d_TOPA_TRIANGLES). + //! @param theMaxVertexs defines the maximum allowed vertex number in the array + //! @param theMaxEdges defines the maximum allowed edge number in the array //! @param theHasVNormals when TRUE, AddVertex(Point,Normal), AddVertex(Point,Normal,Color) or AddVertex(Point,Normal,Texel) should be used to specify vertex normal; //! vertex normals should be specified coherent to triangle orientation (defined by order of vertexes within triangle) for proper rendering //! @param theHasVColors when TRUE, AddVertex(Point,Color) or AddVertex(Point,Normal,Color) should be used to specify vertex color //! @param theHasVTexels when TRUE, AddVertex(Point,Texel) or AddVertex(Point,Normal,Texel) should be used to specify vertex UV coordinates - Graphic3d_ArrayOfTriangles (const Standard_Integer theMaxVertexs, - const Standard_Integer theMaxEdges = 0, - const Standard_Boolean theHasVNormals = Standard_False, - const Standard_Boolean theHasVColors = Standard_False, - const Standard_Boolean theHasVTexels = Standard_False) - : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLES, theMaxVertexs, 0, theMaxEdges, theHasVNormals, theHasVColors, Standard_False, theHasVTexels) {} + Graphic3d_ArrayOfTriangles (Standard_Integer theMaxVertexs, + Standard_Integer theMaxEdges = 0, + Standard_Boolean theHasVNormals = Standard_False, + Standard_Boolean theHasVColors = Standard_False, + Standard_Boolean theHasVTexels = Standard_False) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLES, theMaxVertexs, 0, theMaxEdges, + (theHasVNormals ? Graphic3d_ArrayFlags_VertexNormal : Graphic3d_ArrayFlags_None) + | (theHasVColors ? Graphic3d_ArrayFlags_VertexColor : Graphic3d_ArrayFlags_None) + | (theHasVTexels ? Graphic3d_ArrayFlags_VertexTexel : Graphic3d_ArrayFlags_None)) {} }; diff --git a/src/Graphic3d/Graphic3d_BoundBuffer.hxx b/src/Graphic3d/Graphic3d_BoundBuffer.hxx index 18f74f756f..5aafd1cf14 100644 --- a/src/Graphic3d/Graphic3d_BoundBuffer.hxx +++ b/src/Graphic3d/Graphic3d_BoundBuffer.hxx @@ -19,6 +19,7 @@ //! Bounds buffer. class Graphic3d_BoundBuffer : public NCollection_Buffer { + DEFINE_STANDARD_RTTIEXT(Graphic3d_BoundBuffer, NCollection_Buffer) public: //! Empty constructor. @@ -26,7 +27,8 @@ public: : NCollection_Buffer (theAlloc), Colors (NULL), Bounds (NULL), - NbBounds (0) {} + NbBounds (0), + NbMaxBounds (0) {} //! Allocates new empty array bool Init (const Standard_Integer theNbBounds, @@ -35,6 +37,7 @@ public: Colors = NULL; Bounds = NULL; NbBounds = 0; + NbMaxBounds = 0; Free(); if (theNbBounds < 1) { @@ -52,6 +55,7 @@ public: } NbBounds = theNbBounds; + NbMaxBounds = theNbBounds; Colors = theHasColors ? reinterpret_cast(myData) : NULL; Bounds = reinterpret_cast(theHasColors ? (myData + aColorsSize) : myData); return true; @@ -59,13 +63,10 @@ public: public: - Graphic3d_Vec4* Colors; //!< pointer to facet color values - Standard_Integer* Bounds; //!< pointer to bounds array - Standard_Integer NbBounds; //!< number of bounds - -public: - - DEFINE_STANDARD_RTTI_INLINE(Graphic3d_BoundBuffer,NCollection_Buffer) // Type definition + Graphic3d_Vec4* Colors; //!< pointer to facet color values + Standard_Integer* Bounds; //!< pointer to bounds array + Standard_Integer NbBounds; //!< number of bounds + Standard_Integer NbMaxBounds; //!< number of allocated bounds }; diff --git a/src/Graphic3d/Graphic3d_Buffer.cxx b/src/Graphic3d/Graphic3d_Buffer.cxx new file mode 100644 index 0000000000..6d76b84778 --- /dev/null +++ b/src/Graphic3d/Graphic3d_Buffer.cxx @@ -0,0 +1,20 @@ +// Copyright (c) 2018 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 +#include +#include + +IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Buffer, NCollection_Buffer) +IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_IndexBuffer, Graphic3d_Buffer) +IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_BoundBuffer, NCollection_Buffer) diff --git a/src/Graphic3d/Graphic3d_Buffer.hxx b/src/Graphic3d/Graphic3d_Buffer.hxx index 6aaa671a37..455c8ff85a 100644 --- a/src/Graphic3d/Graphic3d_Buffer.hxx +++ b/src/Graphic3d/Graphic3d_Buffer.hxx @@ -71,6 +71,7 @@ typedef NCollection_Array1 Graphic3d_Array1OfAttribute; //! Buffer of vertex attributes. class Graphic3d_Buffer : public NCollection_Buffer { + DEFINE_STANDARD_RTTIEXT(Graphic3d_Buffer, NCollection_Buffer) public: //! Empty constructor. @@ -83,6 +84,10 @@ public: // } + //! Return number of initially allocated elements which can fit into this buffer, + //! while NbElements can be overwritten to smaller value. + Standard_Integer NbMaxElements() const { return Standard_Integer(mySize / size_t(Stride)); } + //! @return array of attributes definitions const Graphic3d_Attribute* AttributesArray() const { @@ -209,14 +214,10 @@ public: public: - Standard_Integer Stride; //!< the distance to the attributes of the next vertex - Standard_Integer NbElements; //!< number of the elements + Standard_Integer Stride; //!< the distance to the attributes of the next vertex within interleaved array + Standard_Integer NbElements; //!< number of the elements (@sa NbMaxElements() specifying the number of initially allocated number of elements) Standard_Integer NbAttributes; //!< number of vertex attributes -public: - - DEFINE_STANDARD_RTTI_INLINE(Graphic3d_Buffer,NCollection_Buffer) // Type definition - }; DEFINE_STANDARD_HANDLE(Graphic3d_Buffer, NCollection_Buffer) diff --git a/src/Graphic3d/Graphic3d_IndexBuffer.hxx b/src/Graphic3d/Graphic3d_IndexBuffer.hxx index 6b6bc9ebbc..7e0c5a1556 100644 --- a/src/Graphic3d/Graphic3d_IndexBuffer.hxx +++ b/src/Graphic3d/Graphic3d_IndexBuffer.hxx @@ -19,6 +19,7 @@ //! Index buffer. class Graphic3d_IndexBuffer : public Graphic3d_Buffer { + DEFINE_STANDARD_RTTIEXT(Graphic3d_IndexBuffer, Graphic3d_Buffer) public: //! Empty constructor. @@ -76,9 +77,6 @@ public: } } -public: - - DEFINE_STANDARD_RTTI_INLINE(Graphic3d_IndexBuffer,Graphic3d_Buffer) // Type definition }; diff --git a/src/OpenGl/OpenGl_PrimitiveArray.cxx b/src/OpenGl/OpenGl_PrimitiveArray.cxx index 71c96fe539..09538a76e8 100644 --- a/src/OpenGl/OpenGl_PrimitiveArray.cxx +++ b/src/OpenGl/OpenGl_PrimitiveArray.cxx @@ -126,11 +126,8 @@ public: { const Graphic3d_Attribute& anAttrib = Attribs[anAttribIter]; const GLenum aDataType = toGlDataType (anAttrib.DataType, aNbComp); - if (aDataType == GL_NONE) - { - continue; - } - else if (anAttrib.Id == Graphic3d_TOA_POS) + if (anAttrib.Id == Graphic3d_TOA_POS + && aDataType != GL_NONE) { TheBaseClass::bindAttribute (theGlCtx, Graphic3d_TOA_POS, aNbComp, aDataType, Stride, anOffset); break; @@ -154,12 +151,10 @@ public: { const Graphic3d_Attribute& anAttrib = Attribs[anAttribIter]; const GLenum aDataType = toGlDataType (anAttrib.DataType, aNbComp); - if (aDataType == GL_NONE) + if (aDataType != GL_NONE) { - continue; + TheBaseClass::bindAttribute (theGlCtx, anAttrib.Id, aNbComp, aDataType, Stride, anOffset); } - - TheBaseClass::bindAttribute (theGlCtx, anAttrib.Id, aNbComp, aDataType, Stride, anOffset); anOffset += Graphic3d_Attribute::Stride (anAttrib.DataType); } } @@ -179,7 +174,7 @@ public: } } -public: +private: Graphic3d_Attribute Attribs[NbAttributes]; Standard_Integer Stride; diff --git a/src/OpenGl/OpenGl_PrimitiveArray.hxx b/src/OpenGl/OpenGl_PrimitiveArray.hxx index 258497db75..978af7409b 100644 --- a/src/OpenGl/OpenGl_PrimitiveArray.hxx +++ b/src/OpenGl/OpenGl_PrimitiveArray.hxx @@ -107,6 +107,7 @@ protected: Standard_EXPORT Standard_Boolean buildVBO (const Handle(OpenGl_Context)& theCtx, const Standard_Boolean theToKeepData) const; + //! Release GL memory. Standard_EXPORT void clearMemoryGL (const Handle(OpenGl_Context)& theGlCtx) const; private: diff --git a/src/ViewerTest/ViewerTest_ObjectCommands.cxx b/src/ViewerTest/ViewerTest_ObjectCommands.cxx index 2b68f59f99..37e0f34738 100644 --- a/src/ViewerTest/ViewerTest_ObjectCommands.cxx +++ b/src/ViewerTest/ViewerTest_ObjectCommands.cxx @@ -3338,8 +3338,7 @@ MyPArrayObject::MyPArrayObject (Handle(TColStd_HArray1OfAsciiString) theArrayDes // Parsing array description Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0; - Standard_Boolean hasVColors, hasBColors, hasNormals, hasTexels; - hasVColors = hasNormals = hasBColors = hasTexels = Standard_False; + Graphic3d_ArrayFlags anArrayFlags = Graphic3d_ArrayFlags_None; Standard_Integer anArgIndex = 0; Standard_Integer anArgsCount = myArrayDescription->Length(); @@ -3356,15 +3355,21 @@ MyPArrayObject::MyPArrayObject (Handle(TColStd_HArray1OfAsciiString) theArrayDes { // vertex has a normal or normal with color or texel if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount)) - hasNormals = Standard_True; + { + anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexNormal; + } // vertex has a color if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount)) - hasVColors = Standard_True; + { + anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexColor; + } // vertex has a texel if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount)) - hasTexels = Standard_True; + { + anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexTexel; + } aVertexNum++; } @@ -3373,7 +3378,9 @@ MyPArrayObject::MyPArrayObject (Handle(TColStd_HArray1OfAsciiString) theArrayDes { // bound has color if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount)) - hasBColors = Standard_True; + { + anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_BoundColor; + } aBoundNum++; } @@ -3393,33 +3400,21 @@ MyPArrayObject::MyPArrayObject (Handle(TColStd_HArray1OfAsciiString) theArrayDes anArray = new Graphic3d_ArrayOfPoints (aVertexNum); } else if (anArrayType == "segments") - anArray = new Graphic3d_ArrayOfSegments (aVertexNum, aEdgeNum, hasVColors); + anArray = new Graphic3d_ArrayOfSegments (aVertexNum, aEdgeNum, anArrayFlags); else if (anArrayType == "polylines") - anArray = new Graphic3d_ArrayOfPolylines (aVertexNum, aBoundNum, aEdgeNum, - hasVColors, hasBColors); + anArray = new Graphic3d_ArrayOfPolylines (aVertexNum, aBoundNum, aEdgeNum, anArrayFlags); else if (anArrayType == "triangles") - anArray = new Graphic3d_ArrayOfTriangles (aVertexNum, aEdgeNum, hasNormals, - hasVColors, hasTexels); + anArray = new Graphic3d_ArrayOfTriangles (aVertexNum, aEdgeNum, anArrayFlags); else if (anArrayType == "trianglefans") - anArray = new Graphic3d_ArrayOfTriangleFans (aVertexNum, aBoundNum, - hasNormals, hasVColors, - hasBColors, hasTexels); + anArray = new Graphic3d_ArrayOfTriangleFans (aVertexNum, aBoundNum, anArrayFlags); else if (anArrayType == "trianglestrips") - anArray = new Graphic3d_ArrayOfTriangleStrips (aVertexNum, aBoundNum, - hasNormals, hasVColors, - hasBColors, hasTexels); + anArray = new Graphic3d_ArrayOfTriangleStrips (aVertexNum, aBoundNum, anArrayFlags); else if (anArrayType == "quads") - anArray = new Graphic3d_ArrayOfQuadrangles (aVertexNum, aEdgeNum, - hasNormals, hasVColors, - hasTexels); + anArray = new Graphic3d_ArrayOfQuadrangles (aVertexNum, aEdgeNum, anArrayFlags); else if (anArrayType == "quadstrips") - anArray = new Graphic3d_ArrayOfQuadrangleStrips (aVertexNum, aBoundNum, - hasNormals, hasVColors, - hasBColors, hasTexels); + anArray = new Graphic3d_ArrayOfQuadrangleStrips (aVertexNum, aBoundNum, anArrayFlags); else if (anArrayType == "polygons") - anArray = new Graphic3d_ArrayOfPolygons (aVertexNum, aBoundNum, aEdgeNum, - hasNormals, hasVColors, hasBColors, - hasTexels); + anArray = new Graphic3d_ArrayOfPolygons (aVertexNum, aBoundNum, aEdgeNum, anArrayFlags); anArgIndex = 1; while (anArgIndex < anArgsCount)