
https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Introduce zero and update some traits and ops. * oln/convert/to_dpoint.hh: New. * oln/core/gen/zero.hh: New. * oln/core/concept/literal.hh: New. * tests/core/pw_value.cc, * oln/core/gen/over.hh, * oln/convert/to_weighted_window.hh, * oln/draw/bresenham.hh, * oln/morpho/elementary_gradient.hh, * oln/morpho/elementary_gradient_external.hh, * oln/morpho/gradient_internal.hh, * oln/morpho/top_hat_black.hh, * oln/morpho/gradient.hh, * oln/morpho/top_hat_white.hh, * oln/morpho/gradient_external.hh, * oln/morpho/elementary_gradient_internal.hh, * oln/level/compare.hh, * oln/linear/convolution.hh, * oln/linear/mean.hh: Update. * oln/core/gen/traits.hh (oln_internal_specialize_un_trait_T_): New. (clean_for_trait_): New specializations. * oln/core/gen/value.hh (set_trait_): Remove. * oln/core/gen/such_as.hh: Add reminder. * oln/core/concept/iterator_on_points.hh (set_trait_): New specializations. * oln/core/concept/point.hh (assign_): New. (operator): Fix. * oln/core/concept/dpoint.hh: Likewise. * oln/core/concept/window.hh (op_unary_minus_): Change into... (operator-): ...this. * oln/core/concept/operators.hh: Fix. * oln/core/internal/dpoint_base.hh (impl_op_equal_), (impl_op_mod_equal_), (impl_op_less_), (impl_op_plus_equal_), (impl_op_minus_equal_), (impl_op_mod_equal_), (impl_op_unary_minus_): Rmove; obsolete. * oln/value/builtin.hh (super_trait_): New ones. * oln/value/builtin_traits.hh (set_trait_): New one. oln/convert/to_dpoint.hh | 67 +++++++++++++++++++++ oln/convert/to_weighted_window.hh | 4 - oln/core/concept/dpoint.hh | 14 +++- oln/core/concept/iterator_on_points.hh | 16 +++++ oln/core/concept/literal.hh | 88 ++++++++++++++++++++++++++++ oln/core/concept/operators.hh | 18 +---- oln/core/concept/point.hh | 23 +++++-- oln/core/concept/window.hh | 17 ++--- oln/core/gen/over.hh | 15 ++-- oln/core/gen/such_as.hh | 7 ++ oln/core/gen/traits.hh | 52 ++++++++++++++-- oln/core/gen/value.hh | 8 -- oln/core/gen/zero.hh | 91 +++++++++++++++++++++++++++++ oln/core/internal/dpoint_base.hh | 44 -------------- oln/draw/bresenham.hh | 2 oln/level/compare.hh | 19 ++---- oln/linear/convolution.hh | 13 +--- oln/linear/mean.hh | 6 - oln/morpho/elementary_gradient.hh | 3 oln/morpho/elementary_gradient_external.hh | 3 oln/morpho/elementary_gradient_internal.hh | 3 oln/morpho/gradient.hh | 3 oln/morpho/gradient_external.hh | 3 oln/morpho/gradient_internal.hh | 3 oln/morpho/top_hat_black.hh | 3 oln/morpho/top_hat_white.hh | 3 oln/value/builtin.hh | 14 ++++ oln/value/builtin_traits.hh | 6 + tests/core/pw_value.cc | 2 29 files changed, 423 insertions(+), 127 deletions(-) Index: tests/core/pw_value.cc --- tests/core/pw_value.cc (revision 968) +++ tests/core/pw_value.cc (working copy) @@ -45,6 +45,6 @@ image2d<double> ima2(3,3); ima2(p) = 2.3; - double d = ((pw_value(ima1) + pw_value(ima2) * literal(4.)) / literal(.2))(p); + double d = ((pw_value(ima1) + pw_value(ima2) * 4.) / .2)(p); assert(d > 50.9999 and d < 51.0001); } Index: oln/convert/to_weighted_window.hh --- oln/convert/to_weighted_window.hh (revision 968) +++ oln/convert/to_weighted_window.hh (working copy) @@ -28,6 +28,7 @@ #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> @@ -61,11 +62,10 @@ oln_f_image_to_weighted_window(I) to_weighted_window(const Image<I>& input) { - oln_point(I) O; O.set_all(0); oln_f_image_to_weighted_window(I) output; oln_piter(I) p(input.points()); for_all(p) - output.take(input(p), O - oln_point(I)(p)); // FIXME: replace to_point by zero - p + output.take(input(p), zero - oln_point(I)(p)); return output; } Index: oln/convert/to_dpoint.hh --- oln/convert/to_dpoint.hh (revision 0) +++ oln/convert/to_dpoint.hh (revision 0) @@ -0,0 +1,67 @@ +// 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_CONVERT_TO_DPOINT_HH +# define OLN_CONVERT_TO_DPOINT_HH + +# include <oln/core/concept/point.hh> + + +namespace oln +{ + + namespace convert + { + + // Fwd decl. + + template <typename P> + oln_dpoint(P) + to_dpoint(const Generalized_Point<P>& p); + + +# ifndef OLN_INCLUDE_ONLY + + // Generic version. + + template <typename P> + oln_dpoint(P) + to_dpoint(const Generalized_Point<P>& p) + { + oln_dpoint(P) tmp; + tmp.vec() = exact(p).vec(); + return tmp; + } + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace oln::convert + +} // end of namespace oln + + +#endif // ! OLN_CONVERT_TO_DPOINT_HH Index: oln/core/gen/traits.hh --- oln/core/gen/traits.hh (revision 968) +++ oln/core/gen/traits.hh (working copy) @@ -115,6 +115,15 @@ } +# define oln_internal_specialize_un_trait_T_(Name) \ + \ + template <typename T> \ + struct set_utrait_< Name##_id, Any, T > \ + { \ + typedef T ret; \ + } + + namespace oln @@ -146,6 +155,18 @@ }; + // "absorbing" a literal: + template <typename L> struct Literal; // Fwd decl + template <typename L, typename Op, template <class> class C, typename R> + struct set_trait_<Literal, L, Op, C, R> + : public set_trait_<C, R, Op, C, R> + {}; + template <template <class> class C, typename L, typename Op, typename R> + struct set_trait_<C, L, Op, Literal, R> + : public set_trait_<C, L, Op, C, L> + {}; + + // set_utrait_ for unary operators. @@ -209,6 +230,8 @@ oln_internal_specialize_bin_trait_T_(div); oln_internal_specialize_bin_trait_T_(mod); + oln_internal_specialize_un_trait_T_(uminus); + oln_internal_specialize_bin_trait_bool_(eq); oln_internal_specialize_bin_trait_bool_(neq); @@ -221,6 +244,8 @@ oln_internal_specialize_bin_trait_T_(or); oln_internal_specialize_bin_trait_T_(xor); + oln_internal_specialize_un_trait_T_(not); + // Fwd decl. template <typename T> struct value_; @@ -259,17 +284,30 @@ template <typename T> struct clean_for_trait_ { - typedef T ret; + typedef T ret; // default is identity }; template <typename T> - struct clean_for_trait_< const oln::value_<T> > { typedef T ret; }; + struct clean_for_trait_< T& > + { + // remove & + typedef typename clean_for_trait_<T>::ret ret; + }; + template <typename T> - struct clean_for_trait_< const oln::value_<T>& > { typedef T ret; }; + struct clean_for_trait_< const oln::value_<T> > { typedef T ret; }; template <typename T> - struct clean_for_trait_< oln::value_<T>& > { typedef T ret; }; + struct clean_for_trait_< oln::value_<T> > { typedef T ret; }; - // FIXME: Add clean_for_trait_ for builtins? + // builtins + template <> struct clean_for_trait_< const unsigned > { typedef unsigned ret; }; + template <> struct clean_for_trait_< unsigned > { typedef unsigned ret; }; + template <> struct clean_for_trait_< const int > { typedef int ret; }; + template <> struct clean_for_trait_< int > { typedef int ret; }; + template <> struct clean_for_trait_< const float > { typedef float ret; }; + template <> struct clean_for_trait_< float > { typedef float ret; }; + template <> struct clean_for_trait_< const double > { typedef double ret; }; + template <> struct clean_for_trait_< double > { typedef double ret; }; } // end of namespace oln::internal @@ -284,7 +322,9 @@ }; template <typename Op, typename T> - struct get_utrait_ : public internal::get_utrait_cat__< Op, oln_category_of_(T), T > + struct get_utrait_ : public internal::get_utrait_cat__< Op, + oln_category_of_(T), + typename internal::clean_for_trait_<T>::ret > { }; Index: oln/core/gen/such_as.hh --- oln/core/gen/such_as.hh (revision 968) +++ oln/core/gen/such_as.hh (working copy) @@ -60,6 +60,13 @@ // Image | Function_p2b + // FIXME: Do it! +// template <typename I, typename F> +// set_trait_< Image, I, pipe_id, Function_p2b, F > +// { +// typedef op_<I, such_as, F> ret; +// }; + template <typename I, typename F> op_<const I, such_as, const F> operator | (const Image<I>& ima, const Function_p2b<F>& f); Index: oln/core/gen/over.hh --- oln/core/gen/over.hh (revision 968) +++ oln/core/gen/over.hh (working copy) @@ -37,7 +37,8 @@ # include <oln/core/internal/op_fp2v_over_pset.hh> # include <oln/core/gen/fun.hh> -# include <oln/core/gen/literal.hh> +# include <oln/core/gen/constant.hh> +# include <oln/core/gen/value.hh> namespace oln @@ -60,8 +61,8 @@ // V / Point_Set template <typename V, typename S> - op_<const lit_p2v_<oln_point(S), V>, over, const S> - operator / (const literal_<V>& value, const Point_Set<S>& pset); + op_<const constant_p2v_<oln_point(S), V>, over, const S> + operator / (const value_<V>& v, const Point_Set<S>& pset); @@ -92,11 +93,11 @@ // V / Point_Set template <typename V, typename S> - op_<const lit_p2v_<oln_point(S), V>, over, const S> - operator / (const literal_<V>& value, const Point_Set<S>& pset) + op_<const constant_p2v_<oln_point(S), V>, over, const S> + operator / (const value_<V>& v, const Point_Set<S>& pset) { - lit_p2v_<oln_point(S), V> lit(value); - op_<const lit_p2v_<oln_point(S), V>, over, const S> tmp(lit, exact(pset)); + constant_p2v_<oln_point(S), V> v_(v); + op_<const constant_p2v_<oln_point(S), V>, over, const S> tmp(v_, exact(pset)); return tmp; } Index: oln/core/gen/value.hh --- oln/core/gen/value.hh (revision 968) +++ oln/core/gen/value.hh (working copy) @@ -93,14 +93,6 @@ value_<T> make_value(const value_<T>& val); - // traits - - template <typename L, typename Op, typename R> - struct set_trait_< Value, value_<L>, Op, Value, value_<R> > - { - typedef typename get_trait_<L, Op, R>::ret ret; - }; - # ifndef OLN_INCLUDE_ONLY Index: oln/core/gen/zero.hh --- oln/core/gen/zero.hh (revision 0) +++ oln/core/gen/zero.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_CORE_GEN_ZERO_HH +# define OLN_CORE_GEN_ZERO_HH + +# include <oln/core/concept/literal.hh> + + +namespace oln +{ + + struct zero_t : public Literal< zero_t > + { + + template <typename T> + operator T() const; + + // builtins: + operator unsigned() const; + operator int() const; + operator float() const; + operator double() const; + } + + zero; + + + + // Default unary minus operator. + + template <typename T> + T + operator - (const Any<T>& rhs); // Use binary -. + + + +# ifndef OLN_INCLUDE_ONLY + + template <typename T> + zero_t::operator T() const + { + mlc::assert_< mlc_is_a(T, Any) >::check(); // FIXME: Add err msg. + T tmp; + tmp.assign_(*this); + return tmp; + } + + zero_t::operator unsigned() const { return 0u; } + zero_t::operator int() const { return 0; } + zero_t::operator float() const { return 0.f; } + zero_t::operator double() const { return 0.; } + + + template <typename T> + T + operator - (const Any<T>& rhs) + { + return zero - exact(rhs); + } + +# endif // ! OLN_INCLUDE_ONLY + +} // end of namespace oln + + +#endif // ! OLN_CORE_GEN_ZERO_HH Index: oln/core/concept/iterator_on_points.hh --- oln/core/concept/iterator_on_points.hh (revision 968) +++ oln/core/concept/iterator_on_points.hh (working copy) @@ -99,6 +99,22 @@ typedef oln_minus_trait(Pit1, Pit2) ret; }; + template <typename Exact> struct Dpoint; // Fwd decl. + + template <typename It, typename D> + struct set_trait_< Iterator_on_Points, It, plus_id, Dpoint, D > + { + typedef oln_point(It) P; + typedef oln_plus_trait(P, D) ret; + }; + + template <typename It, typename D> + struct set_trait_< Iterator_on_Points, It, minus_id, Dpoint, D > + { + typedef oln_point(It) P; + typedef oln_minus_trait(P, D) ret; + }; + // \} Index: oln/core/concept/point.hh --- oln/core/concept/point.hh (revision 968) +++ oln/core/concept/point.hh (working copy) @@ -33,6 +33,7 @@ # include <oln/core/concept/grid.hh> # include <oln/core/concept/operators.hh> +# include <oln/core/gen/zero.hh> @@ -116,6 +117,9 @@ template <typename Exact> struct Point : public Generalized_Point<Exact> { + + void assign_(zero_t); + protected: Point(); @@ -171,6 +175,13 @@ { } + template <typename Exact> + void + Point<Exact>::assign_(zero_t) + { + exact(this)->vec().set_all(0); + } + template <typename P> oln_minus_trait(P, P) operator - (const Generalized_Point<P>& lhs, const Generalized_Point<P>& rhs) @@ -191,9 +202,10 @@ bool operator < (const Generalized_Point<P1>& lhs, const Generalized_Point<P2>& rhs) { - return exact(lhs).vec() < exact(rhs).vec(); + return xtd::lexi_less(exact(lhs).vec(), exact(rhs).vec()); } + // Invalid operators. template <typename P1, typename P2> @@ -201,7 +213,7 @@ const Generalized_Point<P2>& rhs) { mlc::abort_<P1, - ERROR::operator_< plus_id >::template _is_invalid_for_types_<P1, P2> + typename ERROR::operator_< plus_id >::template _is_invalid_for_types_<P1, P2> >::check(); } @@ -210,7 +222,7 @@ const Generalized_Point<P2>& rhs) { mlc::abort_<P1, - ERROR::operator_< plus_equal_id >::template _is_invalid_for_types_<P1, P2> + typename ERROR::operator_< plus_equal_id >::template _is_invalid_for_types_<P1, P2> >::check(); } @@ -219,7 +231,7 @@ const Generalized_Point<P2>& rhs) { mlc::abort_<P1, - ERROR::operator_< minus_equal_id >::template _is_invalid_for_types_<P1, P2> + typename ERROR::operator_< minus_equal_id >::template _is_invalid_for_types_<P1, P2> >::check(); } @@ -227,7 +239,7 @@ void operator - (const Generalized_Point<P>& rhs) { mlc::abort_<P, - ERROR::operator_< uminus_id >::template _is_invalid_for_<P> + typename ERROR::operator_< uminus_id >::template _is_invalid_for_<P> >::check(); } @@ -260,4 +272,5 @@ } // end of namespace oln + #endif // ! OLN_CORE_CONCEPT_POINT_HH Index: oln/core/concept/literal.hh --- oln/core/concept/literal.hh (revision 0) +++ oln/core/concept/literal.hh (revision 0) @@ -0,0 +1,88 @@ +// 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_CONCEPT_LITERAL_HH +# define OLN_CORE_CONCEPT_LITERAL_HH + +# include <oln/core/concept/operators.hh> + + +namespace oln +{ + + /// Concept-class "Literal". + + template <typename Exact> + struct Literal : public Any<Exact> + { + typedef Literal<void> category; + protected: + Literal(); + }; + + + // Default. + + template <typename L, typename R> + oln_minus_trait(R, R) + operator - (const Literal<L>& lhs, const Any<R>& rhs); + + template <typename L, typename R> + oln_plus_trait(R, R) + operator + (const Literal<L>& lhs, const Any<R>& rhs); + + + +# ifndef OLN_INCLUDE_ONLY + + template <typename Exact> + Literal<Exact>::Literal() + { + } + + template <typename L, typename R> + oln_minus_trait(R, R) + operator - (const Literal<L>& lhs, const Any<R>& rhs) + { + oln_minus_trait(R, R) tmp = exact(lhs).operator R() - exact(rhs); + return tmp; + } + + template <typename L, typename R> + oln_plus_trait(R, R) + operator + (const Literal<L>& lhs, const Any<R>& rhs) + { + oln_plus_trait(R, R) tmp = exact(lhs).operator R() + exact(rhs); + return tmp; + } + +# endif // ! OLN_INCLUDE_ONLY + +} // end of namespace oln + + +#endif // ! OLN_CORE_CONCEPT_LITERAL_HH Index: oln/core/concept/dpoint.hh --- oln/core/concept/dpoint.hh (revision 968) +++ oln/core/concept/dpoint.hh (working copy) @@ -59,6 +59,8 @@ enum { n = mlc_value(dim) }; + void assign_(zero_t); + protected: Dpoint(); @@ -144,6 +146,12 @@ // mlc::assert_defined_< oln_vtype(Exact, dim) >::check(); } + template <typename Exact> + void + Dpoint<Exact>::assign_(zero_t) + { + exact(this)->vec().set_all(0); + } // Operators on Dpoints. @@ -156,7 +164,7 @@ template <typename D1, typename D2> bool operator < (const Dpoint<D1>& lhs, const Dpoint<D2>& rhs) { - return exact(lhs).vec() < exact(rhs).vec(); + return xtd::lexi_less(exact(lhs).vec(), exact(rhs).vec()); } template <typename D, typename D2> @@ -230,7 +238,7 @@ void operator + (const Dpoint<D>& lhs, const Generalized_Point<P>& rhs) { mlc::abort_<D, - ERROR::operator_< plus_id >::template _is_invalid_for_types_<D, P> + typename ERROR::operator_< plus_id >::template _is_invalid_for_types_<D, P> >::check(); } @@ -238,7 +246,7 @@ void operator - (const Dpoint<D>& lhs, const Generalized_Point<P>& rhs) { mlc::abort_<D, - ERROR::operator_< minus_id >::template _is_invalid_for_types_<D, P> + typename ERROR::operator_< minus_id >::template _is_invalid_for_types_<D, P> >::check(); } Index: oln/core/concept/window.hh --- oln/core/concept/window.hh (revision 968) +++ oln/core/concept/window.hh (working copy) @@ -47,7 +47,6 @@ stc_typename(fwd_qiter); stc_typename(bkd_qiter); - Exact op_unary_minus_() const; unsigned size() const; protected: @@ -56,6 +55,9 @@ }; // end of oln::Window<Exact> + template <typename W> + W operator - (const Window<W>& rhs); + # ifndef OLN_INCLUDE_ONLY @@ -65,19 +67,18 @@ } template <typename Exact> - Exact - Window<Exact>::op_unary_minus_() const - { - return exact(this)->impl_op_unary_minus_(); - } - - template <typename Exact> unsigned Window<Exact>::size() const { return exact(this)->impl_size(); } + template <typename W> + W operator - (const Window<W>& rhs) + { + return exact(rhs).impl_op_unary_minus_(); + } + # endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/concept/operators.hh --- oln/core/concept/operators.hh (revision 968) +++ oln/core/concept/operators.hh (working copy) @@ -70,12 +70,6 @@ - - // FIXME: Add: template <typename T> T operator - (const Any<T>& rhs); - - - - namespace ERROR { @@ -184,7 +178,7 @@ void operator = (const Any<L>& lhs, const Any<R>& rhs) { mlc::abort_<L, - ERROR::operator_< eq_id >::template _is_missing_for_types_<L, R> + typename ERROR::operator_< eq_id >::_is_missing_for_types_<L, R> >::check(); } @@ -193,7 +187,7 @@ void operator < (const Any<L>& lhs, const Any<R>& rhs) { mlc::abort_<L, - ERROR::operator_< less_id >::template _is_missing_for_types_<L, R> + typename ERROR::operator_< less_id >::template _is_missing_for_types_<L, R> >::check(); } @@ -202,7 +196,7 @@ void operator += (const Any<L>& lhs, const Any<R>& rhs) { mlc::abort_<L, - ERROR::operator_< plus_equal_id >::template _is_missing_for_types_<L, R> + typename ERROR::operator_< plus_equal_id >::template _is_missing_for_types_<L, R> >::check(); } @@ -211,7 +205,7 @@ void operator -= (const Any<L>& lhs, const Any<R>& rhs) { mlc::abort_<L, - ERROR::operator_< minus_equal_id >::template _is_missing_for_types_<L, R> + typename ERROR::operator_< minus_equal_id >::template _is_missing_for_types_<L, R> >::check(); } @@ -220,7 +214,7 @@ void operator %= (const Any<L>& lhs, const Any<R>& rhs) { mlc::abort_<L, - ERROR::operator_< modulus_equal_id >::template _is_missing_for_types_<L, R> + typename ERROR::operator_< modulus_equal_id >::template _is_missing_for_types_<L, R> >::check(); } @@ -229,7 +223,7 @@ void operator - (const Any<T>& rhs) { mlc::abort_<T, - ERROR::operator_< uminus_id >::template _is_missing_for_<T> + typename ERROR::operator_< uminus_id >::template _is_missing_for_<T> >::check(); } Index: oln/core/internal/dpoint_base.hh --- oln/core/internal/dpoint_base.hh (revision 968) +++ oln/core/internal/dpoint_base.hh (working copy) @@ -85,15 +85,7 @@ coord operator[](unsigned i) const; coord& operator[](unsigned i); - bool impl_op_equal_(const Exact& rhs) const; - - bool impl_op_less_(const Exact& rhs) const; - - Exact& impl_op_plus_equal_(const Exact& rhs); - Exact& impl_op_minus_equal_(const Exact& rhs); - Exact& impl_op_mod_equal_(const Exact& rhs); - - Exact impl_op_unary_minus_() const; + Exact& impl_op_mod_equal_(const Exact& rhs); // FIXME: Remove HERE typedef xtd::vec<n, coord> vec_t; const vec_t& vec() const; @@ -126,32 +118,6 @@ } template <typename Exact> - bool dpoint_base_<Exact>::impl_op_equal_(const Exact& rhs) const - { - return v_ = rhs.v_; - } - - template <typename Exact> - bool dpoint_base_<Exact>::impl_op_less_(const Exact& rhs) const - { - return xtd::lexi_less(v_, rhs.v_); - } - - template <typename Exact> - Exact& dpoint_base_<Exact>::impl_op_plus_equal_(const Exact& rhs) - { - v_ += rhs.v_; - return exact(*this); - } - - template <typename Exact> - Exact& dpoint_base_<Exact>::impl_op_minus_equal_(const Exact& rhs) - { - v_ -= rhs.v_; - return exact(*this); - } - - template <typename Exact> Exact& dpoint_base_<Exact>::impl_op_mod_equal_(const Exact& rhs) { for (unsigned i = 0; i < n; ++i) @@ -164,14 +130,6 @@ } template <typename Exact> - Exact dpoint_base_<Exact>::impl_op_unary_minus_() const - { - Exact tmp; - tmp.v_ = - v_; - return tmp; - } - - template <typename Exact> const typename dpoint_base_<Exact>::vec_t& dpoint_base_<Exact>::vec() const { Index: oln/draw/bresenham.hh --- oln/draw/bresenham.hh (revision 968) +++ oln/draw/bresenham.hh (working copy) @@ -61,7 +61,7 @@ const oln_point(I)& begin, const oln_point(I)& end, const oln_value(I)& value) { - level::paste(literal(value) / line2d(begin, end), + level::paste(make_value(value) / line2d(begin, end), inplace(in_out)); } Index: oln/morpho/elementary_gradient.hh --- oln/morpho/elementary_gradient.hh (revision 968) +++ oln/morpho/elementary_gradient.hh (working copy) @@ -28,6 +28,7 @@ #ifndef OLN_MORPHO_ELEMENTARY_GRADIENT_HH # define OLN_MORPHO_ELEMENTARY_GRADIENT_HH +# include <oln/core/gen/zero.hh> # include <oln/morpho/elementary_erosion.hh> # include <oln/morpho/elementary_dilation.hh> # include <oln/arith/minus.hh> @@ -75,7 +76,7 @@ elementary_gradient(const Image_with_Nbh<I>& input) { oln_plain(I) output = impl::elementary_gradient_(exact(input)); - postcondition(output >= literal(0)); + postcondition(output >= zero); return output; } Index: oln/morpho/elementary_gradient_external.hh --- oln/morpho/elementary_gradient_external.hh (revision 968) +++ oln/morpho/elementary_gradient_external.hh (working copy) @@ -28,6 +28,7 @@ #ifndef OLN_MORPHO_EXTERNAL_GRADIENT_HH # define OLN_MORPHO_EXTERNAL_GRADIENT_HH +# include <oln/core/gen/zero.hh> # include <oln/morpho/elementary_dilation.hh> # include <oln/arith/minus.hh> @@ -73,7 +74,7 @@ elementary_gradient_external(const Image_with_Nbh<I>& input) { oln_plain(I) output = impl::elementary_gradient_external_(exact(input)); - postcondition(output >= literal(0)); + postcondition(output >= zero); return output; } Index: oln/morpho/gradient_internal.hh --- oln/morpho/gradient_internal.hh (revision 968) +++ oln/morpho/gradient_internal.hh (working copy) @@ -28,6 +28,7 @@ #ifndef OLN_MORPHO_GRADIENT_INTERNAL_HH # define OLN_MORPHO_GRADIENT_INTERNAL_HH +# include <oln/core/gen/zero.hh> # include <oln/morpho/erosion.hh> # include <oln/arith/minus.hh> @@ -72,7 +73,7 @@ gradient_internal(const Image<I>& input, const Window<W>& win) { oln_plain(I) output = impl::gradient_internal_(exact(input), exact(win)); - postcondition(output >= literal(0)); + postcondition(output >= zero); return output; } Index: oln/morpho/top_hat_black.hh --- oln/morpho/top_hat_black.hh (revision 968) +++ oln/morpho/top_hat_black.hh (working copy) @@ -28,6 +28,7 @@ #ifndef OLN_MORPHO_TOP_HAT_BLACK_HH # define OLN_MORPHO_TOP_HAT_BLACK_HH +# include <oln/core/gen/zero.hh> # include <oln/morpho/opening.hh> # include <oln/morpho/closing.hh> # include <oln/arith/minus.hh> @@ -74,7 +75,7 @@ top_hat_black(const Image<I>& input, const Window<W>& win) { oln_plain(I) output = impl::top_hat_black_(exact(input), exact(win)); - postcondition(output >= literal(0)); + postcondition(output >= zero); return output; } Index: oln/morpho/gradient.hh --- oln/morpho/gradient.hh (revision 968) +++ oln/morpho/gradient.hh (working copy) @@ -28,6 +28,7 @@ #ifndef OLN_MORPHO_GRADIENT_HH # define OLN_MORPHO_GRADIENT_HH +# include <oln/core/gen/zero.hh> # include <oln/morpho/erosion.hh> # include <oln/morpho/dilation.hh> # include <oln/arith/minus.hh> @@ -73,7 +74,7 @@ gradient(const Image<I>& input, const Window<W>& win) { oln_plain(I) output = impl::gradient_(exact(input), exact(win)); - postcondition(output >= literal(0)); + postcondition(output >= zero); return output; } Index: oln/morpho/top_hat_white.hh --- oln/morpho/top_hat_white.hh (revision 968) +++ oln/morpho/top_hat_white.hh (working copy) @@ -28,6 +28,7 @@ #ifndef OLN_MORPHO_TOP_HAT_WHITE_HH # define OLN_MORPHO_TOP_HAT_WHITE_HH +# include <oln/core/gen/zero.hh> # include <oln/morpho/opening.hh> # include <oln/morpho/closing.hh> # include <oln/arith/minus.hh> @@ -73,7 +74,7 @@ top_hat_white(const Image<I>& input, const Window<W>& win) { oln_plain(I) output = impl::top_hat_white_(exact(input), exact(win)); - postcondition(output >= literal(0)); + postcondition(output >= zero); return output; } Index: oln/morpho/gradient_external.hh --- oln/morpho/gradient_external.hh (revision 968) +++ oln/morpho/gradient_external.hh (working copy) @@ -28,6 +28,7 @@ #ifndef OLN_MORPHO_GRADIENT_EXTERNAL_HH # define OLN_MORPHO_GRADIENT_EXTERNAL_HH +# include <oln/core/gen/zero.hh> # include <oln/morpho/dilation.hh> # include <oln/arith/minus.hh> @@ -71,7 +72,7 @@ gradient_external(const Image<I>& input, const Window<W>& win) { oln_plain(I) output = impl::gradient_external_(exact(input), exact(win)); - postcondition(output >= literal(0)); + postcondition(output >= zero); return output; } Index: oln/morpho/elementary_gradient_internal.hh --- oln/morpho/elementary_gradient_internal.hh (revision 968) +++ oln/morpho/elementary_gradient_internal.hh (working copy) @@ -28,6 +28,7 @@ #ifndef OLN_MORPHO_ELEMENTARY_GRADIENT_INTERNAL_HH # define OLN_MORPHO_ELEMENTARY_GRADIENT_INTERNAL_HH +# include <oln/core/gen/zero.hh> # include <oln/morpho/elementary_erosion.hh> # include <oln/arith/minus.hh> @@ -73,7 +74,7 @@ elementary_gradient_internal(const Image_with_Nbh<I>& input) { oln_plain(I) output = impl::elementary_gradient_internal_(exact(input)); - postcondition(output >= literal(0)); + postcondition(output >= zero); return output; } Index: oln/level/compare.hh --- oln/level/compare.hh (revision 968) +++ oln/level/compare.hh (working copy) @@ -30,7 +30,6 @@ # 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". @@ -45,19 +44,19 @@ 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); + bool operator = (const Image<I>& lhs, const 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); + bool operator < (const Image<I>& lhs, const 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); + bool operator <= (const Image<I>& lhs, const oln_value(I)& val); // FIXME: is-it a good idea to have "ima = lit"? @@ -92,7 +91,7 @@ // Generic version. template <typename I> - bool op_eq_(const Image<I>& lhs, const literal_<oln_value(I)>& val) + bool op_eq_(const Image<I>& lhs, const oln_value(I)& val) { oln_piter(I) p(lhs.points()); for_all(p) @@ -125,7 +124,7 @@ // Generic version. template <typename I> - bool op_less_(const Image<I>& lhs, const literal_<oln_value(I)>& val) + bool op_less_(const Image<I>& lhs, const oln_value(I)& val) { oln_piter(I) p(lhs.points()); for_all(p) @@ -158,7 +157,7 @@ // Generic version. template <typename I> - bool op_leq_(const Image<I>& lhs, const literal_<oln_value(I)>& val) + bool op_leq_(const Image<I>& lhs, const oln_value(I)& val) { oln_piter(I) p(lhs.points()); for_all(p) @@ -181,7 +180,7 @@ } template <typename I> - bool operator = (const Image<I>& lhs, const literal_<oln_value(I)>& val) + bool operator = (const Image<I>& lhs, const oln_value(I)& val) { return impl::op_eq_(exact(lhs), val); } @@ -194,7 +193,7 @@ } template <typename I> - bool operator < (const Image<I>& lhs, const literal_<oln_value(I)>& val) + bool operator < (const Image<I>& lhs, const oln_value(I)& val) { return impl::op_less_(exact(lhs), val); } @@ -207,7 +206,7 @@ } template <typename I> - bool operator <= (const Image<I>& lhs, const literal_<oln_value(I)>& val) + bool operator <= (const Image<I>& lhs, const oln_value(I)& val) { return impl::op_leq_(exact(lhs), val); } Index: oln/linear/convolution.hh --- oln/linear/convolution.hh (revision 968) +++ oln/linear/convolution.hh (working copy) @@ -30,9 +30,9 @@ # include <oln/core/concept/image.hh> # include <oln/core/concept/weighted_window.hh> - # include <oln/core/internal/f_weighted_window.hh> # include <oln/core/internal/f_ch_value.hh> +# include <oln/convert/to_dpoint.hh> namespace oln @@ -69,10 +69,6 @@ { oln_plain_value(I, V) output; prepare(output, with, f); - - oln_point(I) O; O.set_all(0); - oln_point(I) p_q; - oln_piter(I) p(f.points()); oln_piter(J) q(g.points()); for_all(p) @@ -80,10 +76,9 @@ V val = 0; for_all(q) { - oln_dpoint(I) dp = O - oln_point(I)(q); // FIXME: to_point - p_q = oln_point(I)(p) + dp; // FIXME: to_point + oln_point(I) p_q = p - convert::to_dpoint(q); if (f.has(p_q)) - val += g(q) * f(p_q); // FIXME: f(p + (O - q)); + val += g(q) * f(p_q); } output(p) = val; } @@ -102,7 +97,7 @@ V val = 0; for (unsigned i = 0; i < w_win.size(); ++i) { - oln_point(I) q = oln_point(I)(p) + w_win.dp(i); // FIXME: to_point + oln_point(I) q = p + w_win.dp(i); if (input.has(q)) val += w_win.w(i) * input(q); } Index: oln/linear/mean.hh --- oln/linear/mean.hh (revision 968) +++ oln/linear/mean.hh (working copy) @@ -28,9 +28,9 @@ #ifndef OLN_LINEAR_MEAN_HH # define OLN_LINEAR_MEAN_HH -# include <oln/core/gen/literal.hh> -# include <oln/convert/to_weighted_window.hh> # include <oln/linear/convolution.hh> +# include <oln/convert/to_weighted_window.hh> +# include <oln/core/gen/constant.hh> namespace oln @@ -57,7 +57,7 @@ oln_plain_value(I, V) mean_(const Image<I>& f, const Window<W>& win) { - lit_p2v_<oln_point(I), float> g(1.f / win.size()); + constant_p2v_<oln_point(I), float> g(1.f / win.size()); return linear::convolution<V>(f, convert::to_weighted_window(g, win)); } Index: oln/value/builtin.hh --- oln/value/builtin.hh (revision 968) +++ oln/value/builtin.hh (working copy) @@ -72,7 +72,13 @@ - // int, float, ... + // unsigned, int, float, double,... + + template <> + struct super_trait_< unsigned > + { + typedef internal::builtin_base<unsigned> ret; + }; template <> struct super_trait_< int > @@ -86,6 +92,12 @@ typedef internal::builtin_base<float> ret; }; + template <> + struct super_trait_< double > + { + typedef internal::builtin_base<double> ret; + }; + } // end of namespace oln Index: oln/value/builtin_traits.hh --- oln/value/builtin_traits.hh (revision 968) +++ oln/value/builtin_traits.hh (working copy) @@ -42,6 +42,12 @@ }; template <typename Op> + struct set_trait_< Value, double, Op, Value, double > + { + typedef double ret; + }; + + template <typename Op> struct set_trait_< Value, int, Op, Value, double > { typedef double ret;