From 113bda7072530e42c07389c6e000207431cec9f3 Mon Sep 17 00:00:00 2001 From: mzernova Date: Thu, 17 Sep 2020 22:55:27 +0300 Subject: [PATCH] 0031773: Visualization - add Prs3d_ToolTorus Added Prs3d_ToolTorus tool to create a torus Added DRAW commands: - vtorus - vcylinder - vsphere Added test cases: - v3d/quadric/torus - v3d/quadric/cylinder - v3d/quadric/sphere --- src/BRepPrim/BRepPrim_Cylinder.hxx | 2 +- src/BRepPrim/BRepPrim_Torus.hxx | 4 +- src/BRepPrimAPI/BRepPrimAPI_MakeCone.hxx | 27 ++- src/BRepPrimAPI/BRepPrimAPI_MakeCylinder.hxx | 20 +- src/BRepPrimAPI/BRepPrimAPI_MakeSphere.hxx | 75 +++++-- src/BRepPrimAPI/BRepPrimAPI_MakeTorus.hxx | 46 ++++- src/BRepTest/BRepTest_PrimitiveCommands.cxx | 47 ++++- src/Prs3d/FILES | 2 + src/Prs3d/Prs3d_ToolCylinder.hxx | 20 +- src/Prs3d/Prs3d_ToolDisk.hxx | 18 +- src/Prs3d/Prs3d_ToolQuadric.hxx | 4 +- src/Prs3d/Prs3d_ToolSector.hxx | 14 +- src/Prs3d/Prs3d_ToolSphere.hxx | 14 +- src/Prs3d/Prs3d_ToolTorus.cxx | 82 ++++++++ src/Prs3d/Prs3d_ToolTorus.hxx | 201 +++++++++++++++++++ src/ViewerTest/ViewerTest_ObjectCommands.cxx | 168 ++++++++++++++++ tests/v3d/grids.list | 1 + tests/v3d/quadric/begin | 2 + tests/v3d/quadric/cylinder | 19 ++ tests/v3d/quadric/sphere | 10 + tests/v3d/quadric/torus | 19 ++ 21 files changed, 723 insertions(+), 72 deletions(-) create mode 100644 src/Prs3d/Prs3d_ToolTorus.cxx create mode 100644 src/Prs3d/Prs3d_ToolTorus.hxx create mode 100644 tests/v3d/quadric/begin create mode 100644 tests/v3d/quadric/cylinder create mode 100644 tests/v3d/quadric/sphere create mode 100644 tests/v3d/quadric/torus diff --git a/src/BRepPrim/BRepPrim_Cylinder.hxx b/src/BRepPrim/BRepPrim_Cylinder.hxx index 445292c7dc..56bd2f66e1 100644 --- a/src/BRepPrim/BRepPrim_Cylinder.hxx +++ b/src/BRepPrim/BRepPrim_Cylinder.hxx @@ -85,7 +85,7 @@ private: Standard_EXPORT void SetMeridian(); - Standard_Real myRadius; + Standard_Real myRadius; //!< cylinder radius }; diff --git a/src/BRepPrim/BRepPrim_Torus.hxx b/src/BRepPrim/BRepPrim_Torus.hxx index 988577c0dc..900085c6ad 100644 --- a/src/BRepPrim/BRepPrim_Torus.hxx +++ b/src/BRepPrim/BRepPrim_Torus.hxx @@ -70,8 +70,8 @@ private: Standard_EXPORT void SetMeridian(); - Standard_Real myMajor; - Standard_Real myMinor; + Standard_Real myMajor; //!< distance from the center of the pipe to the center of the torus + Standard_Real myMinor; //!< radius of the pipe }; diff --git a/src/BRepPrimAPI/BRepPrimAPI_MakeCone.hxx b/src/BRepPrimAPI/BRepPrimAPI_MakeCone.hxx index bff81e78bb..30d8094571 100644 --- a/src/BRepPrimAPI/BRepPrimAPI_MakeCone.hxx +++ b/src/BRepPrimAPI/BRepPrimAPI_MakeCone.hxx @@ -41,18 +41,25 @@ public: DEFINE_STANDARD_ALLOC - - //! Make a cone of height H radius R1 in the plane z = - //! 0, R2 in the plane Z = H. R1 and R2 may be null. + + //! Make a cone. + //! @param R1 [in] cone bottom radius, may be null (z = 0) + //! @param R2 [in] cone top radius, may be null (z = H) + //! @param H [in] cone height Standard_EXPORT BRepPrimAPI_MakeCone(const Standard_Real R1, const Standard_Real R2, const Standard_Real H); - - //! Make a cone of height H radius R1 in the plane z = - //! 0, R2 in the plane Z = H. R1 and R2 may be null. - //! Take a section of + + //! Make a cone. + //! @param R1 [in] cone bottom radius, may be null (z = 0) + //! @param R2 [in] cone top radius, may be null (z = H) + //! @param H [in] cone height + //! @param angle [in] angle to create a part cone Standard_EXPORT BRepPrimAPI_MakeCone(const Standard_Real R1, const Standard_Real R2, const Standard_Real H, const Standard_Real angle); - - //! Make a cone of height H radius R1 in the plane z = - //! 0, R2 in the plane Z = H. R1 and R2 may be null. + + //! Make a cone. + //! @param axes [in] coordinate system for the construction of the cone + //! @param R1 [in] cone bottom radius, may be null (z = 0) + //! @param R2 [in] cone top radius, may be null (z = H) + //! @param H [in] cone height Standard_EXPORT BRepPrimAPI_MakeCone(const gp_Ax2& Axes, const Standard_Real R1, const Standard_Real R2, const Standard_Real H); //! Make a cone of height H radius R1 in the plane z = diff --git a/src/BRepPrimAPI/BRepPrimAPI_MakeCylinder.hxx b/src/BRepPrimAPI/BRepPrimAPI_MakeCylinder.hxx index fcf646399a..beb2571300 100644 --- a/src/BRepPrimAPI/BRepPrimAPI_MakeCylinder.hxx +++ b/src/BRepPrimAPI/BRepPrimAPI_MakeCylinder.hxx @@ -41,17 +41,23 @@ public: DEFINE_STANDARD_ALLOC - - //! Make a cylinder of radius R and length H. + //! Make a cylinder. + //! @param R [in] cylinder radius + //! @param H [in] cylinder height Standard_EXPORT BRepPrimAPI_MakeCylinder(const Standard_Real R, const Standard_Real H); - - //! Make a cylinder of radius R and length H with - //! angle H. + + //! Make a cylinder (part cylinder). + //! @param R [in] cylinder radius + //! @param H [in] cylinder height + //! @param Angle [in] defines the missing portion of the cylinder Standard_EXPORT BRepPrimAPI_MakeCylinder(const Standard_Real R, const Standard_Real H, const Standard_Real Angle); - + //! Make a cylinder of radius R and length H. + //! @param Axes [in] coordinate system for the construction of the cylinder + //! @param R [in] cylinder radius + //! @param H [in] cylinder height Standard_EXPORT BRepPrimAPI_MakeCylinder(const gp_Ax2& Axes, const Standard_Real R, const Standard_Real H); - + //! Make a cylinder of radius R and length H with //! angle H. //! Constructs diff --git a/src/BRepPrimAPI/BRepPrimAPI_MakeSphere.hxx b/src/BRepPrimAPI/BRepPrimAPI_MakeSphere.hxx index 7c2bcd3a19..7ae7d7f416 100644 --- a/src/BRepPrimAPI/BRepPrimAPI_MakeSphere.hxx +++ b/src/BRepPrimAPI/BRepPrimAPI_MakeSphere.hxx @@ -43,39 +43,72 @@ public: DEFINE_STANDARD_ALLOC - //! Make a sphere of radius R. + //! Make a sphere. + //! @param R [in] sphere radius Standard_EXPORT BRepPrimAPI_MakeSphere(const Standard_Real R); - - //! Make a sphere of radius R. + + //! Make a sphere (spherical wedge). + //! @param R [in] sphere radius + //! @param angle [in] angle between the radii lying within the bounding semidisks Standard_EXPORT BRepPrimAPI_MakeSphere(const Standard_Real R, const Standard_Real angle); - - //! Make a sphere of radius R. + + //! Make a sphere (spherical segment). + //! @param R [in] sphere radius + //! @param angle1 [in] first angle defining a spherical segment + //! @param angle2 [in] second angle defining a spherical segment Standard_EXPORT BRepPrimAPI_MakeSphere(const Standard_Real R, const Standard_Real angle1, const Standard_Real angle2); - - //! Make a sphere of radius R. + + //! Make a sphere (spherical segment). + //! @param R [in] sphere radius + //! @param angle1 [in] first angle defining a spherical segment + //! @param angle2 [in] second angle defining a spherical segment + //! @param angle3 [in] angle between the radii lying within the bounding semidisks Standard_EXPORT BRepPrimAPI_MakeSphere(const Standard_Real R, const Standard_Real angle1, const Standard_Real angle2, const Standard_Real angle3); - - //! Make a sphere of radius R. + + //! Make a sphere. + //! @param Center [in] sphere center coordinates + //! @param R [in] sphere radius Standard_EXPORT BRepPrimAPI_MakeSphere(const gp_Pnt& Center, const Standard_Real R); - //! Make a sphere of radius R. + //! Make a sphere (spherical wedge). + //! @param Center [in] sphere center coordinates + //! @param R [in] sphere radius + //! @param angle [in] angle between the radii lying within the bounding semidisks Standard_EXPORT BRepPrimAPI_MakeSphere(const gp_Pnt& Center, const Standard_Real R, const Standard_Real angle); - - //! Make a sphere of radius R. + + //! Make a sphere (spherical segment). + //! @param Center [in] sphere center coordinates + //! @param R [in] sphere radius + //! @param angle1 [in] first angle defining a spherical segment + //! @param angle2 [in] second angle defining a spherical segment Standard_EXPORT BRepPrimAPI_MakeSphere(const gp_Pnt& Center, const Standard_Real R, const Standard_Real angle1, const Standard_Real angle2); - - //! Make a sphere of radius R. + + //! Make a sphere (spherical segment). + //! @param Center [in] sphere center coordinates + //! @param R [in] sphere radius + //! @param angle1 [in] first angle defining a spherical segment + //! @param angle2 [in] second angle defining a spherical segment + //! @param angle3 [in] angle between the radii lying within the bounding semidisks Standard_EXPORT BRepPrimAPI_MakeSphere(const gp_Pnt& Center, const Standard_Real R, const Standard_Real angle1, const Standard_Real angle2, const Standard_Real angle3); - - //! Make a sphere of radius R. + + //! Make a sphere. + //! @param Axis [in] coordinate system for the construction of the sphere + //! @param R [in] sphere radius Standard_EXPORT BRepPrimAPI_MakeSphere(const gp_Ax2& Axis, const Standard_Real R); - - //! Make a sphere of radius R. + + //! Make a sphere (spherical wedge). + //! @param Axis [in] coordinate system for the construction of the sphere + //! @param R [in] sphere radius + //! @param angle [in] angle between the radii lying within the bounding semidisks Standard_EXPORT BRepPrimAPI_MakeSphere(const gp_Ax2& Axis, const Standard_Real R, const Standard_Real angle); - - //! Make a sphere of radius R. + + //! Make a sphere (spherical segment). + //! @param Axis [in] coordinate system for the construction of the sphere + //! @param R [in] sphere radius + //! @param angle1 [in] first angle defining a spherical segment + //! @param angle2 [in] second angle defining a spherical segment Standard_EXPORT BRepPrimAPI_MakeSphere(const gp_Ax2& Axis, const Standard_Real R, const Standard_Real angle1, const Standard_Real angle2); - + //! Make a sphere of radius R. //! For all algorithms The resulting shape is composed of //! - a lateral spherical face, diff --git a/src/BRepPrimAPI/BRepPrimAPI_MakeTorus.hxx b/src/BRepPrimAPI/BRepPrimAPI_MakeTorus.hxx index d365d7ac64..d4c0b23d00 100644 --- a/src/BRepPrimAPI/BRepPrimAPI_MakeTorus.hxx +++ b/src/BRepPrimAPI/BRepPrimAPI_MakeTorus.hxx @@ -41,28 +41,52 @@ public: DEFINE_STANDARD_ALLOC - - //! Make a torus of radii R1 R2. + + //! Make a torus. + //! @param R1 [in] distance from the center of the pipe to the center of the torus + //! @param R2 [in] radius of the pipe Standard_EXPORT BRepPrimAPI_MakeTorus(const Standard_Real R1, const Standard_Real R2); - - //! Make a section of a torus of radii R1 R2. + + //! Make a section of a torus. + //! @param R1 [in] distance from the center of the pipe to the center of the torus + //! @param R2 [in] radius of the pipe + //! @param angle [in] angle to create a torus pipe segment Standard_EXPORT BRepPrimAPI_MakeTorus(const Standard_Real R1, const Standard_Real R2, const Standard_Real angle); - //! Make a torus of radii R2, R2 with angles on the - //! small circle. + //! Make a torus with angles on the small circle. + //! @param R1 [in] distance from the center of the pipe to the center of the torus + //! @param R2 [in] radius of the pipe + //! @param angle1 [in] first angle to create a torus ring segment + //! @param angle2 [in] second angle to create a torus ring segment Standard_EXPORT BRepPrimAPI_MakeTorus(const Standard_Real R1, const Standard_Real R2, const Standard_Real angle1, const Standard_Real angle2); - //! Make a torus of radii R2, R2 with angles on the - //! small circle. + //! Make a torus with angles on the small circle. + //! @param R1 [in] distance from the center of the pipe to the center of the torus + //! @param R2 [in] radius of the pipe + //! @param angle1 [in] first angle to create a torus ring segment + //! @param angle2 [in] second angle to create a torus ring segment + //! @param angle [in] angle to create a torus pipe segment Standard_EXPORT BRepPrimAPI_MakeTorus(const Standard_Real R1, const Standard_Real R2, const Standard_Real angle1, const Standard_Real angle2, const Standard_Real angle); - //! Make a torus of radii R1 R2. + //! Make a torus. + //! @param Axes [in] coordinate system for the construction of the sphere + //! @param R1 [in] distance from the center of the pipe to the center of the torus + //! @param R2 [in] radius of the pipe Standard_EXPORT BRepPrimAPI_MakeTorus(const gp_Ax2& Axes, const Standard_Real R1, const Standard_Real R2); - //! Make a section of a torus of radii R1 R2. + //! Make a section of a torus. + //! @param Axes [in] coordinate system for the construction of the sphere + //! @param R1 [in] distance from the center of the pipe to the center of the torus + //! @param R2 [in] radius of the pipe + //! @param angle [in] angle to create a torus pipe segment Standard_EXPORT BRepPrimAPI_MakeTorus(const gp_Ax2& Axes, const Standard_Real R1, const Standard_Real R2, const Standard_Real angle); - //! Make a torus of radii R1 R2. + //! Make a torus. + //! @param Axes [in] coordinate system for the construction of the sphere + //! @param R1 [in] distance from the center of the pipe to the center of the torus + //! @param R2 [in] radius of the pipe + //! @param angle1 [in] first angle to create a torus ring segment + //! @param angle2 [in] second angle to create a torus ring segment Standard_EXPORT BRepPrimAPI_MakeTorus(const gp_Ax2& Axes, const Standard_Real R1, const Standard_Real R2, const Standard_Real angle1, const Standard_Real angle2); //! Make a section of a torus of radii R1 R2. diff --git a/src/BRepTest/BRepTest_PrimitiveCommands.cxx b/src/BRepTest/BRepTest_PrimitiveCommands.cxx index 065be130c2..3ad36cedf7 100644 --- a/src/BRepTest/BRepTest_PrimitiveCommands.cxx +++ b/src/BRepTest/BRepTest_PrimitiveCommands.cxx @@ -416,10 +416,49 @@ void BRepTest::PrimitiveCommands(Draw_Interpretor& theCommands) theCommands.Add("wedge","wedge name [Ox Oy Oz Zx Zy Zz Xx Xy Xz] dx dy dz ltx / xmin zmin xmax zmax",__FILE__,wedge,g); - theCommands.Add("pcylinder","pcylinder name [plane(ax2)] R H [angle]",__FILE__,cylinder,g); - theCommands.Add("pcone", "pcone name [plane(ax2)] R1 R2 H [angle]",__FILE__,cone,g); - theCommands.Add("psphere", "psphere name [plane(ax2)] R [angle1 angle2] [angle]",__FILE__,sphere,g); - theCommands.Add("ptorus", "ptorus name [plane(ax2)] R1 R2 [angle1 angle2] [angle]",__FILE__,torus,g); + theCommands.Add("pcylinder", + "pcylinder name [plane(ax2)] R H [angle]" + "\n\t\t: Construct a cylinder and put result into 'name' variable." + "\n\t\t: Parameters of the cylinder :" + "\n\t\t: - plane coordinate system for the construction of the cylinder" + "\n\t\t: - R cylinder radius" + "\n\t\t: - H cylinder height" + "\n\t\t: - angle cylinder top radius", + __FILE__, cylinder, g); + + theCommands.Add("pcone", + "pcone name [plane(ax2)] R1 R2 H [angle]" + "\n\t\t: Construct a cone, part cone or conical frustum and put result into 'name' variable." + "\n\t\t: Parameters of the cone :" + "\n\t\t: - plane coordinate system for the construction of the cone" + "\n\t\t: - R1 cone bottom radius" + "\n\t\t: - R2 cone top radius" + "\n\t\t: - H cone height" + "\n\t\t: - angle angle to create a part cone", + __FILE__, cone, g); + + theCommands.Add("psphere", + "psphere name [plane(ax2)] R [angle1 angle2] [angle]" + "\n\t\t: Construct a sphere, spherical segment or spherical wedge and put result into 'name' variable." + "\n\t\t: Parameters of the sphere :" + "\n\t\t: - plane coordinate system for the construction of the sphere" + "\n\t\t: - R sphere radius" + "\n\t\t: - angle1 first angle to create a spherical segment [-90; 90]" + "\n\t\t: - angle2 second angle to create a spherical segment [-90; 90]" + "\n\t\t: - angle angle to create a spherical wedge", + __FILE__, sphere, g); + + theCommands.Add("ptorus", + "ptorus name [plane(ax2)] R1 R2 [angle1 angle2] [angle]" + "\n\t\t: Construct a torus or torus segment and put result into 'name' variable." + "\n\t\t: Parameters of the torus :" + "\n\t\t: - plane coordinate system for the construction of the torus" + "\n\t\t: - R1 distance from the center of the pipe to the center of the torus" + "\n\t\t: - R2 radius of the pipe" + "\n\t\t: - angle1 first angle to create a torus ring segment" + "\n\t\t: - angle2 second angle to create a torus ring segment" + "\n\t\t: - angle angle to create a torus pipe segment", + __FILE__, torus, g); } diff --git a/src/Prs3d/FILES b/src/Prs3d/FILES index 2785086732..2ac227d719 100755 --- a/src/Prs3d/FILES +++ b/src/Prs3d/FILES @@ -55,6 +55,8 @@ Prs3d_ToolSector.hxx Prs3d_ToolSector.cxx Prs3d_ToolSphere.hxx Prs3d_ToolSphere.cxx +Prs3d_ToolTorus.hxx +Prs3d_ToolTorus.cxx Prs3d_TypeOfHighlight.hxx Prs3d_TypeOfHLR.hxx Prs3d_TypeOfLinePicking.hxx diff --git a/src/Prs3d/Prs3d_ToolCylinder.hxx b/src/Prs3d/Prs3d_ToolCylinder.hxx index 93ce58c3f1..50553aff92 100644 --- a/src/Prs3d/Prs3d_ToolCylinder.hxx +++ b/src/Prs3d/Prs3d_ToolCylinder.hxx @@ -24,6 +24,13 @@ class Prs3d_ToolCylinder : public Prs3d_ToolQuadric public: //! Generate primitives for 3D quadric surface and return a filled array. + //! @param theBottomRad [in] cylinder bottom radius + //! @param theTopRad [in] cylinder top radius + //! @param theHeight [in] cylinder height + //! @param theNbSlices [in] number of slices within U parameter + //! @param theNbStacks [in] number of stacks within V parameter + //! @param theTrsf [in] optional transformation to apply + //! @return generated triangulation Standard_EXPORT static Handle(Graphic3d_ArrayOfTriangles) Create (const Standard_Real theBottomRad, const Standard_Real theTopRad, const Standard_Real theHeight, @@ -32,7 +39,12 @@ public: const gp_Trsf& theTrsf); public: - //! Initializes the algorithm. + //! Initializes the algorithm creating a cylinder. + //! @param theBottomRad [in] cylinder bottom radius + //! @param theTopRad [in] cylinder top radius + //! @param theHeight [in] cylinder height + //! @param theNbSlices [in] number of slices within U parameter + //! @param theNbStacks [in] number of stacks within V parameter Standard_EXPORT Prs3d_ToolCylinder (const Standard_Real theBottomRad, const Standard_Real theTopRad, const Standard_Real theHeight, @@ -49,9 +61,9 @@ protected: protected: - Standard_Real myBottomRadius; - Standard_Real myTopRadius; - Standard_Real myHeight; + Standard_Real myBottomRadius; //!< cylinder bottom radius + Standard_Real myTopRadius; //!< cylinder top radius + Standard_Real myHeight; //!< cylinder height }; diff --git a/src/Prs3d/Prs3d_ToolDisk.hxx b/src/Prs3d/Prs3d_ToolDisk.hxx index afaf8f6e48..7b4fea28df 100644 --- a/src/Prs3d/Prs3d_ToolDisk.hxx +++ b/src/Prs3d/Prs3d_ToolDisk.hxx @@ -23,7 +23,13 @@ class Prs3d_ToolDisk : public Prs3d_ToolQuadric { public: - //! Generate primitives for 3D quadric surface and return a filled array. + //! Generate primitives for 3D quadric surface. + //! @param theInnerRadius [in] inner disc radius + //! @param theOuterRadius [in] outer disc radius + //! @param theNbSlices [in] number of slices within U parameter + //! @param theNbStacks [in] number of stacks within V parameter + //! @param theTrsf [in] optional transformation to apply + //! @return generated triangulation Standard_EXPORT static Handle(Graphic3d_ArrayOfTriangles) Create (const Standard_Real theInnerRadius, const Standard_Real theOuterRadius, const Standard_Integer theNbSlices, @@ -31,7 +37,11 @@ public: const gp_Trsf& theTrsf); public: - //! Initializes the algorithm. + //! Initializes the algorithm creating a disk. + //! @param theInnerRadius [in] inner disk radius + //! @param theOuterRadius [in] outer disk radius + //! @param theNbSlices [in] number of slices within U parameter + //! @param theNbStacks [in] number of stacks within V parameter Standard_EXPORT Prs3d_ToolDisk (const Standard_Real theInnerRadius, const Standard_Real theOuterRadius, const Standard_Integer theNbSlices, @@ -60,8 +70,8 @@ protected: protected: - Standard_Real myInnerRadius; - Standard_Real myOuterRadius; + Standard_Real myInnerRadius; //!< Inner disk radius + Standard_Real myOuterRadius; //!< Outer disk radius Standard_Real myStartAngle; //!< Start angle in counter clockwise order Standard_Real myEndAngle; //!< End angle in counter clockwise order diff --git a/src/Prs3d/Prs3d_ToolQuadric.hxx b/src/Prs3d/Prs3d_ToolQuadric.hxx index eb0c9fea60..a041919c88 100644 --- a/src/Prs3d/Prs3d_ToolQuadric.hxx +++ b/src/Prs3d/Prs3d_ToolQuadric.hxx @@ -98,8 +98,8 @@ protected: protected: - Standard_Integer mySlicesNb; - Standard_Integer myStacksNb; + Standard_Integer mySlicesNb; //!< number of slices within U parameter + Standard_Integer myStacksNb; //!< number of stacks within V parameter }; #endif // _Prs3d_ToolQuadric_HeaderFile diff --git a/src/Prs3d/Prs3d_ToolSector.hxx b/src/Prs3d/Prs3d_ToolSector.hxx index 2f98c029bd..8864381b0f 100644 --- a/src/Prs3d/Prs3d_ToolSector.hxx +++ b/src/Prs3d/Prs3d_ToolSector.hxx @@ -23,14 +23,22 @@ class Prs3d_ToolSector : public Prs3d_ToolQuadric { public: - //! Generate primitives for 3D quadric surface and return a filled array. + //! Generate primitives for 3D quadric surface. + //! @param theRadius [in] sector radius + //! @param theNbSlices [in] number of slices within U parameter + //! @param theNbStacks [in] number of stacks within V parameter + //! @param theTrsf [in] optional transformation to apply + //! @return generated triangulation Standard_EXPORT static Handle(Graphic3d_ArrayOfTriangles) Create (const Standard_Real theRadius, const Standard_Integer theNbSlices, const Standard_Integer theNbStacks, const gp_Trsf& theTrsf); public: - //! Initializes the algorithm. + //! Initializes the algorithm creating a sector (quadrant). + //! @param theRadius [in] sector radius + //! @param theNbSlices [in] number of slices within U parameter + //! @param theNbStacks [in] number of stacks within V parameter Standard_EXPORT Prs3d_ToolSector (const Standard_Real theRadius, const Standard_Integer theNbSlices, const Standard_Integer theNbStacks); @@ -47,7 +55,7 @@ protected: protected: - Standard_Real myRadius; + Standard_Real myRadius; //!< sector radius }; diff --git a/src/Prs3d/Prs3d_ToolSphere.hxx b/src/Prs3d/Prs3d_ToolSphere.hxx index 59f39d0d57..3963298325 100644 --- a/src/Prs3d/Prs3d_ToolSphere.hxx +++ b/src/Prs3d/Prs3d_ToolSphere.hxx @@ -23,14 +23,22 @@ class Prs3d_ToolSphere : public Prs3d_ToolQuadric { public: - //! Generate primitives for 3D quadric surface and return a filled array. + //! Generate primitives for 3D quadric surface. + //! @param theRadius [in] sphere radius + //! @param theNbSlices [in] number of slices within U parameter + //! @param theNbStacks [in] number of stacks within V parameter + //! @param theTrsf [in] optional transformation to apply + //! @return generated triangulation Standard_EXPORT static Handle(Graphic3d_ArrayOfTriangles) Create (const Standard_Real theRadius, const Standard_Integer theNbSlices, const Standard_Integer theNbStacks, const gp_Trsf& theTrsf); public: - //! Initializes the algorithm. + //! Initializes the algorithm creating a sphere. + //! @param theRadius [in] sphere radius + //! @param theNbSlices [in] number of slices within U parameter + //! @param theNbStacks [in] number of stacks within V parameter Standard_EXPORT Prs3d_ToolSphere (const Standard_Real theRadius, const Standard_Integer theNbSlices, const Standard_Integer theNbStacks); @@ -45,7 +53,7 @@ protected: protected: - Standard_Real myRadius; + Standard_Real myRadius; //!< sphere radius }; diff --git a/src/Prs3d/Prs3d_ToolTorus.cxx b/src/Prs3d/Prs3d_ToolTorus.cxx new file mode 100644 index 0000000000..8df318cd0a --- /dev/null +++ b/src/Prs3d/Prs3d_ToolTorus.cxx @@ -0,0 +1,82 @@ +// Created on: 2020-09-17 +// Created by: Marina ZERNOVA +// Copyright (c) 2020 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 + +//======================================================================= +//function : init +//purpose : +//======================================================================= +void Prs3d_ToolTorus::init (const Standard_Real theMajorRad, + const Standard_Real theMinorRad, + const Standard_Real theAngle1, + const Standard_Real theAngle2, + const Standard_Real theAngle, + const Standard_Integer theNbSlices, + const Standard_Integer theNbStacks) +{ + myMajorRadius = theMajorRad; + myMinorRadius = theMinorRad; + myVMin = theAngle1; + myVMax = theAngle2; + myAngle = theAngle; + mySlicesNb = theNbSlices; + myStacksNb = theNbStacks; +} + +//======================================================================= +//function : Vertex +//purpose : +//======================================================================= +gp_Pnt Prs3d_ToolTorus::Vertex (const Standard_Real theU, const Standard_Real theV) const +{ + const Standard_Real aU = theU * myAngle; + const Standard_Real aV = myVMin + theV * (myVMax - myVMin); + return gp_Pnt ((myMajorRadius + myMinorRadius * Cos (aV)) * Cos (aU), + (myMajorRadius + myMinorRadius * Cos (aV)) * Sin (aU), + myMinorRadius * Sin (aV)); +} + +//======================================================================= +//function : Normal +//purpose : +//======================================================================= +gp_Dir Prs3d_ToolTorus::Normal (const Standard_Real theU, const Standard_Real theV) const +{ + const Standard_Real aU = theU * myAngle; + const Standard_Real aV = myVMin + theV * (myVMax - myVMin); + return gp_Dir (Cos (aU) * Cos (aV), + Sin (aU) * Cos (aV), + Sin (aV)); +} + +//======================================================================= +//function : Create +//purpose : +//======================================================================= +Handle(Graphic3d_ArrayOfTriangles) Prs3d_ToolTorus::Create (const Standard_Real theMajorRad, + const Standard_Real theMinorRad, + const Standard_Real theAngle1, + const Standard_Real theAngle2, + const Standard_Real theAngle, + const Standard_Integer theNbSlices, + const Standard_Integer theNbStacks, + const gp_Trsf& theTrsf) +{ + Handle(Graphic3d_ArrayOfTriangles) anArray; + Prs3d_ToolTorus aTool (theMajorRad, theMinorRad, theAngle1, theAngle2, theAngle, theNbSlices, theNbStacks); + aTool.FillArray (anArray, theTrsf); + return anArray; +} diff --git a/src/Prs3d/Prs3d_ToolTorus.hxx b/src/Prs3d/Prs3d_ToolTorus.hxx new file mode 100644 index 0000000000..b488b3c02a --- /dev/null +++ b/src/Prs3d/Prs3d_ToolTorus.hxx @@ -0,0 +1,201 @@ +// Created on: 2020-09-17 +// Created by: Marina ZERNOVA +// Copyright (c) 2020 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 _Prs3d_ToolTorus_HeaderFile +#define _Prs3d_ToolTorus_HeaderFile + +#include + +//! Standard presentation algorithm that outputs graphical primitives for torus surface. +class Prs3d_ToolTorus : public Prs3d_ToolQuadric +{ +public: + + //! Generate primitives for 3D quadric surface (complete torus). + //! @param theMajorRad [in] distance from the center of the pipe to the center of the torus + //! @param theMinorRad [in] radius of the pipe + //! @param theNbSlices [in] number of slices within U parameter + //! @param theNbStacks [in] number of stacks within V parameter + //! @param theTrsf [in] optional transformation to apply + //! @return generated triangulation + static Handle(Graphic3d_ArrayOfTriangles) Create (const Standard_Real theMajorRad, + const Standard_Real theMinorRad, + const Standard_Integer theNbSlices, + const Standard_Integer theNbStacks, + const gp_Trsf& theTrsf) + { + return Create (theMajorRad, theMinorRad, 0.0, M_PI * 2.0, M_PI * 2.0, theNbSlices, theNbStacks, theTrsf); + } + + //! Generate primitives for 3D quadric surface (torus segment). + //! @param theMajorRad [in] distance from the center of the pipe to the center of the torus + //! @param theMinorRad [in] radius of the pipe + //! @param theAngle [in] angle to create a torus pipe segment + //! @param theNbSlices [in] number of slices within U parameter + //! @param theNbStacks [in] number of stacks within V parameter + //! @param theTrsf [in] optional transformation to apply + //! @return generated triangulation + static Handle(Graphic3d_ArrayOfTriangles) Create (const Standard_Real theMajorRad, + const Standard_Real theMinorRad, + const Standard_Real theAngle, + const Standard_Integer theNbSlices, + const Standard_Integer theNbStacks, + const gp_Trsf& theTrsf) + { + return Create (theMajorRad, theMinorRad, 0.0, M_PI * 2.0, theAngle, theNbSlices, theNbStacks, theTrsf); + } + + //! Generate primitives for 3D quadric surface (torus ring segment). + //! @param theMajorRad [in] distance from the center of the pipe to the center of the torus + //! @param theMinorRad [in] radius of the pipe + //! @param theAngle1 [in] first angle to create a torus ring segment + //! @param theAngle2 [in] second angle to create a torus ring segment + //! @param theNbSlices [in] number of slices within U parameter + //! @param theNbStacks [in] number of stacks within V parameter + //! @param theTrsf [in] optional transformation to apply + //! @return generated triangulation + static Handle(Graphic3d_ArrayOfTriangles) Create (const Standard_Real theMajorRad, + const Standard_Real theMinorRad, + const Standard_Real theAngle1, + const Standard_Real theAngle2, + const Standard_Integer theNbSlices, + const Standard_Integer theNbStacks, + const gp_Trsf& theTrsf) + { + return Create (theMajorRad, theMinorRad, theAngle1, theAngle2, M_PI * 2.0, theNbSlices, theNbStacks, theTrsf); + } + + //! Generate primitives for 3D quadric surface (segment of the torus ring segment). + //! @param theMajorRad [in] distance from the center of the pipe to the center of the torus + //! @param theMinorRad [in] radius of the pipe + //! @param theAngle1 [in] first angle to create a torus ring segment + //! @param theAngle2 [in] second angle to create a torus ring segment + //! @param theAngle [in] angle to create a torus pipe segment + //! @param theNbSlices [in] number of slices within U parameter + //! @param theNbStacks [in] number of stacks within V parameter + //! @param theTrsf [in] optional transformation to apply + //! @return generated triangulation + Standard_EXPORT static Handle(Graphic3d_ArrayOfTriangles) Create (const Standard_Real theMajorRad, + const Standard_Real theMinorRad, + const Standard_Real theAngle1, + const Standard_Real theAngle2, + const Standard_Real theAngle, + const Standard_Integer theNbSlices, + const Standard_Integer theNbStacks, + const gp_Trsf& theTrsf); + +public: + + //! Initializes the algorithm creating a complete torus. + //! @param theMajorRad [in] distance from the center of the pipe to the center of the torus + //! @param theMinorRad [in] radius of the pipe + //! @param theNbSlices [in] number of slices within U parameter + //! @param theNbStacks [in] number of stacks within V parameter + Prs3d_ToolTorus (const Standard_Real theMajorRad, + const Standard_Real theMinorRad, + const Standard_Integer theNbSlices, + const Standard_Integer theNbStacks) + { + init (theMajorRad, theMinorRad, 0.0, M_PI * 2.0, M_PI * 2.0, theNbSlices, theNbStacks); + } + + //! Initializes the algorithm creating a torus pipe segment. + //! @param theMajorRad [in] distance from the center of the pipe to the center of the torus + //! @param theMinorRad [in] radius of the pipe + //! @param theAngle [in] angle to create a torus pipe segment + //! @param theNbSlices [in] number of slices within U parameter + //! @param theNbStacks [in] number of stacks within V parameter + Prs3d_ToolTorus (const Standard_Real theMajorRad, + const Standard_Real theMinorRad, + const Standard_Real theAngle, + const Standard_Integer theNbSlices, + const Standard_Integer theNbStacks) + { + init (theMajorRad, theMinorRad, 0.0, M_PI * 2.0, theAngle, theNbSlices, theNbStacks); + } + + //! Initializes the algorithm creating a torus ring segment. + //! @param theMajorRad [in] distance from the center of the pipe to the center of the torus + //! @param theMinorRad [in] radius of the pipe + //! @param theAngle1 [in] first angle to create a torus ring segment + //! @param theAngle2 [in] second angle to create a torus ring segment + //! @param theNbSlices [in] number of slices within U parameter + //! @param theNbStacks [in] number of stacks within V parameter + Prs3d_ToolTorus (const Standard_Real theMajorRad, + const Standard_Real theMinorRad, + const Standard_Real theAngle1, + const Standard_Real theAngle2, + const Standard_Integer theNbSlices, + const Standard_Integer theNbStacks) + { + init (theMajorRad, theMinorRad, theAngle1, theAngle2, M_PI * 2.0, theNbSlices, theNbStacks); + } + + //! Initializes the algorithm creating a torus ring segment. + //! @param theMajorRad [in] distance from the center of the pipe to the center of the torus + //! @param theMinorRad [in] radius of the pipe + //! @param theAngle1 [in] first angle to create a torus ring segment + //! @param theAngle2 [in] second angle to create a torus ring segment + //! @param theAngle [in] angle to create a torus pipe segment + //! @param theNbSlices [in] number of slices within U parameter + //! @param theNbStacks [in] number of stacks within V parameter + Prs3d_ToolTorus (const Standard_Real theMajorRad, + const Standard_Real theMinorRad, + const Standard_Real theAngle1, + const Standard_Real theAngle2, + const Standard_Real theAngle, + const Standard_Integer theNbSlices, + const Standard_Integer theNbStacks) + { + init (theMajorRad, theMinorRad, theAngle1, theAngle2, theAngle, theNbSlices, theNbStacks); + } + +private: + + //! Initialisation + //! @param theMajorRad [in] distance from the center of the pipe to the center of the torus + //! @param theMinorRad [in] radius of the pipe + //! @param theAngle1 [in] first angle to create a torus ring segment + //! @param theAngle2 [in] second angle to create a torus ring segment + //! @param theAngle [in] angle to create a torus pipe segment + //! @param theNbSlices [in] number of slices within U parameter + //! @param theNbStacks [in] number of stacks within V parameter + Standard_EXPORT void init (const Standard_Real theMajorRad, + const Standard_Real theMinorRad, + const Standard_Real theAngle1, + const Standard_Real theAngle2, + const Standard_Real theAngle, + const Standard_Integer theNbSlices, + const Standard_Integer theNbStacks); + +protected: + + //! Computes vertex at given parameter location of the surface. + 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) const Standard_OVERRIDE; + +protected: + + Standard_Real myMajorRadius; //!< distance from the center of the pipe to the center of the torus + Standard_Real myMinorRadius; //!< radius of the pipe + Standard_Real myAngle; //!< angle to create a torus pipe segment + Standard_Real myVMin; //!< first angle to create a torus ring segment + Standard_Real myVMax; //!< second angle to create a torus ring segment + +}; + +#endif // _Prs3d_ToolTorus_HeaderFile diff --git a/src/ViewerTest/ViewerTest_ObjectCommands.cxx b/src/ViewerTest/ViewerTest_ObjectCommands.cxx index 2fc6857539..f1c3a1c43e 100644 --- a/src/ViewerTest/ViewerTest_ObjectCommands.cxx +++ b/src/ViewerTest/ViewerTest_ObjectCommands.cxx @@ -148,6 +148,9 @@ #include #include #include +#include +#include +#include #include #include @@ -5048,6 +5051,146 @@ static Standard_Integer VTriangle (Draw_Interpretor& /*di*/, return 0; } +//=========================================================================== +//function : VTorus +//purpose : creates and displays a torus or torus segment +//=========================================================================== +static Standard_Integer VTorus (Draw_Interpretor& /*di*/, + Standard_Integer argc, + const char ** argv) +{ + if (argc < 4 || argc > 7) + { + Message::SendFail ("Syntax error: wrong number of arguments"); + return 1; + } + + Standard_Real aMajorRad = Draw::Atof (argv[2]); + Standard_Real aMinorRad = Draw::Atof (argv[3]); + if (aMajorRad <= 0 || aMajorRad <= 0) + { + Message::SendFail ("Syntax error: wrong radius value"); + return 1; + } + + Standard_Integer aNbSlices = 100; + Standard_Integer aNbStacks = 100; + const Standard_Integer aTrianglesNb = Prs3d_ToolTorus::TrianglesNb (aNbSlices, aNbStacks); + const Standard_Integer aVerticesNb = Prs3d_ToolTorus::VerticesNb (aNbSlices, aNbStacks); + Handle(Graphic3d_ArrayOfTriangles) aTriangles + = new Graphic3d_ArrayOfTriangles (aVerticesNb, aTrianglesNb * 3, Graphic3d_ArrayFlags_VertexNormal); + + + if (argc == 4) + { + Prs3d_ToolTorus aTool (aMajorRad, aMinorRad, aNbSlices, aNbStacks); + aTool.FillArray (aTriangles, gp_Trsf()); + } + else if (argc == 5) + { + Prs3d_ToolTorus aTool (aMajorRad, aMinorRad, + Draw::Atof (argv[4]) * (M_PI / 180.0), + aNbSlices, aNbStacks); + aTool.FillArray (aTriangles, gp_Trsf()); + } + else if (argc == 6) + { + Prs3d_ToolTorus aTool (aMajorRad, aMinorRad, + Draw::Atof (argv[4]) * (M_PI / 180.0), Draw::Atof (argv[5]) * (M_PI / 180.0), + aNbSlices, aNbStacks); + aTool.FillArray (aTriangles, gp_Trsf()); + } + else if (argc == 7) + { + Prs3d_ToolTorus aTool (aMajorRad, aMinorRad, + Draw::Atof (argv[4]) * (M_PI / 180.0), Draw::Atof (argv[5]) * (M_PI / 180.0), + Draw::Atof (argv[6]) * (M_PI / 180.0), + aNbSlices, aNbStacks); + aTool.FillArray (aTriangles, gp_Trsf()); + } + + Handle(AIS_InteractiveObject) anIO = new MyPArrayObject (aTriangles); + + ViewerTest::Display (argv[1], anIO); + return 0; +} + +//=========================================================================== +//function : VCylinder +//purpose : creates and displays a cylinder +//=========================================================================== +static Standard_Integer VCylinder (Draw_Interpretor& /*di*/, + Standard_Integer argc, + const char ** argv) +{ + if (argc != 5 ) + { + Message::SendFail ("Syntax error: wrong number of arguments"); + return 1; + } + + Standard_Real aBotRad = Draw::Atof (argv[2]); + Standard_Real aTopRad = Draw::Atof (argv[3]); + Standard_Real aHeight = Draw::Atof (argv[4]); + if (aBotRad < 0 || aTopRad < 0 || aHeight < 0) + { + Message::SendFail ("Syntax error: wrong parameter values"); + return 1; + } + + Standard_Integer aNbSlices = 100; + Standard_Integer aNbStacks = 1; + const Standard_Integer aTrianglesNb = Prs3d_ToolCylinder::TrianglesNb (aNbSlices, aNbStacks); + const Standard_Integer aVerticesNb = Prs3d_ToolCylinder::VerticesNb (aNbSlices, aNbStacks); + Handle(Graphic3d_ArrayOfTriangles) aTriangles + = new Graphic3d_ArrayOfTriangles (aVerticesNb, aTrianglesNb * 3, Graphic3d_ArrayFlags_VertexNormal); + + Prs3d_ToolCylinder aTool (aBotRad, aTopRad, aHeight, aNbSlices, aNbStacks); + aTool.FillArray (aTriangles, gp_Trsf()); + + Handle(AIS_InteractiveObject) anIO = new MyPArrayObject (aTriangles); + + ViewerTest::Display (argv[1], anIO); + return 0; +} + +//=========================================================================== +//function : VSphere +//purpose : creates and displays a sphere +//=========================================================================== +static Standard_Integer VSphere (Draw_Interpretor& /*di*/, + Standard_Integer argc, + const char ** argv) +{ + if (argc != 3) + { + Message::SendFail ("Syntax error: wrong number of arguments"); + return 1; + } + + Standard_Real aRad = Draw::Atof (argv[2]); + if (aRad <= 0) + { + Message::SendFail ("Syntax error: wrong radius value"); + return 1; + } + + Standard_Integer aNbSlices = 100; + Standard_Integer aNbStacks = 100; + const Standard_Integer aTrianglesNb = Prs3d_ToolSphere::TrianglesNb (aNbSlices, aNbStacks); + const Standard_Integer aVerticesNb = Prs3d_ToolSphere::VerticesNb (aNbSlices, aNbStacks); + Handle(Graphic3d_ArrayOfTriangles) aTriangles + = new Graphic3d_ArrayOfTriangles (aVerticesNb, aTrianglesNb * 3, Graphic3d_ArrayFlags_VertexNormal); + + Prs3d_ToolSphere aTool (aRad, aNbSlices, aNbStacks); + aTool.FillArray (aTriangles, gp_Trsf()); + + Handle(AIS_InteractiveObject) anIO = new MyPArrayObject (aTriangles); + + ViewerTest::Display (argv[1], anIO); + return 0; +} + //======================================================================= //function : VObjZLayer //purpose : Set or get z layer id for presentable object @@ -6791,6 +6934,31 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands) "\n\t\t: Creates and displays a segment from named points.", __FILE__, VTriangle,group); + theCommands.Add ("vtorus", + "vtorus name R1 R2 [angle1 angle2] [angle]" + "\n\t\t: Creates and displays a torus or torus segment." + "\n\t\t: Parameters of the torus :" + "\n\t\t: - R1 distance from the center of the pipe to the center of the torus" + "\n\t\t: - R2 radius of the pipe" + "\n\t\t: - angle1 first angle to create a torus ring segment" + "\n\t\t: - angle2 second angle to create a torus ring segment" + "\n\t\t: - angle angle to create a torus pipe segment", + __FILE__, VTorus, group); + + theCommands.Add ("vcylinder", + "vcylinder name R1 R2 height" + "\n\t\t: Creates and displays a cylinder." + "\n\t\t: Parameters of the cylinder :" + "\n\t\t: - R1 cylinder bottom radius" + "\n\t\t: - R2 cylinder top radius" + "\n\t\t: - height cylinder height", + __FILE__, VCylinder, group); + + theCommands.Add ("vsphere", + "vsphere name radius" + "\n\t\t: Creates and displays a sphere.", + __FILE__, VSphere, group); + theCommands.Add("vobjzlayer", "vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object", __FILE__, VObjZLayer, group); diff --git a/tests/v3d/grids.list b/tests/v3d/grids.list index 9291a8fd76..27ea80d638 100755 --- a/tests/v3d/grids.list +++ b/tests/v3d/grids.list @@ -21,3 +21,4 @@ 022 transparency 023 viewcube 024 colors +025 quadric diff --git a/tests/v3d/quadric/begin b/tests/v3d/quadric/begin new file mode 100644 index 0000000000..8c0dd45577 --- /dev/null +++ b/tests/v3d/quadric/begin @@ -0,0 +1,2 @@ +vinit View1 +set subgroup "quadric" diff --git a/tests/v3d/quadric/cylinder b/tests/v3d/quadric/cylinder new file mode 100644 index 0000000000..2877d25b60 --- /dev/null +++ b/tests/v3d/quadric/cylinder @@ -0,0 +1,19 @@ +puts "====================================" +puts "Prs3d_ToolCylinder - create cylinder" +puts "====================================" + +# cylinder +vcylinder c1 8 8 20 +vlocation c1 -translate 0 0 20 + +# cone +vcylinder c2 8 0 20 +vlocation c2 -translate -20 -20 -20 + +# frustum of a cone +vcylinder c3 8 4 10 +vlocation c3 -translate 20 20 -20 + +vfit + +vdump $imagedir/${casename}.png diff --git a/tests/v3d/quadric/sphere b/tests/v3d/quadric/sphere new file mode 100644 index 0000000000..c6ff540504 --- /dev/null +++ b/tests/v3d/quadric/sphere @@ -0,0 +1,10 @@ +puts "================================" +puts "Prs3d_ToolSphere - create sphere" +puts "================================" + +# complete sphere +vsphere s 10 + +vfit + +vdump $imagedir/${casename}.png diff --git a/tests/v3d/quadric/torus b/tests/v3d/quadric/torus new file mode 100644 index 0000000000..eebfb28b86 --- /dev/null +++ b/tests/v3d/quadric/torus @@ -0,0 +1,19 @@ +puts "==============================" +puts "Prs3d_ToolTorus - create torus" +puts "==============================" + +# complete torus +vtorus t1 10 5 +vlocation t1 -translate 0 0 20 + +# torus segment +vtorus t2 10 5 270 +vlocation t2 -translate -20 -20 -20 + +# torus ring segment +vtorus t3 10 5 180 360 +vlocation t3 -translate 20 20 -20 + +vfit + +vdump $imagedir/${casename}.png -- 2.39.5