0031490: Foundation Classes, Poly_Connect - speed up temporary allocations
[occt.git] / src / StdPrs / StdPrs_ShadedShape.cxx
index 3a9ac5e..ca30cd5 100644 (file)
 #include <StdPrs_ShadedShape.hxx>
 
 #include <Bnd_Box.hxx>
-#include <BRep_Builder.hxx>
-#include <BRepBndLib.hxx>
-#include <BRepMesh_DiscretFactory.hxx>
-#include <BRepMesh_DiscretRoot.hxx>
 #include <BRepTools.hxx>
+#include <BRepBndLib.hxx>
+#include <BRep_Builder.hxx>
+#include <BRep_Tool.hxx>
 #include <Graphic3d_ArrayOfSegments.hxx>
 #include <Graphic3d_ArrayOfTriangles.hxx>
 #include <Graphic3d_AspectFillArea3d.hxx>
 #include <gp_Dir.hxx>
 #include <gp_Vec.hxx>
 #include <gp_Pnt.hxx>
+#include <NCollection_IncAllocator.hxx>
 #include <NCollection_List.hxx>
+#include <NCollection_Shared.hxx>
 #include <Precision.hxx>
-#include <Prs3d.hxx>
 #include <Prs3d_Drawer.hxx>
 #include <Prs3d_IsoAspect.hxx>
 #include <Prs3d_LineAspect.hxx>
@@ -40,8 +40,7 @@
 #include <Poly_Connect.hxx>
 #include <Poly_PolygonOnTriangulation.hxx>
 #include <Poly_Triangulation.hxx>
-#include <StdPrs_ToolShadedShape.hxx>
-#include <StdPrs_WFDeflectionShape.hxx>
+#include <StdPrs_ToolTriangulatedShape.hxx>
 #include <StdPrs_WFShape.hxx>
 #include <TopExp.hxx>
 #include <TopExp_Explorer.hxx>
@@ -63,18 +62,16 @@ namespace
                            const TopoDS_Shape&                theShape,
                            const Handle (Prs3d_Drawer)&       theDrawer)
   {
-    Standard_Boolean aDrawAllVerticesFlag = (theDrawer->VertexDrawMode() == Prs3d_VDM_All);
-
-    if (!aDrawAllVerticesFlag && theShape.ShapeType() != TopAbs_COMPOUND)
+    TopExp_Explorer aShapeIter (theShape, TopAbs_FACE);
+    if (!aShapeIter.More())
     {
+      StdPrs_WFShape::Add (thePrs, theShape, theDrawer);
       return;
     }
 
-    TopExp_Explorer aShapeIter (theShape, TopAbs_FACE);
-    if (!aShapeIter.More())
+    const Standard_Boolean aDrawAllVerticesFlag = (theDrawer->VertexDrawMode() == Prs3d_VDM_All);
+    if (!aDrawAllVerticesFlag && theShape.ShapeType() != TopAbs_COMPOUND)
     {
-      // compound contains no shaded elements at all
-      StdPrs_WFDeflectionShape::Add (thePrs, theShape, theDrawer);
       return;
     }
 
@@ -103,7 +100,7 @@ namespace
     }
     if (hasElement)
     {
-      StdPrs_WFDeflectionShape::Add (thePrs, aCompoundWF, theDrawer);
+      StdPrs_WFShape::Add (thePrs, aCompoundWF, theDrawer);
     }
   }
 
@@ -136,7 +133,7 @@ namespace
       theDrawer->UIsoAspect()->SetNumber (5);
       theDrawer->VIsoAspect()->SetNumber (5);
 
-      StdPrs_WFDeflectionShape::Add (thePrs, aCompoundWF, theDrawer);
+      StdPrs_WFShape::Add (thePrs, aCompoundWF, theDrawer);
 
       theDrawer->UIsoAspect()->SetNumber (aPrevUIsoNb);
       theDrawer->VIsoAspect()->SetNumber (aPrevVIsoNb);
@@ -163,7 +160,7 @@ namespace
     for (; aFaceIt.More(); aFaceIt.Next())
     {
       const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current());
