Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51987 - in sandbox-branches/andreo/guigl/libs/guigl: build/vc8ide example
From: andreytorba_at_[hidden]
Date: 2009-03-26 13:34:26


Author: andreo
Date: 2009-03-26 13:34:25 EDT (Thu, 26 Mar 2009)
New Revision: 51987
URL: http://svn.boost.org/trac/boost/changeset/51987

Log:
geometry
Added:
   sandbox-branches/andreo/guigl/libs/guigl/example/acceptor.hpp (contents, props changed)
   sandbox-branches/andreo/guigl/libs/guigl/example/graph.hpp (contents, props changed)
   sandbox-branches/andreo/guigl/libs/guigl/example/node_types.hpp (contents, props changed)
   sandbox-branches/andreo/guigl/libs/guigl/example/visitors.hpp (contents, props changed)
Text files modified:
   sandbox-branches/andreo/guigl/libs/guigl/build/vc8ide/example.vcproj | 36 ++
   sandbox-branches/andreo/guigl/libs/guigl/example/Jamfile | 2
   sandbox-branches/andreo/guigl/libs/guigl/example/geometry.cpp | 377 ++++++++++++++++++++++++++++++++++-----
   sandbox-branches/andreo/guigl/libs/guigl/example/geometry.hpp | 3
   sandbox-branches/andreo/guigl/libs/guigl/example/ggl.cpp | 43 ++-
   5 files changed, 385 insertions(+), 76 deletions(-)

Modified: sandbox-branches/andreo/guigl/libs/guigl/build/vc8ide/example.vcproj
==============================================================================
--- sandbox-branches/andreo/guigl/libs/guigl/build/vc8ide/example.vcproj (original)
+++ sandbox-branches/andreo/guigl/libs/guigl/build/vc8ide/example.vcproj 2009-03-26 13:34:25 EDT (Thu, 26 Mar 2009)
@@ -58,16 +58,36 @@
         <References>
         </References>
         <Files>
- <File
- RelativePath="..\..\example\custom_example.cpp"
+ <Filter
+ Name="autogeo"
>
- </File>
+ <File
+ RelativePath="..\..\example\acceptor.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\example\geometry.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\example\geometry.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\example\graph.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\example\node_types.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\example\visitors.hpp"
+ >
+ </File>
+ </Filter>
                 <File
- RelativePath="..\..\example\geometry.cpp"
- >
- </File>
- <File
- RelativePath="..\..\example\geometry.hpp"
+ RelativePath="..\..\example\custom_example.cpp"
>
                 </File>
                 <File

Modified: sandbox-branches/andreo/guigl/libs/guigl/example/Jamfile
==============================================================================
--- sandbox-branches/andreo/guigl/libs/guigl/example/Jamfile (original)
+++ sandbox-branches/andreo/guigl/libs/guigl/example/Jamfile 2009-03-26 13:34:25 EDT (Thu, 26 Mar 2009)
@@ -1,5 +1,5 @@
 #==================================---------------------------------------------
-# Copyright 2008 Stjepan Rajko
+# Copyright 2008, 2009 Stjepan Rajko, Andrey Torba
 #
 # Distributed under the Boost Software License, Version 1.0.
 # (See accompanying file LICENSE_1_0.txt or copy at

