Hi, Does anyone know how to calculate vertex normal after triangulation? I have fond that the class BRepMesh_Discret has a function "Normal", does it works?
Any help will be appreciated!! Thanks in advance !!
Thanks for your help!!
I tried to calcule the vertex normal by averaging the normals of the triangles connected to that vertex. But it still has a problem of the normal orientation.
l_TriangleNormal.Normalize();
l_VertexNormal.Add(l_TriangleNormal);
l_NbTriangles++;
} // end check squaremodules
}// end if (i == l_Triangles.Value(j).Value(1) ...
}// end loop over triangle
l_VertexNormal.Divide(l_NbTriangles);
}// end loop over node
Wed, 04/30/2008 - 18:05
Take a glance at http://www.opencascade.org/org/forum/thread_13152/
I think it's enough for your needs
Tue, 05/06/2008 - 17:13
Thanks for your help!!
I tried to calcule the vertex normal by averaging the normals of the triangles connected to that vertex. But it still has a problem of the normal orientation.
=======================================================
Handle_Poly_Triangulation l_Triangulation = BRep_Tool::Triangulation(l_Face,l_Location);
if(!l_Triangulation.IsNull())
{
const TColgp_Array1OfPnt& l_Nodes = l_Triangulation->Nodes();
const Poly_Array1OfTriangle& l_Triangles = l_Triangulation->Triangles();
for (int i = 1; i <= l_Nodes.Length(); i++ )
{
gp_XYZ l_VertexNormal(0, 0, 0);
int l_NbTriangles = 0;// number of tiangles sharing current node
for (int j = 1 ; j <= l_Triangles.Length() ; j++)
{
if ( i == l_Triangles.Value(j).Value(1) ||
i == l_Triangles.Value(j).Value(2) ||
i == l_Triangles.Value(j).Value(3) )
{
gp_XYZ l_Pt1 = l_Nodes.Value(l_Triangles.Value(j).Value(1)).XYZ();
gp_XYZ l_Pt2 = l_Nodes.Value(l_Triangles.Value(j).Value(2)).XYZ();
gp_XYZ l_Pt3 = l_Nodes.Value(l_Triangles.Value(j).Value(3)).XYZ();
if (l_Face.Orientation() == TopAbs_REVERSED)
{
gp_XYZ l_V1 = l_pt2 - l_pt3;
gp_XYZ l_V2 = l_pt1 - l_pt2;
}
else
{
gp_XYZ l_V1 = l_pt2 - l_pt1;
gp_XYZ l_V2 = l_pt3 - l_pt2;
}// end else
gp_XYZ l_TriangleNormal = l_V1 ^ l_V2;
if (l_TriangleNormal.SquareModulus() > 0)
{
l_TriangleNormal.Normalize();
l_VertexNormal.Add(l_TriangleNormal);
l_NbTriangles++;
} // end check squaremodules
}// end if (i == l_Triangles.Value(j).Value(1) ...
}// end loop over triangle
l_VertexNormal.Divide(l_NbTriangles);
}// end loop over node
}
==================================================