-      aT = StdPrs_ToolShadedShape::Triangulation (aFace, aLoc);
+      aT = BRep_Tool::Triangulation (aFace, aLoc);
       if (!aT.IsNull())
       {
         aNbTriangles += aT->NbTriangles();
@@ -181,7 +178,7 @@ namespace
     for (aFaceIt.Init (theShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
     {
       const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current());
-      aT = StdPrs_ToolShadedShape::Triangulation (aFace, aLoc);
+      aT = BRep_Tool::Triangulation (aFace, aLoc);
       if (aT.IsNull())
       {
         continue;
@@ -191,12 +188,14 @@ namespace
       // Determinant of transform matrix less then 0 means that mirror transform applied.
       Standard_Boolean isMirrored = aTrsf.VectorialPart().Determinant() < 0;
 
-      Poly_Connect aPolyConnect (aT);
       // Extracts vertices & normals from nodes
       const TColgp_Array1OfPnt&   aNodes   = aT->Nodes();
-      const TColgp_Array1OfPnt2d& aUVNodes = aT->UVNodes();
-      TColgp_Array1OfDir aNormals (aNodes.Lower(), aNodes.Upper());
-      StdPrs_ToolShadedShape::Normal (aFace, aPolyConnect, aNormals);
+      const TColgp_Array1OfPnt2d* aUVNodes = theHasTexels && aT->HasUVNodes() && aT->UVNodes().Upper() == aNodes.Upper()
+                                           ? &aT->UVNodes()
+                                           : NULL;
+      StdPrs_ToolTriangulatedShape::ComputeNormals (aFace, aT);
+      const TShort_Array1OfShortReal& aNormals = aT->Normals();
+      const Standard_ShortReal*       aNormArr = &aNormals.First();
 
       if (theHasTexels)
       {
@@ -209,22 +208,29 @@ namespace
       for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter)
       {
         aPoint = aNodes (aNodeIter);
+        const Standard_Integer anId = 3 * (aNodeIter - aNodes.Lower());
+        gp_Dir aNorm (aNormArr[anId + 0], aNormArr[anId + 1], aNormArr[anId + 2]);
+        if ((aFace.Orientation() == TopAbs_REVERSED) ^ isMirrored)
+        {
+          aNorm.Reverse();
+        }
         if (!aLoc.IsIdentity())
         {
           aPoint.Transform (aTrsf);
-
-          aNormals (aNodeIter) = aNormals (aNodeIter).Transformed (aTrsf);
+          aNorm.Transform (aTrsf);
         }
 
-        if (theHasTexels && aUVNodes.Upper() == aNodes.Upper())
+        if (aUVNodes != NULL)
         {
-          const gp_Pnt2d aTexel = gp_Pnt2d ((-theUVOrigin.X() + (theUVRepeat.X() * (aUVNodes (aNodeIter).X() - aUmin)) / dUmax) / theUVScale.X(),
-                                            (-theUVOrigin.Y() + (theUVRepeat.Y() * (aUVNodes (aNodeIter).Y() - aVmin)) / dVmax) / theUVScale.Y());
-          anArray->AddVertex (aPoint, aNormals (aNodeIter), aTexel);
+          const gp_Pnt2d aTexel = (dUmax == 0.0 || dVmax == 0.0)
+                                ? aUVNodes->Value (aNodeIter)
+                                : gp_Pnt2d ((-theUVOrigin.X() + (theUVRepeat.X() * (aUVNodes->Value (aNodeIter).X() - aUmin)) / dUmax) / theUVScale.X(),
+                                            (-theUVOrigin.Y() + (theUVRepeat.Y() * (aUVNodes->Value (aNodeIter).Y() - aVmin)) / dVmax) / theUVScale.Y());
+          anArray->AddVertex (aPoint, aNorm, aTexel);
         }
         else
         {
-          anArray->AddVertex (aPoint, aNormals (aNodeIter));
+          anArray->AddVertex (aPoint, aNorm);
         }
       }
 
@@ -233,7 +239,7 @@ namespace
       Standard_Integer anIndex[3];
       for (Standard_Integer aTriIter = 1; aTriIter <= aT->NbTriangles(); ++aTriIter)
       {
-        if ((aFace.Orientation() == TopAbs_REVERSED) ^ isMirrored)
+        if ((aFace.Orientation() == TopAbs_REVERSED))
         {
           aTriangles (aTriIter).Get (anIndex[0], anIndex[2], anIndex[1]);
         }
@@ -266,9 +272,9 @@ namespace
         aV1.Cross (aV2);
         if (aV1.SquareMagnitude() > aPreci)
         {
-          anArray->AddEdge (anIndex[0] + aDecal);
-          anArray->AddEdge (anIndex[1] + aDecal);
-          anArray->AddEdge (anIndex[2] + aDecal);
+          anArray->AddEdges (anIndex[0] + aDecal,
+                             anIndex[1] + aDecal,
+                             anIndex[2] + aDecal);
         }
       }
     }
@@ -283,7 +289,7 @@ namespace
                                           const gp_Pnt2d&                   theUVOrigin,
                                           const gp_Pnt2d&                   theUVRepeat,
                                           const gp_Pnt2d&                   theUVScale,
-                                          const Standard_Boolean            theIsClosed)
+                                          const bool                        theIsClosed)
   {
     Handle(Graphic3d_ArrayOfTriangles) aPArray = fillTriangles (theShape, theHasTexels, theUVOrigin, theUVRepeat, theUVScale);
     if (aPArray.IsNull())
@@ -293,135 +299,161 @@ namespace
 
     Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePrs);
     aGroup->SetClosed (theIsClosed);
-    if (!theDrawer->ShadingAspectGlobal())
-    {
-      Handle(Graphic3d_AspectFillArea3d) anAsp = theDrawer->ShadingAspect()->Aspect();
-      theIsClosed ? anAsp->SuppressBackFace() : anAsp->AllowBackFace();
-      aGroup->SetGroupPrimitivesAspect (anAsp);
-    }
+    aGroup->SetGroupPrimitivesAspect (theDrawer->ShadingAspect()->Aspect());
     aGroup->AddPrimitiveArray (aPArray);
     return Standard_True;
   }
 
   //! Compute boundary presentation for faces of the shape.