Added: sandbox-branches/andreo/guigl/libs/guigl/example/acceptor.hpp
==============================================================================
--- (empty file)
+++ sandbox-branches/andreo/guigl/libs/guigl/example/acceptor.hpp 2009-03-26 13:34:25 EDT (Thu, 26 Mar 2009)
@@ -0,0 +1,50 @@
+#ifndef BOOST_GUIGL_EXAMPLE_ACCEPTOR_HPP
+#define BOOST_GUIGL_EXAMPLE_ACCEPTOR_HPP
+
+#include <boost/shared_ptr.hpp>
+#include <boost/make_shared.hpp>
+
+class IVisitor;
+
+class IAcceptor
+ {
+ public:
+ virtual ~IAcceptor() {}
+ virtual void accept(int key, IVisitor const& v) = 0;
+ };
+
+template<class T>
+class Acceptor :
+ public IAcceptor,
+ public T
+ {
+ public:
+ explicit Acceptor(T const& obj) : T(obj) {}
+ void accept(int key, IVisitor const& v){
+ T& obj = *this;
+ v.visit(key, obj);
+ }
+
+ //T& get() {return m_obj;}
+ //T const& get() const {return m_obj;}
+
+ typedef typename T::result_type result_type;
+ result_type const& result() const {return T::result;}
+ };
+
+template<class T>
+boost::shared_ptr<Acceptor<T> > make_acceptor(T const& g)
+ {
+ return boost::make_shared<Acceptor<T> >(g);
+ }
+
+struct accept_each
+ {
+ IVisitor const& visitor;
+ accept_each(IVisitor const& v):visitor(v){}
+
+ template<class T>
+ void operator()(T& obj) const {obj.second->accept(obj.first, visitor);}
+ };
+
+#endif

Modified: sandbox-branches/andreo/guigl/libs/guigl/example/geometry.cpp
==============================================================================
--- sandbox-branches/andreo/guigl/libs/guigl/example/geometry.cpp (original)
+++ sandbox-branches/andreo/guigl/libs/guigl/example/geometry.cpp 2009-03-26 13:34:25 EDT (Thu, 26 Mar 2009)
@@ -1,59 +1,336 @@
-///*=================================---------------------------------------------
+#define NOMINMAX
+
+//*=================================---------------------------------------------
 //Copyright 2009 Andrey Torba
 //
 //Distributed under the Boost Software License, Version 1.0.
 //(See accompanying file LICENSE_1_0.txt or copy at
 //http://www.boost.org/LICENSE_1_0.txt)
 //-----------------------------------------------===============================*/
