0025099: Visualization - Option to show vertices of a shape
[occt.git] / src / StdPrs / StdPrs_ShadedShape.cxx
index 64b29a4..b2e1dec 100644 (file)
@@ -31,6 +31,7 @@
 #include <gp_Pnt.hxx>
 #include <NCollection_List.hxx>
 #include <Precision.hxx>
+#include <Prs3d.hxx>
 #include <Prs3d_Drawer.hxx>
 #include <Prs3d_LineAspect.hxx>
 #include <Prs3d_Presentation.hxx>
@@ -60,7 +61,9 @@ namespace
                            const TopoDS_Shape&                theShape,
                            const Handle (Prs3d_Drawer)&       theDrawer)
   {
-    if (theShape.ShapeType() != TopAbs_COMPOUND)
+    Standard_Boolean aDrawAllVerticesFlag = (theDrawer->VertexDrawMode() == Prs3d_VDM_All);
+
+    if (!aDrawAllVerticesFlag && theShape.ShapeType() != TopAbs_COMPOUND)
     {
       return;
     }
@@ -73,6 +76,11 @@ namespace
       return;
     }
 
+    // We have to create a compound and collect all subshapes not drawn by the shading algo.
+    // This includes:
+    // - isolated edges
+    // - isolated vertices, if aDrawAllVerticesFlag == Standard_False
+    // - all shape's vertices, if aDrawAllVerticesFlag == Standard_True
     TopoDS_Compound aCompoundWF;
     BRep_Builder aBuilder;
     aBuilder.MakeCompound (aCompoundWF);
@@ -84,8 +92,9 @@ namespace
       hasElement = Standard_True;
       aBuilder.Add (aCompoundWF, aShapeIter.Current());
     }
-    // isolated vertices
-    for (aShapeIter.Init (theShape, TopAbs_VERTEX, TopAbs_EDGE); aShapeIter.More(); aShapeIter.Next())
+    // isolated or all vertices
+    aShapeIter.Init (theShape, TopAbs_VERTEX, aDrawAllVerticesFlag ? TopAbs_SHAPE : TopAbs_EDGE);
+    for (; aShapeIter.More(); aShapeIter.Next())
     {
       hasElement = Standard_True;
       aBuilder.Add (aCompoundWF, aShapeIter.Current());
@@ -96,28 +105,6 @@ namespace
     }
   }
 
-  //! Computes absolute deflection, required by drawer
-  static Standard_Real getDeflection (const TopoDS_Shape&         theShape,
-                                      const Handle(Prs3d_Drawer)& theDrawer)
-  {
-    #define MAX2(X, Y)    (Abs(X) > Abs(Y) ? Abs(X) : Abs(Y))
-    #define MAX3(X, Y, Z) (MAX2 (MAX2 (X, Y), Z))
-
-    Standard_Real aDeflection = theDrawer->MaximalChordialDeviation();
-    if (theDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE)
-    {
-      Bnd_Box aBndBox;
-      BRepBndLib::Add (theShape, aBndBox, Standard_False);
-      if (!aBndBox.IsVoid())
-      {
-        Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
-        aBndBox.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
-        aDeflection = MAX3 (aXmax-aXmin, aYmax-aYmin, aZmax-aZmin) * theDrawer->DeviationCoefficient() * 4.0;
-      }
-    }
-    return aDeflection;
-  }
-
   //! Gets triangulation of every face of shape and fills output array of triangles
   static Handle(Graphic3d_ArrayOfTriangles) fillTriangles (const TopoDS_Shape&    theShape,
                                                            const Standard_Boolean theHasTexels,
@@ -458,7 +445,7 @@ void StdPrs_ShadedShape::Tessellate (const TopoDS_Shape&          theShape,
                                      const Handle (Prs3d_Drawer)& theDrawer)
 {
   // Check if it is possible to avoid unnecessary recomputation of shape triangulation
-  Standard_Real aDeflection = getDeflection (theShape, theDrawer);
+  Standard_Real aDeflection = Prs3d::GetDeflection (theShape, theDrawer);
   if (BRepTools::Triangulation (theShape, aDeflection))
   {
     return;