3870: Import functions value<->index from sandbox.

https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Import functions value<->index from sandbox. * sandbox/theo/experimental/histo_image.cc: Copy as... * mln/fun/i2v/value_at_index.hh: ...this new file. (value_at_index): Keep only this, layout, and cleanup. * mln/fun/i2v/all.hh: Update. * tests/fun/i2v/array.cc: New. * tests/fun/i2v/value_at_index.cc: New. * tests/fun/i2v/all_to.cc: New. * tests/fun/i2v/Makefile.am: Update. * mln/fun/v2i: New directory. * sandbox/theo/experimental/histo_image.cc: Copy as... * mln/fun/v2i/index_of_value.hh: ...this new file. (index_of_value): Keep only this, layout, and cleanup. * mln/fun/v2i/all.hh: New. * mln/fun/all.hh: Update. * tests/fun/v2i: New directory. * tests/fun/v2i/Makefile.am: New. * tests/fun/v2i/index_of_value.cc: New. mln/fun/all.hh | 5 mln/fun/i2v/all.hh | 6 mln/fun/i2v/value_at_index.hh | 435 ++++------------------------------------ mln/fun/v2i/all.hh | 57 +++++ mln/fun/v2i/index_of_value.hh | 430 +++++---------------------------------- tests/fun/i2v/Makefile.am | 11 + tests/fun/i2v/all_to.cc | 44 ++++ tests/fun/i2v/array.cc | 48 ++++ tests/fun/i2v/value_at_index.cc | 57 +++++ tests/fun/v2i/Makefile.am | 10 tests/fun/v2i/index_of_value.cc | 56 +++++ 11 files changed, 396 insertions(+), 763 deletions(-) Index: mln/fun/i2v/value_at_index.hh --- mln/fun/i2v/value_at_index.hh (revision 3867) +++ mln/fun/i2v/value_at_index.hh (working copy) @@ -1,421 +1,90 @@ -#include <mln/value/int_u8.hh> -#include <mln/value/int_s.hh> -#include <mln/value/rgb8.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> +// 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_I2V_VALUE_AT_INDEX_HH +# define MLN_FUN_I2V_VALUE_AT_INDEX_HH + +/// \file mln/fun/i2v/value_at_index.hh +/// +/// \brief File that define a function that gives an index per value. #include <mln/core/concept/function.hh> -#include <mln/metal/ands.hh> - +#include <mln/trait/value_.hh> 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 - { - - // value -> index - - template <typename T> - struct index_of_value : Function_v2v< index_of_value<T> >, - private metal::bool_<(mln_dim(T) == 1)>::check_t - { - typedef unsigned result; - unsigned operator()(const T& v) const - { - return unsigned( int(v) - int(mln_min(T)) ); - } - }; - - template <> - struct index_of_value<bool> : Function_v2v< index_of_value<bool> > - { - typedef unsigned result; - unsigned operator()(bool b) const - { - return b ? 1u : 0u; - } - }; - - template <typename T> - unsigned - meta_index_of_value(const T& v) + namespace i2v { - 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) ); - } + T operator()(unsigned i) const; }; template <> struct value_at_index<bool> : Function_v2v< value_at_index<bool> > { typedef bool result; - bool operator()(unsigned i) const - { - mln_precondition(i < 2); - return i == 1u ? true : false; - } + bool operator()(unsigned i) const; }; - // . . . . . . . . . . . . . . . value -> point n-D - - - 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> - struct point_from_value; - - template <typename T> - struct point_from_value< 1, T > - { - static point1d run(const T& v) - { - return point1d(meta_index_of_value(v)); - } - }; +# ifndef MLN_INCLUDE_ONLY template <typename T> - struct point_from_value< 2, T > - { - static point2d run(const T& v) + inline + T + value_at_index<T>::operator()(unsigned i) const { - return point2d(meta_index_of_value(v[0]), - meta_index_of_value(v[1])); - } - }; - - template <typename T> - struct point_from_value< 3, T > - { - static point3d run(const T& v) - { - return point3d(meta_index_of_value(v[0]), - meta_index_of_value(v[1]), - meta_index_of_value(v[2])); - } - }; - - } // mln::fun::v2v::internal - - - template <typename T> - struct point_from_value : Function_v2v< point_from_value<T> > - { - 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); - } - - index_of_value<T> f_; - }; - - template <typename T> - mln_result(point_from_value<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; - }; - - 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; - }; - - 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 - { - }; - - } // 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; + return T( int(mln_min(T)) + int(i) ); } - }; - - 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 + inline + bool + value_at_index<bool>::operator()(unsigned i) const { - }; - - - - // 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_precondition(i < 2); + return i == 1u ? true : false; } - } // mln::histo - -} // mln +# endif // ! MLN_INCLUDE_ONLY + } // end of namespace mln::fun::i2v -int main() -{ - using namespace mln; + } // end of namespace mln::fun - { - typedef bool T; - std::cout << histo::image_from_value<T>::get_image().domain() << std::endl; - } +} // end of namespace mln - { - 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_FUN_I2V_VALUE_AT_INDEX_HH Property changes on: mln/fun/i2v/value_at_index.hh ___________________________________________________________________ Added: svn:mergeinfo Index: mln/fun/i2v/all.hh --- mln/fun/i2v/all.hh (revision 3869) +++ mln/fun/i2v/all.hh (working copy) @@ -31,7 +31,7 @@ /// \file mln/fun/i2v/all.hh /// -/// File that includes all functions from index to value. +/// \brief File that includes all integer-to-value functions. namespace mln @@ -40,19 +40,19 @@ namespace fun { - /// \brief Functions from index to value. + /// \brief Namespace of integer-to-value functions. /// /// \ingroup modfun // namespace i2v {} } - } # include <mln/fun/i2v/all_to.hh> # include <mln/fun/i2v/array.hh> +# include <mln/fun/i2v/value_at_index.hh> Index: mln/fun/v2i/index_of_value.hh --- mln/fun/v2i/index_of_value.hh (revision 0) +++ mln/fun/v2i/index_of_value.hh (working copy) @@ -1,421 +1,101 @@ -#include <mln/value/int_u8.hh> -#include <mln/value/int_s.hh> -#include <mln/value/rgb8.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> +// 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_V2I_INDEX_OF_VALUE_HH +# define MLN_FUN_V2I_INDEX_OF_VALUE_HH + +/// \file mln/fun/v2i/index_of_value.hh +/// +/// \brief File that define a function that gives an index per value. #include <mln/core/concept/function.hh> -#include <mln/metal/ands.hh> - +#include <mln/trait/value_.hh> 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 v2i { - // value -> index - template <typename T> struct index_of_value : Function_v2v< index_of_value<T> >, private metal::bool_<(mln_dim(T) == 1)>::check_t { typedef unsigned result; - unsigned operator()(const T& v) const - { - return unsigned( int(v) - int(mln_min(T)) ); - } + unsigned operator()(const T& v) const; }; template <> struct index_of_value<bool> : Function_v2v< index_of_value<bool> > { typedef unsigned result; - unsigned operator()(bool b) const - { - return b ? 1u : 0u; - } + unsigned operator()(bool b) const; }; template <typename T> unsigned - meta_index_of_value(const T& v) - { - index_of_value<T> f; - return f(v); - } + meta_index_of_value(const T& 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 - { - mln_precondition(i < 2); - return i == 1u ? true : false; - } - }; - - - // . . . . . . . . . . . . . . . value -> point n-D - - - 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> - struct point_from_value; - - template <typename T> - struct point_from_value< 1, T > - { - static point1d run(const T& v) - { - return point1d(meta_index_of_value(v)); - } - }; - - template <typename T> - struct point_from_value< 2, T > - { - static point2d run(const T& v) - { - return point2d(meta_index_of_value(v[0]), - meta_index_of_value(v[1])); - } - }; +# ifndef MLN_INCLUDE_ONLY template <typename T> - struct point_from_value< 3, T > - { - static point3d run(const T& v) + inline + unsigned + index_of_value<T>::operator()(const T& v) const { - return point3d(meta_index_of_value(v[0]), - meta_index_of_value(v[1]), - meta_index_of_value(v[2])); + return unsigned( int(v) - int(mln_min(T)) ); } - }; - } // mln::fun::v2v::internal - - - template <typename T> - struct point_from_value : Function_v2v< point_from_value<T> > + inline + unsigned index_of_value<bool>::operator()(bool b) 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); + return b ? 1u : 0u; } - index_of_value<T> f_; - }; - template <typename T> - mln_result(point_from_value<T>) - meta_point_from_value(const T& v) + inline + unsigned + meta_index_of_value(const T& v) { - point_from_value<T> f; + index_of_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; - }; - - 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; - }; - - 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 - { - }; - - } // 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 +# endif // ! MLN_INCLUDE_ONLY - template <typename T> - struct image_from_value : internal::image_from_value_<T>::helper - { - }; + } // end of namespace mln::fun::v2i + } // end of namespace mln::fun +} // end of namespace mln - // 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_FUN_V2I_INDEX_OF_VALUE_HH Property changes on: mln/fun/v2i/index_of_value.hh ___________________________________________________________________ Added: svn:mergeinfo Index: mln/fun/v2i/all.hh --- mln/fun/v2i/all.hh (revision 0) +++ mln/fun/v2i/all.hh (revision 0) @@ -0,0 +1,57 @@ +// 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_V2I_ALL_HH +# define MLN_FUN_V2I_ALL_HH + +/// \file mln/fun/v2i/all.hh +/// +/// \brief File that includes all value-to-integer functions. + + +namespace mln +{ + + /// Namespace of functions. + namespace fun + { + + /// \brief Namespace of value-to-integer functions. + /// + /// \ingroup modfun + // + namespace v2i + {} + + } +} + + +# include <mln/fun/v2i/index_of_value.hh> + + +#endif // ! MLN_FUN_V2I_ALL_HH Index: mln/fun/all.hh --- mln/fun/all.hh (revision 3869) +++ mln/fun/all.hh (working copy) @@ -31,13 +31,13 @@ /// \file mln/fun/all.hh /// -/// File that includes all fun-related routines. +/// File that includes all functions. namespace mln { - /// Namespace of image processing routines related to functions. + /// Namespace of functions. namespace fun { @@ -57,6 +57,7 @@ # include <mln/fun/p2v/all.hh> # include <mln/fun/stat/all.hh> # include <mln/fun/v2b/all.hh> +# include <mln/fun/v2i/all.hh> # include <mln/fun/v2v/all.hh> # include <mln/fun/vv2v/all.hh> # include <mln/fun/x2p/all.hh> Index: tests/fun/i2v/array.cc --- tests/fun/i2v/array.cc (revision 0) +++ tests/fun/i2v/array.cc (revision 0) @@ -0,0 +1,48 @@ +// 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/i2v/array.cc +/// +/// Test on mln::fun::i2v::array. + +#include <mln/fun/i2v/array.hh> + + +int main() +{ + using namespace mln; + + fun::i2v::array<int> f; + mln_assertion(f.size() == 0u); + + f.append(0); + mln_assertion(f(0) == 0); + + f.append(1); + mln_assertion(f(1) == 1); + mln_assertion(f.size() == 2u); +} Index: tests/fun/i2v/Makefile.am --- tests/fun/i2v/Makefile.am (revision 3869) +++ tests/fun/i2v/Makefile.am (working copy) @@ -1,3 +1,14 @@ ## Process this file through Automake to create Makefile.in. include $(top_srcdir)/milena/tests/tests.mk + +check_PROGRAMS = \ + all_to \ + array \ + value_at_index + +all_to_SOURCES = all_to.cc +array_SOURCES = array.cc +value_at_index_SOURCES = value_at_index.cc + +TESTS = $(check_PROGRAMS) Index: tests/fun/i2v/value_at_index.cc --- tests/fun/i2v/value_at_index.cc (revision 0) +++ tests/fun/i2v/value_at_index.cc (revision 0) @@ -0,0 +1,57 @@ +// 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/i2v/value_at_index.cc +/// +/// Test on mln::fun::i2v::value_at_index. + +#include <mln/fun/i2v/value_at_index.hh> +#include <mln/value/int_u8.hh> +#include <mln/value/int_s8.hh> + + +int main() +{ + using namespace mln; + + { + fun::i2v::value_at_index<bool> f; + mln_assertion(f(0) == false); + mln_assertion(f(1) == true); + } + { + fun::i2v::value_at_index< value::int_u8 > f; + mln_assertion(f( 0) == 0); + mln_assertion(f(255) == 255); + } + { + fun::i2v::value_at_index< value::int_s8 > f; + mln_assertion(f( 0) == -127); + mln_assertion(f(254) == +127); + } + +} Index: tests/fun/i2v/all_to.cc --- tests/fun/i2v/all_to.cc (revision 0) +++ tests/fun/i2v/all_to.cc (revision 0) @@ -0,0 +1,44 @@ +// 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/i2v/all_to.cc +/// +/// Test on mln::fun::i2v::all_to. + +#include <mln/fun/i2v/all_to.hh> + + +int main() +{ + using namespace mln; + + fun::i2v::all_to<int> f(51); + + mln_assertion(f( 0) == 51); + mln_assertion(f( 1) == 51); + mln_assertion(f(51) == 51); +} Index: tests/fun/v2i/Makefile.am --- tests/fun/v2i/Makefile.am (revision 0) +++ tests/fun/v2i/Makefile.am (revision 0) @@ -0,0 +1,10 @@ +## Process this file through Automake to create Makefile.in. + +include $(top_srcdir)/milena/tests/tests.mk + +check_PROGRAMS = \ + index_of_value + +index_of_value_SOURCES = index_of_value.cc + +TESTS = $(check_PROGRAMS) Index: tests/fun/v2i/index_of_value.cc --- tests/fun/v2i/index_of_value.cc (revision 0) +++ tests/fun/v2i/index_of_value.cc (revision 0) @@ -0,0 +1,56 @@ +// 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/v2i/index_of_value.cc +/// +/// Test on mln::fun::v2i::index_of_value. + +#include <mln/fun/v2i/index_of_value.hh> +#include <mln/value/int_u8.hh> +#include <mln/value/int_s8.hh> + + +int main() +{ + using namespace mln; + + { + fun::v2i::index_of_value<bool> f; + mln_assertion(f(false) == 0); + mln_assertion(f(true) == 1); + } + { + fun::v2i::index_of_value< value::int_u8 > f; + mln_assertion(f( 0) == 0); + mln_assertion(f(255) == 255); + } + { + fun::v2i::index_of_value< value::int_s8 > f; + mln_assertion(f(-127) == 0); + mln_assertion(f(+127) == 254); + } +}
participants (1)
-
Thierry Geraud