0025814: Visualization, Prs3d_WFShape::AddPolygon() - always use polygonal representa...
[occt.git] / src / Prs3d / Prs3d_WFShape.cxx
index 7837dff..2d0a7f1 100755 (executable)
@@ -28,6 +28,7 @@
 #include <Poly_Array1OfTriangle.hxx>
 #include <Poly_Polygon3D.hxx>
 #include <Poly_PolygonOnTriangulation.hxx>
+#include <Prs3d.hxx>
 #include <Prs3d_Drawer.hxx>
 #include <Prs3d_IsoAspect.hxx>
 #include <Prs3d_PointAspect.hxx>
@@ -66,35 +67,29 @@ namespace
 // purpose :
 // =========================================================================
 Standard_Boolean Prs3d_WFShape::AddPolygon (const TopoDS_Edge&    theEdge,
-                                            const Standard_Real   theDeflection,
                                             TColgp_SequenceOfPnt& thePoints)
 {
   TopLoc_Location aLocation;
-  Standard_Real aFirst, aLast;
-  Handle(Geom_Curve)     aCurve3d = BRep_Tool::Curve     (theEdge, aFirst, aLast);
   Handle(Poly_Polygon3D) aPolygon = BRep_Tool::Polygon3D (theEdge, aLocation);
   if (!aPolygon.IsNull())
   {
-    if ((aPolygon->Deflection() <= theDeflection) || aCurve3d.IsNull())
+    const TColgp_Array1OfPnt& aPoints = aPolygon->Nodes();
+    Standard_Integer anIndex = aPoints.Lower();
+    if (aLocation.IsIdentity())
     {
-      const TColgp_Array1OfPnt& aPoints = aPolygon->Nodes();
-      Standard_Integer anIndex = aPoints.Lower();
-      if (aLocation.IsIdentity())
+      for (; anIndex <= aPoints.Upper(); ++anIndex)
       {
-        for (; anIndex <= aPoints.Upper(); ++anIndex)
-        {
-          thePoints.Append (aPoints.Value (anIndex));
-        }
+        thePoints.Append (aPoints.Value (anIndex));
       }
-      else
+    }
+    else
+    {
+      for (; anIndex <= aPoints.Upper(); ++anIndex)
       {
-        for (; anIndex <= aPoints.Upper(); ++anIndex)
-        {
-          thePoints.Append (aPoints.Value (anIndex).Transformed (aLocation));
-        }
+        thePoints.Append (aPoints.Value (anIndex).Transformed (aLocation));
       }
-      return Standard_True;
     }
+    return Standard_True;
   }
 
   Handle(Poly_Triangulation)          aTriangulation;
@@ -102,28 +97,25 @@ Standard_Boolean Prs3d_WFShape::AddPolygon (const TopoDS_Edge&    theEdge,
   BRep_Tool::PolygonOnTriangulation (theEdge, aHIndices, aTriangulation, aLocation);
   if (!aHIndices.IsNull())
   {
-    if ((aHIndices->Deflection() <= theDeflection) || aCurve3d.IsNull())
-    {
-      const TColStd_Array1OfInteger& anIndices = aHIndices->Nodes();
-      const TColgp_Array1OfPnt&      aNodes    = aTriangulation->Nodes();
+    const TColStd_Array1OfInteger& anIndices = aHIndices->Nodes();
+    const TColgp_Array1OfPnt&      aNodes    = aTriangulation->Nodes();
 
-      Standard_Integer anIndex = anIndices.Lower();
-      if (aLocation.IsIdentity())
+    Standard_Integer anIndex = anIndices.Lower();
+    if (aLocation.IsIdentity())
+    {
+      for (; anIndex <= anIndices.Upper(); ++anIndex)
       {
-        for (; anIndex <= anIndices.Upper(); ++anIndex)
-        {
-          thePoints.Append (aNodes (anIndices (anIndex)));
-        }
+        thePoints.Append (aNodes (anIndices (anIndex)));
       }
-      else
+    }
+    else
+    {
+      for (; anIndex <= anIndices.Upper(); ++anIndex)
       {
-        for (; anIndex <= anIndices.Upper(); ++anIndex)
-        {
-          thePoints.Append (aNodes (anIndices (anIndex)).Transformed (aLocation));
-        }
+        thePoints.Append (aNodes (anIndices (anIndex)).Transformed (aLocation));
       }
-      return Standard_True;
     }
+    return Standard_True;
   }
   return Standard_False;
 }
@@ -141,7 +133,7 @@ void Prs3d_WFShape::Add (const Handle (Prs3d_Presentation)& thePresentation,
     return;
   }
 
-  Prs3d_ShapeTool aTool (theShape);
+  Prs3d_ShapeTool aTool (theShape, theDrawer->VertexDrawMode() == Prs3d_VDM_All);
   TopTools_ListOfShape aLFree, aLUnFree, aLWire;
   for (aTool.InitCurve(); aTool.MoreCurve(); aTool.NextCurve())
   {
@@ -154,29 +146,13 @@ void Prs3d_WFShape::Add (const Handle (Prs3d_Presentation)& thePresentation,
     }
   }
 
-  Standard_Real aDeflection = theDrawer->MaximalChordialDeviation();
-  if (theDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE)
-  {
-    // The arrow calculation is based on the global min max
-    Bnd_Box aBndBox;
-    BRepBndLib::Add (theShape, aBndBox);
-    if (!aBndBox.IsVoid())
-    {
-      Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
-      aBndBox.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
-      aDeflection = Max (aXmax-aXmin, Max (aYmax-aYmin, aZmax-aZmin))
-                       * theDrawer->DeviationCoefficient();
-    }
-  }
-
-  Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
+  Standard_Real aDeflection = Prs3d::GetDeflection(theShape, theDrawer);
 
   Prs3d_NListOfSequenceOfPnt anUIsoCurves;
   Prs3d_NListOfSequenceOfPnt aVIsoCurves;
   Prs3d_NListOfSequenceOfPnt aWireCurves;
   Prs3d_NListOfSequenceOfPnt aFreeCurves;
   Prs3d_NListOfSequenceOfPnt anUnFreeCurves;
-  TColgp_SequenceOfPnt       aShapePoints;
 
   const Standard_Integer anIsoU = theDrawer->UIsoAspect()->Number();
   const Standard_Integer anIsoV = theDrawer->VIsoAspect()->Number();
@@ -248,7 +224,7 @@ void Prs3d_WFShape::Add (const Handle (Prs3d_Presentation)& thePresentation,
             }
             catch (Standard_Failure)
             {
-            #ifdef DEB
+            #ifdef OCCT_DEBUG
               const TopoDS_Face& aFace = aSurface.Face();
               std::cout << "Problem with the face " << (void* ) &(*(aFace).TShape()) << std::endl;
             #endif
@@ -281,7 +257,7 @@ void Prs3d_WFShape::Add (const Handle (Prs3d_Presentation)& thePresentation,
             }
             catch (Standard_Failure)
             {
-            #ifdef DEB
+            #ifdef OCCT_DEBUG
               const TopoDS_Face& aFace = aSurface.Face();
               std::cout << "Problem with the face " << (void* ) &(*(aFace).TShape()) << std::endl;
             #endif
@@ -299,17 +275,16 @@ void Prs3d_WFShape::Add (const Handle (Prs3d_Presentation)& thePresentation,
     Prs3d_NListIteratorOfListOfSequenceOfPnt anIt;
     for (anIt.Init (anUIsoCurves); anIt.More(); anIt.Next())
     {
-      aNbVertices += anIt.Value().Length();
+      aNbVertices += anIt.Value()->Length();
     }
     Handle(Graphic3d_ArrayOfPolylines) anUIsoArray = new Graphic3d_ArrayOfPolylines (aNbVertices, aNbBounds);
     for (anIt.Init (anUIsoCurves); anIt.More(); anIt.Next())
     {
-      TColgp_SequenceOfPnt aPoints;
-      aPoints.Assign (anIt.Value());
-      anUIsoArray->AddBound (aPoints.Length());
-      for (Standard_Integer anI = 1; anI <= aPoints.Length(); ++anI)
+      const Handle(TColgp_HSequenceOfPnt)& aPoints = anIt.Value();
+      anUIsoArray->AddBound (aPoints->Length());
+      for (Standard_Integer anI = 1; anI <= aPoints->Length(); ++anI)
       {
-        anUIsoArray->AddVertex (aPoints.Value (anI));
+        anUIsoArray->AddVertex (aPoints->Value (anI));
       }
     }
     Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePresentation);
@@ -317,23 +292,23 @@ void Prs3d_WFShape::Add (const Handle (Prs3d_Presentation)& thePresentation,
     aGroup->AddPrimitiveArray (anUIsoArray);
   }
 
+  // NOTE: THIS BLOCK WILL NEVER EXECUTE AS aVIsoCurves IS NOT FILLED!!
   if (aVIsoCurves.Size() > 0)
   {
     aNbBounds = aVIsoCurves.Size();
     Prs3d_NListIteratorOfListOfSequenceOfPnt anIt;
     for (anIt.Init (aVIsoCurves); anIt.More(); anIt.Next())
     {
-      aNbVertices += anIt.Value().Length();
+      aNbVertices += anIt.Value()->Length();
     }
     Handle(Graphic3d_ArrayOfPolylines) VIsoArray = new Graphic3d_ArrayOfPolylines (aNbVertices, aNbBounds);
     for (anIt.Init (aVIsoCurves); anIt.More(); anIt.Next())
     {
-      TColgp_SequenceOfPnt aPoints;
-      aPoints.Assign (anIt.Value());
-      VIsoArray->AddBound (aPoints.Length());
-      for (int anI = 1; anI <= aPoints.Length(); anI++)
+      const Handle(TColgp_HSequenceOfPnt)& aPoints = anIt.Value();
+      VIsoArray->AddBound (aPoints->Length());
+      for (int anI = 1; anI <= aPoints->Length(); anI++)
       {
-        VIsoArray->AddVertex (aPoints.Value (anI));
+        VIsoArray->AddVertex (aPoints->Value (anI));
       }
     }
     Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePresentation);
@@ -438,21 +413,20 @@ void Prs3d_WFShape::Add (const Handle (Prs3d_Presentation)& thePresentation,
   if (theDrawer->WireDraw())
   {
     // Wire (without any neighbour)
-    aGroup->SetPrimitivesAspect (theDrawer->WireAspect()->Aspect());
     for (anIt.Initialize(aLWire); anIt.More(); anIt.Next())
     {
       const TopoDS_Edge& anEdge = TopoDS::Edge (anIt.Value());
       try
       {
         OCC_CATCH_SIGNALS
-        TColgp_SequenceOfPnt aPoints;
-        if (!AddPolygon (anEdge, aDeflection, aPoints))
+        const Handle(TColgp_HSequenceOfPnt)& aPoints = new TColgp_HSequenceOfPnt;
+        if (!AddPolygon (anEdge, aPoints->ChangeSequence()))
         {
           if (BRep_Tool::IsGeometric (anEdge))
           {
             BRepAdaptor_Curve aCurve (anEdge);
             myCurveAlgo.Add (thePresentation, aCurve, aDeflection, theDrawer,
-                             aPoints, Standard_False);
+                             aPoints->ChangeSequence(), Standard_False);
             aWireCurves.Append (aPoints);
           }
         }
@@ -463,7 +437,7 @@ void Prs3d_WFShape::Add (const Handle (Prs3d_Presentation)& thePresentation,
       }
       catch (Standard_Failure)
       {
-      #ifdef DEB
+      #ifdef OCCT_DEBUG
         std::cout << "probleme sur aLocation'edge " << (void* ) &(*(anEdge).TShape()) << std::endl;
       #endif
       }
@@ -481,14 +455,14 @@ void Prs3d_WFShape::Add (const Handle (Prs3d_Presentation)& thePresentation,
         try
         {
           OCC_CATCH_SIGNALS
-          TColgp_SequenceOfPnt aPoints;
-          if (!AddPolygon (anEdge, aDeflection, aPoints))
+          const Handle(TColgp_HSequenceOfPnt)& aPoints = new TColgp_HSequenceOfPnt;
+          if (!AddPolygon (anEdge, aPoints->ChangeSequence()))
           {
             if (BRep_Tool::IsGeometric (anEdge))
             {
               BRepAdaptor_Curve aCurve (anEdge);
               myCurveAlgo.Add (thePresentation, aCurve, aDeflection, theDrawer,
-                               aPoints, Standard_False);
+                               aPoints->ChangeSequence(), Standard_False);
               aFreeCurves.Append (aPoints);
             }
           }
@@ -499,7 +473,7 @@ void Prs3d_WFShape::Add (const Handle (Prs3d_Presentation)& thePresentation,
         }
         catch (Standard_Failure)
         {
-        #ifdef DEB
+        #ifdef OCCT_DEBUG
           std::cout << "probleme sur aLocation'edge " << (void* ) &(*(anEdge).TShape()) << std::endl;
         #endif
         }
@@ -516,13 +490,13 @@ void Prs3d_WFShape::Add (const Handle (Prs3d_Presentation)& thePresentation,
       try
       {
         OCC_CATCH_SIGNALS
-        TColgp_SequenceOfPnt aPoints;
-        if (!AddPolygon (anEdge, aDeflection, aPoints))
+        const Handle(TColgp_HSequenceOfPnt)& aPoints = new TColgp_HSequenceOfPnt;
+        if (!AddPolygon (anEdge, aPoints->ChangeSequence()))
         {
           if (BRep_Tool::IsGeometric (anEdge))
           {
             BRepAdaptor_Curve aCurve (anEdge);
-            myCurveAlgo.Add (thePresentation, aCurve, aDeflection, theDrawer, aPoints, Standard_False);
+            myCurveAlgo.Add (thePresentation, aCurve, aDeflection, theDrawer, aPoints->ChangeSequence(), Standard_False);
             anUnFreeCurves.Append (aPoints);
           }
         }
@@ -533,7 +507,7 @@ void Prs3d_WFShape::Add (const Handle (Prs3d_Presentation)& thePresentation,
       }
       catch (Standard_Failure)
       {
-      #ifdef DEB
+      #ifdef OCCT_DEBUG
         std::cout << "probleme sur aLocation'edge " << (void* ) &(*(anEdge).TShape()) << std::endl;
       #endif
       }
@@ -546,17 +520,16 @@ void Prs3d_WFShape::Add (const Handle (Prs3d_Presentation)& thePresentation,
     Prs3d_NListIteratorOfListOfSequenceOfPnt anIt;
     for (anIt.Init (aWireCurves); anIt.More(); anIt.Next())
     {
-      aNbVertices += anIt.Value().Length();
+      aNbVertices += anIt.Value()->Length();
     }
     Handle(Graphic3d_ArrayOfPolylines) WireArray = new Graphic3d_ArrayOfPolylines (aNbVertices, aNbBounds);
     for (anIt.Init (aWireCurves); anIt.More(); anIt.Next())
     {
-      TColgp_SequenceOfPnt aPoints;
-      aPoints.Assign (anIt.Value());
-      WireArray->AddBound (aPoints.Length());
-      for (anI = 1; anI <= aPoints.Length(); ++anI)
+      const Handle(TColgp_HSequenceOfPnt)& aPoints = anIt.Value();
+      WireArray->AddBound (aPoints->Length());
+      for (anI = 1; anI <= aPoints->Length(); ++anI)
       {
-        WireArray->AddVertex (aPoints.Value (anI));
+        WireArray->AddVertex (aPoints->Value (anI));
       }
     }
     Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePresentation);
@@ -570,17 +543,16 @@ void Prs3d_WFShape::Add (const Handle (Prs3d_Presentation)& thePresentation,
     Prs3d_NListIteratorOfListOfSequenceOfPnt anIt;
     for (anIt.Init (aFreeCurves); anIt.More(); anIt.Next())
     {
-      aNbVertices += anIt.Value().Length();
+      aNbVertices += anIt.Value()->Length();
     }
     Handle(Graphic3d_ArrayOfPolylines) aFreeArray = new Graphic3d_ArrayOfPolylines (aNbVertices, aNbBounds);
     for (anIt.Init(aFreeCurves); anIt.More(); anIt.Next())
     {
-      TColgp_SequenceOfPnt aPoints;
-      aPoints.Assign (anIt.Value());
-      aFreeArray->AddBound (aPoints.Length());
-      for (anI = 1; anI <= aPoints.Length(); ++anI)
+      const Handle(TColgp_HSequenceOfPnt)& aPoints = anIt.Value();
+      aFreeArray->AddBound (aPoints->Length());
+      for (anI = 1; anI <= aPoints->Length(); ++anI)
       {
-        aFreeArray->AddVertex (aPoints.Value (anI));
+        aFreeArray->AddVertex (aPoints->Value (anI));
       }
     }  
     Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePresentation);
@@ -594,17 +566,16 @@ void Prs3d_WFShape::Add (const Handle (Prs3d_Presentation)& thePresentation,
     Prs3d_NListIteratorOfListOfSequenceOfPnt anIt;
     for (anIt.Init (anUnFreeCurves); anIt.More(); anIt.Next())
     {
-      aNbVertices += anIt.Value().Length();
+      aNbVertices += anIt.Value()->Length();
     }
     Handle(Graphic3d_ArrayOfPolylines) anUnFreeArray = new Graphic3d_ArrayOfPolylines (aNbVertices, aNbBounds);
     for (anIt.Init (anUnFreeCurves); anIt.More(); anIt.Next())
     {
-      TColgp_SequenceOfPnt aPoints;
-      aPoints.Assign (anIt.Value());
-      anUnFreeArray->AddBound (aPoints.Length());
-      for (anI = 1; anI <= aPoints.Length(); ++anI)
+      const Handle(TColgp_HSequenceOfPnt)& aPoints = anIt.Value();
+      anUnFreeArray->AddBound (aPoints->Length());
+      for (anI = 1; anI <= aPoints->Length(); ++anI)
       {
-        anUnFreeArray->AddVertex (aPoints.Value (anI));
+        anUnFreeArray->AddVertex (aPoints->Value (anI));
       }
     }
     Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePresentation);
@@ -613,6 +584,7 @@ void Prs3d_WFShape::Add (const Handle (Prs3d_Presentation)& thePresentation,
   }
 
   // Points
+  TColgp_SequenceOfPnt aShapePoints;
   for (aTool.InitVertex(); aTool.MoreVertex(); aTool.NextVertex())
   {
     aShapePoints.Append (BRep_Tool::Pnt (aTool.GetVertex()));