Finding the Nodes and Tria's in a meshed body

Hi All,

I want to know how the node id, their coordinates (x,y,z), CTRIA's and the associated nodes for this tria can be found in a triangulated surface (3D body in a triangular mesh).

Thanks and Regards Pavan

kim wj's picture

Look up 'BRep_Tool::Triangulation' in OCC reference documentation.

Pavan's picture

Thanks, I was able to get the node indices of a tria (N1,N2,N3) but was unable to find the coordinates of the nodes (x,y,z) of a meshed body. Plz Let me know how this can be done.

Thanks Pavan

Axel's picture

Hi !

With the code below, you get for each triangle of your triangulation the nodes, the UVNodes and the normal of the triangle. In this code, everything is stored in a Graphic3d_Array1OfVertexNT.

Standard_Integer nnn = myT->NbTriangles(); Standard_Integer nt, n1, n2, n3 = 0;

Handle(Poly_Triangulation) myT = BRep_Tool::Triangulation(myFace, myLocation); const TColgp_Array1OfPnt& Nodes = myT->Nodes(); const TColgp_Array1OfPnt2d& UVNodes = myT->UVNodes(); const Poly_Array1OfTriangle& triangles = myT->Triangles(); Graphic3d_Array1OfVertexNT Points(1,3);

for (Standard_Integer mytriangle = 1; mytriangle <= numberoftriangles; mytriangle++) { gp_Vec Normal = FindNormal(Nodes(n1),Nodes(n2),Nodes(n3)); Points(1).SetCoord(Nodes(n1).X(), Nodes(n1).Y(), Nodes(n1).Z()); Points(1).SetNormal(Normal.X(), Normal.Y(), Normal.Z()); Points(1).SetTextureCoordinate(UVNodes(n1),UVNodes(n1));

Points(2).SetCoord(Nodes(n2).X(), Nodes(n2).Y(), Nodes(n2).Z()); Points(2).SetNormal(Normal.X(), Normal.Y(), Normal.Z()); Points(2).SetTextureCoordinate(UVNodes(n2),UVNodes(n2));

Points(3).SetCoord(Nodes(n3).X(), Nodes(n3).Y(), Nodes(n3).Z()); Points(3).SetNormal(Normal.X(), Normal.Y(), Normal.Z()); Points(3).SetTextureCoordinate(UVNodes(n3),UVNodes(n3)); }

Pavan's picture

Thanks for your code. But when I try to use the code you have given, I am getting an error "FindNormal. undeclared identifier". Do I need to include any files here?

Regards Pavan

Axel's picture

It is just a function to compute the normal of a triangle, according to the position of its vertices :

gp_Vec NEW_Shape::FindNormal(const gp_Pnt P1, const gp_Pnt P2, const gp_Pnt P3) {

gp_Vec V1(P1,P2); // V1=(P1,P2)

gp_Vec V2(P2,P3); // V2=(P2,P3)

gp_Vec V3(P3,P1); // V3=(P3,P1)

if ((V1.SquareMagnitude() > 1.e-10) && (V2.SquareMagnitude() > 1.e-10) && (V3.SquareMagnitude() > 1.e-10))

V1.Cross(V2); // V1 = Normal

return V1; }

Good luck !


Pavan's picture

Thanks for your input. I'd like add some more things here for the benefit of others. As I needed to know the node coordinates, I used the following lines of code.

const TColgp_Array1OfPnt& Nodes = facing->Nodes();

for (static Standard_Integer num=1; num<=(facing->NbNodes());num++) {

fprintf(fp,"%d,%f,%f,%f\n",num,Nodes(num).X(),Nodes(num).Y(), Nodes(num).Z()); }

and for getting the N1, N2, N3 of tria's I added the following lines.

for (i =1, triaid = 1;i<=(facing->NbTriangles());i++, triaid++){

Poly_Triangle trian = tri.Value(i);

Standard_Integer index1,index2,index3,M,N;




Hope this is correct.

Regards Pavan