Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52008 - in sandbox-branches/andreo/guigl: boost/guigl boost/guigl/platform/impl libs/guigl/example
From: andreytorba_at_[hidden]
Date: 2009-03-27 07:10:35


Author: andreo
Date: 2009-03-27 07:10:33 EDT (Fri, 27 Mar 2009)
New Revision: 52008
URL: http://svn.boost.org/trac/boost/changeset/52008

Log:
added gt::tess ggl::tess
added polygon drawing in ggl.cpp example
Text files modified:
   sandbox-branches/andreo/guigl/boost/guigl/ggl.hpp | 110 ++++++++++++++++++++++++++-
   sandbox-branches/andreo/guigl/boost/guigl/platform/impl/tess.hpp | 158 ++++++++++++++++++++++-----------------
   sandbox-branches/andreo/guigl/libs/guigl/example/ggl.cpp | 41 +++-------
   3 files changed, 205 insertions(+), 104 deletions(-)

Modified: sandbox-branches/andreo/guigl/boost/guigl/ggl.hpp
==============================================================================
--- sandbox-branches/andreo/guigl/boost/guigl/ggl.hpp (original)
+++ sandbox-branches/andreo/guigl/boost/guigl/ggl.hpp 2009-03-27 07:10:33 EDT (Fri, 27 Mar 2009)
@@ -30,7 +30,9 @@
 
 #include <geometry/core/cs.hpp>
 #include <geometry/geometries/register/register_point.hpp>
+#include <geometry/algorithms/foreach.hpp>
 #include <boost/static_assert.hpp>
+#include <boost/foreach.hpp>
 
 // GEOMETRY_REGISTER_POINT_2D needs type without '::'
 typedef boost::guigl::position_type boost__guigl__position_type;
