https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Add postconditions to morphology. * oln/value/builtin.hh: Move traits in... * oln/value/builtin_traits.hh: ...this new file. * tests/core/Makefile.am (check_PROGRAMS): Remove iter_point3d. * tests/algorithms/fill.cc: Update. * TODO: Extend. * oln/core/concept/function.hh: Remove stupid fwd decl. * oln/core/concept/operators.hh (operator>=): Rely now on <=. * oln/core/gen/pset_compare.hh (operator>, operator>=): Remove; obsolete. * oln/core/gen/literal.hh (operator T), (operator U): New conversions. * oln/core/gen/traits.hh (set_trait_): Add default relying on Any. * oln/core/internal/image_ops.hh: Add FIXME. * oln/core/internal/op_fp2v_over_pset.hh (fun): New method. * oln/morpho/reconstruction.hh (include): Fix missing. * oln/morpho/cc_tarjan.hh: Likewise. * oln/morpho/elementary_gradient.hh, * oln/morpho/elementary_closing.hh, * oln/morpho/elementary_gradient_external.hh, * oln/morpho/elementary_opening.hh, * oln/morpho/elementary_laplace.hh, * oln/morpho/elementary_dilation.hh, * oln/morpho/gradient_internal.hh, * oln/morpho/top_hat_black.hh, * oln/morpho/gradient.hh, * oln/morpho/top_hat_white.hh, * oln/morpho/closing.hh, * oln/morpho/opening.hh, * oln/morpho/gradient_external.hh, * oln/morpho/laplace.hh, * oln/morpho/dilation.hh, * oln/morpho/elementary_erosion.hh, * oln/morpho/erosion.hh, * oln/morpho/elementary_gradient_internal.hh: Add postconditions. Introduce explicit temporary variables. Various clean-ups. * oln/arith/minus.hh: Remove obsolete inactivated line. * oln/level/compare.hh (operator=, operator<, operator<=): New versions with a literal. * oln/core/gen/pw_value.hh (pw_value_, pw_value): Weaken sig and add static check. * oln/level/local.hh (local): Likewise. * oln/level/apply_local.hh (apply_local): Likewise. TODO | 4 + oln/arith/minus.hh | 1 oln/core/concept/function.hh | 3 oln/core/concept/operators.hh | 10 +- oln/core/gen/literal.hh | 13 +++ oln/core/gen/pset_compare.hh | 21 ----- oln/core/gen/pw_value.hh | 13 ++- oln/core/gen/traits.hh | 35 ++++++--- oln/core/internal/image_ops.hh | 2 oln/core/internal/op_fp2v_over_pset.hh | 10 ++ oln/level/apply_local.hh | 18 +--- oln/level/compare.hh | 112 ++++++++++++++++++++++++++++- oln/level/local.hh | 13 +-- oln/morpho/cc_tarjan.hh | 6 + oln/morpho/closing.hh | 8 +- oln/morpho/dilation.hh | 25 +++--- oln/morpho/elementary_closing.hh | 8 +- oln/morpho/elementary_dilation.hh | 18 ++-- oln/morpho/elementary_erosion.hh | 19 ++-- oln/morpho/elementary_gradient.hh | 9 +- oln/morpho/elementary_gradient_external.hh | 8 +- oln/morpho/elementary_gradient_internal.hh | 8 +- oln/morpho/elementary_laplace.hh | 6 + oln/morpho/elementary_opening.hh | 8 +- oln/morpho/erosion.hh | 25 +++--- oln/morpho/gradient.hh | 18 ++-- oln/morpho/gradient_external.hh | 17 ++-- oln/morpho/gradient_internal.hh | 17 ++-- oln/morpho/laplace.hh | 21 ++--- oln/morpho/opening.hh | 12 +-- oln/morpho/reconstruction.hh | 6 + oln/morpho/top_hat_black.hh | 17 ++-- oln/morpho/top_hat_white.hh | 18 ++-- oln/value/builtin.hh | 17 ---- oln/value/builtin_traits.hh | 57 ++++++++++++++ tests/algorithms/fill.cc | 13 +-- tests/core/Makefile.am | 2 37 files changed, 412 insertions(+), 206 deletions(-) Index: tests/core/Makefile.am --- tests/core/Makefile.am (revision 924) +++ tests/core/Makefile.am (working copy) @@ -27,7 +27,6 @@ image2d \ iter_point1d \ iter_point2d \ - iter_point3d \ neighb2d \ npoints \ point2d \ @@ -45,7 +44,6 @@ image2d_SOURCES = image2d.cc iter_point1d_SOURCES = iter_point1d.cc iter_point2d_SOURCES = iter_point2d.cc -iter_point3d_SOURCES = iter_point3d.cc neighb2d_SOURCES = neighb2d.cc npoints_SOURCES = npoints.cc point2d_SOURCES = point2d.cc Index: tests/algorithms/fill.cc --- tests/algorithms/fill.cc (revision 924) +++ tests/algorithms/fill.cc (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2006 EPITA Research and Development Laboratory +// Copyright (C) 2006, 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 @@ -28,19 +28,18 @@ /// Test oln::level::fill. #include <cassert> -// FIXME: We should not include oln/basics2d.hh, but -// just oln/core/2d/image2d.hh. -#include <oln/basics2d.hh> +#include <oln/core/2d/image2d.hh> #include <oln/level/fill.hh> int main() { - typedef oln::image2d<int> image_t; + using namespace oln; + typedef image2d<int> image_t; image_t ima(3, 3); - oln::level::fill(ima, 51); - oln_piter_(image_t) p(ima.topo()); + level::fill(ima, 51); + image_t::piter p(ima.points()); for_all(p) assert(ima(p) = 51); } Index: TODO --- TODO (revision 924) +++ TODO (working copy) @@ -35,6 +35,10 @@ in image_identity.hh use 'current' +provide arith::minus et al. with explicit output type + +use Generalized_Point when possible + * Tiny improvements Index: oln/core/concept/function.hh --- oln/core/concept/function.hh (revision 924) +++ oln/core/concept/function.hh (working copy) @@ -48,9 +48,6 @@ */ - template <typename Exact> - struct Function; - template <typename Exact> struct Function : public Any<Exact> Index: oln/core/concept/operators.hh --- oln/core/concept/operators.hh (revision 924) +++ oln/core/concept/operators.hh (working copy) @@ -100,19 +100,19 @@ template <typename L, typename R> bool operator> (const Any<L>& lhs, const Any<R>& rhs) { - return exact(rhs) < exact(lhs); + return exact(rhs) < exact(lhs); // use "operator <" } template <typename L, typename R> - bool operator>=(const Any<L>& lhs, const Any<R>& rhs) + bool operator<=(const Any<L>& lhs, const Any<R>& rhs) { - return not (exact(lhs) < exact(rhs)); + return not (exact(rhs) < exact(lhs)); // use "operator <" and "not" } template <typename L, typename R> - bool operator<=(const Any<L>& lhs, const Any<R>& rhs) + bool operator>=(const Any<L>& lhs, const Any<R>& rhs) { - return not (exact(rhs) < exact(lhs)); + return exact(rhs) <= exact(lhs); // use "operator <=" } template <typename L, typename R> Index: oln/core/gen/pset_compare.hh --- oln/core/gen/pset_compare.hh (revision 924) +++ oln/core/gen/pset_compare.hh (working copy) @@ -29,6 +29,7 @@ # define OLN_CORE_GEN_PSET_COMPARE_HH # include <oln/core/concept/point_set.hh> +# include <oln/core/concept/operators.hh> namespace oln @@ -45,12 +46,6 @@ template <typename L, typename R> bool operator <= (const Point_Set<L>& lhs, const Point_Set<R>& rhs); - template <typename L, typename R> - bool operator > (const Point_Set<L>& lhs, const Point_Set<R>& rhs); - - template <typename L, typename R> - bool operator >= (const Point_Set<L>& lhs, const Point_Set<R>& rhs); - template <typename B1, typename B2> bool intersects (const Box<B1>& box1, const Box<B2>& box2); @@ -252,20 +247,6 @@ return impl::op_strict_subset_(exact(lhs), exact(rhs)); } - template <typename L, typename R> - bool operator >= (const Point_Set<L>& lhs, const Point_Set<R>& rhs) - { - assert_same_grid_<L, R>::check(); - return impl::op_subset_(exact(rhs), exact(lhs)); - } - - template <typename L, typename R> - bool operator > (const Point_Set<L>& lhs, const Point_Set<R>& rhs) - { - assert_same_grid_<L, R>::check(); - return impl::op_strict_subset_(exact(rhs), exact(lhs)); - } - // Intersects. template <typename B1, typename B2> Index: oln/core/gen/pw_value.hh --- oln/core/gen/pw_value.hh (revision 924) +++ oln/core/gen/pw_value.hh (working copy) @@ -52,7 +52,7 @@ typedef oln_point(I) argument; // FIXME: psite? typedef oln_value(I) result; - pw_value_(const Point_Wise_Accessible_Image<I>& ima); + pw_value_(const Image<I>& ima); oln_value(I) operator()(const oln_point(I)& p) const; protected: @@ -61,16 +61,17 @@ template <typename I> - pw_value_<I> - pw_value(const Image<I>& ima); + pw_value_<I> pw_value(const Image<I>& ima); # ifndef OLN_INCLUDE_ONLY template <typename I> - pw_value_<I>::pw_value_(const Point_Wise_Accessible_Image<I>& ima) + pw_value_<I>::pw_value_(const Image<I>& ima) : ima_(exact(ima)) { + mlc::assert_< mlc_is_a(I, Point_Wise_Accessible_Image) >::check(); + // FIXME: Add err msg above. } template <typename I> @@ -83,8 +84,10 @@ template <typename I> pw_value_<I> - pw_value(const Point_Wise_Accessible_Image<I>& ima) + pw_value(const Image<I>& ima) { + mlc::assert_< mlc_is_a(I, Point_Wise_Accessible_Image) >::check(); + // FIXME: Add err msg above. pw_value_<I> tmp(ima); return tmp; } Index: oln/core/gen/literal.hh --- oln/core/gen/literal.hh (revision 924) +++ oln/core/gen/literal.hh (working copy) @@ -28,7 +28,6 @@ #ifndef OLN_CORE_GEN_LITERAL_HH # define OLN_CORE_GEN_LITERAL_HH -# include <oln/core/concept/function.hh> # include <oln/core/concept/generator.hh> # include <oln/core/concept/point.hh> # include <oln/core/concept/value.hh> @@ -56,6 +55,18 @@ return this->val_; } + operator T() const + { + return this->val_; + } + + template <typename U> + operator literal_<U>() const + { + literal_<U> tmp(this->val_); + return tmp; + } + result value() const { return this->val_; Index: oln/core/gen/traits.hh --- oln/core/gen/traits.hh (revision 924) +++ oln/core/gen/traits.hh (working copy) @@ -90,9 +90,8 @@ # define oln_internal_specialize_bin_trait_bool_(Name) \ \ - template <template <class> class Cl, typename L, \ - template <class> class Cr, typename R> \ - struct set_trait_< Cl, L, Name##_id, Cr, R > \ + template <typename L, typename R> \ + struct set_trait_< Any, L, Name##_id, Any, R > \ { \ typedef bool ret; \ } @@ -100,9 +99,8 @@ # define oln_internal_specialize_bin_trait_T_(Name) \ \ - template <template <class> class Cl, typename T, \ - template <class> class Cr> \ - struct set_trait_< Cl, T, Name##_id, Cr, T > \ + template <typename T> \ + struct set_trait_< Any, T, Name##_id, Any, T > \ { \ typedef T ret; \ } @@ -115,12 +113,30 @@ // set_trait_ + template <template <class> class Cl, typename L, typename Op, template <class> class Cr, typename R> struct set_trait_; + template <typename L, typename Op, typename R> + struct set_trait_<Any, L, Op, Any, R> + { + // nothing => do not compile + }; + + + template <template <class> class Cl, typename L, + typename Op, + template <class> class Cr, typename R> + struct set_trait_ // default is + : public set_trait_<Any, L, Op, Any, R> + { + }; + + + // ids struct plus_id; @@ -145,7 +161,6 @@ // default (see oln/core/concept/operators.hh) - /* oln_internal_specialize_bin_trait_T_(plus); oln_internal_specialize_bin_trait_T_(minus); @@ -165,8 +180,6 @@ oln_internal_specialize_bin_trait_T_(or); oln_internal_specialize_bin_trait_T_(xor); - */ - namespace internal { @@ -196,4 +209,8 @@ } // end of namespace oln +// FIXME: Bad? +# include <oln/value/builtin.hh> + + #endif // ! OLN_CORE_GEN_TRAITS_HH Index: oln/core/internal/image_ops.hh --- oln/core/internal/image_ops.hh (revision 924) +++ oln/core/internal/image_ops.hh (working copy) @@ -70,6 +70,8 @@ return tmp; } + // FIXME: Add "literal / point set"... + // Specialization "Image such_as f : P -> B". Index: oln/core/internal/op_fp2v_over_pset.hh --- oln/core/internal/op_fp2v_over_pset.hh (revision 924) +++ oln/core/internal/op_fp2v_over_pset.hh (working copy) @@ -90,6 +90,8 @@ rvalue impl_read(const point& p) const; const S& impl_points() const; + const F& fun() const; + protected: special_op_(); special_op_(F& fun, S& pts); @@ -139,6 +141,14 @@ return this->data_->second; } + template <typename F, typename S> + const F& + current::fun() const + { + assert(this->has_data()); + return this->data_->first; + } + } // end of namespace oln::internal # endif // ! OLN_INCLUDE_ONLY Index: oln/morpho/reconstruction.hh --- oln/morpho/reconstruction.hh (revision 924) +++ oln/morpho/reconstruction.hh (working copy) @@ -28,8 +28,10 @@ #ifndef OLN_MORPHO_RECONSTRUCTION_HH # define OLN_MORPHO_RECONSTRUCTION_HH +# include <oln/core/concept/image.hh> #include <oln/accumulator/max.hh> + namespace oln { @@ -47,13 +49,13 @@ // first oln_fwd_piter(I) p(input.points()); for_all(p) - marker(p) = local(max, marker, p) && mask(p); // FIXME : local_sup. + marker(p) = local(max, marker, p) and mask(p); // FIXME : local_sup. // second oln_bkd_piter(I) p(input.points()); for_all(p) - marker(p) = local(max, marker, p) && mask(p); // FIXME : local_inf. + marker(p) = local(max, marker, p) and mask(p); // FIXME : local_inf. } } // end of namespace oln::morpho::impl Index: oln/morpho/elementary_gradient.hh --- oln/morpho/elementary_gradient.hh (revision 924) +++ oln/morpho/elementary_gradient.hh (working copy) @@ -32,6 +32,7 @@ #include <oln/morpho/elementary_dilation.hh> #include <oln/arith/minus.hh> + namespace oln { @@ -56,7 +57,9 @@ oln_plain(I) elementary_gradient_(const Image_with_Nbh<I>& input) { - return elementary_dilation(input) - elementary_erosion(input); + oln_plain(I) dil = elementary_dilation(input); + oln_plain(I) ero = elementary_erosion(input); + return dil - ero; } @@ -71,7 +74,9 @@ oln_plain(I) elementary_gradient(const Image_with_Nbh<I>& input) { - return impl::elementary_gradient_(exact(input)); + oln_plain(I) output = impl::elementary_gradient_(exact(input)); + postcondition(output >= literal(0)); + return output; } # endif // ! OLN_INCLUDE_ONLY Index: oln/morpho/elementary_closing.hh --- oln/morpho/elementary_closing.hh (revision 924) +++ oln/morpho/elementary_closing.hh (working copy) @@ -31,6 +31,7 @@ #include <oln/morpho/elementary_erosion.hh> #include <oln/morpho/elementary_dilation.hh> + namespace oln { @@ -54,7 +55,8 @@ oln_plain(I) elementary_closing_(const Image_with_Nbh<I>& input) { - return elementary_erosion( elementary_dilation(input) ); + oln_plain(I) dil = elementary_dilation(input); + return elementary_erosion(dil); } // FIXME: Add a fast version. @@ -68,7 +70,9 @@ oln_plain(I) elementary_closing(const Image_with_Nbh<I>& input) { - return impl::elementary_closing_(exact(input)); + oln_plain(I) output = impl::elementary_closing_(exact(input)); + postcondition(output >= input); + return output; } # endif // ! OLN_INCLUDE_ONLY Index: oln/morpho/cc_tarjan.hh --- oln/morpho/cc_tarjan.hh (revision 924) +++ oln/morpho/cc_tarjan.hh (working copy) @@ -28,8 +28,10 @@ #ifndef OLN_MORPHO_CC_TARJAN_HH # define OLN_MORPHO_CC_TARJAN_HH +# include <oln/core/concept/image.hh> #include <oln/debug/print.hh> + namespace oln { @@ -76,7 +78,7 @@ oln_niter(I) n(p, input); for_all(n) { - if ( input(n) && is_processed(n) ) + if ( input(n) = true and is_processed(n) ) do_union(input ,n, p, parent); } is_processed(p) = true; @@ -93,7 +95,7 @@ oln_fwd_piter(I) p(input.points()); for_all(p) { - if ( input(p) && parent(p) = p ) + if ( input(p) = true and parent(p) = p ) output(p) = ++current_label; else output(p) = output(parent(p)); Index: oln/morpho/elementary_gradient_external.hh --- oln/morpho/elementary_gradient_external.hh (revision 924) +++ oln/morpho/elementary_gradient_external.hh (working copy) @@ -31,6 +31,7 @@ #include <oln/morpho/elementary_dilation.hh> #include <oln/arith/minus.hh> + namespace oln { @@ -55,7 +56,8 @@ oln_plain(I) elementary_gradient_external_(const Image_with_Nbh<I>& input) { - return elementary_dilation(input) - input; + oln_plain(I) dil = elementary_dilation(input); + return dil - input; } @@ -70,7 +72,9 @@ oln_plain(I) elementary_gradient_external(const Image_with_Nbh<I>& input) { - return impl::elementary_gradient_external_(exact(input)); + oln_plain(I) output = impl::elementary_gradient_external_(exact(input)); + postcondition(output >= literal(0)); + return output; } # endif // ! OLN_INCLUDE_ONLY Index: oln/morpho/elementary_opening.hh --- oln/morpho/elementary_opening.hh (revision 924) +++ oln/morpho/elementary_opening.hh (working copy) @@ -31,6 +31,7 @@ #include <oln/morpho/elementary_erosion.hh> #include <oln/morpho/elementary_dilation.hh> + namespace oln { @@ -54,7 +55,8 @@ oln_plain(I) elementary_opening_(const Image_with_Nbh<I>& input) { - return morpho::elementary_dilation( morpho::elementary_erosion(input) ); + oln_plain(I) ero = morpho::elementary_erosion(input); + return morpho::elementary_dilation(ero); } // FIXME: Add a fast version. @@ -68,7 +70,9 @@ oln_plain(I) elementary_opening(const Image_with_Nbh<I>& input) { - return impl::elementary_opening_(exact(input)); + oln_plain(I) output = impl::elementary_opening_(exact(input)); + postcondition(output <= input); + return output; } # endif // ! OLN_INCLUDE_ONLY Index: oln/morpho/elementary_laplace.hh --- oln/morpho/elementary_laplace.hh (revision 924) +++ oln/morpho/elementary_laplace.hh (working copy) @@ -30,7 +30,7 @@ #include <oln/morpho/elementary_gradient_external.hh> #include <oln/morpho/elementary_gradient_internal.hh> -#include <oln/arith/minus.hh> + namespace oln { @@ -56,7 +56,9 @@ oln_plain(I) elementary_laplace_(const Image_with_Nbh<I>& input) { - return elementary_gradient_external(input) - elementary_gradient_internal(input); + oln_plain(I) g_ext = elementary_gradient_external(input); + oln_plain(I) g_int = elementary_gradient_internal(input); + return g_ext - g_int; } Index: oln/morpho/elementary_dilation.hh --- oln/morpho/elementary_dilation.hh (revision 924) +++ oln/morpho/elementary_dilation.hh (working copy) @@ -29,10 +29,12 @@ # define OLN_MORPHO_ELEMENTARY_DILATION_HH #include <oln/level/apply_local.hh> +# include <oln/level/compare.hh> #include <oln/border/fill.hh> #include <oln/accumulator/max.hh> #include <oln/accumulator/or.hh> + namespace oln { @@ -55,8 +57,7 @@ template <typename I> oln_plain(I) - elementary_dilation_on_function_(const Image<I>&, - const I& input) + elementary_dilation_on_function_(const Image<I>& input) { border::fill(input, oln_min(oln_value(I))); accumulator::max_<oln_value(I)> max; @@ -65,10 +66,9 @@ template <typename I> oln_plain(I) - elementary_dilation_on_set_(const Image<I>&, - const I& input) + elementary_dilation_on_set_(const Image<I>& input) { - border::fill(input, oln_min(oln_value(I))); + border::fill(input, false); accumulator::or_<oln_value(I)> accu_or; return level::apply_local(accu_or, input); } @@ -81,13 +81,13 @@ template <typename I> oln_plain(I) elementary_dilation_(const Image<I>& input) { - return elementary_dilation_on_function_(exact(input), exact(input)); + return elementary_dilation_on_function_(exact(input)); } template <typename I> oln_plain(I) elementary_dilation_(const Binary_Image<I>& input) { - return elementary_dilation_on_set_(exact(input), exact(input)); + return elementary_dilation_on_set_(exact(input)); } } // end of namespace oln::morpho::impl @@ -99,7 +99,9 @@ oln_plain(I) elementary_dilation(const Image_with_Nbh<I>& input) { - return impl::elementary_dilation_(exact(input)); + oln_plain(I) output = impl::elementary_dilation_(exact(input)); + postcondition(output >= input); + return output; } # endif // ! OLN_INCLUDE_ONLY Index: oln/morpho/gradient_internal.hh --- oln/morpho/gradient_internal.hh (revision 924) +++ oln/morpho/gradient_internal.hh (working copy) @@ -31,6 +31,7 @@ #include <oln/morpho/erosion.hh> #include <oln/arith/minus.hh> + namespace oln { @@ -41,8 +42,7 @@ template <typename I, typename W> oln_plain(I) - gradient_internal(const Image<I>& input, - const Window<W>& win); + gradient_internal(const Image<I>& input, const Window<W>& win); # ifndef OLN_INCLUDE_ONLY @@ -54,10 +54,10 @@ template <typename I, typename W> oln_plain(I) - gradient_internal_(const Image<I>& input, - const Window<W>& win) + gradient_internal_(const Image<I>& input, const Window<W>& win) { - return input - erosion(input, win); + oln_plain(I) ero = erosion(input, win); + return input - ero; } @@ -69,10 +69,11 @@ template <typename I, typename W> oln_plain(I) - gradient_internal(const Image<I>& input, - const Window<W>& win) + gradient_internal(const Image<I>& input, const Window<W>& win) { - return impl::gradient_internal_(exact(input), win); + oln_plain(I) output = impl::gradient_internal_(exact(input), exact(win)); + postcondition(output >= literal(0)); + return output; } # endif // ! OLN_INCLUDE_ONLY Index: oln/morpho/top_hat_black.hh --- oln/morpho/top_hat_black.hh (revision 924) +++ oln/morpho/top_hat_black.hh (working copy) @@ -32,6 +32,7 @@ #include <oln/morpho/closing.hh> #include <oln/arith/minus.hh> + namespace oln { @@ -42,8 +43,7 @@ template <typename I, typename W> oln_plain(I) - top_hat_black(const Image<I>& input, - const Window<W>& win); + top_hat_black(const Image<I>& input, const Window<W>& win); # ifndef OLN_INCLUDE_ONLY @@ -55,10 +55,10 @@ template <typename I, typename W> oln_plain(I) - top_hat_black_(const Image<I>& input, - const Window<W>& win) + top_hat_black_(const Image<I>& input, const Window<W>& win) { - return closing(input, win) - input; + oln_plain(I) clo = closing(input, win); + return clo - input; } @@ -71,10 +71,11 @@ template <typename I, typename W> oln_plain(I) - top_hat_black(const Image<I>& input, - const Window<W>& win) + top_hat_black(const Image<I>& input, const Window<W>& win) { - return impl::top_hat_black_(exact(input), win); + oln_plain(I) output = impl::top_hat_black_(exact(input), exact(win)); + postcondition(output >= literal(0)); + return output; } # endif // ! OLN_INCLUDE_ONLY Index: oln/morpho/gradient.hh --- oln/morpho/gradient.hh (revision 924) +++ oln/morpho/gradient.hh (working copy) @@ -32,6 +32,7 @@ #include <oln/morpho/dilation.hh> #include <oln/arith/minus.hh> + namespace oln { @@ -42,8 +43,7 @@ template <typename I, typename W> oln_plain(I) - gradient(const Image<I>& input, - const Window<W>& win); + gradient(const Image<I>& input, const Window<W>& win); # ifndef OLN_INCLUDE_ONLY @@ -55,10 +55,11 @@ template <typename I, typename W> oln_plain(I) - gradient_(const Image<I>& input, - const Window<W>& win) + gradient_(const Image<I>& input, const Window<W>& win) { - return dilation(input, win) - erosion(input, win); + oln_plain(I) dil = dilation(input, win); + oln_plain(I) ero = erosion(input, win); + return dil - ero; } @@ -69,10 +70,11 @@ template <typename I, typename W> oln_plain(I) - gradient(const Image<I>& input, - const Window<W>& win) + gradient(const Image<I>& input, const Window<W>& win) { - return impl::gradient_(exact(input), win); + oln_plain(I) output = impl::gradient_(exact(input), exact(win)); + postcondition(output >= literal(0)); + return output; } # endif // ! OLN_INCLUDE_ONLY Index: oln/morpho/top_hat_white.hh --- oln/morpho/top_hat_white.hh (revision 924) +++ oln/morpho/top_hat_white.hh (working copy) @@ -32,6 +32,7 @@ #include <oln/morpho/closing.hh> #include <oln/arith/minus.hh> + namespace oln { @@ -42,8 +43,8 @@ template <typename I, typename W> oln_plain(I) - top_hat_white(const Image<I>& input, - const Window<W>& win); + top_hat_white(const Image<I>& input, const Window<W>& win); + # ifndef OLN_INCLUDE_ONLY @@ -54,10 +55,10 @@ template <typename I, typename W> oln_plain(I) - top_hat_white_(const Image<I>& input, - const Window<W>& win) + top_hat_white_(const Image<I>& input, const Window<W>& win) { - return input - opening(input, win); + oln_plain(I) ope = opening(input, win) + return input - ope; } @@ -70,10 +71,11 @@ template <typename I, typename W> oln_plain(I) - top_hat_white(const Image<I>& input, - const Window<W>& win) + top_hat_white(const Image<I>& input, const Window<W>& win) { - return impl::top_hat_white_(exact(input), win); + oln_plain(I) output = impl::top_hat_white_(exact(input), exact(win)); + postcondition(output >= literal(0)); + return output; } # endif // ! OLN_INCLUDE_ONLY Index: oln/morpho/closing.hh --- oln/morpho/closing.hh (revision 924) +++ oln/morpho/closing.hh (working copy) @@ -31,6 +31,7 @@ #include <oln/morpho/erosion.hh> #include <oln/morpho/dilation.hh> + namespace oln { @@ -53,8 +54,7 @@ template <typename I, typename W> oln_plain(I) - closing_(const Image<I>& input, - const Window<W>& win) + closing_(const Image<I>& input, const Window<W>& win) { oln_plain(I) tmp = morpho::dilation(input, win); return morpho::erosion(tmp, win); // FIXME : inverse(win). @@ -72,7 +72,9 @@ oln_plain(I) closing(const Image<I>& input, const Window<W>& win) { - return impl::closing_(exact(input), exact(win)); + oln_plain(I) output = impl::closing_(exact(input), exact(win)); + postcondition(output >= input); + return output; } # endif // ! OLN_INCLUDE_ONLY Index: oln/morpho/opening.hh --- oln/morpho/opening.hh (revision 924) +++ oln/morpho/opening.hh (working copy) @@ -31,6 +31,7 @@ #include <oln/morpho/erosion.hh> #include <oln/morpho/dilation.hh> + namespace oln { @@ -53,11 +54,10 @@ template <typename I, typename W> oln_plain(I) - opening_(const Image<I>& input, - const Window<W>& win) + opening_(const Image<I>& input, const Window<W>& win) { - oln_plain(I) tmp = morpho::erosion(input, win); - return morpho::dilation(tmp, win); // FIXME : inverse(win). + oln_plain(I) ero = morpho::erosion(input, win); + return morpho::dilation(ero, win); // FIXME : inverse(win). } // FIXME: Add a fast version. @@ -71,7 +71,9 @@ oln_plain(I) opening(const Image<I>& input, const Window<W>& win) { - return impl::opening_(exact(input), win); + oln_plain(I) output = impl::opening_(exact(input), exact(win)); + postcondition(output <= input); + return output; } # endif // ! OLN_INCLUDE_ONLY Index: oln/morpho/gradient_external.hh --- oln/morpho/gradient_external.hh (revision 924) +++ oln/morpho/gradient_external.hh (working copy) @@ -31,6 +31,7 @@ #include <oln/morpho/dilation.hh> #include <oln/arith/minus.hh> + namespace oln { @@ -41,8 +42,7 @@ template <typename I, typename W> oln_plain(I) - gradient_external(const Image<I>& input, - const Window<W>& win); + gradient_external(const Image<I>& input, const Window<W>& win); # ifndef OLN_INCLUDE_ONLY @@ -54,10 +54,10 @@ template <typename I, typename W> oln_plain(I) - gradient_external_(const Image<I>& input, - const Window<W>& win) + gradient_external_(const Image<I>& input, const Window<W>& win) { - return dilation(input, win) - input; + oln_plain(I) dil = dilation(input, win); + return dil - input; } @@ -68,10 +68,11 @@ template <typename I, typename W> oln_plain(I) - gradient_external(const Image<I>& input, - const Window<W>& win) + gradient_external(const Image<I>& input, const Window<W>& win) { - return impl::gradient_external_(exact(input), win); + oln_plain(I) output = impl::gradient_external_(exact(input), exact(win)); + postcondition(output >= literal(0)); + return output; } # endif // ! OLN_INCLUDE_ONLY Index: oln/morpho/laplace.hh --- oln/morpho/laplace.hh (revision 924) +++ oln/morpho/laplace.hh (working copy) @@ -28,9 +28,9 @@ #ifndef OLN_MORPHO_LAPLACE_HH # define OLN_MORPHO_LAPLACE_HH -#include <oln/morpho/elementary_gradient_external.hh> -#include <oln/morpho/elementary_gradient_internal.hh> -#include <oln/arith/minus.hh> +# include <oln/morpho/gradient_external.hh> +# include <oln/morpho/gradient_internal.hh> + namespace oln { @@ -42,8 +42,7 @@ template <typename I, typename W> oln_plain(I) - laplace(const Image<I>& input, - const Window<W>& win); + laplace(const Image<I>& input, const Window<W>& win); # ifndef OLN_INCLUDE_ONLY @@ -55,10 +54,11 @@ template <typename I, typename W> oln_plain(I) - laplace_(const Image<I>& input, - const Window<W>& win) + laplace_(const Image<I>& input, const Window<W>& win) { - return gradient_external(input, win) - gradient_internal(input, win); + oln_plain(I) g_ext = gradient_external(input, win); + oln_plain(I) g_int = gradient_internal(input, win); + return g_ext - g_int; } @@ -71,10 +71,9 @@ template <typename I, typename W> oln_plain(I) - laplace(const Image<I>& input, - const Window<W>& win) + laplace(const Image<I>& input, const Window<W>& win) { - return impl::laplace_(exact(input), win); + return impl::laplace_(exact(input), exact(win)); } # endif // ! OLN_INCLUDE_ONLY Index: oln/morpho/dilation.hh --- oln/morpho/dilation.hh (revision 924) +++ oln/morpho/dilation.hh (working copy) @@ -29,8 +29,11 @@ # define OLN_MORPHO_DILATION_HH #include <oln/level/apply_local.hh> +# include <oln/level/compare.hh> #include <oln/border/fill.hh> #include <oln/accumulator/max.hh> +# include <oln/accumulator/or.hh> + namespace oln { @@ -54,9 +57,7 @@ template <typename I, typename W> oln_plain(I) - dilation_on_function_(const Image<I>&, - const I& input, - const Window<W>& win) + dilation_on_function_(const Image<I>& input, const Window<W>& win) { border::fill(input, oln_min(oln_value(I))); accumulator::max_<oln_value(I)> max; @@ -65,9 +66,7 @@ template <typename I, typename W> oln_plain(I) - dilation_on_set_(const Image<I>&, - const I& input, - const Window<W>& win) + dilation_on_set_(const Image<I>& input, const Window<W>& win) { border::fill(input, oln_min(oln_value(I))); accumulator::or_<oln_value(I)> accu_or; @@ -80,17 +79,15 @@ // Impl facade. template <typename I, typename W> - oln_plain(I) dilation_(const Image<I>& input, - const Window<W>& win) + oln_plain(I) dilation_(const Image<I>& input, const Window<W>& win) { - return dilation_on_function_(exact(input), exact(input), win); + return dilation_on_function_(exact(input), exact(win)); } template <typename I, typename W> - oln_plain(I) dilation_(const Binary_Image<I>& input, - const Window<W>& win) + oln_plain(I) dilation_(const Binary_Image<I>& input, const Window<W>& win) { - return dilation_on_set_(exact(input), exact(input), win); + return dilation_on_set_(exact(input), exact(win)); } } // end of namespace oln::morpho::impl @@ -102,7 +99,9 @@ oln_plain(I) dilation(const Image<I>& input, const Window<W>& win) { - return impl::dilation_(exact(input), exact(win)); + oln_plain(I) output = impl::dilation_(exact(input), exact(win)); + postcondition(output >= input); + return output; } # endif // ! OLN_INCLUDE_ONLY Index: oln/morpho/elementary_erosion.hh --- oln/morpho/elementary_erosion.hh (revision 924) +++ oln/morpho/elementary_erosion.hh (working copy) @@ -29,8 +29,11 @@ # define OLN_MORPHO_ELEMENTARY_EROSION_HH #include <oln/level/apply_local.hh> +# include <oln/level/compare.hh> #include <oln/border/fill.hh> #include <oln/accumulator/min.hh> +# include <oln/accumulator/and.hh> + namespace oln { @@ -54,8 +57,7 @@ template <typename I> oln_plain(I) - elementary_erosion_on_function_(const Image<I>&, - const I& input) + elementary_erosion_on_function_(const Image<I>& input) { border::fill(input, oln_max(oln_value(I))); accumulator::min_<oln_value(I)> min; @@ -64,10 +66,9 @@ template <typename I> oln_plain(I) - elementary_erosion_on_set_(const Image<I>&, - const I& input) + elementary_erosion_on_set_(const Image<I>& input) { - border::fill(input, oln_max(oln_value(I))); + border::fill(input, true); accumulator::and_<oln_value(I)> accu_and; return level::apply_local(accu_and, input); } @@ -113,13 +114,13 @@ template <typename I> oln_plain(I) elementary_erosion_(const Image<I>& input) { - return elementary_erosion_on_function_(exact(input), exact(input)); + return elementary_erosion_on_function_(exact(input)); } template <typename I> oln_plain(I) elementary_erosion_(const Binary_Image<I>& input) { - return elementary_erosion_on_set_(exact(input), exact(input)); + return elementary_erosion_on_set_(exact(input)); } @@ -132,7 +133,9 @@ oln_plain(I) elementary_erosion(const Image_with_Nbh<I>& input) { - return impl::elementary_erosion_(exact(input)); + oln_plain(I) output = impl::elementary_erosion_(exact(input)); + postcondition(output <= input); + return output; } # endif // ! OLN_INCLUDE_ONLY Index: oln/morpho/erosion.hh --- oln/morpho/erosion.hh (revision 924) +++ oln/morpho/erosion.hh (working copy) @@ -29,8 +29,11 @@ # define OLN_MORPHO_EROSION_HH #include <oln/level/apply_local.hh> +# include <oln/level/compare.hh> #include <oln/border/fill.hh> #include <oln/accumulator/min.hh> +# include <oln/accumulator/and.hh> + namespace oln { @@ -54,9 +57,7 @@ template <typename I, typename W> oln_plain(I) - erosion_on_function_(const Image<I>&, - const I& input, - const Window<W>& win) + erosion_on_function_(const Image<I>& input, const Window<W>& win) { border::fill(input, oln_max(oln_value(I))); accumulator::min_<oln_value(I)> min; @@ -65,9 +66,7 @@ template <typename I, typename W> oln_plain(I) - erosion_on_set_(const Image<I>&, - const I& input, - const Window<W>& win) + erosion_on_set_(const Image<I>& input, const Window<W>& win) { border::fill(input, true); accumulator::and_<oln_value(I)> accu_and; @@ -80,17 +79,15 @@ // Impl facade. template <typename I, typename W> - oln_plain(I) erosion_(const Image<I>& input, - const Window<W>& win) + oln_plain(I) erosion_(const Image<I>& input, const Window<W>& win) { - return erosion_on_function_(exact(input), exact(input), win); + return erosion_on_function_(exact(input), exact(win)); } template <typename I, typename W> - oln_plain(I) erosion_(const Binary_Image<I>& input, - const Window<W>& win) + oln_plain(I) erosion_(const Binary_Image<I>& input, const Window<W>& win) { - return erosion_on_set_(exact(input), exact(input), win); + return erosion_on_set_(exact(input), exact(win)); } } // end of namespace oln::morpho::impl @@ -102,7 +99,9 @@ oln_plain(I) erosion(const Image<I>& input, const Window<W>& win) { - return impl::erosion_(exact(input), exact(win)); + oln_plain(I) output = impl::erosion_(exact(input), exact(win)); + postcondition(output <= input); + return output; } # endif // ! OLN_INCLUDE_ONLY Index: oln/morpho/elementary_gradient_internal.hh --- oln/morpho/elementary_gradient_internal.hh (revision 924) +++ oln/morpho/elementary_gradient_internal.hh (working copy) @@ -31,6 +31,7 @@ #include <oln/morpho/elementary_erosion.hh> #include <oln/arith/minus.hh> + namespace oln { @@ -55,7 +56,8 @@ oln_plain(I) elementary_gradient_internal_(const Image_with_Nbh<I>& input) { - return input - elementary_erosion(input); + oln_plain(I) ero = elementary_erosion(input) + return input - ero; } @@ -70,7 +72,9 @@ oln_plain(I) elementary_gradient_internal(const Image_with_Nbh<I>& input) { - return impl::elementary_gradient_internal_(exact(input)); + oln_plain(I) output = impl::elementary_gradient_internal_(exact(input)); + postcondition(output >= literal(0)); + return output; } # endif // ! OLN_INCLUDE_ONLY Index: oln/arith/minus.hh --- oln/arith/minus.hh (revision 924) +++ oln/arith/minus.hh (working copy) @@ -29,7 +29,6 @@ # define OLN_ARITH_MINUS_HH # include <oln/core/concept/image.hh> -// # include <oln/core/internal/f_ch_value.hh> # include <oln/core/gen/traits.hh> Index: oln/level/compare.hh --- oln/level/compare.hh (revision 924) +++ oln/level/compare.hh (working copy) @@ -30,6 +30,10 @@ # include <oln/core/concept/image.hh> # include <oln/core/gen/pset_compare.hh> +# include <oln/core/gen/literal.hh> + +// FIXME: Rename this file as "comparison.hh". + namespace oln @@ -40,9 +44,22 @@ template <typename L, typename R> bool operator = (const Image<L>& lhs, const Image<R>& rhs); + template <typename I> + bool operator = (const Image<I>& lhs, const literal_<oln_value(I)>& val); + template <typename L, typename R> bool operator < (const Image<L>& lhs, const Image<R>& rhs); + template <typename I> + bool operator < (const Image<I>& lhs, const literal_<oln_value(I)>& val); + + template <typename L, typename R> + bool operator <= (const Image<L>& lhs, const Image<R>& rhs); + + template <typename I> + bool operator <= (const Image<I>& lhs, const literal_<oln_value(I)>& val); + + # ifndef OLN_LNCLUDE_ONLY @@ -55,7 +72,7 @@ // Generic version. template <typename L, typename R> - bool op_eq_(const Image<L>& lhs, const Image<R>& rhs); + bool op_eq_(const Image<L>& lhs, const Image<R>& rhs) { precondition(lhs.points() = rhs.points()); oln_piter(L) p(lhs.points()); @@ -66,13 +83,29 @@ } + // Image I = Value V + // ---------------------- + + // Generic version. + + template <typename I> + bool op_eq_(const Image<I>& lhs, const literal_<oln_value(I)>& val) + { + oln_piter(I) p(lhs.points()); + for_all(p) + if (lhs(p) != val) + return false; + return true; + } + + // Image L < Image R // --------------------- // Generic version. template <typename L, typename R> - bool op_less_(const Image<L>& lhs, const Image<R>& rhs); + bool op_less_(const Image<L>& lhs, const Image<R>& rhs) { precondition(lhs.points() = rhs.points()); oln_piter(L) p(lhs.points()); @@ -82,6 +115,56 @@ return true; } + + // Image I < Value V + // --------------------- + + // Generic version. + + template <typename I> + bool op_less_(const Image<I>& lhs, const literal_<oln_value(I)>& val) + { + oln_piter(I) p(lhs.points()); + for_all(p) + if (lhs(p) >= val) + return false; + return true; + } + + + // Image L <= Image R + // ---------------------- + + // Generic version. + + template <typename L, typename R> + bool op_leq_(const Image<L>& lhs, const Image<R>& rhs) + { + precondition(lhs.points() = rhs.points()); + oln_piter(L) p(lhs.points()); + for_all(p) + if (lhs(p) > rhs(p)) + return false; + return true; + } + + + // Image I <= Value V + // ---------------------- + + // Generic version. + + template <typename I> + bool op_leq_(const Image<I>& lhs, const literal_<oln_value(I)>& val) + { + oln_piter(I) p(lhs.points()); + for_all(p) + if (lhs(p) > val) + return false; + return true; + } + + } // end of namespace oln::level::impl @@ -94,6 +177,12 @@ return impl::op_eq_(exact(lhs), exact(rhs)); } + template <typename I> + bool operator = (const Image<I>& lhs, const literal_<oln_value(I)>& val) + { + return impl::op_eq_(exact(lhs), val); + } + template <typename L, typename R> bool operator < (const Image<L>& lhs, const Image<R>& rhs) { @@ -101,6 +190,25 @@ return impl::op_less_(exact(lhs), exact(rhs)); } + template <typename I> + bool operator < (const Image<I>& lhs, const literal_<oln_value(I)>& val) + { + return impl::op_less_(exact(lhs), val); + } + + template <typename L, typename R> + bool operator <= (const Image<L>& lhs, const Image<R>& rhs) + { + assert_same_grid_<L, R>::check(); + return impl::op_leq_(exact(lhs), exact(rhs)); + } + + template <typename I> + bool operator <= (const Image<I>& lhs, const literal_<oln_value(I)>& val) + { + return impl::op_leq_(exact(lhs), val); + } + # endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/level/local.hh --- oln/level/local.hh (revision 924) +++ oln/level/local.hh (working copy) @@ -42,9 +42,7 @@ template <typename A, typename I> typename A::result - local(const Accumulator<A>& f, - const Image_with_Nbh<I>& input, - const oln_point(I)& p); + local(const Accumulator<A>& f, const Image<I>& input, const oln_point(I)& p); template <typename A, typename I, typename W> typename A::result @@ -72,9 +70,7 @@ f.init_with(input(p)); oln_niter(I) n(p, input); for_all(n) - { f(input(n)); - } return f.value(); } @@ -192,10 +188,9 @@ template <typename A, typename I> typename A::result - local(const Accumulator<A>& f, - const Image_with_Nbh<I>& input, - const oln_point(I)& p) + local(const Accumulator<A>& f, const Image<I>& input, const oln_point(I)& p) { + mlc::assert_< mlc_is_a(I, Image_with_Nbh) >::check(); return impl::local_(exact(f), exact(input), p); } @@ -206,7 +201,7 @@ const oln_point(I)& p, const Window<W>& win) { - return impl::local_(exact(f), exact(input), p, win); + return impl::local_(exact(f), exact(input), p, exact(win)); } #endif // ! OLN_INCLUDE_ONLY Index: oln/level/apply_local.hh --- oln/level/apply_local.hh (revision 924) +++ oln/level/apply_local.hh (working copy) @@ -44,14 +44,12 @@ template <typename F, typename I> oln_plain_value(I, typename F::result) - apply_local(const Accumulator<F>& f, - const Image_with_Nbh<I>& input); + apply_local(const Accumulator<F>& f, const Image<I>& input); template <typename F, typename I, typename W> oln_plain_value(I, typename F::result) - apply_local(const Accumulator<F>& f, - const Image<I>& input, - const Window<W>& win); + apply_local(const Accumulator<F>& f, const Image<I>& input, const Window<W>& win); + # ifndef OLN_INCLUDE_ONLY @@ -94,19 +92,17 @@ template <typename F, typename I> oln_plain_value(I, typename F::result) - apply_local(const Accumulator<F>& f, - const Image_with_Nbh<I>& input) + apply_local(const Accumulator<F>& f, const Image<I>& input) { + mlc::assert_< mlc_is_a(I, Image_with_Nbh) >::check(); return impl::apply_local_(exact(f), exact(input)); } template <typename F, typename I, typename W> oln_plain_value(I, typename F::result) - apply_local(const Accumulator<F>& f, - const Image<I>& input, - const Window<W>& win) + apply_local(const Accumulator<F>& f, const Image<I>& input, const Window<W>& win) { - return impl::apply_local_(exact(f), exact(input), win); + return impl::apply_local_(exact(f), exact(input), exact(win)); } # endif Index: oln/value/builtin.hh --- oln/value/builtin.hh (revision 924) +++ oln/value/builtin.hh (working copy) @@ -29,7 +29,6 @@ # define OLN_VALUE_BUILTIN_HH # include <oln/core/concept/value.hh> -# include <oln/core/gen/traits.hh> namespace oln @@ -88,22 +87,12 @@ }; - template <typename Op> - struct set_trait_< Value, int, Op, Value, float > - { - typedef float ret; - }; - template <typename Op> - struct set_trait_< Value, float, Op, Value, int > - { - typedef float ret; - }; - - // FIXME: To be continued... +} // end of namespace oln -} // end of namespace oln +// FIXME: Bad? +# include <oln/value/builtin_traits.hh> #endif // ! OLN_VALUE_BUILTIN_HH Index: oln/value/builtin_traits.hh --- oln/value/builtin_traits.hh (revision 0) +++ oln/value/builtin_traits.hh (revision 0) @@ -0,0 +1,57 @@ +// 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_VALUE_BUILTIN_TRAITS_HH +# define OLN_VALUE_BUILTIN_TRAITS_HH + +# include <oln/value/builtin.hh> +# include <oln/core/gen/traits.hh> + + +namespace oln +{ + + template <typename Op> + struct set_trait_< Value, int, Op, Value, float > + { + typedef float ret; + }; + + template <typename Op> + struct set_trait_< Value, float, Op, Value, int > + { + typedef float ret; + }; + + // FIXME: To be continued... + + +} // end of namespace oln + + +#endif // ! OLN_VALUE_BUILTIN_TRAITS_HH +