-//#include "geometry.hpp"
-//
-//#include <boost/guigl/application.hpp>
-//#include <boost/guigl/window.hpp>
-//#include <boost/guigl/view/positioned.hpp>
-//#include <boost/guigl/view/impl/positioned.hpp>
-//
-//#include <boost/guigl/ggl.hpp>
-//#include <boost/guigl/gl.hpp>
-//
-//#include <geometry/geometries/geometries.hpp>
-//#include <geometry/geometry.hpp>
-//
-//using namespace boost::guigl;
-//
-//typedef view::positioned<> my_widget_base_type;
-//class my_widget : public my_widget_base_type
-// {
-// public:
-// typedef my_widget_base_type base_type;
-//
-// template<typename ArgumentPack>
-// my_widget(const ArgumentPack &args)
-// : base_type(args)
-// {}
-//
-// void draw_prologue()
-// {
-// base_type::draw_prologue();
-//
-// geometry::polygon_2d ;
-// }
-//
-// BOOST_GUIGL_WIDGET_DRAW_IMPL(my_widget);
-// };
-//
+
+#include "geometry.hpp"
+
+#include <boost/guigl/application.hpp>
+#include <boost/guigl/window.hpp>
+#include <boost/guigl/widget/custom.hpp>
+
+#include <boost/guigl/ggl.hpp>
+#include <boost/guigl/gl.hpp>
+
+#include <geometry/geometries/geometries.hpp>
+#include <geometry/geometry.hpp>
+
+#include <boost/shared_ptr.hpp>
+#include <boost/make_shared.hpp>
+#include <boost/assign/std.hpp>
+#include <boost/foreach.hpp>
+
+#include <geometry/io/wkt/streamwkt.hpp>
+
+#include <geometry/algorithms/correct.hpp>
+#include <geometry/geometry.hpp>
+#include <geometry/algorithms/centroid.hpp>
+#include "graph.hpp"
+
+using namespace boost::guigl;
+
+class RenderVisitor : public IVisitor
+ {
+ public:
+ void visit(int key, source_point& g) const
+ {
+ gl::color(blue(0.7));
+ ggl::draw(g.result);
+ }
+
+ void visit(int key, line_from_two_points& g) const
+ {
+ glLineWidth(4);
+ gl::color(red(0.8));
+ ggl::draw(g.result);
+ }
+
+ void visit(int key, plane_from_three_points& g) const
+ {
+ gl::color(green(0.5));
+ glBegin(GL_POLYGON);
+ ggl::vertex(g.result.outer());
+ glEnd();
+
+ glLineWidth(2);
+ gl::color(black(0.2));
+ ggl::draw<geometry::ring_tag>(g.result.outer());
+ }
+ };
+
+class RecomputeVisitor : public IVisitor
+ {
+ public:
+ void visit(int key, line_from_two_points& g) const
+ {
+ g.result = line_type(g.pt1, g.pt2);
+ };
+
+ void visit(int key, plane_from_three_points& g) const
+ {
+ using namespace boost::assign;
+ g.result.outer().clear();
+ g.result.outer() += g.pt1, g.pt2, g.pt3;
+ geometry::correct(g.result);
+ };
+ };
+
+struct StreamWriter
+ {
+ template<class T>
+ void operator()(int key, T& g) const
+ {
+ std::cout << g.result << std::endl;
+ }
+
+ template<>
+ void operator()<line_from_two_points>(int key, line_from_two_points& g) const
+ {
+ geometry::linestring<point_type> s;
+ geometry::append(s, g.result.first);
+ geometry::append(s, g.result.second);
+ std::cout << s << std::endl;
+ }
+
+ };
+
+template<class Tag>
+struct StreamByTag
+ {
+ template<class T>
+ void operator()(int key, T& g) const
+ {
+ return ;
+ }
+
+ template<>
+ void operator()<Tag>(int key, Tag& g) const
+ {
+ std::cout << g.result << std::endl;
+ }
+ };
+
+void drawString(const char *str, int x, int y, color_type const& clr, void *font)
+ {
+ glPushAttrib(GL_LIGHTING_BIT | GL_CURRENT_BIT); // lighting and color mask
+ glDisable(GL_LIGHTING); // need to disable lighting for proper text color
+
+ gl::color(clr);
+ glRasterPos2i(x, y); // place text position
+
+ // loop all characters in the string
+ while(*str)
+ {
+ glutBitmapCharacter(font, *str);
+ ++str;
+ }
+
+ glEnable(GL_LIGHTING);
+ glPopAttrib();
+ }
+
+struct PrintDescription
+ {
+ std::map<int, std::string> const& descriptions;
+ dependency_graph const& g;
+
+ PrintDescription(
+ std::map<int, std::string> const& descriptions_,
+ dependency_graph const& g_)
+ :descriptions(descriptions_), g(g_) {}
+
+ template<class T>
+ point_type get_center(T const& obj) const
+ {
+ point_type center;
+ geometry::centroid(obj, center);
+ return center;
+ }
+
+ template<>
+ point_type get_center<point_type>(point_type const& obj) const
+ {
+ return obj;
+ }
+
+ template<>
+ point_type get_center<line_type>(line_type const& obj) const
+ {
+ return point_type(
+ (obj.first.x + obj.second.x)/2,
+ (obj.first.y + obj.second.y)/2);
+ }
+
+ //template<class T>
+ //point_type get_center<base_result<line_type> >(T const& obj)
+ // {
+ // return geometry::centet
+ // }
+
+ //template<class T>
+ //point_type get_center<base_result<line_type> >(T const& obj)
+ // {
+
+ // }
+
+ template<class T>
+ void operator()(int key, T const& obj) const
+ {
+ boost::optional<int> i = g.get_key(key);
+ if(!i) return ;
+
+ point_type center = get_center(obj.result);
+ drawString(descriptions.find(*i)->second.c_str(), center.x + 10, center.y, grey(0.1), GLUT_BITMAP_8_BY_13);
+ }
+ };
+
+widget::custom *w;
+
+struct drawer {
+ typedef boost::shared_ptr<IAcceptor> IAcceptorPtr;
+ dependency_graph g;
+ std::map<int, std::string> names;
+
+ void init_geometry_graph();
+
+ enum {
+ middle_notch_point,
+ femoral_head_point,
+ lateral_epi_point,
+ medial_epi_point,
+
+ point1,
+
+ mechanical_axis,
+ epi_axis,
+
+ axial_plane
+ };
+
+ drawer()
+ {
+ using namespace boost::assign;
+
+ typedef GraphVertex<int, point_type> Point;
+ typedef GraphVertex<int, line_type> Line;
+ typedef GraphVertex<int, plane_type> Plane;
+
+
+ insert(names)
+ (middle_notch_point, "middle notch point")
+ (femoral_head_point, "femoral head point")
+ (lateral_epi_point, "lateral epi point")
+ (medial_epi_point, "medial epi point")
+ (point1, "point1")
+ (mechanical_axis, "mechanical axis")
+ (epi_axis, "epi axis")
+ (axial_plane, "axial plane")
+ ;
+
+ init_geometry_graph();
+
+ std::for_each(
+ g.objects.begin(),
+ g.objects.end(),
+ accept_each(RecomputeVisitor()));
+
+ std::for_each(
+ g.objects.begin(),
+ g.objects.end(),
+ accept_each(Visitor<StreamWriter>()));
+ }
+
+ void operator()() const
+ {
+ glLineWidth(0.5);
+ gl::color(black(0.5));
+ ggl::draw(w->segment<HC>());
+ ggl::draw(w->segment<VC>());
+
+ gl::scoped_matrix m;
+ gl::translate(250., 250.);
+
+// drawString("center", 0, 0, grey(0.1), GLUT_BITMAP_8_BY_13);
+
+ glPointSize(10);
+ //glLineWidth(2);
+ glEnable(GL_LINE_SMOOTH);
+ glEnable(GL_POINT_SMOOTH);
+
+
+ std::for_each(
+ g.objects.begin(),
+ g.objects.end(),
+ accept_each(RecomputeVisitor()));
+
+ std::for_each(
+ g.objects.begin(),
+ g.objects.end(),
+ accept_each(RenderVisitor()));
+
+ std::for_each(
+ g.objects.begin(),
+ g.objects.end(),
+ accept_each(Visitor<PrintDescription>(PrintDescription(names, g))));
+ }
+ };
+
 int main()
   {
-// window wnd((
-// _label = "geometry example",
-// _size = size_type(500, 500),
-// _background = white()
-// ));
-//
-// wnd << new my_widget((
-// _size = size_type(300, 300),
-// _position = position_type(100, 100)
-// ));
-//
-// application::run();
-// return 0;
+ window wnd((
+ _label = "geometry example",
+ _size = size_type(500, 500),
+ _background = white()
+ ));
+
+ w = new widget::custom((
+ _size = size_type(500,500),
+ _position = position_type(0, 0),
+ _draw_prologue = drawer()
+ ));
+
+ wnd << w;
+
+ application::run();
+ return 0;
   }
