1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-07 18:30:55 +03:00

0025310: Regressions in visualization

- Memory management in the BRepMesh_FastDiscret class is changed. Now the unused face attributes is immediately removed.
This commit is contained in:
azn 2014-10-08 14:57:22 +04:00 committed by bugmaster
parent 15534713ba
commit fcf15f5ca3
11 changed files with 282 additions and 196 deletions

View File

@ -70,12 +70,7 @@ BRepMesh_FaceAttribute::BRepMesh_FaceAttribute(
//======================================================================= //=======================================================================
BRepMesh_FaceAttribute::~BRepMesh_FaceAttribute() BRepMesh_FaceAttribute::~BRepMesh_FaceAttribute()
{ {
clearLocal(); Clear();
mySurfaceVertices.Clear();
mySurfacePoints->Clear();
myClassifier.Nullify();
myAllocator.Nullify(); myAllocator.Nullify();
} }
@ -102,19 +97,39 @@ void BRepMesh_FaceAttribute::init()
ResetStructure(); ResetStructure();
} }
//=======================================================================
//function : Clear
//purpose :
//=======================================================================
void BRepMesh_FaceAttribute::Clear(
const Standard_Boolean isClearSurfaceDataOnly)
{
clearLocal(isClearSurfaceDataOnly);
mySurfaceVertices.Clear();
mySurfacePoints->Clear();
mySurface.Nullify();
myClassifier.Nullify();
}
//======================================================================= //=======================================================================
//function : clearLocal //function : clearLocal
//purpose : //purpose :
//======================================================================= //=======================================================================
void BRepMesh_FaceAttribute::clearLocal() void BRepMesh_FaceAttribute::clearLocal(
const Standard_Boolean isClearSurfaceDataOnly)
{ {
myStructure.Nullify();
myLocation2D.Clear(); myLocation2D.Clear();
myVertexEdgeMap->Clear(); myVertexEdgeMap->Clear();
myInternalEdges->Clear();
myAllocator->Reset(Standard_False); if (!isClearSurfaceDataOnly)
{
myInternalEdges->Clear();
}
myStructure.Nullify();
myAllocator->Reset(isClearSurfaceDataOnly);
} }
//======================================================================= //=======================================================================

View 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. //! Resets mesh data structure.
//! @returns reset data structure. //! @returns reset data structure.
Standard_EXPORT Handle(BRepMesh_DataStructureOfDelaun)& ResetStructure(); Standard_EXPORT Handle(BRepMesh_DataStructureOfDelaun)& ResetStructure();
@ -330,7 +335,8 @@ private:
const Standard_Real theLastParam) const; const Standard_Real theLastParam) const;
//! Clears internal data structures local to face. //! 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. //! Returns index of the given vertex if it exists in cache.
//! @param theVertex vertex which index should be retrieved. //! @param theVertex vertex which index should be retrieved.

View File

@ -194,7 +194,7 @@ void BRepMesh_FastDiscret::Process(const TopoDS_Face& theFace) const
OCC_CATCH_SIGNALS OCC_CATCH_SIGNALS
BRepMesh_FastDiscretFace aTool(GetAngle(), WithShare()); 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(); myVertexEdgeMap = myAttribute->ChangeVertexEdgeMap();
myInternalEdges = myAttribute->ChangeInternalEdges(); 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; Standard_Integer i1 = 1;
for ( i1 = 1; i1 <= myVertexEdgeMap->Extent(); ++i1 ) 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::HClassifier& aClassifier = myAttribute->ChangeClassifier();
BRepMesh_WireChecker aDFaceChecker(aFace, Precision::PConfusion(), BRepMesh_WireChecker aDFaceChecker(aFace, Precision::PConfusion(),
myInternalEdges, myVertexEdgeMap, myStructure, myInternalEdges, myVertexEdgeMap, aStructure,
myumin, myumax, myvmin, myvmax, myInParallel ); myumin, myumax, myvmin, myvmax, myInParallel );
aDFaceChecker.ReCompute(aClassifier); aDFaceChecker.ReCompute(aClassifier);
@ -435,7 +436,7 @@ Standard_Integer BRepMesh_FastDiscret::Add(const TopoDS_Face& theFace)
++nbmaill; ++nbmaill;
// Clear the structure of links // 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 Standard_Integer theLastNodeId,
const TopAbs_Orientation theOrientation) 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));
} }
//======================================================================= //=======================================================================

