
* mln/core/image/graph_window_piter.hh: Remove exact() member. * mln/core/image/imorph/labeled_image.hh: Reindent. * mln/fun/i2v/array.hh: Fix invalid call to nelements(). * mln/make/relabelfun.hh: Fix invalid results. * mln/trait/op/ord.hh: Revamp header. * tests/core/image/imorph/labeled_image.cc: Fix invalid use of labeled_image. --- milena/ChangeLog | 17 +++++++ milena/mln/core/image/graph_window_piter.hh | 17 ++----- milena/mln/core/image/imorph/labeled_image.hh | 9 ++-- milena/mln/fun/i2v/array.hh | 4 +- milena/mln/make/relabelfun.hh | 16 +++++-- milena/mln/trait/op/ord.hh | 3 +- milena/tests/core/image/imorph/labeled_image.cc | 54 ++++++++++++++-------- 7 files changed, 76 insertions(+), 44 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index 789fd82..f40e949 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,20 @@ +2009-08-28 Guillaume Lazzara <lazzara@lrde.epita.fr> + + Small fixes. + + * mln/core/image/graph_window_piter.hh: Remove exact() member. + + * mln/core/image/imorph/labeled_image.hh: Reindent. + + * mln/fun/i2v/array.hh: Fix invalid call to nelements(). + + * mln/make/relabelfun.hh: Fix invalid results. + + * mln/trait/op/ord.hh: Revamp header. + + * tests/core/image/imorph/labeled_image.cc: Fix invalid use of + labeled_image. + 2009-08-26 Guillaume Lazzara <lazzara@lrde.epita.fr> Small fixes. diff --git a/milena/mln/core/image/graph_window_piter.hh b/milena/mln/core/image/graph_window_piter.hh index 1b4ab7a..1891925 100644 --- a/milena/mln/core/image/graph_window_piter.hh +++ b/milena/mln/core/image/graph_window_piter.hh @@ -54,14 +54,9 @@ namespace mln template <typename C, typename P, typename E> struct impl_selector { - E& exact() - { - return internal::force_exact<E>(*this); - } - void do_start_() { - exact().iter_.start(); + internal::force_exact<E>(*this).iter_.start(); // Nothing else to do. A pointer to the window element's site // set has been already stored in the constructor. } @@ -73,14 +68,10 @@ namespace mln template <typename C, typename E> struct impl_selector<C,C,E> { - E& exact() - { - return internal::force_exact<E>(*this); - } - void do_start_() { - exact().iter_.start(); + E& this_ = internal::force_exact<E>(*this); + this_.iter_.start(); // We need to store a pointer on the site set of the window // center. @@ -90,7 +81,7 @@ namespace mln // potential iterator used as center has been started just // before calling this method. // - exact().change_target_site_set(exact().center().site_set()); + this_.change_target_site_set(this_.center().site_set()); } }; diff --git a/milena/mln/core/image/imorph/labeled_image.hh b/milena/mln/core/image/imorph/labeled_image.hh index 8e27163..b0e5ffb 100644 --- a/milena/mln/core/image/imorph/labeled_image.hh +++ b/milena/mln/core/image/imorph/labeled_image.hh @@ -191,10 +191,10 @@ namespace mln /// Return the component bounding boxes. const util::array<bbox_t>& bboxes() const; - /// Return the domain of the component with label \p label. - p_if<mln_box(I), - fun::eq_v2b_expr_<pw::value_<I>, pw::cst_<mln_value(I)> > > - subdomain(const mln_value(I)& label) const; + /// Return the domain of the component with label \p label. + p_if<mln_box(I), + fun::eq_v2b_expr_<pw::value_<I>, pw::cst_<mln_value(I)> > > + subdomain(const mln_value(I)& label) const; }; @@ -309,6 +309,7 @@ namespace mln packed_relabel_fun = make::relabelfun(f, this->data_->nlabels_, new_nlabels); + labeling::relabel_inplace(this->data_->ima_, this->data_->nlabels_, packed_relabel_fun); diff --git a/milena/mln/fun/i2v/array.hh b/milena/mln/fun/i2v/array.hh index b7175c9..21ddbac 100644 --- a/milena/mln/fun/i2v/array.hh +++ b/milena/mln/fun/i2v/array.hh @@ -354,10 +354,10 @@ namespace mln const array<T>& a) { ostr << '('; - const unsigned n = a.nelements(); + const unsigned n = a.size(); for (unsigned i = 0; i < n; ++i) { - ostr << a[i]; + ostr << a(i); if (i != n - 1) ostr << ", "; } diff --git a/milena/mln/make/relabelfun.hh b/milena/mln/make/relabelfun.hh index b9482b0..0a841f2 100644 --- a/milena/mln/make/relabelfun.hh +++ b/milena/mln/make/relabelfun.hh @@ -111,16 +111,24 @@ namespace mln const F& fv2v = exact(fv2v_); unsigned nlabels_i = static_cast<unsigned>(nlabels) + 1; + + util::array<V> new_labels(nlabels_i, mln_max(V)); + new_labels(0) = literal::zero; V tmp_nlabels = literal::zero; - fun::i2v::array<V> fi2v(nlabels_i, literal::zero); + fun::i2v::array<V> fi2v(nlabels_i, mln_max(V)); + fi2v(0) = literal::zero; + for (V i = 1; i < nlabels_i; ++i) - if (fi2v(fv2v(i)) == literal::zero) + { + mln_assertion(fv2v(i) <= nlabels); + if (new_labels(fv2v(i)) == mln_max(V)) { - fi2v(fv2v(i)) = ++tmp_nlabels; + new_labels(fv2v(i)) = ++tmp_nlabels; fi2v(i) = tmp_nlabels; } else - fi2v(i) = fi2v(fv2v(i)); + fi2v(i) = new_labels(fv2v(i)); + } new_nlabels = tmp_nlabels; trace::exiting("make::relabelfun"); return fi2v; diff --git a/milena/mln/trait/op/ord.hh b/milena/mln/trait/op/ord.hh index ca02815..5e9a370 100644 --- a/milena/mln/trait/op/ord.hh +++ b/milena/mln/trait/op/ord.hh @@ -1,4 +1,5 @@ -// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of Olena. // diff --git a/milena/tests/core/image/imorph/labeled_image.cc b/milena/tests/core/image/imorph/labeled_image.cc index d4e78b0..627c38a 100644 --- a/milena/tests/core/image/imorph/labeled_image.cc +++ b/milena/tests/core/image/imorph/labeled_image.cc @@ -34,11 +34,17 @@ #include <mln/accu/shape/bbox.hh> - -static const unsigned bboxes_1[][4] = { { 1,1, 1,1 }, - { 2,0, 2,1 }, - { 0,0, 0,1 }, - { 2,2, 2,2 } }; +# include <mln/debug/println.hh> + +static const unsigned bboxes_1[][9] = { { 1,1, 1,1 }, // 1 + { 2,2, 2,2 }, // 2 + { 0,0, 0,0 }, + { 0,0, 0,0 }, + { 2,0, 2,1 }, // 5 + { 0,0, 0,0 }, + { 0,0, 0,0 }, + { 0,0, 0,0 }, + { 0,0, 0,1 } }; static const unsigned bboxes_2[][4] = { { 1,1, 1,1 }, @@ -51,14 +57,22 @@ static const unsigned bboxes_2[][4] = { { 1,1, 1,1 }, namespace mln { - template <typename I> + template <typename I, unsigned n> void test_image(const labeled_image<I>& lbl_i, - const unsigned bboxes[][4]) + const unsigned bboxes[][n]) { - unsigned j = 0; - for (unsigned i = 1; i < 5; ++i, ++j) - mln_assertion(lbl_i.bbox(i) == make::box2d(bboxes[j][0], bboxes[j][1], - bboxes[j][2], bboxes[j][3])); + unsigned + j = 0, + k = 0; + for (unsigned i = 1; i <= lbl_i.nlabels(); ++i, ++j) + if (lbl_i.bbox(i).is_valid()) + { + mln_assertion(lbl_i.bbox(i) == make::box2d(bboxes[j][0], bboxes[j][1], + bboxes[j][2], bboxes[j][3])); + ++k; + } + + mln_assertion(k == 4); } } // end of namespace mln @@ -72,26 +86,26 @@ int main() using value::label_8; - label_8 lbl_values[][3] = { { 3, 3, 0 }, + label_8 lbl_values[][3] = { { 9, 9, 0 }, { 0, 1, 0 }, - { 2, 2, 4 } }; + { 5, 5, 2 } }; typedef image2d<label_8> lbl_t; lbl_t lbl = make::image(lbl_values); - labeled_image<lbl_t> lbl_i(lbl, 4); - - + labeled_image<lbl_t> lbl_i(lbl, 9); + mln_assertion(lbl_i.nlabels() == 9); test_image(lbl_i, bboxes_1); - fun::i2v::array<label_8> f(5); + fun::i2v::array<label_8> f(10, 0); f(0) = 0; f(1) = 1; - f(2) = 5; - f(3) = 9; - f(4) = 2; + f(5) = 2; + f(9) = 5; + f(2) = 4; lbl_i.relabel(f); + mln_assertion(lbl_i.nlabels() == 4); test_image(lbl_i, bboxes_2); } -- 1.5.6.5
participants (1)
-
Guillaume Lazzara