From: azn Date: Wed, 8 Oct 2014 10:57:22 +0000 (+0400) Subject: 0025310: Regressions in visualization X-Git-Tag: V6_8_0_beta~5 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=fcf15f5ca3112c96846624d3ed5edd49abd547bb 0025310: Regressions in visualization - Memory management in the BRepMesh_FastDiscret class is changed. Now the unused face attributes is immediately removed. --- diff --git a/src/BRepMesh/BRepMesh_FaceAttribute.cxx b/src/BRepMesh/BRepMesh_FaceAttribute.cxx index 9529ef2e65..6788fbfed9 100644 --- a/src/BRepMesh/BRepMesh_FaceAttribute.cxx +++ b/src/BRepMesh/BRepMesh_FaceAttribute.cxx @@ -70,12 +70,7 @@ BRepMesh_FaceAttribute::BRepMesh_FaceAttribute( //======================================================================= BRepMesh_FaceAttribute::~BRepMesh_FaceAttribute() { - clearLocal(); - - mySurfaceVertices.Clear(); - mySurfacePoints->Clear(); - - myClassifier.Nullify(); + Clear(); myAllocator.Nullify(); } @@ -103,18 +98,38 @@ void BRepMesh_FaceAttribute::init() } //======================================================================= -//function : clearLocal +//function : Clear //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(); - myInternalEdges->Clear(); - myAllocator->Reset(Standard_False); + if (!isClearSurfaceDataOnly) + { + myInternalEdges->Clear(); + } + + myStructure.Nullify(); + myAllocator->Reset(isClearSurfaceDataOnly); } //======================================================================= diff --git a/src/BRepMesh/BRepMesh_FaceAttribute.hxx b/src/BRepMesh/BRepMesh_FaceAttribute.hxx index 8c85ce65b7..d602dbf93e 100644 --- a/src/BRepMesh/BRepMesh_FaceAttribute.hxx +++ b/src/BRepMesh/BRepMesh_FaceAttribute.hxx @@ -189,6 +189,11 @@ public: //! @name main geometrical properties. 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(); @@ -330,7 +335,8 @@ private: 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. diff --git a/src/BRepMesh/BRepMesh_FastDiscret.cxx b/src/BRepMesh/BRepMesh_FastDiscret.cxx index b70f724ee8..2c8221bd15 100644 --- a/src/BRepMesh/BRepMesh_FastDiscret.cxx +++ b/src/BRepMesh/BRepMesh_FastDiscret.cxx @@ -194,7 +194,7 @@ void BRepMesh_FastDiscret::Process(const TopoDS_Face& theFace) const OCC_CATCH_SIGNALS BRepMesh_FastDiscretFace aTool(GetAngle(), WithShare()); - aTool.Add(anAttribute); + aTool.Perform(anAttribute); } catch (Standard_Failure) { @@ -224,9 +224,10 @@ Standard_Integer BRepMesh_FastDiscret::Add(const TopoDS_Face& theFace) myAttributes.Bind(theFace, myAttribute); } - myStructure = myAttribute->ResetStructure(); myVertexEdgeMap = myAttribute->ChangeVertexEdgeMap(); myInternalEdges = myAttribute->ChangeInternalEdges(); + Handle(BRepMesh_DataStructureOfDelaun)& aStructure = + myAttribute->ResetStructure(); 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 ) { - const BRepMesh_Vertex& aVertex = myStructure->GetNode(myVertexEdgeMap->FindKey(i1)); + const BRepMesh_Vertex& aVertex = aStructure->GetNode(myVertexEdgeMap->FindKey(i1)); ++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(), - myInternalEdges, myVertexEdgeMap, myStructure, + myInternalEdges, myVertexEdgeMap, aStructure, 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 - myStructure = myAttribute->ResetStructure(); + aStructure = myAttribute->ResetStructure(); 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) { + Handle(BRepMesh_DataStructureOfDelaun)& aStructure = + myAttribute->ChangeStructure(); + 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) - myStructure->AddLink(BRepMesh_Edge(theLastNodeId, theFirstNodeId, BRepMesh_Frontier)); + aStructure->AddLink(BRepMesh_Edge(theLastNodeId, theFirstNodeId, BRepMesh_Frontier)); else if (theOrientation == TopAbs_INTERNAL) - myStructure->AddLink(BRepMesh_Edge(theFirstNodeId, theLastNodeId, BRepMesh_Fixed)); + aStructure->AddLink(BRepMesh_Edge(theFirstNodeId, theLastNodeId, BRepMesh_Fixed)); } //======================================================================= diff --git a/src/BRepMesh/BRepMesh_FastDiscret.hxx b/src/BRepMesh/BRepMesh_FastDiscret.hxx index 7d303e138c..66382cec8a 100644 --- a/src/BRepMesh/BRepMesh_FastDiscret.hxx +++ b/src/BRepMesh/BRepMesh_FastDiscret.hxx @@ -364,7 +364,6 @@ private: // Fast access to attributes of current face Handle(BRepMesh_FaceAttribute) myAttribute; - Handle(BRepMesh_DataStructureOfDelaun) myStructure; BRepMesh::HIMapOfInteger myVertexEdgeMap; BRepMesh::HDMapOfShapePairOfPolygon myInternalEdges; TopTools_IndexedDataMapOfShapeListOfShape mySharedFaces; diff --git a/src/BRepMesh/BRepMesh_FastDiscretFace.cxx b/src/BRepMesh/BRepMesh_FastDiscretFace.cxx index caba67d0e6..28004d3246 100644 --- a/src/BRepMesh/BRepMesh_FastDiscretFace.cxx +++ b/src/BRepMesh/BRepMesh_FastDiscretFace.cxx @@ -142,15 +142,25 @@ namespace { //======================================================================= 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); } //======================================================================= -//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) @@ -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); -} \ 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); +} diff --git a/src/BRepMesh/BRepMesh_FastDiscretFace.hxx b/src/BRepMesh/BRepMesh_FastDiscretFace.hxx index 4871108ebf..3c286d55b0 100644 --- a/src/BRepMesh/BRepMesh_FastDiscretFace.hxx +++ b/src/BRepMesh/BRepMesh_FastDiscretFace.hxx @@ -55,6 +55,7 @@ public: 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) @@ -134,6 +135,9 @@ private: const gp_XY& theUV, BRepMesh::ListOfVertex& theVertices); + //! Stores mesh into the face (without internal edges). + void commitSurfaceTriangulation(); + private: Standard_Real myAngle; diff --git a/src/BRepMesh/BRepMesh_IncrementalMesh.cxx b/src/BRepMesh/BRepMesh_IncrementalMesh.cxx index 2cba2750c3..f7473da41a 100644 --- a/src/BRepMesh/BRepMesh_IncrementalMesh.cxx +++ b/src/BRepMesh/BRepMesh_IncrementalMesh.cxx @@ -481,16 +481,16 @@ void BRepMesh_IncrementalMesh::commit() { std::vector::iterator aFaceIt(myFaces.begin()); for (; aFaceIt != myFaces.end(); aFaceIt++) - commitFace(*aFaceIt); + commitEdges(*aFaceIt); discretizeFreeEdges(); } //======================================================================= -//function : commitFace +//function : commitEdges //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); @@ -499,8 +499,6 @@ void BRepMesh_IncrementalMesh::commitFace(const TopoDS_Face& theFace) if (!myMesh->GetFaceAttribute(aFace, aFaceAttribute)) return; - BRepMesh_ShapeTool::NullifyFace(aFace); - if (!aFaceAttribute->IsValid()) { myStatus |= aFaceAttribute->GetStatus(); @@ -508,60 +506,18 @@ void BRepMesh_IncrementalMesh::commitFace(const TopoDS_Face& theFace) } 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 - 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); @@ -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(); - BRepMesh_ShapeTool::NullifyEdge(aEdge, aOldTriangulation, aLoc); if (aPolygon1 == aPolygon2) - BRepMesh_ShapeTool::UpdateEdge(aEdge, aPolygon1, aNewTriangulation, aLoc); + BRepMesh_ShapeTool::UpdateEdge(aEdge, aPolygon1, aTriangulation, aLoc); else - BRepMesh_ShapeTool::UpdateEdge(aEdge, aPolygon1, aPolygon2, aNewTriangulation, aLoc); + BRepMesh_ShapeTool::UpdateEdge(aEdge, aPolygon1, aPolygon2, aTriangulation, aLoc); } + + aFaceAttribute->Clear(); } catch (Standard_Failure) { diff --git a/src/BRepMesh/BRepMesh_IncrementalMesh.hxx b/src/BRepMesh/BRepMesh_IncrementalMesh.hxx index b99d79d1b5..bc1bed4492 100644 --- a/src/BRepMesh/BRepMesh_IncrementalMesh.hxx +++ b/src/BRepMesh/BRepMesh_IncrementalMesh.hxx @@ -189,8 +189,8 @@ private: //! 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: diff --git a/src/MeshTest/MeshTest.cxx b/src/MeshTest/MeshTest.cxx index 9b92c29156..ad592699db 100644 --- a/src/MeshTest/MeshTest.cxx +++ b/src/MeshTest/MeshTest.cxx @@ -433,19 +433,22 @@ static Standard_Integer triangule(Draw_Interpretor& di, Standard_Integer nbarg, 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()); - 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)); } } diff --git a/src/MeshTest/MeshTest_DrawableMesh.cxx b/src/MeshTest/MeshTest_DrawableMesh.cxx index 68cd1914e8..c238141d3b 100644 --- a/src/MeshTest/MeshTest_DrawableMesh.cxx +++ b/src/MeshTest/MeshTest_DrawableMesh.cxx @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include #include @@ -31,6 +33,16 @@ IMPLEMENT_STANDARD_HANDLE (MeshTest_DrawableMesh, Draw_Drawable3D) IMPLEMENT_STANDARD_RTTIEXT(MeshTest_DrawableMesh, Draw_Drawable3D) +typedef NCollection_Map 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 : @@ -221,28 +233,40 @@ void MeshTest_DrawableMesh::Dump(Standard_OStream&) const //======================================================================= void MeshTest_DrawableMesh::Whatis(Draw_Interpretor& theStream) const { + const TopoDS_Shape& aShape = myMesher->Shape(); const Handle(BRepMesh_FastDiscret)& aMesh = myMesher->Mesh(); + 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()); - Handle(BRepMesh_FaceAttribute) aAtrribure; - if (!aMesh->GetFaceAttribute(aFace, aAtrribure) || !aAtrribure->IsValid()) + aTriangulation = BRep_Tool::Triangulation(aFace, aLocation); + if (aTriangulation.IsNull()) 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"; diff --git a/src/XSDRAWSTLVRML/XSDRAWSTLVRML_ToVRML.cxx b/src/XSDRAWSTLVRML/XSDRAWSTLVRML_ToVRML.cxx index 5aaa2f5a12..d721052054 100644 --- a/src/XSDRAWSTLVRML/XSDRAWSTLVRML_ToVRML.cxx +++ b/src/XSDRAWSTLVRML/XSDRAWSTLVRML_ToVRML.cxx @@ -14,13 +14,15 @@ #include #include -#include -#include -#include #include #include +#include +#include +#include +#include #include #include +#include #include //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 //======================================================================= - 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; - 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 {