View File

@ -364,7 +364,6 @@ private:
// Fast access to attributes of current face // Fast access to attributes of current face
Handle(BRepMesh_FaceAttribute) myAttribute; Handle(BRepMesh_FaceAttribute) myAttribute;
Handle(BRepMesh_DataStructureOfDelaun) myStructure;
BRepMesh::HIMapOfInteger myVertexEdgeMap; BRepMesh::HIMapOfInteger myVertexEdgeMap;
BRepMesh::HDMapOfShapePairOfPolygon myInternalEdges; BRepMesh::HDMapOfShapePairOfPolygon myInternalEdges;
TopTools_IndexedDataMapOfShapeListOfShape mySharedFaces; TopTools_IndexedDataMapOfShapeListOfShape mySharedFaces;

View File

@ -142,15 +142,25 @@ namespace {
//======================================================================= //=======================================================================
BRepMesh_FastDiscretFace::BRepMesh_FastDiscretFace BRepMesh_FastDiscretFace::BRepMesh_FastDiscretFace
(const Standard_Real theAngle, (const Standard_Real theAngle,
const Standard_Boolean theWithShare) : const Standard_Boolean theWithShare)
myAngle(theAngle), myWithShare(theWithShare), : myAngle(theAngle), myWithShare(theWithShare),
myInternalVerticesMode(Standard_True) myInternalVerticesMode(Standard_True)
{ {
myAllocator = new NCollection_IncAllocator(64000); 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 : //purpose :
//======================================================================= //=======================================================================
void BRepMesh_FastDiscretFace::Add(const Handle(BRepMesh_FaceAttribute)& theAttribute) void BRepMesh_FastDiscretFace::Add(const Handle(BRepMesh_FaceAttribute)& theAttribute)
@ -1210,3 +1220,69 @@ void BRepMesh_FastDiscretFace::insertVertex(
BRepMesh_Vertex aVertex(aPnt2d, aNbLocat, BRepMesh_Free); BRepMesh_Vertex aVertex(aPnt2d, aNbLocat, BRepMesh_Free);
theVertices.Append(aVertex); theVertices.Append(aVertex);
} }
//=======================================================================
//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);
}

View File

@ -55,6 +55,7 @@ public:
const Standard_Boolean theWithShare = Standard_True); const Standard_Boolean theWithShare = Standard_True);
Standard_EXPORT void Add(const Handle(BRepMesh_FaceAttribute)& theAttribute); 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, const gp_XY& theUV,
BRepMesh::ListOfVertex& theVertices); BRepMesh::ListOfVertex& theVertices);
//! Stores mesh into the face (without internal edges).
void commitSurfaceTriangulation();
private: private:
Standard_Real myAngle; Standard_Real myAngle;

View File

