[Insight-users] How to render ITK mesh in OpenGL-based environment?

Luis Ibanez luis . ibanez at kitware . com
Tue, 12 Aug 2003 19:11:54 -0400


Hi Bjorn,

You can retrieve the vertices of the itk::Mesh using the
method described in the software guide

    http://www . itk . org/ItkSoftwareGuide . pdf

Section 4.2.2 "Getting access to Points" pdf-page 73.


The generations of Normals would have to be done manually,
using as a guide the vectors between one vertex and its
neighbors.

The neighborhood relationship between vertices, is mangaged
in the case of the Morphogenesis application, by having
itk::PolygonCells on top of every node of the mesh.
These polygonal cells inherit the capability of having an
array of nodes (the neighbors).

In this particular application (Morphogenesis), these
itkVertexCells are called "Voronoi regions", although they
are not technically voronoi regions (that is the do not
satisfy the geometrical properties).

In order to compute the normal you could compute a mean
of the cross products between the vector irradiating from
the current node.

It will be much simpler just to generate a VTK PolyData
as Bill suggested and let VTK generate the normals for you.


If you want to have a better idea of what the Morphogenesis
application is doing, please take a look at
http://www . itk . org/HTML/Morphogenesis . htm


Regards,


   Luis


-------------------------
Bjorn Hanch Sollie wrote:
> On Thu, 7 Aug 2003, Luis Ibanez wrote:
> 
> Hi Luis,
> 
> Thank you so much for replying!
> 
> 
>>You may want to take a look at the method
>>
>>    void CellularAggregate::Draw(void) const
>>
>>in CellularAggregate.cxx
> 
> 
> Done, and I do see how to use the basic mesh operators to retrieve the
> mesh data.  I do, however, still have some problems understanding
> exactly what the rest of the code does (besides drawing, of course).
> What I need is to construct a data buffer that is to be drawn by the
> (relatively straightforward) OpenGL code listed below.  How exactly do
> I retrieve the vertices (and what do the VoroniRegion data types have
> to do with that anyway; a bit confusing)?  How do I create the needed
> normals from the available mesh data?  I will be very grateful for
> hints and help on how to do this.
> 
>   while(npolys--)
>   {
>     glBegin( GL_TRIANGLE_STRIP );
>     glColor3fv((float*)&data[(PNTINTS*0)+OFFSET_COLOR]);
>     glNormal3fv((float*)&data[(PNTINTS*0)+OFFSET_NORMAL]);
>     glVertex3fv((float*)&data[(PNTINTS*0)+OFFSET_POINT]);
>     glColor3fv((float*)&data[(PNTINTS*1)+OFFSET_COLOR]);
>     glNormal3fv((float*)&data[(PNTINTS*1)+OFFSET_NORMAL]);
>     glVertex3fv((float*)&data[(PNTINTS*1)+OFFSET_POINT]);
>     glColor3fv((float*)&data[(PNTINTS*3)+OFFSET_COLOR]);
>     glNormal3fv((float*)&data[(PNTINTS*3)+OFFSET_NORMAL]);
>     glVertex3fv((float*)&data[(PNTINTS*3)+OFFSET_POINT]);
>     glColor3fv((float*)&data[(PNTINTS*2)+OFFSET_COLOR]);
>     glNormal3fv((float*)&data[(PNTINTS*2)+OFFSET_NORMAL]);
>     glVertex3fv((float*)&data[(PNTINTS*2)+OFFSET_POINT]);
>     glEnd();
>     data += PNTINTS*4;
>   }
> 
> Thanks in advance,
> 
> -Beorn