27 #ifndef SCRIBO_CORE_COMPONENT_SET_HH
28 # define SCRIBO_CORE_COMPONENT_SET_HH
37 # include <mln/core/concept/site_set.hh>
38 # include <mln/core/concept/function.hh>
40 # include <mln/data/fill.hh>
42 # include <mln/util/array.hh>
43 # include <mln/value/next.hh>
45 # include <mln/accu/pair.hh>
46 # include <mln/accu/center.hh>
47 # include <mln/accu/shape/bbox.hh>
49 # include <mln/labeling/compute.hh>
50 # include <mln/labeling/relabel.hh>
52 # include <mln/logical/or.hh>
54 # include <mln/convert/from_to.hh>
56 # include <mln/core/image/dmorph/image_if.hh>
57 # include <mln/pw/all.hh>
59 # include <mln/core/routine/duplicate.hh>
61 # include <mln/value/next.hh>
63 # include <scribo/core/macros.hh>
64 # include <scribo/core/component_info.hh>
65 # include <scribo/core/concept/serializable.hh>
72 template <
typename L>
class component_set;
88 typedef std::pair<mln_box(L),
89 std::pair<mln_site(L), unsigned> > pair_data_t;
112 void soft_init(
const mln_value(L) ncomps);
115 mln_value(L) ncomps_;
216 template <
typename L>
223 typedef std::pair<mln_box(L),
224 std::pair<mln_site(L), unsigned> > pair_data_t;
277 template <
typename F>
338 void update_labeled_image_(
const L& lbl);
361 template <
typename L>
366 template <
typename L>
368 operator<<(std::ostream& ostr, const component_set<L>&
info);
373 # ifndef MLN_INCLUDE_ONLY
384 template <
typename L>
386 component_set_data<L>::component_set_data()
391 template <
typename L>
393 component_set_data<L>::component_set_data(
const L& ima,
394 const mln_value(L)& ncomps)
395 : ima_(ima), ncomps_(ncomps)
400 template <
typename L>
403 component_set_data<L>::soft_init(
const mln_value(L) ncomps)
405 mln_precondition(infos_.nelements() == 0);
409 infos_.append(component_info<L>());
418 template <
typename L>
420 component_set<L>::component_set()
424 template <
typename L>
431 template <
typename L>
433 component_set<L>::component_set(
const L& ima,
const mln_value(L)& ncomps)
435 data_ =
new internal::component_set_data<L>(ima, ncomps);
449 typedef mln_site(L) P;
451 data_->infos_.reserve(mln::
value::next(ncomps));
453 data_->infos_.append(component_info<L>());
454 for_all_comp_data(i, attribs)
456 component_info<L> info(i, attribs[i].first(),
457 attribs[i].second(), attribs[i].second_accu().
nsites());
458 data_->infos_.append(info);
463 template <
typename L>
465 component_set<L>::component_set(
const L& ima,
const mln_value(L)& ncomps,
467 component::Type type)
469 data_ =
new internal::component_set_data<L>(ima, ncomps);
474 typedef mln_site(L) P;
476 data_->infos_.reserve(mln::
value::next(ncomps));
478 data_->infos_.append(component_info<L>());
479 for_all_comp_data(i, attribs)
481 component_info<L> info(i, attribs[i].first(),
482 attribs[i].second(), attribs[i].second_accu().
nsites(),
484 data_->infos_.append(info);
489 template <
typename L>
492 component_set<L>::component_set(
const L& ima,
const mln_value(L)& ncomps,
494 component::Type type)
496 data_ =
new internal::component_set_data<L>(ima, ncomps);
501 typedef mln_site(L) P;
503 data_->infos_.reserve(mln::
value::next(ncomps));
505 data_->infos_.append(component_info<L>());
506 for_all_comp_data(i, attribs)
508 component_info<L> info(i, attribs[i].first,
509 attribs[i].second.first, attribs[i].second.second,
511 data_->infos_.append(info);
516 template <
typename L>
520 component_set<L>::nelements()
const
522 return data_->ncomps_;
525 template <
typename L>
527 const component_info<L>&
528 component_set<L>::info(
const mln_value(L)&
id)
const
530 return data_->infos_[id];
533 template <
typename L>
536 component_set<L>::info(
const mln_value(L)&
id)
538 return data_->infos_[id];
541 template <
typename L>
543 const component_info<L>&
544 component_set<L>::operator()(
const component_id_t&
id)
const
546 return data_->infos_[id];
549 template <
typename L>
552 component_set<L>::operator()(
const component_id_t&
id)
554 return data_->infos_[id];
558 template <
typename L>
559 template <
typename F>
565 const F& f =
exact(f_);
567 for_all_comp_data(i, data_->infos_)
569 data_->infos_[i].update_tag(tag);
573 template <typename L>
578 component_set<L> output;
585 template <
typename L>
588 component_set<L>::labeled_image()
const
594 template <
typename L>
597 component_set<L>::update_labeled_image_(
const L& lbl)
603 template <
typename L>
606 component_set<L>::is_valid()
const
608 return data_ != 0 && data_->ima_.is_valid();
612 template <
typename L>
614 typename component_set<L>::id_t
615 component_set<L>::id_()
const
621 template <
typename L>
624 component_set<L>::labeled_image_()
630 template <
typename L>
633 component_set<L>::valid_comps_image_()
const
638 for_all_comps(c, (*
this))
639 f(c) = (*this)(c).is_valid();
641 mln_value(L) new_ncomps;
652 template <typename L>
655 component_set<L>::has_separators()
const
657 return data_->separators_.is_valid();
661 template <
typename L>
664 component_set<L>::add_separators(
const mln_ch_value(L,
bool)& ima)
666 if (! has_separators())
667 data_->separators_ = ima;
673 template <
typename L>
678 return data_->separators_;
682 template <
typename L>
685 component_set<L>::clear_separators()
687 data_->separators_.destroy();
691 template <
typename L>
694 component_set<L>::infos_()
const
696 return data_->infos_;
699 template <
typename L>
702 component_set<L>::init_(
const component_set<L>&
set)
704 data_ =
new internal::component_set_data<L>();
706 data_->ncomps_ =
set.nelements();
707 data_->infos_ =
set.infos_();
708 data_->separators_ =
set.separators();
712 template <
typename L>
714 operator==(
const component_set<L>& lhs,
const component_set<L>& rhs)
716 if (lhs.id_() == rhs.id_())
719 if (! (lhs.labeled_image() == rhs.labeled_image()))
722 if (! (lhs.separators() == rhs.separators()))
725 if (! (lhs.nelements() == rhs.nelements()
726 && lhs.labeled_image() == rhs.labeled_image()
727 && lhs.separators() == rhs.separators()))
730 for_all_comps(c, lhs)
731 if (! (lhs(c) == rhs(c)))
737 template <typename L>
739 operator<<(std::ostream& ostr, const component_set<L>& info)
741 ostr <<
"component_set[" << std::endl;
742 for_all_comps(i, info)
744 ostr << "]" << std::endl;
749 # endif // ! MLN_INCLUDE_ONLY
753 #endif // ! SCRIBO_CORE_COMPONENT_SET_HH