proto-1.0 171: Preparing morpho's update.

2005-04-27 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr> Files in oln/morpho move to 'trash' since inheritance in image operators will soon be no longer in use. * oln/morpho/*.hh: Rename as... * oln/morpho/*.trash: ...this. * oln/morpho/*.inc: Rename as... * oln/morpho/*.inctrash: ...this. * oln/convert/nbh_to_se.hh: Remove cause meaningless. The changes below are for safety purpose; we should ensure that some (now commented) features are no more in use. * oln/core/2d/image2d.hh (operator=(box)): Comment. (operator=(image_like_): Comment. (image2d(const image2d&)): Add decl to help compiler. * oln/core/box.hh (operator I): New. (operator=(box<II>): Comment. (operator=(image_like_<I>)): Comment. (operator=(image_like_<II>)): Comment. (operator=(image<II>)): Comment. * oln/utils/clone.hh: Update. Index: oln/morpho/reconstruction.hh =================================================================== --- oln/morpho/reconstruction.hh (revision 166) +++ oln/morpho/reconstruction.hh (working copy) @@ -1,227 +0,0 @@ -// Copyright (C) 2001, 2002, 2004, 2005 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, 59 Temple Place - Suite 330, Boston, -// MA 02111-1307, USA. -// -// As a special exception, you may use this filek 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 OLENA_MORPHO_RECONSTRUCTION_HH -# define OLENA_MORPHO_RECONSTRUCTION_HH - -# include <queue> - -# include <mlc/cmp.hh> -# include <mlc/contract.hh> - -# include <oln/convert/nbh_to_se.hh> - -# include <oln/core/abstract/image_operator.hh> -# include <oln/core/abstract/neighborhood.hh> - -# include <oln/level/compare.hh> - -# include <oln/morpho/splitse.hh> -# include <oln/morpho/stat.hh> - -# include <oln/utils/clone.hh> - -namespace oln { - - - namespace tag { - - template <typename Op> struct oper {}; - - struct by_dilation : public oper< by_dilation > {}; - struct by_erosion : public oper< by_erosion > {}; - - - template <typename A> struct algo {}; - - struct sequential : public algo< sequential > {}; - struct hybrid : public algo< hybrid > {}; - - } // end of namespace oln::morpho::tag - - - - namespace morpho { - template <typename I1, typename I2> struct reconstruction_ret; - } // end of namespace oln::morpho - - // super_type - - template <typename I1, typename I2> - struct set_super_type< morpho::reconstruction_ret<I1, I2> > - { - typedef oln_type_of(I1, concrete) output_type; - - typedef morpho::reconstruction_ret<I1,I2> self_type; - typedef abstract::image_binary_operator<output_type, I1, I2, self_type > ret; - }; - - namespace morpho { - - // Reconstruction as a 'classical' procedure returning an image (do not - // use it; prefer morpho::reconstruction). - - namespace proc { - - // FIXME: ... - - } // end of namespace oln::morpho::proc - - - template <typename I1, typename I2> - struct reconstruction_ret : - // FIXME: oln_super_of_ - public oln::internal::get_super_type< reconstruction_ret<I1,I2> >::ret - { - typedef reconstruction_ret<I1, I2> self_type; - typedef typename oln::internal::get_super_type<self_type>::ret super_type; - - box<const I1> marker; - box<const I2> mask; - - reconstruction_ret(const abstract::image_with_nbh<I1>& marker, - const abstract::image<I2>& mask) : - super_type(marker, mask), - marker(marker), - mask(mask) - { - } - - const oln_type_of(I1, neighb)& impl_nbh_get() const - { - return marker.nbh_get(); - } - - }; - - } // end of namespace morpho - -} // end of namespace oln - -# include <oln/morpho/reconstruction_canvas.inc> - -namespace oln { - - namespace morpho { - - namespace impl { - - template<typename Op, typename A, typename I1, typename I2> - struct generic_reconstruction; - - } // end of namespace impl - - } // end of namespace morpho - -} // end of namespace oln - -# include <oln/morpho/reconstruction_by_dilation.inc> -# include <oln/morpho/reconstruction_by_erosion.inc> - -namespace oln { - - namespace morpho { - - namespace impl { - - // Generic implementation of reconstruction (routine). - - template<typename Op, typename A, typename I1, typename I2> - reconstruction_ret<I1,I2> - reconstruction(const abstract::image_with_nbh<I1>& marker, - const abstract::image<I2>& mask) - { - generic_reconstruction<Op, A, I1, I2> tmp(marker, mask); - tmp.run(); - return tmp; - } - - } // end of namespace impl - - /// Generic reconstruction (facade). - - template<typename Op, typename I1, typename I2, typename A> - reconstruction_ret<I1,I2> - reconstruction(const tag::oper<Op>& oper_, - const abstract::image_with_nbh<I1>& marker, - const abstract::image<I2>& mask, - const tag::algo<A>& algo_) - { - return impl::reconstruction<Op,A>(marker.exact(), mask.exact()); - } - - // by dilation - - template<typename I1, typename I2, typename A> - reconstruction_ret<I1,I2> - reconstruction_by_dilation(const abstract::image_with_nbh<I1>& marker, - const abstract::image<I2>& mask, - const tag::algo<A>& algo_) - { - mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure(); - precondition(marker.size() == mask.size()); - return reconstruction(tag::by_dilation(), marker, mask, algo_); - } - - template<typename I1, typename I2> - reconstruction_ret<I1,I2> - reconstruction_by_dilation(const abstract::image_with_nbh<I1>& marker, - const abstract::image<I2>& mask) - { - mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure(); - precondition(marker.size() == mask.size()); - return reconstruction(tag::by_dilation(), marker, mask, tag::hybrid()); - } - - // by erosion - - template<typename I1, typename I2, typename A> - reconstruction_ret<I1,I2> - reconstruction_by_erosion(const abstract::image_with_nbh<I1>& marker, - const abstract::image<I2>& mask, - const tag::algo<A>& algo_) - { - mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure(); - precondition(marker.size() == mask.size()); - return reconstruction(tag::by_erosion(), marker, mask, algo_); - } - - template<typename I1, typename I2> - reconstruction_ret<I1,I2> - reconstruction_by_erosion(const abstract::image_with_nbh<I1>& marker, - const abstract::image<I2>& mask) - { - mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure(); - precondition(marker.size() == mask.size()); - return reconstruction(tag::by_erosion(), marker, mask, tag::hybrid()); - } - - } // end of namespace oln::morpho - -} // end of namespace oln - -#endif // ! OLENA_MORPHO_RECONSTRUCTION_HH Index: oln/morpho/reconstruction_by_erosion.inc =================================================================== --- oln/morpho/reconstruction_by_erosion.inc (revision 166) +++ oln/morpho/reconstruction_by_erosion.inc (working copy) @@ -1,141 +0,0 @@ -// Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, -// MA 02111-1307, USA. -// -// As a special exception, you may use this filek 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. - -namespace oln { - - namespace morpho { - - namespace impl { - - // Sequential version - - template<typename I1, typename I2> - struct generic_reconstruction <tag::by_erosion, tag::sequential, I1, I2> - : public generic_reconstruction_canvas<I1, I2, tag::sequential, - generic_reconstruction<tag::by_erosion, tag::sequential, I1, I2> > - { - typedef generic_reconstruction<tag::by_erosion, - tag::sequential, I1,I2> self_type; - typedef generic_reconstruction_canvas<I1, I2, tag::sequential, - self_type> super_type; - - generic_reconstruction(const abstract::image_with_nbh<I1>& marker, - const abstract::image<I2>& mask) : - super_type(marker, mask) - { - } - - - void impl_bkd_loop_body() - { - this->output[this->bkd_p] = ntg::max(morpho::min(this->output, - this->bkd_p, - this->win_minus), - this->mask[this->bkd_p].value()); - } - - void impl_fwd_loop_body() - { - this->output[this->fwd_p] = ntg::max(morpho::min(this->output, - this->fwd_p, - this->win_plus), - this->mask[this->fwd_p].value()); - } - - void impl_preconditions() - { - precondition(level::is_greater_or_equal(this->marker, this->mask)); - } - - }; - - // Hybrid version - - template<typename I1, typename I2> - struct generic_reconstruction <tag::by_erosion, tag::hybrid, I1, I2> - : public generic_reconstruction_canvas<I1, I2, tag::hybrid, - generic_reconstruction<tag::by_erosion, tag::hybrid, I1, I2> > - { - typedef generic_reconstruction<tag::by_erosion, - tag::hybrid, I1,I2> self_type; - typedef generic_reconstruction_canvas<I1, I2, tag::hybrid, - self_type> super_type; - - generic_reconstruction(const abstract::image_with_nbh<I1>& marker, - const abstract::image<I2>& mask) : - super_type(marker, mask) - { - } - - - - void impl_bkd_loop_body() - { - this->output[this->bkd_p] = ntg::max(morpho::min(this->work, - this->bkd_p, - this->win_minus), - this->mask[this->bkd_p].value()); - } - - void impl_fwd_loop_body() - { - this->output[this->fwd_p] = ntg::max(morpho::min(this->work, - this->fwd_p, - this->win_plus), - this->mask[this->fwd_p].value()); - } - - void impl_fifo_loop_body() - { - if ((this->output[this->q] > this->output[this->p]) && - (this->mask[this->q] != this->output[this->q])) - { - this->output[this->q] = ntg::min(this->output[this->p].value(), - this->mask[this->q].value()); - this->fifo.push(this->q); - } - } - - bool impl_exist_init() - { - return this->output.hold(this->q) && - (this->output[this->q] > this->output[this->bkd_p]) && - (this->output[this->q] > this->mask[this->q]); - } - - void impl_preconditions() - { - precondition(level::is_greater_or_equal(this->marker, this->mask)); - } - - }; - - } - - } - -} Index: oln/morpho/splitse.hh =================================================================== --- oln/morpho/splitse.hh (revision 166) +++ oln/morpho/splitse.hh (working copy) @@ -1,209 +0,0 @@ -// Copyright (C) 2001, 2002, 2004, 2005 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, 59 Temple Place - Suite 330, 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 OLENA_MORPHO_SPLITSE_HH -# define OLENA_MORPHO_SPLITSE_HH - -# include <oln/basics.hh> - -# include <oln/core/1d/size1d.hh> -# include <oln/core/2d/size2d.hh> -# include <oln/core/3d/size3d.hh> - -# include <oln/core/abstract/window.hh> -# include <oln/core/abstract/window.hh> - - -namespace oln { - namespace morpho { - - template <class S> - struct dim_traits - { - }; - - template <> - struct dim_traits<size1d> - { - enum {dim = 1}; - }; - - template <> - struct dim_traits<size2d> - { - enum {dim = 2}; - }; - - template <> - struct dim_traits<size3d> - { - enum {dim = 3}; - }; - - /*! - ** \brief Get a sub part of a window. - ** - ** \param E Exact type of the window. - ** - ** \arg win The window. - ** - ** A point p take part of the new window if it exists - ** a i that belongs to [[0..dim-1]] like p(i) < 0 and for all j - ** that belongs to [[0..i-1]] p(j) = 0. - ** - */ - - - template<class W> - W - get_plus_win_only(const W& win) // FIXME: abstract::window<W>& win) - { - W out; - for (unsigned i = 0; i < win.card(); ++i) - { - const oln_wn_type_of(W, dpoint)& dp = win.get_dp()[i]; - unsigned n; - for (n = 0; n < dim_traits<oln_wn_type_of(W, size)>::dim; ++n) - if (dp.nth(n) < 0) { - out.add(dp); - break; - } else if (dp.nth(n) > 0) { - break; - } - } - return out; - } - - /*! - ** \brief Get a sub part of a window. - ** - ** \param W Exact type of the window. - ** - ** \arg win The window. - ** - ** A point p take part of the new window if it exists - ** a i that belongs to [[0..dim-1]] like p(i) < 0 and for all j - ** that belongs to [[0..i-1]] p(j) = 0 or if for all i that - ** belongs to [[0..dim-1]] p(i) = 0. - ** - */ - template<class W> - W - get_plus_win_p(const W& win) // abstract::window<W>& win) - { - W out; - for (unsigned i = 0; i < win.card(); ++i) - { - const oln_wn_type_of(W, dpoint)& dp = win.get_dp()[i]; - unsigned n; - for (n = 0; n < dim_traits<oln_wn_type_of(W, size)>::dim; ++n) - if (dp.nth(n) < 0) { - out.add(dp); - break; - } else if (dp.nth(n) > 0) { - break; - } - // All p.nth(n) are 0. - if (n == dim_traits<oln_wn_type_of(W, size)>::dim) - out.add(dp); - } - return out; - } - - /*! - ** \brief Get a sub part of a window. - ** - ** \param W Exact type of the window. - ** - ** \arg win The window. - ** - ** A point p take part of the new window if it exists - ** a i that belongs to [[0..dim-1]] like p(i) > 0 and for all j - ** that belongs to [[0..i-1]] p(j) = 0. - ** - */ - template<class W> - W - get_minus_win_only(const W& win) // abstract::window<W>& win) - { - W out; - for (unsigned i = 0; i < win.card(); ++i) - { - const oln_wn_type_of(W, dpoint)& dp = win.get_dp()[i]; - unsigned n; - for (n = 0; n < dim_traits<oln_wn_type_of(W, size)>::dim; ++n) - if (dp.nth(n) > 0) { - out.add(dp); - break; - } else if (dp.nth(n) < 0) { - break; - } - } - return out; - } - - /*! - ** \brief Get a sub part of a window. - ** - ** \param W Exact type of the window. - ** - ** \arg win The window. - ** - ** A point p take part of the new window if it exists - ** a i that belongs to [[0..dim-1]] like p(i) > 0 and for all j - ** that belongs to [[0..i-1]] p(j) = 0 or if for all i that - ** belongs to [[0..dim-1]] p(i) = 0. - ** - */ - template<class W> - W - get_minus_win_p(const W& win) // abstract::window<W>& win) - { - W out; - for (unsigned i = 0; i < win.card(); ++i) - { - const oln_wn_type_of(W, dpoint)& dp = win.get_dp()[i]; - unsigned n; - for (n = 0; n < dim_traits<oln_wn_type_of(W, size)>::dim; ++n) - if (dp.nth(n) > 0) { - out.add(dp); - break; - } else if (dp.nth(n) < 0) { - break; - } - // All p.nth(n) are 0. - if (n == dim_traits<oln_wn_type_of(W, size)>::dim) - out.add(dp); - } - return out; - } - - } // end of namespace oln::morpho - -} // end of namespace oln - -#endif // ! OLENA_MORPHO_SPLITSE_HH Index: oln/morpho/cc_tarjan.hh =================================================================== --- oln/morpho/cc_tarjan.hh (revision 166) +++ oln/morpho/cc_tarjan.hh (working copy) @@ -1,233 +0,0 @@ -// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CC_TARJAN_HH -# define OLENA_CC_TARJAN_HH - -# include <vector> - -# include <oln/basics2d.hh> -# include <oln/core/abstract/image_operator.hh> -# include <oln/level/fill.hh> - -// -// Based on "Ruminations on Tarjan's Union-Find algorithm and connected -// operators" of Thierry Geraud. -// - - -namespace oln { - - // fwd decl - namespace morpho { - template <typename T, typename I, typename E> struct cc_tarjan_ret; - } - - // FIXME: this macro is waiting for the mute. - // (we may use a property to do it) - #define tmp_mute(I, T) image2d< T > - - // category - template <typename T, typename I, typename E> - struct set_category< morpho::cc_tarjan_ret<T,I,E> > - { typedef category::image ret; }; - - // super_type - template <typename T, typename I, typename E> - struct set_super_type< morpho::cc_tarjan_ret<T,I,E> > - { - typedef abstract::image_unary_operator - <tmp_mute(I, T), I, morpho::cc_tarjan_ret<T, I, E> > - ret; - }; - - - namespace morpho { - - template <typename T, typename I, typename E> - struct cc_tarjan_ret - : public abstract::image_unary_operator - <tmp_mute(I, T), I, cc_tarjan_ret<T, I, E> > - { - typedef abstract::image_unary_operator - <tmp_mute(I, T), I, cc_tarjan_ret<T, I, E> > - super_type; - typedef typename super_type::output_type output_type; - - const E ng; - - cc_tarjan_ret(const abstract::image<I>& input, - const abstract::neighborhood<E>& ng) : - super_type(input), - ng(ng.exact()) - { - } - - }; - - - namespace impl { - - - namespace misc { - - // FIXME: This code should be generalized. - // While iterating on image and then on a neighborhood, here we do - // not want to see the neighborhood points ever seen. - std::vector<dpoint2d> get_superior(const neighborhood2d& n) - { - std::vector<dpoint2d> output; - for (unsigned i = 0; i < n.card(); ++i) - { - dpoint2d dp = n.dp(i); - if (dp.row() < 0 || (dp.row() == 0 && dp.col() < 0)) - output.push_back(dp); - } - return output; - } - - std::vector<dpoint2d> get_inferior(const neighborhood2d& n) - { - std::vector<dpoint2d> output; - for (unsigned i = 0; i < n.card(); ++i) - { - dpoint2d dp = n.dp(i); - if (dp.row() > 0 || (dp.row() == 0 && dp.col() > 0)) - output.push_back(dp); - } - return output; - } - - } // end of misc namespace - - - template <typename T, typename I, typename N> - struct generic_cc_tarjan : public cc_tarjan_ret<T, I, N> - { - typedef cc_tarjan_ret<T, I, N> super_type; - typedef typename super_type::output_type output_type; - - tmp_mute(I, oln_type_of(I, point)) parent; - T ncomps; - - generic_cc_tarjan(const abstract::image<I>& input, - const abstract::neighborhood<N>& ng) : - super_type(input, ng), - parent(input.size()) - { - } - - void impl_run() - { - mlc::eq<oln_type_of(I, size), oln_type_of(N, size)>::ensure(); - - output_type tmp(this->input.size()); // FIXME: trick - this->output = tmp; - - first_pass(); - second_pass(); - } - - void first_pass() - { - std::vector<dpoint2d> neighb = misc::get_inferior(this->ng); - oln_type_of(I, bkd_piter) p(this->input.size()); - for_all_p (p) - if (this->input[p]) - { - make_set(p); - for (unsigned v = 0; v < neighb.size(); ++v) - { - oln_type_of(I, point) n = oln_type_of(I, point)(p) + neighb[v]; - if (this->input[n]) - do_union(n, p); - } - } - } - - void second_pass() - { - oln_type_of(I, fwd_piter) p(this->input.size()); - level::fill(this->output, 0); - ncomps = 0; - for_all_p (p) - if (this->input[p]) - { - oln_type_of(I, point) q = parent[p]; - // FIXME: test if ncomps > T::max() - this->output[p] = (q == p ? ++ncomps : this->output[q]); - } - } - - void make_set(const oln_type_of(I, point)& x) - { - parent[x] = x; - } - - oln_type_of(I, point) find_root(const oln_type_of(I, point)& x) - { - if (parent[x] != x) - { - parent[x] = find_root(parent[x]); - return parent[x]; - } - return x; - } - - void do_union(const oln_type_of(I, point)& n, - const oln_type_of(I, point)& p) - { - oln_type_of(I, point) r = find_root(n); - if (r != p) - parent[r] = p; - } - - - }; - - } // end of namespace oln::morpho::impl - - - /// Connected component labelling via Tarjan Union-Find generic routine. - - // T is the component label type (usually unsigned). - template<typename T, typename I, typename N> - cc_tarjan_ret<T, I, N> cc_tarjan(const abstract::image<I>& input, - const abstract::neighborhood<N>& ng) - { - impl::generic_cc_tarjan<T, I, N> tmp(input, ng); - tmp.run(); - return tmp; - } - - - } // end of namespace oln::morpho - -} // end of namespace oln - - -#endif // ! OLENA_CC_TARJAN_HH Index: oln/morpho/reconstruction_canvas.inc =================================================================== --- oln/morpho/reconstruction_canvas.inc (revision 166) +++ oln/morpho/reconstruction_canvas.inc (working copy) @@ -1,238 +0,0 @@ -// Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, -// MA 02111-1307, USA. -// -// As a special exception, you may use this filek 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. - - -namespace oln { - - namespace morpho { - - namespace impl { - - template <typename I1, typename I2, typename A, typename E> - struct generic_reconstruction_canvas; - - template <typename I1, typename I2, typename E> - struct generic_reconstruction_canvas<I1, I2, tag::sequential, E> : - public reconstruction_ret<I1, I2> - { - typedef reconstruction_ret<I1, I2> super_type; - typedef oln_type_of(I1, neighb) nbh_type; - typedef oln_type_of(I1, concrete) output_type; - - E& exact__() - { - return *(E*)(void*)(this); - } - - void bkd_loop_body() - { - this->exact__().impl_bkd_loop_body(); - } - void fwd_loop_body() - { - this->exact__().impl_fwd_loop_body(); - } - - void preconditions() - { - mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure(); - precondition(this->marker.size() == this->mask.size()); - this->exact__().impl_preconditions(); - } - - void init() - { - // no call to impl_init here because this canvas can't be generalized yet. - this->output = utils::clone(this->marker); - this->work = utils::clone(this->marker); - - win_plus = get_plus_win_p(convert::nbh_to_cse(this->marker.nbh_get())); - win_minus = get_minus_win_p(convert::nbh_to_cse(this->marker.nbh_get())); - } - - bool is_stable() - { - // same explanation as above - return level::is_equal(this->work, this->output); - } - - void impl_run() - { - this->preconditions(); - this->init(); - for (;;) - { - for_all_p (fwd_p) - this->fwd_loop_body(); - for_all_p (bkd_p) - this->bkd_loop_body(); - if (this->is_stable()) - return; - work = utils::clone(this->output); - } - } - - protected: - - generic_reconstruction_canvas(const abstract::image_with_nbh<I1>& marker, - const abstract::image<I2>& mask) : - super_type(marker, mask), - bkd_p(marker.size()), - fwd_p(marker.size()) - { - } - - - oln_type_of(I1, bkd_piter) bkd_p; - oln_type_of(I1, fwd_piter) fwd_p; - - oln_nbh_type_of(nbh_type, window) win_plus; - oln_nbh_type_of(nbh_type, window) win_minus; - - box<oln_type_of(I1, concrete)> work; - }; - - template <typename I1, typename I2, typename E> - struct generic_reconstruction_canvas<I1, I2, tag::hybrid, E> : - public reconstruction_ret<I1, I2> - { - typedef reconstruction_ret<I1, I2> super_type; - typedef oln_type_of(I1, neighb) nbh_type; - typedef oln_nbh_type_of(nbh_type, window) window_type; - typedef oln_type_of(I1, concrete) output_type; - - E& exact__() - { - return *(E*)(void*)(this); - } - - - bool exist_init() - { - for (unsigned i = 0; i < win_minus.card(); ++i) - { - q = win_minus.get_dp()[i] + (oln_type_of(I1, point))bkd_p; - if (this->exact__().impl_exist_init()) - return true; - } - return false; - } - - void bkd_loop_body() - { - this->exact__().impl_bkd_loop_body(); - } - void fwd_loop_body() - { - this->exact__().impl_fwd_loop_body(); - } - - void fifo_loop_body() - { - this->exact__().impl_fifo_loop_body(); - } - - void preconditions() - { - mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure(); - precondition(this->marker.size() == this->mask.size()); - this->exact__().impl_preconditions(); - } - - void init() - { - output_type tmp(this->marker.size()); - - this->output = tmp; - this->work = utils::clone(this->marker); - - win_plus = get_plus_win_p(convert::nbh_to_cse(this->marker.nbh_get())); - win_minus = get_minus_win_p(convert::nbh_to_cse(this->marker.nbh_get())); - } - - void impl_run() - { - this->preconditions(); - this->init(); - - for_all_p (fwd_p) - this->fwd_loop_body(); - - for_all_p (bkd_p) - { - bkd_loop_body(); - if (exist_init()) - fifo.push(bkd_p); - } - // Propagation Step - while (!fifo.empty()) - { - p = fifo.front(); - fifo.pop(); - - window_type win = convert::nbh_to_se(this->marker.nbh_get()); - for (unsigned i = 0; i < win.card(); ++i) - { - q = win.get_dp()[i] + p; - - if (this->output.hold(q)) - fifo_loop_body(); - } - } - } - - protected: - - generic_reconstruction_canvas(const abstract::image_with_nbh<I1>& marker, - const abstract::image<I2>& mask) : - super_type(marker, mask), - bkd_p(marker.size()), - fwd_p(marker.size()) - { - } - - - oln_type_of(I1, bkd_piter) bkd_p; - oln_type_of(I1, fwd_piter) fwd_p; - - oln_type_of(I1, point) p; - oln_type_of(I1, point) q; - - window_type win_plus; - window_type win_minus; - - box<oln_type_of(I1, concrete)> work; - - std::queue<oln_type_of(I1, point) > fifo; - - }; - - } // end of namespace impl - - } // end of namespace morpho - -} // end of namespace oln Index: oln/morpho/closing.hh =================================================================== --- oln/morpho/closing.hh (revision 166) +++ oln/morpho/closing.hh (working copy) @@ -1,165 +0,0 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2005 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, 59 Temple Place - Suite 330, 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 OLENA_MORPHO_CLOSING_HH -# define OLENA_MORPHO_CLOSING_HH - -# include <mlc/cmp.hh> -# include <mlc/to_string.hh> - -# include <oln/core/abstract/image_operator.hh> - -# include <oln/morpho/dilation.hh> -# include <oln/morpho/erosion.hh> -# include <oln/core/2d/window2d.hh> - - -namespace oln { - - - // fwd decl - - namespace morpho { - template <typename I> struct closing_ret; - } - - // super_type - - template <typename I> - struct set_super_type< morpho::closing_ret<I> > - { - typedef oln_type_of(I, concrete) output_type; - - typedef morpho::closing_ret<I> self_type; - typedef abstract::image_unary_operator<output_type, I, self_type > ret; - }; - - - - - namespace morpho { - - - - // Closing as a 'classical' procedure returning an image (do not - // use it; prefer morpho::closing). - - namespace proc { - - template<typename I, typename W> - oln_type_of(I, concrete) closing(const abstract::image<I>& input, - const abstract::window<W>& win) - { - mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); - oln_type_of(I, concrete) output(input.size()); - output = morpho::erosion(morpho::dilation(input, win), win); - return output; - } - - } // end of namespace oln::morpho::proc - - - - /// Closing return type. - - template <typename I> - struct closing_ret : public oln_super_of_(closing_ret<I>) - { - typedef oln_super_of(closing_ret<I>) super_type; - - closing_ret(const abstract::image<I>& input) : - super_type(input) - { - } - - }; - - - // Various implementation. - - namespace impl { - - - /// Generic implementation of closing (type). - - template <typename I, typename W> - struct generic_closing : public closing_ret<I> - { - typedef closing_ret<I> super_type; - // FIXME: typedef oln_type_of(super_type, output) output_type; - - const W& win; - - generic_closing(const abstract::image<I>& input, - const abstract::window<W>& win) : - super_type(input), - win(win.exact()) - { - } - - void impl_run() - { - oln_type_of(super_type, output) tmp(input.size()); - tmp = morpho::erosion(morpho::dilation(input, win), win); - output = tmp; - } - }; - - // Generic implementation of closing (routine). - - template<typename I, typename W> - closing_ret<I> closing(const abstract::image<I>& input, - const abstract::window<W>& win) - { - impl::generic_closing<I,W> tmp(input, win); - tmp.run(); - return tmp; - } - - // FIXME: Add specialized implementations. - - } // end of namespace oln::morpho::impl - - - /// Generic closing (facade). - - template<typename I, typename W> - closing_ret<I> closing(const abstract::image<I>& input, - const abstract::window<W>& win) - { - mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); - return impl::closing(input.exact(), win.exact()); - } - - - } // end of namespace oln::morpho - - -} // end of namespace oln - - -#endif // ! OLENA_MORPHO_CLOSING_HH Index: oln/morpho/opening.hh =================================================================== --- oln/morpho/opening.hh (revision 166) +++ oln/morpho/opening.hh (working copy) @@ -1,165 +0,0 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2005 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, 59 Temple Place - Suite 330, 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 OLENA_MORPHO_OPENING_HH -# define OLENA_MORPHO_OPENING_HH - -# include <mlc/cmp.hh> -# include <mlc/to_string.hh> - -# include <oln/core/abstract/image_operator.hh> - -# include <oln/morpho/dilation.hh> -# include <oln/morpho/erosion.hh> -# include <oln/core/2d/window2d.hh> - - -namespace oln { - - - // fwd decl - - namespace morpho { - template <typename I> struct opening_ret; - } - - // super_type - - template <typename I> - struct set_super_type< morpho::opening_ret<I> > - { - typedef oln_type_of(I, concrete) output_type; - - typedef morpho::opening_ret<I> self_type; - typedef abstract::image_unary_operator<output_type, I, self_type > ret; - }; - - - - - namespace morpho { - - - - // Opening as a 'classical' procedure returning an image (do not - // use it; prefer morpho::opening). - - namespace proc { - - template<typename I, typename W> - oln_type_of(I, concrete) opening(const abstract::image<I>& input, - const abstract::window<W>& win) - { - mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); - oln_type_of(I, concrete) output(input.size()); - output = morpho::dilation(morpho::erosion(input, win), win); - return output; - } - - } // end of namespace oln::morpho::proc - - - - /// Opening return type. - - template <typename I> - struct opening_ret : public oln_super_of_(opening_ret<I>) - { - typedef oln_super_of(opening_ret<I>) super_type; - - opening_ret(const abstract::image<I>& input) : - super_type(input) - { - } - - }; - - - // Various implementation. - - namespace impl { - - - /// Generic implementation of opening (type). - - template <typename I, typename W> - struct generic_opening : public opening_ret<I> - { - typedef opening_ret<I> super_type; - // FIXME: typedef oln_type_of(super_type, output) output_type; - - const W& win; - - generic_opening(const abstract::image<I>& input, - const abstract::window<W>& win) : - super_type(input), - win(win.exact()) - { - } - - void impl_run() - { - oln_type_of(super_type, output) tmp(input.size()); - tmp = morpho::dilation(morpho::erosion(input, win), win); - output = tmp; - } - }; - - // Generic implementation of opening (routine). - - template<typename I, typename W> - opening_ret<I> opening(const abstract::image<I>& input, - const abstract::window<W>& win) - { - impl::generic_opening<I,W> tmp(input, win); - tmp.run(); - return tmp; - } - - // FIXME: Add specialized implementations. - - } // end of namespace oln::morpho::impl - - - /// Generic opening (facade). - - template<typename I, typename W> - opening_ret<I> opening(const abstract::image<I>& input, - const abstract::window<W>& win) - { - mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); - return impl::opening(input.exact(), win.exact()); - } - - - } // end of namespace oln::morpho - - -} // end of namespace oln - - -#endif // ! OLENA_MORPHO_OPENING_HH Index: oln/morpho/dilation.hh =================================================================== --- oln/morpho/dilation.hh (revision 166) +++ oln/morpho/dilation.hh (working copy) @@ -1,202 +0,0 @@ -// Copyright (C) 2001, 2002, 2004, 2005 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, 59 Temple Place - Suite 330, Boston, -// MA 02111-1307, USA. -// -// As a special exception, you may use this filek 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 OLENA_MORPHO_DILATION_HH -# define OLENA_MORPHO_DILATION_HH - -# include <mlc/cmp.hh> - -# include <oln/core/abstract/image_operator.hh> -# include <oln/morpho/stat.hh> - - -namespace oln { - - namespace morpho { - - - - namespace proc { - - /// Dilation as a procedure (do not use it; prefer morpho::dilation). - - template<typename I, typename W> - oln_type_of(I, concrete) dilation(const abstract::image<I>& input, - const abstract::window<W>& win) - { - oln_type_of(I, concrete) output(input.size()); - oln_type_of(I, fwd_piter) p(input.size()); - for_all_p (p) - output[p] = morpho::max(input, p, win); - return output; - } - - } // end of namespace oln::morpho::proc - - - - /*! - ** \brief Processing dilation. - ** - ** Compute the morphological dilation of input using win - ** as structural element.\n - ** - ** On grey-scale images, each point is replaced by the maximum value - ** of its neighbors, as indicated by win. On binary images, - ** a logical or is performed between neighbors.\n - ** - ** The morpho::fast version of this function use a different - ** algorithm: This algorithm is described in - ** Implementation of morphological operations from: - ** M. Van Droogenbroeck and H. Talbot. - ** "Fast computation of morphological operations with arbitrary - ** structuring elements". Pattern Recognition Letters, - ** 17(14):1451-1460, 1996.\n - ** - ** An histogram of the value of the neighborhood indicated by - ** win is updated while iterating over all point of the - ** image. Doing so is more efficient when the - ** structural element is large.\n - ** - ** \param I Exact type of the input image. - ** \param E Exact type of the neighborhood. - ** - ** \arg input The input image. - ** \arg win Structuring element to use. - ** - ** \code - ** #include <oln/basics2d.hh> - ** #include <oln/morpho/dilation.hh> - ** #include <oln/level/compare.hh> - ** #include <ntg/all.hh> - ** int main() - ** { - ** typedef oln::image2d<ntg::bin> im_type; - ** - ** im_type im1(oln::load(IMG_IN "object.pbm")); - ** save(oln::morpho::dilation(im1, oln::win_c8p()), - ** IMG_OUT "oln_morpho_dilation.pbm"); - ** } - ** \endcode - ** - ** \image html object_pbm.png - ** \image latex object_pbm.png - ** => - ** \image html oln_morpho_dilation.png - ** \image latex oln_morpho_dilation.png - */ - - // fwd decl - template <typename I, typename E> struct dilation_ret; - - } - - // category - template <typename I, typename E> - struct set_category< morpho::dilation_ret<I,E> > { typedef category::image ret; }; - - // super_type - template <typename I, typename E> - struct set_super_type< morpho::dilation_ret<I,E> > - { - typedef abstract::image_unary_operator<oln_type_of(I, concrete), I, morpho::dilation_ret<I, E> > ret; - }; - - - - namespace morpho { - - /// Dilatation return. - - template <typename I, typename W> - struct dilation_ret : public abstract::image_unary_operator<oln_type_of(I, concrete), I, dilation_ret<I,W> > - { - typedef abstract::image_unary_operator<oln_type_of(I, concrete), I, dilation_ret<I,W> > super_type; - typedef typename super_type::output_type output_type; - - const W win; - - dilation_ret(const abstract::image<I>& input, - const abstract::window<W>& win) : - super_type(input.exact()), - win(win.exact()) - { - } - - }; - - - // Implementation: - - namespace impl { - - /// Dilation generic implementation. - - template <typename I, typename W> - struct generic_dilation : public dilation_ret<I,W> - { - typedef dilation_ret<I,W> super_type; - typedef typename super_type::output_type output_type; - - generic_dilation(const abstract::image<I>& input, - const abstract::window<W>& win) : - super_type(input, win) - { - } - - void impl_run() - { - mlc::eq<oln_type_of(I, size), oln_wn_type_of(W, size)>::ensure(); - - output_type tmp(this->input.size()); // FIXME: trick - this->output = tmp; - - oln_type_of(I, fwd_piter) p(this->input.size()); - for_all_p (p) - this->output[p] = morpho::max(this->input, p, this->win); - } - }; - - } // end of namespace oln::morpho::impl - - - /// Dilation generic routine. - - template<typename I, typename W> - dilation_ret<I,W> dilation(const abstract::image<I>& input, - const abstract::window<W>& win) - { - impl::generic_dilation<I,W> tmp(input, win); - tmp.run(); - return tmp; - } - - } // end of morpho - -} // end of oln - -#endif // ! OLENA_MORPHO_DILATION_HH Index: oln/morpho/geodesic_dilation.hh =================================================================== --- oln/morpho/geodesic_dilation.hh (revision 166) +++ oln/morpho/geodesic_dilation.hh (working copy) @@ -1,141 +0,0 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2005 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, 59 Temple Place - Suite 330, 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 OLENA_MORPHO_GEODESIC_DILATION_HH -# define OLENA_MORPHO_GEODESIC_DILATION_HH - -# include <mlc/cmp.hh> - -# include <oln/core/abstract/image_operator.hh> -# include <oln/morpho/stat.hh> -# include <oln/level/compare.hh> -# include <oln/arith/min.hh> - -# include <oln/core/abstract/neighborhood.hh> -# include <oln/morpho/dilation.hh> - -namespace oln { - - namespace morpho { - - // fwd declaration - template <class I1, class I2> struct geodesic_dilation_ret; - - namespace proc { - - template<class I1, class I2> - oln_type_of(I1, concrete) - geodesic_dilation(const abstract::image_with_nbh<I1>& marker, - const abstract::image<I2>& mask) - { - mlc::eq<oln_type_of(I1, size), oln_type_of(I2, size)>::ensure(); - precondition(marker.size() == mask.size()); - precondition(level::is_greater_or_equal(mask, marker)); - oln_type_of(I1, concrete) output(marker.size()); - // FIXME: Useless? - // marker.border_adapt_copy(marker.nbh_get().delta()); - oln_type_of(I1, piter) p(marker.size()); - for_all_p (p) - { - oln_type_of(I1, value) a = - morpho::max(marker, p, marker.nbh_get().get_win()); - oln_type_of(I2, value) b = mask[p]; - // Min. - output[p] = a < b ? a : b; - } - return output; - } - - } // end of namespace oln::morpho::proc - - } // end of namespace oln::morpho - - - - // super_type - template <class I1, class I2> - struct set_super_type< morpho::geodesic_dilation_ret<I1, I2> > - { - typedef abstract::image_binary_operator<oln_type_of(I1, concrete), I1, I2, morpho::geodesic_dilation_ret<I1, I2> > ret; - }; - - - namespace morpho { - - template <class I1, class I2> - struct geodesic_dilation_ret : public abstract::image_binary_operator<oln_type_of(I1, concrete), I1, I2, morpho::geodesic_dilation_ret<I1, I2> > - { - typedef abstract::image_binary_operator<oln_type_of(I1, concrete), I1, I2, geodesic_dilation_ret<I1, I2> > super_type; - - geodesic_dilation_ret(const abstract::image_with_nbh<I1>& marker, - const abstract::image<I2>& mask) : - super_type(marker, mask) - {} - }; - - - namespace safe { - - template <class I1, class I2> - struct geodesic_dilation : public geodesic_dilation_ret<I1, I2> - { - typedef geodesic_dilation_ret<I1, I2> super_type; - - geodesic_dilation(const abstract::image_with_nbh<I1>& marker, - const abstract::image<I2>& mask) : - super_type(marker, mask) - {} - - void impl_run() - { - mlc::eq<oln_type_of(I1, size), oln_type_of(I2, size)>::ensure(); - precondition((this->input1).size() == (this->input2).size()); - precondition(level::is_greater_or_equal(this->input2, this->input1)); - this->output = - arith::min(dilation(this->input1.unbox(), - this->input1.unbox().nbh_get().get_win()).output.unbox(), - this->input2.unbox()).output; - } - }; - - } // end of namespace oln::morpho::safe - - template<class I1, class I2> - geodesic_dilation_ret<I1, I2> - geodesic_dilation(const abstract::image_with_nbh<I1>& marker, - const abstract::image<I2>& mask) - { - safe::geodesic_dilation<I1, I2> tmp(marker, mask); - tmp.run(); - return tmp; - } - - } // end of namespace oln::morpho - -} // end of namespace oln - -#endif // OLENA_MORPHO_GEODESIC_DILATION_HH Index: oln/morpho/reconstruction_by_dilation.inc =================================================================== --- oln/morpho/reconstruction_by_dilation.inc (revision 166) +++ oln/morpho/reconstruction_by_dilation.inc (working copy) @@ -1,142 +0,0 @@ -// Copyright (C) 2005 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, 59 Temple Place - Suite 330, Boston, -// MA 02111-1307, USA. -// -// As a special exception, you may use this filek 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. - -namespace oln { - - namespace morpho { - - namespace impl { - - // Sequential version - - template<typename I1, typename I2> - struct generic_reconstruction <tag::by_dilation, tag::sequential, I1, I2> - : public generic_reconstruction_canvas<I1, I2, tag::sequential, - generic_reconstruction<tag::by_dilation, tag::sequential, I1, I2> > - { - typedef generic_reconstruction<tag::by_dilation, - tag::sequential, I1,I2> self_type; - typedef generic_reconstruction_canvas<I1, I2, tag::sequential, - self_type> super_type; - - generic_reconstruction(const abstract::image_with_nbh<I1>& marker, - const abstract::image<I2>& mask) : - super_type(marker, mask) - { - } - - - void impl_bkd_loop_body() - { - this->output[this->bkd_p] = ntg::min(morpho::max(this->output, - this->bkd_p, - this->win_minus), - this->mask[this->bkd_p].value()); - } - - void impl_fwd_loop_body() - { - this->output[this->fwd_p] = ntg::min(morpho::max(this->output, - this->fwd_p, - this->win_plus), - this->mask[this->fwd_p].value()); - } - - void impl_preconditions() - { - precondition(level::is_greater_or_equal(this->mask, this->marker)); - } - - }; - - - // Hybrid version - - template<typename I1, typename I2> - struct generic_reconstruction <tag::by_dilation, tag::hybrid, I1, I2> - : public generic_reconstruction_canvas<I1, I2, tag::hybrid, - generic_reconstruction<tag::by_dilation, tag::hybrid, I1, I2> > - { - typedef generic_reconstruction<tag::by_dilation, - tag::hybrid, I1,I2> self_type; - typedef generic_reconstruction_canvas<I1, I2, tag::hybrid, - self_type> super_type; - - generic_reconstruction(const abstract::image_with_nbh<I1>& marker, - const abstract::image<I2>& mask) : - super_type(marker, mask) - { - } - - - - void impl_bkd_loop_body() - { - this->output[this->bkd_p] = ntg::min(morpho::max(this->work, - this->bkd_p, - this->win_minus), - this->mask[this->bkd_p].value()); - } - - void impl_fwd_loop_body() - { - this->output[this->fwd_p] = ntg::min(morpho::max(this->work, - this->fwd_p, - this->win_plus), - this->mask[this->fwd_p].value()); - } - - void impl_fifo_loop_body() - { - if ((this->output[this->q] < this->output[this->p]) && - (this->mask[this->q] != this->output[this->q])) - { - this->output[this->q] = ntg::min(this->output[this->p].value(), - this->mask[this->q].value()); - this->fifo.push(this->q); - } - } - - bool impl_exist_init() - { - return this->output.hold(this->q) && - (this->output[this->q] < this->output[this->bkd_p]) && - (this->output[this->q] < this->mask[this->q]); - } - - void impl_preconditions() - { - precondition(level::is_greater_or_equal(this->mask, this->marker)); - } - - }; - - } - - } - -} Index: oln/morpho/stat.hh =================================================================== --- oln/morpho/stat.hh (revision 166) +++ oln/morpho/stat.hh (working copy) @@ -1,122 +0,0 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2005 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, 59 Temple Place - Suite 330, 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 OLENA_MORPHO_STAT_HH -# define OLENA_MORPHO_STAT_HH - -# include <mlc/cmp.hh> -# include <ntg/bin.hh> -# include <oln/core/abstract/image_entry.hh> -# include <oln/core/abstract/window.hh> -# include <oln/funobj/accum.hh> - - -namespace oln { - - namespace morpho { - - - /// Local min on a function. - - template <typename I, typename W> - oln_type_of(I, value) min(const abstract::image<I>& input, - const oln_type_of(I, point)& p, - const abstract::window<W>& win) - { - mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); - - oln_wn_type_of(W, fwd_iter) q(win); - funobj::min_accumulator<oln_type_of(I, value)> minval; - - for_all_q_of_p (q, p) - if (input.hold(q)) - minval(input[q]); - - return minval; - } - - - /// Local min on a set. - - template <typename I, typename W> - bool min(const abstract::binary_image<I>& input, - const oln_type_of(I, point)& p, - const abstract::window<W>& win) - { - mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); - - oln_wn_type_of(W, fwd_iter) q(win); - for_all_q_of_p (q, p) - if (input.hold(q) and not input[q]) - return false; - return true; - } - - - /// Local max on a function. - - template <typename I, typename W> - oln_type_of(I, value) max(const abstract::image<I>& input, - const oln_type_of(I, point)& p, - const abstract::window<W>& win) - { - mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); - - oln_wn_type_of(W, fwd_iter) q(win); - funobj::max_accumulator<oln_type_of(I, value)> maxval; - - for_all_q_of_p (q, p) - if (input.hold(q)) - maxval(input[q]); - - return maxval; - } - - - /// Local max on a set. - - template <typename I, typename W> - bool max(const abstract::binary_image<I>& input, - const oln_type_of(I, point)& p, - const abstract::window<W>& win) - { - mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); - - oln_wn_type_of(W, fwd_iter) q(win); - for_all_q_of_p (q, p) - if (input.hold(q) and input[q]) - return true; - return false; - } - - - } // end of namespace morpho - -} // end of namespace oln - - -#endif // ! OLENA_MORPHO_STAT_HH Index: oln/morpho/erosion.hh =================================================================== --- oln/morpho/erosion.hh (revision 166) +++ oln/morpho/erosion.hh (working copy) @@ -1,220 +0,0 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2005 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, 59 Temple Place - Suite 330, 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 OLENA_MORPHO_EROSION_HH -# define OLENA_MORPHO_EROSION_HH - -# include <mlc/cmp.hh> -# include <mlc/to_string.hh> - -# include <oln/core/abstract/image_operator.hh> -# include <oln/morpho/stat.hh> - -# include <oln/core/2d/window2d.hh> - - -namespace oln { - - - // fwd decl - - namespace morpho { - template <typename I> struct erosion_ret; - - template<typename I, typename W> - erosion_ret<I> erosion(const abstract::image<I>& input, - const abstract::window<W>& win); - } - - // super_type - - template <typename I> - struct set_super_type< morpho::erosion_ret<I> > - { - typedef oln_type_of(I, concrete) output_type; - - typedef morpho::erosion_ret<I> self_type; - typedef abstract::image_unary_operator<output_type, I, self_type > ret; - }; - - - - - namespace morpho { - - - - // Erosion as a 'classical' procedure returning an image (do not - // use it; prefer morpho::erosion). - - namespace proc { - - template<typename I, typename W> - oln_type_of(I, concrete) erosion(const abstract::image<I>& input, - const abstract::window<W>& win) - { - mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); - oln_type_of(I, concrete) output(input.size()); - oln_type_of(I, fwd_piter) p(input.size()); - for_all_p (p) - output[p] = morpho::min(input, p, win); - return output; - } - - } // end of namespace oln::morpho::proc - - - - /// Erosion return type. - - template <typename I> - struct erosion_ret : public oln_super_of_(erosion_ret<I>) - { - typedef oln_super_of(erosion_ret<I>) super_type; - - erosion_ret(const abstract::image<I>& input) : - super_type(input) - { - } - - }; - - - // Various implementation. - - - namespace impl { - - - /// Generic implementation of erosion (type). - - template <typename I, typename W> - struct generic_erosion : public erosion_ret<I> - { - typedef erosion_ret<I> super_type; - // FIXME: typedef oln_type_of(super_type, output) output_type; - - const W& win; - - generic_erosion(const abstract::image<I>& input, - const abstract::window<W>& win) : - super_type(input), - win(win.exact()) - { - } - - void impl_run() - { - oln_type_of(super_type, output) tmp(this->input.size()); // FIXME: trick - this->output = tmp; - // FIXME: output.resize(input.size); - - oln_type_of(I, fwd_piter) p(this->input.size()); - for_all_p (p) - this->output[p] = morpho::min(this->input, p, this->win); - } - }; - - // Generic implementation of erosion (routine). - - template<typename I, typename W> - erosion_ret<I> erosion(const abstract::image<I>& input, - const abstract::window<W>& win) - { - impl::generic_erosion<I,W> tmp(input, win); - tmp.run(); - return tmp; - } - - - - - /// Rectangle2d implementation of erosion (type). - - template <typename I> - struct rectangle2d_erosion : public erosion_ret<I> - { - typedef erosion_ret<I> super_type; - // FIXME: typedef oln_type_of(super_type, output) output_type; - - const win_rectangle2d& win; - - rectangle2d_erosion(const abstract::image<I>& input, - const win_rectangle2d& win) : - super_type(input), - win(win) - {} - - void impl_run() - { - box<oln_type_of(super_type, output)> temp; // FIXME: box? - // FIXME: output_type temp; - - win_hline2d hline(this->win.width); - win_vline2d vline(this->win.height); - - temp = oln::morpho::erosion(this->input, hline); - this->output = oln::morpho::erosion(temp, vline); - } - }; - - // Rectangle2d implementation of erosion (routine). - - template<typename I> - erosion_ret<I> erosion(const abstract::image<I>& input, - const win_rectangle2d& win) - { - impl::rectangle2d_erosion<I> tmp(input, win); - tmp.run(); - return tmp; - } - - - - - } // end of namespace oln::morpho::impl - - - - /// Generic erosion (facade). - - template<typename I, typename W> - erosion_ret<I> erosion(const abstract::image<I>& input, - const abstract::window<W>& win) - { - mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); - return impl::erosion(input.exact(), win.exact()); - } - - - } // end of namespace oln::morpho - - -} // end of namespace oln - - -#endif // ! OLENA_MORPHO_EROSION_HH Index: oln/morpho/hit_or_miss.hh =================================================================== --- oln/morpho/hit_or_miss.hh (revision 166) +++ oln/morpho/hit_or_miss.hh (working copy) @@ -1,186 +0,0 @@ -// Copyright (C) 2001, 2003, 2004, 2005 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, 59 Temple Place - Suite 330, 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 OLENA_MORPHO_HIT_OR_MISS_HH -# define OLENA_MORPHO_HIT_OR_MISS_HH - -# include <oln/core/gen/image_with_nbh.hh> -# include <oln/morpho/erosion.hh> -# include <oln/morpho/dilation.hh> -# include <oln/arith/min.hh> -# include <oln/utils/invert.hh> - -namespace oln { - - namespace tag { - - // No tags yet - - } // end of namespace oln::morpho::tag - - - namespace morpho { - template <typename I, typename W1, typename W2> struct hit_or_miss_ret; - } // end of namespace oln::morpho - - // super_type - - template <typename I, typename W1, typename W2> - struct set_super_type< morpho::hit_or_miss_ret<I, W1, W2> > - { - typedef oln_type_of(I, concrete) output_type; - - typedef morpho::hit_or_miss_ret<I, W1, W2> self_type; - typedef abstract::image_unary_operator<output_type, I, self_type > ret; - }; - - namespace morpho { - - // Reconstruction as a 'classical' procedure returning an image (do not - // use it; prefer morpho::hit_or_miss). - - namespace proc { - - // FIXME: ... - - } // end of namespace oln::morpho::proc - - - template <typename I, typename W1, typename W2> - struct hit_or_miss_ret : - // FIXME: oln_super_of_ - public oln::internal::get_super_type< hit_or_miss_ret<I, W1, W2> >::ret - { - typedef hit_or_miss_ret<I, W1, W2> self_type; - typedef typename oln::internal::get_super_type<self_type>::ret super_type; - const W1& win1; - const W2& win2; - - hit_or_miss_ret(const abstract::image<I>& input, - const abstract::regular_window<oln_type_of(I, grid), W1> win1, - const abstract::regular_window<oln_type_of(I, grid), W2> win2) : - super_type(input), - win1(win1.exact()), - win2(win2.exact()) - { - } - - }; - - - namespace impl { - - template <typename I, typename W1, typename W2> - struct generic_hit_or_miss : public hit_or_miss_ret<I, W1, W2> - { - typedef hit_or_miss_ret<I, W1, W2> super_type; - - generic_hit_or_miss(const abstract::image<I>& input, - const abstract::regular_window<oln_type_of(I, grid), W1> win1, - const abstract::regular_window<oln_type_of(I, grid), W2> win2) : - super_type(input, win1, win2) - { - } - - void impl_run() - { - this->output = arith::min(erosion(this->input, this->win1), - erosion(utils::invert(this->input), - this->win2)); - } - }; - - template <typename I, typename W1, typename W2> - hit_or_miss_ret<I, W1, W2> - hit_or_miss(const abstract::image<I>& input, - const abstract::regular_window<oln_type_of(I, grid), W1> win1, - const abstract::regular_window<oln_type_of(I, grid), W2> win2) - { - generic_hit_or_miss<I, W1, W2> tmp(input, win1, win2); - tmp.run(); - return tmp; - } - - } //end of namespace impl - - template <typename I, typename W1, typename W2> - hit_or_miss_ret<I, W1, W2> - hit_or_miss(const abstract::image<I>& input, - const abstract::regular_window<oln_type_of(I, grid), W1> win1, - const abstract::regular_window<oln_type_of(I, grid), W2> win2) - { - // FIXME: win1 inter win2 must be empty - return impl::hit_or_miss(input.exact(), win1.exact(), win2.exact()); - } - - - template<class I, class W1, class W2> - dilation_ret<hit_or_miss_ret<I, W1, W2>, W1> - hit_or_miss_opening(const abstract::image<I>& input, - const abstract::regular_window<oln_type_of(I, grid), W1> win1, - const abstract::regular_window<oln_type_of(I, grid), W2> win2) - { - return dilation(hit_or_miss(input, win1, win2), -win1); - } - - template<class I, class W1, class W2> - dilation_ret<hit_or_miss_ret<I, W2, W1>, W2> - hit_or_miss_opening_bg(const abstract::image<I>& input, - const abstract::regular_window<oln_type_of(I, grid), W1> win1, - const abstract::regular_window<oln_type_of(I, grid), W2> win2) - { - return hit_or_miss_opening(input, win2, win1); - } - - template<class I, class W1, class W2> - utils::image_inverted<dilation_ret<hit_or_miss_ret<utils::image_inverted<I>, - W1, W2>, W1> > // !!! - hit_or_miss_closing(const abstract::image<I>& input, - const abstract::regular_window<oln_type_of(I, grid), W1> win1, - const abstract::regular_window<oln_type_of(I, grid), W2> win2) - { - return utils::invert(hit_or_miss_opening(utils::invert(input), - win1, win2)); - } - - template<class I, class W1, class W2> - utils::image_inverted<dilation_ret<hit_or_miss_ret<utils::image_inverted<I>, - W2, W1>, W2> > // !!! - hit_or_miss_closing_bg(const abstract::image<I>& input, - const abstract::regular_window<oln_type_of(I, grid), W1> win1, - const abstract::regular_window<oln_type_of(I, grid), W2> win2) - { - return hit_or_miss_closing(input, win2, win1); - } - - - - } // end of namespace morpho - -} // end of namespace oln - -#endif // ! OLENA_MORPHO_HIT_OR_MISS_HH Index: oln/morpho/geodesic_erosion.hh =================================================================== --- oln/morpho/geodesic_erosion.hh (revision 166) +++ oln/morpho/geodesic_erosion.hh (working copy) @@ -1,140 +0,0 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2005 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, 59 Temple Place - Suite 330, 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 OLENA_MORPHO_GEODESIC_EROSION_HH -# define OLENA_MORPHO_GEODESIC_EROSION_HH - -# include <mlc/cmp.hh> - -# include <oln/core/abstract/image_operator.hh> -# include <oln/morpho/stat.hh> -# include <oln/level/compare.hh> -# include <oln/arith/max.hh> - -# include <oln/core/abstract/neighborhood.hh> -# include <oln/morpho/erosion.hh> - -namespace oln { - - namespace morpho { - - // fwd declaration - template <class I1, class I2> struct geodesic_erosion_ret; - - namespace proc { - - template<class I1, class I2> - oln_type_of(I1, concrete) - geodesic_erosion(const abstract::image_with_nbh<I1>& marker, - const abstract::image<I2>& mask) - { - mlc::eq<oln_type_of(I1, size), oln_type_of(I2, size)>::ensure(); - precondition(marker.size() == mask.size()); - precondition(level::is_greater_or_equal(marker, mask)); - oln_type_of(I1, concrete) output(marker.size()); - // FIXME: Useless? - // marker.border_adapt_copy(marker.nbh_get().delta()); - oln_type_of(I1, piter) p(marker.size()); - for_all_p (p) - { - oln_type_of(I1, value) a = - morpho::min(marker, p, marker.nbh_get().get_win()); - oln_type_of(I2, value) b = mask[p]; - // Max. - output[p] = a > b ? a : b; - } - return output; - } - - } // end of namespace oln::morpho::proc - - } // end of namespace oln::morpho - - - // super_type - template <class I1, class I2> - struct set_super_type< morpho::geodesic_erosion_ret<I1, I2> > - { - typedef abstract::image_binary_operator<oln_type_of(I1, concrete), I1, I2, morpho::geodesic_erosion_ret<I1, I2> > ret; - }; - - - namespace morpho { - - template <class I1, class I2> - struct geodesic_erosion_ret : public abstract::image_binary_operator<oln_type_of(I1, concrete), I1, I2, morpho::geodesic_erosion_ret<I1, I2> > - { - typedef abstract::image_binary_operator<oln_type_of(I1, concrete), I1, I2, geodesic_erosion_ret<I1, I2> > super_type; - - geodesic_erosion_ret(const abstract::image_with_nbh<I1>& marker, - const abstract::image<I2>& mask) : - super_type(marker, mask) - {} - }; - - - namespace safe { - - template <class I1, class I2> - struct geodesic_erosion : public geodesic_erosion_ret<I1, I2> - { - typedef geodesic_erosion_ret<I1, I2> super_type; - - geodesic_erosion(const abstract::image_with_nbh<I1>& marker, - const abstract::image<I2>& mask) : - super_type(marker, mask) - {} - - void impl_run() - { - mlc::eq<oln_type_of(I1, size), oln_type_of(I2, size)>::ensure(); - precondition((this->input1).size() == (this->input2).size()); - precondition(level::is_greater_or_equal(this->input1, this->input2)); - this->output = - arith::max(erosion(this->input1.unbox(), - this->input1.unbox().nbh_get().get_win()).output.unbox(), - this->input2.unbox()).output; - } - }; - - } // end of namespace oln::morpho::safe - - template<class I1, class I2> - geodesic_erosion_ret<I1, I2> - geodesic_erosion(const abstract::image_with_nbh<I1>& marker, - const abstract::image<I2>& mask) - { - safe::geodesic_erosion<I1, I2> tmp(marker, mask); - tmp.run(); - return tmp; - } - - } // end of namespace oln::morpho - -} // end of namespace oln - -#endif // OLENA_MORPHO_GEODESIC_EROSION_HH
participants (1)
-
Thierry GERAUD