Subject: CGAL users discussion list
List archive
- From: mikef <>
- To:
- Subject: Re: [cgal-discuss] CGAL+OpenGL, incorrectly render mesh triangles
- Date: Fri, 14 Apr 2017 11:45:04 -0700 (PDT)
- Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None ; spf=SoftFail ; spf=None
- Ironport-phdr: 9a23:VtQz+BfRUm1OV+vnP2L4xIUUlGMj4u6mDksu8pMizoh2WeGdxcW/bR7h7PlgxGXEQZ/co6odzbGH7+a4ASQp2tWoiDg6aptCVhsI2409vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6nK94iQPFRrhKAF7Ovr6GpLIj8Swyuu+54Dfbx9GiTe5br5+Ngm6oRnMvcQKnIVuLbo8xAHUqXVSYeRWwm1oJVOXnxni48q74YBu/SdNtf8/7sBMSar1cbg2QrxeFzQmLns65Nb3uhnZTAuA/WUTX2MLmRdVGQfF7RX6XpDssivms+d2xSeXMdHqQb0yRD+v6bpgRh31hycdLzM3/mHZhNJzgq1ZrhKvuhNwzJLbboyOKPpzfLnQcc8GSWZdQMpcUTFKDIOmb4sICuoMJeNYr4j+p1QQoxu1GA6hBO3gyj5Im3P6wa433v8uEQHDxgMgHtYOvG7Io9XyMacfSOa4x7TGwzXEavNZwzb96I7QfxAnu/6DRql/cc7PxkU1CwzFiVCQpZTkPzOTzOQNsnKU4/BuVeK1k2Iotw5xrSKrxss2jYnJnI0VxkjL9Spnx4Y1IMO3SFJhYd+kHptfrT2VN5dxQsM4Q2Bkojo1yroDuZO9YSMEy4wnygbCZ/GGbYSE+AzvWeafLDtimX5odryyiwy9/EWu0uHwS8i53EhQoiZbktTBuGoB2wHd58WJUPdw/kWs1DCS3A7J8O5EO1o7la/DJp4h3LEwkp0TvFzGHi74n0X2lqyWel8i+uey8OvoebHmqYGGO4BojQH+N7wims25AesmLggDR3WX9OWi2LH540H0QLtHgucrnqTXvp3WP8sWq6ChDw9QyIkj6hK/Dzm80NQfmHkKNFxFeB2HjoT0J13DI+v1Dfi6g1u2kTdrw+rKMaHmApXINnTDiqvufa5h605Azwo+1cxQ551OBbEFOf78R07xtMfEAR8kKAy02P3qCM5914MbQWKAGLWVMKLUsV+S5+IgOfOAZIEPuGW1Fv4++vS7jWMlgURPOu6yzJ4PYTa5GO5nKgOXez33k9IZGCALuAQ5C+flgVnHXT9IbGupRPEB4ComAtemEZvbXdLqx6eQ2T+yWJxQfGFPTF6WVmz5cp2NHPYKZiXVKcBolnkIVKOqVpQ6hiyorxLwnrp7MvLPqGpfroPmzNEz5uvJlBh0+yYzFNWYy2jKTmd6mSQDSDYymax+ukdg0UzQ7a8tiPNREZlf5uhCTxwhHZ/a1e1zTd7oCSzbedLcTVelT9vuVT8+X4tpk/cBZk98H5OpiRWVjHniOKMci7HeXM98yanbxXWkf8s=
Laurent Rineau (CGAL/GeometryFactory) wrote
> 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/
>
>
> --
> You are currently subscribed to cgal-discuss.
> To unsubscribe or access the archives, go to
> https://sympa.inria.fr/sympa/info/cgal-discuss
Laurent Rineau (CGAL/GeometryFactory) wrote
> 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/
>
>
> --
> You are currently subscribed to cgal-discuss.
> To unsubscribe or access the archives, go to
> https://sympa.inria.fr/sympa/info/cgal-discuss
Laurent Rineau (CGAL/GeometryFactory) wrote
> 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/
>
>
> --
> You are currently subscribed to cgal-discuss.
> To unsubscribe or access the archives, go to
> https://sympa.inria.fr/sympa/info/cgal-discuss
Thanks for reply.
I tried using vertex_triple_index in this way. It doesn't help.
pt0 = ch->vertex(i&3)->point();
pt1 = ch->vertex(tr.vertex_triple_index(i, 0))->point();
pt2 = ch->vertex(tr.vertex_triple_index(i, 1))->point();
pt3 = ch->vertex(tr.vertex_triple_index(i, 2))->point();
I added glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE), still no luck.
I saw your post somewhere else about the coherent normal of faces, so I
added the following codes in hope of fixing the 2nd issue in your reply. But
it doesn't do any good.
auto vv = pt1 - pt0;
auto n = CGAL::normal(pt1, pt2, pt3);
if (CGAL::angle(n, vv) == CGAL::ACUTE) { n = -n; }
--
View this message in context:
http://cgal-discuss.949826.n4.nabble.com/CGAL-OpenGL-incorrectly-render-mesh-triangles-tp4662670p4662680.html
Sent from the cgal-discuss mailing list archive at Nabble.com.
- [cgal-discuss] CGAL+OpenGL, incorrectly render mesh triangles, mikef, 04/14/2017
- Re: [cgal-discuss] CGAL+OpenGL, incorrectly render mesh triangles, Ch'Gans, 04/14/2017
- Re: [cgal-discuss] CGAL+OpenGL, incorrectly render mesh triangles, Andreas Fabri, 04/14/2017
- Re: [cgal-discuss] CGAL+OpenGL, incorrectly render mesh triangles, mikef, 04/14/2017
- Re: [cgal-discuss] CGAL+OpenGL, incorrectly render mesh triangles, Andreas Fabri, 04/14/2017
- Re: [cgal-discuss] CGAL+OpenGL, incorrectly render mesh triangles, Laurent Rineau (CGAL/GeometryFactory), 04/14/2017
- Re: [cgal-discuss] CGAL+OpenGL, incorrectly render mesh triangles, mikef, 04/14/2017
- Re: [cgal-discuss] CGAL+OpenGL, incorrectly render mesh triangles, mikef, 04/14/2017
- Re: [cgal-discuss] CGAL+OpenGL, incorrectly render mesh triangles, mikef, 04/14/2017
- Re: [cgal-discuss] CGAL+OpenGL, incorrectly render mesh triangles, Julia Fischer, 04/18/2017
- Re: [cgal-discuss] CGAL+OpenGL, incorrectly render mesh triangles, mikef, 04/14/2017
- Re: [cgal-discuss] CGAL+OpenGL, incorrectly render mesh triangles, mikef, 04/14/2017
- Re: [cgal-discuss] CGAL+OpenGL, incorrectly render mesh triangles, mikef, 04/14/2017
- Re: [cgal-discuss] CGAL+OpenGL, incorrectly render mesh triangles, Ch'Gans, 04/14/2017
Archive powered by MHonArc 2.6.18.