1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

Integration of OCCT 6.5.0 from SVN

This commit is contained in:
bugmaster
2011-03-16 07:30:28 +00:00
committed by bugmaster
parent 4903637061
commit 7fd59977df
16375 changed files with 3882564 additions and 0 deletions

3
src/MeshTest/FILES Executable file
View File

@@ -0,0 +1,3 @@
MeshTest_PluginCommands.cxx
MeshTest_CheckTopology.cxx
MeshTest_CheckTopology.hxx

31
src/MeshTest/MeshTest.cdl Executable file
View File

@@ -0,0 +1,31 @@
-- File: MeshTest.cdl
-- Created: Wed Aug 3 16:41:21 1994
-- Author: Modeling
-- <modeling@bravox>
---Copyright: Matra Datavision 1994
package MeshTest
---Purpose: Provides methods for testing the mesh algorithms.
uses
TColStd,
Draw,
TopoDS,
BRepMesh
is
class DrawableMesh;
---Purpose: Provides a mesh object inherited from Drawable3d
-- to draw a triangulation.
Commands(DI : in out Interpretor from Draw);
---Purpose: Defines meshing commands
PluginCommands(DI : in out Interpretor from Draw);
---Purpose: Defines plugin commands
end MeshTest;

1499
src/MeshTest/MeshTest.cxx Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,193 @@
// File: MeshTest_CheckTopology.cxx
// Created: 5.10.2004
// Author: Michael SAZONOV
#include <MeshTest_CheckTopology.hxx>
#include <BRep_Tool.hxx>
#include <TColStd_MapOfInteger.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Face.hxx>
#include <TopLoc_Location.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <Poly_Triangulation.hxx>
#include <Poly_PolygonOnTriangulation.hxx>
#include <Poly_Connect.hxx>
//=======================================================================
//function : Perform
//purpose : Performs checking
//=======================================================================
void MeshTest_CheckTopology::Perform ()
{
TopTools_IndexedMapOfShape aMapF;
TopTools_IndexedDataMapOfShapeListOfShape aMapEF;
TopExp::MapShapes (myShape, TopAbs_FACE, aMapF);
TopExp::MapShapesAndAncestors (myShape, TopAbs_EDGE, TopAbs_FACE, aMapEF);
// check polygons
Standard_Integer ie;
for (ie=1; ie <= aMapEF.Extent(); ie++) {
const TopoDS_Edge& aEdge = TopoDS::Edge(aMapEF.FindKey(ie));
const TopTools_ListOfShape& aFaces = aMapEF(ie);
if (aFaces.Extent() < 2) continue;
// get polygon on first face
const TopoDS_Face& aFace1 = TopoDS::Face(aFaces.First());
TopLoc_Location aLoc1;
Handle(Poly_Triangulation) aT1 = BRep_Tool::Triangulation(aFace1, aLoc1);
Handle(Poly_PolygonOnTriangulation) aPoly1 =
BRep_Tool::PolygonOnTriangulation(aEdge, aT1, aLoc1);
if (aPoly1.IsNull() || aT1.IsNull()) {
#ifdef DEB
cout<<"problem getting PolygonOnTriangulation of edge "<<ie<<endl;
#endif
continue;
}
const TColStd_Array1OfInteger& aNodes1 = aPoly1->Nodes();
// cycle on other polygons
TopTools_ListIteratorOfListOfShape it(aFaces);
it.Next();
for (; it.More(); it.Next()) {
const TopoDS_Face& aFace2 = TopoDS::Face(it.Value());
TopLoc_Location aLoc2;
Handle(Poly_Triangulation) aT2 = BRep_Tool::Triangulation(aFace2, aLoc2);
Handle(Poly_PolygonOnTriangulation) aPoly2 =
BRep_Tool::PolygonOnTriangulation(aEdge, aT2, aLoc2);
if (aPoly2.IsNull() || aT2.IsNull()) {
#ifdef DEB
cout<<"problem getting PolygonOnTriangulation of edge "<<ie<<endl;
#endif
continue;
}
const TColStd_Array1OfInteger& aNodes2 = aPoly2->Nodes();
// check equality of polygons lengths
if (aNodes2.Length() != aNodes1.Length()) {
myAsyncEdges.Append(ie);
break;
}
// check distances between corresponding points
Standard_Real aDefle = Max(aT1->Deflection(), aT2->Deflection());
const TColgp_Array1OfPnt& aPoints1 = aT1->Nodes();
const TColgp_Array1OfPnt& aPoints2 = aT2->Nodes();
Standard_Integer iF1 = aMapF.FindIndex(aFace1);
Standard_Integer iF2 = aMapF.FindIndex(aFace2);
Standard_Integer i1 = aNodes1.Lower();
Standard_Integer i2 = aNodes2.Lower();
gp_Trsf aTrsf1 = aFace1.Location().Transformation();
gp_Trsf aTrsf2 = aFace2.Location().Transformation();
for (; i1 <= aNodes1.Upper(); i1++, i2++) {
gp_Pnt aP1 = aPoints1(aNodes1(i1)).Transformed(aTrsf1);
gp_Pnt aP2 = aPoints2(aNodes2(i2)).Transformed(aTrsf2);
Standard_Real aDist = aP1.Distance(aP2);
if (aDist > aDefle) {
myErrors.Append(iF1);
myErrors.Append(i1);
myErrors.Append(iF2);
myErrors.Append(i2);
myErrorsVal.Append(aDist);
}
}
}
}
// check triangulations
Standard_Integer iF;
for (iF=1; iF <= aMapF.Extent(); iF++) {
const TopoDS_Face& aFace = TopoDS::Face(aMapF.FindKey(iF));
TopLoc_Location aLoc;
Handle(Poly_Triangulation) aT = BRep_Tool::Triangulation(aFace, aLoc);
if (aT.IsNull()) {
#ifdef DEB
cout<<"no Triangulation of face "<<iF<<endl;
#endif
continue;
}
// remember boundary nodes
TColStd_MapOfInteger aMapBndNodes;
TopExp_Explorer ex(aFace, TopAbs_EDGE);
for (; ex.More(); ex.Next()) {
const TopoDS_Edge& aEdge = TopoDS::Edge(ex.Current());
Handle(Poly_PolygonOnTriangulation) aPoly =
BRep_Tool::PolygonOnTriangulation(aEdge, aT, aLoc);
if (aPoly.IsNull()) continue;
const TColStd_Array1OfInteger& aNodes = aPoly->Nodes();
Standard_Integer i;
for (i=aNodes.Lower(); i <= aNodes.Upper(); i++)
aMapBndNodes.Add(aNodes(i));
}
Poly_Connect aConn(aT);
const Poly_Array1OfTriangle& aTriangles = aT->Triangles();
Standard_Integer nbTri = aT->NbTriangles(), i, j, n[3], t[3];
for (i = 1; i <= nbTri; i++) {
aTriangles(i).Get(n[0], n[1], n[2]);
aConn.Triangles(i, t[0], t[1], t[2]);
for (j = 0; j < 3; j++) {
if (t[j] == 0) {
// free link found
Standard_Integer k = (j+1) % 3; // the following node of the edge
Standard_Integer n1 = n[j];
Standard_Integer n2 = n[k];
// skip if it is on boundary
if (aMapBndNodes.Contains(n1) && aMapBndNodes.Contains(n2))
continue;
if (!myMapFaceLinks.Contains(iF)) {
//myMapFaceLinks.Add(iF, TColStd_SequenceOfInteger());
TColStd_SequenceOfInteger tmpSeq;
myMapFaceLinks.Add(iF, tmpSeq);
}
TColStd_SequenceOfInteger& aSeq = myMapFaceLinks.ChangeFromKey(iF);
aSeq.Append(n1);
aSeq.Append(n2);
}
}
}
}
}
//=======================================================================
//function : GetFreeLink
//purpose : gets the numbers of nodes of a free link with the given index
// in the face with the given index
//=======================================================================
void MeshTest_CheckTopology::GetFreeLink(const Standard_Integer theFaceIndex,
const Standard_Integer theLinkIndex,
Standard_Integer& theNode1,
Standard_Integer& theNode2) const
{
const TColStd_SequenceOfInteger& aSeq = myMapFaceLinks(theFaceIndex);
Standard_Integer aInd = (theLinkIndex-1)*2 + 1;
theNode1 = aSeq(aInd);
theNode2 = aSeq(aInd+1);
}
//=======================================================================
//function : GetCrossFaceError
//purpose : gets the attributes of a cross face error with the given index
//=======================================================================
void MeshTest_CheckTopology::GetCrossFaceError(const Standard_Integer theIndex,
Standard_Integer& theFace1,
Standard_Integer& theNode1,
Standard_Integer& theFace2,
Standard_Integer& theNode2,
Standard_Real& theValue) const
{
Standard_Integer aInd = (theIndex-1)*4 + 1;
theFace1 = myErrors(aInd);
theNode1 = myErrors(aInd+1);
theFace2 = myErrors(aInd+2);
theNode2 = myErrors(aInd+3);
theValue = myErrorsVal(theIndex);
}