+
+
+
+
+void drawer::init_geometry_graph()
+ {
+ using namespace boost::assign;
+
+ typedef GraphVertex<int, point_type> Point;
+ typedef GraphVertex<int, line_type> Line;
+ typedef GraphVertex<int, plane_type> Plane;
+
+ Point
+ pt_mnp = g.make_source_point(middle_notch_point, point_type(90, 90)),
+ pt_fh = g.make_source_point(femoral_head_point, point_type(-90, -90)),
+ pt_laepi = g.make_source_point(lateral_epi_point, point_type(90, -90)),
+ pt_meepi = g.make_source_point(medial_epi_point, point_type(0, -180));
+
+ ////Point
+ //// pt_mnp = g.make_indicatable_point(middle_notch_point);
+
+ Line
+ ax_mech = g.make_line(mechanical_axis, pt_mnp, pt_fh),
+ ax_epi = g.make_line(epi_axis, pt_meepi, pt_laepi);
+
+ Plane
+ pl_axial = g.make_plane(axial_plane, pt_mnp, pt_fh, pt_laepi);
+
+ Point pt1 = g.make_source_point(point1, point_type(120, 30));
+
+ g.make_plane(
+ g.make_source_point(point_type(-90, 90)),
+ pt1,
+ pt_mnp);
+ }
\ No newline at end of file