@ -481,16 +481,16 @@ void BRepMesh_IncrementalMesh::commit()
{ {
std::vector<TopoDS_Face>::iterator aFaceIt(myFaces.begin()); std::vector<TopoDS_Face>::iterator aFaceIt(myFaces.begin());
for (; aFaceIt != myFaces.end(); aFaceIt++) 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; TopoDS_Face aFace = theFace;
aFace.Orientation(TopAbs_FORWARD); aFace.Orientation(TopAbs_FORWARD);
@ -499,8 +499,6 @@ void BRepMesh_IncrementalMesh::commitFace(const TopoDS_Face& theFace)
if (!myMesh->GetFaceAttribute(aFace, aFaceAttribute)) if (!myMesh->GetFaceAttribute(aFace, aFaceAttribute))
return; return;
BRepMesh_ShapeTool::NullifyFace(aFace);
if (!aFaceAttribute->IsValid()) if (!aFaceAttribute->IsValid())
{ {
myStatus |= aFaceAttribute->GetStatus(); 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 try
{ {
OCC_CATCH_SIGNALS 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 // Store discretization of edges
BRepMesh::HDMapOfShapePairOfPolygon& aInternalEdges = aFaceAttribute->ChangeInternalEdges(); BRepMesh::HDMapOfShapePairOfPolygon& aInternalEdges = aFaceAttribute->ChangeInternalEdges();
BRepMesh::DMapOfShapePairOfPolygon::Iterator aEdgeIt(*aInternalEdges); 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)& aPolygon1 = aPolyPair.First();
const Handle(Poly_PolygonOnTriangulation)& aPolygon2 = aPolyPair.Last(); 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)
{ {

View File

@ -189,8 +189,8 @@ private:
//! Stores mesh to the shape. //! Stores mesh to the shape.
void commit(); void commit();
//! Stores mesh to the face. //! Stores mesh of internal edges to the face.
void commitFace(const TopoDS_Face& theFace); void commitEdges(const TopoDS_Face& theFace);
protected: protected:

View 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); TopExp_Explorer aFaceIt(aShape, TopAbs_FACE);
for (; aFaceIt.More(); aFaceIt.Next()) for (; aFaceIt.More(); aFaceIt.Next())
{ {
const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current()); const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current());
Handle(BRepMesh_FaceAttribute) anAttribute; TopLoc_Location aLoc = aFace.Location();
if (aFastDiscret->GetFaceAttribute(aFace, anAttribute) && anAttribute->IsValid()) Handle(Poly_Triangulation) aTriangulation =
BRep_Tool::Triangulation(aFace, aLoc);
if (!aTriangulation.IsNull())
{ {
const Standard_Integer aNbPnts = anAttribute->LastPointId(); const Standard_Integer aLength = aTriangulation->NbNodes();
for (Standard_Integer i = 1; i < aNbPnts; ++i) const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
aBox.Add(anAttribute->GetPoint(i)); for (Standard_Integer i = 1; i <= aLength; ++i)
aBox.Add(aNodes(i));
} }
} }

View File

@ -20,6 +20,8 @@
#include <Draw_ColorKind.hxx> #include <Draw_ColorKind.hxx>
#include <Draw_Color.hxx> #include <Draw_Color.hxx>
#include <TColStd_ListIteratorOfListOfInteger.hxx> #include <TColStd_ListIteratorOfListOfInteger.hxx>
#include <TColStd_Array1OfInteger.hxx>
#include <Poly_Triangulation.hxx>
#include <Standard_RangeError.hxx> #include <Standard_RangeError.hxx>
#include <BRepMesh_DegreeOfFreedom.hxx> #include <BRepMesh_DegreeOfFreedom.hxx>
#include <BRepMesh_Edge.hxx> #include <BRepMesh_Edge.hxx>
@ -31,6 +33,16 @@
IMPLEMENT_STANDARD_HANDLE (MeshTest_DrawableMesh, Draw_Drawable3D) IMPLEMENT_STANDARD_HANDLE (MeshTest_DrawableMesh, Draw_Drawable3D)
IMPLEMENT_STANDARD_RTTIEXT(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 //function : MeshTest_DrawableMesh
//purpose : //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 aPointsNb = aMesh->NbBoundaryPoints();
Standard_Integer aTrianglesNb = 0; Standard_Integer aTrianglesNb = 0;
Standard_Integer aEdgesNb = 0; Standard_Integer aEdgesNb = 0;
const TopoDS_Shape& aShape = myMesher->Shape(); TopLoc_Location aLocation;
Handle(Poly_Triangulation) aTriangulation;
TopExp_Explorer aFaceIt(aShape, TopAbs_FACE); TopExp_Explorer aFaceIt(aShape, TopAbs_FACE);
for (; aFaceIt.More(); aFaceIt.Next()) for (; aFaceIt.More(); aFaceIt.Next())
{ {
const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current()); const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current());
Handle(BRepMesh_FaceAttribute) aAtrribure; aTriangulation = BRep_Tool::Triangulation(aFace, aLocation);
if (!aMesh->GetFaceAttribute(aFace, aAtrribure) || !aAtrribure->IsValid()) if (aTriangulation.IsNull())
continue; continue;
aPointsNb += aAtrribure->ChangeSurfacePoints()->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]);
Handle(BRepMesh_DataStructureOfDelaun)& aStructure = addLink(v[0], v[1], aMap);
aAtrribure->ChangeStructure(); addLink(v[1], v[2], aMap);
addLink(v[2], v[0], aMap);
}
aTrianglesNb += aStructure->ElementsOfDomain().Extent(); aPointsNb += aTriangulation->NbNodes();
aEdgesNb += aStructure->LinksOfDomain().Extent(); aTrianglesNb += aTriangulation->NbTriangles();
aEdgesNb += aMap.Extent();
} }
theStream << " 3d mesh\n"; theStream << " 3d mesh\n";

