• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

draw_graph.hh

00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
00025 
00026 #ifndef MLN_DEBUG_DRAW_GRAPH_HH
00027 # define MLN_DEBUG_DRAW_GRAPH_HH
00028 
00034 
00035 # include <mln/core/site_set/p_vertices.hh>
00036 # include <mln/core/site_set/p_edges.hh>
00037 # include <mln/util/line_graph.hh>
00038 # include <mln/util/site_pair.hh>
00039 # include <mln/draw/line.hh>
00040 # include <mln/data/fill.hh>
00041 # include <mln/metal/equal.hh>
00042 
00043 namespace mln
00044 {
00045 
00046   namespace debug
00047   {
00048 
00052     /*
00053      * \param[in,out] ima      The image to be drawn.
00054      * \param[in]     pv       The p_vertices which contains vertices positions.
00055      * \param[in]     vcolor The value to assign to pixels which contains
00056      *                          vertices.
00057      * \param[in]     ecolor   The value to assign to pixels which contains
00058      *                         edges.
00059      */
00060     template <typename I, typename G, typename F>
00061     void
00062     draw_graph(Image<I>& ima, const p_vertices<G, F>& pv,
00063                mln_value(I) vcolor, mln_value(I) ecolor);
00064 
00065 
00069     /*
00070      * \param[in,out] ima       The image to be drawn.
00071      * \param[in]     pv        The p_vertices which contains vertices positions.
00072      * \param[in]     vcolor_f_ A function returning a color value for vertices.
00073      * \param[in]     ecolor_f_ A function returning a color value for edges.
00074      *
00075      */
00076     template <typename I, typename G, typename F, typename V, typename E>
00077     void
00078     draw_graph(Image<I>& ima,
00079                const p_vertices<G, F>& pv,
00080                const Function<V>& vcolor_f_, const Function<E>& ecolor_f_);
00081 
00085     /*
00086      * \param[in,out] ima       The image to be drawn.
00087      * \param[in]     pv        The p_vertices which contains vertices positions.
00088      * \param[in]     vcolor_f_ A function returning a color value for vertices.
00089      * \param[in]     ecolor_f_ A function returning a color value for edges.
00090      *
00091      */
00092     template <typename I, typename G, typename F, typename V, typename E>
00093     inline
00094     void
00095     draw_graph(Image<I>& ima,
00096                const p_vertices<util::line_graph<G>, F>& pv,
00097                const Function<V>& vcolor_f_, const Function<E>& ecolor_f_);
00098 
00099 
00100 # ifndef MLN_INCLUDE_ONLY
00101 
00102 
00103 
00104     // FIXME: Add assertions on the size of the image: it must be large
00105     // enough to hold the representation of the graph/graph_image.
00106 
00107     template <typename I, typename G, typename F>
00108     inline
00109     void
00110     draw_graph(Image<I>& ima,
00111                const p_edges<G, F>& pe,
00112                mln_value(I) vcolor,
00113                mln_value(I) ecolor)
00114     {
00115       trace::entering("debug::draw_graph");
00116 
00117       // Draw edges.
00118       typedef p_edges<G, F> pe_t;
00119       mln_piter(pe_t) p(pe);
00120       for_all(p)
00121       {
00122         if (exact(ima).has(p.first()) && exact(ima).has(p.second()))
00123           draw::line(exact(ima), p.first(), p.second(), ecolor);
00124         if (exact(ima).has(p.first()))
00125           exact(ima)(p.first()) = vcolor;
00126         if (exact(ima).has(p.second()))
00127           exact(ima)(p.second()) = vcolor;
00128       }
00129 
00130       trace::exiting("debug::draw_graph");
00131     }
00132 
00133 
00134     template <typename I, typename G, typename F>
00135     inline
00136     void
00137     draw_graph(Image<I>& ima,
00138                const p_vertices<G, F>& pv,
00139                mln_value(I) vcolor,
00140                mln_value(I) ecolor)
00141     {
00142       trace::entering("debug::draw_graph");
00143 
00144       // Draw edges.
00145       const G& g = pv.graph();
00146       typedef p_vertices<G, F> pv_t;
00147       mln_edge_iter(G) ei(g);
00148       for_all(ei)
00149         draw::line(exact(ima), pv(ei.v1()), pv(ei.v2()), ecolor);
00150 
00151       // Draw vertices.
00152       mln_piter(pv_t) p(pv);
00153       for_all(p)
00154         if (exact(ima).has(p))
00155           exact(ima)(p) = vcolor;
00156 
00157       trace::exiting("debug::draw_graph");
00158     }
00159 
00160 
00161     // FIXME: Refactor + be more restrictive on the function type.
00162     template <typename I, typename G, typename F, typename V, typename E>
00163     inline
00164     void
00165     draw_graph(Image<I>& ima,
00166                const p_vertices<G, F>& pv,
00167                const Function<V>& vcolor_f_, const Function<E>& ecolor_f_)
00168     {
00169       trace::entering("debug::draw_graph");
00170 
00171       const V& vcolor_f = exact(vcolor_f_);
00172       const E& ecolor_f = exact(ecolor_f_);
00173 
00174       // Draw edges.
00175       const G& g = pv.graph();
00176       typedef p_vertices<G, F> pv_t;
00177       mln_edge_iter(G) ei(g);
00178       for_all(ei)
00179         draw::line(exact(ima), pv(ei.v1()), pv(ei.v2()), ecolor_f(ei.id()));
00180 
00181       // Draw vertices.
00182       mln_piter(pv_t) p(pv);
00183       for_all(p)
00184         if (exact(ima).has(p))
00185           exact(ima)(p) = vcolor_f(p);
00186 
00187       trace::exiting("debug::draw_graph");
00188     }
00189 
00190 
00191     // FIXME: Refactor + be more restrictive on the function type.
00192     template <typename I, typename G, typename F, typename V, typename E>
00193     inline
00194     void
00195     draw_graph(Image<I>& ima,
00196                const p_vertices<util::line_graph<G>, F>& pv,
00197                const Function<V>& vcolor_f_, const Function<E>& ecolor_f_)
00198     {
00199       trace::entering("debug::draw_graph");
00200 
00201       const V& vcolor_f = exact(vcolor_f_);
00202       const E& ecolor_f = exact(ecolor_f_);
00203 
00204       typedef util::line_graph<G> LG;
00205 
00206       const LG& lg = pv.graph();
00207       const G& g = lg.graph();
00208       typedef p_vertices<LG, F> pv_t;
00209       mln_vertex_iter(LG) vi(lg);
00210       for_all(vi)
00211       {
00212         p_line2d l = pv(vi.id());
00213         // Draw edges (Line graph vertices).
00214         draw::line(exact(ima), l.begin(), l.end(), ecolor_f(vi.id()));
00215 
00216         // Draw vertices (graph vertices).
00217         if (exact(ima).has(l.begin()))
00218           exact(ima)(l.begin()) = vcolor_f(g.edge(vi).v1());
00219         if (exact(ima).has(l.end()))
00220           exact(ima)(l.end()) = vcolor_f(g.edge(vi).v2());
00221       }
00222 
00223       trace::exiting("debug::draw_graph");
00224     }
00225 
00226 # endif // ! MLN_INCLUDE_ONLY
00227 
00228    } // end of namespace mln::debug
00229 
00230 } // end of namespace mln
00231 
00232 #endif // ! MLN_DEBUG_DRAW_GRAPH_HH

Generated on Thu Sep 8 2011 18:31:46 for Milena (Olena) by  doxygen 1.7.1