From 7d6be4672b18c3f966e03e12b417cb9760807a24 Mon Sep 17 00:00:00 2001 From: mzernova Date: Mon, 31 Aug 2020 17:28:25 +0300 Subject: [PATCH] 0031733: Visualization, Prs3d_ToolQuadric - create indexed arrays Prs3d_ToolQuadric has been modified to return an indexed triangulation. Added methods Prs3d_ToolQuadric::CreateTriangulation() and Prs3d_ToolQuadric::CreateTriangulation() as more straightforward API returning generated triangulation. Added missing const to constant methods. Confusing method Prs3d_ToolQuadric::FillArray() filling both Graphic3d_ArrayOfTriangles and Poly_Triangulation at once has been marked deprecated. V3d_Trihedron and AIS_Manipulator now set Closed flag to groups with shaded sphere and arrows. --- src/AIS/AIS_Manipulator.cxx | 26 +++-- src/Prs3d/Prs3d_Arrow.cxx | 5 +- src/Prs3d/Prs3d_ToolCylinder.cxx | 8 +- src/Prs3d/Prs3d_ToolCylinder.hxx | 4 +- src/Prs3d/Prs3d_ToolDisk.cxx | 13 +-- src/Prs3d/Prs3d_ToolDisk.hxx | 7 +- src/Prs3d/Prs3d_ToolQuadric.cxx | 177 +++++++++++++++++-------------- src/Prs3d/Prs3d_ToolQuadric.hxx | 68 +++++++++--- src/Prs3d/Prs3d_ToolSphere.cxx | 8 +- src/Prs3d/Prs3d_ToolSphere.hxx | 4 +- src/V3d/V3d_Trihedron.cxx | 2 + 11 files changed, 194 insertions(+), 128 deletions(-) diff --git a/src/AIS/AIS_Manipulator.cxx b/src/AIS/AIS_Manipulator.cxx index 32e7080dd2..3083b55639 100644 --- a/src/AIS/AIS_Manipulator.cxx +++ b/src/AIS/AIS_Manipulator.cxx @@ -1005,7 +1005,8 @@ void AIS_Manipulator::Disk::Init (const Standard_ShortReal theInnerRadius, gp_Ax3 aSystem (myPosition.Location(), myPosition.Direction()); gp_Trsf aTrsf; aTrsf.SetTransformation (aSystem, gp_Ax3()); - aTool.FillArray (myArray, myTriangulation, aTrsf); + myArray = aTool.CreateTriangulation (aTrsf); + myTriangulation = aTool.CreatePolyTriangulation (aTrsf); } //======================================================================= @@ -1024,7 +1025,8 @@ void AIS_Manipulator::Sphere::Init (const Standard_ShortReal theRadius, Prs3d_ToolSphere aTool (theRadius, theSlicesNb, theStacksNb); gp_Trsf aTrsf; aTrsf.SetTranslation (gp_Vec(gp::Origin(), thePosition)); - aTool.FillArray (myArray, myTriangulation, aTrsf); + myArray = aTool.CreateTriangulation (aTrsf); + myTriangulation = aTool.CreatePolyTriangulation (aTrsf); } //======================================================================= @@ -1060,24 +1062,24 @@ void AIS_Manipulator::Cube::Init (const gp_Ax1& thePosition, const Standard_Shor addTriangle (1, aBottomLeft, aV3, aV4, -thePosition.Direction()); // Front - addTriangle (2, aV3, aV4, aV5, aFront); - addTriangle (3, aV3, aV5, aTopRight, aFront); + addTriangle (2, aV3, aV5, aV4, -aFront); + addTriangle (3, aV3, aTopRight, aV5, -aFront); // Back - addTriangle (4, aBottomLeft, aV2, aV7, -aFront); - addTriangle (5, aBottomLeft, aV7, aV6, -aFront); + addTriangle (4, aBottomLeft, aV7, aV2, aFront); + addTriangle (5, aBottomLeft, aV6, aV7, aFront); // aTop addTriangle (6, aV7, aV6, aV5, thePosition.Direction()); addTriangle (7, aTopRight, aV7, aV5, thePosition.Direction()); - //Left - addTriangle (8, aV6, aV5, aV4, -aRight); - addTriangle (9, aBottomLeft, aV6, aV4, -aRight); + // Left + addTriangle (8, aV6, aV4, aV5, aRight); + addTriangle (9, aBottomLeft, aV4, aV6, aRight); // Right - addTriangle (10, aV3, aTopRight, aV7, aRight); - addTriangle (11, aV3, aV7, aV2, aRight); + addTriangle (10, aV3, aV7, aTopRight, -aRight); + addTriangle (11, aV3, aV2, aV7, -aRight); } //======================================================================= @@ -1148,6 +1150,7 @@ void AIS_Manipulator::Axis::Compute (const Handle(PrsMgr_PresentationManager)& t anArrowLength, myFacettesNumber); myTranslatorGroup = Prs3d_Root::NewGroup (thePrs); + myTranslatorGroup->SetClosed (true); myTranslatorGroup->SetGroupPrimitivesAspect (theAspect->Aspect()); myTranslatorGroup->AddPrimitiveArray (myTriangleArray); @@ -1169,6 +1172,7 @@ void AIS_Manipulator::Axis::Compute (const Handle(PrsMgr_PresentationManager)& t myCube.Init (gp_Ax1 (myCubePos, myReferenceAxis.Direction()), myBoxSize); myScalerGroup = Prs3d_Root::NewGroup (thePrs); + myScalerGroup->SetClosed (true); myScalerGroup->SetGroupPrimitivesAspect (theAspect->Aspect()); myScalerGroup->AddPrimitiveArray (myCube.Array()); diff --git a/src/Prs3d/Prs3d_Arrow.cxx b/src/Prs3d/Prs3d_Arrow.cxx index cedd23a991..ed5a7068d3 100644 --- a/src/Prs3d/Prs3d_Arrow.cxx +++ b/src/Prs3d/Prs3d_Arrow.cxx @@ -138,7 +138,10 @@ Handle(Graphic3d_ArrayOfTriangles) Prs3d_Arrow::DrawShaded (const gp_Ax1& return Handle(Graphic3d_ArrayOfTriangles)(); } - Handle(Graphic3d_ArrayOfTriangles) anArray = new Graphic3d_ArrayOfTriangles (aNbTris * 3, 0, Standard_True); + Standard_Integer aMaxVertexs = (aNbTrisTube > 0 ? Prs3d_ToolCylinder::VerticesNb (theNbFacettes, 1) : 0) + + (aNbTrisCone > 0 ? Prs3d_ToolDisk ::VerticesNb (theNbFacettes, 1) + + Prs3d_ToolCylinder::VerticesNb (theNbFacettes, 1) : 0); + Handle(Graphic3d_ArrayOfTriangles) anArray = new Graphic3d_ArrayOfTriangles (aMaxVertexs, aNbTris * 3, Standard_True); if (aNbTrisTube != 0) { gp_Ax3 aSystem (theAxis.Location(), theAxis.Direction()); diff --git a/src/Prs3d/Prs3d_ToolCylinder.cxx b/src/Prs3d/Prs3d_ToolCylinder.cxx index a570e5fde0..83325c9c47 100644 --- a/src/Prs3d/Prs3d_ToolCylinder.cxx +++ b/src/Prs3d/Prs3d_ToolCylinder.cxx @@ -41,7 +41,7 @@ Prs3d_ToolCylinder::Prs3d_ToolCylinder (const Standard_Real theBottomRad, //function : Vertex //purpose : //======================================================================= -gp_Pnt Prs3d_ToolCylinder::Vertex (const Standard_Real theU, const Standard_Real theV) +gp_Pnt Prs3d_ToolCylinder::Vertex (const Standard_Real theU, const Standard_Real theV) const { const Standard_Real aU = theU * M_PI * 2.0; const Standard_Real aRadius = myBottomRadius + (myTopRadius - myBottomRadius) * theV; @@ -51,10 +51,10 @@ gp_Pnt Prs3d_ToolCylinder::Vertex (const Standard_Real theU, const Standard_Real } //======================================================================= -//function : Add +//function : Normal //purpose : //======================================================================= -gp_Dir Prs3d_ToolCylinder::Normal (const Standard_Real theU, const Standard_Real /*theV*/) +gp_Dir Prs3d_ToolCylinder::Normal (const Standard_Real theU, const Standard_Real ) const { const Standard_Real aU = theU * M_PI * 2.0; return gp_Dir (Cos (aU) * myHeight, @@ -63,7 +63,7 @@ gp_Dir Prs3d_ToolCylinder::Normal (const Standard_Real theU, const Standard_Real } //======================================================================= -//function : Perform +//function : Create //purpose : //======================================================================= Handle(Graphic3d_ArrayOfTriangles) Prs3d_ToolCylinder::Create (const Standard_Real theBottomRad, diff --git a/src/Prs3d/Prs3d_ToolCylinder.hxx b/src/Prs3d/Prs3d_ToolCylinder.hxx index 681778b544..a1d26fcd3d 100644 --- a/src/Prs3d/Prs3d_ToolCylinder.hxx +++ b/src/Prs3d/Prs3d_ToolCylinder.hxx @@ -43,10 +43,10 @@ public: protected: //! Computes vertex at given parameter location of the surface. - Standard_EXPORT virtual gp_Pnt Vertex (const Standard_Real theU, const Standard_Real theV) Standard_OVERRIDE; + Standard_EXPORT virtual gp_Pnt Vertex (const Standard_Real theU, const Standard_Real theV) const Standard_OVERRIDE; //! Computes normal at given parameter location of the surface. - Standard_EXPORT virtual gp_Dir Normal (const Standard_Real theU, const Standard_Real theV) Standard_OVERRIDE; + Standard_EXPORT virtual gp_Dir Normal (const Standard_Real theU, const Standard_Real theV) const Standard_OVERRIDE; protected: diff --git a/src/Prs3d/Prs3d_ToolDisk.cxx b/src/Prs3d/Prs3d_ToolDisk.cxx index 3857d15c81..d15a6f2de8 100644 --- a/src/Prs3d/Prs3d_ToolDisk.cxx +++ b/src/Prs3d/Prs3d_ToolDisk.cxx @@ -38,7 +38,7 @@ Prs3d_ToolDisk::Prs3d_ToolDisk (const Standard_Real theInnerRadius, //function : Vertex //purpose : //======================================================================= -gp_Pnt Prs3d_ToolDisk::Vertex (const Standard_Real theU, const Standard_Real theV) +gp_Pnt Prs3d_ToolDisk::Vertex (const Standard_Real theU, const Standard_Real theV) const { const Standard_Real aU = theU * M_PI * 2.0; const Standard_Real aRadius = myInnerRadius + (myOuterRadius - myInnerRadius) * theV; @@ -48,16 +48,7 @@ gp_Pnt Prs3d_ToolDisk::Vertex (const Standard_Real theU, const Standard_Real the } //======================================================================= -//function : Add -//purpose : -//======================================================================= -gp_Dir Prs3d_ToolDisk::Normal (const Standard_Real /*theU*/, const Standard_Real /*theV*/) -{ - return gp_Dir (0.0, 0.0, -1.0); -} - -//======================================================================= -//function : Perform +//function : Create //purpose : //======================================================================= Handle(Graphic3d_ArrayOfTriangles) Prs3d_ToolDisk::Create (const Standard_Real theInnerRadius, diff --git a/src/Prs3d/Prs3d_ToolDisk.hxx b/src/Prs3d/Prs3d_ToolDisk.hxx index 1e66093e1f..a57a20e9b5 100644 --- a/src/Prs3d/Prs3d_ToolDisk.hxx +++ b/src/Prs3d/Prs3d_ToolDisk.hxx @@ -40,10 +40,13 @@ public: protected: //! Computes vertex at given parameter location of the surface. - Standard_EXPORT virtual gp_Pnt Vertex (const Standard_Real theU, const Standard_Real theV) Standard_OVERRIDE; + Standard_EXPORT virtual gp_Pnt Vertex (const Standard_Real theU, const Standard_Real theV) const Standard_OVERRIDE; //! Computes normal at given parameter location of the surface. - Standard_EXPORT virtual gp_Dir Normal (const Standard_Real theU, const Standard_Real theV) Standard_OVERRIDE; + virtual gp_Dir Normal (const Standard_Real , const Standard_Real ) const Standard_OVERRIDE + { + return gp_Dir (0.0, 0.0, -1.0); + } protected: diff --git a/src/Prs3d/Prs3d_ToolQuadric.cxx b/src/Prs3d/Prs3d_ToolQuadric.cxx index 5af6cfda37..aaad0ea863 100644 --- a/src/Prs3d/Prs3d_ToolQuadric.cxx +++ b/src/Prs3d/Prs3d_ToolQuadric.cxx @@ -20,102 +20,125 @@ #include #include -//======================================================================= -//function : fillArrays -//purpose : -//======================================================================= -void Prs3d_ToolQuadric::fillArrays (const gp_Trsf& theTrsf, TColgp_Array1OfPnt& theArray, NCollection_Array1& theNormals) -{ - Standard_ShortReal aStepU = 1.0f / mySlicesNb; - Standard_ShortReal aStepV = 1.0f / myStacksNb; - - for (Standard_Integer aU = 0; aU <= mySlicesNb; aU++) - { - const Standard_Real aParamU = aU * aStepU; - for (Standard_Integer aV = 0; aV <= myStacksNb; aV++) - { - const Standard_ShortReal aParamV = aV * aStepV; - const Standard_Integer aVertId = aU * (myStacksNb + 1) + aV + 1; - gp_Pnt aVertex = Vertex(aParamU, aParamV); - gp_Dir aNormal = Normal(aParamU, aParamV); - - aVertex.Transform (theTrsf); - aNormal.Transform (theTrsf); - - theArray.SetValue (aVertId, aVertex); - theNormals.SetValue (aVertId, aNormal); - } - } -} - //======================================================================= //function : FIllArray //purpose : //======================================================================= -void Prs3d_ToolQuadric::FillArray (Handle(Graphic3d_ArrayOfTriangles)& theArray, const gp_Trsf& theTrsf) +void Prs3d_ToolQuadric::FillArray (Handle(Graphic3d_ArrayOfTriangles)& theArray, + const gp_Trsf& theTrsf) const { - const Standard_Integer aTrianglesNb = TrianglesNb(); if (theArray.IsNull()) { - theArray = new Graphic3d_ArrayOfTriangles (aTrianglesNb * 3, 0, Standard_True); + theArray = new Graphic3d_ArrayOfTriangles (VerticesNb(), TrianglesNb() * 3, Standard_True); } - Poly_Array1OfTriangle aPolyTriangles (1, aTrianglesNb); - TColgp_Array1OfPnt anArray (1, aTrianglesNb * 3); - NCollection_Array1 aNormals (1, aTrianglesNb * 3); - fillArrays (theTrsf, anArray, aNormals); - - // Fill primitives - for (Standard_Integer aU = 0; aU < mySlicesNb; ++aU) + const Standard_Real aStepU = 1.0f / mySlicesNb; + const Standard_Real aStepV = 1.0f / myStacksNb; + if (!theArray->Indices().IsNull()) { - for (Standard_Integer aV = 1; aV <= myStacksNb; ++aV) + // indexed array + for (Standard_Integer aU = 0; aU <= mySlicesNb; ++aU) { - theArray->AddVertex (anArray.Value (aU * (myStacksNb + 1) + aV), aNormals.Value (aU * (myStacksNb + 1) + aV)); - theArray->AddVertex (anArray.Value ((aU + 1) * (myStacksNb + 1) + aV), aNormals.Value ((aU + 1) * (myStacksNb + 1) + aV)); - theArray->AddVertex (anArray.Value ((aU + 1) * (myStacksNb + 1) + (aV + 1)), aNormals.Value ((aU + 1) * (myStacksNb + 1) + (aV + 1))); - theArray->AddVertex (anArray.Value ((aU + 1) * (myStacksNb + 1) + (aV + 1)), aNormals.Value ((aU + 1) * (myStacksNb + 1) + (aV + 1))); - theArray->AddVertex (anArray.Value (aU * (myStacksNb + 1) + (aV + 1)), aNormals.Value (aU * (myStacksNb + 1) + (aV + 1))); - theArray->AddVertex (anArray.Value (aU * (myStacksNb + 1) + aV), aNormals.Value (aU * (myStacksNb + 1) + aV)); + const Standard_Real aParamU = aU * aStepU; + for (Standard_Integer aV = 0; aV <= myStacksNb; ++aV) + { + const Standard_Real aParamV = aV * aStepV; + const gp_Pnt aVertex = Vertex (aParamU, aParamV).Transformed (theTrsf); + const gp_Dir aNormal = Normal (aParamU, aParamV).Transformed (theTrsf); + theArray->AddVertex (aVertex, aNormal); + + if (aU != 0 && aV != 0) + { + const int aVertId = theArray->VertexNumber(); + theArray->AddEdge (aVertId); + theArray->AddEdge (aVertId - myStacksNb - 2); + theArray->AddEdge (aVertId - 1); + theArray->AddEdge (aVertId - myStacksNb - 2); + theArray->AddEdge (aVertId); + theArray->AddEdge (aVertId - myStacksNb - 1); + } + } + } + } + else + { + // non-indexed array + for (Standard_Integer aU = 0; aU < mySlicesNb; ++aU) + { + const Standard_Real aParamU = aU * aStepU; + for (Standard_Integer aV = 0; aV < myStacksNb; ++aV) + { + const Standard_Real aParamV = aV * aStepV; + theArray->AddVertex (Vertex (aParamU, aParamV).Transformed (theTrsf), + Normal (aParamU, aParamV).Transformed (theTrsf)); + theArray->AddVertex (Vertex (aParamU + aStepU, aParamV).Transformed (theTrsf), + Normal (aParamU + aStepU, aParamV).Transformed (theTrsf)); + theArray->AddVertex (Vertex (aParamU + aStepU, aParamV + aStepV).Transformed (theTrsf), + Normal (aParamU + aStepU, aParamV + aStepV).Transformed (theTrsf)); + theArray->AddVertex (Vertex (aParamU + aStepU, aParamV + aStepV).Transformed (theTrsf), + Normal (aParamU + aStepU, aParamV + aStepV).Transformed (theTrsf)); + theArray->AddVertex (Vertex (aParamU, aParamV + aStepV).Transformed (theTrsf), + Normal (aParamU, aParamV + aStepV).Transformed (theTrsf)); + theArray->AddVertex (Vertex (aParamU, aParamV).Transformed (theTrsf), + Normal (aParamU, aParamV).Transformed (theTrsf)); + } } } } //======================================================================= -//function : FillTriangulation +//function : CreateTriangulation +//purpose : +//======================================================================= +Handle(Graphic3d_ArrayOfTriangles) Prs3d_ToolQuadric::CreateTriangulation (const gp_Trsf& theTrsf) const +{ + Handle(Graphic3d_ArrayOfTriangles) aTriangulation; + FillArray (aTriangulation, theTrsf); + return aTriangulation; +} + +//======================================================================= +//function : CreatePolyTriangulation +//purpose : +//======================================================================= +Handle(Poly_Triangulation) Prs3d_ToolQuadric::CreatePolyTriangulation (const gp_Trsf& theTrsf) const +{ + Handle(Poly_Triangulation) aTriangulation = new Poly_Triangulation (VerticesNb(), TrianglesNb(), Standard_False); + TColgp_Array1OfPnt& aNodes = aTriangulation->ChangeNodes(); + Poly_Array1OfTriangle& aTriangles = aTriangulation->ChangeTriangles(); + + Standard_ShortReal aStepU = 1.0f / mySlicesNb; + Standard_ShortReal aStepV = 1.0f / myStacksNb; + + // Fill triangles + for (Standard_Integer aU = 0, anIndex = 0; aU <= mySlicesNb; ++aU) + { + const Standard_Real aParamU = aU * aStepU; + for (Standard_Integer aV = 0; aV <= myStacksNb; ++aV) + { + const Standard_ShortReal aParamV = aV * aStepV; + const Standard_Integer aVertId = aU * (myStacksNb + 1) + (aV + 1); + gp_Pnt aVertex = Vertex (aParamU, aParamV).Transformed (theTrsf); + + aNodes.SetValue (aVertId, aVertex); + if (aU != 0 && aV != 0) + { + aTriangles.SetValue (++anIndex, Poly_Triangle (aVertId, aVertId - myStacksNb - 2, aVertId - 1)); + aTriangles.SetValue (++anIndex, Poly_Triangle (aVertId - myStacksNb - 2, aVertId, aVertId - myStacksNb - 1)); + } + } + } + return aTriangulation; +} + +//======================================================================= +//function : FillArray //purpose : //======================================================================= void Prs3d_ToolQuadric::FillArray (Handle(Graphic3d_ArrayOfTriangles)& theArray, Handle(Poly_Triangulation)& theTriangulation, - const gp_Trsf& theTrsf) + const gp_Trsf& theTrsf) const { - const Standard_Integer aTrianglesNb = TrianglesNb(); - theArray = new Graphic3d_ArrayOfTriangles(aTrianglesNb * 3, 0, Standard_True); - - Poly_Array1OfTriangle aPolyTriangles(1, aTrianglesNb); - TColgp_Array1OfPnt anArray(1, aTrianglesNb * 3); - NCollection_Array1 aNormals(1, aTrianglesNb * 3); - fillArrays(theTrsf, anArray, aNormals); - - // Fill triangles - for (Standard_Integer aU = 0, anIndex = 0; aU < mySlicesNb; ++aU) - { - for (Standard_Integer aV = 1; aV <= myStacksNb; ++aV) - { - theArray->AddVertex(anArray.Value(aU * (myStacksNb + 1) + aV), aNormals.Value(aU * (myStacksNb + 1) + aV)); - theArray->AddVertex(anArray.Value((aU + 1) * (myStacksNb + 1) + aV), aNormals.Value((aU + 1) * (myStacksNb + 1) + aV)); - theArray->AddVertex(anArray.Value((aU + 1) * (myStacksNb + 1) + (aV + 1)), aNormals.Value((aU + 1) * (myStacksNb + 1) + (aV + 1))); - theArray->AddVertex(anArray.Value((aU + 1) * (myStacksNb + 1) + (aV + 1)), aNormals.Value((aU + 1) * (myStacksNb + 1) + (aV + 1))); - theArray->AddVertex(anArray.Value(aU * (myStacksNb + 1) + (aV + 1)), aNormals.Value(aU * (myStacksNb + 1) + (aV + 1))); - theArray->AddVertex(anArray.Value(aU * (myStacksNb + 1) + aV), aNormals.Value(aU * (myStacksNb + 1) + aV)); - - aPolyTriangles.SetValue (++anIndex, Poly_Triangle(aU * (myStacksNb + 1) + aV, - (aU + 1) * (myStacksNb + 1) + aV, - (aU + 1) * (myStacksNb + 1) + (aV + 1))); - aPolyTriangles.SetValue (++anIndex, Poly_Triangle((aU + 1) * (myStacksNb + 1) + (aV + 1), - aU * (myStacksNb + 1) + (aV + 1), - aU * (myStacksNb + 1) + aV)); - } - } - - theTriangulation = new Poly_Triangulation (anArray, aPolyTriangles); + theArray = CreateTriangulation (theTrsf); + theTriangulation = CreatePolyTriangulation (theTrsf); } diff --git a/src/Prs3d/Prs3d_ToolQuadric.hxx b/src/Prs3d/Prs3d_ToolQuadric.hxx index 8b6befa1ae..237d2b98c5 100644 --- a/src/Prs3d/Prs3d_ToolQuadric.hxx +++ b/src/Prs3d/Prs3d_ToolQuadric.hxx @@ -29,38 +29,78 @@ class Prs3d_ToolQuadric { public: - DEFINE_STANDARD_ALLOC - //! Generate primitives for 3D quadric surface and fill the given array. Optional transformation is applied. - Standard_EXPORT void FillArray (Handle(Graphic3d_ArrayOfTriangles)& theArray, const gp_Trsf& theTrsf); - - //! Generate primitives for 3D quadric surface presentation and fill the given array and poly triangulation structure. Optional transformation is applied. - Standard_EXPORT void FillArray (Handle(Graphic3d_ArrayOfTriangles)& theArray, Handle(Poly_Triangulation)& theTriangulation, const gp_Trsf& theTrsf); - - //! Number of triangles for presentation with the given params. + //! Return number of triangles for presentation with the given params. static Standard_Integer TrianglesNb (const Standard_Integer theSlicesNb, const Standard_Integer theStacksNb) { return theSlicesNb * theStacksNb * 2; } + //! Return number of vertices for presentation with the given params. + static Standard_Integer VerticesNb (const Standard_Integer theSlicesNb, + const Standard_Integer theStacksNb, + const Standard_Boolean theIsIndexed = Standard_True) + { + return theIsIndexed + ? (theSlicesNb + 1) * (theStacksNb + 1) + : TrianglesNb (theSlicesNb, theStacksNb) * 3; + } + +public: + + //! Generate primitives for 3D quadric surface presentation. + //! @param theTrsf [in] optional transformation to apply + //! @return generated triangulation + Standard_EXPORT Handle(Graphic3d_ArrayOfTriangles) CreateTriangulation (const gp_Trsf& theTrsf) const; + + //! Generate primitives for 3D quadric surface presentation. + //! @param theTrsf [in] optional transformation to apply + //! @return generated triangulation + Standard_EXPORT Handle(Poly_Triangulation) CreatePolyTriangulation (const gp_Trsf& theTrsf) const; + + //! Generate primitives for 3D quadric surface and fill the given array. + //! @param theArray [in][out] the array of vertices; + //! when NULL, function will create an indexed array; + //! when not NULL, triangles will be appended to the end of array + //! (will raise an exception if reserved array size is not large enough) + //! @param theTrsf [in] optional transformation to apply + Standard_EXPORT void FillArray (Handle(Graphic3d_ArrayOfTriangles)& theArray, + const gp_Trsf& theTrsf) const; + +public: + + //! Generate primitives for 3D quadric surface presentation. + //! @param theArray [out] generated array of triangles + //! @param theTriangulation [out] generated triangulation + //! @param theTrsf [in] optional transformation to apply + Standard_DEPRECATED("Deprecated method, CreateTriangulation() and CreatePolyTriangulation() should be used instead") + Standard_EXPORT void FillArray (Handle(Graphic3d_ArrayOfTriangles)& theArray, + Handle(Poly_Triangulation)& theTriangulation, + const gp_Trsf& theTrsf) const; + protected: - //! Method implements an algorithm to generate arrays of vertices and normals for 3D surface. - Standard_EXPORT void fillArrays (const gp_Trsf& theTrsf, TColgp_Array1OfPnt& theArray, NCollection_Array1& theNormals); - - //! Number of triangles in generated presentation. + //! Return number of triangles in generated presentation. Standard_Integer TrianglesNb() const { return mySlicesNb * myStacksNb * 2; } + //! Return number of vertices in generated presentation. + Standard_Integer VerticesNb (const Standard_Boolean theIsIndexed = Standard_True) const + { + return theIsIndexed + ? (mySlicesNb + 1) * (myStacksNb + 1) + : TrianglesNb() * 3; + } + //! Redefine this method to generate vertex at given parameters. - virtual gp_Pnt Vertex (const Standard_Real theU, const Standard_Real theV) = 0; + virtual gp_Pnt Vertex (const Standard_Real theU, const Standard_Real theV) const = 0; //! Redefine this method to generate normal at given parameters. - virtual gp_Dir Normal (const Standard_Real theU, const Standard_Real theV) = 0; + virtual gp_Dir Normal (const Standard_Real theU, const Standard_Real theV) const = 0; protected: diff --git a/src/Prs3d/Prs3d_ToolSphere.cxx b/src/Prs3d/Prs3d_ToolSphere.cxx index 973a71b8c6..459f9207bf 100644 --- a/src/Prs3d/Prs3d_ToolSphere.cxx +++ b/src/Prs3d/Prs3d_ToolSphere.cxx @@ -36,7 +36,7 @@ Prs3d_ToolSphere::Prs3d_ToolSphere (const Standard_Real theRadius, //function : Vertex //purpose : //======================================================================= -gp_Pnt Prs3d_ToolSphere::Vertex (const Standard_Real theU, const Standard_Real theV) +gp_Pnt Prs3d_ToolSphere::Vertex (const Standard_Real theU, const Standard_Real theV) const { const Standard_Real aU = theU * M_PI * 2.0; const Standard_Real aV = theV * M_PI; @@ -46,10 +46,10 @@ gp_Pnt Prs3d_ToolSphere::Vertex (const Standard_Real theU, const Standard_Real t } //======================================================================= -//function : Add +//function : Normal //purpose : //======================================================================= -gp_Dir Prs3d_ToolSphere::Normal (const Standard_Real theU, const Standard_Real theV) +gp_Dir Prs3d_ToolSphere::Normal (const Standard_Real theU, const Standard_Real theV) const { const Standard_Real aU = theU * M_PI * 2.0; const Standard_Real aV = theV * M_PI; @@ -59,7 +59,7 @@ gp_Dir Prs3d_ToolSphere::Normal (const Standard_Real theU, const Standard_Real t } //======================================================================= -//function : Perform +//function : Create //purpose : //======================================================================= Handle(Graphic3d_ArrayOfTriangles) Prs3d_ToolSphere::Create (const Standard_Real theRadius, diff --git a/src/Prs3d/Prs3d_ToolSphere.hxx b/src/Prs3d/Prs3d_ToolSphere.hxx index 671262c5b3..5faa483eb1 100644 --- a/src/Prs3d/Prs3d_ToolSphere.hxx +++ b/src/Prs3d/Prs3d_ToolSphere.hxx @@ -46,10 +46,10 @@ public: protected: //! Computes vertex at given parameter location of the surface. - Standard_EXPORT virtual gp_Pnt Vertex (const Standard_Real theU, const Standard_Real theV) Standard_OVERRIDE; + Standard_EXPORT virtual gp_Pnt Vertex (const Standard_Real theU, const Standard_Real theV) const Standard_OVERRIDE; //! Computes normal at given parameter location of the surface. - Standard_EXPORT virtual gp_Dir Normal (const Standard_Real theU, const Standard_Real theV) Standard_OVERRIDE; + Standard_EXPORT virtual gp_Dir Normal (const Standard_Real theU, const Standard_Real theV) const Standard_OVERRIDE; protected: diff --git a/src/V3d/V3d_Trihedron.cxx b/src/V3d/V3d_Trihedron.cxx index e02db0e4ce..14ff80111f 100644 --- a/src/V3d/V3d_Trihedron.cxx +++ b/src/V3d/V3d_Trihedron.cxx @@ -292,6 +292,7 @@ void V3d_Trihedron::compute() Standard_Integer aGroupIter = myStructure->Groups().Lower(); { Handle(Graphic3d_Group) aSphereGroup = addGroup (myStructure, aGroupIter); + aSphereGroup->SetClosed (!myIsWireframe); // Display origin. if (myIsWireframe) @@ -322,6 +323,7 @@ void V3d_Trihedron::compute() for (Standard_Integer anIter = 0; anIter < 3; ++anIter) { Handle(Graphic3d_Group) anAxisGroup = addGroup (myStructure, aGroupIter); + anAxisGroup->SetClosed (!myIsWireframe); if (myIsWireframe) { // create a tube