-  static void computeFaceBoundaries (const TopoDS_Shape&               theShape,
-                                     const Handle(Prs3d_Presentation)& thePrs,
-                                     const Handle(Prs3d_Drawer)&       theDrawer)
+  static Handle(Graphic3d_ArrayOfSegments) fillFaceBoundaries (const TopoDS_Shape& theShape,
+                                                               GeomAbs_Shape theUpperContinuity)
   {
     // collection of all triangulation nodes on edges
     // for computing boundaries presentation
-    NCollection_List<Handle(TColgp_HArray1OfPnt)> aNodeCollection;
     Standard_Integer aNodeNumber = 0;
+    Standard_Integer aNbPolylines = 0;
 
     TopLoc_Location aTrsf;
 
+    Handle(NCollection_Shared<TColgp_SequenceOfPnt>) aSeqPntsExtra;
+    for (TopExp_Explorer aFaceIter (theShape, TopAbs_FACE); aFaceIter.More(); aFaceIter.Next())
+    {
+      const TopoDS_Face& aFace = TopoDS::Face (aFaceIter.Current());
+      if (aFace.NbChildren() == 0)
+      {
+        // handle specifically faces without boundary definition (triangulation-only)
+        if (aSeqPntsExtra.IsNull())
+        {
+          Handle(NCollection_IncAllocator) anIncAlloc = new NCollection_IncAllocator();
+          aSeqPntsExtra = new NCollection_Shared<TColgp_SequenceOfPnt> (anIncAlloc);
+        }
+        StdPrs_WFShape::AddEdgesOnTriangulation (*aSeqPntsExtra, aFace, Standard_False);
+      }
+    }
+
     // explore all boundary edges
     TopTools_IndexedDataMapOfShapeListOfShape anEdgesMap;
-    TopExp::MapShapesAndAncestors (
-      theShape, TopAbs_EDGE, TopAbs_FACE, anEdgesMap);
-
-    Standard_Integer anEdgeIdx = 1;
-    for ( ; anEdgeIdx <= anEdgesMap.Extent (); anEdgeIdx++)
+    TopExp::MapShapesAndAncestors (theShape, TopAbs_EDGE, TopAbs_FACE, anEdgesMap);
+    for (TopTools_IndexedDataMapOfShapeListOfShape::Iterator anEdgeIter (anEdgesMap); anEdgeIter.More(); anEdgeIter.Next())
     {
       // reject free edges
-      const TopTools_ListOfShape& aFaceList = anEdgesMap.FindFromIndex (anEdgeIdx);
-      if (aFaceList.Extent() == 0)
+      if (anEdgeIter.Value().Extent() == 0)
+      {
         continue;
+      }
 
       // take one of the shared edges and get edge triangulation
-      const TopoDS_Face& aFace  = TopoDS::Face (aFaceList.First ());
-      const TopoDS_Edge& anEdge = TopoDS::Edge (anEdgesMap.FindKey (anEdgeIdx));
-
-      Handle(Poly_Triangulation) aTriangulation =
-        BRep_Tool::Triangulation (aFace, aTrsf);
+      const TopoDS_Face& aFace = TopoDS::Face (anEdgeIter.Value().First());
+      Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aTrsf);
+      if (aTriangulation.IsNull())
+      {
+        continue;
+      }
 
-      if (aTriangulation.IsNull ())
+      const TopoDS_Edge& anEdge = TopoDS::Edge (anEdgeIter.Key());
+      if (theUpperContinuity < GeomAbs_CN
+       && anEdgeIter.Value().Extent() >= 2
+       && BRep_Tool::MaxContinuity (anEdge) > theUpperContinuity)
+      {
         continue;
+      }
+
+      Handle(Poly_PolygonOnTriangulation) anEdgePoly = BRep_Tool::PolygonOnTriangulation (anEdge, aTriangulation, aTrsf);
+      if (!anEdgePoly.IsNull()
+        && anEdgePoly->Nodes().Length() >= 2)
+      {
+        aNodeNumber += anEdgePoly->Nodes().Length();
+        ++aNbPolylines;
+      }
+    }
+    const Standard_Integer aNbExtra = !aSeqPntsExtra.IsNull() ? aSeqPntsExtra->Size() : 0;
+    if (aNodeNumber == 0)
+    {
+      if (aNbExtra < 2)
+      {
+        return Handle(Graphic3d_ArrayOfSegments)();
+      }
 
-      Handle(Poly_PolygonOnTriangulation) anEdgePoly =
-        BRep_Tool::PolygonOnTriangulation (anEdge, aTriangulation, aTrsf);
+      Handle(Graphic3d_ArrayOfSegments) aSegments = new Graphic3d_ArrayOfSegments (aNbExtra);
+      for (TColgp_SequenceOfPnt::Iterator aPntIter (*aSeqPntsExtra); aPntIter.More(); aPntIter.Next())
+      {
+        aSegments->AddVertex (aPntIter.Value());
+      }
+      return aSegments;
+    }
 
