00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 #ifndef MLN_DEBUG_DRAW_GRAPH_HH
00028 # define MLN_DEBUG_DRAW_GRAPH_HH
00029 
00035 
00036 # include <mln/core/site_set/p_vertices.hh>
00037 # include <mln/core/site_set/p_edges.hh>
00038 # include <mln/util/line_graph.hh>
00039 # include <mln/util/site_pair.hh>
00040 # include <mln/draw/line.hh>
00041 # include <mln/draw/box_plain.hh>
00042 # include <mln/data/fill.hh>
00043 # include <mln/metal/equal.hh>
00044 
00045 namespace mln
00046 {
00047 
00048   namespace debug
00049   {
00050 
00054     
00055 
00056 
00057 
00058 
00059 
00060 
00061 
00062     template <typename I, typename G, typename F>
00063     void
00064     draw_graph(Image<I>& ima, const p_vertices<G, F>& pv,
00065                mln_value(I) vcolor, mln_value(I) ecolor);
00066 
00067 
00071     
00072 
00073 
00074 
00075 
00076 
00077 
00078     template <typename I, typename G, typename F, typename V, typename E>
00079     void
00080     draw_graph(Image<I>& ima,
00081                const p_vertices<G, F>& pv,
00082                const Function<V>& vcolor_f_, const Function<E>& ecolor_f_);
00083 
00087     
00088 
00089 
00090 
00091 
00092 
00093 
00094     template <typename I, typename G, typename F, typename V, typename E>
00095     inline
00096     void
00097     draw_graph(Image<I>& ima,
00098                const p_vertices<util::line_graph<G>, F>& pv,
00099                const Function<V>& vcolor_f_, const Function<E>& ecolor_f_);
00100 
00101 
00102 # ifndef MLN_INCLUDE_ONLY
00103 
00104 
00105 
00106     
00107     
00108 
00109     template <typename I, typename G, typename F>
00110     inline
00111     void
00112     draw_graph(Image<I>& ima_,
00113                const p_edges<G, F>& pe,
00114                mln_value(I) vcolor,
00115                mln_value(I) ecolor)
00116     {
00117       trace::entering("debug::draw_graph");
00118 
00119       I& ima = exact(ima_);
00120       mln_precondition(ima.is_valid());
00121 
00122       
00123       typedef p_edges<G, F> pe_t;
00124       mln_piter(pe_t) p(pe);
00125       for_all(p)
00126       {
00127         if (ima.has(p.first()) && ima.has(p.second()))
00128           draw::line(ima, p.first(), p.second(), ecolor);
00129         if (ima.has(p.first()))
00130           ima(p.first()) = vcolor;
00131         if (ima.has(p.second()))
00132           ima(p.second()) = vcolor;
00133       }
00134 
00135       trace::exiting("debug::draw_graph");
00136     }
00137 
00138 
00139     template <typename I, typename G, typename F>
00140     inline
00141     void
00142     draw_graph(Image<I>& ima_,
00143                const p_vertices<G, F>& pv,
00144                mln_value(I) vcolor,
00145                mln_value(I) ecolor)
00146     {
00147       trace::entering("debug::draw_graph");
00148 
00149       I& ima = exact(ima_);
00150       mln_precondition(ima.is_valid());
00151 
00152       
00153       const G& g = pv.graph();
00154       typedef p_vertices<G, F> pv_t;
00155       mln_edge_iter(G) ei(g);
00156       for_all(ei)
00157         draw::line(ima, pv(ei.v1()), pv(ei.v2()), ecolor);
00158 
00159       
00160       mln_piter(pv_t) p(pv);
00161       for_all(p)
00162         if (ima.has(p))
00163           ima(p) = vcolor;
00164 
00165       trace::exiting("debug::draw_graph");
00166     }
00167 
00168 
00169     
00170     template <typename I, typename G, typename F, typename V, typename E>
00171     inline
00172     void
00173     draw_graph(Image<I>& ima_,
00174                const p_vertices<G, F>& pv,
00175                const Function<V>& vcolor_f_, const Function<E>& ecolor_f_)
00176     {
00177       trace::entering("debug::draw_graph");
00178 
00179       I& ima = exact(ima_);
00180       const V& vcolor_f = exact(vcolor_f_);
00181       const E& ecolor_f = exact(ecolor_f_);
00182 
00183       mln_precondition(ima.is_valid());
00184 
00185       
00186       const G& g = pv.graph();
00187       typedef p_vertices<G, F> pv_t;
00188       mln_edge_iter(G) ei(g);
00189       for_all(ei)
00190         if (ei.v1() != 0 && ei.v2() != 0)
00191           draw::line(ima, pv(ei.v1()), pv(ei.v2()), ecolor_f(ei.id()));
00192 
00193       
00194       mln_piter(pv_t) p(pv);
00195       for_all(p)
00196         if (ima.has(p) && p.id() != 0u)
00197         {
00198           box2d box(p + dpoint2d(-5, -5), p + dpoint2d(+5, +5));
00199           box.crop_wrt(ima.domain());
00200           draw::box_plain(ima, box, vcolor_f(p.id()));
00201         }
00202 
00203       trace::exiting("debug::draw_graph");
00204     }
00205 
00206 
00207     
00208     template <typename I, typename G, typename F, typename V, typename E>
00209     inline
00210     void
00211     draw_graph(Image<I>& ima_,
00212                const p_vertices<util::line_graph<G>, F>& pv,
00213                const Function<V>& vcolor_f_, const Function<E>& ecolor_f_)
00214     {
00215       trace::entering("debug::draw_graph");
00216 
00217       I& ima = exact(ima_);
00218       const V& vcolor_f = exact(vcolor_f_);
00219       const E& ecolor_f = exact(ecolor_f_);
00220 
00221       mln_precondition(ima.is_valid());
00222 
00223       typedef util::line_graph<G> LG;
00224 
00225       const LG& lg = pv.graph();
00226       const G& g = lg.graph();
00227       typedef p_vertices<LG, F> pv_t;
00228       mln_vertex_iter(LG) vi(lg);
00229       for_all(vi)
00230       {
00231         p_line2d l = pv(vi.id());
00232         
00233         draw::line(ima, l.begin(), l.end(), ecolor_f(vi.id()));
00234 
00235         
00236         if (ima.has(l.begin()))
00237           ima(l.begin()) = vcolor_f(g.edge(vi).v1());
00238         if (ima.has(l.end()))
00239           ima(l.end()) = vcolor_f(g.edge(vi).v2());
00240       }
00241 
00242       trace::exiting("debug::draw_graph");
00243     }
00244 
00245 # endif // ! MLN_INCLUDE_ONLY
00246 
00247    } 
00248 
00249 } 
00250 
00251 #endif // ! MLN_DEBUG_DRAW_GRAPH_HH