0025310: Regressions in visualization
authorazn <azn@opencascade.com>
Wed, 8 Oct 2014 10:57:22 +0000 (14:57 +0400)
committerbugmaster <bugmaster@opencascade.com>
Fri, 10 Oct 2014 12:05:55 +0000 (16:05 +0400)
- Memory management in the BRepMesh_FastDiscret class is changed. Now the unused face attributes is immediately removed.

src/BRepMesh/BRepMesh_FaceAttribute.cxx
src/BRepMesh/BRepMesh_FaceAttribute.hxx
src/BRepMesh/BRepMesh_FastDiscret.cxx
src/BRepMesh/BRepMesh_FastDiscret.hxx
src/BRepMesh/BRepMesh_FastDiscretFace.cxx
src/BRepMesh/BRepMesh_FastDiscretFace.hxx
src/BRepMesh/BRepMesh_IncrementalMesh.cxx
src/BRepMesh/BRepMesh_IncrementalMesh.hxx
src/MeshTest/MeshTest.cxx
src/MeshTest/MeshTest_DrawableMesh.cxx
src/XSDRAWSTLVRML/XSDRAWSTLVRML_ToVRML.cxx

index 9529ef2..6788fbf 100644 (file)
@@ -70,12 +70,7 @@ BRepMesh_FaceAttribute::BRepMesh_FaceAttribute(
 //=======================================================================
 BRepMesh_FaceAttribute::~BRepMesh_FaceAttribute()
 {
 //=======================================================================
 BRepMesh_FaceAttribute::~BRepMesh_FaceAttribute()
 {
-  clearLocal();
-
-  mySurfaceVertices.Clear();
-  mySurfacePoints->Clear();
-
-  myClassifier.Nullify();
+  Clear();
   myAllocator.Nullify();
 }
 
   myAllocator.Nullify();
 }
 
@@ -103,18 +98,38 @@ void BRepMesh_FaceAttribute::init()
 }
 
 //=======================================================================
 }
 
 //=======================================================================
-//function : clearLocal
+//function : Clear
 //purpose  : 
 //=======================================================================
 //purpose  : 
 //=======================================================================
-void BRepMesh_FaceAttribute::clearLocal()
+void BRepMesh_FaceAttribute::Clear(
+  const Standard_Boolean isClearSurfaceDataOnly)
 {
 {
-  myStructure.Nullify();
+  clearLocal(isClearSurfaceDataOnly);
+
+  mySurfaceVertices.Clear();
+  mySurfacePoints->Clear();
 
 
+  mySurface.Nullify();
+  myClassifier.Nullify();
+}
+
+//=======================================================================
+//function : clearLocal
+//purpose  : 
+//=======================================================================
+void BRepMesh_FaceAttribute::clearLocal(
+  const Standard_Boolean isClearSurfaceDataOnly)
+{
   myLocation2D.Clear();
   myVertexEdgeMap->Clear();
   myLocation2D.Clear();
   myVertexEdgeMap->Clear();
-  myInternalEdges->Clear();
 
 
-  myAllocator->Reset(Standard_False);
+  if (!isClearSurfaceDataOnly)
+  {
+    myInternalEdges->Clear();
+  }
+
+  myStructure.Nullify();
+  myAllocator->Reset(isClearSurfaceDataOnly);
 }
 
 //=======================================================================
 }
 
 //=======================================================================
index 8c85ce6..d602dbf 100644 (file)
@@ -189,6 +189,11 @@ public: //! @name main geometrical properties.
 
 public: //! @name auxiliary structures
 
 
 public: //! @name auxiliary structures
 
+  //! Clear face attribute.
+  //! @param isClearSurfaceDataOnly clears only surface attributes if true value is set.
+  Standard_EXPORT void Clear(
+    const Standard_Boolean isClearSurfaceDataOnly = Standard_False);
+
   //! Resets mesh data structure.
   //! @returns reset data structure.
   Standard_EXPORT Handle(BRepMesh_DataStructureOfDelaun)& ResetStructure();
   //! Resets mesh data structure.
   //! @returns reset data structure.
   Standard_EXPORT Handle(BRepMesh_DataStructureOfDelaun)& ResetStructure();
@@ -330,7 +335,8 @@ private:
     const Standard_Real theLastParam) const;
 
   //! Clears internal data structures local to face.
     const Standard_Real theLastParam) const;
 
   //! Clears internal data structures local to face.
-  void clearLocal();
+  void clearLocal(
+    const Standard_Boolean isClearSurfaceDataOnly = Standard_False);
 
   //! Returns index of the given vertex if it exists in cache.
   //! @param theVertex vertex which index should be retrieved.
 
   //! Returns index of the given vertex if it exists in cache.
   //! @param theVertex vertex which index should be retrieved.
index b70f724..2c8221b 100644 (file)
@@ -194,7 +194,7 @@ void BRepMesh_FastDiscret::Process(const TopoDS_Face& theFace) const
       OCC_CATCH_SIGNALS
 
       BRepMesh_FastDiscretFace aTool(GetAngle(), WithShare());
       OCC_CATCH_SIGNALS
 
       BRepMesh_FastDiscretFace aTool(GetAngle(), WithShare());
