Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] CGAL+OpenGL, incorrectly render mesh triangles

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] CGAL+OpenGL, incorrectly render mesh triangles


Chronological Thread 
  • From: "Laurent Rineau (CGAL/GeometryFactory)" <>
  • To:
  • Subject: Re: [cgal-discuss] CGAL+OpenGL, incorrectly render mesh triangles
  • Date: Fri, 14 Apr 2017 19:21:56 +0200
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None ; spf=Pass ; spf=None
  • Ironport-phdr: 9a23:mPRCAxV8AgVHnSXbkhHl5zOdsKvV8LGtZVwlr6E/grcLSJyIuqrYbRSAt8tkgFKBZ4jH8fUM07OQ6PG8HzRYqb+681k6OKRWUBEEjchE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i764jEdAAjwOhRoLerpBIHSk9631+ev8JHPfglEnjSwbLd9IRmssQndqtQdjJd/JKo21hbHuGZDdf5MxWNvK1KTnhL86dm18ZV+7SleuO8v+tBZX6nicKs2UbJXDDI9M2Ao/8LrrgXMTRGO5nQHTGoblAdDDhXf4xH7WpfxtTb6tvZ41SKHM8D6Uaw4VDK/5KptVRTmijoINyQh/W/XlMJ+kaxVrhGmpxN9zY7bb46bO+Zlc6PBYN0XX3ZNUtpNWyBfBI63cosBD/AGPeZdt4TxqV0AogGjBQm2GuzvzCNIjWLq06071eQuDxvJ3BE9FN4Krnnarcn4OqEJXe600qbIyjDDYO1K2Tfn6InGcgouru2QXbJ3a8rQyUwjGw3YhViXrYzqJS6V1v4TvGid8+psT/ivi28hqw5vuDev29whhZXGho0PzlDI7yJ5wJw6JdChTkNwfNCqEJxVty6ANot2RNsvTH1nuCkgzr0Ko5m7fDIFyJg/yB7QdfuHc42W7RL/TuaQITl4i2h5d7KjgBay60ihxvfgWcmz1VZHqDdOnNrUtn0VyhDe6MuKRuFz80u/wzqC0wLe5vtaLUwplafXM5Esz78qmpYOsknOEDX6lUrygaOMa0kp9Oel5uL6abv8vJCcLZV7igTmP6QuhMO/BeM4PxATU2WU4+i80brj8VDjTLVPlPI2k63ZvIndJcQGuq61GQhV0pgj6xqlCTepzsgYkWEGLFJDZh2Hk5DkN0zMLf37F/uyjUqgnC1vyv3EJLHtHIjBI3jbnLfkZ7l96kpcyAQpzdBY4pJZErUBL+juWk/rqtPYCAM5Pxauw+bmDtVyyJkRWX+UD6CFP6Pdq1uI6vgoI+mWa48ZoCz9JOQ95/7ykX85nkcQcrWm3ZQNbHC0B+lpI0SCYXXwn9cBCnwKsxElTO3qjV2CSSRca2yzX6I6/DE7CZipAZ3NRoC30/S923KwEZRSI2xHEVuRCmzAdoOeWv5KZjjBDNVml2lOcbG8UYInyVmUtQn3wqcvbsH70wlfmp/k0dVp/fz9nBou8iZlTo7Vh2WEUnt5mH9OXT4w0aliiUdyw1PF1rJ31a8LXedP7u9EB19pfaXXyPZ3Xoj/
  • Organization: GeometryFactory

Le Friday, April 14, 2017 5:05:36 AM CEST mikef a ?crit :
> I am using CGAL "make_surface_mesh" to create a mesh out of an ellipsoid
> function, then using OpenGL to draw it by plotting triangle by triangle. I
> have no clue what is going on...
>
> *Problem:* the plotted surface is weird, some triangle has color, some not,
> some are like holes.
>
> *My codes for mesh generation:*
> Surface_3 surface(earth_function, // pointer to
> function Sphere_3(CGAL::ORIGIN, 7000*7000));
> // bounding sphere
> // Note that "2." above is the *squared* radius of the bounding
> sphere!
> // defining meshing criteria
> CGAL::Surface_mesh_default_criteria_3 criteria(30., // angular
> bound
> 500, // radius bound
> 50); // distance bound
> // meshing surface
> CGAL::make_surface_mesh(c2t3, surface, criteria ,
> CGAL::Manifold_tag());
>
> *My codes for mesh plotting: *
> glNewList(EARTH_S, GL_COMPILE);
>
> Point_3 pt0, pt1, pt2, pt3;
> for (auto it = c2t3.facets_begin(); it != c2t3.facets_end(); it++)
> {
>
> pt0 = it->first->vertex((it->second) & 3)->point();
> pt1 = it->first->vertex((it->second + 1) & 3)->point();
> pt2 = it->first->vertex((it->second + 2) & 3)->point();
> pt3 = it->first->vertex((it->second + 3) & 3)->point();
>
> auto vv = pt1 - pt0;
> auto n = CGAL::normal(pt1, pt2, pt3);
> if (CGAL::angle(n, vv) == CGAL::ACUTE) { n = -n; }
> //auto n = ((it->second % 2 ) == 1)?CGAL::normal(pt1, pt2,
> pt3): CGAL::normal(pt1, pt3, pt2);

First: to get the oriented list of three points of a facets, you should use
the function tr.vertex_triple_index(i, j), a function in a base class of the
triangulation.

http://doc.cgal.org/latest/TDS_3/
classCGAL_1_1Triangulation__utils__3.html#a71288c8c2833f954a73090336ed60054

Second: the facets of a c2t3 are actually not oriented, and that means that
their orientation is random. That probably explains your rendering issues.
You should use the OpenGL lightening model "two sides", and disable the back-
culling.

--
Laurent Rineau, PhD
R&D Engineer at GeometryFactory http://www.geometryfactory.com/
Release Manager of the CGAL Project http://www.cgal.org/




Archive powered by MHonArc 2.6.18.

Top of Page