
Tue, 12/11/2007 - 14:40
Hi,
I'm importing an IGES file using "IGESControl_Reader".
I'm tesselelating each face of the TopoDS_Shape.
The next step I want to realize is to calculate (and display) a normal for each triangle.
What is the easiest way to get the normal of each triangle?
Here's the code I'm using to tesselate and display the TopoDS_Shape:
BRepMesh::Mesh(tshape,1);
BRep_Builder builder;
TopoDS_Compound Comp;
builder.MakeCompound(Comp);
for (TopExp_Explorer ex(tshape,TopAbs_FACE) ; ex.More(); ex.Next()) {
TopoDS_Face F =TopoDS::Face(ex.Current());
TopLoc_Location L;
Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(F,L);
TColgp_Array1OfPnt tab(1,(facing->NbNodes()));
tab = facing->Nodes();
Poly_Array1OfTriangle tri(1,facing->NbTriangles());
tri = facing->Triangles();
for (Standard_Integer i=1;iNbTriangles());i++) {
Poly_Triangle trian = tri.Value(i);
Standard_Integer index1,index2,index3,M,N;
trian.Get(index1,index2,index3);
for (Standard_Integer j=1;j
switch (j) {
case 1 :
M = index1;
N = index2;
break;
case 2 :
N = index3;
break;
case 3 :
M = index2;
}
BRepBuilderAPI_MakeEdge ME(tab.Value(M),tab.Value(N));
if (ME.IsDone())
{
builder.Add(Comp,ME.Edge());
}
}
}
}
Handle_AIS_Shape atriangulation = new AIS_Shape(Comp);
myAISContext->SetDisplayMode(atriangulation,0);
myAISContext->SetColor(atriangulation,Quantity_NOC_WHITE);
myAISContext->Display(atriangulation);
Thanks for your help,
Stephan
Sat, 04/05/2008 - 16:48
gp_XYZ pt1 = tab.Value(index1).XYZ();
gp_XYZ pt2 = tab.Value(index2).XYZ();
gp_XYZ pt3 = tab.Value(index3).XYZ();
gp_XYZ v1 = pt2-pt1;
gp_XYZ v2 = pt3-pt2;
gp_XYZ normal = v1^v2;
use this it will count