@@ -90,6 +92,80 @@
 
 namespace boost{ namespace guigl { namespace ggl {
 
+ template<class Point>
+ class tess : public boost::guigl::gl::tess
+ {
+ public:
+ typedef boost::guigl::gl::tess base_type;
+ typedef Point point_type;
+
+ private:
+
+ static void CALLBACK begin_cb(GLenum which)
+ {
+ glBegin(which);
+ }
+
+ static void CALLBACK end_cb()
+ {
+ glEnd();
+ }
+ static void CALLBACK vertex_cb(const GLvoid *data)
+ {
+ point_type const& pt =
+ *((point_type const*)data);
+
+ boost::guigl::ggl::vertex(pt);
+ }
+
+ static void CALLBACK error_cb(GLenum error_code)
+ {
+ BOOST_ASSERT(!gluGetString(error_code));
+ }
+
+ public:
+ tess() {
+ if(base_type::operator !())
+ throw std::runtime_error("invalid tess");
+
+ begin_callback(begin_cb);
+ end_callback(end_cb);
+ vertex_callback(vertex_cb);
+ error_callback(error_cb);
+ }
+
+ class contour : public base_type::contour
+ {
+ private:
+
+ inline void init_coordinates(double coord[3], point_type const& pt, boost::mpl::int_<2>)
+ {
+ coord[0] = geometry::get<0>(pt);
+ coord[1] = geometry::get<1>(pt);
+ coord[2] = 0.0;
+ }
+
+ inline void init_coordinates(double coord[3], point_type const& pt, boost::mpl::int_<3>)
+ {
+ coord[0] = geometry::get<0>(pt);
+ coord[1] = geometry::get<1>(pt);
+ coord[2] = geometry::get<2>(pt);
+ }
+
+ public:
+ inline explicit contour(polygon const& pg)
+ : base_type::contour(pg) {}
+
+ inline void operator()(point_type const& pt)
+ {
+ double coord[3];
+ init_coordinates(coord, pt, geometry::dimension<point_type>());
+ base_type::contour::operator()(coord, (void*)&pt);
+ }
+
+ };
+ };
+
     namespace dispatch
     {
         template <typename Tag, typename G>
@@ -348,12 +424,13 @@
                 (void))
                 vertex(G const& g)
             {
- ggl::vertex(geometry::exterior_ring(g));
+ geometry::for_each_point(g, vertex_drawer());
+ //ggl::vertex(geometry::exterior_ring(g));
 
- std::for_each(
- boost::begin(geometry::interior_rings(g)),
- boost::end(geometry::interior_rings(g)),
- vertex_drawer());
+ //std::for_each(
+ // boost::begin(geometry::interior_rings(g)),
+ // boost::end(geometry::interior_rings(g)),
+ // vertex_drawer());
             }
 
             static inline
@@ -361,6 +438,29 @@
                 (void))
                 draw(G const& g)
             {
+ typedef
+ typename geometry::point_type<G>::type
+ point_type;
+ typedef
+ typename geometry::ring_type<G>::type
+ ring_type;
+ typedef
+ ::boost::guigl::ggl::tess<point_type>
+ tess_type;
+
+ tess_type t;
+ typename tess_type::polygon p(t);
+ {
+ typename tess_type::contour c(p);
+ BOOST_FOREACH(point_type const& pt, geometry::exterior_ring(g))
+ c(pt);
+ }
+ BOOST_FOREACH(ring_type const& ring, geometry::interior_rings(g))
+ {
+ typename tess_type::contour c(p);
+ BOOST_FOREACH(point_type const& pt, ring)
+ c(pt);
+ }
             }
         };
 

Modified: sandbox-branches/andreo/guigl/boost/guigl/platform/impl/tess.hpp
==============================================================================
--- sandbox-branches/andreo/guigl/boost/guigl/platform/impl/tess.hpp (original)
+++ sandbox-branches/andreo/guigl/boost/guigl/platform/impl/tess.hpp 2009-03-27 07:10:33 EDT (Fri, 27 Mar 2009)
@@ -10,6 +10,7 @@
 #define BOOST__GUIGL__GL__TESS_HPP
 
 #include <boost/guigl/types.hpp>
+#include <boost/guigl/platform/glu.hpp>
 
 namespace boost{ namespace guigl { namespace gl {
 
@@ -17,88 +18,103 @@
     private:
         GLUtesselator *m_tess;
         friend class polygon;
-
- static void CALLBACK begin_cb(GLenum which)
- {
- glBegin(which);
- }
-
- static void CALLBACK end_cb() {
- glEnd();
- }
- static void CALLBACK vertex_cb(const GLvoid *data)
- {
- boost::guigl::position_type* pos =
- (boost::guigl::position_type*)data;
- glVertex2d(pos->x, pos->y);
- }
-
- static void CALLBACK error_cb(GLenum errorCode)
- {
- BOOST_ASSERT(!gluErrorString(errorCode));
- //const GLubyte *errorStr;
- //errorStr = gluErrorString(errorCode);
- //std::cerr << "[ERROR]: " << errorStr << std::endl;
- }
-
     public:
- tess() {
- m_tess = gluNewTess(); // create a tessellator
- BOOST_ASSERT(m_tess);
- if(!m_tess) return ;
- gluTessCallback(m_tess, GLU_TESS_BEGIN, (void (CALLBACK *)())&tess::begin_cb);
- gluTessCallback(m_tess, GLU_TESS_END, (void (CALLBACK *)())&tess::end_cb);
- gluTessCallback(m_tess, GLU_TESS_ERROR, (void (CALLBACK *)())&tess::error_cb);
- gluTessCallback(m_tess, GLU_TESS_VERTEX, (void (CALLBACK *)())&tess::vertex_cb);
- }
- ~tess() { gluDeleteTess(m_tess); }
+ tess();
+ ~tess();
+
+ inline bool operator!() const;
+ GLUtesselator * get() const;
 
- bool operator!() const {return !m_tess;}
+ void begin_callback(void (CALLBACK *cb)(GLenum which));
+ void end_callback(void (CALLBACK *cb)());
+ void vertex_callback(void (CALLBACK *cb)(void const* data));
+ void error_callback(void (CALLBACK *cb)(GLenum error_code));
 
+ class contour;
         class polygon : boost::noncopyable {
         private:
             GLUtesselator *m_tess;
- friend class contour;
+ friend contour;
 
         public:
- explicit polygon(tess const& t)
- : m_tess(t.m_tess)
- {
- BOOST_ASSERT(m_tess);
- gluTessBeginPolygon(m_tess, 0);
- }
- ~polygon(){ gluTessEndPolygon(m_tess); }
-
- class contour : boost::noncopyable {
- private:
- GLUtesselator *m_tess;
-
- public:
- explicit contour(polygon const& pg)
- : m_tess(pg.m_tess)
- {
- BOOST_ASSERT(m_tess);
- gluTessBeginContour(m_tess);
- }
- ~contour(){ gluTessEndContour(m_tess); }
-
- inline void operator()(double coord[3], void *data) const {
- gluTessVertex(m_tess, coord, data);
- }
-
- inline void operator()(double coord[3]) const {
- (*this)(coord, coord);
- }
-
- inline void operator()(boost::guigl::position_type const& pos) const {
- double coord[3] = {pos.x, pos.y, 0.};
- (*this)(coord, (void*)&pos);
- }
- };
+ explicit polygon(tess const& t);
+ ~polygon();
         };
- };
 
+ class contour : boost::noncopyable {
+ private:
+ GLUtesselator *m_tess;
+
+ public:
+ explicit contour(polygon const& pg);
+ ~contour();
+
+ void operator()(double coord[3], void *data);
+ void operator()(double coord[3]);
+ };
+ };
 
+ ////////////////////////////////////////////////////////////////////////////////
+ inline tess::tess()
+ {
+ m_tess = gluNewTess();
+ BOOST_ASSERT(m_tess);
+ if(!m_tess) return ;
+ }
+
+ inline tess::~tess() { gluDeleteTess(m_tess); }
+
+ inline bool tess::operator!() const {return !m_tess;}
+
+ //inline GLUtesselator * tess::get() const {return m_tess;}
+
+ inline void tess::begin_callback(void (CALLBACK * cb)(GLenum which))
+ {
+ gluTessCallback(m_tess, GLU_TESS_BEGIN, (void (CALLBACK *)())cb);
+ }
+
+ inline void tess::end_callback(void (CALLBACK *cb)())
+ {
+ gluTessCallback(m_tess, GLU_TESS_END, cb);
+ }
+
+ inline void tess::vertex_callback(void (CALLBACK *cb)(void const* data))
+ {
+ gluTessCallback(m_tess, GLU_TESS_VERTEX, (void (CALLBACK *)())cb);
+ }
+
+ inline void tess::error_callback(void (CALLBACK *cb)(GLenum error_code))
+ {
+ gluTessCallback(m_tess, GLU_TESS_ERROR, (void (CALLBACK *)())cb);
+ }
+
+ ////////////////////////////////////////////////////////////////////////////////
+ inline tess::polygon::polygon(tess const& t)
+ : m_tess(t.m_tess)
+ {
+ BOOST_ASSERT(m_tess);
+ gluTessBeginPolygon(m_tess, 0);
+ }
+ inline tess::polygon::~polygon(){ gluTessEndPolygon(m_tess); }
+
+ ////////////////////////////////////////////////////////////////////////////////
+ inline tess::contour::contour(polygon const& pg)
+ : m_tess(pg.m_tess)
+ {
+ BOOST_ASSERT(m_tess);
+ gluTessBeginContour(m_tess);
+ }
+ inline tess::contour::~contour(){ gluTessEndContour(m_tess); }
+
+ inline void tess::contour::operator()(double coord[3], void *data)
+ {
+ gluTessVertex(m_tess, coord, data);
+ }
+
+ inline void tess::contour::operator()(double coord[3])
+ {
+ (*this)(coord, coord);
+ }
 }}}
 
 #endif // BOOST__GUIGL__GL__TESS_HPP