Modified: sandbox-branches/andreo/guigl/libs/guigl/example/geometry.hpp
==============================================================================
--- sandbox-branches/andreo/guigl/libs/guigl/example/geometry.hpp (original)
+++ sandbox-branches/andreo/guigl/libs/guigl/example/geometry.hpp 2009-03-26 13:34:25 EDT (Thu, 26 Mar 2009)
@@ -1,6 +1,7 @@
 #ifndef BOOST_GUIGL_EXAMPLE_GEOMETRY_HPP
 #define BOOST_GUIGL_EXAMPLE_GEOMETRY_HPP
 
-
+#include "acceptor.hpp"
+#include "visitors.hpp"
 
 #endif

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-26 13:34:25 EDT (Thu, 26 Mar 2009)
@@ -31,9 +31,18 @@
 
 using namespace boost::guigl;
 
-void CALLBACK tess_begin_cb(GLenum which) { glBegin(which); }
-void CALLBACK tess_end_cb() { glEnd(); }
-void CALLBACK tess_vertex_cb(const GLvoid *data) { glVertex3dv((const GLdouble*)data); }
+void CALLBACK tess_begin_cb(GLenum which) {
+ //std::cout << __FUNCTION__ << ": " << which << std::endl;
+ glBegin(which);
+ }
+void CALLBACK tess_end_cb() {
+ //std::cout << __FUNCTION__ << std::endl;
+ glEnd();
+ }
+void CALLBACK tess_vertex_cb(const GLvoid *data) {
+ //std::cout << __FUNCTION__ << std::endl;
+ glVertex3dv((const GLdouble*)data);
+ }
 void CALLBACK tess_error_cb(GLenum errorCode)
 {
     const GLubyte *errorStr;
@@ -54,25 +63,25 @@
 
     class polygon : boost::noncopyable {
     public:
- tess const& m_tess;
+ GLUtesselator *m_tess;
     public:
- polygon(tess const& t)
- : m_tess(t)
- { gluTessBeginPolygon(m_tess.m_tess, 0); }
- ~polygon(){ gluTessEndPolygon(m_tess.m_tess); }
+ explicit polygon(tess const& t)
+ : m_tess(t.m_tess)
+ { gluTessBeginPolygon(m_tess, 0); }
+ ~polygon(){ gluTessEndPolygon(m_tess); }
 
         class contour : boost::noncopyable {
         public:
- tess const& m_tess;
+ GLUtesselator *m_tess;
 
         public:
- contour(tess const& t)
- : m_tess(t)
- { gluTessBeginContour(m_tess.m_tess); }
- ~contour(){ gluTessEndContour(m_tess.m_tess); }
+ explicit contour(polygon const& pg)
+ : m_tess(pg.m_tess)
+ { gluTessBeginContour(m_tess); }
+ ~contour(){ gluTessEndContour(m_tess); }
 
             inline void operator()(double coord[3], void *data) const {
- gluTessVertex(m_tess.m_tess, coord, data);
+ gluTessVertex(m_tess, coord, data);
             }
 
             inline void operator()(double coord[3]) const {
@@ -90,7 +99,7 @@
 
 GLuint tessellate1()
 {
- glColor3f(1,1,0);
+ glColor3f(1,0,0);
 
     tess tt;
     GLUtesselator* t = tt.m_tess;
@@ -105,7 +114,7 @@
 // glNewList(id, GL_COMPILE);
     {
         tess::polygon p(tt);
- tess::polygon::contour c(tt);
+ tess::polygon::contour c(p);
         c(quad1[0]);
         c(quad1[1]);
         c(quad1[2]);
@@ -234,7 +243,9 @@
         // gluDeleteTess(t);
         //}
 
+ //std::cout << "tess-begin" << std::endl;
         tessellate1();
+ //std::cout << "tess-end" << std::endl;
 // glCallList(tessellate1());
     }
 

Added: sandbox-branches/andreo/guigl/libs/guigl/example/graph.hpp
==============================================================================
--- (empty file)
+++ sandbox-branches/andreo/guigl/libs/guigl/example/graph.hpp 2009-03-26 13:34:25 EDT (Thu, 26 Mar 2009)
@@ -0,0 +1,130 @@
+#ifndef BOOST_GUIGL_EXAMPLE_GRAPH_HPP
+#define BOOST_GUIGL_EXAMPLE_GRAPH_HPP
+
+#include "node_types.hpp"
+
+#include <boost/graph/graph_traits.hpp>
+#include <boost/graph/adjacency_list.hpp>
+//#include <boost/graph/dijkstra_shortest_paths.hpp>
+
+template<class Key, class T>
+class GraphVertex
+ {
+ public:
+ Key key;
+ boost::shared_ptr<base_result<T> > obj;
+
+ GraphVertex(
+ Key key_,
+ boost::shared_ptr<base_result<T> > const& obj_)
+ :key(key_), obj(obj_) {}
+ };
+
+
+class dependency_graph
+ {
+ public:
+ std::map<int, boost::shared_ptr<IAcceptor> > objects;
+ std::map<int, int> key_map;
+
+ public:
+ typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS> Graph;
+
+ Graph g;
+
+ boost::shared_ptr<IAcceptor> get(int key)
+ {
+ return objects[key_map[key]];
+ }
+
+ int add_vertex(boost::shared_ptr<IAcceptor> const& ptr)
+ {
+ int v = boost::add_vertex(g);
+ objects[v] = ptr;
+ return v;
+ }
+
+ void add_key(int key, int v)
+ {
+ if(key_map.end() != key_map.find(key))
+ throw std::runtime_error("vertex already exists");
+ key_map[key] = v;
+ }
+
+ boost::optional<int> get_key(int v) const
+ {
+ typedef std::pair<int, int> pair_type;
+ BOOST_FOREACH(pair_type const& p, key_map)
+ if(p.second == v)
+ return p.first;
+ return boost::optional<int>();
+ }
+
+ GraphVertex<int, point_type> make_source_point(point_type const& pt)
+ {
+ boost::shared_ptr<Acceptor<source_point> >
+ obj(new Acceptor<source_point>(source_point(pt)) );
+ int v = add_vertex(obj);
+ return GraphVertex<int, point_type>(v, obj);
+ }
+
+ GraphVertex<int, point_type> make_source_point(int key, point_type const& pt)
+ {
+ GraphVertex<int, point_type> result = make_source_point(pt);
+ add_key(key, result.key);
+ return result;
+ }
+
+ GraphVertex<int, line_type> make_line(
+ GraphVertex<int, point_type> const& pt1,
+ GraphVertex<int, point_type> const& pt2)
+ {
+ boost::shared_ptr<Acceptor<line_from_two_points> >
+ obj(new Acceptor<line_from_two_points>(line_from_two_points(pt1.obj->result, pt2.obj->result)) );
+
+ int v = add_vertex(obj);
+
+ boost::add_edge(pt1.key, v, g);
+ boost::add_edge(pt2.key, v, g);
+
+ return GraphVertex<int, line_type>(v, obj);
+ }
+
+ GraphVertex<int, line_type> make_line(int key,
+ GraphVertex<int, point_type> const& pt1,
+ GraphVertex<int, point_type> const& pt2)
+ {
+ GraphVertex<int, line_type> result = make_line(pt1, pt2);
+ add_key(key, result.key);
+ return result;
+ }
+
+ GraphVertex<int, plane_type> make_plane(
+ GraphVertex<int, point_type> const& pt1,
+ GraphVertex<int, point_type> const& pt2,
+ GraphVertex<int, point_type> const& pt3)
+ {
+ boost::shared_ptr<Acceptor<plane_from_three_points> >
+ obj(new Acceptor<plane_from_three_points>(plane_from_three_points(pt1.obj->result, pt2.obj->result, pt3.obj->result)) );
+
+ int v = add_vertex(obj);
+
+ boost::add_edge(pt1.key, v, g);
+ boost::add_edge(pt2.key, v, g);
+ boost::add_edge(pt3.key, v, g);
+
+ return GraphVertex<int, plane_type>(v, obj);
+ }
+
+ GraphVertex<int, plane_type> make_plane(int key,
+ GraphVertex<int, point_type> const& pt1,
+ GraphVertex<int, point_type> const& pt2,
+ GraphVertex<int, point_type> const& pt3)
+ {
+ GraphVertex<int, plane_type> result = make_plane(pt1, pt2, pt3);
+ add_key(key, result.key);
+ return result;
+ }
+ };
+
+#endif

Added: sandbox-branches/andreo/guigl/libs/guigl/example/node_types.hpp
==============================================================================
--- (empty file)
+++ sandbox-branches/andreo/guigl/libs/guigl/example/node_types.hpp 2009-03-26 13:34:25 EDT (Thu, 26 Mar 2009)
@@ -0,0 +1,48 @@
+#ifndef BOOST_GUIGL_EXAMPLE_NODE_TYPES_HPP
+#define BOOST_GUIGL_EXAMPLE_NODE_TYPES_HPP
+
+#include <boost/guigl/types.hpp>
+#include <boost/array.hpp>
+#include <geometry/geometries/polygon.hpp>
+#include <boost/guigl/ggl.hpp>
+
+typedef boost::guigl::position_type point_type;
+typedef boost::guigl::segment_type line_type;
+typedef geometry::polygon<point_type> plane_type;
+
+template<class T>
+struct base_result
+ {
+ typedef T result_type;
+ result_type result;
+
+ base_result():result(){}
+ explicit base_result(T const& r):result(r){}
+ };
+
+struct source_point : public base_result<point_type>
+ {
+ source_point(point_type const& pt):base_result<point_type>(pt){}
+ };
+
+struct line_from_two_points : public base_result<line_type>
+ {
+ point_type const& pt1, pt2;
+
+ line_from_two_points(
+ point_type const& pt1_, point_type const& pt2_)
+ : pt1(pt1_), pt2(pt2_)
+ {}
+ };
+
+struct plane_from_three_points : public base_result<plane_type>
+ {
+ point_type const& pt1, pt2, pt3;
+
+ plane_from_three_points(
+ point_type const& pt1_, point_type const& pt2_, point_type const& pt3_)
+ : pt1(pt1_), pt2(pt2_), pt3(pt3_)
+ {}
+ };
+
+#endif // BOOST_GUIGL_EXAMPLE_NODE_TYPES_HPP

Added: sandbox-branches/andreo/guigl/libs/guigl/example/visitors.hpp
==============================================================================
--- (empty file)
+++ sandbox-branches/andreo/guigl/libs/guigl/example/visitors.hpp 2009-03-26 13:34:25 EDT (Thu, 26 Mar 2009)
@@ -0,0 +1,30 @@
+#ifndef BOOST_GUIGL_EXAMPLE_VISITOR_HPP
+#define BOOST_GUIGL_EXAMPLE_VISITOR_HPP
+
+#include "node_types.hpp"
+
+class IVisitor
+ {
+ public:
+ virtual ~IVisitor(){}
+
+ virtual void visit(int key, source_point& g) const {}
+ virtual void visit(int key, line_from_two_points& g) const {};
+ virtual void visit(int key, plane_from_three_points& g) const {};
+ };
+
+template<class StaticVisitor>
+class Visitor : public IVisitor
+ {
+ private:
+ StaticVisitor m_static_visitor;
+
+ public:
+ Visitor(StaticVisitor const& static_visitor = StaticVisitor())
+ : m_static_visitor(static_visitor) {}
+ void visit(int key, source_point& g) const {m_static_visitor(key, g);}
+ void visit(int key, line_from_two_points& g) const {m_static_visitor(key, g);};
+ void visit(int key, plane_from_three_points& g) const {m_static_visitor(key, g);};
+ };
+
+#endif


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