View File

@@ -0,0 +1,87 @@
// File: MeshTest_CheckTopology.hxx
// Created: 5.10.2004
// Author: Michael SAZONOV
// Copyright: Open CASCADE 2004
#ifndef MeshTest_CheckTopology_HeaderFile
#define MeshTest_CheckTopology_HeaderFile
#include <TopoDS_Shape.hxx>
#include <NCollection_IndexedDataMap.hxx>
#include <TColStd_SequenceOfInteger.hxx>
#include <TColStd_SequenceOfReal.hxx>
// This class checks topology of the mesh presented by
// triangulations of faces.
//
// The following error are reported:
// - free links. A link is considered free if it has only one
// neighboring triangle and at least one of its nodes belongs to
// interior of the face rather than to its boundary.
// - cross face errors. It is a situation when a point on a common
// boundary between two faces has different 3d coordinates on each
// triangulation. The error is reported if the distance is greater
// than a deflection written in triangulations.
// - asynchronous edges. It is an edge having polygons on two neighboring
// triangulations with different number of points in the polygons
class MeshTest_CheckTopology
{
public:
MeshTest_CheckTopology(const TopoDS_Shape& theShape)
: myShape(theShape) {}
// constructor
Standard_EXPORT void Perform();
// performs checking
Standard_Integer NbFacesWithFL() const
{ return myMapFaceLinks.Extent(); }
// returns the number of faces with free links
Standard_Integer GetFaceNumWithFL(const Standard_Integer theIndex) const
{ return myMapFaceLinks.FindKey(theIndex); }
// returns the number (in the shape) of a face with free links
// with the given index
Standard_Integer NbFreeLinks(const Standard_Integer theIndex) const
{ return myMapFaceLinks(theIndex).Length() / 2; }
// returns the number free links on a face with the given index
Standard_EXPORT void GetFreeLink(const Standard_Integer theFaceIndex,
const Standard_Integer theLinkIndex,
Standard_Integer& theNode1,
Standard_Integer& theNode2) const;
// gets the numbers of nodes of a free link with the given index
// in the face with the given index
Standard_Integer NbCrossFaceErrors() const
{ return myErrorsVal.Length(); }
// returns the number of cross face errors
Standard_EXPORT void GetCrossFaceError(const Standard_Integer theIndex,
Standard_Integer& theFace1,
Standard_Integer& theNode1,
Standard_Integer& theFace2,
Standard_Integer& theNode2,
Standard_Real& theValue) const;
// gets the attributes of a cross face error with the given index
Standard_Integer NbAsyncEdges() const
{ return myAsyncEdges.Length(); }
// returns the number of async edges
Standard_Integer GetAsyncEdgeNum(const Standard_Integer theIndex) const
{ return myAsyncEdges(theIndex); }
// returns the number (in the shape) of an async edge with the given index
private:
TopoDS_Shape myShape;
NCollection_IndexedDataMap<Standard_Integer,TColStd_SequenceOfInteger>
myMapFaceLinks;
TColStd_SequenceOfInteger myErrors;
TColStd_SequenceOfReal myErrorsVal;
TColStd_SequenceOfInteger myAsyncEdges;
};
#endif