View File

@ -14,13 +14,15 @@
#include <XSDRAWSTLVRML_ToVRML.ixx> #include <XSDRAWSTLVRML_ToVRML.ixx>
#include <Standard_Stream.hxx> #include <Standard_Stream.hxx>
#include <BRepMesh_FastDiscret.hxx>
#include <BRepMesh_Triangle.hxx>
#include <BRepMesh_Edge.hxx>
#include <Bnd_Box.hxx> #include <Bnd_Box.hxx>
#include <BRepBndLib.hxx> #include <BRepBndLib.hxx>
#include <BRep_Tool.hxx>
#include <BRepTools.hxx>
#include <BRepMesh_DiscretFactory.hxx>
#include <Poly_Triangulation.hxx>
#include <TopExp_Explorer.hxx> #include <TopExp_Explorer.hxx>
#include <TopoDS.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 // function : ToVRML::Write
// purpose : conversion of a Shape into VRML format for 3d visualisation // purpose : conversion of a Shape into VRML format for 3d visualisation
//======================================================================= //=======================================================================
Standard_Boolean XSDRAWSTLVRML_ToVRML::Write Standard_Boolean XSDRAWSTLVRML_ToVRML::Write
(const TopoDS_Shape& theShape, const Standard_CString theFileName) const (const TopoDS_Shape& theShape, const Standard_CString theFileName) const
{ {
@ -82,116 +83,113 @@ Standard_Boolean XSDRAWSTLVRML_ToVRML::Write
// shapetrigu: Boolean from Standard = Standard_False) // shapetrigu: Boolean from Standard = Standard_False)
// returns mutable Discret from BRepMesh; // returns mutable Discret from BRepMesh;
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);
if ( !aMeshAlgo.IsNull() )
{
aMeshAlgo->Perform();
}
}
Bnd_Box aBox; Bnd_Box aBox;
BRepBndLib::Add(theShape, aBox); BRepBndLib::Add(theShape, aBox);
Handle(BRepMesh_FastDiscret) aDiscret = // Header of the VRML file
new BRepMesh_FastDiscret( theShape, anOut << "#VRML V2.0 utf8" << endl;
myDeflection, anOut << "Group {" << endl;
0.17, anOut << " children [ " << endl;
aBox, anOut << " NavigationInfo {" << endl;
Standard_True, anOut << " type \"EXAMINE\" " << endl;
Standard_False, anOut << " }," << endl;
Standard_True, anOut << " Shape {" << endl;
Standard_True );
// Header of the VRML file anOut << " appearance Appearance {" << endl;
anOut << "#VRML V2.0 utf8" << endl; anOut << " texture ImageTexture {" << endl;
anOut << "Group {" << endl; anOut << " url " << myTexture.ToCString() << endl;
anOut << " children [ " << endl; anOut << " }" << endl;
anOut << " NavigationInfo {" << endl; anOut << " material Material {" << endl;
anOut << " type \"EXAMINE\" " << endl; anOut << " diffuseColor " << myDiffuseColorRed << " "
anOut << " }," << endl; << myDiffuseColorGreen << " "
anOut << " Shape {" << endl; << 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 << " appearance Appearance {" << endl; anOut << " geometry IndexedFaceSet {" << endl;
anOut << " texture ImageTexture {" << endl; anOut << " coord Coordinate {" << endl;
anOut << " url " << myTexture.ToCString() << endl; anOut << " point [" << 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; // Puts the coordinates of all the vertices using the order
anOut << " coord Coordinate {" << endl; // given during the discretisation
anOut << " point [" << endl; TopExp_Explorer aFaceIt(theShape, TopAbs_FACE);
for (; aFaceIt.More(); aFaceIt.Next())
{
const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current());
// Puts the coordinates of all the vertices using the order TopLoc_Location aLoc = aFace.Location();
// given during the discretisation Handle(Poly_Triangulation) aTriangulation =
TopExp_Explorer aFaceIt(theShape, TopAbs_FACE); BRep_Tool::Triangulation(aFace, aLoc);
for (; aFaceIt.More(); aFaceIt.Next())
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 gp_Pnt& aPoint = aNodes(i);
const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current());
if (!aDiscret->GetFaceAttribute(aFace, anAttribute) || !anAttribute->IsValid())
continue;
Handle(BRepMesh_DataStructureOfDelaun)& aStructure = anOut << " "
anAttribute->ChangeStructure(); << aPoint.X() << " "
<< aPoint.Y() << " "
const Standard_Integer aNbVertices = aStructure->NbNodes(); << aPoint.Z() << "," << endl;
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;
}
} }
}
anOut << " ]" << endl; anOut << " ]" << endl;
anOut << " }" << endl; anOut << " }" << endl;
anOut << " coordIndex [" << endl; anOut << " coordIndex [" << endl;
// Retrieves all the triangles in order to draw the facets // Retrieves all the triangles in order to draw the facets
for (aFaceIt.Init(theShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next()) for (aFaceIt.Init(theShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
{
TopoDS_Face aFace = TopoDS::Face(aFaceIt.Current());
aFace.Orientation(TopAbs_FORWARD);
TopLoc_Location aLoc = aFace.Location();
Handle(Poly_Triangulation) aTriangulation =
BRep_Tool::Triangulation(aFace, aLoc);
const Standard_Integer aNbTriangles = aTriangulation->NbTriangles();
const Poly_Array1OfTriangle& aTriangles = aTriangulation->Triangles();
for ( Standard_Integer i = 1, v[3]; i <= aNbTriangles; ++i )
{ {
Handle(BRepMesh_FaceAttribute) anAttribute; aTriangles(i).Get(v[0], v[1], v[2]);
const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current());
if (!aDiscret->GetFaceAttribute(aFace, anAttribute) || !anAttribute->IsValid()) anOut << " "
continue; << v[0] - 1 << ", "
<< v[1] - 1 << ", "
Handle(BRepMesh_DataStructureOfDelaun)& aStructure = << v[2] - 1 << ", -1," << endl;
anAttribute->ChangeStructure();
const Standard_Integer aNbTriangles = aStructure->NbElements();
for ( Standard_Integer i = 1; i <= aNbTriangles; ++i )
{
const BRepMesh_Triangle& aTriangle = aStructure->GetElement(i);
Standard_Integer v[3];
aStructure->ElementNodes(aTriangle, v);
anOut << " "
<< v[0] - 1 << ", "
<< v[1] - 1 << ", "
<< v[2] - 1 << ", -1," << endl;
}
} }
}
anOut << " ]" << endl; anOut << " ]" << endl;
anOut << " solid FALSE" << endl; // it is not a closed solid anOut << " solid FALSE" << endl; // it is not a closed solid
anOut << " creaseAngle " << myCreaseAngle << " " << endl; // for smooth shading anOut << " creaseAngle " << myCreaseAngle << " " << endl; // for smooth shading
anOut << " }" << endl; anOut << " }" << endl;
anOut << " }" << endl; anOut << " }" << endl;
anOut << " ]" << endl; anOut << " ]" << endl;
anOut << "}" << endl; anOut << "}" << endl;
} }
else else
{ {