0025099: Visualization - Option to show vertices of a shape
[occt.git] / src / StdPrs / StdPrs_ShadedShape.cxx
index 6834543..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>
@@ -41,6 +42,8 @@
 #include <StdPrs_ToolShadedShape.hxx>
 #include <StdPrs_WFShape.hxx>
 #include <TopExp.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopoDS.hxx>
 #include <TopoDS_Compound.hxx>
 #include <TopoDS_Face.hxx>
 #include <TopoDS_Shape.hxx>
@@ -58,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;
     }
@@ -71,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);
@@ -82,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());
@@ -94,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,
@@ -132,11 +121,11 @@ namespace
     // Precision for compare square distances
     const Standard_Real aPreci = Precision::SquareConfusion();
 
-    StdPrs_ToolShadedShape aShapeTool;
-    for (aShapeTool.Init (theShape); aShapeTool.MoreFace(); aShapeTool.NextFace())
+    TopExp_Explorer aFaceIt(theShape, TopAbs_FACE);
+    for (; aFaceIt.More(); aFaceIt.Next())
     {
-      const TopoDS_Face& aFace = aShapeTool.CurrentFace();
-      aT = aShapeTool.Triangulation (aFace, aLoc);
+      const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current());
+      aT = StdPrs_ToolShadedShape::Triangulation (aFace, aLoc);
       if (!aT.IsNull())
       {
         aNbTriangles += aT->NbTriangles();
@@ -151,10 +140,10 @@ namespace
     Handle(Graphic3d_ArrayOfTriangles) anArray = new Graphic3d_ArrayOfTriangles (aNbVertices, 3 * aNbTriangles,
                                                                                  Standard_True, Standard_False, theHasTexels);
     Standard_Real aUmin (0.0), aUmax (0.0), aVmin (0.0), aVmax (0.0), dUmax (0.0), dVmax (0.0);
-    for (aShapeTool.Init (theShape); aShapeTool.MoreFace(); aShapeTool.NextFace())
+    for (aFaceIt.Init (theShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
     {
-      const TopoDS_Face& aFace = aShapeTool.CurrentFace();
-      aT = aShapeTool.Triangulation (aFace, aLoc);
+      const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current());
+      aT = StdPrs_ToolShadedShape::Triangulation (aFace, aLoc);
       if (aT.IsNull())
       {
         continue;
@@ -165,7 +154,7 @@ namespace
       const TColgp_Array1OfPnt&   aNodes   = aT->Nodes();
       const TColgp_Array1OfPnt2d& aUVNodes = aT->UVNodes();
       TColgp_Array1OfDir aNormals (aNodes.Lower(), aNodes.Upper());
-      aShapeTool.Normal (aFace, aPolyConnect, aNormals);
+      StdPrs_ToolShadedShape::Normal (aFace, aPolyConnect, aNormals);
 
       if (theHasTexels)
       {
@@ -201,7 +190,7 @@ namespace
       Standard_Integer anIndex[3];
       for (Standard_Integer aTriIter = 1; aTriIter <= aT->NbTriangles(); ++aTriIter)
       {
-        if (aShapeTool.Orientation (aFace) == TopAbs_REVERSED)
+        if (aFace.Orientation() == TopAbs_REVERSED)
         {
           aTriangles (aTriIter).Get (anIndex[0], anIndex[2], anIndex[1]);
         }
@@ -456,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;