- Memory management in the BRepMesh_FastDiscret class is changed. Now the unused face attributes is immediately removed.
//=======================================================================
BRepMesh_FaceAttribute::~BRepMesh_FaceAttribute()
{
- clearLocal();
-
- mySurfaceVertices.Clear();
- mySurfacePoints->Clear();
-
- myClassifier.Nullify();
+ Clear();
myAllocator.Nullify();
}
}
//=======================================================================
-//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);
}
//=======================================================================
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();
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.
OCC_CATCH_SIGNALS
BRepMesh_FastDiscretFace aTool(GetAngle(), WithShare());
- aTool.Add(anAttribute);
+ aTool.Perform(anAttribute);
}
catch (Standard_Failure)
{
myAttributes.Bind(theFace, myAttribute);
}
- myStructure = myAttribute->ResetStructure();
myVertexEdgeMap = myAttribute->ChangeVertexEdgeMap();
myInternalEdges = myAttribute->ChangeInternalEdges();
+ Handle(BRepMesh_DataStructureOfDelaun)& aStructure =
+ myAttribute->ResetStructure();
if (!myWithShare)
{
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;
{
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);
++nbmaill;
// Clear the structure of links
- myStructure = myAttribute->ResetStructure();
+ aStructure = myAttribute->ResetStructure();
for (Standard_Integer j = 1; j <= aFaceEdges.Length(); ++j)
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));
}
//=======================================================================
// 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_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)
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);
+}
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)
const gp_XY& theUV,
BRepMesh::ListOfVertex& theVertices);
+ //! Stores mesh into the face (without internal edges).
+ void commitSurfaceTriangulation();
+
private:
Standard_Real myAngle;
{
std::vector<TopoDS_Face>::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);
if (!myMesh->GetFaceAttribute(aFace, aFaceAttribute))
return;
- BRepMesh_ShapeTool::NullifyFace(aFace);
-
if (!aFaceAttribute->IsValid())
{
myStatus |= aFaceAttribute->GetStatus();
}
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);
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)
{
//! 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:
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));
}
}
#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>
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 :
//=======================================================================
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";
#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
// 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
{
// 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
{