mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +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:
@@ -14,13 +14,15 @@
|
||||
#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 <BRep_Tool.hxx>
|
||||
#include <BRepTools.hxx>
|
||||
#include <BRepMesh_DiscretFactory.hxx>
|
||||
#include <Poly_Triangulation.hxx>
|
||||
#include <TopExp_Explorer.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <TopoDS_Face.hxx>
|
||||
|
||||
#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
|
||||
//=======================================================================
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
BRepBndLib::Add(theShape, aBox);
|
||||
|
||||
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;
|
||||
|
||||
// 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 << " 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;
|
||||
|
||||
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());
|
||||
|
||||
// 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())
|
||||
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());
|
||||
if (!aDiscret->GetFaceAttribute(aFace, anAttribute) || !anAttribute->IsValid())
|
||||
continue;
|
||||
const gp_Pnt& aPoint = aNodes(i);
|
||||
|
||||
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;
|
||||
}
|
||||
anOut << " "
|
||||
<< aPoint.X() << " "
|
||||
<< aPoint.Y() << " "
|
||||
<< aPoint.Z() << "," << endl;
|
||||
}
|
||||
}
|
||||
|
||||
anOut << " ]" << endl;
|
||||
anOut << " }" << endl;
|
||||
anOut << " coordIndex [" << endl;
|
||||
anOut << " ]" << endl;
|
||||
anOut << " }" << endl;
|
||||
anOut << " coordIndex [" << endl;
|
||||
|
||||
// Retrieves all the triangles in order to draw the facets
|
||||
for (aFaceIt.Init(theShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
|
||||
// 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);
|
||||
|
||||
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;
|
||||
const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current());
|
||||
aTriangles(i).Get(v[0], v[1], v[2]);
|
||||
|
||||
if (!aDiscret->GetFaceAttribute(aFace, anAttribute) || !anAttribute->IsValid())
|
||||
continue;
|
||||
|
||||
Handle(BRepMesh_DataStructureOfDelaun)& aStructure =
|
||||
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 << " "
|
||||
<< 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;
|
||||
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
|
||||
{
|
||||
|
Reference in New Issue
Block a user