
* mln/fun/v2v/ch_function_value.hh: new. Wrap a function and convert that function results to another type thanks to from_to. * mln/fun/internal/ch_function_value_impl.hh: new. Allow extensions to ch_function_value according to the function it wraps. * mln/trait/ch_function_value.hh: Dispatch to the proper way to change the function return type. * mln/trait/ch_value.hh: handle ch_value on graph images here. * headers.mk: add new headers to distribution. --- milena/ChangeLog | 17 ++++ milena/headers.mk | 3 + milena/mln/fun/internal/ch_function_value_impl.hh | 57 +++++++++++ milena/mln/fun/v2v/ch_function_value.hh | 106 +++++++++++++++++++++ milena/mln/trait/ch_function_value.hh | 84 ++++++++++++++++ milena/mln/trait/ch_value.hh | 35 ++++++-- 6 files changed, 295 insertions(+), 7 deletions(-) create mode 100644 milena/mln/fun/internal/ch_function_value_impl.hh create mode 100644 milena/mln/fun/v2v/ch_function_value.hh create mode 100644 milena/mln/trait/ch_function_value.hh diff --git a/milena/ChangeLog b/milena/ChangeLog index 0541e7e..6c23d7b 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,22 @@ 2008-12-31 Guillaume Lazzara <z@lrde.epita.fr> + Handle ch_value on graph images and introduce ch_function_value. + + * mln/fun/v2v/ch_function_value.hh: new. Wrap a function and + convert that function results to another type thanks to from_to. + + * mln/fun/internal/ch_function_value_impl.hh: new. Allow extensions to + ch_function_value according to the function it wraps. + + * mln/trait/ch_function_value.hh: Dispatch to the proper way to change + the function return type. + + * mln/trait/ch_value.hh: handle ch_value on graph images here. + + * headers.mk: add new headers to distribution. + +2008-12-31 Guillaume Lazzara <z@lrde.epita.fr> + Fix/improve graph related classes. * mln/core/image/graph_window_piter.hh: update comments. diff --git a/milena/headers.mk b/milena/headers.mk index 8cd49e1..b348a9e 100644 --- a/milena/headers.mk +++ b/milena/headers.mk @@ -189,6 +189,7 @@ mln/fun/vv2v/min.hh \ mln/fun/vv2v/essential.hh \ mln/fun/internal/array_base.hh \ mln/fun/internal/x2x_linear_impl.hh \ +mln/fun/internal/ch_function_value_impl.hh \ mln/fun/internal/selector.hh \ mln/fun/v2w_w2v/norm.hh \ mln/fun/p2v/ternary.hh \ @@ -211,6 +212,7 @@ mln/fun/v2v/dec.hh \ mln/fun/v2v/abs.hh \ mln/fun/v2v/rgb_to_hsl.hh \ mln/fun/v2v/cast.hh \ +mln/fun/v2v/ch_function_value.hh \ mln/fun/v2v/rgb_to_hsi.hh \ mln/fun/v2v/enc.hh \ mln/fun/v2v/convert.hh \ @@ -440,6 +442,7 @@ mln/trait/value/essential.hh \ mln/trait/images.hh \ mln/trait/window/props.hh \ mln/trait/window/print.hh \ +mln/trait/ch_function_value.hh \ mln/trait/ch_value.hh \ mln/trait/solve.hh \ mln/trait/solve_unary.hh \ diff --git a/milena/mln/fun/internal/ch_function_value_impl.hh b/milena/mln/fun/internal/ch_function_value_impl.hh new file mode 100644 index 0000000..fa57290 --- /dev/null +++ b/milena/mln/fun/internal/ch_function_value_impl.hh @@ -0,0 +1,57 @@ +// Copyright (C) 2008 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_INTERNAL_CH_FUNCTION_VALUE_IMPL_HH +# define MLN_FUN_INTERNAL_CH_FUNCTION_VALUE_IMPL_HH + +/// \file mln/fun/internal/ch_function_value_impl.hh +/// +/// Enable the possibility of adding methods to fun::v2v::ch_function_value. + +namespace mln +{ + + namespace fun + { + + namespace internal + { + + /// Default implementation. + template <typename F, typename V> + struct ch_function_value_impl + { + }; + + } // end of namespace mln::fun::internal + + } // end of namespace mln::fun + +} // end of namespace mln + +#endif // ! MLN_FUN_INTERNAL_CH_FUNCTION_VALUE_IMPL_HH diff --git a/milena/mln/fun/v2v/ch_function_value.hh b/milena/mln/fun/v2v/ch_function_value.hh new file mode 100644 index 0000000..a4c7ca4 --- /dev/null +++ b/milena/mln/fun/v2v/ch_function_value.hh @@ -0,0 +1,106 @@ +// Copyright (C) 2008 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_CH_FUNCTION_VALUE_HH +# define MLN_FUN_V2V_CH_FUNCTION_VALUE_HH + +/// \file mln/fun/v2v/ch_function_value.hh +/// +/// Wrap a function v2v and convert its result to another type. + +# include <mln/core/concept/function.hh> +# include <mln/convert/to.hh> +# include <mln/fun/internal/ch_function_value_impl.hh> + + + +namespace mln +{ + + namespace fun + { + + namespace v2v + { + + /// Wrap a function v2v and convert its result to another type. + template <typename F, typename V> + class ch_function_value : public Function_v2v< ch_function_value<F,V> >, + public internal::ch_function_value_impl<F, V> + { + public: + typedef F function; + typedef V result; + typedef V rvalue; + typedef V lvalue; + + ch_function_value(); + ch_function_value(const F& f); + + template <typename W> + V operator()(const W& w) const; + + private: + F f_; + }; + + +# ifndef MLN_INCLUDE_ONLY + + template <typename F, typename V> + inline + ch_function_value<F,V>::ch_function_value() + { + } + + template <typename F, typename V> + inline + ch_function_value<F,V>::ch_function_value(const F& f) + { + f_ = f; + } + + template <typename F, typename V> + template <typename W> + inline + V + ch_function_value<F,V>::operator()(const W& w) const + { + return mln::convert::to<V>(f_(w)); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::fun::v2v + + } // end of namespace mln::fun + +} // end of namespace mln + + +#endif // ! MLN_FUN_V2V_CH_FUNCTION_VALUE_HH diff --git a/milena/mln/trait/ch_function_value.hh b/milena/mln/trait/ch_function_value.hh new file mode 100644 index 0000000..6ed1e47 --- /dev/null +++ b/milena/mln/trait/ch_function_value.hh @@ -0,0 +1,84 @@ +// Copyright (C) 2008 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_TRAIT_CH_FUNCTION_VALUE_HH +# define MLN_TRAIT_CH_FUNCTION_VALUE_HH + +/// \file mln/trait/ch_function_value.hh +/// +/// Definition of the "change value" function trait. + +# define mln_ch_function_value(I, V) \ +typename mln::trait::ch_function_value< I, V >::ret + +# define mln_ch_function_value_(I, V) \ +mln::trait::ch_functionvalue< I, V >::ret + +# include <mln/fun/v2v/ch_function_value.hh> + +namespace mln +{ + + namespace trait + { + + // Forward declaration. + template <typename F, typename V> struct ch_function_value; + + + namespace impl + { + + /// Default. + template <typename F, typename VF, typename V> + struct ch_function_value + { + typedef fun::v2v::ch_function_value<F, V> ret; + }; + + template <typename VF, typename V> + struct ch_function_value<fun::i2v::array<VF>, VF, V> + { + typedef fun::i2v::array<V> ret; + }; + + } // end of namespace mln::trait::impl + + + template <typename F, typename V> + struct ch_function_value + { + typedef typename impl::ch_function_value<F, mln_result(F), V>::ret ret; + }; + + + } // end of namespace mln::trait + +} // end of namespace mln + +#endif // ! MLN_TRAIT_CH_FUNCTION_VALUE_HH diff --git a/milena/mln/trait/ch_value.hh b/milena/mln/trait/ch_value.hh index 0333a16..cff3a59 100644 --- a/milena/mln/trait/ch_value.hh +++ b/milena/mln/trait/ch_value.hh @@ -29,13 +29,13 @@ #ifndef MLN_TRAIT_CH_VALUE_HH # define MLN_TRAIT_CH_VALUE_HH -/*! \file mln/trait/ch_value.hh - * - * \brief Definition of the "change value" image trait. - */ +/// \file mln/trait/ch_value.hh +/// +/// Definition of the "change value" image trait. # include <mln/tag/skeleton.hh> # include <mln/trait/image_from_grid.hh> +# include <mln/trait/ch_function_value.hh> # define mln_ch_value(I, V) typename mln::trait::ch_value< I, V >::ret @@ -46,16 +46,18 @@ namespace mln { - // Fwd decl. + // Forward declarations. namespace algebra { template <unsigned n, typename T> class vec; } - + template <typename G, typename F> class p_edges; + template <typename G, typename F> class p_vertices; + namespace pw { template <typename F, typename S> class image; } namespace trait { - // Fwd decl. + // Forward declaration. template <typename I, typename V> struct ch_value; @@ -163,6 +165,25 @@ namespace mln typedef typename image_from_grid< grid, V >::ret ret; }; + // line_graph image + template < typename F, + typename G, typename FP, + typename V > + struct ch_value_< pw::image< tag::function_<F>, tag::pset_<p_edges<G, FP> > >, V > + { + typedef pw::image< mln_ch_function_value(F, V), p_edges<G, FP> > ret; + }; + + // graph image + template < typename F, + typename G, typename FP, + typename V > + struct ch_value_< pw::image< tag::function_<F>, tag::pset_<p_vertices<G, FP> > >, V > + { + typedef pw::image< mln_ch_function_value(F, V), p_vertices<G, FP> > ret; + }; + + template < template <class, class> class M, typename T, typename S, typename V > struct ch_value_< M< tag::value_<T>, tag::pset_<S> >, V > -- 1.5.6.5