39 VL_DEBUG_SET_OBJECT_NAME()
54 if (!append_tessellated_tris)
63 vl::Log::error(
"Tessellator::tessellate(): no contours specified.\n");
67 GLUtesselator* tobj = gluNewTess();
69 gluTessCallback(tobj, GLU_TESS_BEGIN_DATA, (callback_type)
tessBeginData);
70 gluTessCallback(tobj, GLU_TESS_VERTEX_DATA, (callback_type)
tessVertexData);
71 gluTessCallback(tobj, GLU_TESS_COMBINE_DATA, (callback_type)
tessCombineData);
72 gluTessCallback(tobj, GLU_TESS_END, (callback_type)
tessEnd);
73 gluTessCallback(tobj, GLU_TESS_ERROR, (callback_type)
tessError);
77 gluTessProperty(tobj, GLU_TESS_BOUNDARY_ONLY,
boundaryOnly() ? GL_TRUE : GL_FALSE);
78 gluTessProperty(tobj, GLU_TESS_TOLERANCE,
tolerance());
79 gluTessProperty(tobj, GLU_TESS_WINDING_RULE,
windingRule());
83 gluTessBeginPolygon(tobj,
this);
84 for(
unsigned cont=0, idx=0; cont<
mContours.size(); ++cont)
86 gluTessBeginContour(tobj);
87 for(
int i=0; i<
mContours[cont]; ++i, ++idx)
89 gluTessEndContour(tobj);
91 gluTessEndPolygon(tobj);
95 for(
unsigned cont=0, idx=0; cont<
mContours.size(); ++cont)
97 gluTessBeginPolygon(tobj,
this);
98 gluTessBeginContour(tobj);
99 for(
int i=0; i<
mContours[cont]; ++i, ++idx)
101 gluTessEndContour(tobj);
102 gluTessEndPolygon(tobj);
108 for(
unsigned fan=0; fan<
mFans.size(); ++fan)
109 for(
unsigned iv =1; iv<
mFans[fan].size()-1; ++iv)
117 for(
unsigned strip=0; strip<
mTriStrips.size(); ++strip)
118 for(
unsigned iv=0; iv<
mTriStrips[strip].size()-2; ++iv)
178 if(type == GL_TRIANGLES)
183 if(type == GL_TRIANGLE_FAN)
184 tessellator->
mFans.resize( tessellator->
mFans.size() + 1 );
186 if(type == GL_TRIANGLE_STRIP)
189 if(type == GL_LINE_LOOP)
193 Log::error(
"Tessellator::beginData() unknown primitive.\n");
203 tessellator->
mFans.back().push_back( (
fvec3)(*vec) );
212 Log::error(
"Tessellator::vertexData() unknown primitive.\n");
219 vec->
x() = coords[0];
220 vec->
y() = coords[1];
221 vec->
z() = coords[2];
232 const GLubyte* estring = gluErrorString(errno);
const std::vector< fvec3 > & tessellatedTris() const
A set of triangles representing the tessellated polygon.
Tessellates a complex polygon defined by a set of outlines into a set of triangles that can be render...
Vector3< float > fvec3
A 3 components vector with float precision.
bool boundaryOnly() const
See gluTessProperty documentation (GLU_TESS_BOUNDARY_ONLY)
static void CALLBACK tessBeginData(GLenum type, Tessellator *tessellator)
A simple String formatting class.
static void warning(const String &message)
Use this function to provide information about situations that might lead to errors or loss of data...
std::vector< fvec3 > mTessellatedTris
const T_Scalar & z() const
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
void setVertexArray(ArrayAbstract *data)
Conventional vertex array.
static void CALLBACK tessError(GLenum errno)
std::vector< std::vector< fvec3 > > mFans
static void CALLBACK tessEnd(void)
static void CALLBACK tessVertexData(dvec3 *vec, Tessellator *tessellator)
const fvec3 & tessNormal() const
See gluTessNormal documentation.
bool mTessellateIntoSinglePolygon
std::vector< std::vector< fvec3 > > mTriStrips
double tolerance() const
See gluTessProperty documentation (GLU_TESS_TOLERANCE)
std::vector< std::vector< fvec3 > > mLineLoops
size_t size() const
Returns the number of elements of an array.
The Geometry class is a Renderable that implements a polygonal mesh made of polygons, lines and points.
Visualization Library main namespace.
~Tessellator()
Destructor.
static void CALLBACK tessCombineData(GLdouble coords[3], dvec3 *d[4], GLfloat w[4], dvec3 **dataOut, Tessellator *tessellator)
The Vector3 class is a template class that implements a generic 3 components vector, see also vl::fvec3, vl::dvec3, vl::uvec3, vl::ivec3, vl::svec3, vl::usvec3, vl::bvec3, vl::ubvec3.
void initFrom(const std::vector< T_VectorType > &vector)
std::vector< int > mContours
void freeCombinedVertices()
Vector3< double > dvec3
A 3 components vector with double precision.
const T_Scalar & y() const
bool tessellateIntoSinglePolygon() const
void computeNormals(bool verbose=false)
Computes the normals in a "smooth" way, i.e.
Tessellator()
Constructor.
ETessellationWinding windingRule() const
See gluTessProperty documentation (GLU_TESS_WINDING_RULE)
ref< Geometry > tessellateGeometry(bool append_tessellated_tris=false)
Utility function that calls tessellate() and creates a Geometry with the tessellated triangles...
std::vector< dvec3 *> mCombinedVertices
const T_Scalar & x() const
The ref<> class is used to reference-count an Object.
std::vector< dvec3 > mContourVerts
Wraps the OpenGL function glDrawArrays().
ETessellationWinding mWindingRule
bool tessellate(bool append_tessellated_tris=false)
Collection< DrawCall > & drawCalls()
Returns the list of DrawCall objects bound to a Geometry.