Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] Render a Polyhedron_3 using OpenGL vertex arrays

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] Render a Polyhedron_3 using OpenGL vertex arrays


Chronological Thread 
  • From: "alvaro cuno" <>
  • To:
  • Subject: Re: [cgal-discuss] Render a Polyhedron_3 using OpenGL vertex arrays
  • Date: Fri, 7 Dec 2007 18:24:27 -0200
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=QrxERapvOikRyTnMtxTXFPkpxOUuWQWslVUKdnS0YoqpqQB2W3T3cz0oCBPuLY+ndmjM4iJNxe1tXgxWSv6OnZ0V+Yh2Iw0HJWecBHDPLmbCclQ7EYCLYH7yDHDVB9uevD2t5bdUlPDQgIbHH8CsXq2yZqZsoUxxzBKuTNnT/Y0=

Hi Andreas, thanks for your suggestions! ... with those, I have coded
a simple example to illustrate how to render "directly" a Polyhedron_3
using OpenGL Vertex Arrays.

Everyone can download the source code here:
http://www.cos.ufrj.br/~aecp/code/meshviewer.tar.gz

I don't know if it is possible to do more improvements (do you have
some suggestions?). I would like to extend it for using with VBO too,
somebody is interested?

I think the CGAL+OpenGL combination is great!

Alvaro
COPPE-UFRJ

On 08/11/2007, Andreas Fabri
<>
wrote:
>
> Hi Alvaro,
>
> alvaro cuno wrote:
> > Hi Andreas,
> >
> > At the moment, I am using this alternative:
> > - I have derived a SurfaceMesh class from
> > CGAL::HalfedgeDS_vector<Kernel, HDSItems>. As a member of this class I
> > have a linear array storing the vertex positions.
> > - For my Vertex structure I avoid to instance a position (without
> > Point). With this I avoid wasting memory.
> > - I send the array of positions to the OpenGL as the third parameter
> > of the function glVertexPointer.
> > - As you can see, I am using the HDS only for the connectivity
> > information.
> >
> > This option works very good. However, I don't like because is not
> > elegant. Requires some additional tricks. For example, It is necessary
> > to code I/O operators, etc.
> >
> > For my case (the number (2)), I think there is a more elegant solution
> > using the Polyhedron_3 directly. But I have some doubts:
> >
> > - Using the HalfedgeDS_vector it is possible to assert that the
> > structures will be in consecutive order in the memory?
>
> It's guaranteed that all vertices will be consecutive.
> That's what it is about.
>
> > - The coordinates of a Point_3 are in consecutive order?
> Yes, but they are not necessarily inside the Point object.
> This depends on the kernel: If you use CGAL::Cartesian, the points are
> reference counted, that is the real x,y,z coordinates are somewhere
> in memory, but certainly not in the vector of vertices holding
> the points.
>
> So it needs Simple_cartesian<double> or Filtered_kernel<
> Simple_cartesian<double> >.
> Also the Exact_predicates_inexact_constructions_kernel should be ok.
>
> > - For computing the STRIDE value I have to use "sizeof(Vertex)" or
> > "sizeof(PolyhedronItems_3)" or ... ?
>
> sizeof(Vertex) might be fine, but I didn't try it out.
>
> andreas
>
> >
> > I think that for fast rendering of Polyhedron_3 using opengl we need only:
> > 1- a pointer to the first position of vertex positions
> > 2- these positions must be in consecutive order in the system memory, and
> > 3- a STRIDE value
> >
> > What do you think? Could you give more suggestions, please?
> >
> > Alvaro Cuno
> > COPPE-UFRJ
> >
> > PD: I have the same question of Laurent Rineau. For example, the
> > rendering of sharp features requires normals per vertex. Anyone know
> > to do this for OpenGL efficiently?
> >
> > On 07/11/2007, Andreas Fabri
> > <>
> > wrote:
> >> Hello,
> >>
> >> I see two options. By default the polyhedron uses a halfedge data
> >> structure
> >> where the vertices, halfedges, and faces are stored in a list. For a
> >> list
> >> of vertices a stride will not do it, as the list elements can be anywhere
> >> in memory. But you could have your own Vertex class, and an array for
> >> your
> >> points coordinates, and you let your vertex have a pointer in the array
> >> instead of directly storing the point.
> >>
> >> The second option is to use the fact that the halfedge data structure
> >> is a template parameter of the Polyhedron, and there is a class
> >> HalfedgeDS_vector.
> >> It stores the vertices, halfedges, and faces in std::vectors. The
> >> limitation
> >> is that you cannot delete vertices, but you should be able to compute
> >> the stride
> >> even if this is not offered by the API. For more information on
> >> HalfedgeDS_vector:
> >> http://www.cgal.org/Manual/3.3/doc_html/cgal_manual/Polyhedron/Chapter_main.html#Subsection_12.3.5
> >>
> >> I would be glad to get your feedback once it works.
> >>
> >> andreas
> >>
> >>
> >>
> >> wrote:
> >>> Dear all,
> >>>
> >>> I would like to render a Polyhedron_3 mesh with +100K vertices in
> >>> interactive FPS using OpenGL.
> >>>
> >>> (1) If the mesh is static, there is not problem:
> >>> - I can use a display list, build vertex arrays or use VBO (looping on
> >>> the Vertex_iterator, Facet_iterator). This is not my case.
> >>>
> >>> (2) If the mesh geometry is dynamic (but the connectivity is static)
> >>> - It is possible to build a vertex array or VBO each time the geometry
> >>> is modified. However, I wouldn't like to loop on the iterators to build
> >>> the new opengl vertex array every time because is not efficient. I
> >>> would like to pass the pointer to the mesh geometry directly to OpenGL.
> >>> I would like something similar to (mesh is a pointer to a Polyhedron_3
> >>> object):
> >>>
> >>> ###############################
> >>> typedef Polyhedron_3::Point_iterator Point_iterator;
> >>> Point_iterator pi = mesh->points_begin();
> >>>
> >>> glEnableClientState(GL_VERTEX_ARRAY);
> >>> glVertexPointer(3, GL_FLOAT, sizeof(SOMESTRIDEVALUE), &(*pi)[0]);
> >>> glDrawElements(GL_TRIANGLES, 3*mesh->nfaces(), GL_UNSIGNED_INT,
> >>> &faces[0]);
> >>> ###############################
> >>>
> >>> ..... It is possible to do this? how to determine the STRIDE value?
> >>>
> >>>
> >>> (3) If the geometry and the connectivity is dynamic
> >>> - This is not my case
> >>>
> >>> Thanks in advance,
> >>>
> >>> Alvaro Cuno
> >>> COPPE-UFRJ
> >> --
> >> You are currently subscribed to cgal-discuss.
> >> To unsubscribe or access the archives, go to
> >> https://lists-sop.inria.fr/wws/info/cgal-discuss
> >>
> --
> You are currently subscribed to cgal-discuss.
> To unsubscribe or access the archives, go to
> https://lists-sop.inria.fr/wws/info/cgal-discuss
>



Archive powered by MHonArc 2.6.16.

Top of Page