911: Fix 'Make check morpho' / 'morpho'. draft cc_tarjan .

Index: ChangeLog from Ugo Jardonnet <ugo.jardonnet@lrde.epita.fr> Fix 'Make check morpho' / 'morpho'. draft cc_tarjan . * olena/tests/algorithms/basic_morpho.cc: . * olena/oln/morpho/dilation.hh: . * olena/oln/morpho/cc_tarjan.cc: New. * olena/oln/morpho/erosion.hh: . * olena/oln/level/apply.hh: . * olena/oln/core/2d/image2d.hh: . * olena/oln/core/internal/image_base.hh: . oln/core/2d/image2d.hh | 3 - oln/core/internal/image_base.hh | 16 ++--- oln/level/apply.hh | 2 oln/morpho/cc_tarjan.cc | 107 +++++++++++++++++++++++++++++++++++++++ oln/morpho/dilation.hh | 25 +++++---- oln/morpho/erosion.hh | 25 +++++---- tests/algorithms/basic_morpho.cc | 60 ++++++--------------- 7 files changed, 164 insertions(+), 74 deletions(-) Index: olena/tests/algorithms/basic_morpho.cc --- olena/tests/algorithms/basic_morpho.cc (revision 910) +++ olena/tests/algorithms/basic_morpho.cc (working copy) @@ -17,6 +17,15 @@ #include <oln/debug/print.hh> + +template <typename I> +void my_test(I ima, int i) +{ + oln_piter(I) p1(ima.points()); + for_all(p1) + assert(ima(p1) == i); +} + int main() { using namespace oln; @@ -31,54 +40,19 @@ for_all(p1) ima(p1) = i++ % 2; - std::cout << "ima" << std::endl; - debug::print(ima); + my_test( (morpho::elementary_erosion(ima + c4)).image(), 0); + my_test( (morpho::elementary_dilation(ima + c4)).image(), 1 ); - I tmp = (morpho::elementary_erosion(ima + c4)).image(); - p1 = tmp.points(); - for_all(p1) - assert(tmp(p1) == 0); + my_test( (morpho::elementary_opening(ima + c4)).image(), 0); - // std::cout << "elementary_dilation" << std::endl; - tmp = (morpho::elementary_dilation(ima + c4)).image(); - p1 = tmp.points(); - for_all(p1) - assert(tmp(p1) == 1); + my_test( (morpho::elementary_closing(ima + c4)).image(), 1); - // std::cout << "erosion_w" << std::endl; - tmp = morpho::erosion(ima, win3x3); - p1 = tmp.points(); - for_all(p1) - assert(tmp(p1) == 0); + my_test( morpho::erosion(ima, win3x3), 0); - // std::cout << "dilation_w" << std::endl; - tmp = morpho::dilation(ima, win3x3); - p1 = tmp.points(); - for_all(p1) - assert(tmp(p1) == 1); - - // std::cout << "elementary_opening" << std::endl; - tmp = (morpho::elementary_opening(ima + c4)).image(); - p1 = tmp.points(); - for_all(p1) - assert(tmp(p1) == 0); + my_test( morpho::dilation(ima, win3x3), 1); - // std::cout << "elementary_closing" << std::endl; - tmp = (morpho::elementary_closing(ima + c4)).image(); - p1 = (tmp.points()); - for_all(p1) - assert(tmp(p1) == 1); + my_test( morpho::opening(ima, win3x3), 0); - // std::cout << "opening" << std::endl; - tmp = morpho::opening(ima, win3x3); - p1 = (tmp.points()); - for_all(p1) - assert(tmp(p1) == 1); - - // std::cout << "closing" << std::endl; - debug::print( morpho::closing(ima, win3x3) ); - p1 = (tmp.points()); - for_all(p1) - assert(tmp(p1) == 1); + my_test( morpho::closing(ima, win3x3), 1); } Index: olena/oln/morpho/dilation.hh --- olena/oln/morpho/dilation.hh (revision 910) +++ olena/oln/morpho/dilation.hh (working copy) @@ -54,21 +54,24 @@ template <typename I, typename W> oln_plain(I) - dilation_(const Image<I>& input, const Window<W>& win) + dilation_on_function_(const Image<I>&, + const I& input, + const Window<W>& win) { border::fill(input, oln_min(oln_value(I))); accumulator::max_<oln_value(I)> max; return level::apply_local(max, input, win); } - template <typename I> + template <typename I, typename W> oln_plain(I) dilation_on_set_(const Image<I>&, - const I& input) + const I& input, + const Window<W>& win) { border::fill(input, oln_min(oln_value(I))); accumulator::or_<oln_value(I)> accu_or; - return level::apply_local(accu_or, input); + return level::apply_local(accu_or, input, win); } // FIXME: Add a fast version. @@ -76,16 +79,18 @@ // Impl facade. - template <typename I> - oln_plain(I) dilation_(const Image<I>& input) + template <typename I, typename W> + oln_plain(I) dilation_(const Image<I>& input, + const Window<W>& win) { - return dilation_on_function_(exact(input), exact(input)); + return dilation_on_function_(exact(input), exact(input), win); } - template <typename I> - oln_plain(I) dilation_(const Binary_Image<I>& input) + template <typename I, typename W> + oln_plain(I) dilation_(const Binary_Image<I>& input, + const Window<W>& win) { - return dilation_on_set_(exact(input), exact(input)); + return dilation_on_set_(exact(input), exact(input), win); } } // end of namespace oln::morpho::impl Index: olena/oln/morpho/cc_tarjan.cc --- olena/oln/morpho/cc_tarjan.cc (revision 0) +++ olena/oln/morpho/cc_tarjan.cc (revision 0) @@ -0,0 +1,107 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_MORPHO_DILATION_HH +# define OLN_MORPHO_DILATION_HH + +namespace oln +{ + + namespace morpho + { + + template <typename I> + oln_point(I) find_root(const oln_point(I)& x) + { + if (parent[x] != x) + { + parent[x] = find_root(parent[x]); + return parent(x); + } + return x; + } + + template <typename I> + void do_union(const oln_point(I)& n, + const oln_point(I)& p, + const oln_plain_value(I, oln_point(I))& parent) + { + oln_point(I) r = find_root(n); + if (r != p) + parent(r) = p; + } + + template <typename I> + oln_plain_value(I, unsigned) + cc_tarjan(const Binary_Image<I>& input) + { + oln_plain_value(I, unsigned) output; + prepare(output, with, input); + + oln_plain_value(I, oln_point(I)) parent; + prepare(parent, with, input); + + // Init + unsigned current_label = 0; + oln_plain(I) is_processed; + prepare(is_processed, with, input); + oln_piter(I) p(input.points()); + for_all(p) + is_processed(p) = false; // FIXME : built with. + + + // Fist pass + oln_piter(I) p(input.points()); + for_all(p) + { + oln_niter(I) n(p, input); + for_all(n) + { + if ( is_processed(n) ) + do_union(n, p, parent); + } + is_processed(p) = true; + } + + + // Second pass + oln_piter(I) p2(input.points()); + for_all(p2) + { + if ( parent(p) == p ) + output(p) = ++current_label; + else + output(p) = output(parent(p)); + } + } + + } // end of namespace oln::morpho + +} // end of namespace oln + + +#endif // ! OLN_MORPHO_DILATION_HH Index: olena/oln/morpho/erosion.hh --- olena/oln/morpho/erosion.hh (revision 910) +++ olena/oln/morpho/erosion.hh (working copy) @@ -54,21 +54,24 @@ template <typename I, typename W> oln_plain(I) - erosion_(const Image<I>& input, const Window<W>& win) + erosion_on_function_(const Image<I>&, + const I& input, + const Window<W>& win) { border::fill(input, oln_max(oln_value(I))); accumulator::min_<oln_value(I)> min; return level::apply_local(min, input, win); } - template <typename I> + template <typename I, typename W> oln_plain(I) erosion_on_set_(const Image<I>&, - const I& input) + const I& input, + const Window<W>& win) { border::fill(input, true); accumulator::and_<oln_value(I)> accu_and; - return level::apply_local(accu_and, input); + return level::apply_local(accu_and, input, win); } // FIXME: Add a fast version. @@ -76,16 +79,18 @@ // Impl facade. - template <typename I> - oln_plain(I) erosion_(const Image<I>& input) + template <typename I, typename W> + oln_plain(I) erosion_(const Image<I>& input, + const Window<W>& win) { - return erosion_on_function_(exact(input), exact(input)); + return erosion_on_function_(exact(input), exact(input), win); } - template <typename I> - oln_plain(I) erosion_(const Binary_Image<I>& input) + template <typename I, typename W> + oln_plain(I) erosion_(const Binary_Image<I>& input, + const Window<W>& win) { - return erosion_on_set_(exact(input), exact(input)); + return erosion_on_set_(exact(input), exact(input), win); } } // end of namespace oln::morpho::impl Index: olena/oln/level/apply.hh --- olena/oln/level/apply.hh (revision 910) +++ olena/oln/level/apply.hh (working copy) @@ -66,7 +66,7 @@ typedef typename F::result result; oln_plain_value(I, result) output; - init(output, with, input); + prepare(output, with, input); oln_piter(I) p(input.points()); for_all(p) output(p) = f(input(p)); Index: olena/oln/core/2d/image2d.hh --- olena/oln/core/2d/image2d.hh (revision 910) +++ olena/oln/core/2d/image2d.hh (working copy) @@ -213,8 +213,7 @@ box2d b; bool box_ok = init(b, with, dat); postcondition(box_ok); - array2d_<T,int>* ptr = new array2d_<T,int>(b.pmin().row(), //FIXME - //: *. + array2d_<T,int>* ptr = new array2d_<T,int>(b.pmin().row(), b.pmin().col(), b.pmax().row(), b.pmax().col()); Index: olena/oln/core/internal/image_base.hh --- olena/oln/core/internal/image_base.hh (revision 910) +++ olena/oln/core/internal/image_base.hh (working copy) @@ -434,21 +434,21 @@ // init - template <typename P, typename I> - bool init_(typename internal::image_base_<I>::box* this_, const internal::image_base_<I>& data); + template <typename I> + bool init_(typename I::box* this_, const internal::image_base_<I>& data); template <typename Target, typename I> bool init_(Any<Target>* this_, const internal::single_image_morpher_<I>& data); - template <typename P, typename I> // for disambiguation purpose + template <typename I> // for disambiguation purpose bool - init_(typename internal::image_base_<I>::box** this_, const internal::single_image_morpher_<I>& data); + init_(typename I::box* this_, const internal::single_image_morpher_<I>& data); # ifndef OLN_INCLUDE_ONLY - template <typename P, typename I> - bool init_(typename internal::image_base_<I>::box** this_, const internal::image_base_<I>& data) + template <typename I> + bool init_(typename I::box* this_, const internal::image_base_<I>& data) { *this_ = data.bbox(); return true; @@ -460,9 +460,9 @@ return init(*this_, with, data.image()); } - template <typename P, typename I> + template <typename I> bool - init_(typename internal::image_base_<I>::box** this_, const internal::single_image_morpher_<I>& data) + init_(typename I::box* this_, const internal::single_image_morpher_<I>& data) { *this_ = data.bbox(); return true;
participants (1)
-
Ugo Jardonnet