1287: Clean value traits.

https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Clean value traits. Augment metal. * mln/metal/int.hh: New. * mln/metal/math: New directory. (math): New namespace. * mln/metal/math.hh: Rename as... * mln/metal/math/pow.hh: ...this. (pow): Move into math:: and rename as... (pow_int): ...this. (pow): New; work on metal::int_. * mln/metal/math/all.hh: New. * mln/metal/bool.hh (value): Strengthen type. * mln/metal/all.hh: Update. * mln/metal/is.hh (helper_is_): Change selector arg from & to *; that allows for this tool to work on non-POD types. * tests/metal_pow.cc: New. Clean value traits. * mln/trait/image_from_mesh.hh: Add FIXMEs. * mln/trait/images.hh: Fix file doc. * mln/trait/value_.hh: Augment. * mln/trait/value/quant.hh: New. * mln/trait/value/all.hh: New. * mln/trait/value/print.hh: Update. * mln/trait/value/nature.hh (unknown): New. * mln/value/graylevel.hh, * mln/value/float01_.hh, * mln/value/builtin.hh, * mln/value/int_s.hh, * mln/value/int_u.hh, * mln/value/int_u_sat.hh, * mln/value/props.hh, * mln/value/rgb.hh, * mln/value/rgb8_non_templated.hh, * mln/value/label.hh: Update. Misc. * mln/fun/x2x/bijective_tr.hh: Fix. * mln/morpho/erosion.hh (erosion): New overload with output as return. * tests/morpho_erosion.cc: Update. mln/fun/x2x/bijective_tr.hh | 21 +++++++-- mln/metal/all.hh | 4 - mln/metal/bool.hh | 5 ++ mln/metal/int.hh | 72 +++++++++++++++++++++++++++++++ mln/metal/is.hh | 7 +-- mln/metal/math/all.hh | 57 ++++++++++++++++++++++++ mln/metal/math/pow.hh | 66 ++++++++++++++++++++++++---- mln/morpho/erosion.hh | 18 +++++++ mln/trait/image_from_mesh.hh | 5 ++ mln/trait/images.hh | 2 mln/trait/value/all.hh | 58 +++++++++++++++++++++++++ mln/trait/value/nature.hh | 2 mln/trait/value/print.hh | 15 +++++- mln/trait/value/quant.hh | 62 ++++++++++++++++++++++++++ mln/trait/value_.hh | 65 +++++++++++++++++++++++----- mln/value/builtin.hh | 92 ++++++++++++++++++++++++++++++++++++++++ mln/value/float01_.hh | 4 - mln/value/graylevel.hh | 4 - mln/value/int_s.hh | 10 ++-- mln/value/int_u.hh | 11 ++-- mln/value/int_u_sat.hh | 4 - mln/value/label.hh | 6 +- mln/value/props.hh | 7 +++ mln/value/rgb.hh | 2 mln/value/rgb8_non_templated.hh | 2 tests/metal_pow.cc | 47 ++++++++++++++++++++ tests/morpho_erosion.cc | 7 +-- 27 files changed, 598 insertions(+), 57 deletions(-) Index: tests/metal_pow.cc --- tests/metal_pow.cc (revision 0) +++ tests/metal_pow.cc (revision 0) @@ -0,0 +1,47 @@ +// 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. + +/*! \file tests/metal_pow.cc + * + * \brief Test on mln::metal::math::pow. + */ + +#include <iostream> +#include <mln/core/contract.hh> +#include <mln/metal/math/pow.hh> + + +int main() +{ + using namespace mln; + using namespace mln::metal; + + int res = metal::math::pow_int<2,3>::value; + mln_assertion(res = 8); + + std::cout << metal::math::pow< int_<2>, int_<3> >::ret().name() << std::endl; +} Index: tests/morpho_erosion.cc --- tests/morpho_erosion.cc (revision 1286) +++ tests/morpho_erosion.cc (working copy) @@ -69,10 +69,9 @@ } { - win::octagon2d oct(31); - image2d<int_u8> out(lena.domain()); - morpho::erosion(lena, oct, out); - io::pgm::save(out, "out2.pgm"); + io::pgm::save(morpho::erosion(lena, + win::octagon2d(31)), + "out2.pgm"); } // { Index: mln/trait/image_from_mesh.hh --- mln/trait/image_from_mesh.hh (revision 1286) +++ mln/trait/image_from_mesh.hh (working copy) @@ -74,6 +74,11 @@ }; + // FIXME: Return other image types than imagend when size trait is not regular... + + // FIXME: Add cases when the mesh is not a grid... + + } // end of namespace mln::trait } // end of namespace mln Index: mln/trait/images.hh --- mln/trait/images.hh (revision 1286) +++ mln/trait/images.hh (working copy) @@ -30,7 +30,7 @@ /*! \file mln/trait/images.hh * - * \brief Forward declarations of all image types. + * \brief Some base trait types for images. * * \todo Split this file into many. */ Index: mln/trait/value_.hh --- mln/trait/value_.hh (revision 1286) +++ mln/trait/value_.hh (working copy) @@ -28,24 +28,31 @@ #ifndef MLN_TRAIT_VALUE__HH # define MLN_TRAIT_VALUE__HH -/*! \file mln/trait/images.hh +/*! \file mln/trait/value_.hh * - * \brief Forward declarations of all image types. - * - * \todo Split this file into many. + * \brief Some base trait types for value types. */ # include <iostream> # include <string> -# include <mln/trait/undef.hh> +# include <mln/metal/math/pow.hh> +# include <mln/metal/if.hh> -# include <mln/trait/value/nature.hh> -# include <mln/trait/value/kind.hh> +# include <mln/trait/value/all.hh> -# define mln_trait_value_nature(I) typename mln::trait::value_< V >::nature +# define mln_trait_value_nature(V) typename mln::trait::value_< V >::nature # define mln_trait_value_kind(V) typename mln::trait::value_< V >::kind +# define mln_trait_value_quant(V) typename mln::trait::value_< V >::quant +# define mln_trait_value_card(V) typename mln::trait::value_< V >::card + + +# define mln_value_quant_from_card(C) \ + mlc_if(mln::metal::bool_<( C::value > 65536 || C::value = 0 )>, \ + mln::trait::value::quant::high, \ + mln::trait::value::quant::low) + namespace mln @@ -55,17 +62,55 @@ { - template <typename V> struct undefined_value_ { typedef undef nature; typedef undef kind; + typedef undef quant; + typedef undef card; + typedef undef sum; + // FIXME: signed or not, with zero or not, centered or not, etc. + }; + + + struct default_value_ + { + typedef trait::value::nature::unknown nature; + typedef trait::value::kind::data kind; + typedef trait::value::quant::high quant; + typedef metal::int_<0> card; + typedef undef sum; }; template <typename V> - struct value_ : undefined_value_<V> + struct value_ : undefined_value_ + { + }; + + + template <unsigned n_bits, int card_ = 1> + struct value_integer_ + { + typedef metal::math::pow_int<2, n_bits> pow_; + + typedef metal::int_<n_bits> nbits; + typedef trait::value::nature::integer nature; + typedef trait::value::kind::data kind; + typedef metal::int_<pow_::value> card; + typedef mln_value_quant_from_card(card) quant; + typedef float sum; + }; + + template <unsigned n_bits> + struct value_integer_< n_bits, 0 > { + typedef metal::int_<n_bits> nbits; + typedef trait::value::nature::integer nature; + typedef value::kind::data kind; + typedef metal::int_<0> card; + typedef value::quant::high quant; + typedef float sum; }; Index: mln/trait/value/quant.hh --- mln/trait/value/quant.hh (revision 0) +++ mln/trait/value/quant.hh (revision 0) @@ -0,0 +1,62 @@ +// 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 MLN_TRAIT_VALUE_QUANT_HH +# define MLN_TRAIT_VALUE_QUANT_HH + +/*! \file mln/trait/value/quant.hh + * + * \brief Quantification of values (for use in images). + */ + +# include <string> + + +namespace mln +{ + + namespace trait + { + + namespace value + { + + struct quant + { + struct any {}; + struct low : any { std::string name() const { return "quant::low"; } }; + struct high : any { std::string name() const { return "quant::high"; } }; + }; + + } // end of namespace mln::trait::quant + + } // end of namespace mln::trait + +} // end of namespace mln + + +#endif // ! MLN_TRAIT_VALUE_QUANT_HH Index: mln/trait/value/all.hh --- mln/trait/value/all.hh (revision 0) +++ mln/trait/value/all.hh (revision 0) @@ -0,0 +1,58 @@ +// 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 MLN_TRAIT_VALUE_ALL_HH +# define MLN_TRAIT_VALUE_ALL_HH + +/*! \file mln/trait/value/all.hh + * + * \brief FIXME + */ + + +namespace mln +{ + + namespace trait + { + + /// FIXME: Doc! + namespace value {} + + } // end of namespace mln::trait + +} // end of namespace mln + + + +# include <mln/trait/undef.hh> +# include <mln/trait/value/nature.hh> +# include <mln/trait/value/kind.hh> +# include <mln/trait/value/quant.hh> + + +#endif // ! MLN_TRAIT_VALUE_ALL_HH Index: mln/trait/value/print.hh --- mln/trait/value/print.hh (revision 1286) +++ mln/trait/value/print.hh (working copy) @@ -55,17 +55,28 @@ template <typename V> void print(std::ostream& ostr); + template <typename V> + void print(const Value<V>& v, std::ostream& ostr); + # ifndef MLN_INCLUDE_ONLY template <typename V> void print(std::ostream& ostr) { - mlc_is_a(V, Value)::check(); + mlc_is_a(V, Value)::check(); // FIXME: What about built-ins? typedef mln::trait::value_<V> the; ostr << "{ " << typename the::nature().name() << ", " - << typename the::kind() .name() << " }" << std::endl; + << typename the::kind() .name() << ", " + << typename the::quant() .name() << ", " + << typename the::card() .name() << " }" << std::endl; + } + + template <typename V> + void print(const Value<V>&, std::ostream& ostr) + { + print<V>(ostr); } # endif // ! MLN_INCLUDE_ONLY Index: mln/trait/value/nature.hh --- mln/trait/value/nature.hh (revision 1286) +++ mln/trait/value/nature.hh (working copy) @@ -56,6 +56,8 @@ struct vectorial : any { std::string name() const { return "nature::vectorial"; } }; struct symbolic : any { std::string name() const { return "nature::symbolic"; } }; struct structured : any { std::string name() const { return "nature::structured"; } }; + + struct unknown : any { std::string name() const { return "nature::unknown"; } }; }; } // end of namespace mln::trait::value Index: mln/metal/int.hh --- mln/metal/int.hh (revision 0) +++ mln/metal/int.hh (revision 0) @@ -0,0 +1,72 @@ +// 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 MLN_METAL_INT_HH +# define MLN_METAL_INT_HH + +/*! \file mln/metal/int.hh + * + * \brief Definition of an integer value type. + */ + +# include <string> +# include <sstream> + + +namespace mln +{ + + namespace metal + { + + /// "int" type. + template <int i> + struct int_ + { + static const int value = i; + std::string name() const; + }; + + +# ifndef MLN_INCLUDE_ONLY + + template <int i> + std::string int_<i>::name() const + { + std::ostringstream o; + o << "metal::int_<" << i << ">"; + return o.str(); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::metal + +} // end of namespace mln + + +#endif // ! MLN_METAL_INT_HH Index: mln/metal/math/pow.hh --- mln/metal/math/pow.hh (revision 0) +++ mln/metal/math/pow.hh (working copy) @@ -25,14 +25,17 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_METAL_MATH_HH -# define MLN_METAL_MATH_HH +#ifndef MLN_METAL_MATH_POW_HH +# define MLN_METAL_MATH_POW_HH -/*! \file mln/metal/math.hh +/*! \file mln/metal/math/pow.hh * * \brief Definition of some mathematical static functions. */ +# include <mln/metal/bool.hh> +# include <mln/metal/int.hh> + namespace mln { @@ -40,24 +43,69 @@ namespace metal { - // pow<x, n> + namespace math + { + + // pow_int<x, n> - template <int x, unsigned n> - struct pow + namespace impl { - enum { value = x * pow<x, n-1>::value }; + + template <int x, int n> + struct pow_int_ + { + enum { value = x * pow_int_<x, n-1>::value }; }; template <int x> - struct pow< x, 0 > + struct pow_int_< x, 0 > { enum { value = 1 }; }; + template <> + struct pow_int_< 0, 0 >; + + + // Entry. + + template <int x, int n, bool b> + struct pow_int_if_ : pow_int_<x, n> + { + }; + + template <int x, int n> + struct pow_int_if_< x, n, false > + { + }; + + } + + template <int x, int n> + struct pow_int : impl::pow_int_if_< x, n, + (n >= 0 && ! (x = 0 && n = 0)) > + { + }; + + + // pow<X, N> + + template <typename X, typename N> + struct pow; + + template <int x, int n> + struct pow< int_<x>, int_<n> > : pow_int<x, n> + { + typedef pow_int<x, n> super_; + typedef int_<super_::value> ret; + }; + + + } // end of namespace mln::metal::math } // end of namespace mln::metal } // end of namespace mln -#endif // ! MLN_METAL_MATH_HH +#endif // ! MLN_METAL_MATH_POW_HH Index: mln/metal/math/all.hh --- mln/metal/math/all.hh (revision 0) +++ mln/metal/math/all.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 MLN_METAL_MATH_ALL_HH +# define MLN_METAL_MATH_ALL_HH + +/*! \file mln/metal/math/all.hh + * + * \brief Include all static mathematical functions. + */ + + +namespace mln +{ + + namespace metal + { + + /// Namespace of static mathematical functions. + namespace math {} + + } // end of namespace mln::metal + +} // end of namespace mln + + + +# include <mln/metal/math/pow.hh> +// ... + + + +#endif // ! MLN_METAL_MATH_ALL_HH Index: mln/metal/bool.hh --- mln/metal/bool.hh (revision 1286) +++ mln/metal/bool.hh (working copy) @@ -33,6 +33,8 @@ * \brief Definition of a Boolean value type. */ +# include <string> + namespace mln { @@ -43,6 +45,7 @@ // Fwd decl. template <bool b> struct bool_; + /// "true" type. template <> struct bool_< true > @@ -50,6 +53,7 @@ static const bool value = true; typedef bool_<true> eval; static void check(); + std::string name() const { return "true"; } }; typedef bool_<true> true_; @@ -62,6 +66,7 @@ static const bool value = false; typedef bool_<false> eval; static void check_not(); + std::string name() const { return "false"; } }; typedef bool_<false> false_; Index: mln/metal/all.hh --- mln/metal/all.hh (revision 1286) +++ mln/metal/all.hh (working copy) @@ -55,8 +55,6 @@ # include <mln/metal/is_a.hh> # include <mln/metal/goes_to.hh> -# include <mln/metal/math.hh> - # include <mln/metal/const.hh> # include <mln/metal/unconst.hh> # include <mln/metal/is_const.hh> @@ -70,6 +68,8 @@ # include <mln/metal/vec.hh> # include <mln/metal/mat.hh> +# include <mln/metal/math/all.hh> + // FIXME: Remove the following includes below! # include <mln/metal/same_coord.hh> # include <mln/metal/same_point.hh> Index: mln/metal/is.hh --- mln/metal/is.hh (revision 1286) +++ mln/metal/is.hh (working copy) @@ -52,7 +52,7 @@ template <typename T, typename U> struct helper_is_ { - static yes_ selector(U&); + static yes_ selector(U*const); static no_ selector(...); }; @@ -65,10 +65,11 @@ * FIXME: Doc! */ template <typename T, typename U> - struct is : bool_<( sizeof(internal::helper_is_<T, U>::selector(*internal::make_<T>::ptr())) + struct is : bool_<( sizeof(internal::helper_is_<T, U>::selector(internal::make_<T>::ptr())) = sizeof(internal::yes_) )> - {}; + { + }; template <typename T, typename U> struct is< T*, U* > : is<T, U>::eval Index: mln/value/graylevel.hh --- mln/value/graylevel.hh (revision 1286) +++ mln/value/graylevel.hh (working copy) @@ -31,7 +31,7 @@ # include <iostream> # include <mln/core/contract.hh> -# include <mln/metal/math.hh> +# include <mln/metal/math/pow.hh> # include <mln/metal/bexpr.hh> # include <mln/value/int_u.hh> @@ -76,7 +76,7 @@ template <unsigned n> struct props< graylevel<n> > { - static const std::size_t card_ = metal::pow<2, n>::value; + static const std::size_t card_ = metal::math::pow_int<2, n>::value; static const graylevel<n> min() { return 0; } static const graylevel<n> max() { return card_ - 1; } static const unsigned nbits = n; Index: mln/value/float01_.hh --- mln/value/float01_.hh (revision 1286) +++ mln/value/float01_.hh (working copy) @@ -30,7 +30,7 @@ # include <iostream> # include <mln/core/contract.hh> -# include <mln/metal/math.hh> +# include <mln/metal/math/pow.hh> # include <mln/metal/bexpr.hh> # include <mln/value/int_u.hh> @@ -101,7 +101,7 @@ template <unsigned n> struct props< float01_<n> > { - static const std::size_t card_ = metal::pow<2, n>::value; + static const std::size_t card_ = metal::math::pow_int<2, n>::value; static const float min() { return 0.f; } static const float max() { return 1.f; } static const unsigned nbits = n; Index: mln/value/builtin.hh --- mln/value/builtin.hh (revision 1286) +++ mln/value/builtin.hh (working copy) @@ -29,10 +29,13 @@ # define MLN_VALUE_BUILTIN_HH /*! \file mln/value/builtin.hh + * * \brief Some definitions about builtins. */ # include <mln/core/category.hh> +# include <mln/metal/int.hh> +# include <mln/trait/value_.hh> namespace mln @@ -68,6 +71,95 @@ // FIXME: ... + namespace trait + { + + // Fwd decl. + template <typename V> struct value_; + + + // Bool. + + template <> + struct value_< bool> + { + typedef metal::int_<1> nbits; + typedef value::nature::symbolic nature; + typedef value::kind::binary kind; + typedef value::quant::low quant; + typedef metal::int_<2> card; + }; + + + // Integer. + + template <> + struct value_< unsigned char > : value_integer_<8> + { + }; + + template <> + struct value_< signed char > : value_integer_<8> + { + }; + + template <> + struct value_< unsigned short > : value_integer_<16> + { + }; + + template <> + struct value_< signed short > : value_integer_<16> + { + }; + + template <> + struct value_< unsigned int > : value_integer_<8 * sizeof(unsigned int), 0> + { + }; + + template <> + struct value_< signed int > : value_integer_<8 * sizeof(signed int), 0> + { + }; + + template <> + struct value_< unsigned long int > : value_integer_<8 * sizeof(unsigned long), 0> + { + }; + + template <> + struct value_< signed long int > : value_integer_<8 * sizeof(signed long), 0> + { + }; + + + // Floating. + + template <> + struct value_< float > + { + typedef metal::int_<8*sizeof(float)> nbits; + typedef value::nature::floating nature; + typedef value::kind::data kind; + typedef metal::int_<0> card; + typedef value::quant::high quant; + typedef float sum; + }; + + template <> + struct value_< double > + { + typedef metal::int_<8*sizeof(double)> nbits; + typedef value::nature::floating nature; + typedef value::kind::data kind; + typedef metal::int_<0> card; + typedef value::quant::high quant; + typedef double sum; + }; + + } // end of namespace mln::trait + } // end of namespace mln Index: mln/value/int_s.hh --- mln/value/int_s.hh (revision 1286) +++ mln/value/int_s.hh (working copy) @@ -33,7 +33,7 @@ * \brief Define a generic class for signed integers. */ -# include <mln/metal/math.hh> +# include <mln/metal/math/pow.hh> # include <mln/value/internal/value_like.hh> # include <mln/value/concept/integer.hh> # include <mln/value/internal/encoding.hh> @@ -137,8 +137,8 @@ template <unsigned n> struct props< int_s<n> > { - static const std::size_t card_ = metal::pow<2, n>::value - 1; - static const int_s<n> max() { return metal::pow<2, n-1>::value - 1; } + static const std::size_t card_ = metal::math::pow_int<2, n>::value - 1; + static const int_s<n> max() { return metal::math::pow_int<2, n-1>::value - 1; } static const int_s<n> min() { return - max(); } static const unsigned nbits = n; typedef trait::value::kind::data kind; @@ -175,7 +175,7 @@ template <unsigned n> int_s<n>::int_s(int i) { - static const int max = metal::pow<2, n-1>::value - 1; + static const int max = metal::math::pow_int<2, n-1>::value - 1; static const int min = - max; mln_precondition(i >= min); mln_precondition(i <= max); @@ -186,7 +186,7 @@ int_s<n>& int_s<n>::operator=(int i) { - static const int max = metal::pow<2, n-1>::value - 1; + static const int max = metal::math::pow_int<2, n-1>::value - 1; static const int min = - max; mln_precondition(i >= min); mln_precondition(i <= max); Index: mln/value/int_u.hh --- mln/value/int_u.hh (revision 1286) +++ mln/value/int_u.hh (working copy) @@ -33,12 +33,13 @@ * \brief Define a generic class for unsigned integers. */ -# include <mln/metal/math.hh> +# include <mln/metal/math/pow.hh> # include <mln/value/internal/value_like.hh> # include <mln/value/internal/encoding.hh> # include <mln/value/concept/integer.hh> # include <mln/value/props.hh> -# include <mln/trait/all.hh> +# include <mln/trait/all.hh> // FIXME! +# include <mln/trait/value_.hh> # include <mln/debug/format.hh> @@ -81,10 +82,8 @@ // FIXME: Is that all? (No!) template <unsigned n> - struct value_< mln::value::int_u<n> > + struct value_< mln::value::int_u<n> > : mln::trait::value_integer_<8> { - typedef trait::value::nature::integer nature; - typedef trait::value::kind::data kind; }; } // end of namespace mln::trait @@ -144,7 +143,7 @@ template <unsigned n> struct props< int_u<n> > { - static const std::size_t card_ = metal::pow<2, n>::value; + static const std::size_t card_ = metal::math::pow_int<2, n>::value; static const int_u<n> min() { return 0; } static const int_u<n> max() { return card_ - 1; } static const unsigned nbits = n; Index: mln/value/int_u_sat.hh --- mln/value/int_u_sat.hh (revision 1286) +++ mln/value/int_u_sat.hh (working copy) @@ -34,7 +34,7 @@ * behavior. */ -# include <mln/metal/math.hh> +# include <mln/metal/math/pow.hh> # include <mln/value/internal/value_like.hh> # include <mln/value/concept/integer.hh> # include <mln/value/internal/encoding.hh> @@ -98,7 +98,7 @@ template <unsigned n> struct props< int_u_sat<n> > { - static const std::size_t card_ = metal::pow<2, n>::value; + static const std::size_t card_ = metal::math::pow_int<2, n>::value; static const int_u_sat<n> min() { return 0; } static const int_u_sat<n> max() { return card_ - 1; } static const unsigned nbits = n; Index: mln/value/props.hh --- mln/value/props.hh (revision 1286) +++ mln/value/props.hh (working copy) @@ -106,6 +106,13 @@ } }; + template <typename T> + struct helper_quant_ + { + static const std::size_t card = mln::value::props<T>::card_; + + }; + } // end of namespace mln::value::internal Index: mln/value/rgb.hh --- mln/value/rgb.hh (revision 1286) +++ mln/value/rgb.hh (working copy) @@ -133,7 +133,7 @@ struct props< rgb<n> > { static const unsigned nbits = 24; - static const std::size_t card_ = 0; // FIXME: was: metal::pow<2, nbits>::value; + static const std::size_t card_ = 0; // FIXME: was: metal::math::pow_int<2, nbits>::value; typedef trait::value::kind::color kind; typedef float_x3_t sum; typedef uchar_x3_t interop; Index: mln/value/rgb8_non_templated.hh --- mln/value/rgb8_non_templated.hh (revision 1286) +++ mln/value/rgb8_non_templated.hh (working copy) @@ -105,7 +105,7 @@ struct props< rgb8 > { static const unsigned nbits = 24; - static const std::size_t card_ = metal::pow<2, nbits>::value; + static const std::size_t card_ = metal::math::pow_int<2, nbits>::value; typedef trait::value::kind::color kind; typedef float_x3_t sum; typedef uchar_x3_t interop; Index: mln/value/label.hh --- mln/value/label.hh (revision 1286) +++ mln/value/label.hh (working copy) @@ -33,7 +33,7 @@ * \brief Define a generic class for labels. */ -# include <mln/metal/math.hh> +# include <mln/metal/math/pow.hh> # include <mln/value/internal/value_like.hh> # include <mln/value/concept/symbolic.hh> # include <mln/value/internal/encoding.hh> @@ -129,7 +129,7 @@ template <unsigned n> struct props< label<n> > { - static const std::size_t card_ = metal::pow<2, n>::value; + static const std::size_t card_ = metal::math::pow_int<2, n>::value; static const label<n> min; // = 0 static const label<n> max; // = card_ - 1 static const unsigned nbits = n; @@ -222,7 +222,7 @@ template <unsigned n> const label<n> - props< label<n> >::max = metal::pow<2, n>::value - 1; + props< label<n> >::max = metal::math::pow_int<2, n>::value - 1; template <unsigned n> std::ostream& operator<<(std::ostream& ostr, const label<n>& i) Index: mln/fun/x2x/bijective_tr.hh --- mln/fun/x2x/bijective_tr.hh (revision 1286) +++ mln/fun/x2x/bijective_tr.hh (working copy) @@ -52,12 +52,27 @@ template <typename E> struct bijective_tr : public Function_x2x< E > { - typedef E::result result; - typedef E::invert invert; - + /* + typedef invert; invert inv() const; + */ + protected: + bijective_tr(); }; + +# ifndef MLN_INCLUDE_ONLY + + template <typename E> + bijective_tr<E>::bijective_tr() + { + typedef typename E::invert invert; + invert (E::*m)() const = & E::inv; + m = 0; + } + +# endif // ! MLN_INCLUDE_ONLY + } // end of namespace mln::fun::x2x } // end of namespace mln::fun Index: mln/morpho/erosion.hh --- mln/morpho/erosion.hh (revision 1286) +++ mln/morpho/erosion.hh (working copy) @@ -55,6 +55,12 @@ void erosion(const Image<I>& input, const Window<W>& win, Image<O>& output); + // FIXME: Doc! + template <typename I, typename W> + mln_concrete(I) + erosion(const Image<I>& input, const Window<W>& win); + + # ifndef MLN_INCLUDE_ONLY namespace impl @@ -108,7 +114,7 @@ - // Facade. + // Facades. template <typename I, typename W, typename O> void erosion(const Image<I>& input, const Window<W>& win, Image<O>& output) @@ -124,6 +130,16 @@ trace::exiting("morpho::erosion"); } + template <typename I, typename W> + mln_concrete(I) + erosion(const Image<I>& input, const Window<W>& win) + { + mln_concrete(I) output; + initialize(output, input); + erosion(input, win, output); + return output; + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::morpho
participants (1)
-
Thierry Geraud