
https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Add image level comparisons and better point set ones. * oln/level/compare.hh: New. * TODO: New "Rough list" and "Tiny improvements" sections. * oln/core/concept/grid.hh (both_types_should_have_the_same_grid_), (assert_same_grid_): New. * oln/core/concept/operators.hh: Separate defs from decls. Fix dispatch using 'exact'. * oln/core/gen/pset_compare.hh (guards): Remove. (operator<=, impl_leq_): Replace by... (operator<, impl_less_): ...these. TODO | 50 ++++++++++++++ oln/core/concept/grid.hh | 21 ++++++ oln/core/concept/operators.hh | 141 +++++++++++++++++++----------------------- oln/core/gen/pset_compare.hh | 54 +++++++--------- oln/level/compare.hh | 109 ++++++++++++++++++++++++++++++++ 5 files changed, 271 insertions(+), 104 deletions(-) Index: TODO --- TODO (revision 906) +++ TODO (working copy) @@ -1,3 +1,53 @@ + + +* Rough list + +value types (including gray level types, label types, (bool, T) type, +color types, etc.) + +op traits (for C types, oln value types, and also oln types such as +points, etc.) + +image thru a function f (where f is pure, a bijection, a two-way +function, an accessor, a projection, etc.) + +basics important routines: fill, assign, clone, unmorph (undress?), +convert, ... + +torus and mask types, and the proper niter type deductions (with or +without virtual border) + +virtual border adaptation and initialization policies + +safe type when image is mutable; question: can we have Mutable_Image& +as argument when an image, a morpher, is created on the fly? + +io pnm + +draw routines + +window types such as lines, rectangles, and so on + +meta-window type; for instance, ball, segment, etc. + +const promotions for op_<L,O,R> types + + +* Tiny improvements + +Replace point type comparison assertions by an explicit version +(just like assert_same_grid_) + + + +* Some ideas + +Consider the morphological gradient "d(f) - e(f)", it is a combination +of local functions; can we make it explicit? Advantage: no temp image +created. + + + * Renaming ** point_accessibility Index: oln/level/compare.hh --- oln/level/compare.hh (revision 0) +++ oln/level/compare.hh (revision 0) @@ -0,0 +1,109 @@ +// 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_COMPARE_HH +# define OLN_LEVEL_COMPARE_HH + +# include <oln/core/concept/image.hh> +# include <oln/core/gen/pset_compare.hh> + + +namespace oln +{ + + // Fwd decls. + + template <typename L, typename R> + bool operator = (const Image<L>& lhs, const Image<R>& rhs); + + template <typename L, typename R> + bool operator < (const Image<L>& lhs, const Image<R>& rhs); + + +# ifndef OLN_LNCLUDE_ONLY + + namespace impl + { + + // Image L = Image R + // ---------------------- + + // Generic version. + + template <typename L, typename R> + bool op_eq_(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 L < Image R + // --------------------- + + // Generic version. + + template <typename L, typename R> + bool op_less_(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; + } + + } // end of namespace oln::level::impl + + + // Facades. + + template <typename L, typename R> + bool operator = (const Image<L>& lhs, const Image<R>& rhs) + { + assert_same_grid_<L, R>::check(); + return impl::op_eq_(exact(lhs), exact(rhs)); + } + + template <typename L, typename R> + bool operator < (const Image<L>& lhs, const Image<R>& rhs) + { + assert_same_grid_<L, R>::check(); + return impl::op_less_(exact(lhs), exact(rhs)); + } + +# endif // ! OLN_INCLUDE_ONLY + +} // end of namespace oln + + +#endif // ! OLN_LEVEL_COMPARE_HH Index: oln/core/concept/grid.hh --- oln/core/concept/grid.hh (revision 906) +++ oln/core/concept/grid.hh (working copy) @@ -52,6 +52,27 @@ }; + namespace ERROR + { + + template < typename Type_1, + typename Type_2, + typename Grid_1 = oln_grid(Type_1), + typename Grid_2 = oln_grid(Type_2) > + struct both_types_should_have_the_same_grid_ + { + }; + + } // end of namespace oln::ERROR + + + template <typename T1, typename T2> + struct assert_same_grid_ + : public mlc::assert_< mlc::eq_<oln_grid(T1), oln_grid(T2)>, + ERROR::both_types_should_have_the_same_grid_<T1, T2> > + {}; + + } // end of namespace oln Index: oln/core/concept/operators.hh --- oln/core/concept/operators.hh (revision 906) +++ oln/core/concept/operators.hh (working copy) @@ -34,8 +34,50 @@ namespace oln { - /// \{ /// Operator = (default version). + template <typename L, typename R> + bool operator=(const Any<L>& lhs, const Any<R>& rhs); + + /// Operator != (default version). + template <typename L, typename R> + bool operator!=(const Any<L>& lhs, const Any<R>& rhs); + + /// Operator < (default version). + template <typename L, typename R> + bool operator< (const Any<L>& lhs, const Any<R>& rhs); + + /// Operator > (default version). + template <typename L, typename R> + bool operator> (const Any<L>& lhs, const Any<R>& rhs); + + /// Operator >= (default version). + template <typename L, typename R> + bool operator>=(const Any<L>& lhs, const Any<R>& rhs); + + /// Operator <= (default version). + template <typename L, typename R> + bool operator<=(const Any<L>& lhs, const Any<R>& rhs); + + /// Operator += (default version). + template <typename L, typename R> + L& operator+=(Any<L>& lhs, const Any<R>& rhs); + + /// Operator + (default version). + template <typename T> + T operator+ (const Any<T>& lhs, const Any<T>& rhs); + + /// Operator -= (default version). + template <typename L, typename R> + L& operator-=(Any<L>& lhs, const Any<R>& rhs); + + /// Operator - (default version). + template <typename T> + T operator- (const Any<T>& rhs); + + + + +# ifndef OLN_INCLUDE_ONLY template <typename L, typename R> bool operator=(const Any<L>& lhs, const Any<R>& rhs) @@ -43,138 +85,87 @@ return exact(lhs).op_equal_(exact(rhs)); } - /// \} - - - /// \{ - /// Operator != (default version). - template <typename L, typename R> bool operator!=(const Any<L>& lhs, const Any<R>& rhs) { - return not (lhs = rhs); + return not (exact(lhs) = exact(rhs)); } - /// \} - - - /// \{ - /// Operator < (default version). - template <typename L, typename R> bool operator< (const Any<L>& lhs, const Any<R>& rhs) { return exact(lhs).op_less_(exact(rhs)); } - /// \} - - - /// \{ - /// Operator > (default version). - template <typename L, typename R> bool operator> (const Any<L>& lhs, const Any<R>& rhs) { - return rhs < lhs; + return exact(rhs) < exact(lhs); } - /// \} - - - /// \{ - /// Operator >= (default version). - template <typename L, typename R> bool operator>=(const Any<L>& lhs, const Any<R>& rhs) { - return not (lhs < rhs); + return not (exact(lhs) < exact(rhs)); } - /// \} - - - /// \{ - /// Operator <= (default version). - template <typename L, typename R> bool operator<=(const Any<L>& lhs, const Any<R>& rhs) { - return not (rhs < lhs); + return not (exact(rhs) < exact(lhs)); } - /// \} - - - /// \{ - /// Operator += (default version). - template <typename L, typename R> L& operator+=(Any<L>& lhs, const Any<R>& rhs) { return exact(lhs).op_plus_equal_(exact(rhs)); } - /// \} - - - /// \{ - /// Operators + (default versions). - template <typename T> T operator+ (const Any<T>& lhs, const Any<T>& rhs) { T tmp = exact(lhs); - return tmp += rhs; + return tmp += exact(rhs); } -// template <typename L, typename R> -// xtd_op_plus_trait(L, R) operator+ (const Any<L>& lhs, const Any<R>& rhs) -// { -// return exact(lhs).op_plus_(exact(rhs)); -// } - - /// \} - - - /// \{ - /// Operator -= (default version). - template <typename L, typename R> L& operator-=(Any<L>& lhs, const Any<R>& rhs) { return exact(lhs).op_minus_equal_(exact(rhs)); } - /// \} - - - /// \{ - /// Operators - (default versions). - template <typename T> T operator- (const Any<T>& rhs) { return exact(rhs).op_unary_minus_(); } -/* template <typename T> + /* + + FIXME: Activate? + + template <typename L, typename R> + xtd_op_plus_trait(L, R) operator+ (const Any<L>& lhs, const Any<R>& rhs) + { + return exact(lhs).op_plus_(exact(rhs)); + } + + template <typename T> T operator- (const Any<T>& lhs, const Any<T>& rhs) { T tmp = exact(lhs); return tmp -= rhs; } -*/ - -// template <typename L, typename R> -// xtd_op_minus_trait(L, R) operator- (const Any<L>& lhs, const Any<R>& rhs) -// { -// return exact(lhs).op_minus_(exact(rhs)); -// } - /// \} + template <typename L, typename R> + xtd_op_minus_trait(L, R) operator- (const Any<L>& lhs, const Any<R>& rhs) + { + return exact(lhs).op_minus_(exact(rhs)); + } + */ +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/gen/pset_compare.hh --- oln/core/gen/pset_compare.hh (revision 906) +++ oln/core/gen/pset_compare.hh (working copy) @@ -40,15 +40,7 @@ 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); - - - // FIXME: Guards; without impl! - template <typename L, typename R> bool operator < (const Point_Set<L>&, const Point_Set<R>&); - template <typename L, typename R> bool operator > (const Point_Set<L>&, const Point_Set<R>&); - template <typename L, typename R> bool operator >= (const Point_Set<L>&, const Point_Set<R>&); - // end of FIXME - + bool operator < (const Point_Set<L>& lhs, const Point_Set<R>& rhs); # ifndef OLN_INCLUDE_ONLY @@ -92,26 +84,26 @@ */ - // Point_Set L <= Point_Set R - // ------------------------------ + // Point_Set L < Point_Set R + // ----------------------------- // Generic version. template <typename L, typename R> - bool op_leq_(const Point_Set<L>& lhs, const Point_Set<R>& rhs) + bool op_less_(const Point_Set<L>& lhs, const Point_Set<R>& rhs) { - // quick test: - if (lhs.npoints() > rhs.npoints()) + if (lhs.npoints() >= rhs.npoints()) // quick test return false; - // final test: - oln_piter(R) pr(rhs); - pr.start(); - oln_piter(L) pl(lhs); - for_all(pl) - { - while (pr.is_valid() and pr.to_point() != pl.to_point()) - pr.next(); - if (not pr.is_valid()) + // we have lhs.npoints() < rhs.npoints() + // so we shall now test that all points of lhs are IN rhs + oln_piter(R) p_rhs(rhs); + p_rhs.start(); + oln_piter(L) p_lhs(lhs); + for_all(p_lhs) + { + while (p_rhs.is_valid() and p_rhs.to_point() != p_lhs.to_point()) + p_rhs.next(); + if (not p_rhs.is_valid()) return false; } return true; @@ -122,12 +114,16 @@ FIXME: Activate. template <typename L, typename R> - bool op_leq_(const Box<L>& lhs, const Box<R>& rhs) + bool op_less_(const Box<L>& lhs, const Box<R>& rhs) { + // subset test (i.e., lhs <= rhs) for (unsigned i = 0; i < L::n; ++i) + { if (lhs.pmin()[i] < rhs.pmin()[i] or lhs.pmax()[i] > rhs.pmax()[i]) return false; - return true; + } + // proper (strict) test + return lhs != rhs; } */ @@ -140,15 +136,15 @@ template <typename L, typename R> bool operator = (const Point_Set<L>& lhs, const Point_Set<R>& rhs) { - mlc::assert_equal_< oln_grid(L), oln_grid(R) >::check(); // FIXME: Add err msg. + assert_same_grid_<L, R>::check(); return impl::op_eq_(exact(lhs), exact(rhs)); } template <typename L, typename R> - bool operator <= (const Point_Set<L>& lhs, const Point_Set<R>& rhs) + bool operator < (const Point_Set<L>& lhs, const Point_Set<R>& rhs) { - mlc::assert_equal_< oln_grid(L), oln_grid(R) >::check(); // FIXME: Add err msg. - return impl::op_leq_(exact(lhs), exact(rhs)); + assert_same_grid_<L, R>::check(); + return impl::op_less_(exact(lhs), exact(rhs)); } # endif // ! OLN_INCLUDE_ONLY