Hello
I have a shell (connected faces).
I need to compute normals(say gp_Dir) at each of the vertices.
Any piece of code which is optimized for performance too.

regards

- PG

Francesco Argese Thu, 11/24/2011 - 15:36

Hi,

have you resolved the problem?

I also need to compute normals at each of the vertices from triangulation.

I have tried in these ways without great results:
1) Using method HasNormals of Poly_Triangulation class:
Handle(Poly_Triangulation) aTri = BRep_Tool::Triangulation(static_cast(face), aLocation);
if( aTri.IsNull() )
{
std::cout << "Error tessellating!!!" << std::endl;
return false;
}
if(aTri->HasNormals())
{
for(int i = 1; i < aTri->Normals().Length()+1; i=i+3)
{
aTri->Normals().Value(i);
aTri->Normals().Value(i+1);
aTri->Normals().Value(i+2);
}
}

aTri->HasNormals() give me always false. Is there a manner to force OpenCascade to calculate normals? Is it enabled only for some cad formats? I'm working with iges at the moment.

2) Following another post on this forum [1] i have tried to calculate normals (one for every triangle) but some normals seems reversed and reversing all when orientation is TopAbs_REVERSED doesn't resolve the problem (see attachment).

3) Has someone any suggestion to do the same thing using other functions? For example using (u, v) surface representation utilities [2]?

4) I think that presentation module of OpenCascade must calculate these normals somewhere. Could you give me some hints on how to find some pieces of code doing this?

Thu, 11/24/2011 - 15:36

Hi,

have you resolved the problem?

I also need to compute normals at each of the vertices from triangulation.

I have tried in these ways without great results:

1) Using method HasNormals of Poly_Triangulation class:

Handle(Poly_Triangulation) aTri = BRep_Tool::Triangulation(static_cast(face), aLocation);

if( aTri.IsNull() )

{

std::cout << "Error tessellating!!!" << std::endl;

return false;

}

if(aTri->HasNormals())

{

for(int i = 1; i < aTri->Normals().Length()+1; i=i+3)

{

aTri->Normals().Value(i);

aTri->Normals().Value(i+1);

aTri->Normals().Value(i+2);

}

}

aTri->HasNormals() give me always false. Is there a manner to force OpenCascade to calculate normals? Is it enabled only for some cad formats? I'm working with iges at the moment.

2) Following another post on this forum [1] i have tried to calculate normals (one for every triangle) but some normals seems reversed and reversing all when orientation is TopAbs_REVERSED doesn't resolve the problem (see attachment).

3) Has someone any suggestion to do the same thing using other functions? For example using (u, v) surface representation utilities [2]?

4) I think that presentation module of OpenCascade must calculate these normals somewhere. Could you give me some hints on how to find some pieces of code doing this?

Thanks in advance.

Regards

Francesco Argese

[1] http://www.opencascade.org/org/forum/thread_12568/

[2] http://www.opencascade.org/org/forum/thread_21118/

Thu, 11/24/2011 - 18:36

Hi all,

I have resolved my problem adapting this code (found in OCCCoin3d_viewer_msdev.zip [1]) to my needs:

/*******************************************

* Compute normal of vertex on a surface

*******************************************/

void ComputeNormal(const BRepAdaptor_Surface& SF,

gp_Pnt& V1,

gp_Pnt2d& V1_2d,

gp_Vec &Normal)

{

gp_Vec T1,T2;

// Compute normal

SF.D1(V1_2d.X(),V1_2d.Y(),V1,T1,T2);

Normal = T1.Crossed(T2);

Standard_Real x = Normal.Magnitude();

if (x > 1.e-10)

Normal.Multiply(1/x);

else {

Normal.SetCoord(1/2.,0,0);

cout << "Null normal"<< endl;

}

}

/*******************************************

* Add a vertex with normal for strip algo

*******************************************/

void AddVertex(int N1,

const BRepAdaptor_Surface& SF,

const TColgp_Array1OfPnt& Nodes,

const TColgp_Array1OfPnt2d& UVNodes,

Standard_Boolean identity,

gp_Trsf myTransf)

{

gp_Pnt V1 = Nodes(N1);

if(!identity) V1.Transform(myTransf);

gp_Vec Normal(0,0,0);

gp_Pnt2d P = UVNodes(N1);

ComputeNormal(SF,V1,P,Normal);

// Here normal is correcly computed

}

It works well! :-)

Francesco Argese

[1] http://projects.opencascade.org/projects/graphperf/coin3d.htm