-      if (anEdgePoly.IsNull ())
+    // create indexed segments array to pack polylines from different edges into single array
+    const Standard_Integer aSegmentEdgeNb = (aNodeNumber - aNbPolylines) * 2;
+    Handle(Graphic3d_ArrayOfSegments) aSegments = new Graphic3d_ArrayOfSegments (aNodeNumber + aNbExtra, aSegmentEdgeNb + aNbExtra);
+    for (TopTools_IndexedDataMapOfShapeListOfShape::Iterator anEdgeIter (anEdgesMap); anEdgeIter.More(); anEdgeIter.Next())
+    {
+      if (anEdgeIter.Value().Extent() == 0)
+      {
         continue;
+      }
 
-      // get edge nodes indexes from face triangulation
-      const TColgp_Array1OfPnt& aTriNodes = aTriangulation->Nodes ();
-      const TColStd_Array1OfInteger& anEdgeNodes = anEdgePoly->Nodes ();
+      const TopoDS_Face& aFace = TopoDS::Face (anEdgeIter.Value().First());
+      Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aTrsf);
+      if (aTriangulation.IsNull())
+      {
+        continue;
+      }
 
-      if (anEdgeNodes.Length () < 2)
+      const TopoDS_Edge& anEdge = TopoDS::Edge (anEdgeIter.Key());
+      if (theUpperContinuity < GeomAbs_CN
+       && anEdgeIter.Value().Extent() >= 2
+       && BRep_Tool::MaxContinuity (anEdge) > theUpperContinuity)
+      {
         continue;
+      }
 