View File

@@ -0,0 +1,74 @@
-- File: MeshTest_DrawableMesh.cdl
-- Created: Wed Aug 3 18:19:44 1994
-- Author: Modeling
-- <modeling@bravox>
---Copyright: Matra Datavision 1994
class DrawableMesh from MeshTest inherits Drawable3D from Draw
---Purpose: A drawable mesh. It contains a sequence of
-- highlighted edges and highlighted vertices.
uses
Display from Draw,
Interpretor from Draw,
Shape from TopoDS,
FastDiscret from BRepMesh,
SequenceOfInteger from TColStd
is
Create returns mutable DrawableMesh from MeshTest;
Create(S : Shape from TopoDS; Deflect : Real;
Partage : Boolean; InShape: Boolean from Standard= Standard_False)
returns mutable DrawableMesh from MeshTest;
Create(Tr: FastDiscret from BRepMesh)
returns mutable DrawableMesh from MeshTest;
AddInShape(me: mutable; inshape: Boolean)
is static;
Add(me : mutable; S : Shape from TopoDS)
is static;
Edges(me : mutable) returns SequenceOfInteger from TColStd
---C++: return &
is static;
Vertices(me : mutable) returns SequenceOfInteger from TColStd
---C++: return &
is static;
Triangles(me : mutable) returns SequenceOfInteger from TColStd
---C++: return &
is static;
DrawOn(me; dis : in out Display from Draw);
Copy(me) returns mutable Drawable3D from Draw
is redefined;
Dump(me; S : in out OStream)
is redefined;
Whatis(me; S : in out Interpretor from Draw)
is redefined;
Mesh(me) returns mutable FastDiscret from BRepMesh
is static;
fields
myMesh : FastDiscret from BRepMesh;
myDeflection : Real;
myEdges : SequenceOfInteger from TColStd;
myVertices : SequenceOfInteger from TColStd;
myTriangles : SequenceOfInteger from TColStd;
myinshape : Boolean from Standard;
end DrawableMesh;

