$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
line_set.hh
1 // Copyright (C) 2009, 2010, 2011, 2013 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_CORE_LINE_SET_HH
28 # define SCRIBO_CORE_LINE_SET_HH
29 
33 
34 # include <mln/util/array.hh>
35 
36 # include <mln/accu/pair.hh>
37 # include <mln/accu/center.hh>
38 # include <mln/accu/shape/bbox.hh>
39 
40 # include <mln/labeling/compute.hh>
41 # include <mln/make/relabelfun.hh>
42 
43 # include <mln/fun/i2v/array.hh>
44 
45 # include <mln/convert/from_to.hh>
46 
47 
48 # include <scribo/core/macros.hh>
49 # include <scribo/core/line_info.hh>
50 
51 # include <scribo/core/object_links.hh>
52 # include <scribo/core/object_groups.hh>
53 
54 
55 namespace scribo
56 {
57 
58  // Forward declaration.
59  template <typename L> class line_set;
60  template <typename L> class line_info;
61 
62 
64 
65  namespace internal
66  {
68  template <typename L>
70  {
71  line_set_data();
72  line_set_data(const object_groups<L>& comp_set);
74  const object_groups<L>& comp_set);
75 
77  component_set<L> components_;
78  object_links<L> links_;
79  object_groups<L> groups_;
80  };
81 
82  } // end of namespace scribo::internal
83 
84 
93  template <typename L>
94  class line_set
95  {
96  public:
97 
101  line_set();
102 
105 
107  line_set(const object_groups<L>& groups,
108  const mln::util::array<line_info<L> >& line_data);
110 
112  void compute_lines(const object_groups<L>& groups);
113 
115  mln_value(L) nelements() const;
116 
118  const line_info<L>& info(const mln_value(L)& id) const;
119 
121  line_info<L>& info(const mln_value(L)& id);
122 
124  line_info<L>& operator()(const line_id_t& id);
125 
127  const line_info<L>& operator()(const line_id_t& id) const;
128 
130  const mln::util::array<line_info<L> >& infos() const;
131 
133  template <typename F>
134  void update_tags(const mln::Function_v2b<F>& f, line::Tag tag);
135 
137  template <typename F>
138  void update_types(const mln::Function_v2b<F>& f, line::Type type);
139 
141  line_set<L> duplicate() const;
142 
144  const component_set<L>& components() const;
145 
148 
150  const object_groups<L>& groups() const;
151 
153  const object_links<L>& links() const;
154 
155 
158 
159  void force_stats_update();
160 
162 
165 
168 
170 
171 
174  bool is_valid() const;
175 
176 
177  void update_line_data_(const mln::util::array<line_info<L> >& line_data);
178 
179  private:
181  void init_(const line_set<L>& model);
182 
184  };
185 
186 
187  template <typename L>
188  bool
189  operator==(const line_set<L>& lhs, const line_set<L>& rhs);
190 
191  template <typename L>
192  std::ostream&
193  operator<<(std::ostream& ostr, const line_set<L>& lines);
194 
195  namespace make
196  {
197 
198  template <typename L>
200  line_set(const object_groups<L>& groups);
201 
202  } // End of namespace scribo::make
203 
204 
205 
206 # ifndef MLN_INCLUDE_ONLY
207 
208 
209  // line_set_data<L> >
210 
211  namespace internal
212  {
213 
214  // data< line_set<L> >
215 
216 
217  template <typename L>
218  inline
219  line_set_data<L>::line_set_data()
220  {
221  }
222 
223 
224  template <typename L>
225  inline
226  line_set_data<L>::line_set_data(const object_groups<L>& groups)
227  : components_(groups.components()), links_(groups.links()),
228  groups_(groups)
229  {
230  }
231 
232 
233  template <typename L>
234  inline
235  line_set_data<L>::line_set_data(const mln::util::array<scribo::line_info<L> >& infos,
236  const object_groups<L>& groups)
237  : infos_(infos), components_(groups.components()),
238  links_(groups.links()), groups_(groups)
239  {
240  }
241 
242  } // end of namespace mln::internal
243 
244 
245 
246 
247  template <typename L>
248  inline
249  line_set<L>::line_set()
250  {
251  }
252 
253 
254  template <typename L>
255  inline
256  line_set<L>::line_set(const object_groups<L>& groups)
257  {
258  compute_lines(groups);
259  }
260 
261 
262  template <typename L>
263  inline
264  line_set<L>::line_set(const object_groups<L>& groups,
265  const mln::util::array<line_info<L> >& line_data)
266  {
267  data_ = new internal::line_set_data<L>(line_data, groups);
268  }
269 
270 
271  template <typename L>
272  void
273  line_set<L>::compute_lines(const object_groups<L>& groups)
274  {
275  data_ = new internal::line_set_data<L>(groups);
276 
277  // 2nd pass - Store data.
278  data_->infos_.reserve(groups.nelements());
279  data_->infos_.append(line_info<L>()); // line with id 0 is invalid.
280 
281  for_all_groups(i, groups)
282  {
283  // Add line info.
284  line_info<L> info(*this, i, groups(i));
285  data_->infos_.append(info);
286  }
287  }
288 
289 
290 
291  template <typename L>
292  inline
293  mln_value(L)
294  line_set<L>::nelements() const
295  {
296  return data_->infos_.nelements() - 1;
297  }
298 
299  template <typename L>
300  inline
301  const line_info<L>&
302  line_set<L>::info(const mln_value(L)& id) const
303  {
304  return this->data_->infos_[id];
305  }
306 
307  template <typename L>
308  inline
309  line_info<L>&
310  line_set<L>::info(const mln_value(L)& id)
311  {
312  return this->data_->infos_[id];
313  }
314 
315  template <typename L>
316  inline
317  const line_info<L>&
318  line_set<L>::operator()(const line_id_t& id) const
319  {
320  return this->data_->infos_[id];
321  }
322 
323  template <typename L>
324  inline
325  line_info<L>&
326  line_set<L>::operator()(const line_id_t& id)
327  {
328  return this->data_->infos_[id];
329  }
330 
331  template <typename L>
333  line_set<L>::infos() const
334  {
335  return this->data_->infos_;
336  }
337 
338  template <typename L>
339  template <typename F>
340  inline
341  void
342  line_set<L>::update_tags(const mln::Function_v2b<F>& f_,
343  line::Tag tag)
344  {
345  const F& f = exact(f_);
346 
347  for_all_lines_info(i, data_->infos_)
348  if (!f(i))
349  data_->infos_[i].update_tag(tag);
350  }
351 
352  template <typename L>
353  template <typename F>
354  inline
355  void
356  line_set<L>::update_types(const mln::Function_v2b<F>& f_,
357  line::Type type)
358  {
359  const F& f = exact(f_);
360 
361  for_all_lines_info(i, data_->infos_)
362  if (!f(i))
363  data_->infos_[i].update_type(type);
364  }
365 
366  template <typename L>
367  inline
368  line_set<L>
369  line_set<L>::duplicate() const
370  {
371  line_set<L> output;
372  output.init_(*this);
373  return output;
374  }
375 
376  template <typename L>
377  inline
378  const component_set<L>&
380  {
381  return data_->components_;
382  }
383 
384  template <typename L>
385  inline
386  component_set<L>&
387  line_set<L>::components_()
388  {
389  return data_->components_;
390  }
391 
392  template <typename L>
393  inline
394  const object_groups<L>&
395  line_set<L>::groups() const
396  {
397  return data_->groups_;
398  }
399 
400  template <typename L>
401  inline
402  const object_links<L>&
403  line_set<L>::links() const
404  {
405  return data_->links_;
406  }
407 
408  template <typename L>
409  inline
410  void
411  line_set<L>::force_stats_update()
412  {
413  for_all_lines_info(i, data_->infos_)
414  if (data_->infos_(i).tag() == line::Needs_Precise_Stats_Update)
415  data_->infos_(i).force_stats_update();
416  }
417 
418  template <typename L>
419  inline
420  const mln::util::array<scribo::line_info<L> >&
421  line_set<L>::infos_() const
422  {
423  return data_->infos_;
424  }
425 
426  template <typename L>
427  inline
428  bool
429  line_set<L>::is_valid() const
430  {
431  return data_ && data_->groups_.is_valid();
432  }
433 
434  template <typename L>
435  inline
436  void
437  line_set<L>::update_line_data_(const mln::util::array<line_info<L> >& line_data)
438  {
439  data_->infos_ = line_data;
440  }
441 
442  template <typename L>
443  inline
444  void
445  line_set<L>::init_(const line_set<L>& set)
446  {
447  data_ = new internal::line_set_data<L>(set.infos_(), set.groups());
448  }
449 
450  template <typename L>
451  bool
452  operator==(const line_set<L>& lhs, const line_set<L>& rhs)
453  {
454  if (! (lhs.groups() == rhs.groups() && lhs.nelements() == rhs.nelements()))
455  {
456  return false;
457  }
458 
459  for_all_lines(l, lhs)
460  if ( ! (lhs(l) != rhs(l)))
461  {
462  return false;
463  }
464 
465  return true;
466  }
467 
468 
469 
470  template <typename L>
471  std::ostream&
472  operator<<(std::ostream& ostr, const line_set<L>& lines)
473  {
474  ostr << "line_set[" << std::endl;
475  for_all_lines(i, lines)
476  ostr << lines(i);
477  ostr << "]" << std::endl;
478 
479  return ostr;
480  }
481 
482 
483  // Make routines.
484 
485  namespace make
486  {
487 
488  template <typename L>
490  line_set(const object_groups<L>& groups)
491  {
492  mln_precondition(groups.is_valid());
493  scribo::line_set<L> tmp(groups);
494  return tmp;
495  }
496 
497  } // end of namespace scribo::make
498 
499 
500 # endif // ! MLN_INCLUDE_ONLY
501 
502 } // end of namespace scribo
503 
504 #endif // ! SCRIBO_CORE_LINE_SET_HH