971: Augment morphology.

https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Augment morphology. * oln/core/gen/ternary_fun.hh: New. * oln/logic: New directory. * oln/logic/and.hh, * oln/logic/not.hh, * oln/morpho/hit_or_miss_all.hh, * oln/morpho/hit_or_miss.hh, * oln/morpho/hit_or_miss_background_closing.hh, * oln/morpho/hit_or_miss_background_opening.hh, * oln/morpho/hit_or_miss_closing.hh, * oln/morpho/complementation.hh, * oln/morpho/hit_or_miss_opening.hh, * oln/level/ternary.hh, * oln/arith/min.hh, * oln/arith/negate.hh: New. * oln/convert/to_window.hh (to_window_values_, fill_): New in internal. (to_window): New overload. * oln/convert/to_weighted_window.hh: Update. * oln/core/gen/dpoints_piter.hh (dpoints_fwd_piter_, dpoints_bkd_piter_): New ctor overloads. * oln/core/gen/window.hh (impl_fill_with): New. * oln/core/gen/pw_value.hh (pw_value_base_): New. (pw_value): Make inheritance flexible. * oln/core/concept/window.hh (is_centered): New. * oln/core/internal/window.hh (impl_is_centered): New. * oln/core/internal/dpoints_impl.hh: Fix. * oln/morpho/cc_tarjan_v1.hh (cc_tarjan): New facade. * oln/morpho/cc_tarjan_v2.hh: Fix. * oln/morpho/erosion.hh (postcondition): Fix. * oln/morpho/dilation.hh (postcondition): Fix. * oln/level/apply.hh: Cosmetic change. * oln/canvas/two_pass.hh: Fix. arith/min.hh | 86 ++++++++++++++++++++ arith/negate.hh | 96 ++++++++++++++++++++++ canvas/two_pass.hh | 4 convert/to_weighted_window.hh | 18 ++-- convert/to_window.hh | 63 +++++++++++++-- core/concept/window.hh | 8 + core/gen/dpoints_piter.hh | 44 ++++++++++ core/gen/pw_value.hh | 33 +++++++ core/gen/ternary_fun.hh | 121 ++++++++++++++++++++++++++++ core/gen/window.hh | 3 core/internal/dpoints_impl.hh | 2 core/internal/window.hh | 9 ++ level/apply.hh | 6 - level/ternary.hh | 90 +++++++++++++++++++++ logic/and.hh | 96 ++++++++++++++++++++++ logic/not.hh | 95 ++++++++++++++++++++++ morpho/cc_tarjan_v1.hh | 52 +++++++++--- morpho/cc_tarjan_v2.hh | 7 - morpho/complementation.hh | 89 +++++++++++++++++++++ morpho/dilation.hh | 1 morpho/erosion.hh | 1 morpho/hit_or_miss.hh | 130 +++++++++++++++++++++++++++++++ morpho/hit_or_miss_all.hh | 41 +++++++++ morpho/hit_or_miss_background_closing.hh | 89 +++++++++++++++++++++ morpho/hit_or_miss_background_opening.hh | 89 +++++++++++++++++++++ morpho/hit_or_miss_closing.hh | 91 +++++++++++++++++++++ morpho/hit_or_miss_opening.hh | 92 +++++++++++++++++++++ 27 files changed, 1415 insertions(+), 41 deletions(-) Index: oln/convert/to_window.hh --- oln/convert/to_window.hh (revision 970) +++ oln/convert/to_window.hh (working copy) @@ -30,6 +30,7 @@ # include <oln/core/concept/image.hh> # include <oln/core/internal/f_image_to_window.hh> +# include <oln/convert/to_dpoint.hh> namespace oln @@ -38,12 +39,23 @@ namespace convert { - // Fwd decl. + // Fwd decls. + + namespace internal + { + template <unsigned n> + struct to_window_values_; + } template <typename I> oln_f_image_to_window(I) to_window(const Binary_Image<I>& input); + template <unsigned n> + internal::to_window_values_<n> + to_window(const bool (&values)[n]); + // FIXME: Wrong semantics: to_window should really give a window... + # ifndef OLN_INCLUDE_ONLY @@ -53,18 +65,59 @@ oln_f_image_to_window(I) to_window(const Binary_Image<I>& input) { - oln_f_image_to_window(I) tmp; + oln_f_image_to_window(I) win; oln_dpoint(I) dp; oln_piter(I) p(input.points()); for_all(p) if (input(p) = true) + win.take(convert::to_dpoint(p)); + return win; + } + + + namespace internal { - dp.vec() = p.vec(); - // FIXME: Better s.a. dp = p.to_dpoint(); - tmp.take(dp); + + template <typename G, typename W, unsigned n> + void fill_(W& win, const bool (&values)[n]) + { + int h = int(std::sqrt(n)) / 2; + precondition((2 * h + 1) * (2 * h + 1) = n); + unsigned i = 0; + for (int drow = -h; drow <= h; ++drow) // FIXME: Replace 'int' by 'oln_coord(W)' + for (int dcol = -h; dcol <= h; ++dcol) + if (values[i++] = true) + win.take(oln_dpoint(W)(drow, dcol)); } + + template <unsigned n> + struct to_window_values_ + { + const bool (&values_)[n]; + + to_window_values_(const bool (&values)[n]) + : values_(values) + {} + + template <typename W> + operator W() const + { + mlc::assert_< mlc_is_a(W, Window) >::check(); // FIXME: Add err msg. + W tmp; + fill_<oln_grid(W)>(tmp, values_); return tmp; } + }; + + } // end of namespace oln::convert::internal + + + template <unsigned n> + internal::to_window_values_<n> + to_window(const bool (&values)[n]) + { + return internal::to_window_values_<n>(values); + } # endif // ! OLN_INCLUDE_ONLY Index: oln/convert/to_weighted_window.hh --- oln/convert/to_weighted_window.hh (revision 970) +++ oln/convert/to_weighted_window.hh (working copy) @@ -28,10 +28,11 @@ #ifndef OLN_CONVERT_TO_WEIGHTED_WINDOW_HH # define OLN_CONVERT_TO_WEIGHTED_WINDOW_HH -# include <oln/core/gen/zero.hh> # include <oln/core/concept/image.hh> # include <oln/core/concept/window.hh> # include <oln/core/concept/function.hh> +# include <oln/core/gen/zero.hh> +# include <oln/convert/to_dpoint.hh> # include <oln/core/internal/f_weighted_window.hh> @@ -62,11 +63,11 @@ oln_f_image_to_weighted_window(I) to_weighted_window(const Image<I>& input) { - oln_f_image_to_weighted_window(I) output; + oln_f_image_to_weighted_window(I) w_win; oln_piter(I) p(input.points()); for_all(p) - output.take(input(p), zero - oln_point(I)(p)); - return output; + w_win.take(input(p), convert::to_dpoint(p)); + return w_win; } template <typename F, typename W> @@ -74,12 +75,11 @@ to_weighted_window(const Function_p2v<F>& weight, const Window<W>& win) { const F& weight_ = exact(weight); - oln_f_weighted_window(oln_result(F), oln_dpoint(W)) output; - oln_point(W) O; O.set_all(0); - oln_qiter(W) q(win, O); + oln_f_weighted_window(oln_result(F), oln_dpoint(W)) w_win; + oln_qiter(W) q(win, zero); for_all(q) - output.take(weight_(q), O - oln_point(W)(q)); // FIXME: to_point - return output; + w_win.take(weight_(q), convert::to_dpoint(q)); + return w_win; } # endif // ! OLN_INCLUDE_ONLY Index: oln/core/gen/dpoints_piter.hh --- oln/core/gen/dpoints_piter.hh (revision 970) +++ oln/core/gen/dpoints_piter.hh (working copy) @@ -75,12 +75,18 @@ template <typename W, typename Pl> dpoints_fwd_piter_(const Window<W>& win, const Generalized_Point<Pl>& p); + template <typename W> + dpoints_fwd_piter_(const Window<W>& win, const P& p); + template <typename I, typename Pl> dpoints_fwd_piter_(const Image_with_Nbh<I>& ima, const Generalized_Point<Pl>& p); template <typename N, typename Pl> dpoints_fwd_piter_(const Neighborhood<N>& nbh, const Generalized_Point<Pl>& p); + template <typename N> + dpoints_fwd_piter_(const Neighborhood<N>& nbh, const P& p); + }; // end of class oln::dpoints_fwd_piter_<P> @@ -120,12 +126,18 @@ template <typename W, typename Pl> dpoints_bkd_piter_(const Window<W>& win, const Generalized_Point<Pl>& p); + template <typename W> + dpoints_bkd_piter_(const Window<W>& win, const P& p); + template <typename I, typename Pl> dpoints_bkd_piter_(const Image_with_Nbh<I>& ima, const Generalized_Point<Pl>& p); template <typename N, typename Pl> dpoints_bkd_piter_(const Neighborhood<N>& nbh, const Generalized_Point<Pl>& p); + template <typename N> + dpoints_bkd_piter_(const Neighborhood<N>& nbh, const P& p); + }; // end of class oln::dpoints_bkd_piter_<P> @@ -143,6 +155,14 @@ } template <typename P> + template <typename W> + dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Window<W>& win, const P& p) + : + internal::dpoints_fwd_piter_impl_<P>(p, exact(win)) // FIXME: Propagate "win first, then p". + { + } + + template <typename P> template <typename I, typename Pl> dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Image_with_Nbh<I>& ima, const Generalized_Point<Pl>& p) : @@ -158,6 +178,14 @@ { } + template <typename P> + template <typename N> + dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Neighborhood<N>& nbh, const P& p) + : + internal::dpoints_fwd_piter_impl_<P>(p, exact(nbh)) + { + } + // bkd template <typename P> @@ -169,6 +197,14 @@ } template <typename P> + template <typename W> + dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Window<W>& win, const P& p) + : + internal::dpoints_bkd_piter_impl_<P>(p, exact(win)) + { + } + + template <typename P> template <typename I, typename Pl> dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Image_with_Nbh<I>& ima, const Generalized_Point<Pl>& p) : @@ -184,6 +220,14 @@ { } + template <typename P> + template <typename N> + dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Neighborhood<N>& nbh, const P& p) + : + internal::dpoints_bkd_piter_impl_<P>(p, exact(nbh)) + { + } + # endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/gen/window.hh --- oln/core/gen/window.hh (revision 970) +++ oln/core/gen/window.hh (working copy) @@ -65,6 +65,9 @@ gen_window(); + template <unsigned n> + void impl_fill_with(const bool (&values)[n]); + }; // end of class oln::gen_window<Dp> Index: oln/core/gen/pw_value.hh --- oln/core/gen/pw_value.hh (revision 970) +++ oln/core/gen/pw_value.hh (working copy) @@ -45,10 +45,34 @@ } // end of namespace oln::ERROR + // Fwd decl. + template <typename I> class pw_value_; + + + namespace internal + { + + template <bool b, typename I> + struct pw_value_base_; + + template <typename I> + struct pw_value_base_< true, I > : public Function_p2b< pw_value_<I> > + { + }; + template <typename I> - class pw_value_ : public Function_p2v< pw_value_<I> >, - private mlc::assert_< mlc_is_a(I, Image), - ERROR::pw_value_works_on_images_not_on_<I> > + struct pw_value_base_< false, I > : public Function_p2v< pw_value_<I> > + { + }; + + } // end of namespace oln::internal + + + template <typename I> + class pw_value_ + : + public internal::pw_value_base_< mlc_is_a(I, Binary_Image)::eval::value, + I > { public: typedef oln_point(I) argument; // FIXME: psite? @@ -64,6 +88,7 @@ }; + template <typename I> pw_value_<I> pw_value(const Image<I>& ima); @@ -94,6 +119,8 @@ return this->ima_; } + // pw_value + template <typename I> pw_value_<I> pw_value(const Image<I>& ima) Index: oln/core/gen/ternary_fun.hh --- oln/core/gen/ternary_fun.hh (revision 0) +++ oln/core/gen/ternary_fun.hh (revision 0) @@ -0,0 +1,121 @@ +// 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_CORE_GEN_TERNARY_FUN_HH +# define OLN_CORE_GEN_TERNARY_FUN_HH + +# include <oln/core/concept/function.hh> + + + +namespace oln +{ + + + namespace internal + { + + template <bool b, typename B, typename T, typename F> + struct ternary_base_; + + template <typename B, typename T, typename F> + struct ternary_base_< true, B,T,F > : public Function_p2b< ternary_fun_<B,T,F> > + { + }; + + template <typename B, typename T, typename F> + struct ternary_base_< false, B,T,F > : public Function_p2v< ternary_fun_<B,T,F> > + { + }; + + } // end of namespace oln::internal + + + + template <typename B, typename T, typename F> + class ternary_fun_ + : + public internal::ternary_base_< mlc_is_a(oln_result(T), bool), B,T,F > + { + public: + typedef oln_argument(B) argument; + typedef oln_result(T) result; // FIXME: oln_promote_trait( oln_result(T), oln_result(F) )? + + ternary_fun_(const B& b, const T& t, const F& f); + + result operator()(argument arg) const; + + protected: + B b_; + T t_; + F f_; + }; + + + template <typename B, typename T, typename F> + ternary_fun_<B,T,F> ternary_fun(const Function_p2b<B>& b, + const Function_p2v<T>& t, const Function_p2v<F>& f); + + + +# ifndef OLN_INCLUDE_ONLY + + // ternary_fun_<B,T,F> + + template <typename B, typename T, typename F> + ternary_fun_<B,T,F>::ternary_fun_(const B& b, const T& t, const F& f) + : b_(b), + t_(t), + f_(f) + { + } + + template <typename B, typename T, typename F> + typename ternary_fun_<B,T,F>::result + ternary_fun_<B,T,F>::operator()(argument arg) const + { + return this->b_(arg) ? this->t_(arg) : this->f_(arg); + } + + // ternary_fun + + template <typename B, typename T, typename F> + ternary_fun_<B,T,F> + ternary_fun(const Function_p2b<B>& b, + const Function_p2v<T>& t, const Function_p2v<F>& f) + { + // FIXME: Add static asserts here! + ternary_fun_<B,T,F> tmp(exact(b), exact(t), exact(f)); + return tmp; + } + +# endif // ! OLN_INCLUDE_ONLY + +} // end of namespace oln + + +#endif // ! OLN_CORE_GEN_TERNARY_FUN_HH Index: oln/core/concept/window.hh --- oln/core/concept/window.hh (revision 970) +++ oln/core/concept/window.hh (working copy) @@ -48,6 +48,7 @@ stc_typename(bkd_qiter); unsigned size() const; + bool is_centered() const; protected: Window(); @@ -73,6 +74,13 @@ return exact(this)->impl_size(); } + template <typename Exact> + bool + Window<Exact>::is_centered() const + { + return exact(this)->impl_is_centered(); + } + template <typename W> W operator - (const Window<W>& rhs) { Index: oln/core/internal/window.hh --- oln/core/internal/window.hh (revision 970) +++ oln/core/internal/window.hh (working copy) @@ -31,6 +31,7 @@ # include <oln/core/internal/window_base.hh> # include <oln/core/internal/dpoints_impl.hh> # include <oln/core/gen/dpoints_piter.hh> +# include <oln/core/gen/zero.hh> namespace oln @@ -76,6 +77,7 @@ Exact& take(const dpoint& dp); Exact& impl_take(const dpoint& dp); + bool impl_is_centered() const; Exact impl_op_unary_minus_() const; @@ -108,6 +110,13 @@ } template <typename Exact> + bool + window_<Exact>::impl_is_centered() const + { + return this->has(zero); + } + + template <typename Exact> Exact window_<Exact>::impl_op_unary_minus_() const { Index: oln/core/internal/dpoints_impl.hh --- oln/core/internal/dpoints_impl.hh (revision 970) +++ oln/core/internal/dpoints_impl.hh (working copy) @@ -74,7 +74,7 @@ const dpoints_impl_<Dp>& dps) { ostr << "[ "; - unsigned n = dps.size(); + unsigned n = dps.impl_size(); for (unsigned i = 0; i < n; ++i) ostr << dps[i] << (i = n - 1 ? " ]" : ", "); return ostr; Index: oln/logic/and.hh --- oln/logic/and.hh (revision 0) +++ oln/logic/and.hh (revision 0) @@ -0,0 +1,96 @@ +// 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_LOGIC_AND_HH +# define OLN_LOGIC_AND_HH + +# include <oln/core/concept/image.hh> +# include <oln/core/gen/traits.hh> +# include <oln/core/gen/pw_value.hh> +# include <oln/level/fill.hh> + + + +namespace oln +{ + + // Trait. + + template <typename I> + struct set_trait_< Image, I, and_id, Image, I > + { + typedef oln_plain(I) ret; + }; + + + // Fwd decl. + + template <typename I> + oln_plain(I) + operator and (const Binary_Image<I>& lhs, const Binary_Image<I>& rhs); + + +# ifndef OLN_INCLUDE_ONLY + + namespace logic + { + namespace impl + { + + // Generic version. + + template <typename I> + oln_plain(I) + and_(const Binary_Image<I>& lhs, const Binary_Image<I>& rhs) + { + oln_plain(I) output; + prepare(output, with, lhs); + level::fill(inplace(output), pw_value(lhs) and pw_value(rhs)); + return output; + } + + + } // end of namespace oln::logic::impl + + } // end of namespace oln::logic + + + // Facade. + + template <typename I> + oln_plain(I) + operator and (const Binary_Image<I>& lhs, const Binary_Image<I>& rhs) + { + precondition(lhs.points() = rhs.points()); + return logic::impl::and_(lhs, rhs); + } + +# endif // ! OLN_INCLUDE_ONLY + +} // end of namespace oln + +#endif // ! OLN_LOGIC_AND_HH Index: oln/logic/not.hh --- oln/logic/not.hh (revision 0) +++ oln/logic/not.hh (revision 0) @@ -0,0 +1,95 @@ +// 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_LOGIC_NOT_HH +# define OLN_LOGIC_NOT_HH + +# include <oln/core/concept/image.hh> +# include <oln/core/gen/traits.hh> +# include <oln/core/gen/pw_value.hh> +# include <oln/level/fill.hh> + + + +namespace oln +{ + + // Trait. + + template <typename I> + struct set_utrait_< not_id, Image, I > + { + typedef oln_plain(I) ret; + }; + + + // Fwd decl. + + template <typename I> + oln_plain(I) + operator not (const Binary_Image<I>& rhs); + + +# ifndef OLN_INCLUDE_ONLY + + namespace logic + { + namespace impl + { + + // Generic version. + + template <typename I> + oln_plain(I) + not_(const Binary_Image<I>& rhs) + { + oln_plain(I) output; + prepare(output, with, rhs); + level::fill(inplace(output), not pw_value(rhs)); + return output; + } + + + } // end of namespace oln::logic::impl + + } // end of namespace oln::logic + + + // Facade. + + template <typename I> + oln_plain(I) + operator not (const Binary_Image<I>& rhs) + { + return logic::impl::not_(rhs); + } + +# endif // ! OLN_INCLUDE_ONLY + +} // end of namespace oln + +#endif // ! OLN_LOGIC_NOT_HH Index: oln/morpho/cc_tarjan_v2.hh --- oln/morpho/cc_tarjan_v2.hh (revision 970) +++ oln/morpho/cc_tarjan_v2.hh (working copy) @@ -68,7 +68,7 @@ level::fill(inplace(is_processed), false); } - void first_pass_body(const point& p, I f) + void first_pass_body(const point& p, const I& f) { parent(p) = p; if ( f(p) ) @@ -84,7 +84,7 @@ } - void second_pass_body(const point& p, I f) + void second_pass_body(const point& p, const I& f) { unsigned current_label = 0; if ( f(p) = true and parent(p) = p ) @@ -93,9 +93,8 @@ output(p) = output(parent(p)); } - void final(I f) + void final(const I&) { - f = f; } point find_root(const I& ima, Index: oln/morpho/hit_or_miss_all.hh --- oln/morpho/hit_or_miss_all.hh (revision 0) +++ oln/morpho/hit_or_miss_all.hh (revision 0) @@ -0,0 +1,41 @@ +// 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_HIT_OR_MISS_ALL_HH +# define OLN_MORPHO_HIT_OR_MISS_ALL_HH + + +# include <oln/morpho/hit_or_miss.hh> + +# include <oln/morpho/hit_or_miss_opening.hh> +# include <oln/morpho/hit_or_miss_closing.hh> + +# include <oln/morpho/hit_or_miss_background_opening.hh> +# include <oln/morpho/hit_or_miss_background_closing.hh> + + +#endif // ! OLN_MORPHO_HIT_OR_MISS_ALL_HH Index: oln/morpho/erosion.hh --- oln/morpho/erosion.hh (revision 970) +++ oln/morpho/erosion.hh (working copy) @@ -119,6 +119,7 @@ erosion(const Image<I>& input, const Window<W>& win) { oln_plain(I) output = impl::erosion_(exact(input), exact(win)); + if (win.is_centered()) postcondition(output <= input); return output; } Index: oln/morpho/hit_or_miss.hh --- oln/morpho/hit_or_miss.hh (revision 0) +++ oln/morpho/hit_or_miss.hh (revision 0) @@ -0,0 +1,130 @@ +// 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_HIT_OR_MISS_HH +# define OLN_MORPHO_HIT_OR_MISS_HH + +# include <oln/morpho/erosion.hh> + +# include <oln/arith/min.hh> +# include <oln/arith/negate.hh> + +# include <oln/logic/not.hh> +# include <oln/logic/and.hh> + + +namespace oln +{ + + namespace morpho + { + + // Fwd decl. + + template <typename I, typename W1, typename W2> + oln_plain(I) + hit_or_miss(const Image<I>& input, + const Window<W1>& B1, const Window<W2>& B2); + + +# ifndef OLN_INCLUDE_ONLY + + namespace impl + { + + // Generic versions. + + template <typename I, typename W1, typename W2> + oln_plain(I) + hit_or_miss_on_function_(const Image<I>& input, + const Window<W1>& B1, const Window<W2>& B2) + { + oln_plain(I) + fit = erosion(input, B1), + miss = erosion(arith::negate(input), B2); + return arith::min(fit, miss); + } + + template <typename I, typename W1, typename W2> + oln_plain(I) + hit_or_miss_on_set_(const Binary_Image<I>& input, + const Window<W1>& B1, const Window<W2>& B2) + { + oln_plain(I) + fit = erosion(input, B1), + miss = erosion(not input, B2); + return fit and miss; + } + + // FIXME: Add a fast version. + + + // Impl facade. + + template <typename I, typename W1, typename W2> + oln_plain(I) + hit_or_miss_(const Image<I>& input, + const W1& B1, const W2& B2) + { + return hit_or_miss_on_function_(exact(input), B1, B2); + } + + template <typename I, typename W1, typename W2> + oln_plain(I) + hit_or_miss_(const Binary_Image<I>& input, + const W1& B1, const W2& B2) + { + return hit_or_miss_on_set_(exact(input), B1, B2); + } + + + } // end of namespace oln::morpho::impl + + + // Facade. + + template <typename I, typename W1, typename W2> + oln_plain(I) + hit_or_miss(const Image<I>& input, + const Window<W1>& B1, const Window<W2>& B2) + { + // FIXME: Add: precondition(inter(B1, B2).card() = 0); + oln_plain(I) output = impl::hit_or_miss_(exact(input), + exact(B1), exact(B2)); + if (B1.is_centered()) // FIXME: ok? + postcondition(output <= input); + return output; + } + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace oln::morpho + +} // end of namespace oln + + +#endif // ! OLN_MORPHO_HIT_OR_MISS_HH Index: oln/morpho/cc_tarjan_v1.hh --- oln/morpho/cc_tarjan_v1.hh (revision 970) +++ oln/morpho/cc_tarjan_v1.hh (working copy) @@ -34,6 +34,7 @@ # include <oln/level/fill.hh> # include <oln/core/internal/f_ch_value.hh> + namespace oln { @@ -44,6 +45,11 @@ oln_plain_value(I, unsigned) cc_tarjan(const Image_with_Nbh<I>& f); + template <typename I> + oln_plain_value(I, unsigned) + cc_tarjan(const Image_with_Nbh<I>& f, unsigned& nlabels); + + # ifndef OLN_INCLUDE_ONLY namespace impl @@ -58,6 +64,7 @@ oln_plain_value(I, unsigned) output; oln_plain_value(I, bool) is_processed; oln_plain_value(I, point) parent; + unsigned nlabels; cc_tarjan_(const I& f) : f(f) @@ -70,12 +77,13 @@ prepare(output, with, f); prepare(parent, with, f); level::fill(inplace(is_processed), false); + nlabels = 0; } void first_pass_body(const point& p) { parent(p) = p; - if ( f(p) ) + if (f(p) = true) { oln_niter(I) n(f, p); for_all(n) @@ -85,31 +93,34 @@ } is_processed(p) = true; } - } void second_pass_body(const point& p) { - unsigned current_label = 0; - if ( f(p) = true and parent(p) = p ) - output(p) = ++current_label; + if (f(p) = true) + { + if (parent(p) = p) + output(p) = ++nlabels; else output(p) = output(parent(p)); } + else + output(p) = 0; // bg label + } - void final() { } + void final() + { + } // auxiliary methods - point find_root(const point& x) + point find_root(const point& x) // FIXME: or w/o const&? { - if (parent(x) != x) - { - parent(x) = find_root(parent(x)); - return parent(x); - } + if (parent(x) = x) return x; + else + return parent(x) = find_root(parent(x)); } void do_union(const point& n, @@ -124,15 +135,28 @@ } // end of namespace oln::morpho::impl + // Facades. template <typename I> oln_plain_value(I, unsigned) - cc_tarjan(const Image_with_Nbh<I>& f) + cc_tarjan(const Image_with_Nbh<I>& f, unsigned& nlabels) { impl::cc_tarjan_<I> run(exact(f)); + std::cout << run.output.is_empty() << std::endl; canvas::v1::two_pass(run); - return run.output; + std::cout << run.output.is_empty() << std::endl; + nlabels = run.nlabels; + oln_plain_value(I, unsigned) tmp = run.output; + return tmp; + } + + template <typename I> + oln_plain_value(I, unsigned) + cc_tarjan(const Image_with_Nbh<I>& f) + { + unsigned nlabels; + return cc_tarjan(f, nlabels); } # endif // ! OLN_INCLUDE_ONLY Index: oln/morpho/hit_or_miss_background_closing.hh --- oln/morpho/hit_or_miss_background_closing.hh (revision 0) +++ oln/morpho/hit_or_miss_background_closing.hh (revision 0) @@ -0,0 +1,89 @@ +// 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_HIT_OR_MISS_BACKGROUND_CLOSING_HH +# define OLN_MORPHO_HIT_OR_MISS_BACKGROUND_CLOSING_HH + +# include <oln/morpho/hit_or_miss_closing.hh> +# include <oln/morpho/complementation.hh> + + +namespace oln +{ + + namespace morpho + { + + // Fwd decl. + + template <typename I, typename W1, typename W2> + oln_plain(I) + hit_or_miss_background_closing(const Image<I>& input, + const Window<W1>& B1, const Window<W2>& B2); + + +# ifndef OLN_INCLUDE_ONLY + + namespace impl + { + + // Generic version. + + template <typename I, typename W1, typename W2> + oln_plain(I) + hit_or_miss_background_closing_(const Image<I>& input, + const Window<W1>& B1, const Window<W2>& B2) + { + oln_plain(I) + com = morpho::complementation(input), + output = morpho::hit_or_miss_closing(com, B2, B1); + return output; + } + + } // end of namespace oln::morpho::impl + + + // Facade. + + template <typename I, typename W1, typename W2> + oln_plain(I) + hit_or_miss_background_closing(const Image<I>& input, + const Window<W1>& B1, const Window<W2>& B2) + { + // FIXME: Add: precondition(inter(B1, B2).card() = 0); + return impl::hit_or_miss_background_closing_(exact(input), + exact(B1), exact(B2)); + } + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace oln::morpho + +} // end of namespace oln + + +#endif // ! OLN_MORPHO_HIT_OR_MISS_BACKGROUND_CLOSING_HH Index: oln/morpho/hit_or_miss_background_opening.hh --- oln/morpho/hit_or_miss_background_opening.hh (revision 0) +++ oln/morpho/hit_or_miss_background_opening.hh (revision 0) @@ -0,0 +1,89 @@ +// 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_HIT_OR_MISS_BACKGROUND_OPENING_HH +# define OLN_MORPHO_HIT_OR_MISS_BACKGROUND_OPENING_HH + +# include <oln/morpho/hit_or_miss_opening.hh> +# include <oln/morpho/complementation.hh> + + +namespace oln +{ + + namespace morpho + { + + // Fwd decl. + + template <typename I, typename W1, typename W2> + oln_plain(I) + hit_or_miss_background_opening(const Image<I>& input, + const Window<W1>& B1, const Window<W2>& B2); + + +# ifndef OLN_INCLUDE_ONLY + + namespace impl + { + + // Generic version. + + template <typename I, typename W1, typename W2> + oln_plain(I) + hit_or_miss_background_opening_(const Image<I>& input, + const Window<W1>& B1, const Window<W2>& B2) + { + oln_plain(I) + com = morpho::complementation(input), + output = morpho::hit_or_miss_opening(com, B2, B1); + return output; + } + + } // end of namespace oln::morpho::impl + + + // Facade. + + template <typename I, typename W1, typename W2> + oln_plain(I) + hit_or_miss_background_opening(const Image<I>& input, + const Window<W1>& B1, const Window<W2>& B2) + { + // FIXME: Add: precondition(inter(B1, B2).card() = 0); + return impl::hit_or_miss_background_opening_(exact(input), + exact(B1), exact(B2)); + } + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace oln::morpho + +} // end of namespace oln + + +#endif // ! OLN_MORPHO_HIT_OR_MISS_BACKGROUND_OPENING_HH Index: oln/morpho/hit_or_miss_closing.hh --- oln/morpho/hit_or_miss_closing.hh (revision 0) +++ oln/morpho/hit_or_miss_closing.hh (revision 0) @@ -0,0 +1,91 @@ +// 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_HIT_OR_MISS_CLOSING_HH +# define OLN_MORPHO_HIT_OR_MISS_CLOSING_HH + +# include <oln/morpho/hit_or_miss_opening.hh> +# include <oln/morpho/complementation.hh> +# include <oln/morpho/closing.hh> + + +namespace oln +{ + + namespace morpho + { + + // Fwd decl. + + template <typename I, typename W1, typename W2> + oln_plain(I) + hit_or_miss_closing(const Image<I>& input, + const Window<W1>& B1, const Window<W2>& B2); + + +# ifndef OLN_INCLUDE_ONLY + + namespace impl + { + + // Generic version. + + template <typename I, typename W1, typename W2> + oln_plain(I) + hit_or_miss_closing_(const Image<I>& input, + const Window<W1>& B1, const Window<W2>& B2) + { + oln_plain(I) + com = morpho::complementation(input), + ope = morpho::hit_or_miss_opening(com, B1, B2); + return morpho::complementation(ope); + } + + } // end of namespace oln::morpho::impl + + + // Facade. + + template <typename I, typename W1, typename W2> + oln_plain(I) + hit_or_miss_closing(const Image<I>& input, + const Window<W1>& B1, const Window<W2>& B2) + { + // FIXME: Add: precondition(inter(B1, B2).card() = 0); + oln_plain(I) output = impl::hit_or_miss_closing_(exact(input), + exact(B1), exact(B2)); + postcondition(output >= morpho::closing(input, B1)); + } + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace oln::morpho + +} // end of namespace oln + + +#endif // ! OLN_MORPHO_HIT_OR_MISS_CLOSING_HH Index: oln/morpho/complementation.hh --- oln/morpho/complementation.hh (revision 0) +++ oln/morpho/complementation.hh (revision 0) @@ -0,0 +1,89 @@ +// 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_COMPLEMENTATION_HH +# define OLN_MORPHO_COMPLEMENTATION_HH + +# include <oln/arith/negate.hh> +# include <oln/logic/not.hh> + + +namespace oln +{ + + namespace morpho + { + + // Fwd decl. + + template <typename I> + oln_plain(I) + complementation(const Image<I>& input); + + +# ifndef OLN_INCLUDE_ONLY + + namespace impl + { + + // Generic versions. + + template <typename I> + oln_plain(I) + complementation_(const Image<I>& input) + { + return arith::negate(input); + } + + template <typename I> + oln_plain(I) + complementation_(const Binary_Image<I>& input) + { + return not input; + } + + } // end of namespace oln::morpho::impl + + + // Facade. + + template <typename I> + oln_plain(I) + complementation(const Image<I>& input) + { + oln_plain(I) output = impl::complementation_(exact(input)); + return output; + } + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace oln::morpho + +} // end of namespace oln + + +#endif // ! OLN_MORPHO_COMPLEMENTATION_HH Index: oln/morpho/hit_or_miss_opening.hh --- oln/morpho/hit_or_miss_opening.hh (revision 0) +++ oln/morpho/hit_or_miss_opening.hh (revision 0) @@ -0,0 +1,92 @@ +// 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_HIT_OR_MISS_OPENING_HH +# define OLN_MORPHO_HIT_OR_MISS_OPENING_HH + +# include <oln/morpho/hit_or_miss.hh> +# include <oln/morpho/opening.hh> + + +namespace oln +{ + + namespace morpho + { + + // Fwd decl. + + template <typename I, typename W1, typename W2> + oln_plain(I) + hit_or_miss_opening(const Image<I>& input, + const Window<W1>& B1, const Window<W2>& B2); + + +# ifndef OLN_INCLUDE_ONLY + + namespace impl + { + + // Generic version. + + template <typename I, typename W1, typename W2> + oln_plain(I) + hit_or_miss_opening_(const Image<I>& input, + const Window<W1>& B1, const Window<W2>& B2) + { + oln_plain(I) hom = morpho::hit_or_miss(input, B1, B2); + return morpho::dilation(hom, - B1); + } + + // FIXME: Add a fast version. + + + } // end of namespace oln::morpho::impl + + + // Facade. + + template <typename I, typename W1, typename W2> + oln_plain(I) + hit_or_miss_opening(const Image<I>& input, + const Window<W1>& B1, const Window<W2>& B2) + { + // FIXME: Add: precondition(inter(B1, B2).card() = 0); + oln_plain(I) output = impl::hit_or_miss_opening_(exact(input), + exact(B1), exact(B2)); + postcondition(output <= morpho::opening(input, B1)); + return output; + } + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace oln::morpho + +} // end of namespace oln + + +#endif // ! OLN_MORPHO_HIT_OR_MISS_OPENING_HH Index: oln/morpho/dilation.hh --- oln/morpho/dilation.hh (revision 970) +++ oln/morpho/dilation.hh (working copy) @@ -100,6 +100,7 @@ dilation(const Image<I>& input, const Window<W>& win) { oln_plain(I) output = impl::dilation_(exact(input), exact(win)); + if (win.is_centered()) postcondition(output >= input); return output; } Index: oln/level/ternary.hh --- oln/level/ternary.hh (revision 0) +++ oln/level/ternary.hh (revision 0) @@ -0,0 +1,90 @@ +// 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_LEVEL_TERNARY_HH +# define OLN_LEVEL_TERNARY_HH + +# include <oln/core/concept/image.hh> +# include <oln/core/gen/ternary_fun.hh> +# include <oln/core/gen/pw_value.hh> +# include <oln/core/level/fill.hh> + + +namespace oln +{ + + namespace level + { + + // Fwd decl. + + template <typename B, typename T, typename F> + oln_plain(T) // FIXME: oln_promote_trait(oln_value(T), oln_value(B)) + ternary(const Binary_Image<B>& b, const Image<T>& t, const Image<F>& f); + + +# ifndef OLN_INCLUDE_ONLY + + namespace impl + { + + // Generic version. + + template <typename B, typename T, typename F> + oln_plain(T) + ternary(const Binary_Image<B>& b, const Image<T>& t, const Image<F>& f) + { + oln_plain(T) output; + prepare(output, with, t); + return level::fill(inplace(output), + ternary_fun(pw_value(b), pw_value(t), pw_value(f))); + } + + } // end of namespace oln::level::impl + + + // Facades. + + template <typename B, typename T, typename F> + oln_plain(T) + ternary(const Binary_Image<B>& b, const Image<T>& t, const Image<F>& f) + { + oln::assert_same_point_<B, T>::check(); + oln::assert_same_point_<T, F>::check(); + precondition(b.points() >= t.points()); + precondition(t.points() = f.points()); + return impl::ternary_(exact(b), exact(t), exact(f)); + } + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace oln::level + +} // end of namespace oln + + +#endif // ! OLN_LEVEL_TERNARY_HH Index: oln/level/apply.hh --- oln/level/apply.hh (revision 970) +++ oln/level/apply.hh (working copy) @@ -40,7 +40,7 @@ namespace level { - /// Fwd decls. + // Fwd decls. template <typename F, typename I> oln_plain_value(I, typename F::result) @@ -76,7 +76,7 @@ } // end of namespace oln::level::impl - /// Facades. + // Facades. template <typename F, typename I> oln_plain_value(I, typename F::result) @@ -93,7 +93,7 @@ } -# endif +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln::level Index: oln/arith/min.hh --- oln/arith/min.hh (revision 0) +++ oln/arith/min.hh (revision 0) @@ -0,0 +1,86 @@ +// 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_ARITH_MIN_HH +# define OLN_ARITH_MIN_HH + +# include <oln/core/concept/image.hh> + + +namespace oln +{ + + namespace arith + { + + // Fwd decl. + + template <typename I> + oln_plain(I) + min(const Image<I>& input1, const Image<I>& input2); + + +# ifndef OLN_INCLUDE_ONLY + + namespace impl + { + + // Generic version. + + template <typename I> + oln_plain(I) + min_(const Image<I>& input1, const Image<I>& input2) + { + oln_plain(I) output; + prepare(output, with, input1); + oln_piter(I) p(input1.points()); + for_all(p) + output(p) = ( input1(p) < input2(p) + ? input1(p) + : input2(p) ); + return output; + } + + } // end of namespace oln::arith::impl + + + // Facade. + + template <typename I> + oln_plain(I) + min(const Image<I>& input1, const Image<I>& input2) + { + return impl::min_(exact(input1), exact(input2)); + } + + } // end of namespace oln::arith + +# endif // ! OLN_INCLUDE_ONLY + +} // end of namespace oln + +#endif // ! OLN_ARITH_MIN_HH Index: oln/arith/negate.hh --- oln/arith/negate.hh (revision 0) +++ oln/arith/negate.hh (revision 0) @@ -0,0 +1,96 @@ +// 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_ARITH_NEGATE_HH +# define OLN_ARITH_NEGATE_HH + +# include <oln/core/concept/image.hh> +# include <oln/core/internal/max_value.hh> +# include <oln/core/internal/min_value.hh> + + +namespace oln +{ + + namespace arith + { + + // Fwd decl. + + template <typename I> + oln_plain(I) + negate(const Image<I>& input); + + +# ifndef OLN_INCLUDE_ONLY + + namespace impl + { + + // FIXME: Trash code! Not so simple... + + template <typename T> + T value_negate_(const T& v) + { + return static_cast<T>(oln_min(T) + (oln_max(T) - v)); + } + + + // Generic version. + + template <typename I> + oln_plain(I) + negate_(const Image<I>& input) + { + oln_plain(I) output; + prepare(output, with, input); + oln_piter(I) p(input.points()); + for_all(p) + output(p) = value_negate_<oln_value(I)>(input(p)); + return output; + } + + } // end of namespace oln::arith::impl + + + // Facade. + + template <typename I> + oln_plain(I) + negate(const Image<I>& input) + { + return impl::negate_(exact(input)); + } + + + } // end of namespace oln::arith + +# endif // ! OLN_INCLUDE_ONLY + +} // end of namespace oln + +#endif // ! OLN_ARITH_NEGATE_HH Index: oln/canvas/two_pass.hh --- oln/canvas/two_pass.hh (revision 970) +++ oln/canvas/two_pass.hh (working copy) @@ -37,7 +37,7 @@ { template <template <class> class F, typename I> // Data owned by f. - void two_pass(F<I> fun) + void two_pass(F<I>& fun) { // mlc::assert_< mlc_is_a(I, Image) >::check(); @@ -104,7 +104,7 @@ } - namespace v4 // Via Inheritens. + namespace v4 // Via Inheritance. { template <typename I>
participants (1)
-
Thierry Geraud