Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

SbTesselator Class Reference

The SbTesselator class is used to tesselate polygons into triangles. More...

#include <Inventor/SbTesselator.h>

List of all members.

Public Methods

 SbTesselator (void(*callback)(void *v0, void *v1, void *v2, void *data)=NULL, void *userdata=NULL)
 ~SbTesselator (void)
void beginPolygon (SbBool keepVertices=FALSE, const SbVec3f &normal=SbVec3f(0.0f, 0.0f, 0.0f))
void addVertex (const SbVec3f &v, void *data)
void endPolygon (void)
void setCallback (void(*callback)(void *v0, void *v1, void *v2, void *data), void *data)


Detailed Description

The SbTesselator class is used to tesselate polygons into triangles.

SbTesselator is used within Coin to split polygons into triangles. It handles concave polygons, does Delaunay triangulation and avoids generating self-intersecting triangles.

Here's a simple example which shows how to tesselate a quad polygon with corners in <0, 0, 0>, <1, 0, 0>, <1, 1, 0> and <0, 1, 0>.

// Callback function for the tesselator. Called once for each
// generated triangle with the vertices.
static void
tess_cb(void * v0, void * v1, void * v2, void * cbdata)
{
  SbVec3f * vtx0 = (SbVec3f *)v0;
  SbVec3f * vtx1 = (SbVec3f *)v1;
  SbVec3f * vtx2 = (SbVec3f *)v2;
  (void)fprintf(stdout, "triangle: <%f, %f, %f> <%f, %f, %f> <%f, %f, %f>\n",
                (*vtx0)[0], (*vtx0)[1], (*vtx0)[2],
                (*vtx1)[0], (*vtx1)[1], (*vtx1)[2],
                (*vtx2)[0], (*vtx2)[1], (*vtx2)[2]);

  // Do stuff with triangle here.
}


static SbVec3f vertices[] = {
  SbVec3f(1, 0, 0), SbVec3f(1, 1, 0),
  SbVec3f(0, 1, 0), SbVec3f(0, 0, 0)
};

SbTesselator mytesselator(tess_cb, NULL);
mytesselator.beginPolygon();
for (int i=0; i < 4; i++)
  mytesselator.addVertex(vertices[i], &vertices[i]);
mytesselator.endPolygon();

The call to SbTesselator::endPolygon() triggers the SbTesselator to spring into action, calling the tess_cb() function for each triangle it generates.

The reason we use 2 arguments to SbTesselator::addVertex() and passes void pointers for the vertices to the callback function is to make it possible to have more complex structures than just the coordinates themselves (as in the example above), like material information, lighting information or whatever other attributes your vertices have.

This class is not part of the original Open Inventor API.

(Another option for tesselating polygons is the tesselator of the GLU library. It has some features not part of SbTesselator (like handling hulls), but the GLU library is known to have bugs in various implementations and doesn't do Delaunay triangulation.)


Constructor & Destructor Documentation

SbTesselator::SbTesselator void(* callback)(void *v0, void *v1, void *v2, void *data) = NULL,
void * userdata = NULL
 

Initializes a tesselator. The callback argument specifies a function which will be called for each triangle returned by the tesselator. The callback function will get three pointers to each vertex and the userdata pointer. The vertex pointers are specified in the SbTesselator::addVertex() method.

SbTesselator::~SbTesselator void
 

Destructor.


Member Function Documentation

void SbTesselator::beginPolygon SbBool keepVerts = FALSE,
const SbVec3f & normal = SbVec3f(0.0f, 0.0f, 0.0f)
 

Initializes new polygon.

You can explicitly set the polygon normal if you know what it is. Otherwise it will be calculated internally.

If keepVerts is TRUE, all vertices will be included in the returned triangles, even though this might lead to triangles without area.

void SbTesselator::addVertex const SbVec3f & v,
void * data
 

Adds a new vertex to the polygon. data will be returned as a vertex in the callback-function.

void SbTesselator::endPolygon void
 

Signals the tesselator to begin tesselating. The callback function specified in the constructor (or set using the SbTesselator::setCallback() method) will be called for each triangle before returning.

void SbTesselator::setCallback void(* callback)(void *v0, void *v1, void *v2, void *data),
void * data
 

Sets the callback function for this tesselator.


The documentation for this class was generated from the following files:
Generated at Tue Mar 5 03:31:31 2002 for Coin by doxygen1.2.9 written by Dimitri van Heesch, © 1997-2001