View File

@@ -0,0 +1,307 @@
// File: MeshTest_DrawableMesh.cxx
// Created: Wed Aug 3 18:30:07 1994
// Author: Modeling
// <modeling@bravox>
#include <MeshTest_DrawableMesh.ixx>
#include <TopoDS.hxx>
#include <Draw.hxx>
#include <Draw_ColorKind.hxx>
#include <Draw_Color.hxx>
#include <TColStd_ListIteratorOfListOfInteger.hxx>
#include <Standard_RangeError.hxx>
#include <MeshDS_DegreeOfFreedom.hxx>
#include <BRepMesh_Edge.hxx>
#include <BRepMesh_Vertex.hxx>
#include <BRepMesh_Triangle.hxx>
#include <BRepMesh_DataStructureOfDelaun.hxx>
#include <Bnd_Box.hxx>
#include <BRepBndLib.hxx>
//=======================================================================
//function : MeshTest_DrawableMesh
//purpose :
//=======================================================================
MeshTest_DrawableMesh::MeshTest_DrawableMesh() :
myDeflection(1.), myinshape(Standard_False)
{
}
//=======================================================================
//function : MeshTest_DrawableMesh
//purpose :
//=======================================================================
MeshTest_DrawableMesh::MeshTest_DrawableMesh(const TopoDS_Shape& S,
const Standard_Real Deflect,
const Standard_Boolean Partage,
const Standard_Boolean inshape) :
myDeflection(Deflect), myinshape(inshape)
{
Bnd_Box B;
BRepBndLib::Add(S, B);
myMesh = new BRepMesh_FastDiscret(Deflect, S, B, 0.5, Partage, inshape);
}
//=======================================================================
//function : MeshTest_DrawableMesh
//purpose :
//=======================================================================
MeshTest_DrawableMesh::MeshTest_DrawableMesh(const Handle(BRepMesh_FastDiscret)& Tr):
myDeflection(1.0)
{
myMesh = Tr;
}
//=======================================================================
//function : MeshTest_DrawableMesh
//purpose :
//=======================================================================
void MeshTest_DrawableMesh::Add(const TopoDS_Shape& S)
{
Bnd_Box B;
BRepBndLib::Add(S, B);
if (myMesh.IsNull())
myMesh=new BRepMesh_FastDiscret(myDeflection, S, B, 0.5, myinshape);
else
myMesh->Perform(S);
}
//=======================================================================
//function : AddInShape
//purpose :
//=======================================================================
void MeshTest_DrawableMesh::AddInShape(const Standard_Boolean inshape)
{
myinshape = inshape;
}
//=======================================================================
//function : DrawOn
//purpose :
//=======================================================================
void MeshTest_DrawableMesh::DrawOn(Draw_Display& D) const
{
// should be reimplemented!!
/* Handle(BRepMesh_DataStructureOfDelaun) struc = myMesh->Result();
Standard_Integer nbc;
D.SetColor(Draw_vert);
for (Standard_Integer iLi=1; iLi<=myMesh->NbEdges(); iLi++) {
const BRepMesh_Edge& ed=myMesh->Edge(iLi);
if (ed.Movability()!=MeshDS_Deleted) {
nbc=struc->ElemConnectedTo(iLi).Extent();
if (nbc<=0) D.SetColor(Draw_bleu);
else if (nbc==1) D.SetColor(Draw_jaune);
else if (nbc==2) D.SetColor(Draw_vert);
else D.SetColor(Draw_corail);
D.MoveTo(myMesh->Pnt(ed.FirstNode()));
D.DrawTo(myMesh->Pnt(ed.LastNode()));
}
}
// highlighted triangles
D.SetColor(Draw_blanc);
Standard_Integer e1, e2, e3, i;
Standard_Boolean o1, o2, o3;
for (i = 1; i <= myTriangles.Length(); i++) {
const BRepMesh_Triangle& tri=struc->GetElement(myTriangles(i));
tri.Edges(e1, e2, e3, o1, o2, o3);
const BRepMesh_Edge& ed1=myMesh->Edge(e1);
if (ed1.Movability()!=MeshDS_Deleted) {
D.MoveTo(myMesh->Pnt(ed1.FirstNode()));
D.DrawTo(myMesh->Pnt(ed1.LastNode()));
}
const BRepMesh_Edge& ed2=myMesh->Edge(e2);
if (ed2.Movability()!=MeshDS_Deleted) {
D.MoveTo(myMesh->Pnt(ed2.FirstNode()));
D.DrawTo(myMesh->Pnt(ed2.LastNode()));
}
const BRepMesh_Edge& ed3=myMesh->Edge(e3);
if (ed3.Movability()!=MeshDS_Deleted) {
D.MoveTo(myMesh->Pnt(ed3.FirstNode()));
D.DrawTo(myMesh->Pnt(ed3.LastNode()));
}
}
// highlighted edges
D.SetColor(Draw_rouge);
for (i = 1; i <= myEdges.Length(); i++) {
const BRepMesh_Edge& ed=myMesh->Edge(myEdges(i));
if (ed.Movability()!=MeshDS_Deleted) {
D.MoveTo(myMesh->Pnt(ed.FirstNode()));
D.DrawTo(myMesh->Pnt(ed.LastNode()));
}
}
// highlighted vertices
for (i = 1; i <= myVertices.Length(); i++) {
D.DrawMarker(myMesh->Pnt(myVertices(i)),Draw_Losange);
}
*/
}
//=======================================================================
//function : Copy
//purpose :
//=======================================================================
Handle(Draw_Drawable3D) MeshTest_DrawableMesh::Copy() const
{
Handle(MeshTest_DrawableMesh) D = new MeshTest_DrawableMesh();
return D;
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
static void printdegree(MeshDS_DegreeOfFreedom dof)
{
switch (dof) {
case MeshDS_InVolume :
cout << "InVolume";
break;
case MeshDS_OnSurface :
cout << "OnSurface";
break;
case MeshDS_OnCurve :
cout << "OnCurve";
break;
case MeshDS_Fixed :
cout << "Fixed";
break;
case MeshDS_Frontier :
cout << "Frontier";
break;
case MeshDS_Deleted :
cout << "Deleted";
break;
case MeshDS_Free :
cout << "Free";
break;
}
}
void MeshTest_DrawableMesh::Dump(Standard_OStream& S) const
{
// Should be reimplemented
/*Handle(BRepMesh_DataStructureOfDelaun) struc=myMesh->Result();
Standard_Integer e1, e2, e3;
Standard_Boolean o1, o2, o3;
Standard_Integer in, il, ie;
Standard_Integer nbn=struc->NbNodes();
Standard_Integer nbl=struc->NbLinks();
Standard_Integer nbe=struc->NbElements();
for (in=1; in<=nbn; in++) {
BRepMesh_Vertex nod=struc->GetNode(in);
S<<"(node "<<in<<" (uv "<<nod.Coord().X()<<" "
<<nod.Coord().Y()<<") (3d "
<<nod.Location3d()<<") ";
printdegree(nod.Movability());
S<<" (edgeconex";
MeshDS_ListOfInteger::Iterator tati(struc->LinkNeighboursOf(in));
for (; tati.More(); tati.Next()) S<<" "<<tati.Value();
S << "))\n";
}
S <<endl;
for (il=1; il<=nbl; il++) {
BRepMesh_Edge edg=struc->GetLink(il);
S << "(edge "<<il<<" ("<<edg.FirstNode()<<" "<<edg.LastNode()
<<" ";
printdegree(edg.Movability());
S<<") (triconex";
const MeshDS_PairOfIndex& pair = struc->ElemConnectedTo(il);
for (Standard_Integer j = 1, jn = pair.Extent(); j <= jn; j++)
S<<" "<<pair.Index(j);
S << "))\n";
}
S <<endl;
for (ie=1; ie<=nbe; ie++) {
BRepMesh_Triangle tri=struc->GetElement(ie);
tri.Edges(e1, e2, e3, o1, o2, o3);
if (!o1) e1=-e1;
if (!o2) e2=-e2;
if (!o3) e3=-e3;
S<<" (maille "<<ie<<" (links "<<e1<<" "
<<e2<<" "<<e3<<")";
printdegree(tri.Movability());
S<<")\n";
}
S << endl;
*/
}
//=======================================================================
//function : Whatis
//purpose :
//=======================================================================
void MeshTest_DrawableMesh::Whatis(Draw_Interpretor& S) const
{
S << " 3d mesh\n";
S << " - Triangles : " << myMesh->NbTriangles() << "\n";
S << " - Edges : " << myMesh->NbEdges() << "\n";
S << " - Vertices : " << myMesh->NbVertices() << "\n";
S << " - Point3d : " << myMesh->NbPoint3d() << "\n";
}
//=======================================================================
//function : Mesh
//purpose :
//=======================================================================
Handle(BRepMesh_FastDiscret) MeshTest_DrawableMesh::Mesh() const
{
return myMesh;
}
//=======================================================================
//function : Edges
//purpose :
//=======================================================================
TColStd_SequenceOfInteger& MeshTest_DrawableMesh::Edges()
{
return myEdges;
}
//=======================================================================
//function : Vertices
//purpose :
//=======================================================================
TColStd_SequenceOfInteger& MeshTest_DrawableMesh::Vertices()
{
return myVertices;
}
//=======================================================================
//function : Triangles
//purpose :
//=======================================================================
TColStd_SequenceOfInteger& MeshTest_DrawableMesh::Triangles()
{
return myTriangles;
}

View File

@@ -0,0 +1,387 @@
// File: MeshTest_PluginCommands.cxx
// Created: Fri Apr 11 15:41:24 2008
// Author: Peter KURNEV
// <pkv@irinox>
#include <MeshTest.ixx>
#include <Draw_Interpretor.hxx>
#include <TColStd_MapOfAsciiString.hxx>
#include <BRepMesh_DiscretFactory.hxx>
#include <TCollection_AsciiString.hxx>
#include <TColStd_MapIteratorOfMapOfAsciiString.hxx>
#include <BRepMesh_FactoryError.hxx>
#include <BRepMesh_DiscretRoot.hxx>
#include <Bnd_Box.hxx>
#include <BRepMesh_PDiscretRoot.hxx>
#include <DBRep.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <TopExp.hxx>
#include <Poly_Triangulation.hxx>
#include <gp_Vec.hxx>
#include <GProp_GProps.hxx>
#include <BRepGProp.hxx>
#include <DrawTrSurf.hxx>
#include <BRep_Tool.hxx>
#include <TopoDS.hxx>
#include <MeshTest_CheckTopology.hxx>
#include <TColgp_Array1OfPnt2d.hxx>
#include <Poly_Polygon3D.hxx>
#include <Poly_Polygon2D.hxx>
static Standard_Integer mpnames (Draw_Interpretor& , Standard_Integer , const char** );
static Standard_Integer mpsetdefaultname (Draw_Interpretor& , Standard_Integer , const char** );
static Standard_Integer mpgetdefaultname (Draw_Interpretor& , Standard_Integer , const char** );
static Standard_Integer mpsetfunctionname (Draw_Interpretor& , Standard_Integer , const char** );
static Standard_Integer mpgetfunctionname (Draw_Interpretor& , Standard_Integer , const char** );
static Standard_Integer mperror (Draw_Interpretor& , Standard_Integer , const char** );
static Standard_Integer mpincmesh (Draw_Interpretor& , Standard_Integer , const char** );
static Standard_Integer triarea (Draw_Interpretor& , Standard_Integer , const char** );
static Standard_Integer checktopo (Draw_Interpretor& , Standard_Integer , const char** );
//=======================================================================
//function : PluginCommands
//purpose :
//=======================================================================
void MeshTest::PluginCommands(Draw_Interpretor& theCommands)
{
static Standard_Boolean done = Standard_False;
if (done) {
return;
}
done = Standard_True;
//
const char* g = "Mesh Commands";
// Commands
theCommands.Add("mpnames" , "use mpnames" , __FILE__, mpnames , g);
theCommands.Add("mpsetdefaultname" , "use mpsetdefaultname" , __FILE__, mpsetdefaultname , g);
theCommands.Add("mpgetdefaultname" , "use mpgetdefaultname" , __FILE__, mpgetdefaultname , g);
theCommands.Add("mpsetfunctionname", "use mpsetfunctionname", __FILE__, mpsetfunctionname , g);
theCommands.Add("mpgetfunctionname", "use mpgetfunctionname", __FILE__, mpgetfunctionname , g);
theCommands.Add("mperror" , "use mperror" , __FILE__, mperror , g);
theCommands.Add("mpincmesh" , "use mpincmesh" , __FILE__, mpincmesh , g);
theCommands.Add("triarea","shape [eps] (computes triangles and surface area)",__FILE__, triarea, g);
theCommands.Add("checktopo", "shape (checks mesh topology)", __FILE__, checktopo, g);
}
//=======================================================================
//function : mpnames
//purpose :
//=======================================================================
static Standard_Integer mpnames (Draw_Interpretor& , Standard_Integer n, const char** )
{
Standard_Integer aNb;
TColStd_MapIteratorOfMapOfAsciiString aIt;
//
if (n!=1) {
printf(" use mpnames\n");
return 0;
}
//
const TColStd_MapOfAsciiString& aMN=BRepMesh_DiscretFactory::Get().Names();
aNb=aMN.Extent();
if (!aNb) {
printf(" *no names found\n");
return 0;
}
//
printf(" *available names:\n");
aIt.Initialize(aMN);
for (; aIt.More(); aIt.Next()) {
const TCollection_AsciiString& aName=aIt.Key();
printf(" %s\n", aName.ToCString());
}
//
return 0;
}
//=======================================================================
//function : mpsetdefaultname
//purpose :
//=======================================================================
static Standard_Integer mpsetdefaultname (Draw_Interpretor& , Standard_Integer n, const char**a )
{
TCollection_AsciiString aName;
//
if (n!=2) {
printf(" use mpsetdefaultname name\n");
return 0;
}
//
aName=a[1];
//
BRepMesh_DiscretFactory::Get().SetDefaultName(aName);
printf(" *ready\n");
//
return 0;
}
//=======================================================================
//function : mpgetdefaultname
//purpose :
//=======================================================================
static Standard_Integer mpgetdefaultname (Draw_Interpretor& , Standard_Integer n, const char** )
{
if (n!=1) {
printf(" use mpgetdefaultname\n");
return 0;
}
//
const TCollection_AsciiString& aName=BRepMesh_DiscretFactory::Get().DefaultName();
printf(" *default name: %s\n", aName.ToCString());
//
return 0;
}
//=======================================================================
//function : mpsetfunctionname
//purpose :
//=======================================================================
static Standard_Integer mpsetfunctionname (Draw_Interpretor& , Standard_Integer n, const char**a )
{
TCollection_AsciiString aName;
//
if (n!=2) {
printf(" use mpsetfunctionname name\n");
return 0;
}
//
aName=a[1];
//
BRepMesh_DiscretFactory::Get().SetFunctionName(aName);
printf(" *ready\n");
//
return 0;
}
//=======================================================================
//function : mpgetdefaultname
//purpose :
//=======================================================================
static Standard_Integer mpgetfunctionname (Draw_Interpretor& , Standard_Integer n, const char** )
{
if (n!=1) {
printf(" use mpgetfunctionname\n");
return 0;
}
//
const TCollection_AsciiString& aName=BRepMesh_DiscretFactory::Get().FunctionName();
printf(" *function name: %s\n", aName.ToCString());
//
return 0;
}
//=======================================================================
//function : mperror
//purpose :
//=======================================================================
static Standard_Integer mperror (Draw_Interpretor& , Standard_Integer n, const char** )
{
BRepMesh_FactoryError aErr;
//
if (n!=1) {
printf(" use mperror\n");
return 0;
}
//
aErr=BRepMesh_DiscretFactory::Get().ErrorStatus();
printf(" *ErrorStatus: %d\n", (int)aErr);
//
return 0;
}
//=======================================================================
//function :mpincmesh
//purpose :
//=======================================================================
static Standard_Integer mpincmesh (Draw_Interpretor& , Standard_Integer n, const char** a)
{
Standard_Boolean bIsDone;
Standard_Real aDeflection, aAngle;
TopoDS_Shape aS;
BRepMesh_FactoryError aErr;
BRepMesh_PDiscretRoot pAlgo;
//
if (n<3) {
printf(" use mpincmesh s deflection [angle]\n");
return 0;
}
//
aS=DBRep::Get(a[1]);
if (aS.IsNull()) {
printf(" null shapes is not allowed here\n");
return 0;
}
//
aDeflection=atof(a[2]);
aAngle=0.5;
if (n>3) {
aAngle=atof(a[3]);
}
//
pAlgo=BRepMesh_DiscretFactory::Get().Discret(aS,
aDeflection,
aAngle);
//
aErr=BRepMesh_DiscretFactory::Get().ErrorStatus();
if (aErr!=BRepMesh_FE_NOERROR) {
printf(" *Factory::Get().ErrorStatus()=%d\n", (int)aErr);
}
//
if (!pAlgo) {
printf(" *Can not create the algo\n");
return 0;
}
//
pAlgo->Perform();
bIsDone=pAlgo->IsDone();
if (!bIsDone) {
printf(" *Not done\n");
}
//
return 0;
}
//#######################################################################
static Standard_Integer triarea (Draw_Interpretor& di, int n, const char ** a)
{
if (n < 2) return 1;
TopoDS_Shape shape = DBRep::Get(a[1]);
if (shape.IsNull()) return 1;
Standard_Real anEps = -1.;
if (n > 2)
anEps = atof(a[2]);
TopTools_IndexedMapOfShape aMapF;
TopExp::MapShapes (shape, TopAbs_FACE, aMapF);
// detect if a shape has triangulation
Standard_Boolean hasPoly = Standard_False;
int i;
for (i=1; i <= aMapF.Extent(); i++) {
const TopoDS_Face& aFace = TopoDS::Face(aMapF(i));
TopLoc_Location aLoc;
Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
if (!aPoly.IsNull()) {
hasPoly = Standard_True;
break;
}
}
// compute area by triangles
double aTriArea=0;
if (hasPoly) {
for (i=1; i <= aMapF.Extent(); i++) {
const TopoDS_Face& aFace = TopoDS::Face(aMapF(i));
TopLoc_Location aLoc;
Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
if (aPoly.IsNull()) {
cout << "face "<<i<<" has no triangulation"<<endl;
break;
}
const Poly_Array1OfTriangle& triangles = aPoly->Triangles();
const TColgp_Array1OfPnt& nodes = aPoly->Nodes();
for (int j=triangles.Lower(); j <= triangles.Upper(); j++) {
const Poly_Triangle& tri = triangles(j);
int n1, n2, n3;
tri.Get (n1, n2, n3);
const gp_Pnt& p1 = nodes(n1);
const gp_Pnt& p2 = nodes(n2);
const gp_Pnt& p3 = nodes(n3);
gp_Vec v1(p1, p2);
gp_Vec v2(p1, p3);
double ar = v1.CrossMagnitude(v2);
aTriArea += ar;
}
}
aTriArea /= 2;
}
// compute area by geometry
GProp_GProps props;
if (anEps <= 0.)
BRepGProp::SurfaceProperties(shape, props);
else
BRepGProp::SurfaceProperties(shape, props, anEps);
double aGeomArea = props.Mass();
di << aTriArea << " " << aGeomArea << " ";
return 0;
}
//#######################################################################
static Standard_Integer checktopo (Draw_Interpretor& di, int n, const char ** a)
{
if (n < 2) return 1;
TopoDS_Shape shape = DBRep::Get(a[1]);
if (shape.IsNull()) return 1;
TopTools_IndexedMapOfShape aMapF;
TopExp::MapShapes (shape, TopAbs_FACE, aMapF);
Standard_CString name = ".";
MeshTest_CheckTopology aCheck(shape);
aCheck.Perform();
Standard_Integer nbFree = 0;
Standard_Integer nbFac = aCheck.NbFacesWithFL(), i, k;
if (nbFac > 0) {
for (k=1; k <= nbFac; k++) {
Standard_Integer nbEdge = aCheck.NbFreeLinks(k);
Standard_Integer iF = aCheck.GetFaceNumWithFL(k);
nbFree += nbEdge;
cout<<"free links of face "<<iF<<endl;
const TopoDS_Face& aFace = TopoDS::Face(aMapF.FindKey(iF));
TopLoc_Location aLoc;
Handle(Poly_Triangulation) aT = BRep_Tool::Triangulation(aFace, aLoc);
const TColgp_Array1OfPnt& aPoints = aT->Nodes();
const TColgp_Array1OfPnt2d& aPoints2d = aT->UVNodes();
const gp_Trsf& trsf = aLoc.Transformation();
TColgp_Array1OfPnt pnts(1,2);
TColgp_Array1OfPnt2d pnts2d(1,2);
for (i=1; i <= nbEdge; i++) {
Standard_Integer n1, n2;
aCheck.GetFreeLink(k, i, n1, n2);
cout<<"{"<<n1<<" "<<n2<<"} ";
pnts(1) = aPoints(n1).Transformed(trsf);
pnts(2) = aPoints(n2).Transformed(trsf);
Handle(Poly_Polygon3D) poly = new Poly_Polygon3D (pnts);
DrawTrSurf::Set (name, poly);
DrawTrSurf::Set (name, pnts(1));
DrawTrSurf::Set (name, pnts(2));
pnts2d(1) = aPoints2d(n1);
pnts2d(2) = aPoints2d(n2);
Handle(Poly_Polygon2D) poly2d = new Poly_Polygon2D (pnts2d);
DrawTrSurf::Set (name, poly2d);
DrawTrSurf::Set (name, pnts2d(1));
DrawTrSurf::Set (name, pnts2d(2));
}
cout<<endl;
}
}
Standard_Integer nbErr = aCheck.NbCrossFaceErrors();
if (nbErr > 0) {
cout<<"cross face errors: {face1, node1, face2, node2, distance}"<<endl;
for (i=1; i <= nbErr; i++) {
Standard_Integer iF1, n1, iF2, n2;
Standard_Real aVal;
aCheck.GetCrossFaceError(i, iF1, n1, iF2, n2, aVal);
cout<<"{"<<iF1<<" "<<n1<<" "<<iF2<<" "<<n2<<" "<<aVal<<"} ";
}
cout<<endl;
}
Standard_Integer nbAsync = aCheck.NbAsyncEdges();
if (nbAsync > 0) {
cout<<"async edges:"<<endl;
for (i=1; i <= nbAsync; i++) {
Standard_Integer ie = aCheck.GetAsyncEdgeNum(i);
cout<<ie<<" ";
}
cout<<endl;
}
if (nbFree > 0 || nbErr > 0 || nbAsync > 0)
di<<"Free_links "<<nbFree
<<" Cross_face_errors "<<nbErr
<<" Async_edges "<<nbAsync << " ";
return 0;
}