Modified: sandbox-branches/andreo/guigl/libs/guigl/example/ggl.cpp
==============================================================================
--- sandbox-branches/andreo/guigl/libs/guigl/example/ggl.cpp (original)
+++ sandbox-branches/andreo/guigl/libs/guigl/example/ggl.cpp 2009-03-27 07:10:33 EDT (Fri, 27 Mar 2009)
@@ -94,45 +94,30 @@
 
         // polygon
         geometry::polygon<position_type> pg;
+
+ // making outer contour
         pg.outer() +=
             point<LT>(),
             point<RT>(),
             point<RB>(),
             point<LB>();
+
+ // making inner contour
         pg.inners().resize(1);
         std::copy(v.begin(), v.end(), std::back_inserter(pg.inners().back()));
- geometry::correct(pg);
 
- //gl::point_size(10);
- //gl::color(red());
- //glBegin(GL_POINTS);
- //ggl::vertex(pg);
- //glEnd();
+ // correct polygon
+ geometry::correct(pg);
 
- GLuint id = glGenLists(1); // create a display list
- glNewList(id, GL_COMPILE);
+ // drawing
         gl::color(red(0.5));
+ ggl::draw(pg);
 
- {
- gl::tess t;
- gl::tess::polygon p(t);
- {
- gl::tess::polygon::contour c(p);
- BOOST_FOREACH(position_type const& pos, pg.outer())
- c(pos);
- }
- BOOST_FOREACH(
- geometry::linear_ring<position_type> const& ring,
- pg.inners())
- {
- gl::tess::polygon::contour c(p);
- BOOST_FOREACH(position_type const& pos, ring)
- c(pos);
- }
- }
- glEndList();
-
- glCallList(id);
+ gl::color(blue(0.5));
+ gl::point_size(10);
+ glBegin(GL_POINTS);
+ ggl::vertex(pg);
+ glEnd();
     }
 
     BOOST_GUIGL_WIDGET_DRAW_IMPL(my_widget);


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk