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: Petros Kataras <>
  • To:
  • Subject: Re: [cgal-discuss] Properly oriented Polyhedron_3 vertex normals for rendering with OpenGL
  • Date: Sun, 7 Feb 2016 11:47:22 +0100
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None ; spf=Pass ; spf=None
  • Ironport-phdr: 9a23:m1oeyxVLFNT5Gm+eJkiT+NIeplDV8LGtZVwlr6E/grcLSJyIuqrYZh2Gt8tkgFKBZ4jH8fUM07OQ6PC/HzZdqs/Q+Fk5M7VyFDY9wf0MmAIhBMPXQWbaF9XNKxIAIcJZSVV+9Gu6O0UGUOz3ZlnVv2HgpWVKQka3CwN5K6zPF5LIiIzvjqbpq8KVOVgD3Wv1SIgxBSv1hD2ZjtMRj4pmJ/R54TryiVwMRd5rw3h1L0mYhRf265T41pdi9yNNp6BprJYYAu2pN5k+VqFSWTQ6L3gutoqsrgjGVQLJ530GU2xQnAAPGBnA9Bi9X5H/tWzxueN5nSWbJsbrVqtnZTP35KhiTFrkiTwMKiUi2GDRkM15yqxB8zy7oBkq+4PIeoaOfNl3YqrHdMhSEWMaWM9WUQROB4q9a80ECO9XbrUQlJX0u1Zb9Uj2PgKrHu66kjI=

Hi Andreas and thanks for your prompt reply.

This totally did the trick. 

I was wondering now what would be the fastest way to construct a Surface_mesh from a Polyhedron_3 or a C3t3 cell directly.

i.e Right now for a tetrahedron for example I am creating the surface mesh by manually adding the vertices and faces of the tetrahedron to the mesh. 

Is there a way to pass it directly to a Surface_mesh after a make_tetrahedron for example ??

Thanks again!

Also, FWIW, I had some compilation issues when trying to run the compute_normals example on OS X 10.11.2 with Xcode 7.1 and clang-700.1.76. There are some typedef conflicts and also nil seems to be defined which was causing troubles.

A fast workaround for me was to undef nil and do the necessary typedefs inside an anonymous namespace.

Best,
Petros




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

-- 
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss




Archive powered by MHonArc 2.6.18.

Top of Page