3895: Add histo 'point from value' fun v2v 'component' functions.
https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Add histo 'point from value' fun v2v 'component' functions. * mln/trait/value/internal/comp.hh (on): New method. (mln_trait_value_comp): Remove; already define outside internal. (todo): New. * mln/trait/value/comp.hh: Upgrade doc style. * tests/trait/value/comp.cc: Fix doc. * mln/value/hsl.hh (trait): Update. * mln/value/rgb.hh (trait): Update. * mln/fun/i2v/value_at_index.hh: Layout. * mln/fun/v2i/index_of_value.hh: Layout. * mln/fun/v2v/component.hh: New. * tests/fun/v2v/component.cc: New. * tests/fun/ops.cc: New. * tests/fun/Makefile.am: Update. * mln/core/grids.hh: Upgrade doc style. * sandbox/theo/experimental/histo_image.cc: Copy as... * mln/histo/point_from_value.hh: ...this new file. Keep only point_from_value. Revamp. * mln/histo/all.hh: Layout. Update. * tests/histo/compute.cc (todo): New. * tests/histo/point_from_value.cc: New. * tests/histo/Makefile.am: Update. mln/core/grids.hh | 10 mln/fun/v2v/component.hh | 80 +++++++ mln/histo/all.hh | 5 mln/histo/point_from_value.hh | 444 +++++++-------------------------------- mln/trait/value/comp.hh | 2 mln/trait/value/internal/comp.hh | 177 +++++++++++++-- mln/value/hsl.hh | 11 mln/value/rgb.hh | 9 tests/fun/Makefile.am | 6 tests/fun/ops.cc | 43 +++ tests/fun/v2v/component.cc | 75 ++++++ tests/histo/Makefile.am | 2 tests/histo/compute.cc | 5 tests/histo/point_from_value.cc | 53 ++++ tests/trait/value/comp.cc | 2 15 files changed, 531 insertions(+), 393 deletions(-) Index: mln/trait/value/internal/comp.hh --- mln/trait/value/internal/comp.hh (revision 3894) +++ mln/trait/value/internal/comp.hh (working copy) @@ -30,16 +30,16 @@ /// \file mln/trait/value/internal/comp.hh /// -/// Include all internals for value traits. +/// Include all internals for comp value trait. +/// +/// \todo Revamp to directly access to the most internal helper +/// instead of bumping from one helper to another. # include <mln/metal/bool.hh> # include <mln/metal/if.hh> -# define mln_trait_value_comp(T, i) typename mln::trait::value::internal::comp< T, i >::ret - - namespace mln { @@ -60,33 +60,131 @@ // bind_comp< T, i > - template <typename Tr, unsigned i> + template <typename T, typename Tr, unsigned i> struct bind_comp; - template <typename Tr> struct bind_comp< Tr, 0 > { typedef typename Tr::comp_0 ret; }; - template <typename Tr> struct bind_comp< Tr, 1 > { typedef typename Tr::comp_1 ret; }; - template <typename Tr> struct bind_comp< Tr, 2 > { typedef typename Tr::comp_2 ret; }; - template <typename Tr> struct bind_comp< Tr, 3 > { typedef typename Tr::comp_3 ret; }; - template <typename Tr> struct bind_comp< Tr, 4 > { typedef typename Tr::comp_4 ret; }; - template <typename Tr> struct bind_comp< Tr, 5 > { typedef typename Tr::comp_5 ret; }; - template <typename Tr> struct bind_comp< Tr, 6 > { typedef typename Tr::comp_6 ret; }; - template <typename Tr> struct bind_comp< Tr, 7 > { typedef typename Tr::comp_7 ret; }; - template <typename Tr> struct bind_comp< Tr, 8 > { typedef typename Tr::comp_8 ret; }; - template <typename Tr> struct bind_comp< Tr, 9 > { typedef typename Tr::comp_9 ret; }; + template <typename T, typename Tr> + struct bind_comp< T, Tr, 0 > + { + typedef typename Tr::comp_0 ret; + static ret on(const T& v) + { + return Tr::get_comp_0(v); + } + }; + + template <typename T, typename Tr> + struct bind_comp< T, Tr, 1 > + { + typedef typename Tr::comp_1 ret; + static ret on(const T& v) + { + return Tr::get_comp_1(v); + } + }; + + template <typename T, typename Tr> + struct bind_comp< T, Tr, 2 > + { + typedef typename Tr::comp_2 ret; + static ret on(const T& v) + { + return Tr::get_comp_2(v); + } + }; + + template <typename T, typename Tr> + struct bind_comp< T, Tr, 3 > + { + typedef typename Tr::comp_3 ret; + static ret on(const T& v) + { + return Tr::get_comp_3(v); + } + }; + + template <typename T, typename Tr> + struct bind_comp< T, Tr, 4 > + { + typedef typename Tr::comp_4 ret; + static ret on(const T& v) + { + return Tr::get_comp_4(v); + } + }; + + template <typename T, typename Tr> + struct bind_comp< T, Tr, 5 > + { + typedef typename Tr::comp_5 ret; + static ret on(const T& v) + { + return Tr::get_comp_5(v); + } + }; + + template <typename T, typename Tr> + struct bind_comp< T, Tr, 6 > + { + typedef typename Tr::comp_6 ret; + static ret on(const T& v) + { + return Tr::get_comp_6(v); + } + }; + + template <typename T, typename Tr> + struct bind_comp< T, Tr, 7 > + { + typedef typename Tr::comp_7 ret; + static ret on(const T& v) + { + return Tr::get_comp_7(v); + } + }; + + template <typename T, typename Tr> + struct bind_comp< T, Tr, 8 > + { + typedef typename Tr::comp_8 ret; + static ret on(const T& v) + { + return Tr::get_comp_8(v); + } + }; + + template <typename T, typename Tr> + struct bind_comp< T, Tr, 9 > + { + typedef typename Tr::comp_9 ret; + static ret on(const T& v) + { + return Tr::get_comp_9(v); + } + }; // get_comp< T, i, dim > - template <typename C, typename Tr, unsigned i> + template <typename T, typename C, typename Tr, unsigned i> struct get_comp_helper { typedef C ret; + static ret on(const T& v) + { + return v[i]; + } }; - template <typename Tr, unsigned i> - struct get_comp_helper< void, Tr, i > + template <typename T, typename Tr, unsigned i> + struct get_comp_helper< T, void, Tr, i > + { + typedef bind_comp<T, Tr, i> helper; + typedef typename helper::ret ret; + static ret on(const T& v) { - typedef typename bind_comp<Tr, i>::ret ret; + return helper::on(v); + } }; template <typename T, unsigned i, unsigned dim> @@ -94,13 +192,44 @@ { typedef mln::trait::value_<T> Tr; typedef typename Tr::comp C; - typedef typename get_comp_helper<C, Tr, i>::ret ret; + typedef get_comp_helper<T, C, Tr, i> helper; + typedef typename helper::ret ret; + + static ret on(const T& v) + { + return helper::on(v); + } + }; + + + template <typename T, unsigned i, unsigned dim> + struct get_comp< T[dim], i, dim > + { + typedef T ret; + + static ret on(const T (&v)[dim]) + { + return v[i]; + } }; template <typename T> struct get_comp< T, 0, 1 > { typedef T ret; + + static ret on(const T& v) + { + return v; + } + }; + + template <typename T> + struct get_comp< T[1], 0, 1 > // Disambiguate between both + // previous specialization. + { + typedef T ret; + static ret on(const T (&v)[1]) { return v[0]; } }; @@ -111,7 +240,13 @@ : private metal::bool_< (i < mln::trait::value_<T>::dim) >::check_t { enum { dim = mln::trait::value_<T>::dim }; - typedef typename get_comp<T, i, dim>::ret ret; + typedef get_comp<T, i, dim> helper; + typedef typename helper::ret ret; + + static ret on(const T& v) + { + return helper::on(v); + } }; } // end of namespace mln::trait::value::internal Index: mln/trait/value/comp.hh --- mln/trait/value/comp.hh (revision 3894) +++ mln/trait/value/comp.hh (working copy) @@ -30,7 +30,7 @@ /// \file mln/trait/value/comp.hh /// -/// Access to the i-th component type of a given type. +/// \brief Access to the i-th component type of a given type. # include <mln/trait/value/internal/comp.hh> Index: mln/histo/all.hh --- mln/histo/all.hh (revision 3894) +++ mln/histo/all.hh (working copy) @@ -47,12 +47,13 @@ namespace generic {} } - } - } + # include <mln/histo/compute.hh> # include <mln/histo/array.hh> +# include <mln/histo/point_from_value.hh> + #endif // ! MLN_HISTO_ALL_HH Index: mln/histo/point_from_value.hh --- mln/histo/point_from_value.hh (revision 3870) +++ mln/histo/point_from_value.hh (working copy) @@ -1,421 +1,145 @@ -#include <mln/value/int_u8.hh> -#include <mln/value/int_s.hh> -#include <mln/value/rgb8.hh> +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// +// 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_HISTO_POINT_FROM_VALUE_HH +# define MLN_HISTO_POINT_FROM_VALUE_HH + +/// \file mln/histo/point_from_value.hh +/// +/// Function 'point from value'. + +# include <mln/core/grids.hh> +# include <mln/core/point.hh> +# include <mln/fun/v2i/index_of_value.hh> +# include <mln/fun/v2v/component.hh> #include <mln/trait/value/comp.hh> -#include <mln/core/alias/box1d.hh> -#include <mln/core/image/image1d.hh> -#include <mln/core/image/image3d.hh> - -#include <mln/core/concept/function.hh> -#include <mln/metal/ands.hh> +# define mln_histo_point_type_from(T) typename mln::histo::point_type_from<T>::ret namespace mln { - - // -------------------------------------------------- fun - - - namespace fun - { - - // . . . . . . . . . . . . . . . v2v:: value <-> index - - // This is a revamp of mln/value/internal/convert.hh. It remains - // to be updated with Fred's new function writting. Then we'll be - // able to make it better, i.e., to handle the different cases - // properly. Precisely a case for scalars with low quantization - // (with a special encoding like quantized float, or not), a case - // for vectors with low quant, etc. - - namespace v2v + namespace histo { - // value -> index template <typename T> - struct index_of_value : Function_v2v< index_of_value<T> >, - private metal::bool_<(mln_dim(T) == 1)>::check_t + struct point_type_from { - typedef unsigned result; - unsigned operator()(const T& v) const - { - return unsigned( int(v) - int(mln_min(T)) ); - } - }; + private: + enum { d = mln_dim(T) }; + typedef mln_regular_grid_from_dim(d) G; - template <> - struct index_of_value<bool> : Function_v2v< index_of_value<bool> > - { - typedef unsigned result; - unsigned operator()(bool b) const - { - return b ? 1u : 0u; - } + public: + typedef mln::point<G, def::coord> ret; }; - template <typename T> - unsigned - meta_index_of_value(const T& v) - { - index_of_value<T> f; - return f(v); - } - - // index -> value template <typename T> - struct value_at_index : Function_v2v< value_at_index<T> >, - private metal::bool_<(mln_dim(T) == 1)>::check_t - { - typedef T result; - T operator()(unsigned i) const - { - return T( int(mln_min(T)) + int(i) ); - } - }; - - template <> - struct value_at_index<bool> : Function_v2v< value_at_index<bool> > - { - typedef bool result; - bool operator()(unsigned i) const + struct point_from_value : Function_v2v< point_from_value<T> > { - mln_precondition(i < 2); - return i == 1u ? true : false; - } + typedef mln_histo_point_type_from(T) result; + result operator()(const T& v) const; }; + template <typename T> + mln_histo_point_type_from(T) + meta_point_from_value(const T& v); - // . . . . . . . . . . . . . . . value -> point n-D +# ifndef MLN_INCLUDE_ONLY namespace internal { - // FIXME: It can be straightforwardly written using - // fun::ith_component. Yet there is no test file for this - // function. - - template <unsigned dim, typename T> + template <unsigned d> struct point_from_value; - template <typename T> - struct point_from_value< 1, T > + template <> + struct point_from_value< 1 > { - static point1d run(const T& v) + template <typename T, typename P> + static void run(const T& v, P& p) { - return point1d(meta_index_of_value(v)); + p[0] = fun::v2i::meta_index_of_value(v); } }; - template <typename T> - struct point_from_value< 2, T > + template <> + struct point_from_value< 2 > { - static point2d run(const T& v) + template <typename T, typename P> + static void run(const T& v, P& p) { - return point2d(meta_index_of_value(v[0]), - meta_index_of_value(v[1])); + p[0] = fun::v2i::meta_index_of_value( fun::v2v::component<T,0>()(v) ); + p[1] = fun::v2i::meta_index_of_value( fun::v2v::component<T,1>()(v) ); } }; - template <typename T> - struct point_from_value< 3, T > + template <> + struct point_from_value< 3 > { - static point3d run(const T& v) + template <typename T, typename P> + static void run(const T& v, P& p) { - return point3d(meta_index_of_value(v[0]), - meta_index_of_value(v[1]), - meta_index_of_value(v[2])); + p[0] = fun::v2i::meta_index_of_value( fun::v2v::component<T,0>()(v) ); + p[1] = fun::v2i::meta_index_of_value( fun::v2v::component<T,1>()(v) ); + p[2] = fun::v2i::meta_index_of_value( fun::v2v::component<T,2>()(v) ); } }; - } // mln::fun::v2v::internal + } // end of namespace mln::histo::internal template <typename T> - struct point_from_value : Function_v2v< point_from_value<T> > + inline + typename point_from_value<T>::result + point_from_value<T>::operator()(const T& v) const { - enum { d = mln_dim(T) }; - typedef mln_regular_grid_from_dim(d) G; - typedef mln::point<G, def::coord> result; - - result operator()(const T& v) const - { - return internal::point_from_value<d,T>::run(v); + mln_histo_point_type_from(T) p; + internal::point_from_value<mln_dim(T)>::run(v, p); + return p; } - index_of_value<T> f_; - }; - template <typename T> - mln_result(point_from_value<T>) + mln_histo_point_type_from(T) meta_point_from_value(const T& v) { point_from_value<T> f; return f(v); } - } // mln::fun::v2v - - - - - // . . . . . . . . . . . . . . . p2p::fold* - - namespace p2p - { - - struct fold1d : Function_p2p< fold1d > - { - typedef point1d result; - result operator()(const point1d& p) const - { - point1d tmp(p[0] % b.len(0)); - return tmp; - } - box1d b; - }; +# endif // ! MLN_INCLUDE_ONLY - template <bool along_0, bool along_1> - struct fold2d : Function_p2p< fold2d<along_0,along_1> > - { - typedef point2d result; - result operator()(const point2d& p) const - { - point2d tmp(along_0 ? p[0] % b.len(0) : p[0], - along_1 ? p[1] % b.len(1) : p[1]); - return tmp; - } - box2d b; - }; + } // end of namespace mln::histo - template <bool along_0, bool along_1, bool along_2> - struct fold3d : Function_p2p< fold3d<along_0,along_1,along_2> > - { - typedef point3d result; - result operator()(const point3d& p) const - { - point3d tmp(along_0 ? p[0] % b.len(0) : p[0], - along_1 ? p[1] % b.len(1) : p[1], - along_2 ? p[2] % b.len(2) : p[2]); - return tmp; - } - box3d b; - }; - - } // mln::fun::p2p - - - } // mln::fun - - - // -------------------------------------------------- value - - - namespace value - { - - template <unsigned n, int inf, int sup> - struct circular - { - }; - - - namespace internal - { - template <typename T> - struct is_circular_helper : metal::false_ - {}; - - template <unsigned n, int inf, int sup> - struct is_circular_helper< circular<n,inf,sup> > : metal::true_ - {}; - - template <typename T> - struct is_circular : is_circular_helper<T>::eval - { - }; +} // end of namespace mln - } // mln::value::internal - } // mln::value - - - namespace trait - { - - template <unsigned n, int inf, int sup> - struct value_< mln::value::circular<n, inf, sup> > - { - enum { - dim = 1, - nbits = n, - card = mln_value_card_from_(n) - }; - // ... - }; - - } // end of namespace trait - - - // -------------------------------------------------- histo - - - namespace histo - { - - namespace internal - { - - template <int dim, typename T> - struct image_from_value_helper - { - }; - - // dim = 1 - - template <typename T, bool is_c> - struct image_from_value_helper_1; - - template <typename T> - struct image_from_value_helper_1< T, false > - { - typedef image1d<unsigned> ret; - - static ret get_image() - { - ret tmp(mln_card(T)); - return tmp; - } - }; - - template <typename T> - struct image_from_value_helper_1< T, true > - { - typedef void ret; - }; - - template <typename T> - struct image_from_value_helper< 1, T > - { - enum { is_c = value::internal::is_circular<T>::value }; - typedef image_from_value_helper_1< T, is_c > helper; - }; - - // dim = 3 - - template <typename C0, bool is_c0, - typename C1, bool is_c1, - typename C2, bool is_c2, - typename T> - struct image_from_value_helper_3; - - template <typename C0, typename C1, typename C2, - typename T> - struct image_from_value_helper_3< C0, false, - C1, false, - C2, false, - T > - { - typedef image3d<unsigned> ret; - static ret get_image() - { - ret tmp(mln_card(C0), mln_card(C1), mln_card(C2)); - return tmp; - } - }; - - template <typename C0, typename C1, typename C2, - typename T> - struct image_from_value_helper_3< C0, true, - C1, false, - C2, false, - T > - { - typedef void ret; - }; - - template <typename T> - struct image_from_value_helper< 3, T > - { - typedef mln_trait_value_comp(T, 0) C0; - typedef mln_trait_value_comp(T, 1) C1; - typedef mln_trait_value_comp(T, 2) C2; - typedef image_from_value_helper_3< C0, value::internal::is_circular<C0>::value, - C1, value::internal::is_circular<C1>::value, - C2, value::internal::is_circular<C2>::value, - T > helper; - }; - - template <typename T> - struct image_from_value_ // Entry point. - { - typedef typename image_from_value_helper<mln_dim(T), T>::helper helper; - }; - - - } // mln::histo::internal - - template <typename T> - struct image_from_value : internal::image_from_value_<T>::helper - { - }; - - - - // First code: the result of this function shall be replaced by - // an histo::image<T> where T is mln_value(I). As a consequence, - // we will not have to call meta_point_from_value... - - template <typename I> - typename image_from_value<mln_value(I)>::ret - compute_image(const Image<I>& input_) - { - const I& input = exact(input_); - typedef image_from_value<mln_value(I)> helper; - typename helper::ret h = helper::get_image(); - - mln_piter(I) p(input.domain()); - for_all(p) - ++h( fun::v2v::meta_point_from_value(input(p)) ); - - return h; - } - - } // mln::histo - -} // mln - - -int main() -{ - using namespace mln; - - { - typedef bool T; - std::cout << histo::image_from_value<T>::get_image().domain() << std::endl; - } - - { - typedef unsigned char T; - std::cout << histo::image_from_value<T>::get_image().domain() << std::endl; - } - - { - typedef value::int_s<3> T; - std::cout << histo::image_from_value<T>::get_image().domain() << std::endl; - } - - { - typedef value::rgb8 T; - std::cout << histo::image_from_value<T>::get_image().domain() << std::endl; - } - - { - // typedef value::circular<8,0,9> T; - } -} +#endif // ! MLN_HISTO_POINT_FROM_VALUE_HH Property changes on: mln/histo/point_from_value.hh ___________________________________________________________________ Added: svn:mergeinfo Index: mln/core/grids.hh --- mln/core/grids.hh (revision 3894) +++ mln/core/grids.hh (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008, 2009 EPITA Research and Development +// Laboratory (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -28,10 +29,9 @@ #ifndef MLN_CORE_GRIDS_HH # define MLN_CORE_GRIDS_HH -/*! \file mln/core/grids.hh - * - * \brief Definition of some grid classes. - */ +/// \file mln/core/grids.hh +/// +/// \brief Definition of some grid classes. # include <mln/core/concept/regular_grid.hh> # include <mln/core/def/coord.hh> Index: mln/value/hsl.hh --- mln/value/hsl.hh (revision 3894) +++ mln/value/hsl.hh (working copy) @@ -28,10 +28,12 @@ /// \file mln/value/hsl.hh /// -/// Color class. +/// \brief HSL color class. +/// +/// \todo Write a better doc. /// -/// \todo write a better doc. /// \todo Cleanup/Revamp! +/// \todo Factor comp_i and get_comp_i in a base class. #ifndef MLN_VALUE_HSL_HH # define MLN_VALUE_HSL_HH @@ -139,10 +141,15 @@ typedef trait::value::kind::color kind; typedef mln_value_quant_from_(card) quant; + typedef void comp; typedef H comp_0; typedef S comp_1; typedef L comp_2; + template <typename V> static comp_0 get_comp_0(const V& v) { return v.hue(); } + template <typename V> static comp_1 get_comp_1(const V& v) { return v.sat(); } + template <typename V> static comp_2 get_comp_2(const V& v) { return v.lum(); } + // typedef algebra::vec<3, float> sum; typedef mln::value::hsl_<H,S,L> sum; }; Index: mln/value/rgb.hh --- mln/value/rgb.hh (revision 3894) +++ mln/value/rgb.hh (working copy) @@ -220,7 +220,14 @@ typedef trait::value::kind::color kind; typedef mln_value_quant_from_(card) quant; - typedef mln::value::int_u<n> comp; + typedef void comp; + typedef mln::value::int_u<n> comp_0; + typedef mln::value::int_u<n> comp_1; + typedef mln::value::int_u<n> comp_2; + + template <typename V> static comp_0 get_comp_0(const V& v) { return v.red(); } + template <typename V> static comp_1 get_comp_1(const V& v) { return v.green(); } + template <typename V> static comp_2 get_comp_2(const V& v) { return v.blue(); } typedef algebra::vec<dim, float> sum; Index: mln/fun/i2v/value_at_index.hh Index: mln/fun/v2i/index_of_value.hh Index: mln/fun/v2v/component.hh --- mln/fun/v2v/component.hh (revision 0) +++ mln/fun/v2v/component.hh (revision 0) @@ -0,0 +1,80 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// +// 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_FUN_V2V_COMPONENT_HH +# define MLN_FUN_V2V_COMPONENT_HH + +/// \file mln/fun/v2v/component.hh +/// +/// Functor that accesses the i-th component of a value. + +# include <mln/core/concept/function.hh> +# include <mln/trait/value_.hh> +# include <mln/trait/value/comp.hh> +# include <mln/value/builtin/all.hh> + + +namespace mln +{ + + namespace fun + { + + namespace v2v + { + + /// \brief Functor that accesses the i-th component of a value. + // + template <typename T, unsigned i> + struct component : public Function_v2v< component<T,i> >, + private metal::bool_<(i <= trait::value_<T>::dim)>::check_t + { + typedef mln_trait_value_comp(T, i) result; + result operator()(const T& v) const; + }; + + +# ifndef MLN_INCLUDE_ONLY + + template <typename T, unsigned i> + inline + typename component<T,i>::result + component<T,i>::operator()(const T& v) const + { + return trait::value::internal::comp<T,i>::on(v); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::fun::v2v + + } // end of namespace mln::fun + +} // end of namespace mln + + +#endif // ! MLN_FUN_V2V_COMPONENT_HH Index: tests/trait/value/comp.cc --- tests/trait/value/comp.cc (revision 3894) +++ tests/trait/value/comp.cc (working copy) @@ -27,7 +27,7 @@ /// \file tests/trait/value/comp.cc /// -/// Tests on mln_trait_value_comp. +/// \brief Tests on mln_trait_value_comp. /// /// \todo Add tests on some actual heterogeneous types. Index: tests/histo/compute.cc --- tests/histo/compute.cc (revision 3894) +++ tests/histo/compute.cc (working copy) @@ -29,6 +29,11 @@ /// \file tests/histo/compute.cc /// /// Tests on mln::accu::histo and mln::histo::array. +/// +/// \todo Just test *one* file (here: compute.hh); other features +/// should also be tested but in a dedicated test file! +/// +/// \todo Remove echos. #include <iterator> #include <sstream> Index: tests/histo/Makefile.am --- tests/histo/Makefile.am (revision 3894) +++ tests/histo/Makefile.am (working copy) @@ -4,9 +4,11 @@ check_PROGRAMS = \ compute \ + point_from_value \ to_image1d compute_SOURCES = compute.cc +point_from_value_SOURCES = point_from_value.cc to_image1d_SOURCES = to_image1d.cc TESTS = $(check_PROGRAMS) Index: tests/histo/point_from_value.cc --- tests/histo/point_from_value.cc (revision 0) +++ tests/histo/point_from_value.cc (revision 0) @@ -0,0 +1,53 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// +// 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/point_from_value.cc +/// +/// \brief Tests on mln::histo::point_from_value. + +#include <mln/histo/point_from_value.hh> + +#include <mln/core/alias/point1d.hh> +#include <mln/core/alias/point3d.hh> + +#include <mln/value/int_u8.hh> +#include <mln/value/rgb8.hh> + + +int main() +{ + using namespace mln; + + int i = 51; + mln_assertion(histo::meta_point_from_value(i) == point1d(51)); + + value::int_u8 v = 51; + mln_assertion(histo::meta_point_from_value(v) == point1d(51)); + + value::rgb8 c(0,5,1); + mln_assertion(histo::meta_point_from_value(c) == point3d(0,5,1)); +} Index: tests/fun/ops.cc --- tests/fun/ops.cc (revision 0) +++ tests/fun/ops.cc (revision 0) @@ -0,0 +1,43 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// +// 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/fun/ops.cc +/// +/// Test on mln::fun::ops.hh. + +#include <mln/fun/p2b/chess.hh> +#include <mln/fun/ops.hh> + + +int main() +{ + using namespace mln; + + fun::p2b::chess f; + point2d p(0,0); + mln_assertion(f(p) != (! f)(p)); +} Index: tests/fun/Makefile.am --- tests/fun/Makefile.am (revision 3894) +++ tests/fun/Makefile.am (working copy) @@ -11,3 +11,9 @@ v2v \ vv2v \ x2x + + +check_PROGRAMS = \ + ops + +ops_SOURCES = ops.cc Index: tests/fun/v2v/component.cc --- tests/fun/v2v/component.cc (revision 0) +++ tests/fun/v2v/component.cc (revision 0) @@ -0,0 +1,75 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// +// 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/fun/v2v/component.cc +/// +/// \brief Test fun::v2v::component. + +#include <mln/fun/v2v/component.hh> +#include <mln/algebra/vec.hh> +#include <mln/value/rgb8.hh> +#include <mln/value/hsl.hh> + + +int main() +{ + using namespace mln; + + { + fun::v2v::component<int, 0> f; + int i = 51; + mln_assertion(f(i) == 51); + } + { + typedef int V[1]; + V v; + v[0] = 51; + fun::v2v::component<V, 0> f; + mln_assertion(f(v) == 51); + } + { + typedef algebra::vec<2,int> V; + V v; + v[0] = 51; + fun::v2v::component<V, 0> f; + mln_assertion(f(v) == 51); + } + { + typedef value::rgb8 V; + V v; + v.red() = 51; + fun::v2v::component<V, 0> f; + mln_assertion(f(v) == 51); + } + { + typedef value::hsl_<int,int,int> V; + V v; + v.hue() = 51; + fun::v2v::component<V, 0> f; + mln_assertion(f(v) == 51); + } +}
participants (1)
-
Thierry Geraud