$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
bounding_box_links.hh
1 // Copyright (C) 2009, 2010, 2011 EPITA Research and Development
2 // Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef SCRIBO_DRAW_BOUNDING_BOX_LINKS_HH
28 # define SCRIBO_DRAW_BOUNDING_BOX_LINKS_HH
29 
33 
34 # include <mln/core/concept/image.hh>
35 # include <mln/draw/line.hh>
36 # include <mln/util/array.hh>
37 # include <mln/canvas/browsing/depth_first_search.hh>
38 
39 # include <scribo/core/tag/anchor.hh>
40 # include <scribo/core/macros.hh>
41 # include <scribo/core/object_links.hh>
42 # include <scribo/primitive/internal/is_link_valid.hh>
43 # include <scribo/primitive/link/internal/compute_anchor.hh>
44 
45 namespace scribo
46 {
47 
48  namespace draw
49  {
50 
51  using namespace mln;
52 
59  //
60  template <typename I, typename L>
61  void
63  const object_links<L>& link,
64  const mln_value(I)& value,
65  anchor::Type anchor);
66 
67 
70  //
71  template <typename I, typename L>
72  void
74  const object_links<L>& link,
75  const mln_value(I)& value);
76 
77 
88  //
89  template <typename I, typename L>
90  inline
91  void
93  const object_links<L>& left_link,
94  const object_links<L>& right_link,
95  const mln_value(I)& left_link_value,
96  const mln_value(I)& right_link_value,
97  const mln_value(I)& validated_link_value,
98  anchor::Type anchor);
99 
100 
107  //
108  template <typename I, typename G>
109  inline
110  void
112  const Graph<G>& g,
113  const mln_value(I)& link_value);
114 
115 
116 # ifndef MLN_INCLUDE_ONLY
117 
118 
119  namespace internal
120  {
121 
122 
123  template <typename I>
124  mln_site(I)
125  shift_site(const I& ima,
126  const mln_site(I)& p, const mln_dpsite(mln_site_(I))& dp)
127  {
128  if (ima.has(p + dp))
129  return p + dp;
130  return p;
131  }
132 
135  template <typename I, typename G>
136  struct draw_graph_edges_functor
137  {
138 
143  draw_graph_edges_functor(I& ima,
144  const mln_value(I)& value)
145  : ima_(ima), value_(value)
146  {}
147 
151  void
152  init(const Graph<G>& g)
153  {
154  g_ = g;
155  deja_vu.resize(exact(g).v_nmax(), false);
156  }
157 
159  void final()
160  {}
161 
163  void next_component()
164  {}
165 
168  void new_component_from_vertex(unsigned)
169  {}
170 
171 
173  void added_to_queue(unsigned id)
174  {
175  deja_vu[id] = true;
176  mln::draw::line(ima_, g_.components()(current_vertex).bbox().pcenter(),
177  g_.components()(id).bbox().pcenter(), value_);
178  }
179 
181  void process_vertex(unsigned id)
182  { current_vertex = id; }
183 
185  bool to_be_treated(unsigned id)
186  { return ! deja_vu[id]; }
187 
189  bool to_be_queued(unsigned id)
190  { return to_be_treated(id); }
191 
193  I& ima_;
194 
196  mln_value(I) value_;
197 
199  unsigned current_vertex;
200 
202  std::vector<bool> deja_vu;
203 
204  G g_;
205  };
206 
207  } // end of namespace scribo::draw::internal
208 
209 
210  template <typename I, typename L>
211  inline
212  void
213  bounding_box_links(Image<I>& input_,
214  const object_links<L>& links,
215  const mln_value(I)& value,
216  anchor::Type anchor)
217  {
218  mln_trace("scribo::draw::bounding_box_links");
219 
220  I& input = exact(input_);
221 
222  mln_precondition(input.is_valid());
223 
224  const component_set<L>& comps = links.components();
225  for_all_links(i, links)
226  if (links(i) != i && links(i) != 0)
227  {
228  mln_site(L)
229  p1 = primitive::link::internal::compute_anchor(comps, i, anchor),
230  p2 = primitive::link::internal::compute_anchor(comps, links(i), anchor);
231 
232  mln::draw::line(input, p1, p2, value);
233  }
234 
235  }
236 
237 
238  template <typename I, typename L>
239  inline
240  void
241  bounding_box_links(Image<I>& input,
242  const object_links<L>& links,
243  const mln_value(I)& value)
244  {
245  return bounding_box_links(input, links, value, anchor::Center);
246  }
247 
248 
249  template <typename I, typename L>
250  inline
251  void
253  const object_links<L>& left_link,
254  const object_links<L>& right_link,
255  const mln_value(I)& left_link_value,
256  const mln_value(I)& right_link_value,
257  const mln_value(I)& validated_link_value,
258  anchor::Type anchor)
259  {
260  mln_trace("scribo::draw::bounding_box_links");
261 
262  I& input = exact(input_);
263  mln_precondition(input.is_valid());
264 
265  typedef mln_site(I) P;
266 
267  const component_set<L>& comps = left_link.components();
268 
269  mln_dpsite(P) dleft = literal::zero;
270  dleft[0] = 2;
271  mln_dpsite(P) dright = literal::zero;
272  dright[0] = -2;
273  for_all_links(i, left_link)
274  {
275  mln::draw::line(input,
276  internal::shift_site(input,
277  primitive::link::internal::compute_anchor(comps, i, anchor),
278  dleft),
279  internal::shift_site(input,
280  primitive::link::internal::compute_anchor(comps, left_link(i), anchor),
281  dleft),
282  left_link_value);
283 
284 
285 
286  mln::draw::line(input,
287  internal::shift_site(input,
288  primitive::link::internal::compute_anchor(comps, i, anchor),
289  dleft),
290  internal::shift_site(input,
291  primitive::link::internal::compute_anchor(comps, right_link(i), anchor),
292  dleft),
293  right_link_value);
294 
295 
297  right_link, i))
298  mln::draw::line(input,
299  primitive::link::internal::compute_anchor(comps, i, anchor),
300  primitive::link::internal::compute_anchor(comps, left_link(i), anchor),
301  validated_link_value);
302 
303  }
304 
305  }
306 
307 
308 
309  template <typename I, typename G>
310  inline
311  void
313  const Graph<G>& g,
314  const mln_value(I)& link_value)
315  {
316  mln_trace("scribo::draw::bounding_box_links");
317  mln_precondition(exact(input).is_valid());
318 
319 
320  internal::draw_graph_edges_functor<I,G> f(exact(input), link_value);
322 
323  }
324 
325 
326 # endif // ! MLN_INCLUDE_ONLY
327 
328  } // end of namespace scribo::draw
329 
330 } // end of namespace scribo
331 
332 
333 #endif // ! SCRIBO_DRAW_BOUNDING_BOX_LINKS_HH