-      // collect the edge nodes
-      Handle(TColgp_HArray1OfPnt) aCollected =
-        new TColgp_HArray1OfPnt (anEdgeNodes.Lower (), anEdgeNodes.Upper ());
+      Handle(Poly_PolygonOnTriangulation) anEdgePoly = BRep_Tool::PolygonOnTriangulation (anEdge, aTriangulation, aTrsf);
+      if (anEdgePoly.IsNull()
+       || anEdgePoly->Nodes().Length () < 2)
+      {
+        continue;
+      }
 
-      Standard_Integer aNodeIdx = anEdgeNodes.Lower ();
-      for ( ; aNodeIdx <= anEdgeNodes.Upper (); aNodeIdx++)
+      // get edge nodes indexes from face triangulation
+      const TColgp_Array1OfPnt&      aTriNodes   = aTriangulation->Nodes();
+      const TColStd_Array1OfInteger& anEdgeNodes = anEdgePoly->Nodes();
+
+      // collect the edge nodes
+      Standard_Integer aSegmentEdge = aSegments->VertexNumber() + 1;
+      for (Standard_Integer aNodeIdx = anEdgeNodes.Lower(); aNodeIdx <= anEdgeNodes.Upper(); ++aNodeIdx)
       {
         // node index in face triangulation
-        Standard_Integer aTriIndex = anEdgeNodes.Value (aNodeIdx);
-
         // get node and apply location transformation to the node
+        const Standard_Integer aTriIndex = anEdgeNodes.Value (aNodeIdx);
         gp_Pnt aTriNode = aTriNodes.Value (aTriIndex);
-        if (!aTrsf.IsIdentity ())
+        if (!aTrsf.IsIdentity())
+        {
           aTriNode.Transform (aTrsf);
+        }
 
-        // add node to the boundary array
-        aCollected->SetValue (aNodeIdx, aTriNode);
+        aSegments->AddVertex (aTriNode);
+        if (aNodeIdx != anEdgeNodes.Lower())
+        {
+          aSegments->AddEdge (  aSegmentEdge);
+          aSegments->AddEdge (++aSegmentEdge);
+        }
       }
-
-      aNodeNumber += anEdgeNodes.Length ();
-      aNodeCollection.Append (aCollected);
     }
 
-    // check if it possible to continue building the presentation
-    if (aNodeNumber == 0)
-      return;
-
-    // allocate polyline array for presentation
-    Standard_Integer aSegmentEdgeNb = 
-      (aNodeNumber - aNodeCollection.Extent()) * 2;
-
-    Handle(Graphic3d_ArrayOfSegments) aSegments = 
-      new Graphic3d_ArrayOfSegments (aNodeNumber, aSegmentEdgeNb);
-
-    // build presentation for edge bondaries
-    NCollection_List<Handle(TColgp_HArray1OfPnt)>::Iterator 
-      aCollIt (aNodeCollection);
-
-    // the edge index is increased in each iteration step to
-    // avoid contiguous segments between different face edges.
-    for ( ; aCollIt.More(); aCollIt.Next () )
+    if (!aSeqPntsExtra.IsNull())
     {
-      const Handle(TColgp_HArray1OfPnt)& aNodeArray = aCollIt.Value ();
-
-      Standard_Integer aNodeIdx = aNodeArray->Lower ();
-
-      // add first node (this node is not shared with previous segment).
-      // for each face edge, indices for sharing nodes 
-      // between segments begin from the first added node.
-      Standard_Integer aSegmentEdge = 
-        aSegments->AddVertex (aNodeArray->Value (aNodeIdx));
-
-      // add subsequent nodes and provide edge indexes for sharing
-      // the nodes between the sequential segments.
-      for ( aNodeIdx++; aNodeIdx <= aNodeArray->Upper (); aNodeIdx++ )
+      Standard_Integer aSegmentEdge = aSegments->VertexNumber();
+      for (TColgp_SequenceOfPnt::Iterator aPntIter (*aSeqPntsExtra); aPntIter.More(); aPntIter.Next())
       {
-        aSegments->AddVertex (aNodeArray->Value (aNodeIdx));
-        aSegments->AddEdge (  aSegmentEdge);
+        aSegments->AddVertex (aPntIter.Value());
         aSegments->AddEdge (++aSegmentEdge);
       }
     }
 
