1512: Get rid of the former property mechanism for value types.

https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Get rid of the former property mechanism for value types. Start cleaning the histogram-related test. * tests/histo_compute.cc: Rename as... * tests/histo/compute.cc: ...this. Activate the test with int_s<5>. * tests/accu_all.cc: Inactivate tests on "median< value::set<bool> >" and "min_h< value::set<bool> >" since traits for bool are not equiped with min() and max(). * tests/Makefile.am (SUBDIRS): Sort, Add histo. (histo_compute_SOURCES): Remove. * tests/io_pbm.cc: Simplify. * tests/histo/Makefile.am (check_PROGRAMS): New. (compute_SOURCES, TESTS): New. Preparing to get rid of former property mechanism for value types. * mln/value/props.hh (mln_card_): Move... * mln/trait/value_.hh: ...here and rename as... (mln_card): ...this. * mln/value/props.hh (mln_value_sum, mln_value_kind, mln_value_card_): Remove. (mln_is_lowq): Remove. (mln_min, mln_max): Move... * mln/trait/value_.hh: ...here. * mln/trait/value_.hh (mln_trait_value_card): Rename as... (mln_card): ...this. (mln_value_quant_from_card): Rename as... (mln_value_quant_from_): ...this. (mln_value_card_from_): New macro. (mln_nbits, mln_epsilon): New. * mln/trait/value/nature.hh (matrix): New. Now get rid of value "props". * mln/value/props.hh: Remove. (convert_): Move into... * mln/value/internal/convert.hh: ...this new file. (convert_<bool>): New specialization. Propagate changes. * tests/value_bool.cc, * mln/trait/images.hh, * mln/trait/value/print.hh, * mln/core/macros.hh, * mln/math/round_sat.hh, * mln/metal/mat.hh, * mln/metal/vec.hh, * mln/arith/revert.hh, * mln/arith/revert.spe.hh, * mln/level/sort_points.hh, * mln/level/transform.spe.hh, * mln/level/transform.hh, * mln/level/stretch.hh, * mln/accu/min.hh, * mln/accu/max.hh, * mln/accu/min_max.hh, * mln/accu/sum.hh, * mln/value/proxy.hh, * mln/value/graylevel.hh, * mln/value/lut_vec.hh, * mln/value/ops.hh, * mln/value/gray.hh, * mln/value/float01_.hh, * mln/value/all.hh, * mln/value/quat.hh, * mln/value/int_s.hh, * mln/value/int_u.hh, * mln/value/int_u_sat.hh, * mln/value/set.hh, * mln/value/float01.hh, * mln/value/builtin/symbolics.hh, * mln/value/builtin/floatings.hh, * mln/value/builtin/integers.hh, * mln/value/rgb.hh, * mln/value/float01_f.hh, * mln/value/label.hh, * mln/fun/v2v/saturate.hh, * mln/morpho/Rd.hh, * mln/norm/l1.hh, * mln/norm/l2.hh: Update. Misc. * mln/metal/math/pow.hh (mlc_pow, mlc_pow_int): New macros. * mln/value/internal/iterable_set.hh: . * mln/io/pnm/save_header.hh (save_max_val): New specialization for bool. * mln/io/pnm/load.hh: Fix. * mln/io/pbm/save.hh: Fix. mln/accu/max.hh | 2 mln/accu/min.hh | 2 mln/accu/min_max.hh | 2 mln/accu/sum.hh | 2 mln/arith/revert.hh | 2 mln/arith/revert.spe.hh | 2 mln/core/macros.hh | 3 - mln/fun/v2v/saturate.hh | 2 mln/io/pbm/save.hh | 35 ++++++------ mln/io/pnm/load.hh | 4 - mln/io/pnm/save_header.hh | 10 +++ mln/level/sort_points.hh | 16 +++-- mln/level/stretch.hh | 2 mln/level/transform.hh | 2 mln/level/transform.spe.hh | 4 - mln/math/round_sat.hh | 2 mln/metal/mat.hh | 46 ++++++++++------ mln/metal/math/pow.hh | 5 + mln/metal/vec.hh | 48 +++++++++------- mln/morpho/Rd.hh | 2 mln/norm/l1.hh | 24 ++++---- mln/norm/l2.hh | 24 ++++---- mln/trait/images.hh | 7 +- mln/trait/value/nature.hh | 1 mln/trait/value/print.hh | 4 + mln/trait/value_.hh | 49 ++++++++++++++--- mln/value/all.hh | 2 mln/value/builtin/floatings.hh | 50 ++++++++++++++++- mln/value/builtin/integers.hh | 54 +++++++++---------- mln/value/builtin/symbolics.hh | 7 +- mln/value/float01.hh | 2 mln/value/float01_.hh | 57 +++++++++++++------- mln/value/float01_f.hh | 52 ++++++++++++------ mln/value/gray.hh | 65 ++++++++++++++++++++++ mln/value/graylevel.hh | 41 +++++++++----- mln/value/int_s.hh | 41 ++++++++------ mln/value/int_u.hh | 37 +++++++------ mln/value/int_u_sat.hh | 2 mln/value/internal/convert.hh | 105 +++++++++++++++++++++++++++++++++++++ mln/value/internal/iterable_set.hh | 5 - mln/value/label.hh | 65 +++++++++++++--------- mln/value/lut_vec.hh | 2 mln/value/ops.hh | 6 +- mln/value/proxy.hh | 37 +++++++++---- mln/value/quat.hh | 31 +++++++++- mln/value/rgb.hh | 39 +++++++++---- mln/value/set.hh | 11 ++- tests/Makefile.am | 16 ++--- tests/accu_all.cc | 4 - tests/histo/Makefile.am | 7 ++ tests/histo/compute.cc | 104 ++++++++++++++++++++++++++++++++++++ tests/io_pbm.cc | 48 ++++------------ tests/value_bool.cc | 4 - 53 files changed, 848 insertions(+), 348 deletions(-) Index: tests/accu_all.cc --- tests/accu_all.cc (revision 1511) +++ tests/accu_all.cc (working copy) @@ -46,9 +46,9 @@ histo< value::set<bool> > h; max_<int> ma; mean_<int> me; - median< value::set<bool> > med; + // median< value::set<bool> > med; // FIXME: bool has no min so workaround! min_<int> mi; - min_h< value::set<bool> > mh; + // min_h< value::set<bool> > mh; // OK: do not work since bool has no min/max :) min_max_<int> mm; nil n; pair_< min_<int>, max_<int> > p; Index: tests/Makefile.am --- tests/Makefile.am (revision 1511) +++ tests/Makefile.am (working copy) @@ -2,15 +2,17 @@ include $(top_srcdir)/milena/tests/tests.mk -SUBDIRS = norm \ - level \ +SUBDIRS = \ arith \ - logical \ - draw \ border \ canvas \ - win \ - set + draw \ + histo \ + level \ + logical \ + norm \ + set \ + win check_PROGRAMS = \ accu_all \ @@ -57,7 +59,6 @@ fun_x2x_translation \ \ hexa \ - histo_compute \ histo_to_image1d \ h_vec \ \ @@ -210,7 +211,6 @@ fun_x2x_translation_SOURCES = fun_x2x_translation.cc hexa_SOURCES = hexa.cc -histo_compute_SOURCES = histo_compute.cc histo_to_image1d_SOURCES = histo_to_image1d.cc h_vec_SOURCES = h_vec.cc Index: tests/io_pbm.cc --- tests/io_pbm.cc (revision 1511) +++ tests/io_pbm.cc (working copy) @@ -27,53 +27,29 @@ /*! \file tests/io_pbm.cc * - * \brief Test on mln::io::pbm::load and mln::io::pbm::save. + * \brief Test on mln::io::pbm::. */ #include <mln/core/image2d.hh> - -#include <mln/value/int_u8.hh> -#include <mln/pw/all.hh> - -#include <mln/io/pgm/load.hh> #include <mln/io/pbm/load.hh> #include <mln/io/pbm/save.hh> -#include <mln/level/compare.hh> -#include <mln/level/fill.hh> - -#include <mln/display/show.hh> -#include <mln/display/save.hh> - -#include <mln/border/thickness.hh> int main() { using namespace mln; - using typename value::int_u8; - - typedef image2d< bool > I; - - border::thickness = 0; - image2d< int_u8 > - lena = io::pgm::load("../img/lena.pgm"); - - I out(lena.domain()); - level::fill(out, pw::value(lena) > pw::cst(127)); - io::pbm::save(out, "out.pbm"); - - { - I lena = io::pbm::load("out.pbm"); - image2d<bool> out(lena.domain()); - - io::pbm::save(lena, "out2.pbm"); + image2d<bool> pic = io::pbm::load("../img/picasso.pbm"); + io::pbm::save(pic, "pic.pbm"); +} - I lena2 = io::pbm::load("out2.pbm"); - io::pbm::save(lena2, "out3.pbm"); +// sample binary image to test with xv, imview, and display +// to bring into the fore the binary image bug with raw pbm. - mln_assertion(lena.domain() = lena2.domain()); - mln_assertion(lena = lena2); - } -} +// | | | | - +// | | - - - +// | - - - - +// - - - - - +// - - - - - +// - - - - - Index: tests/histo/compute.cc --- tests/histo/compute.cc (revision 0) +++ tests/histo/compute.cc (revision 0) @@ -0,0 +1,104 @@ +// 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/histo/compute.cc + * + * \brief Tests on mln::accu::histo and mln::histo::data. + */ + +#include <iterator> +#include <sstream> + +#include <mln/core/image2d.hh> +#include <mln/value/int_u8.hh> +#include <mln/value/int_s.hh> + +#include <mln/debug/iota.hh> +#include <mln/debug/println.hh> +#include <mln/accu/histo.hh> +#include <mln/histo/compute.hh> + + +int main() +{ + using namespace mln; + using value::int_u8; + +// // Test on 'bool'. +// { +// accu::histo< value::set<bool> > h; + +// for (unsigned i = 0; i < 5; ++i) +// h.take(false); +// for (unsigned i = 0; i < 2; ++i) +// h.take(true); +// h.untake(true); + +// mln_assertion(h[0] * 10 + h[1] = 51); +// mln_assertion(h(false) * 10 + h(true) = 51); +// } + +// // Test on 'int_u8'. +// { +// image2d<int_u8> ima(3, 3); +// debug::iota(ima); +// ima.at(0,0) = 2; + +// histo::data< value::set<int_u8> > h = histo::compute(ima); +// std::ostringstream oss; +// oss << h; +// mln_assertion(oss.str() = "2:2 3:1 4:1 5:1 6:1 7:1 8:1 9:1 "); + +// int_u8 i = 2; +// mln_assertion(h(i) = 2); +// } + + // Test on 'int_s5'. + { + typedef value::int_s<5> int_s5; + image2d<int_s5> ima(3, 3); + debug::iota(ima); + ima.at(0,0) = 2; + + std::cout << "int_s5: " + << value::props< int_s5 >::min() << ' ' + << value::props< int_s5 >::max() << ' ' + << value::props< int_s5 >::card_ << std::endl; + + debug::println(ima); + + + histo::data< value::set<int_s5> > h = histo::compute(ima); + std::cout << "nvalues = " << h.vset().nvalues() << std::endl; + std::cout << h << std::endl; + + for (unsigned i = 0; i < h.vset().nvalues(); ++i) + std::cout << i << ':' << h[i] << ' '; + std::cout << std::endl; + } + +} Index: tests/histo/Makefile.am --- tests/histo/Makefile.am (revision 1511) +++ tests/histo/Makefile.am (working copy) @@ -1,3 +1,10 @@ ## Process this file through Automake to create Makefile.in -*- Makefile -*- include $(top_srcdir)/milena/tests/tests.mk + +check_PROGRAMS = \ + compute + +compute_SOURCES = compute.cc + +TESTS = $(check_PROGRAMS) Index: tests/value_bool.cc --- tests/value_bool.cc (revision 1511) +++ tests/value_bool.cc (working copy) @@ -30,7 +30,7 @@ * \brief Tests on mln::value::set. */ -#include <mln/value/props.hh> +#include <mln/trait/value_.hh> #include <mln/value/set.hh> @@ -38,7 +38,7 @@ { using namespace mln; - mln_assertion(mln::trait::value_<bool>::card::value = 2); + mln_assertion(mln_card(bool) = 2); value::set<bool> B; std::cout << B << std::endl; Index: mln/trait/images.hh --- mln/trait/images.hh (revision 1511) +++ mln/trait/images.hh (working copy) @@ -40,7 +40,7 @@ # include <mln/trait/undef.hh> # include <mln/trait/image/props.hh> -# include <mln/value/props.hh> +# include <mln/trait/value_.hh> # include <mln/metal/bexpr.hh> # include <mln/metal/equal.hh> @@ -148,9 +148,10 @@ struct default_image_ : undefined_image_<I> { private: - typedef metal::bool_<( mln_value_card_(T) = 0 )> is_high_quant_; + typedef mlc_equal(mln_trait_value_quant(T), + trait::value::quant::high) is_high_quant_; public: - typedef mln_value_kind(T) kind; + typedef mln_trait_value_kind(T) kind; typedef mlc_if( is_high_quant_, trait::image::quant::high, trait::image::quant::low ) quant; Index: mln/trait/value_.hh --- mln/trait/value_.hh (revision 1511) +++ mln/trait/value_.hh (working copy) @@ -41,19 +41,38 @@ # include <mln/metal/if.hh> # include <mln/trait/value/all.hh> +# include <mln/metal/math/pow.hh> # 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 )>, \ +# define mln_nbits(V) mln::trait::value_< V >::nbits +# define mln_card(V) mln::trait::value_< V >::card +# define mln_min(V) mln::trait::value_< V >::min() +# define mln_max(V) mln::trait::value_< V >::max() +# define mln_epsilon(V) mln::trait::value_< V >::epsilon() + + +/// Give the summation type for values of type \c T. +# define mln_trait_value_sum(V) typename mln::trait::value_< V >::sum +# define mln_sum(V) mln_trait_value_sum(V) + + + +# define mln_value_quant_from_(C) \ + mlc_if(mln::metal::bool_<( C > 65536 || C = 0 )>, \ mln::trait::value::quant::high, \ mln::trait::value::quant::low) +# define mln_value_card_from_(N) \ + N <= 16 \ + ? mlc_pow_int((N <= 16 ? 2 : 1), \ + (N <= 16 ? N : 1)) \ + : 0 + namespace mln @@ -68,24 +87,38 @@ typedef undef nature; typedef undef kind; typedef undef quant; - typedef undef card; + + /* + * enum { + * nbits = ?, + * card = ? + * }; + * + * static const E min(); + * static const E max(); + * static const E epsilon(); + */ + typedef undef sum; // FIXME: signed or not, with zero or not, centered or not, etc. }; - struct default_value_ + struct default_value_ : undefined_value_ { + enum { + nbits = 0, + card = 0 + }; + 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_ + struct value_ : default_value_ { }; Index: mln/trait/value/print.hh --- mln/trait/value/print.hh (revision 1511) +++ mln/trait/value/print.hh (working copy) @@ -70,7 +70,9 @@ << typename the::nature().name() << ", " << typename the::kind() .name() << ", " << typename the::quant() .name() << ", " - << typename the::card() .name() << " }" << std::endl; + << "nbits=" << the::nbits << ", " + << "card=" << the::card << ", " + << " }" << std::endl; } template <typename V> Index: mln/trait/value/nature.hh --- mln/trait/value/nature.hh (revision 1511) +++ mln/trait/value/nature.hh (working copy) @@ -54,6 +54,7 @@ struct floating : scalar { std::string name() const { return "nature::floating"; } }; struct vectorial : any { std::string name() const { return "nature::vectorial"; } }; + struct matrix : any { std::string name() const { return "nature::matrix"; } }; struct symbolic : any { std::string name() const { return "nature::symbolic"; } }; struct structured : any { std::string name() const { return "nature::structured"; } }; Index: mln/core/macros.hh --- mln/core/macros.hh (revision 1511) +++ mln/core/macros.hh (working copy) @@ -173,9 +173,6 @@ # define mln_value(T) typename T::value # define mln_value_(T) T::value -/// Shortcut to test if the values of an image with type \c I are lowly quantifized. -# define mln_is_value_lowq(I) mln_is_lowq( mln_value(I) ) - /// Shortcut to access the type of value set (vset) associated to T. # define mln_vset(T) typename T::vset Index: mln/math/round_sat.hh --- mln/math/round_sat.hh (revision 1511) +++ mln/math/round_sat.hh (working copy) @@ -36,7 +36,7 @@ # include <cmath> # include <mln/core/concept/function.hh> -# include <mln/value/props.hh> +# include <mln/trait/value_.hh> Index: mln/metal/mat.hh --- mln/metal/mat.hh (revision 1511) +++ mln/metal/mat.hh (working copy) @@ -40,7 +40,7 @@ # include <mln/core/concept/function.hh> # include <mln/core/contract.hh> # include <mln/trait/all.hh> -# include <mln/value/props.hh> +# include <mln/trait/value_.hh> # include <mln/metal/vec.hh> @@ -51,6 +51,35 @@ namespace mln { + + // Fwd decl. + namespace metal { + template <unsigned n, unsigned m, typename T> class mat; + } + + + namespace trait + { + + template <unsigned n, unsigned m, typename T> + struct value_< metal::mat<n,m,T> > + { + typedef trait::value::nature::matrix nature; + typedef trait::value::kind::data kind; + + enum { + nbits = n * m * mln_nbits(T), + card = n * m * mln_card(T) + }; + typedef mln_value_quant_from_(card) quant; + + typedef metal::mat<n, m, mln_sum(T)> sum; + }; + + } // end of namespace mln::trait + + + namespace metal { @@ -166,21 +195,6 @@ - namespace value - { - - template <unsigned n, unsigned m, typename T> - struct props< metal::mat<n,m,T> > - { - typedef trait::value::kind::data kind; - static const std::size_t card_ = n * m * mln_card_(T); - typedef metal::mat<n,m, mln_value_sum(T)> sum; - }; - - } // end of namespace mln::value - - - namespace metal { Index: mln/metal/math/pow.hh --- mln/metal/math/pow.hh (revision 1511) +++ mln/metal/math/pow.hh (working copy) @@ -37,6 +37,11 @@ # include <mln/metal/int.hh> +# define mlc_pow(X, N) typename mln::metal::math::pow< X, N >::ret +# define mlc_pow_int(x, n) mln::metal::math::pow_int< x, n >::value + + + namespace mln { Index: mln/metal/vec.hh --- mln/metal/vec.hh (revision 1511) +++ mln/metal/vec.hh (working copy) @@ -40,7 +40,7 @@ # include <mln/core/concept/object.hh> # include <mln/trait/all.hh> -# include <mln/value/props.hh> +# include <mln/trait/value_.hh> # include <mln/fun/i2v/all_to.hh> # include <mln/debug/format.hh> @@ -54,18 +54,41 @@ { // Fwd decls. - namespace literal { struct zero_t; } + namespace metal { + template <unsigned n, typename T> class vec; + } + namespace literal { + struct zero_t; + } template <unsigned d, typename C> struct h_vec; - namespace metal + namespace trait { - // Fwd decl. - template <unsigned n, typename T> class vec; + template <unsigned n, typename T> + struct value_< mln::metal::vec<n,T> > + { + typedef trait::value::nature::vectorial nature; + typedef trait::value::kind::data kind; + + enum { + nbits = n * mln_nbits(T), + card = n * mln_card(T) + }; + typedef mln_value_quant_from_(card) quant; + + typedef metal::vec<n, mln_sum(T)> sum; + }; + + } // end of namespace mln::trait + + namespace metal + { + namespace internal { @@ -253,21 +276,6 @@ - namespace value - { - - template <unsigned n, typename T> - struct props< metal::vec<n,T> > - { - typedef trait::value::kind::data kind; - static const std::size_t card_ = n * mln_card_(T); - typedef metal::vec<n, mln_value_sum(T)> sum; - }; - - } // end of namespace mln::value - - - namespace metal { Index: mln/arith/revert.hh --- mln/arith/revert.hh (revision 1511) +++ mln/arith/revert.hh (working copy) @@ -36,7 +36,7 @@ */ # include <mln/core/concept/image.hh> -# include <mln/value/props.hh> +# include <mln/trait/value_.hh> // Specializations are in: # include <mln/arith/revert.spe.hh> Index: mln/arith/revert.spe.hh --- mln/arith/revert.spe.hh (revision 1511) +++ mln/arith/revert.spe.hh (working copy) @@ -35,7 +35,7 @@ */ # include <mln/core/concept/image.hh> -# include <mln/value/props.hh> +# include <mln/trait/value_.hh> # ifndef MLN_INCLUDE_ONLY Index: mln/level/sort_points.hh --- mln/level/sort_points.hh (revision 1511) +++ mln/level/sort_points.hh (working copy) @@ -107,7 +107,8 @@ template <typename I> p_array<mln_point(I)> - sort_points_increasing_(metal::false_, const I& input) // general case + sort_points_increasing_(trait::image::quant::any, // general case + const I& input) { p_array<mln_point(I)> v = convert::to_p_array(input.domain()); std::sort(v.hook_().begin(), v.hook_().end(), @@ -117,7 +118,8 @@ template <typename I> p_array<mln_point(I)> - sort_points_increasing_(metal::true_, const I& input) // low quantization + sort_points_increasing_(trait::image::quant::low, // low quantization + const I& input) { typedef mln_vset(I) S; const S& vset = input.values(); @@ -148,7 +150,8 @@ template <typename I> p_array<mln_point(I)> - sort_points_decreasing_(metal::false_, const I& input) // general case + sort_points_decreasing_(trait::image::quant::any, // general case + const I& input) { p_array<mln_point(I)> v = convert::to_p_array(input.domain()); std::sort(v.hook_().begin(), v.hook_().end(), @@ -158,7 +161,8 @@ template <typename I> p_array<mln_point(I)> - sort_points_decreasing_(metal::true_, const I& input) // low quantization + sort_points_decreasing_(trait::image::quant::low, // low quantization + const I& input) { typedef mln_vset(I) S; const S& vset = input.values(); @@ -195,7 +199,7 @@ sort_points_increasing(const Image<I>& input) { mln_precondition(exact(input).has_data()); - return impl::sort_points_increasing_(mln_is_value_lowq(I)(), exact(input)); + return impl::sort_points_increasing_(mln_trait_image_quant(I)(), exact(input)); } template <typename I> @@ -203,7 +207,7 @@ sort_points_decreasing(const Image<I>& input) { mln_precondition(exact(input).has_data()); - return impl::sort_points_decreasing_(mln_is_value_lowq(I)(), exact(input)); + return impl::sort_points_decreasing_(mln_trait_image_quant(I)(), exact(input)); } # endif // ! MLN_INCLUDE_ONLY Index: mln/level/transform.spe.hh --- mln/level/transform.spe.hh (revision 1511) +++ mln/level/transform.spe.hh (working copy) @@ -62,7 +62,7 @@ } template <typename I, typename F, typename O> - void transform_(metal::false_, // general case + void transform_(mln::trait::image::quant::any, // general case const Image<I>& input_, const Function_v2v<F>& f_, Image<O>& output_) { generic::transform_(input_, f_, output_); @@ -70,7 +70,7 @@ template <typename I, typename F, typename O> - void transform_(metal::true_, // low quantization + void transform_(mln::trait::image::quant::low, // low quantization const Image<I>& input_, const Function_v2v<F>& f_, Image<O>& output_) { trace::entering("level::impl::transform"); Index: mln/level/transform.hh --- mln/level/transform.hh (revision 1511) +++ mln/level/transform.hh (working copy) @@ -110,7 +110,7 @@ trace::entering("level::transform"); mln_precondition(exact(output).domain() >= exact(input).domain()); - impl::transform_(mln_is_value_lowq(I)(), + impl::transform_(mln_trait_image_quant(I)(), exact(input), exact(f), exact(output)); trace::exiting("level::transform"); Index: mln/level/stretch.hh --- mln/level/stretch.hh (revision 1511) +++ mln/level/stretch.hh (working copy) @@ -73,7 +73,7 @@ if (max_ = min_) return; // FIXME float min = float(min_), max = float(max_); - const float epsilon = value::props<float>::epsilon(); + const float epsilon = mln_epsilon(float); float m = 0.0f - 0.5f + epsilon; float M = mln_max(value::int_u<n>) + 0.5f - epsilon; float a = (M - m) / (max - min); Index: mln/accu/min.hh --- mln/accu/min.hh (revision 1511) +++ mln/accu/min.hh (working copy) @@ -35,7 +35,7 @@ # include <mln/accu/internal/base.hh> # include <mln/core/concept/meta_accumulator.hh> -# include <mln/value/props.hh> +# include <mln/trait/value_.hh> # include <mln/util/pix.hh> Index: mln/accu/max.hh --- mln/accu/max.hh (revision 1511) +++ mln/accu/max.hh (working copy) @@ -34,7 +34,7 @@ */ # include <mln/core/concept/meta_accumulator.hh> -# include <mln/value/props.hh> +# include <mln/trait/value_.hh> # include <mln/util/pix.hh> Index: mln/accu/min_max.hh --- mln/accu/min_max.hh (revision 1511) +++ mln/accu/min_max.hh (working copy) @@ -40,7 +40,7 @@ # include <mln/accu/pair.hh> # include <mln/accu/min.hh> # include <mln/accu/max.hh> -# include <mln/value/props.hh> +# include <mln/trait/value_.hh> # include <mln/util/pix.hh> Index: mln/accu/sum.hh --- mln/accu/sum.hh (revision 1511) +++ mln/accu/sum.hh (working copy) @@ -36,7 +36,7 @@ # include <mln/core/concept/meta_accumulator.hh> # include <mln/accu/internal/base.hh> -# include <mln/value/props.hh> +# include <mln/trait/value_.hh> # include <mln/util/pix.hh> # include <mln/literal/zero.hh> Index: mln/value/proxy.hh --- mln/value/proxy.hh (revision 1511) +++ mln/value/proxy.hh (working copy) @@ -34,16 +34,41 @@ */ # include <mln/core/concept/value.hh> -# include <mln/value/props.hh> +# include <mln/trait/value_.hh> # include <mln/metal/unconst.hh> namespace mln { - namespace value + // Fwd decl. + namespace value { + template <typename I> class proxy; + } + + + namespace trait + { + + template <typename I> + struct value_< mln::value::proxy<I> > + : + value_< mln_value(I) > + { + }; + + template <typename I> + struct value_< mln::value::proxy<const I> > + : + value_< mln_value(I) > { + }; + + } // end of namespace trait + + namespace value + { /*! \brief Generic proxy class for an image pixel value. * @@ -156,14 +181,6 @@ - template <typename I> - struct props< proxy<I> > : public props< mln_value(I) > - { - // Contents is inherited. - }; - - - /*! \brief Print a value proxy \p x into the output stream \p ostr. * * \param[in,out] ostr An output stream. Index: mln/value/graylevel.hh --- mln/value/graylevel.hh (revision 1511) +++ mln/value/graylevel.hh (working copy) @@ -44,7 +44,7 @@ # include <mln/value/int_u.hh> # include <mln/value/gray.hh> -# include <mln/value/props.hh> +# include <mln/trait/value_.hh> namespace mln @@ -144,6 +144,33 @@ mln::value::scalar_<S>) ret; }; + + // 'graylevel<n>' as a value. + + template <unsigned n> + struct value_< mln::value::graylevel<n> > + { + private: + typedef mln::value::graylevel<n> self_; + public: + + enum { + nbits = n, + card = mln_value_card_from_(n) + }; + + typedef trait::value::nature::integer nature; // FIXME: Or scalar? + typedef trait::value::kind::gray kind; + typedef mln_value_quant_from_(card) quant; + + static const self_ min() { return 0; } + static const self_ max() { return card - 1; } + static const self_ epsilon() { return 0; } + + typedef float sum; + }; + + } // end of namespace mln::trait @@ -219,18 +246,6 @@ }; - template <unsigned n> - struct props< graylevel<n> > - { - 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; - typedef trait::value::kind::data kind; - typedef float sum; - typedef int interop; - }; - /// Op<<. template <unsigned n> Index: mln/value/lut_vec.hh --- mln/value/lut_vec.hh (revision 1511) +++ mln/value/lut_vec.hh (working copy) @@ -37,7 +37,7 @@ # include <mln/core/concept/value_set.hh> # include <mln/core/concept/function.hh> -# include <mln/value/props.hh> +# include <mln/trait/value_.hh> namespace mln Index: mln/value/ops.hh --- mln/value/ops.hh (revision 1511) +++ mln/value/ops.hh (working copy) @@ -37,14 +37,16 @@ # include <mln/value/builtin/all.hh> # include <mln/value/concept/all.hh> # include <mln/value/equiv.hh> -# include <mln/value/props.hh> +# include <mln/trait/value_.hh> # include <mln/literal/zero.hh> # include <mln/literal/one.hh> # include <mln/literal/ops.hh> # include <mln/metal/ret.hh> -# define mln_sum_x(T, U) typename mln::value::props< mln_trait_op_times(T,U) >::sum +# define mln_trait_value_sum_x(T, U) typename mln::trait::value_< mln_trait_op_times(T,U) >::sum + +# define mln_sum_x(T, U) mln_trait_value_sum_x(T, U) Index: mln/value/gray.hh --- mln/value/gray.hh (revision 1511) +++ mln/value/gray.hh (working copy) @@ -69,9 +69,36 @@ typedef mln::value::gray ret; }; + + // 'gray' as a value. + + template <> + struct value_< mln::value::gray > + { + private: + typedef mln::value::gray self_; + public: + + enum { + nbits = 8 * (sizeof(unsigned) + sizeof(long)), + card = 0 + }; + + typedef trait::value::nature::integer nature; // FIXME: Or scalar? + typedef trait::value::kind::gray kind; + typedef trait::value::quant::high quant; + + static const self_ min(); + static const self_ max(); + static const self_ epsilon(); + + typedef self_ sum; // FIXME: OK? + }; + } // end of namespace mln::trait + namespace value { @@ -131,7 +158,7 @@ unsigned nbits_; /// Value. - long val_; + long val_; // FIXME: Why not int? }; @@ -151,10 +178,15 @@ gray operator/(const gray& lhs, int s); + } // end of namespace mln::value + # ifndef MLN_INCLUDE_ONLY + namespace value + { + // Gray. gray::gray() @@ -513,10 +545,39 @@ return internal::helper_gray_op_<ret>::div(lhs, rhs); } -# endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::value + + + namespace trait + { + + // 'gray' as a value. + + const mln::value::gray + value_< mln::value::gray >::min() + { + return mln::value::gray(1, 0); + } + + const mln::value::gray + value_< mln::value::gray >::max() + { + return mln::value::gray(1, 1); + } + + const mln::value::gray + value_< mln::value::gray >::epsilon() + { + return mln::value::gray(1, 0); // Means '0'. + } + + } // end of namespace mln::trait + + +# endif // ! MLN_INCLUDE_ONLY + } // end of namespace mln Index: mln/value/float01_.hh --- mln/value/float01_.hh (revision 1511) +++ mln/value/float01_.hh (working copy) @@ -40,20 +40,49 @@ # include <mln/value/int_u.hh> # include <mln/value/concept/floating.hh> +# include <mln/value/internal/convert.hh> # include <mln/value/float01.hh> -# include <mln/value/props.hh> +# include <mln/trait/value_.hh> namespace mln { - namespace value + // Fwd decls. + namespace value { + class float01; + template <unsigned n> struct float01_; + } + + + namespace trait { - /// Fwd decl. - class float01; + template <unsigned n> + struct value_< mln::value::float01_<n> > + { + enum { + nbits = n, + card = mln_value_card_from_(nbits) + }; + typedef trait::value::nature::floating nature; + typedef trait::value::kind::data kind; + typedef mln_value_quant_from_(card) quant; + + static const float min() { return 0.f; } + static const float max() { return 1.f; } + static const float epsilon() { return 0.f; } + + typedef float sum; + }; + + } // end of namespace trait + + + namespace value + { /// General class for the interval [0,1] of |R made discrete (quantized with n bits). template <unsigned n> @@ -106,18 +135,6 @@ }; } - template <unsigned n> - struct props< float01_<n> > - { - 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; - typedef trait::value::kind::data kind; - typedef float sum; - typedef float interop; - }; - /// Op<<. template <unsigned n> @@ -146,14 +163,14 @@ { mln_precondition(val >= 0); mln_precondition(val <= 1); - this->v_ = int(val * (mln_card_(float01_<n>) - 1)); // FIXME + this->v_ = int(val * (mln_card(float01_<n>) - 1)); // FIXME } template <unsigned n> float float01_<n>::value() const { - return float(this->v_) / (mln_card_(float01_<n>) - 1); // FIXME + return float(this->v_) / (mln_card(float01_<n>) - 1); // FIXME } template <unsigned n> @@ -169,14 +186,14 @@ { mln_precondition(val >= 0); mln_precondition(val <= 1); - this->v_ = int(val * (mln_card_(float01_<n>) - 1)); // FIXME + this->v_ = int(val * (mln_card(float01_<n>) - 1)); // FIXME return *this; } template <unsigned n> float01_<n>::operator float() const { - return float(this->v_) / (mln_card_(float01_<n>) - 1); + return float(this->v_) / (mln_card(float01_<n>) - 1); } Index: mln/value/all.hh --- mln/value/all.hh (revision 1511) +++ mln/value/all.hh (working copy) @@ -49,7 +49,7 @@ # include <mln/value/aliases.hh> # include <mln/value/label.hh> -# include <mln/value/props.hh> +# include <mln/trait/value_.hh> # include <mln/value/proxy.hh> # include <mln/value/interval.hh> Index: mln/value/quat.hh --- mln/value/quat.hh (revision 1511) +++ mln/value/quat.hh (working copy) @@ -39,7 +39,7 @@ # include <mln/value/concept/vectorial.hh> # include <mln/value/internal/value_like.hh> -# include <mln/value/props.hh> +# include <mln/trait/value_.hh> # include <mln/metal/vec.hh> # include <mln/norm/l2.hh> @@ -90,6 +90,26 @@ typedef mln::value::quat ret; }; + + // 'quat' as a value. + + + template <> + struct value_< mln::value::quat > + { + typedef trait::value::nature::vectorial nature; + typedef trait::value::kind::data kind; + typedef trait::value::quant::high quant; + + enum { + nbits = 4 * sizeof(float), + card = 0 + }; + + typedef mln::value::quat sum; + }; + + } // end of namespace mln::trait @@ -376,8 +396,8 @@ { static const float pi = 3.14159265358979323846; - mln_precondition(theta > - pi - props<float>::epsilon() - && theta < pi + props<float>::epsilon()); + mln_precondition(theta > - pi - mln_epsilon(float) + && theta < pi + mln_epsilon(float)); mln_precondition(about_equal(norm::l2(uv), 1.f)); this->v_[0] = cos(theta); @@ -496,9 +516,10 @@ template <typename T> bool about_equal(const T& f, const T& q) { + // FIXME: Use abs! if (f > q) - return (f - q ) < props<T>::epsilon(); - return (q - f) < props<T>::epsilon(); + return (f - q ) < mln_epsilon(T); + return (q - f) < mln_epsilon(T); } bool about_equal(const quat& p, const quat& q) Index: mln/value/int_s.hh --- mln/value/int_s.hh (revision 1511) +++ mln/value/int_s.hh (working copy) @@ -39,7 +39,7 @@ # include <mln/value/internal/value_like.hh> # include <mln/value/concept/integer.hh> # include <mln/value/internal/encoding.hh> -# include <mln/value/props.hh> +# include <mln/trait/value_.hh> # include <mln/trait/all.hh> # include <mln/debug/format.hh> @@ -69,8 +69,26 @@ { template <unsigned n> - struct value_< mln::value::int_s<n> > : mln::trait::value_integer_<n> + struct value_< mln::value::int_s<n> > { + private: + typedef mln::value::int_s<n> self_; + public: + + enum { + nbits = n, + card = mln_value_card_from_(n) + }; + + typedef trait::value::nature::integer nature; + typedef trait::value::kind::data kind; + typedef mln_value_quant_from_(card) quant; + + static const self_ max() { return card / 2 - 1; } + static const self_ min() { return - max(); } + static const self_ epsilon() { return 0; } + + typedef float sum; }; } // end of namespace mln::trait @@ -88,8 +106,10 @@ template <unsigned n> struct int_s : - public Integer< int_s<n> >, - + private metal::bool_<(n <= 32)>::check_t + , + public Integer< int_s<n> > + , public internal::value_like_< int, // Equivalent. typename internal::encoding_signed_<n>::ret, // Enc. int, // Interoperation. @@ -129,19 +149,6 @@ - template <unsigned n> - struct props< int_s<n> > - { - 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; - typedef float sum; - }; - - - /*! \brief Print an signed integer \p i into the output stream \p ostr. * * \param[in,out] ostr An output stream. Index: mln/value/int_u.hh --- mln/value/int_u.hh (revision 1511) +++ mln/value/int_u.hh (working copy) @@ -39,7 +39,7 @@ # 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/value_.hh> # include <mln/trait/all.hh> // FIXME! # include <mln/trait/value_.hh> # include <mln/debug/format.hh> @@ -74,9 +74,28 @@ typedef int ret; }; + template <unsigned n> - struct value_< mln::value::int_u<n> > : mln::trait::value_integer_<n> + struct value_< mln::value::int_u<n> > { + private: + typedef mln::value::int_u<n> self_; + public: + + enum { + nbits = n, + card = mln_value_card_from_(n) + }; + + typedef trait::value::nature::integer nature; + typedef trait::value::kind::data kind; + typedef mln_value_quant_from_(card) quant; + + static const self_ min() { return 0; } + static const self_ max() { return card - 1; } + static const self_ epsilon() { return 0; } + + typedef float sum; }; } // end of namespace mln::trait @@ -136,20 +155,6 @@ - template <unsigned n> - struct props< int_u<n> > - { - 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; - typedef trait::value::kind::data kind; - typedef float sum; - typedef int interop; - }; - - - /*! \brief Print an unsigned integer \p i into the output stream \p ostr. * * \param[in,out] ostr An output stream. Index: mln/value/internal/iterable_set.hh --- mln/value/internal/iterable_set.hh (revision 1511) +++ mln/value/internal/iterable_set.hh (working copy) @@ -34,9 +34,9 @@ */ # include <mln/core/concept/value_set.hh> -# include <mln/value/props.hh> # include <mln/trait/value_.hh> # include <mln/value/builtin/all.hh> +# include <mln/value/internal/convert.hh> namespace mln @@ -112,8 +112,7 @@ unsigned iterable_set<T,E>::nvalues() const { - typedef mln_trait_value_card(T) card_; - return card_::value; + return mln_card(T); } # endif // ! MLN_INCLUDE_ONLY Index: mln/value/internal/convert.hh --- mln/value/internal/convert.hh (revision 0) +++ mln/value/internal/convert.hh (revision 0) @@ -0,0 +1,105 @@ +// 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_VALUE_INTERNAL_CONVERT_HH +# define MLN_VALUE_INTERNAL_CONVERT_HH + +/*! \file mln/value/internal/convert.hh + * + * \brief Define a conversion between an index and an iterable value. + */ + +# include <mln/trait/value_.hh> + + +namespace mln +{ + + namespace value + { + + namespace internal + { + + template <typename T> + struct convert_ + { + // FIXME: Check that we have a type T compatible with 'int'. + + static T value_at_index(unsigned i); + static unsigned index_of_value(const T& v); + }; + + template <> + struct convert_<bool> + { + static bool value_at_index(unsigned i); + static unsigned index_of_value(bool v); + }; + + +# ifndef MLN_INCLUDE_ONLY + + template <typename T> + T + convert_<T>::value_at_index(unsigned i) + { + return T( int(mln_min(T)) + int(i) ); + } + + template <typename T> + unsigned + convert_<T>::index_of_value(const T& v) + { + return unsigned( int(v) - int(mln_min(T)) ); + } + + // Case of 'bool'. + + bool + convert_<bool>::value_at_index(unsigned i) + { + mln_precondition(i < 2); + return i = 1 ? true : false; + } + + unsigned + convert_<bool>::index_of_value(bool v) + { + return v ? 1 : 0; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::value::internal + + } // end of namespace mln::value + +} // end of namespace mln + + +#endif // ! MLN_VALUE_INTERNAL_CONVERT_HH Index: mln/value/int_u_sat.hh --- mln/value/int_u_sat.hh (revision 1511) +++ mln/value/int_u_sat.hh (working copy) @@ -38,7 +38,7 @@ # include <mln/value/internal/value_like.hh> # include <mln/value/concept/integer.hh> # include <mln/value/internal/encoding.hh> -# include <mln/value/props.hh> +# include <mln/trait/value_.hh> # include <mln/debug/format.hh> Index: mln/value/set.hh --- mln/value/set.hh (revision 1511) +++ mln/value/set.hh (working copy) @@ -34,7 +34,7 @@ */ # include <mln/value/internal/iterable_set.hh> -# include <mln/value/props.hh> +# include <mln/trait/value_.hh> namespace mln @@ -46,12 +46,12 @@ namespace internal { - template <typename T, typename E, typename is_lowq = metal::false_> + template <typename T, typename E, bool is_lowq = false> struct set_selector_ // no inheritance {}; template <typename T, typename E> - struct set_selector_< T, E, metal::true_ > // lowq so iterable + struct set_selector_< T, E, true > // lowq so iterable : public iterable_set< T, E > {}; @@ -65,7 +65,10 @@ * This is the exhaustive set of values obtainable from type \c T. */ template <typename T> - struct set : public internal::set_selector_< T, set<T>, mln_is_lowq(T) > + struct set : public internal::set_selector_< T, set<T>, + mlc_equal( mln_trait_value_quant(T), + mln::trait::value::quant::low )::value + > { /// Return a singleton. static const set<T>& the(); Index: mln/value/float01.hh --- mln/value/float01.hh (revision 1511) +++ mln/value/float01.hh (working copy) @@ -38,7 +38,7 @@ # include <mln/core/concept/value.hh> # include <mln/value/float01_.hh> -# include <mln/value/props.hh> +# include <mln/trait/value_.hh> # include <mln/trait/all.hh> // FIXME! # include <mln/trait/value_.hh> Index: mln/value/builtin/symbolics.hh --- mln/value/builtin/symbolics.hh (revision 1511) +++ mln/value/builtin/symbolics.hh (working copy) @@ -56,11 +56,14 @@ template <> struct value_< bool> { - typedef metal::int_<1> nbits; typedef value::nature::symbolic nature; typedef value::kind::binary kind; + + enum { + nbits = 1, + card = 2 + }; typedef value::quant::low quant; - typedef metal::int_<2> card; }; } // end of namespace mln::trait Index: mln/value/builtin/floatings.hh --- mln/value/builtin/floatings.hh (revision 1511) +++ mln/value/builtin/floatings.hh (working copy) @@ -33,6 +33,8 @@ * \brief Some definitions about built-in floating types. */ +# include <limits> + # include <mln/value/concept/built_in.hh> # include <mln/value/concept/floating.hh> # include <mln/trait/value_.hh> @@ -63,22 +65,62 @@ template <> struct value_< float > { - typedef metal::int_<8*sizeof(float)> nbits; + enum { + nbits = 8 * sizeof(float), + card = 0 + }; + typedef value::nature::floating nature; typedef value::kind::data kind; - typedef metal::int_<0> card; typedef value::quant::high quant; + + static const float min() + { + static const float min_ = std::numeric_limits<float>::min(); + return min_; + } + static const float max() + { + static const float max_ = std::numeric_limits<float>::max(); + return max_; + } + static const float epsilon() + { + static const float epsilon_ = std::numeric_limits<float>::epsilon(); + return epsilon_; + } + typedef float sum; }; template <> struct value_< double > { - typedef metal::int_<8*sizeof(double)> nbits; + enum { + nbits = 8 * sizeof(double), + card = 0 + }; + typedef value::nature::floating nature; typedef value::kind::data kind; - typedef metal::int_<0> card; typedef value::quant::high quant; + + static const double min() + { + static const double min_ = std::numeric_limits<double>::min(); + return min_; + } + static const double max() + { + static const double max_ = std::numeric_limits<double>::max(); + return max_; + } + static const double epsilon() + { + static const double epsilon_ = std::numeric_limits<double>::epsilon(); + return epsilon_; + } + typedef double sum; }; Index: mln/value/builtin/integers.hh --- mln/value/builtin/integers.hh (revision 1511) +++ mln/value/builtin/integers.hh (working copy) @@ -33,6 +33,8 @@ * \brief Some definitions about built-in integer types. */ +# include <limits> + # include <mln/value/concept/built_in.hh> # include <mln/value/concept/integer.hh> # include <mln/trait/value_.hh> @@ -63,43 +65,39 @@ namespace internal { - template < bool small_n /* = true */, unsigned n_bits > - struct helper_card_ - { - typedef metal::math::pow_int<2, n_bits> pow_; - typedef metal::int_<pow_::value> card; - }; - - template < unsigned n_bits > - struct helper_card_< false, n_bits > - { - typedef metal::int_<0> card; - }; - - } // end of namespace mln::trait::internal - - - template <unsigned n_bits> + template <typename E> struct value_integer_ { - typedef typename internal::helper_card_<(n_bits <= 16), n_bits>::card card; + private: + enum { n = 8 * sizeof(E) }; + public: + + enum { + nbits = n, + card = mln_value_card_from_(n) + }; - typedef metal::int_<n_bits> nbits; typedef trait::value::nature::integer nature; typedef trait::value::kind::data kind; - typedef mln_value_quant_from_card(card) quant; + typedef mln_value_quant_from_(card) quant; + + static const E min() { return std::numeric_limits<E>::min(); } + static const E max() { return std::numeric_limits<E>::max(); } + typedef float sum; }; + } // end of namespace mln::trait::internal + - template <> struct value_< unsigned char > : value_integer_< 8 * sizeof(unsigned char) > {}; - template <> struct value_< signed char > : value_integer_< 8 * sizeof( signed char) > {}; - template <> struct value_< unsigned short > : value_integer_< 8 * sizeof(unsigned short) > {}; - template <> struct value_< signed short > : value_integer_< 8 * sizeof( signed short) > {}; - template <> struct value_< unsigned int > : value_integer_< 8 * sizeof(unsigned int) > {}; - template <> struct value_< signed int > : value_integer_< 8 * sizeof( signed int) > {}; - template <> struct value_< unsigned long > : value_integer_< 8 * sizeof(unsigned long) > {}; - template <> struct value_< signed long > : value_integer_< 8 * sizeof( signed long) > {}; + template <> struct value_< unsigned char > : internal::value_integer_< unsigned char > {}; + template <> struct value_< signed char > : internal::value_integer_< signed char > {}; + template <> struct value_< unsigned short > : internal::value_integer_< unsigned short > {}; + template <> struct value_< signed short > : internal::value_integer_< signed short > {}; + template <> struct value_< unsigned int > : internal::value_integer_< unsigned int > {}; + template <> struct value_< signed int > : internal::value_integer_< signed int > {}; + template <> struct value_< unsigned long > : internal::value_integer_< unsigned long > {}; + template <> struct value_< signed long > : internal::value_integer_< signed long > {}; } // end of namespace mln::trait Index: mln/value/rgb.hh --- mln/value/rgb.hh (revision 1511) +++ mln/value/rgb.hh (working copy) @@ -57,6 +57,34 @@ } + // Fwd decl. + namespace value { + template <unsigned n> struct rgb; + } + + + namespace trait + { + + template <unsigned n> + struct value_< mln::value::rgb<n> > + { + enum { + nbits = 3 * n, + card = mln_value_card_from_(nbits) + }; + + typedef trait::value::nature::vectorial nature; + typedef trait::value::kind::color kind; + typedef mln_value_quant_from_(card) quant; + + typedef metal::vec<3, float> sum; + }; + + } // end of namespace trait + + + namespace value { @@ -129,17 +157,6 @@ - template <unsigned n> - struct props< rgb<n> > - { - static const unsigned nbits = 3 * n; - static const std::size_t card_ = 0; // FIXME: was: metal::math::pow_int<2, nbits>::value; - typedef trait::value::kind::color kind; - typedef metal::vec<3, float> sum; - typedef metal::vec<3, int> interop; - }; - - /*! \brief Print an rgb \p c into the output stream \p ostr. * * \param[in,out] ostr An output stream. Index: mln/value/float01_f.hh --- mln/value/float01_f.hh (revision 1511) +++ mln/value/float01_f.hh (working copy) @@ -36,18 +36,49 @@ # include <iostream> # include <mln/value/internal/value_like.hh> # include <mln/value/concept/floating.hh> -# include <mln/value/props.hh> +# include <mln/value/builtin/floatings.hh> +# include <mln/trait/value_.hh> + namespace mln { - namespace value + // Fwd decls. + namespace value { + struct float01; + struct float01_f; + } + + + namespace trait { - /// Fwd decl. - struct float01; + template <> + struct value_< mln::value::float01_f > + { + typedef trait::value::nature::floating nature; + typedef trait::value::kind::data kind; + typedef trait::value::quant::high quant; + + enum { + nbits = 8 * sizeof(float), + card = 0 + }; + + static const float min() { return 0; } + static const float max() { return 1; } + static const float epsilon() { return mln_epsilon(float); } + + typedef float sum; + }; + + } // end of namespace trait + + namespace value + { + /// Class for floating values restricted to the interval [0..1]. struct float01_f : @@ -75,19 +106,6 @@ }; - template <> - struct props< float01_f > - { - static const std::size_t card_ = 0; - static const float min() { return 0; } - static const float max() { return 1; } - //static const unsigned nbits = n; - typedef trait::value::kind::data kind; - typedef float sum; - typedef float interop; - }; - - # ifndef MLN_INCLUDE_ONLY // Float01_F. Index: mln/value/label.hh --- mln/value/label.hh (revision 1511) +++ mln/value/label.hh (working copy) @@ -34,19 +34,53 @@ */ # include <mln/metal/math/pow.hh> -# include <mln/value/internal/value_like.hh> # include <mln/value/concept/symbolic.hh> +# include <mln/value/internal/value_like.hh> +# include <mln/value/internal/convert.hh> # include <mln/value/internal/encoding.hh> -# include <mln/value/props.hh> +# include <mln/trait/value_.hh> namespace mln { - namespace value + // Fwd decl. + namespace value { + template <unsigned n> struct label; + } + + + + namespace trait + { + + template <unsigned n> + struct value_< mln::value::label<n> > { + private: + typedef mln::value::label<n> self_; + public: + + enum { + nbits = n, + card = mln_value_card_from_(n) + }; + + typedef trait::value::nature::symbolic nature; + typedef trait::value::kind::label kind; + typedef mln_value_quant_from_(card) quant; + + static const self_ min() { return 0; } + static const self_ max() { return card - 1; } + }; + + } // end of namespace trait + + namespace value + { + /*! \brief Label value class. * @@ -125,23 +159,6 @@ - - template <unsigned n> - struct props< label<n> > - { - 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; - typedef trait::value::kind::label kind; - }; - - - - - - - /*! \brief Print a label \p l into the output stream \p ostr. * * \param[in,out] ostr An output stream. @@ -217,14 +234,6 @@ } template <unsigned n> - const label<n> - props< label<n> >::min = 0; - - template <unsigned n> - const label<n> - 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) { return ostr << i.to_enc(); Index: mln/fun/v2v/saturate.hh --- mln/fun/v2v/saturate.hh (revision 1511) +++ mln/fun/v2v/saturate.hh (working copy) @@ -35,7 +35,7 @@ # include <mln/core/concept/function.hh> # include <mln/metal/converts_to.hh> -# include <mln/value/props.hh> +# include <mln/trait/value_.hh> namespace mln Index: mln/morpho/Rd.hh --- mln/morpho/Rd.hh (revision 1511) +++ mln/morpho/Rd.hh (working copy) @@ -39,7 +39,7 @@ # include <mln/core/concept/image.hh> # include <mln/core/concept/neighborhood.hh> -# include <mln/value/props.hh> +# include <mln/trait/value_.hh> # include <mln/level/fill.hh> # include <mln/level/compare.hh> Index: mln/io/pnm/save_header.hh --- mln/io/pnm/save_header.hh (revision 1511) +++ mln/io/pnm/save_header.hh (working copy) @@ -61,6 +61,10 @@ file << unsigned(mln_max(V)) << std::endl; } + void save_max_val(bool&, std::ofstream& file) + { + } + template <unsigned int n> void save_max_val(value::rgb<n>&, std::ofstream& file) { @@ -80,7 +84,11 @@ abort(); } file << "P" << type << std::endl; - file << "# milena" << std::endl; + file << "# Generated by milena 1.0 http://olena.lrde.epita.fr" << std::endl; + file << "# EPITA Research and Development Laboratory (LRDE)" << std::endl; + // We have a two-line comment because xv is buggy for some + // tiny binary images and their workaround is to have such a + // two-line comment... file << geom::ncols(ima) << ' ' << geom::nrows(ima) << std::endl; mln_value(I) i; Index: mln/io/pnm/load.hh --- mln/io/pnm/load.hh (revision 1511) +++ mln/io/pnm/load.hh (working copy) @@ -189,9 +189,9 @@ read_header(type_ - 3, type_, file, type, nrows, ncols, maxval); - if (value::props< mln_value(I) >::max() != maxval) + if (mln_max(mln_value(I)) != maxval) { - std::cerr << "max ref : " << value::props< mln_value(I) >::max() + std::cerr << "max ref : " << mln_max(mln_value(I)) << "max image : " << maxval << std::endl; Index: mln/io/pbm/save.hh --- mln/io/pbm/save.hh (revision 1511) +++ mln/io/pbm/save.hh (working copy) @@ -80,29 +80,30 @@ io::pnm::save_header(PBM, ima, filename, file); - const int - min_row = geom::min_row(ima), - max_row = geom::max_row(ima), - min_col = geom::min_col(ima), - max_col = geom::max_col(ima); - point2d p; - + int ncols = geom::ncols(ima); + int col = 0; + int stride = 0; unsigned char c = 0; - int i = 0; - mln_piter(I) it(ima.domain()); - for_all(it) + mln_fwd_piter(I) p(ima.domain()); + for_all(p) + { + c <<= 1; + c += (ima(p) = true ? 1 : 0); // FIXME: Swap. + if (++col >= ncols) { - if (i && (i = 8)) + c <<= (8 - stride - 1); + file << c; + c = col = stride = 0; + } + else + if (++stride >= 8) { - file.write((char*)(&c), 1); - i = 0; + file << c; + c = stride = 0; } - c = c * 2; - c += ima(it); - ++i; } - file.write((char*)(&c), 1); + mln_postcondition(stride = 0); } } // end of namespace mln::io::impl Index: mln/norm/l1.hh --- mln/norm/l1.hh (revision 1511) +++ mln/norm/l1.hh (working copy) @@ -47,19 +47,19 @@ /// L1-norm of a vector \a vec. /// \{ template <unsigned n, typename C> - mln_value_sum(C) l1(const C (&vec)[n]); + mln_sum(C) l1(const C (&vec)[n]); template <unsigned n, typename C> - mln_value_sum(C) l1(const metal::vec<n,C>& vec); + mln_sum(C) l1(const metal::vec<n,C>& vec); /// \} /// L1-norm distance between vectors \a vec1 and \a vec2. /// \{ template <unsigned n, typename C> - mln_value_sum(C) l1_distance(const C (&vec1)[n], const C (&vec2)[n]); + mln_sum(C) l1_distance(const C (&vec1)[n], const C (&vec2)[n]); template <unsigned n, typename C> - mln_value_sum(C) l1_distance(const metal::vec<n,C>& vec1, + mln_sum(C) l1_distance(const metal::vec<n,C>& vec1, const metal::vec<n,C>& vec2); /// \} @@ -69,20 +69,20 @@ namespace impl { template <unsigned n, typename C, typename V> - mln_value_sum(C) + mln_sum(C) l1_(const V& vec) { - mln_value_sum(C) m = 0; + mln_sum(C) m = 0; for (unsigned i = 0; i < n; ++i) m += mln::math::abs (vec[i]); return m; } template <unsigned n, typename C, typename V> - mln_value_sum(C) + mln_sum(C) l1_distance_(const V& vec1, const V& vec2) { - mln_value_sum(C) d = 0; + mln_sum(C) d = 0; for (unsigned i = 0; i < n; ++i) d += mln::math::abs (vec1[i] - vec2[i]); return d; @@ -96,28 +96,28 @@ `----------*/ template <unsigned n, typename C> - mln_value_sum(C) + mln_sum(C) l1(const C (&vec)[n]) { return impl::l1_<n, C>(vec); } template <unsigned n, typename C> - mln_value_sum(C) + mln_sum(C) l1(const metal::vec<n,C>& vec) { return impl::l1_<n, C>(vec); } template <unsigned n, typename C> - mln_value_sum(C) + mln_sum(C) l1_distance(const C (&vec1)[n], const C (&vec2)[n]) { return impl::l1_distance_<n, C>(vec1, vec2); } template <unsigned n, typename C> - mln_value_sum(C) + mln_sum(C) l1_distance(const metal::vec<n,C>& vec1, const metal::vec<n,C>& vec2) { return impl::l1_distance_<n, C>(vec1, vec2); Index: mln/norm/l2.hh --- mln/norm/l2.hh (revision 1511) +++ mln/norm/l2.hh (working copy) @@ -48,19 +48,19 @@ /// L2-norm of a vector \a vec. /// \{ template <unsigned n, typename C> - mln_value_sum(C) l2(const C (&vec)[n]); + mln_sum(C) l2(const C (&vec)[n]); template <unsigned n, typename C> - mln_value_sum(C) l2(const metal::vec<n,C>& vec); + mln_sum(C) l2(const metal::vec<n,C>& vec); /// \} /// L2-norm distance between vectors \a vec1 and \p vec2. /// \{ template <unsigned n, typename C> - mln_value_sum(C) l2_distance(const C (&vec1)[n], const C (&vec2)[n]); + mln_sum(C) l2_distance(const C (&vec1)[n], const C (&vec2)[n]); template <unsigned n, typename C> - mln_value_sum(C) l2_distance(const metal::vec<n,C>& vec1, + mln_sum(C) l2_distance(const metal::vec<n,C>& vec1, const metal::vec<n,C>& vec2); /// \} @@ -71,20 +71,20 @@ { template <unsigned n, typename C, typename V> - mln_value_sum(C) + mln_sum(C) l2_(const V& vec) { - mln_value_sum(C) m = 0; + mln_sum(C) m = 0; for (unsigned i = 0; i < n; ++i) m += mln::math::sqr(vec[i]); return mln::math::sqrt(m); } template <unsigned n, typename C, typename V> - mln_value_sum(C) + mln_sum(C) l2_distance_(const V& vec1, const V& vec2) { - mln_value_sum(C) d = 0; + mln_sum(C) d = 0; for (unsigned i = 0; i < n; ++i) d += mln::math::sqr(vec1[i] - vec2[i]); return mln::math::sqrt(d); @@ -98,28 +98,28 @@ `----------*/ template <unsigned n, typename C> - mln_value_sum(C) + mln_sum(C) l2(const C (&vec)[n]) { return impl::l2_<n, C>(vec); } template <unsigned n, typename C> - mln_value_sum(C) + mln_sum(C) l2(const metal::vec<n,C>& vec) { return impl::l2_<n, C>(vec); } template <unsigned n, typename C> - mln_value_sum(C) + mln_sum(C) l2_distance(const C (&vec1)[n], const C (&vec2)[n]) { return impl::l2_distance_<n, C>(vec1, vec2); } template <unsigned n, typename C> - mln_value_sum(C) + mln_sum(C) l2_distance(const metal::vec<n,C>& vec1, const metal::vec<n,C>& vec2) { return impl::l2_distance_<n, C>(vec1, vec2);
participants (1)
-
Thierry Geraud