-      aTool.Add(anAttribute);
+      aTool.Perform(anAttribute);
     }
     catch (Standard_Failure)
     {
     }
     catch (Standard_Failure)
     {
@@ -224,9 +224,10 @@ Standard_Integer BRepMesh_FastDiscret::Add(const TopoDS_Face& theFace)
       myAttributes.Bind(theFace, myAttribute);
     }
 
       myAttributes.Bind(theFace, myAttribute);
     }
 
-    myStructure     = myAttribute->ResetStructure();
     myVertexEdgeMap = myAttribute->ChangeVertexEdgeMap();
     myInternalEdges = myAttribute->ChangeInternalEdges();
     myVertexEdgeMap = myAttribute->ChangeVertexEdgeMap();
     myInternalEdges = myAttribute->ChangeInternalEdges();
+    Handle(BRepMesh_DataStructureOfDelaun)& aStructure =
+      myAttribute->ResetStructure();
 
     if (!myWithShare)
     {
 
     if (!myWithShare)
     {
@@ -346,7 +347,7 @@ Standard_Integer BRepMesh_FastDiscret::Add(const TopoDS_Face& theFace)
       Standard_Integer i1 = 1;
       for ( i1 = 1; i1 <= myVertexEdgeMap->Extent(); ++i1 )
       {
       Standard_Integer i1 = 1;
       for ( i1 = 1; i1 <= myVertexEdgeMap->Extent(); ++i1 )
       {
-        const BRepMesh_Vertex& aVertex = myStructure->GetNode(myVertexEdgeMap->FindKey(i1));
+        const BRepMesh_Vertex& aVertex = aStructure->GetNode(myVertexEdgeMap->FindKey(i1));
 
         ++ipn;
 
 
         ++ipn;
 
@@ -420,7 +421,7 @@ Standard_Integer BRepMesh_FastDiscret::Add(const TopoDS_Face& theFace)
       {
         BRepMesh::HClassifier& aClassifier = myAttribute->ChangeClassifier();
         BRepMesh_WireChecker aDFaceChecker(aFace, Precision::PConfusion(),
       {
         BRepMesh::HClassifier& aClassifier = myAttribute->ChangeClassifier();
         BRepMesh_WireChecker aDFaceChecker(aFace, Precision::PConfusion(),
-          myInternalEdges, myVertexEdgeMap, myStructure,
+          myInternalEdges, myVertexEdgeMap, aStructure,
           myumin, myumax, myvmin, myvmax, myInParallel );
 
         aDFaceChecker.ReCompute(aClassifier);
           myumin, myumax, myvmin, myvmax, myInParallel );
 
         aDFaceChecker.ReCompute(aClassifier);
@@ -435,7 +436,7 @@ Standard_Integer BRepMesh_FastDiscret::Add(const TopoDS_Face& theFace)
             ++nbmaill;
 
             // Clear the structure of links
             ++nbmaill;
 
             // Clear the structure of links
-            myStructure = myAttribute->ResetStructure();
+            aStructure = myAttribute->ResetStructure();
 
             
             for (Standard_Integer j = 1; j <= aFaceEdges.Length(); ++j)
 
             
             for (Standard_Integer j = 1; j <= aFaceEdges.Length(); ++j)
@@ -610,12 +611,15 @@ void BRepMesh_FastDiscret::addLinkToMesh(
   const Standard_Integer   theLastNodeId,
   const TopAbs_Orientation theOrientation)
 {
   const Standard_Integer   theLastNodeId,
   const TopAbs_Orientation theOrientation)
 {
+  Handle(BRepMesh_DataStructureOfDelaun)& aStructure =
+    myAttribute->ChangeStructure();
+
   if (theOrientation == TopAbs_FORWARD)
   if (theOrientation == TopAbs_FORWARD)
-    myStructure->AddLink(BRepMesh_Edge(theFirstNodeId, theLastNodeId, BRepMesh_Frontier));
+    aStructure->AddLink(BRepMesh_Edge(theFirstNodeId, theLastNodeId, BRepMesh_Frontier));
   else if (theOrientation == TopAbs_REVERSED)
   else if (theOrientation == TopAbs_REVERSED)
-    myStructure->AddLink(BRepMesh_Edge(theLastNodeId, theFirstNodeId, BRepMesh_Frontier));
+    aStructure->AddLink(BRepMesh_Edge(theLastNodeId, theFirstNodeId, BRepMesh_Frontier));
   else if (theOrientation == TopAbs_INTERNAL)
   else if (theOrientation == TopAbs_INTERNAL)
-    myStructure->AddLink(BRepMesh_Edge(theFirstNodeId, theLastNodeId, BRepMesh_Fixed));
+    aStructure->AddLink(BRepMesh_Edge(theFirstNodeId, theLastNodeId, BRepMesh_Fixed));
 }
 
 //=======================================================================
 }
 
 //=======================================================================
index 7d303e1..66382ce 100644 (file)
@@ -364,7 +364,6 @@ private:
 
   // Fast access to attributes of current face
   Handle(BRepMesh_FaceAttribute)                   myAttribute;
 
   // Fast access to attributes of current face
   Handle(BRepMesh_FaceAttribute)                   myAttribute;
-  Handle(BRepMesh_DataStructureOfDelaun)           myStructure;
   BRepMesh::HIMapOfInteger                         myVertexEdgeMap;
   BRepMesh::HDMapOfShapePairOfPolygon              myInternalEdges;
   TopTools_IndexedDataMapOfShapeListOfShape        mySharedFaces;
   BRepMesh::HIMapOfInteger                         myVertexEdgeMap;
   BRepMesh::HDMapOfShapePairOfPolygon              myInternalEdges;
   TopTools_IndexedDataMapOfShapeListOfShape        mySharedFaces;
index caba67d..28004d3 100644 (file)
@@ -142,15 +142,25 @@ namespace {
 //=======================================================================
 BRepMesh_FastDiscretFace::BRepMesh_FastDiscretFace
                           (const Standard_Real     theAngle,
 //=======================================================================
 BRepMesh_FastDiscretFace::BRepMesh_FastDiscretFace
                           (const Standard_Real     theAngle,
-                           const Standard_Boolean  theWithShare) : 
-  myAngle(theAngle), myWithShare(theWithShare),
+                           const Standard_Boolean  theWithShare)
+: myAngle(theAngle), myWithShare(theWithShare),
   myInternalVerticesMode(Standard_True)
 {
   myAllocator = new NCollection_IncAllocator(64000);
 }
 
 //=======================================================================
   myInternalVerticesMode(Standard_True)
 {
   myAllocator = new NCollection_IncAllocator(64000);
 }
 
 //=======================================================================
-//function : Add(face)
+//function : Perform
+//purpose  : 
+//=======================================================================
+void BRepMesh_FastDiscretFace::Perform(const Handle(BRepMesh_FaceAttribute)& theAttribute)
+{
+  Add(theAttribute);
+  commitSurfaceTriangulation();
+}
+
+//=======================================================================
+//function : Add
 //purpose  : 
 //=======================================================================
 void BRepMesh_FastDiscretFace::Add(const Handle(BRepMesh_FaceAttribute)& theAttribute)
 //purpose  : 
 //=======================================================================
 void BRepMesh_FastDiscretFace::Add(const Handle(BRepMesh_FaceAttribute)& theAttribute)
@@ -1209,4 +1219,70 @@ void BRepMesh_FastDiscretFace::insertVertex(
   gp_XY aPnt2d  = myAttribute->Scale(theUV, Standard_True);
   BRepMesh_Vertex aVertex(aPnt2d, aNbLocat, BRepMesh_Free);
   theVertices.Append(aVertex);
   gp_XY aPnt2d  = myAttribute->Scale(theUV, Standard_True);
   BRepMesh_Vertex aVertex(aPnt2d, aNbLocat, BRepMesh_Free);
   theVertices.Append(aVertex);
-}
\ No newline at end of file
+}
+
+//=======================================================================
+//function : commitSurfaceTriangulation
+//purpose  : 
+//=======================================================================
+void BRepMesh_FastDiscretFace::commitSurfaceTriangulation()
+{
+  if (myAttribute.IsNull() || !myAttribute->IsValid())
+    return;
+
+  TopoDS_Face aFace = myAttribute->Face();
+  BRepMesh_ShapeTool::NullifyFace(aFace);
+
+  Handle(BRepMesh_DataStructureOfDelaun)& aStructure = myAttribute->ChangeStructure();
+  const BRepMesh::MapOfInteger&           aTriangles = aStructure->ElementsOfDomain();
+
+  if (aTriangles.IsEmpty())
+    return;
+
+  BRepMesh::HIMapOfInteger& aVetrexEdgeMap = myAttribute->ChangeVertexEdgeMap();
+
+  // Store triangles
+  Standard_Integer aVerticesNb  = aVetrexEdgeMap->Extent();
+  Standard_Integer aTrianglesNb = aTriangles.Extent();
+  Handle(Poly_Triangulation) aNewTriangulation =
+    new Poly_Triangulation(aVerticesNb, aTrianglesNb, Standard_True);
+
+  Poly_Array1OfTriangle& aPolyTrianges = aNewTriangulation->ChangeTriangles();
+
+  Standard_Integer aTriangeId = 1;
+  BRepMesh::MapOfInteger::Iterator aTriIt(aTriangles);
+  for (; aTriIt.More(); aTriIt.Next())
+  {
+    const BRepMesh_Triangle& aCurElem = aStructure->GetElement(aTriIt.Key());
+
+    Standard_Integer aNode[3];
+    aStructure->ElementNodes(aCurElem, aNode);
+
+    Standard_Integer aNodeId[3];
+    for (Standard_Integer i = 0; i < 3; ++i)
+      aNodeId[i] = aVetrexEdgeMap->FindIndex(aNode[i]);
+
+    aPolyTrianges(aTriangeId++).Set(aNodeId[0], aNodeId[1], aNodeId[2]);
+  }
+
+  // Store mesh nodes
+  TColgp_Array1OfPnt&   aNodes   = aNewTriangulation->ChangeNodes();
+  TColgp_Array1OfPnt2d& aNodes2d = aNewTriangulation->ChangeUVNodes();
+
+  for (Standard_Integer i = 1; i <= aVerticesNb; ++i)
+  {
+    Standard_Integer       aVertexId = aVetrexEdgeMap->FindKey(i);
+    const BRepMesh_Vertex& aVertex   = aStructure->GetNode(aVertexId);
+    const gp_Pnt&          aPoint    = myAttribute->GetPoint(aVertex);
+
+    aNodes(i)   = aPoint;
+    aNodes2d(i) = aVertex.Coord();
+  }
+
+  aNewTriangulation->Deflection(myAttribute->GetDefFace());
+  BRepMesh_ShapeTool::AddInFace(aFace, aNewTriangulation);
+
+  // Delete unused data
+  myStructure.Nullify();
+  myAttribute->Clear(Standard_True);
+}
index 4871108..3c286d5 100644 (file)
@@ -55,6 +55,7 @@ public:
     const Standard_Boolean theWithShare = Standard_True);
 
   Standard_EXPORT void Add(const Handle(BRepMesh_FaceAttribute)& theAttribute);
     const Standard_Boolean theWithShare = Standard_True);
 
   Standard_EXPORT void Add(const Handle(BRepMesh_FaceAttribute)& theAttribute);
+  Standard_EXPORT void Perform(const Handle(BRepMesh_FaceAttribute)& theAttribute);
 
   DEFINE_STANDARD_RTTI(BRepMesh_FastDiscretFace)
 
 
   DEFINE_STANDARD_RTTI(BRepMesh_FastDiscretFace)
 
@@ -134,6 +135,9 @@ private:
                     const gp_XY&            theUV,
                     BRepMesh::ListOfVertex& theVertices);
 
                     const gp_XY&            theUV,
                     BRepMesh::ListOfVertex& theVertices);
 
+  //! Stores mesh into the face (without internal edges).
+  void commitSurfaceTriangulation();
+
 private:
 
   Standard_Real                          myAngle;
 private:
 
   Standard_Real                          myAngle;
index 2cba275..f7473da 100644 (file)
@@ -481,16 +481,16 @@ void BRepMesh_IncrementalMesh::commit()
 {
   std::vector<TopoDS_Face>::iterator aFaceIt(myFaces.begin());
   for (; aFaceIt != myFaces.end(); aFaceIt++)
 {
   std::vector<TopoDS_Face>::iterator aFaceIt(myFaces.begin());
   for (; aFaceIt != myFaces.end(); aFaceIt++)
-    commitFace(*aFaceIt);
+    commitEdges(*aFaceIt);
 
   discretizeFreeEdges();
 }
 
 //=======================================================================
 
   discretizeFreeEdges();
 }
 
 //=======================================================================
-//function : commitFace
+//function : commitEdges
 //purpose  : 
 //=======================================================================
 //purpose  : 
 //=======================================================================
-void BRepMesh_IncrementalMesh::commitFace(const TopoDS_Face& theFace)
+void BRepMesh_IncrementalMesh::commitEdges(const TopoDS_Face& theFace)
 {
   TopoDS_Face aFace = theFace;
   aFace.Orientation(TopAbs_FORWARD);
 {
   TopoDS_Face aFace = theFace;
   aFace.Orientation(TopAbs_FORWARD);
@@ -499,8 +499,6 @@ void BRepMesh_IncrementalMesh::commitFace(const TopoDS_Face& theFace)
   if (!myMesh->GetFaceAttribute(aFace, aFaceAttribute))
     return;
 
   if (!myMesh->GetFaceAttribute(aFace, aFaceAttribute))
     return;
 
-  BRepMesh_ShapeTool::NullifyFace(aFace);
-
   if (!aFaceAttribute->IsValid())
   {
     myStatus |= aFaceAttribute->GetStatus();
   if (!aFaceAttribute->IsValid())
   {
     myStatus |= aFaceAttribute->GetStatus();
@@ -508,60 +506,18 @@ void BRepMesh_IncrementalMesh::commitFace(const TopoDS_Face& theFace)
   }
 
   TopLoc_Location            aLoc = aFace.Location();
   }
 
   TopLoc_Location            aLoc = aFace.Location();
-  Handle(Poly_Triangulation) aOldTriangulation = BRep_Tool::Triangulation(aFace, aLoc);
+  Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation(aFace, aLoc);
+
+  if (aTriangulation.IsNull())
+  {
+    aFaceAttribute->Clear();
+    return;
+  }
 
   try
   {
     OCC_CATCH_SIGNALS
 
 
   try
   {
     OCC_CATCH_SIGNALS
 
-    Handle(BRepMesh_DataStructureOfDelaun)& aStructure = aFaceAttribute->ChangeStructure();
-    const BRepMesh::MapOfInteger&           aTriangles = aStructure->ElementsOfDomain();
-    if (aTriangles.IsEmpty())
-      return;
-
-    BRepMesh::HIMapOfInteger& aVetrexEdgeMap = aFaceAttribute->ChangeVertexEdgeMap();
-
-    // Store triangles
-    Standard_Integer aVerticesNb  = aVetrexEdgeMap->Extent();
-    Standard_Integer aTrianglesNb = aTriangles.Extent();
-    Handle(Poly_Triangulation) aNewTriangulation =
-      new Poly_Triangulation(aVerticesNb, aTrianglesNb, Standard_True);
-
-    Poly_Array1OfTriangle& aPolyTrianges = aNewTriangulation->ChangeTriangles();
-
-    Standard_Integer aTriangeId = 1;
-    BRepMesh::MapOfInteger::Iterator aTriIt(aTriangles);
-    for (; aTriIt.More(); aTriIt.Next())
-    {
-      const BRepMesh_Triangle& aCurElem = aStructure->GetElement(aTriIt.Key());
-
-      Standard_Integer aNode[3];
-      aStructure->ElementNodes(aCurElem, aNode);
-
-      Standard_Integer aNodeId[3];
-      for (Standard_Integer i = 0; i < 3; ++i)
-        aNodeId[i] = aVetrexEdgeMap->FindIndex(aNode[i]);
-
-      aPolyTrianges(aTriangeId++).Set(aNodeId[0], aNodeId[1], aNodeId[2]);
-    }
-
-    // Store mesh nodes
-    TColgp_Array1OfPnt&   aNodes   = aNewTriangulation->ChangeNodes();
-    TColgp_Array1OfPnt2d& aNodes2d = aNewTriangulation->ChangeUVNodes();
-
-    for (Standard_Integer i = 1; i <= aVerticesNb; ++i)
-    {
-      Standard_Integer       aVertexId = aVetrexEdgeMap->FindKey(i);
-      const BRepMesh_Vertex& aVertex   = aStructure->GetNode(aVertexId);
-      const gp_Pnt&          aPoint    = aFaceAttribute->GetPoint(aVertex);
-
-      aNodes(i)   = aPoint;
-      aNodes2d(i) = aVertex.Coord();
-    }
-
-    aNewTriangulation->Deflection(aFaceAttribute->GetDefFace());
-    BRepMesh_ShapeTool::AddInFace(aFace, aNewTriangulation);
-
     // Store discretization of edges
     BRepMesh::HDMapOfShapePairOfPolygon& aInternalEdges = aFaceAttribute->ChangeInternalEdges();
     BRepMesh::DMapOfShapePairOfPolygon::Iterator aEdgeIt(*aInternalEdges);
     // Store discretization of edges
     BRepMesh::HDMapOfShapePairOfPolygon& aInternalEdges = aFaceAttribute->ChangeInternalEdges();
     BRepMesh::DMapOfShapePairOfPolygon::Iterator aEdgeIt(*aInternalEdges);
@@ -572,12 +528,13 @@ void BRepMesh_IncrementalMesh::commitFace(const TopoDS_Face& theFace)
       const Handle(Poly_PolygonOnTriangulation)& aPolygon1 = aPolyPair.First();
       const Handle(Poly_PolygonOnTriangulation)& aPolygon2 = aPolyPair.Last();
 
       const Handle(Poly_PolygonOnTriangulation)& aPolygon1 = aPolyPair.First();
       const Handle(Poly_PolygonOnTriangulation)& aPolygon2 = aPolyPair.Last();
 
-      BRepMesh_ShapeTool::NullifyEdge(aEdge, aOldTriangulation, aLoc);
       if (aPolygon1 == aPolygon2)
       if (aPolygon1 == aPolygon2)
-        BRepMesh_ShapeTool::UpdateEdge(aEdge, aPolygon1, aNewTriangulation, aLoc);
+        BRepMesh_ShapeTool::UpdateEdge(aEdge, aPolygon1, aTriangulation, aLoc);
       else
       else
-        BRepMesh_ShapeTool::UpdateEdge(aEdge, aPolygon1, aPolygon2, aNewTriangulation, aLoc);
+        BRepMesh_ShapeTool::UpdateEdge(aEdge, aPolygon1, aPolygon2, aTriangulation, aLoc);
     }
     }
+
+    aFaceAttribute->Clear();
   }
   catch (Standard_Failure)
   {
   }
   catch (Standard_Failure)
   {
index b99d79d..bc1bed4 100644 (file)
@@ -189,8 +189,8 @@ private:
   //! Stores mesh to the shape.
   void commit();
 
   //! Stores mesh to the shape.
   void commit();
 
-  //! Stores mesh to the face.
-  void commitFace(const TopoDS_Face& theFace);
+  //! Stores mesh of internal edges to the face.
+  void commitEdges(const TopoDS_Face& theFace);
 
 protected:
 
 
 protected:
 
index 9b92c29..ad59269 100644 (file)
@@ -433,19 +433,22 @@ static Standard_Integer triangule(Draw_Interpretor& di, Standard_Integer nbarg,
 
 
   Bnd_Box aBox;
 
 
   Bnd_Box aBox;
-  const Handle(BRepMesh_FastDiscret)& aFastDiscret = aDMesh->Mesher()->Mesh();
 
   TopExp_Explorer aFaceIt(aShape, TopAbs_FACE);
   for (; aFaceIt.More(); aFaceIt.Next())
   {
     const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current());
 
 
   TopExp_Explorer aFaceIt(aShape, TopAbs_FACE);
   for (; aFaceIt.More(); aFaceIt.Next())
   {
     const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current());
 
-    Handle(BRepMesh_FaceAttribute) anAttribute;
-    if (aFastDiscret->GetFaceAttribute(aFace, anAttribute) && anAttribute->IsValid())
+    TopLoc_Location aLoc = aFace.Location();
+    Handle(Poly_Triangulation) aTriangulation =
+      BRep_Tool::Triangulation(aFace, aLoc);
+
+    if (!aTriangulation.IsNull())
     {
     {
-      const Standard_Integer aNbPnts = anAttribute->LastPointId();
-      for (Standard_Integer i = 1; i < aNbPnts; ++i)
-        aBox.Add(anAttribute->GetPoint(i));
+      const Standard_Integer    aLength = aTriangulation->NbNodes();
+      const TColgp_Array1OfPnt& aNodes  = aTriangulation->Nodes();
+      for (Standard_Integer i = 1; i <= aLength; ++i)
+        aBox.Add(aNodes(i));
     }
   }
 
     }
   }
 
index 68cd191..c238141 100644 (file)
@@ -20,6 +20,8 @@
 #include <Draw_ColorKind.hxx>
 #include <Draw_Color.hxx>
 #include <TColStd_ListIteratorOfListOfInteger.hxx>
 #include <Draw_ColorKind.hxx>
 #include <Draw_Color.hxx>
 #include <TColStd_ListIteratorOfListOfInteger.hxx>
+#include <TColStd_Array1OfInteger.hxx>
+#include <Poly_Triangulation.hxx>
 #include <Standard_RangeError.hxx>
 #include <BRepMesh_DegreeOfFreedom.hxx>
 #include <BRepMesh_Edge.hxx>
 #include <Standard_RangeError.hxx>
 #include <BRepMesh_DegreeOfFreedom.hxx>
 #include <BRepMesh_Edge.hxx>
 IMPLEMENT_STANDARD_HANDLE (MeshTest_DrawableMesh, Draw_Drawable3D)
 IMPLEMENT_STANDARD_RTTIEXT(MeshTest_DrawableMesh, Draw_Drawable3D)
 
 IMPLEMENT_STANDARD_HANDLE (MeshTest_DrawableMesh, Draw_Drawable3D)
 IMPLEMENT_STANDARD_RTTIEXT(MeshTest_DrawableMesh, Draw_Drawable3D)
 
+typedef NCollection_Map<BRepMesh_Edge> BRepMesh_MapOfLinks;
+
+static inline void addLink(const Standard_Integer theIndex1,
+                           const Standard_Integer theIndex2,
+                           BRepMesh_MapOfLinks&   theMap)
+{
+  BRepMesh_Edge anEdge(theIndex1, theIndex2, BRepMesh_Free);
+  theMap.Add(anEdge);
+}
+
 //=======================================================================
 //function : MeshTest_DrawableMesh
 //purpose  : 
 //=======================================================================
 //function : MeshTest_DrawableMesh
 //purpose  : 
@@ -221,28 +233,40 @@ void MeshTest_DrawableMesh::Dump(Standard_OStream&) const
 //=======================================================================
 void MeshTest_DrawableMesh::Whatis(Draw_Interpretor& theStream) const 
 {
 //=======================================================================
 void MeshTest_DrawableMesh::Whatis(Draw_Interpretor& theStream) const 
 {
+  const TopoDS_Shape& aShape                = myMesher->Shape();
   const Handle(BRepMesh_FastDiscret)& aMesh = myMesher->Mesh();
   const Handle(BRepMesh_FastDiscret)& aMesh = myMesher->Mesh();
+
   Standard_Integer aPointsNb    = aMesh->NbBoundaryPoints();
   Standard_Integer aTrianglesNb = 0;
   Standard_Integer aEdgesNb     = 0;
 
   Standard_Integer aPointsNb    = aMesh->NbBoundaryPoints();
   Standard_Integer aTrianglesNb = 0;
   Standard_Integer aEdgesNb     = 0;
 
-  const TopoDS_Shape& aShape = myMesher->Shape();
+  TopLoc_Location aLocation;
+  Handle(Poly_Triangulation) aTriangulation;
+
   TopExp_Explorer aFaceIt(aShape, TopAbs_FACE);
   for (; aFaceIt.More(); aFaceIt.Next())
   {
     const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current());
 
   TopExp_Explorer aFaceIt(aShape, TopAbs_FACE);
   for (; aFaceIt.More(); aFaceIt.Next())
   {
     const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current());
 
-    Handle(BRepMesh_FaceAttribute) aAtrribure;
-    if (!aMesh->GetFaceAttribute(aFace, aAtrribure) || !aAtrribure->IsValid())
+    aTriangulation = BRep_Tool::Triangulation(aFace, aLocation);
+    if (aTriangulation.IsNull())
       continue;
 
       continue;
 
-    aPointsNb   += aAtrribure->ChangeSurfacePoints()->Extent();
-
-    Handle(BRepMesh_DataStructureOfDelaun)& aStructure =
-      aAtrribure->ChangeStructure();
-
-    aTrianglesNb += aStructure->ElementsOfDomain().Extent();
-    aEdgesNb     += aStructure->LinksOfDomain().Extent();
+    // Count number of links
+    BRepMesh_MapOfLinks aMap;
+    const Poly_Array1OfTriangle& aTriangles = aTriangulation->Triangles();
+    for (Standard_Integer i = 1, v[3]; i <= aTriangles.Length(); ++i)
+    {
+      aTriangles(i).Get(v[0], v[1], v[2]);
+
+      addLink(v[0], v[1], aMap);
+      addLink(v[1], v[2], aMap);
+      addLink(v[2], v[0], aMap);
+    }
+
+    aPointsNb    += aTriangulation->NbNodes();
+    aTrianglesNb += aTriangulation->NbTriangles();
+    aEdgesNb     += aMap.Extent();
   }
 
   theStream << " 3d mesh\n";
   }
 
   theStream << " 3d mesh\n";
index 5aaa2f5..d721052 100644 (file)
 #include <XSDRAWSTLVRML_ToVRML.ixx>
 
 #include <Standard_Stream.hxx>
 #include <XSDRAWSTLVRML_ToVRML.ixx>
 
 #include <Standard_Stream.hxx>
-#include <BRepMesh_FastDiscret.hxx>
-#include <BRepMesh_Triangle.hxx>
-#include <BRepMesh_Edge.hxx>
 #include <Bnd_Box.hxx>
 #include <BRepBndLib.hxx>
 #include <Bnd_Box.hxx>
 #include <BRepBndLib.hxx>
+#include <BRep_Tool.hxx>
+#include <BRepTools.hxx>
+#include <BRepMesh_DiscretFactory.hxx>
+#include <Poly_Triangulation.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
+#include <TopoDS_Face.hxx>
 
 #include <gp_Pnt.hxx> //ied_modif_for_compil_Nov-20-1998
 
 
 #include <gp_Pnt.hxx> //ied_modif_for_compil_Nov-20-1998
 
@@ -63,7 +65,6 @@ Standard_Real&  XSDRAWSTLVRML_ToVRML::Deflection ()         {  return myDeflecti
 // function : ToVRML::Write
 // purpose  : conversion of a Shape into VRML format for 3d visualisation
 //=======================================================================
 // function : ToVRML::Write
 // purpose  : conversion of a Shape into VRML format for 3d visualisation
 //=======================================================================
-
 Standard_Boolean  XSDRAWSTLVRML_ToVRML::Write
   (const TopoDS_Shape& theShape, const Standard_CString theFileName) const
 {
 Standard_Boolean  XSDRAWSTLVRML_ToVRML::Write
   (const TopoDS_Shape& theShape, const Standard_CString theFileName) const
 {
@@ -82,116 +83,113 @@ Standard_Boolean  XSDRAWSTLVRML_ToVRML::Write
     //         shapetrigu: Boolean from Standard = Standard_False)
     //         returns mutable Discret from BRepMesh;
 
     //         shapetrigu: Boolean from Standard = Standard_False)
     //         returns mutable Discret from BRepMesh;
 
-    Bnd_Box aBox;
-    BRepBndLib::Add(theShape, aBox);
+    if ( !BRepTools::Triangulation (theShape, myDeflection) )
+    {
+      // retrieve meshing tool from Factory
+      BRepTools::Clean (theShape);
+      Handle(BRepMesh_DiscretRoot) aMeshAlgo =
+        BRepMesh_DiscretFactory::Get().Discret(theShape, myDeflection, 0.17);
 
 
-    Handle(BRepMesh_FastDiscret) aDiscret =
-      new BRepMesh_FastDiscret( theShape,
-                                myDeflection,
-                                0.17,
-                                aBox,
-                                Standard_True,
-                                Standard_False,
-                                Standard_True,
-                                Standard_True );
-
-      // Header of the VRML file
-      anOut << "#VRML V2.0 utf8" << endl;
-      anOut << "Group {" << endl;
-      anOut << "  children [ " << endl;
-      anOut << "    NavigationInfo {" << endl;
-      anOut << "      type \"EXAMINE\" " << endl;
-      anOut << "    }," << endl;
-      anOut << "    Shape {" << endl;
-
-      anOut << "      appearance Appearance {" << endl;
-      anOut << "        texture ImageTexture {" << endl;
-      anOut << "          url " << myTexture.ToCString() << endl;
-      anOut << "        }" << endl;
-      anOut << "        material Material {" << endl;
-      anOut << "          diffuseColor " << myDiffuseColorRed << " "
-                                         << myDiffuseColorGreen << " "
-                                         << myDiffuseColorBlue << " " << endl;
-      anOut << "          emissiveColor " << myEmissiveColorRed << " "
-                                          << myEmissiveColorGreen << " "
-                                          << myEmissiveColorBlue << " " << endl;
-      anOut << "          transparency " << myTransparency << endl;
-      anOut << "          ambientIntensity " << myAmbientIntensity << " " << endl;
-      anOut << "          specularColor " << mySpecularColorRed << " "
-                                          << mySpecularColorGreen << " "
-                                          << mySpecularColorBlue << " " << endl;
-      anOut << "          shininess " << myShininess << " " << endl;
-      anOut << "        }" << endl;
-      anOut << "      }" << endl;
-
-      anOut << "      geometry IndexedFaceSet {" << endl;
-      anOut << "        coord Coordinate {" << endl;
-      anOut << "          point [" << endl;
-
-      // Puts the coordinates of all the vertices using the order
-      // given during the discretisation
-      TopExp_Explorer aFaceIt(theShape, TopAbs_FACE);
-      for (; aFaceIt.More(); aFaceIt.Next())
+      if ( !aMeshAlgo.IsNull() )
       {
       {
-        Handle(BRepMesh_FaceAttribute) anAttribute;
-        const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current());
-        if (!aDiscret->GetFaceAttribute(aFace, anAttribute) || !anAttribute->IsValid())
-          continue;
-
-        Handle(BRepMesh_DataStructureOfDelaun)& aStructure =
-          anAttribute->ChangeStructure();
-
-        const Standard_Integer aNbVertices = aStructure->NbNodes();
-        for (Standard_Integer i = 1; i <= aNbVertices; ++i)
-        {
-          const BRepMesh_Vertex& aVertex = aStructure->GetNode(i);
-          const gp_Pnt&          aPoint  = anAttribute->GetPoint(aVertex);
-
-          anOut << "          "
-            << aPoint.Coord().X() << " "
-            << aPoint.Coord().Y() << " "
-            << aPoint.Coord().Z() << "," << endl;
-        }
+        aMeshAlgo->Perform();
       }
       }
+    }
 
 
-      anOut << "          ]" << endl;
-      anOut << "        }" << endl;
-      anOut << "        coordIndex [" << endl;
+    Bnd_Box aBox;
+    BRepBndLib::Add(theShape, aBox);
 
 
-      // Retrieves all the triangles in order to draw the facets
-      for (aFaceIt.Init(theShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
+    // Header of the VRML file
+    anOut << "#VRML V2.0 utf8" << endl;
+    anOut << "Group {" << endl;
+    anOut << "  children [ " << endl;
+    anOut << "    NavigationInfo {" << endl;
+    anOut << "      type \"EXAMINE\" " << endl;
+    anOut << "    }," << endl;
+    anOut << "    Shape {" << endl;
+
+    anOut << "      appearance Appearance {" << endl;
+    anOut << "        texture ImageTexture {" << endl;
+    anOut << "          url " << myTexture.ToCString() << endl;
+    anOut << "        }" << endl;
+    anOut << "        material Material {" << endl;
+    anOut << "          diffuseColor " << myDiffuseColorRed << " "
+                                       << myDiffuseColorGreen << " "
+                                       << myDiffuseColorBlue << " " << endl;
+    anOut << "          emissiveColor " << myEmissiveColorRed << " "
+                                        << myEmissiveColorGreen << " "
+                                        << myEmissiveColorBlue << " " << endl;
+    anOut << "          transparency " << myTransparency << endl;
+    anOut << "          ambientIntensity " << myAmbientIntensity << " " << endl;
+    anOut << "          specularColor " << mySpecularColorRed << " "
+                                        << mySpecularColorGreen << " "
+                                        << mySpecularColorBlue << " " << endl;
+    anOut << "          shininess " << myShininess << " " << endl;
+    anOut << "        }" << endl;
+    anOut << "      }" << endl;
+
+    anOut << "      geometry IndexedFaceSet {" << endl;
+    anOut << "        coord Coordinate {" << endl;
+    anOut << "          point [" << endl;
+
+    // Puts the coordinates of all the vertices using the order
+    // given during the discretisation
+    TopExp_Explorer aFaceIt(theShape, TopAbs_FACE);
+    for (; aFaceIt.More(); aFaceIt.Next())
+    {
+      const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current());
+
+      TopLoc_Location aLoc = aFace.Location();
+      Handle(Poly_Triangulation) aTriangulation =
+        BRep_Tool::Triangulation(aFace, aLoc);
+
+      const Standard_Integer   aLength = aTriangulation->NbNodes();
+      const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
+      for ( Standard_Integer i = 1; i <= aLength; ++i )
       {
       {
-        Handle(BRepMesh_FaceAttribute) anAttribute;
-        const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current());
+        const gp_Pnt& aPoint = aNodes(i);
 
 
-        if (!aDiscret->GetFaceAttribute(aFace, anAttribute) || !anAttribute->IsValid())
-          continue;
+        anOut << "          "
+              << aPoint.X() << " "
+              << aPoint.Y() << " "
+              << aPoint.Z() << "," << endl;
+      }
+    }
 
 
-        Handle(BRepMesh_DataStructureOfDelaun)& aStructure =
-          anAttribute->ChangeStructure();
+    anOut << "          ]" << endl;
+    anOut << "        }" << endl;
+    anOut << "        coordIndex [" << endl;
 
 
-        const Standard_Integer aNbTriangles = aStructure->NbElements();
-        for ( Standard_Integer i = 1; i <= aNbTriangles; ++i )
-        {
-          const BRepMesh_Triangle& aTriangle = aStructure->GetElement(i);
+    // Retrieves all the triangles in order to draw the facets
+    for (aFaceIt.Init(theShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
+    {
+      TopoDS_Face aFace = TopoDS::Face(aFaceIt.Current());
+      aFace.Orientation(TopAbs_FORWARD);
 
 
-          Standard_Integer v[3];
-          aStructure->ElementNodes(aTriangle, v);
+      TopLoc_Location aLoc = aFace.Location();
+      Handle(Poly_Triangulation) aTriangulation =
+        BRep_Tool::Triangulation(aFace, aLoc);
 
 
-          anOut << "          "
-                << v[0] - 1 << ", "
-                << v[1] - 1 << ", "
-                << v[2] - 1 << ", -1," << endl;
-        }
-      }
+      const Standard_Integer aNbTriangles = aTriangulation->NbTriangles();
+      const Poly_Array1OfTriangle& aTriangles = aTriangulation->Triangles();
+      for ( Standard_Integer i = 1, v[3]; i <= aNbTriangles; ++i )
+      {
+        aTriangles(i).Get(v[0], v[1], v[2]);
 
 
-      anOut << "        ]" << endl;
-      anOut << "        solid FALSE" << endl; // it is not a closed solid
-      anOut << "        creaseAngle " << myCreaseAngle << " " << endl; // for smooth shading
-      anOut << "      }" << endl;
-      anOut << "    }" << endl;
-      anOut << "  ]" << endl;
-      anOut << "}" << endl;
+        anOut << "          "
+              << v[0] - 1 << ", "
+              << v[1] - 1 << ", "
+              << v[2] - 1 << ", -1," << endl;
+      }
+    }
+
+    anOut << "        ]" << endl;
+    anOut << "        solid FALSE" << endl; // it is not a closed solid
+    anOut << "        creaseAngle " << myCreaseAngle << " " << endl; // for smooth shading
+    anOut << "      }" << endl;
+    anOut << "    }" << endl;
+    anOut << "  ]" << endl;
+    anOut << "}" << endl;
   }
   else
   {
   }
   else
   {