27 #ifndef MLN_CORE_IMAGE_IMORPH_LABELED_IMAGE_BASE_HH
28 # define MLN_CORE_IMAGE_IMORPH_LABELED_IMAGE_BASE_HH
34 # include <mln/core/image/dmorph/image_if.hh>
35 # include <mln/core/concept/function.hh>
36 # include <mln/core/internal/image_identity.hh>
37 # include <mln/core/site_set/box.hh>
39 # include <mln/accu/shape/bbox.hh>
41 # include <mln/labeling/relabel.hh>
43 # include <mln/util/array.hh>
44 # include <mln/value/next.hh>
46 # include <mln/pw/cst.hh>
47 # include <mln/pw/value.hh>
49 # include <mln/make/relabelfun.hh>
56 template <
typename I,
typename E>
57 class labeled_image_base;
64 template <
typename I,
typename E>
65 struct data< labeled_image_base<I,E> >
67 data(
const I& ima,
const mln_value(I)& nlabels);
68 data(
const I& ima,
const mln_value(I)& nlabels,
69 const util::array<mln_box(I)>& bboxes);
72 mln_value(I) nlabels_;
73 mutable util::array< box<mln_psite(I)> > bboxes_;
83 template <
typename I,
typename E>
84 struct image_< labeled_image_base<I,E> > : image_< I >
87 typedef trait::image::category::identity_morpher category;
88 typedef mln_internal_trait_image_speed_from(I) speed;
89 typedef trait::image::value_access::indirect value_access;
91 typedef trait::image::value_io::read_only value_io;
92 typedef trait::image::pw_io::read pw_io;
95 typedef trait::image::ext_value::multiple ext_value;
96 typedef trait::image::ext_io::read_only ext_io;
115 template <typename I, typename E>
117 : public internal::image_identity< const I, mln_domain(I), E >
119 typedef internal::image_identity< const I, mln_domain(I), E >
140 template <typename F>
145 template <typename F>
150 mln_value(I) nlabels() const;
153 const
bbox_t& bbox(const mln_value(I)&
label) const;
156 const util::array<
bbox_t>& bboxes() const;
160 fun::eq_v2b_expr_<pw::value_<I>, pw::cst_<mln_value(I)> > >
161 subdomain(const mln_value(I)&
label) const;
165 void update_data(const fun::i2v::array<mln_value(I)>& relabel_fun);
167 template <typename F>
170 template <typename F>
175 void init_update_data_();
176 void prepare_update_data_(const mln_value(I)& lbl,
177 const mln_value(I)& new_lbl);
178 void update_data_(const fun::i2v::array<mln_value(I)>& relabel_fun);
185 # ifndef MLN_INCLUDE_ONLY
196 template <
typename I,
typename E>
199 : ima_(ima), nlabels_(nlabels)
203 template <
typename I,
typename E>
207 : ima_(ima), nlabels_(nlabels), bboxes_(bboxes)
215 template <
typename I,
typename E>
222 template <
typename I,
typename E>
223 template <
typename F>
228 const F& f = exact(f_);
229 mln_value(I) new_nlabels;
231 fun::i2v::array<mln_value(I)>
233 this->data_->nlabels_,
239 this->data_->nlabels_ = new_nlabels;
241 exact(
this)->relabel_(f);
244 update_data(packed_relabel_fun);
248 template <
typename I,
typename E>
249 template <
typename F>
254 const F& f = exact(f_);
257 typedef fun::i2v::array<mln_value(I)> fv2v_t;
259 this->data_->nlabels_,
260 this->data_->nlabels_);
264 exact(
this)->relabel_(f);
270 template <
typename I,
typename E>
275 return this->data_->nlabels_;
279 template <
typename I,
typename E>
284 new_bboxes(mln::value::next(this->data_->nlabels_));
286 exact(
this)->init_update_data_();
288 for (
unsigned i = 1; i < this->data_->bboxes_.size(); ++i)
289 if (relabel_fun(i) != 0)
291 new_bboxes[relabel_fun(i)].take(this->data_->bboxes_[i]);
292 exact(
this)->prepare_update_data_(i, relabel_fun(i));
295 convert::from_to(new_bboxes, this->data_->bboxes_);
297 mln_assertion(new_bboxes.
size() == this->data_->bboxes_.size());
299 exact(
this)->update_data_(relabel_fun);
303 template <
typename I,
typename E>
307 return this->data_->bboxes_[label];
311 template <
typename I,
typename E>
315 return this->data_->bboxes_;
319 template <
typename I,
typename E>
321 fun::eq_v2b_expr_<pw::value_<I>, pw::cst_<mln_value(I)> > >
324 return ((this->data_->ima_ | bbox(label))
325 | (pw::value(this->data_->ima_) == pw::cst(label))).domain();
330 template <
typename I,
typename E>
331 template <
typename F>
339 template <
typename I,
typename E>
340 template <
typename F>
342 labeled_image_base<I,E>::relabel_(
const Function_v2b<F>& f)
348 template <
typename I,
typename E>
350 labeled_image_base<I,E>::update_data_(
351 const fun::i2v::array<mln_value(I)>& relabel_fun)
357 template <
typename I,
typename E>
359 labeled_image_base<I,E>::prepare_update_data_(
const mln_value(I)& lbl,
360 const mln_value(I)& new_lbl)
367 template <
typename I,
typename E>
369 labeled_image_base<I,E>::init_update_data_()
375 # endif // ! MLN_INCLUDE_ONLY
380 #endif // ! MLN_CORE_IMAGE_IMORPH_LABELED_IMAGE_BASE_HH