Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] Properly oriented Polyhedron_3 vertex normals for rendering with OpenGL

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] Properly oriented Polyhedron_3 vertex normals for rendering with OpenGL


Chronological Thread 
  • From: Andreas Fabri <>
  • To:
  • Subject: Re: [cgal-discuss] Properly oriented Polyhedron_3 vertex normals for rendering with OpenGL
  • Date: Sat, 6 Feb 2016 19:16:03 +0100
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None ; spf=None ; spf=None
  • Ironport-phdr: 9a23:6IqwuBxMhDiKI4nXCy+O+j09IxM/srCxBDY+r6Qd0e8QIJqq85mqBkHD//Il1AaPBtWEragYwLOO7+jJYi8p39WoiDg6aptCVhsI2409vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6kO74TNaIBjjLw09fr2zQd6NyZ7rnLnqp9X6WEZhunmUWftKNhK4rAHc5IE9oLBJDeIP8CbPuWZCYO9MxGlldhq5lhf44dqsrtY4q3wD86Fpy8kVWqrze+E0TKdTES89G2Ez/szi8xfZHiWV4X5Je2MaiBdBGEDr5RvgX9+luy32rOd0w2+UNMfsTJg7VDOn4rtxWRHhgzsALS9/+2bS3J8jxJlHqQ6s8kQsi7XfZ5uYYaJz
  • Organization: GeometryFactory

Hello,

You might call, or have a look at the implementation of
http://doc.cgal.org/4.7/Polygon_mesh_processing/index.html#PMPNormalComp

best,

andreas

On 06/02/2016 18:44, Petros Kataras wrote:
Hello,

I am trying to render 3d meshes produced by CGAL through OpenGL and I am
hitting a wall regarding the calculation of properly oriented normals.

I have reduced my test case to the absolute minimal of creating and
rendering a simple tetrahedron generated from
Polyhedron_3::make_tetrahedron.

After the creation I am iterating over the vertices of the tetrahedron
and calculate the per vertex-normal based on the following functions
that I found :

// Compute facet normal
template <class Facet, class Kernel>
typename Kernel::Vector_3 compute_facet_normal(const Facet& f)
{
typedef typename Kernel::Point_3 Point;
typedef typename Kernel::Vector_3 Vector;
typedef typename Facet::Halfedge_around_facet_const_circulator
HF_circulator;
Vector normal = CGAL::NULL_VECTOR;
HF_circulator he = f.facet_begin();
HF_circulator end = he;
CGAL_For_all(he,end)
{
const Point& prev = he->prev()->vertex()->point();
const Point& curr = he->vertex()->point();
const Point& next = he->next()->vertex()->point();

Vector n = CGAL::cross_product(next-curr,prev-curr);
normal = normal + n;
}
return normal / std::sqrt(normal * normal);
}

// Compute vertex normal
template <class Vertex, class Kernel>
typename Kernel::Vector_3 compute_vertex_normal(const Vertex& v)
{

typedef typename Kernel::Vector_3 Vector;
typedef typename Vertex::Halfedge_around_vertex_const_circulator
HV_circulator;
typedef typename Vertex::Facet Facet;
Vector normal = CGAL::NULL_VECTOR;
HV_circulator he = v.vertex_begin();
HV_circulator end = he;

CGAL_For_all(he,end)
{
if(!he->is_border())
{
Vector n = compute_facet_normal<Facet,Kernel>(*he->facet());
normal = normal + (n / std::sqrt(n*n));
}
}
return normal / std::sqrt(normal * normal);
}

I would expect this to be enough to give me properly oriented normals
based on the fact that CGAL maintains CCW order but obviously I am
missing something since the result is not correct. The normals of the
front facet especially look like the winding order is reversed for the
specific triangle. The attached image shows the result that I get.

Is there a way to ensure CCW order on the vertices of facets so that
normals are pointing outwards or am I totally missing something?

Thanks in advance for any hints,

Petros


--
Andreas Fabri, PhD
Chief Officer, GeometryFactory
Editor, The CGAL Project

phone: +33.492.954.912 skype: andreas.fabri



Archive powered by MHonArc 2.6.18.

Top of Page