-    // set up aspect and add polyline data
-    Handle(Graphic3d_AspectLine3d) aBoundaryAspect = 
-      theDrawer->FaceBoundaryAspect ()->Aspect ();
-
-    Handle(Graphic3d_Group) aPrsGrp = Prs3d_Root::CurrentGroup (thePrs);
-    aPrsGrp->SetGroupPrimitivesAspect (aBoundaryAspect);
-    aPrsGrp->AddPrimitiveArray (aSegments);
+    return aSegments;
   }
-};
+
+} // anonymous namespace
 
 // =======================================================================
 // function : ExploreSolids
@@ -456,7 +488,7 @@ void StdPrs_ShadedShape::ExploreSolids (const TopoDS_Shape&    theShape,
         const TopoDS_Shape& aSubShape   = anIter.Value();
         const Standard_Boolean isClosed = aSubShape.ShapeType() == TopAbs_SHELL &&
                                           BRep_Tool::IsClosed (aSubShape)       &&
-                                          StdPrs_ToolShadedShape::IsTriangulated (aSubShape);
+                                          StdPrs_ToolTriangulatedShape::IsTriangulated (aSubShape);
         theBuilder.Add (isClosed ? theClosed : theOpened, aSubShape);
       }
       return;
@@ -497,30 +529,6 @@ void StdPrs_ShadedShape::Add (const Handle(Prs3d_Presentation)& thePrs,
                            Standard_False, aDummy, aDummy, aDummy, theVolume);
 }
 
-// =======================================================================
-// function : Tessellate
-// purpose  :
-// =======================================================================
-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 = Prs3d::GetDeflection (theShape, theDrawer);
-  if (BRepTools::Triangulation (theShape, aDeflection))
-  {
-    return;
-  }
-
-  // retrieve meshing tool from Factory
-  Handle(BRepMesh_DiscretRoot) aMeshAlgo = BRepMesh_DiscretFactory::Get().Discret (theShape,
-                                                                                   aDeflection,
-                                                                                   theDrawer->HLRAngle());
-  if (!aMeshAlgo.IsNull())
-  {
-    aMeshAlgo->Perform();
-  }
-}
-
 // =======================================================================
 // function : Add
 // purpose  :
@@ -539,16 +547,16 @@ void StdPrs_ShadedShape::Add (const Handle (Prs3d_Presentation)& thePrs,
     return;
   }
 
-  // add wireframe presentation for isolated edges and vertices
-  wireframeFromShape (thePrs, theShape, theDrawer);
-
   // Use automatic re-triangulation with deflection-check logic only if this feature is enable
   if (theDrawer->IsAutoTriangulation())
   {
     // Triangulation completeness is important for "open-closed" analysis - perform tessellation beforehand
-    Tessellate (theShape, theDrawer);
+    StdPrs_ToolTriangulatedShape::Tessellate (theShape, theDrawer);
   }
 
+  // add wireframe presentation for isolated edges and vertices
+  wireframeFromShape (thePrs, theShape, theDrawer);
+
   // add special wireframe presentation for faces without triangulation
   wireframeNoTriangFacesFromShape (thePrs, theShape, theDrawer);
 
