| Mesh a nurbs face |
 |
| SunHongLei |
2012/12/07 11:03 |
Hi,all:
How to mesh a nurbs face? I want to use
StlTransfer trans;
trans.BuildIncrementalMesh(shape,Tol,Standard_False,aMesh);
But there is a problem: how to make a TopoDS_Shape from Geom_BSplineSurface?
Thanks |
 |
| |
 | | Rabih |
2012/12/07 13:11 |
Hi SunHongLei,
I hope that the code will help you.
Handle(Geom_BSplineSurface) bSurf = .....;
TopoDS_Face face = BRepBuilderAPI_MakeFace(surf).Face();
Handle_StlMesh_Mesh hStlMesh = new StlMesh_Mesh();
StlTransfer::BuildIncrementalMesh((TopoDS_Shape &)face, deflection, hStlMesh );
Standard_Real x1,y1,z1,x2,y2,z2,x3,y3,z3,nx,ny,nz;
StlMesh_MeshExplorer theMeshExplorer(hStlMesh);
for (Standard_Integer nbd=1;nbd<=hStlMesh->NbDomains();nbd++)
{
for (theMeshExplorer.InitTriangle(nbd); theMeshExplorer.MoreTriangle(); theMeshExplorer.NextTriangle())
{
theMeshExplorer.TriangleVertices (x1,y1,z1,x2,y2,z2,x3,y3,z3);
theMeshExplorer.TriangleOrientation(nx,ny,nz);
BRepBuilderAPI_MakePolygon MP;
gp_Pnt P(x1,y1,z1);
MP.Add(P);
gp_Pnt P1(x2,y2,z2);
MP.Add(P1);
gp_Pnt P2(x3,y3,z3);
MP.Add(P2);
MP.Close();
TopoDS_Wire W = MP.Wire();
TopoDS_Face aFace = BRepBuilderAPI_MakeFace(W);
if(!aFace.IsNull())
theBuilder.Add(theCompound,aFace);
else
continue;
}
}
//----------- or
BRepTools::Clean(face);
BRepTools::Update(face);
BRepMesh::Mesh(face, deflection);
TopExp_Explorer ExpFace;
for( NumFace=0,ExpFace.Init(myShape,TopAbs_FACE); ExpFace.More(); ExpFace.Next(),NumFace++ )
{
TopoDS_Face myFace = TopoDS::Face(ExpFace.Current());
TopLoc_Location myLocation = myFace.Location();
Handle(Poly_Triangulation) myT = BRep_Tool::Triangulation(myFace, myLocation);
Poly_Connect pc(myT);
const TColgp_Array1OfPnt& Nodes= myT->Nodes();
BAR = GProp_PGProps::Barycentre(Nodes);
const TColgp_Array1OfPnt2d& UVNodes = myT->UVNodes();
const Poly_Array1OfTriangle& triangles = myT->Triangles();
TColgp_Array1OfDir myNormal(Nodes.Lower(), Nodes.Upper());
Standard_Integer nnn = myT->NbTriangles();
for (nt = 1; nt <= nnn; nt++)
{
if (SST.Orientation(myFace) == TopAbs_REVERSED) triangles(nt).Get(n1,n3,n2);
else
triangles(nt).Get(n1,n2,n3);
if (TriangleIsValid (Nodes(n1),Nodes(n2),Nodes(n3)) )
{
gp_Pnt p1 = Nodes(n1).Transformed(myLocation.Transformation());
gp_Pnt p2 = Nodes(n2).Transformed(myLocation.Transformation());
gp_Pnt p3 = Nodes(n3).Transformed(myLocation.Transformation());
BRepBuilderAPI_MakePolygon MP;
MP.Add(p0);
MP.Add(p1);
MP.Add(p2);
..........
}
}
}
}
} // end of the exploration of the shape in faces
}
best regards
Rabih
|
 |
| |
 | | SunHongLei |
2012/12/10 05:15 |
Dear Rabih ,Thanks very much! This code give me a lot of help! Thanks!
Best regards!
SunHongLei |
 |
| | | |