From f0da497005750987cd262f3389efd43bf01ba00c 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, AIS_ViewCube and AIS_Manipulator now set Closed flag to groups with shaded sphere and arrows. --- src/AIS/AIS_Manipulator.cxx | 33 +++--- src/AIS/AIS_ViewCube.cxx | 2 + src/Prs3d/Prs3d_Arrow.cxx | 5 +- src/Prs3d/Prs3d_ToolCylinder.cxx | 8 +- src/Prs3d/Prs3d_ToolCylinder.hxx | 4 +- src/Prs3d/Prs3d_ToolDisk.cxx | 4 +- src/Prs3d/Prs3d_ToolDisk.hxx | 7 +- src/Prs3d/Prs3d_ToolQuadric.cxx | 173 +++++++++++++++++-------------- src/Prs3d/Prs3d_ToolQuadric.hxx | 68 +++++++++--- src/Prs3d/Prs3d_ToolSector.cxx | 13 +-- src/Prs3d/Prs3d_ToolSector.hxx | 7 +- src/Prs3d/Prs3d_ToolSphere.cxx | 8 +- src/Prs3d/Prs3d_ToolSphere.hxx | 4 +- src/V3d/V3d_Trihedron.cxx | 2 + 14 files changed, 203 insertions(+), 135 deletions(-) diff --git a/src/AIS/AIS_Manipulator.cxx b/src/AIS/AIS_Manipulator.cxx index c3e89ecd35..45e5ca4fa8 100644 --- a/src/AIS/AIS_Manipulator.cxx +++ b/src/AIS/AIS_Manipulator.cxx @@ -1212,7 +1212,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); } //======================================================================= @@ -1231,7 +1232,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); } //======================================================================= @@ -1267,24 +1269,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); } //======================================================================= @@ -1321,7 +1323,8 @@ void AIS_Manipulator::Sector::Init (const Standard_ShortReal theRadius, gp_Ax3 aSystem(thePosition.Location(), thePosition.Direction(), theXDirection); gp_Trsf aTrsf; aTrsf.SetTransformation(aSystem, gp_Ax3()); - aTool.FillArray(myArray, myTriangulation, aTrsf); + myArray = aTool.CreateTriangulation (aTrsf); + myTriangulation = aTool.CreatePolyTriangulation (aTrsf); } //======================================================================= @@ -1373,7 +1376,8 @@ void AIS_Manipulator::Axis::Compute (const Handle(PrsMgr_PresentationManager)& t myAxisRadius * 1.5, anArrowLength, myFacettesNumber); - myTranslatorGroup = thePrs->NewGroup (); + myTranslatorGroup = thePrs->NewGroup(); + myTranslatorGroup->SetClosed (true); myTranslatorGroup->SetGroupPrimitivesAspect (theAspect->Aspect()); myTranslatorGroup->AddPrimitiveArray (myTriangleArray); @@ -1397,7 +1401,8 @@ void AIS_Manipulator::Axis::Compute (const Handle(PrsMgr_PresentationManager)& t myCubePos = myReferenceAxis.Direction().XYZ() * (myLength + myIndent); myCube.Init (gp_Ax1 (myCubePos, myReferenceAxis.Direction()), myBoxSize); - myScalerGroup = thePrs->NewGroup (); + myScalerGroup = thePrs->NewGroup(); + myScalerGroup->SetClosed (true); myScalerGroup->SetGroupPrimitivesAspect (theAspect->Aspect()); myScalerGroup->AddPrimitiveArray (myCube.Array()); diff --git a/src/AIS/AIS_ViewCube.cxx b/src/AIS/AIS_ViewCube.cxx index ff60577ad1..bb95443808 100644 --- a/src/AIS/AIS_ViewCube.cxx +++ b/src/AIS/AIS_ViewCube.cxx @@ -598,6 +598,7 @@ void AIS_ViewCube::Compute (const Handle(PrsMgr_PresentationManager3d)& , } Handle(Graphic3d_Group) anAxisGroup = thePrs->NewGroup(); + anAxisGroup->SetClosed (true); anAxisGroup->SetGroupPrimitivesAspect (aDatumAspect->ShadingAspect (aPart)->Aspect()); const Standard_Real anArrowLength = 0.2 * anAxisSize; @@ -620,6 +621,7 @@ void AIS_ViewCube::Compute (const Handle(PrsMgr_PresentationManager3d)& , // Display center { Handle(Graphic3d_Group) aGroup = thePrs->NewGroup(); + aGroup->SetClosed (true); Handle(Prs3d_ShadingAspect) anAspectCen = new Prs3d_ShadingAspect(); anAspectCen->SetColor (Quantity_NOC_WHITE); aGroup->SetGroupPrimitivesAspect (anAspectCen->Aspect()); diff --git a/src/Prs3d/Prs3d_Arrow.cxx b/src/Prs3d/Prs3d_Arrow.cxx index cedd23a991..5294ec340c 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, Graphic3d_ArrayFlags_VertexNormal); 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 fecfba14be..93ce58c3f1 100644 --- a/src/Prs3d/Prs3d_ToolCylinder.hxx +++ b/src/Prs3d/Prs3d_ToolCylinder.hxx @@ -42,10 +42,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 5eec91b3cd..6377d79444 100644 --- a/src/Prs3d/Prs3d_ToolDisk.cxx +++ b/src/Prs3d/Prs3d_ToolDisk.cxx @@ -40,7 +40,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 = myStartAngle + theU * (myEndAngle - myStartAngle); const Standard_Real aRadius = myInnerRadius + (myOuterRadius - myInnerRadius) * theV; @@ -50,7 +50,7 @@ gp_Pnt Prs3d_ToolDisk::Vertex (const Standard_Real theU, const Standard_Real the } //======================================================================= -//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 c722639f7b..afaf8f6e48 100644 --- a/src/Prs3d/Prs3d_ToolDisk.hxx +++ b/src/Prs3d/Prs3d_ToolDisk.hxx @@ -50,10 +50,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. - virtual gp_Dir Normal (const Standard_Real , const Standard_Real ) Standard_OVERRIDE { return gp_Dir (0.0, 0.0, -1.0); } + 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..e74c50023e 100644 --- a/src/Prs3d/Prs3d_ToolQuadric.cxx +++ b/src/Prs3d/Prs3d_ToolQuadric.cxx @@ -20,102 +20,121 @@ #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, Graphic3d_ArrayFlags_VertexNormal); } - 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->EdgeNumberAllocated() > 0) { - 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->AddTriangleEdges (aVertId, aVertId - myStacksNb - 2, aVertId - 1); + theArray->AddTriangleEdges (aVertId - myStacksNb - 2, aVertId, 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 c3493edd1b..eb0c9fea60 100644 --- a/src/Prs3d/Prs3d_ToolQuadric.hxx +++ b/src/Prs3d/Prs3d_ToolQuadric.hxx @@ -23,38 +23,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_ToolSector.cxx b/src/Prs3d/Prs3d_ToolSector.cxx index ce8330d8bc..646a6b5fd3 100644 --- a/src/Prs3d/Prs3d_ToolSector.cxx +++ b/src/Prs3d/Prs3d_ToolSector.cxx @@ -36,7 +36,7 @@ Prs3d_ToolSector::Prs3d_ToolSector (const Standard_Real theRadius, //function : Vertex //purpose : //======================================================================= -gp_Pnt Prs3d_ToolSector::Vertex (const Standard_Real theU, const Standard_Real theV) +gp_Pnt Prs3d_ToolSector::Vertex (const Standard_Real theU, const Standard_Real theV) const { const Standard_Real aU = theU * M_PI / 2.0; const Standard_Real aRadius = myRadius * theV; @@ -46,16 +46,7 @@ gp_Pnt Prs3d_ToolSector::Vertex (const Standard_Real theU, const Standard_Real t } //======================================================================= -//function : Add -//purpose : -//======================================================================= -gp_Dir Prs3d_ToolSector::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_ToolSector::Create (const Standard_Real theRadius, diff --git a/src/Prs3d/Prs3d_ToolSector.hxx b/src/Prs3d/Prs3d_ToolSector.hxx index 383de716cd..2f98c029bd 100644 --- a/src/Prs3d/Prs3d_ToolSector.hxx +++ b/src/Prs3d/Prs3d_ToolSector.hxx @@ -37,10 +37,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_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 ed893a71f4..59f39d0d57 100644 --- a/src/Prs3d/Prs3d_ToolSphere.hxx +++ b/src/Prs3d/Prs3d_ToolSphere.hxx @@ -38,10 +38,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 20bb0671c2..6d28d637d9 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