diff --git a/wrap/gl/glu_tesselator.h b/wrap/gl/glu_tesselator.h new file mode 100644 index 00000000..bb0fbcf0 --- /dev/null +++ b/wrap/gl/glu_tesselator.h @@ -0,0 +1,246 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +/**************************************************************************** + History + +$Log: not supported by cvs2svn $ + + +****************************************************************************/ + +#ifndef __VCGLIB_GLU_TESSELATOR_H +#define __VCGLIB_GLU_TESSELATOR_H + +#include +#include + +namespace vcg +{ + +class glu_tesselator +{ + public: + + typedef glu_tesselator this_type; + + /* + Works with Point2 and Point3; + + sample usage: + + // tesselation input: each outline represents a polygon contour + std::vector< std::vector > outlines = ...; + + // tesselation output (triangles indices) + std::vector indices; + + // compute triangles indices + glu_tesselator::tesselate(outlines, indices); + + // unroll input contours points + std::vector points; + + for (size_t i=0; i + static inline void unroll(const std::vector< std::vector > & outlines, std::vector & points) + { + for (size_t i=0; i + static inline void tesselate(const std::vector< std::vector > & outlines, std::vector & indices) + { + tess_prim_data_vec t_data; + + this_type::do_tesselation(outlines, t_data); + + int k = 0; + for (size_t i=0; i indices; + + tess_prim_data(void) { } + tess_prim_data(GLenum t) : type(t) { } + }; + + typedef std::vector tess_prim_data_vec; + + static void CALLBACK begin_cb(GLenum type, void * polygon_data) + { + tess_prim_data_vec * t_data = (tess_prim_data_vec *)polygon_data; + t_data->push_back(tess_prim_data(type)); + } + + static void CALLBACK end_cb(void * polygon_data) + { + (void)polygon_data; + } + + static void CALLBACK vertex_cb(void * vertex_data, void * polygon_data) + { + tess_prim_data_vec * t_data = (tess_prim_data_vec *)polygon_data; + t_data->back().indices.push_back((int)vertex_data); + } + + template + static void do_tesselation(const std::vector< std::vector > & outlines, tess_prim_data_vec & t_data) + { + GLUtesselator * tess = gluNewTess(); + + gluTessCallback(tess, GLU_TESS_BEGIN_DATA, (void (CALLBACK *)(void))(this_type::begin_cb)); + gluTessCallback(tess, GLU_TESS_END_DATA, (void (CALLBACK *)(void))(this_type::end_cb)); + gluTessCallback(tess, GLU_TESS_VERTEX_DATA, (void (CALLBACK *)(void))(this_type::vertex_cb)); + + void * polygon_data = (void *)(&t_data); + + GLdouble vertex[3]; + + int k = 0; + gluTessBeginPolygon(tess, polygon_data); + for (size_t i=0; i + static inline void get_position(const vcg::Point2 & p, GLdouble * d) + { + d[0] = (GLdouble)(p[0]); + d[1] = (GLdouble)(p[1]); + d[2] = (GLdouble)(0); + } + + template + static inline void get_position(const vcg::Point3 & p, GLdouble * d) + { + d[0] = (GLdouble)(p[0]); + d[1] = (GLdouble)(p[1]); + d[2] = (GLdouble)(p[2]); + } +}; + +} // end namespace vcg + +#endif // __VCGLIB_GLU_TESSELATOR_H