27 #ifndef MLN_DEBUG_DRAW_GRAPH_HH
28 # define MLN_DEBUG_DRAW_GRAPH_HH
36 # include <mln/core/site_set/p_vertices.hh>
37 # include <mln/core/site_set/p_edges.hh>
38 # include <mln/util/line_graph.hh>
39 # include <mln/util/site_pair.hh>
40 # include <mln/draw/line.hh>
41 # include <mln/draw/box_plain.hh>
42 # include <mln/data/fill.hh>
43 # include <mln/metal/equal.hh>
65 template <
typename I,
typename G,
typename F>
67 draw_graph(Image<I>& ima,
const p_vertices<G, F>& pv,
68 mln_value(I) vcolor, mln_value(I) ecolor);
85 template <
typename I,
typename G,
typename F,
typename V,
typename E>
88 const p_vertices<G, F>& pv,
89 const Function<V>& vcolor_f,
const Function<E>& ecolor_f,
94 template <
typename I,
typename G,
typename F,
typename V,
typename E>
98 const p_vertices<G, F>& pv,
99 const Function<V>& vcolor_f_,
const Function<E>& ecolor_f_);
114 template <
typename I,
typename G,
typename F,
typename V,
typename E>
118 const p_vertices<util::line_graph<G>, F>& pv,
119 const Function<V>& vcolor_f,
const Function<E>& ecolor_f);
122 # ifndef MLN_INCLUDE_ONLY
129 template <
typename I,
typename G,
typename F>
133 const p_edges<G, F>& pe,
137 mln_trace(
"debug::draw_graph");
139 I& ima =
exact(ima_);
140 mln_precondition(ima.is_valid());
143 typedef p_edges<G, F> pe_t;
144 mln_piter(pe_t)
p(pe);
147 if (ima.has(p.first()) && ima.has(p.second()))
148 draw::line(ima, p.first(), p.second(), ecolor);
149 if (ima.has(p.first()))
150 ima(p.first()) = vcolor;
151 if (ima.has(p.second()))
152 ima(p.second()) = vcolor;
158 template <
typename I,
typename G,
typename F>
162 const p_vertices<G, F>& pv,
166 mln_trace(
"debug::draw_graph");
168 I& ima =
exact(ima_);
169 mln_precondition(ima.is_valid());
172 const G& g = pv.graph();
173 typedef p_vertices<G, F> pv_t;
174 mln_edge_iter(G) ei(g);
176 draw::
line(ima, pv(ei.v1()), pv(ei.v2()), ecolor);
179 mln_piter(pv_t) p(pv);
188 template <typename I, typename G, typename F, typename V, typename E>
192 const p_vertices<G, F>& pv,
193 const Function<V>& vcolor_f_, const Function<E>& ecolor_f_,
196 mln_trace(
"debug::draw_graph");
198 I& ima =
exact(ima_);
199 const V& vcolor_f =
exact(vcolor_f_);
200 const E& ecolor_f =
exact(ecolor_f_);
202 mln_precondition(ima.is_valid());
205 const G& g = pv.graph();
206 typedef p_vertices<G, F> pv_t;
207 mln_edge_iter(G) ei(g);
209 if (ei.v1() != 0 && ei.v2() != 0)
210 draw::
line(ima, pv(ei.v1()), pv(ei.v2()), ecolor_f(ei.
id()));
213 unsigned vhalf_width = vwidth / 2;
214 mln_piter(pv_t) p(pv);
216 if (ima.has(p) && p.
id() != 0u)
218 box2d box(p + dpoint2d(-vhalf_width, -vhalf_width),
219 p + dpoint2d(+vhalf_width, +vhalf_width));
220 box.crop_wrt(ima.domain());
227 template <
typename I,
typename G,
typename F,
typename V,
typename E>
231 const p_vertices<G, F>& pv,
232 const Function<V>& vcolor_f,
const Function<E>& ecolor_f)
239 template <
typename I,
typename G,
typename F,
typename V,
typename E>
243 const p_vertices<util::line_graph<G>, F>& pv,
244 const Function<V>& vcolor_f_,
const Function<E>& ecolor_f_)
246 mln_trace(
"debug::draw_graph");
248 I& ima =
exact(ima_);
249 const V& vcolor_f =
exact(vcolor_f_);
250 const E& ecolor_f =
exact(ecolor_f_);
252 mln_precondition(ima.is_valid());
254 typedef util::line_graph<G> LG;
256 const LG& lg = pv.graph();
257 const G& g = lg.graph();
258 typedef p_vertices<LG, F> pv_t;
259 mln_vertex_iter(LG) vi(lg);
262 p_line2d l = pv(vi.id());
264 draw::line(ima, l.begin(), l.end(), ecolor_f(vi.id()));
267 if (ima.has(l.begin()))
268 ima(l.begin()) = vcolor_f(g.edge(vi).v1());
269 if (ima.has(l.end()))
270 ima(l.end()) = vcolor_f(g.edge(vi).v2());
275 # endif // ! MLN_INCLUDE_ONLY
281 #endif // ! MLN_DEBUG_DRAW_GRAPH_HH