@@ -567,18 +575,16 @@ void StdPrs_ShadedShape::Add (const Handle (Prs3d_Presentation)& thePrs,
     aBuilder.MakeCompound (anOpened);
     ExploreSolids (theShape, aBuilder, aClosed, anOpened, Standard_True);
 
-    TopoDS_Iterator aShapeIter (aClosed);
-    if (aShapeIter.More())
+    if (aClosed.NbChildren() > 0)
     {
       shadeFromShape (aClosed, thePrs, theDrawer,
-                      theHasTexels, theUVOrigin, theUVRepeat, theUVScale, Standard_True);
+                      theHasTexels, theUVOrigin, theUVRepeat, theUVScale, true);
     }
 
-    aShapeIter.Initialize (anOpened);
-    if (aShapeIter.More())
+    if (anOpened.NbChildren() > 0)
     {
       shadeFromShape (anOpened, thePrs, theDrawer,
-                      theHasTexels, theUVOrigin, theUVRepeat, theUVScale, Standard_False);
+                      theHasTexels, theUVOrigin, theUVRepeat, theUVScale, false);
     }
   }
   else
@@ -586,11 +592,61 @@ void StdPrs_ShadedShape::Add (const Handle (Prs3d_Presentation)& thePrs,
     // if the shape type is not compound, composolid or solid, use autodetection back-facing filled
     shadeFromShape (theShape, thePrs, theDrawer,
                     theHasTexels, theUVOrigin, theUVRepeat, theUVScale,
-                    (theVolume == StdPrs_Volume_Closed ? Standard_True : Standard_False));
+                    theVolume == StdPrs_Volume_Closed);
   }
 
   if (theDrawer->FaceBoundaryDraw())
   {
-    computeFaceBoundaries (theShape, thePrs, theDrawer);
+    if (Handle(Graphic3d_ArrayOfSegments) aBndSegments = fillFaceBoundaries (theShape, theDrawer->FaceBoundaryUpperContinuity()))
+    {
+      Handle(Graphic3d_Group) aPrsGrp = thePrs->NewGroup();
+      aPrsGrp->SetGroupPrimitivesAspect (theDrawer->FaceBoundaryAspect()->Aspect());
+      aPrsGrp->AddPrimitiveArray (aBndSegments);
+    }
   }
 }
+
+// =======================================================================
+// function : FillTriangles
+// purpose  :
+// =======================================================================
+Handle(Graphic3d_ArrayOfTriangles) StdPrs_ShadedShape::FillTriangles (const TopoDS_Shape&    theShape,
+                                                                      const Standard_Boolean theHasTexels,
+                                                                      const gp_Pnt2d&        theUVOrigin,
+                                                                      const gp_Pnt2d&        theUVRepeat,
+                                                                      const gp_Pnt2d&        theUVScale)
+{
+  return fillTriangles (theShape, theHasTexels, theUVOrigin, theUVRepeat, theUVScale);
+}
+
+// =======================================================================
+// function : FillFaceBoundaries
+// purpose  :
+// =======================================================================
+Handle(Graphic3d_ArrayOfSegments) StdPrs_ShadedShape::FillFaceBoundaries (const TopoDS_Shape& theShape,
+                                                                          GeomAbs_Shape theUpperContinuity)
+{
+  return fillFaceBoundaries (theShape, theUpperContinuity);
+}
+
+// =======================================================================
+// function : AddWireframeForFreeElements
+// purpose  :
+// =======================================================================
+void StdPrs_ShadedShape::AddWireframeForFreeElements (const Handle (Prs3d_Presentation)& thePrs,
+                                                      const TopoDS_Shape&                theShape,
+                                                      const Handle (Prs3d_Drawer)&       theDrawer)
+{
+  wireframeFromShape (thePrs, theShape, theDrawer);
+}
+
+// =======================================================================
+// function : AddWireframeForFacesWithoutTriangles
+// purpose  :
+// =======================================================================
+void StdPrs_ShadedShape::AddWireframeForFacesWithoutTriangles (const Handle(Prs3d_Presentation)& thePrs,
+                                                               const TopoDS_Shape&               theShape,
+                                                               const Handle(Prs3d_Drawer)&       theDrawer)
+{
+  wireframeNoTriangFacesFromShape (thePrs, theShape, theDrawer);
+}