* mln/world/kn/compute_tree_of_shapes.hh: Use kn::debug::println for printing debug.
* mln/world/kn/internal/display.hh: Remove. --- milena/ChangeLog | 9 + milena/mln/world/kn/compute_tree_of_shapes.hh | 75 ++---- milena/mln/world/kn/internal/display.hh | 320 ------------------------- 3 files changed, 30 insertions(+), 374 deletions(-) delete mode 100644 milena/mln/world/kn/internal/display.hh
diff --git a/milena/ChangeLog b/milena/ChangeLog index 4d9dc1a..cafb263 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,14 @@ 2012-11-29 Guillaume Lazzara z@lrde.epita.fr
+ Remove kn::internal::display. + + * mln/world/kn/compute_tree_of_shapes.hh: Use kn::debug::println + for printing debug. + + * mln/world/kn/internal/display.hh: Remove. + +2012-11-29 Guillaume Lazzara z@lrde.epita.fr + * mln/world/kn/compute_tree_of_shapes.hh: Fix tree canonicalization.
diff --git a/milena/mln/world/kn/compute_tree_of_shapes.hh b/milena/mln/world/kn/compute_tree_of_shapes.hh index 8fe5073..4a3b226 100644 --- a/milena/mln/world/kn/compute_tree_of_shapes.hh +++ b/milena/mln/world/kn/compute_tree_of_shapes.hh @@ -48,7 +48,7 @@
// FIXME: to be removed or disabled. -# include <mln/world/kn/internal/display.hh> +# include <mln/world/kn/debug/println.hh>
namespace mln @@ -114,7 +114,7 @@ namespace mln
P find_root(T& zpar, P x);
- T union_find(const Array_P& R, display& dsp); + T union_find(const util::tree_of_shapes<I>& t);
void priority_push(q_type& q, const P& p, const I& F); P priority_pop(q_type& q); @@ -125,8 +125,7 @@ namespace mln
EV level_next_to_lcur(q_type& q);
- void sort(const Image<I>& F_, util::tree_of_shapes<I>& t, - display& dsp); + void sort(const Image<I>& F_, util::tree_of_shapes<I>& t); void canonicalize_tree(util::tree_of_shapes<I>& t);
@@ -183,10 +182,10 @@ namespace mln
template <typename I, typename IV> typename compute_tree_of_shapes_t<I,IV>::T - compute_tree_of_shapes_t<I,IV>::union_find(const Array_P& R, - display& dsp) + compute_tree_of_shapes_t<I,IV>::union_find(const util::tree_of_shapes<I>& t) // with balancing { + const Array_P& R = t.R; T zpar(D), parent(D); U rank(D), last(D); mln_ch_value(I,bool) done(D); @@ -218,12 +217,13 @@ namespace mln } done(p) = true;
- if (dsp.level_changes_at(i)) + if (t.level_changes_at(i)) { - std::cout << "union-find: done with level " << dsp.level(p) << std::endl; - //dsp.show(done); + std::cout << "union-find: done with level " << t.level(p) << std::endl; + kn::debug::println(done); } } + return parent; }
@@ -358,7 +358,7 @@ namespace mln template <typename I, typename IV> void compute_tree_of_shapes_t<I,IV>::sort(const Image<I>& F_, - util::tree_of_shapes<I>& t, display& dsp) + util::tree_of_shapes<I>& t) { trace::entering("mln::world::kn::sort"); mln_precondition(exact(F_).is_valid()); @@ -403,7 +403,7 @@ namespace mln if (q.is_empty_at(lcur)) { std::cout << "sort: done with level " << lcur << std::endl; - dsp.show(done); + kn::debug::println(done); } } while (i != N); @@ -429,43 +429,6 @@ namespace mln if (Fb(parent(q)) == Fb(q)) parent(p) = parent(q); } - - // mln_ch_value(I,bool) show(D); - // for (unsigned i = 0; i <= N - 1; ++i) - // { - // P p = R[i]; - // show(p) = k2::is_primary_2_face(p) || t.is_representative(p); - // } - - // for (unsigned i = 0; i <= N - 1; ++i) - // { - // P p = R[i]; // p goes from root to leaves - // if (! show(p)) - // continue; - // P q = parent(p); - - // if (show(q) == false) // skip node q - // { - // if (parent(q) == q) // q cannot be root - // std::abort(); - - // P r = parent(q); // new representative - // if (p != r) // if p is a repr node, do nothing - // parent(p) = r; - // } - // else - // if (Fb(q) == Fb(p) && k2::is_primary_2_face(p) && ! k2::is_primary_2_face(q)) - // { - // show(q) = false; - - // if (parent(q) == q) // q is root - // parent(p) = p; // p is the new root - // else - // parent(p) = parent(q); // new parent of the representative - // parent(q) = p; // the new representative is p, stored as q's parent - // } - // } - // t.show = show; }
@@ -492,10 +455,9 @@ namespace mln
util::tree_of_shapes<I> t;
- display_in_K2<util::tree_of_shapes<I> > dsp(t, std::cout); - sort(F, t, dsp); + sort(F, t);
- t.parent = union_find(t.R, dsp); + t.parent = union_find(t); canonicalize_tree(t);
return t; @@ -521,10 +483,9 @@ namespace mln
util::tree_of_shapes<I> t;
- display_in_K2<util::tree_of_shapes<I> > dsp(t, std::cout); - sort(F, t, dsp); + sort(F, t);
- t.parent = union_find(t.R, dsp); + t.parent = union_find(t); canonicalize_tree(t);
return t; @@ -538,14 +499,20 @@ namespace mln // Each face's parent is a representative. for (unsigned i = 0; i <= tree.R.size() - 1; ++i) if (!tree.is_representative(tree.parent(tree.R[i]))) + { + mln_assertion(false); return false; + }
// Checking that the parent of a representative face is a parent. mln_piter(I) p(tree.Fb.domain()); for_all(p) if (tree.is_representative(p) && !tree.is_root(p)) if (tree.level(p) == tree.level(tree.parent(p))) + { + mln_assertion(false); return false; + }
return true; } diff --git a/milena/mln/world/kn/internal/display.hh b/milena/mln/world/kn/internal/display.hh deleted file mode 100644 index efa0b59..0000000 --- a/milena/mln/world/kn/internal/display.hh +++ /dev/null @@ -1,320 +0,0 @@ -// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena 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 Olena. If not, see http://www.gnu.org/licenses/. -// -// As a special exception, you may use this file as part of a free -// software project 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. - -/// \file -/// -/// \brief Helpers to display tree of shapes. - -#ifndef MLN_WORLD_KN_INTERNAL_DISPLAY_HH -# define MLN_WORLD_KN_INTERNAL_DISPLAY_HH - -# include <sstream> -# include <mln/world/kn/face_dim.hh> -# include <mln/world/k2/is_primary_2_face.hh> -# include <mln/world/kn/is_1_face_horizontal.hh> -# include <mln/world/kn/is_1_face_vertical.hh> - - -namespace mln -{ - - namespace world - { - - namespace kn - { - - namespace internal - { - - - struct display - { - virtual bool is_on() const = 0; - virtual std::string level(const point2d& p) = 0; - virtual bool level_changes_at(unsigned i) const = 0; - virtual void show(const image2d<bool>& input) = 0; - virtual ~display(); - }; - - - struct display_off : public display - { - virtual bool is_on() const; - virtual std::string level(const point2d&); - virtual bool level_changes_at(unsigned) const; - virtual void show(const image2d<bool>&); - }; - - - template <typename Tree> - struct display_on : public display - { - const Tree& t; - std::ostream& ostr; - - display_on(const Tree& t, std::ostream& ostr); - virtual bool is_on() const; - virtual std::string level(const point2d& p); - virtual bool level_changes_at(unsigned i) const; - virtual void print_p(const point2d& p) = 0; - virtual void show(const image2d<bool>& input); - }; - - - - template <typename Tree> - struct display_in_D : public display_on<Tree> - { - typedef display_on<Tree> super; - using super::ostr; - using super::t; - - display_in_D(const Tree& t, std::ostream& ostr = std::cout); - virtual void print_p(const point2d& p); - }; - - - - template <typename Tree> - struct display_in_K1 : public display_on<Tree> - { - typedef display_on<Tree> super; - using super::ostr; - using super::t; - - display_in_K1(const Tree& t, std::ostream& ostr = std::cout); - virtual void print_p(const point2d& p); - }; - - - - template <typename Tree> - struct display_in_K2 : public display_on<Tree> - { - typedef display_on<Tree> super; - using super::ostr; - using super::t; - - display_in_K2(const Tree& t, std::ostream& ostr = std::cout); - virtual void print_p(const point2d& p); - }; - - -# ifndef MLN_INCLUDE_ONLY - - // display - - inline - display::~display() - { - } - - - // display_off - - inline - bool - display_off::is_on() const - { - return false; - } - - inline - std::string - display_off::level(const point2d&) - { - return ""; - } - - inline - bool - display_off::level_changes_at(unsigned) const - { - return false; - } - - inline - void - display_off:: show(const image2d<bool>&) - { - } - - - // display_on - - template <typename Tree> - display_on<Tree>::display_on(const Tree& t, - std::ostream& ostr) - : t(t), ostr(ostr) - { - } - - template <typename Tree> - bool - display_on<Tree>::is_on() const - { - return true; - } - - template <typename Tree> - std::string - display_on<Tree>::level(const point2d& p) - { - std::ostringstream s; - s << t.level(p); - return s.str(); - } - - template <typename Tree> - bool - display_on<Tree>::level_changes_at(unsigned i) const - { - return t.level_changes_at(i); - } - - template <typename Tree> - void - display_on<Tree>::show(const image2d<bool>& input) - { - box2d dom = input.domain(); - const short - min_row = dom.pmin().row(), - max_row = dom.pmax().row(), - min_col = dom.pmin().col(), - max_col = dom.pmax().col(); - - point2d p; - short& row = p.row(); - short& col = p.col(); - - char bdr = '#'; - - for (col = min_col; col <= max_col + 2; ++col) - ostr << bdr << ' '; - ostr << std::endl; - - for (row = min_row; row <= max_row; ++row) - { - ostr << bdr; - for (col = min_col; col <= max_col; ++col) - if (input(p)) - print_p(p); - else - ostr << " "; - ostr << ' ' << bdr << std::endl; - } - - for (col = min_col; col <= max_col + 2; ++col) - ostr << bdr << ' '; - ostr << std::endl - << std::endl; - } - - - // display_in_D - - template <typename Tree> - display_in_D<Tree>::display_in_D(const Tree& t, - std::ostream& ostr) - : super(t, ostr) - { - } - - template <typename Tree> - void - display_in_D<Tree>::print_p(const point2d& p) - { - ostr << " O"; - } - - - // display_in_K1 - - template <typename Tree> - display_in_K1<Tree>::display_in_K1(const Tree& t, - std::ostream& ostr) - : super(t, ostr) - { - } - - template <typename Tree> - void - display_in_K1<Tree>::print_p(const point2d& p) - { - switch (face_dim(p)) - { - case 0: - ostr << " +"; - break; - case 1: - ostr << (kn::is_1_face_horizontal(p) ? " -" : " |"); - break; - case 2: - ostr << " O"; - break; - } - } - - - // display_in_K2 - - template <typename Tree> - display_in_K2<Tree>::display_in_K2(const Tree& t, - std::ostream& ostr) - : super(t, ostr) - { - } - - template <typename Tree> - void - display_in_K2<Tree>::print_p(const point2d& p) - { - switch (face_dim(p)) - { - case 0: - ostr << " +"; - break; - case 1: - ostr << (kn::is_1_face_horizontal(p) ? " -" : " |"); - break; - case 2: - ostr << (k2::is_primary_2_face(p) ? " O" : " x"); - break; - } - } - -# endif // ! MLN_INCLUDE_ONLY - - } // end of namespace mln::world::kn::internal - - } // end of namespace mln::world::kn - - } // end of namespace mln::world - -} // end of namespace mln - - -#endif // ! MLN_WORLD_KN_INTERNAL_DISPLAY_HH