draw_connections.h
00001 #ifndef VVELIB_ALGORITHMS_DRAW_CONNECTIONS_H
00002 #define VVELIB_ALGORITHMS_DRAW_CONNECTIONS_H
00003
00004 #include <config.h>
00005 #include <util/palette.h>
00006 #include <util/parms.h>
00007 #include <viewer.h>
00008 #include <geometry/geometry.h>
00009
00010 namespace algorithms
00011 {
00012
00013 using geometry::Point3d;
00014
00015 template <typename src_t, typename tgt_t, typename Model, typename Graph, typename iterator>
00016 void _drawGraphConnections(Model* model, Viewer* viewer, const Graph& G, iterator (Graph::*begin)() const, iterator (Graph::*end)() const, bool order_neighbors)
00017 {
00018 bool has_cull_face = glIsEnabled(GL_CULL_FACE);
00019 glDisable(GL_CULL_FACE);
00020 forall_range(const src_t& c, std::make_pair((G.*begin)(), (G.*end)()))
00021 {
00022 double nc = G.valence(c);
00023 double min_l = HUGE_VAL;
00024 const Point3d& cpos = model->position(c);
00025 if(order_neighbors)
00026 {
00027 forall(const tgt_t& n, G.neighbors(c))
00028 {
00029 const Point3d& npos = model->position(n);
00030 double l = norm(npos - cpos);
00031 if(l < min_l)
00032 min_l = l;
00033 }
00034 min_l /= 2*nc;
00035 }
00036
00037 int i = 1;
00038 forall(const tgt_t& n, G.neighbors(c))
00039 {
00040 const Point3d& npos = model->position(n);
00041 Point3d endpos = cpos;
00042 if(order_neighbors)
00043 {
00044 Point3d u = util::normalized(npos - cpos);
00045 endpos += u*min_l*i;
00046 i++;
00047 }
00048 else
00049 {
00050 endpos += (npos-cpos)/2;
00051 }
00052 viewer->drawArrow(Vec(cpos), Vec(endpos));
00053 }
00054 }
00055 if(has_cull_face)
00056 glEnable(GL_CULL_FACE);
00057 }
00058
00067 template <typename Model, typename GraphType>
00068 void drawVVGraphConnections(Model* model, Viewer* viewer, const GraphType& G, bool order_neighbors)
00069 {
00070 typedef typename GraphType::vertex_t vertex;
00071 typedef typename GraphType::const_iterator (GraphType::*range_fct)() const;
00072 _drawGraphConnections<vertex,vertex>(model, viewer, G, (range_fct)&GraphType::begin, (range_fct)&GraphType::end, order_neighbors);
00073 }
00074
00085 template <typename Model, typename GraphType>
00086 void drawVVBiGraphConnections1(Model* model, Viewer* viewer, const GraphType& G, bool order_neighbors)
00087 {
00088 typedef typename GraphType::vertex1_t vertex1;
00089 typedef typename GraphType::vertex2_t vertex2;
00090 typedef typename GraphType::const_iterator1 (GraphType::*range_fct)() const;
00091 _drawGraphConnections<vertex1,vertex2>(model, viewer, G, (range_fct)&GraphType::begin_vertex1, (range_fct)&GraphType::end_vertex1, order_neighbors);
00092 }
00093
00104 template <typename Model, typename GraphType>
00105 void drawVVBiGraphConnections2(Model* model, Viewer* viewer, const GraphType& G, bool order_neighbors)
00106 {
00107 typedef typename GraphType::vertex1_t vertex1;
00108 typedef typename GraphType::vertex2_t vertex2;
00109 typedef typename GraphType::const_iterator2 (GraphType::*range_fct)() const;
00110 _drawGraphConnections<vertex2,vertex1>(model, viewer, G, (range_fct)&GraphType::begin_vertex2, (range_fct)&GraphType::end_vertex2, order_neighbors);
00111 }
00112
00113 }
00114
00115 #endif // VVELIB_ALGORITHMS_DRAW_CONNECTIONS_H
00116