cleanup-2008 2160: Add image domain extension morphers plus the flat image.

https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Add image domain extension morphers plus the flat image. Add image domain extension morphers. * mln/core/image/extension_ima.hh: New. * mln/trait/ch_value.hh (ch_value_): New overload to deal with extension_ima. * mln/core/image/extension_fun.hh: New. * mln/core/image/extension_val.hh: New. * mln/core/routine: New directory. * mln/core/routine/all.hh: New. * mln/core/routine/extend.hh: New. * doc/tutorial/examples/image_if.cc: Augment to test extensions. Add the flat image type. * mln/core/image/flat_image.hh: New. * doc/tutorial/examples/image_flat.cc: New. * mln/core/image/status.txt: Update. Enforce consistency for iterator naming. * mln/core/macros.hh (mln_iter, mln_fwd_iter, mln_bkd_iter): Rename as... (mln_eiter, mln_fwd_eiter, mln_bkd_eiter): ...these. * mln/core/site_set/p_key.hh, * mln/core/site_set/p_mutable_array_of.hh, * mln/core/site_set/p_set_of.hh, * mln/core/p_runs.hh, * mln/util/set.hh, * mln/util/array.hh: Update. Misc. * mln/core/image/instant.hh (file): Fix. * sandbox/geraud/p_runs__with_dedicated_piter.hh (todo): Remove; obsolete. * mln/core/internal/morpher_lvalue.hh (mln_morpher_lvalue): New macro. * mln/core/internal/image_identity.hh: Use the new macro. * mln/core/safe.hh: Likewise. doc/tutorial/examples/image_flat.cc | 12 + doc/tutorial/examples/image_if.cc | 59 ++++- mln/core/image/extension_fun.hh | 222 ++++++++++++++++++++ mln/core/image/extension_ima.hh | 254 +++++++++++++++++++++++ mln/core/image/extension_val.hh | 240 +++++++++++++++++++++ mln/core/image/flat_image.hh | 273 +++++++++++++++++++++++++ mln/core/image/instant.hh | 2 mln/core/image/status.txt | 4 mln/core/internal/image_identity.hh | 2 mln/core/internal/morpher_lvalue.hh | 4 mln/core/macros.hh | 26 +- mln/core/p_runs.hh | 4 mln/core/routine/all.hh | 45 ++++ mln/core/routine/extend.hh | 157 ++++++++++++++ mln/core/safe.hh | 4 mln/core/site_set/p_key.hh | 8 mln/core/site_set/p_mutable_array_of.hh | 4 mln/core/site_set/p_set_of.hh | 4 mln/trait/ch_value.hh | 7 mln/util/array.hh | 6 mln/util/set.hh | 6 sandbox/geraud/p_runs__with_dedicated_piter.hh | 4 22 files changed, 1305 insertions(+), 42 deletions(-) Index: doc/tutorial/examples/image_if.cc --- doc/tutorial/examples/image_if.cc (revision 2159) +++ doc/tutorial/examples/image_if.cc (working copy) @@ -1,10 +1,16 @@ # include <mln/core/image2d.hh> +# include <mln/core/neighb2d.hh> # include <mln/core/image_if.hh> # include <mln/debug/iota.hh> # include <mln/debug/println.hh> # include <mln/fun/p2b/chess.hh> +# include <mln/border/fill.hh> +# include <mln/core/var.hh> +# include <mln/core/routine/extend.hh> +# include <mln/pw/all.hh> + template <typename It, typename S> void ch_target(It it, const S& s) @@ -13,21 +19,64 @@ } +template <typename I, typename N> +void browse(const I& ima, const N& nbh) +{ + // Relies on "ima.has(p)". + mln_fwd_piter(I) p(ima.domain()); + mln_fwd_niter(N) n(nbh, p); + for_all(p) + { + std::cout << ima(p) << ": "; + for_all(n) + if (ima.has(n)) + std::cout << ima(n) << ' '; + std::cout << std::endl; + } +} + +template <typename I, typename N> +void browse_domain(const I& ima, const N& nbh) +{ + // Relies on "ima.domain().has(p)". + mln_fwd_piter(I) p(ima.domain()); + mln_fwd_niter(N) n(nbh, p); + for_all(p) + { + std::cout << ima(p) << ": "; + for_all(n) + if (ima.domain().has(n)) + std::cout << ima(n) << ' '; + std::cout << std::endl; + } +} + + + + int main() { using namespace mln; typedef image2d<unsigned> I; - I ima(3, 5); + I ima(3, 3, 1); + // FIXME: border::fill(ima, 0); debug::iota(ima); + mln_VAR(ima_, ima | fun::p2b::chess); + debug::println(ima); - debug::println(ima | fun::p2b::chess); + debug::println(ima_); - trait::image::print(ima | fun::p2b::chess); + trait::image::print(ima_); + std::cout << std::endl; typedef pset_if<box2d, fun::p2b::chess_t> S; + ch_target(mln_fwd_piter_(S)(), ima_.domain()); - ch_target(mln_fwd_piter_(S)(), - (ima | fun::p2b::chess).domain()); + // mln_VAR(ima_e, extend(ima_, pw::value(ima))); + // mln_VAR(ima_e, extend(ima_, 0)); + mln_VAR(ima_e, extend(ima_, ima)); + debug::println(ima_e); + browse(ima_e, c4()); } Index: doc/tutorial/examples/image_flat.cc --- doc/tutorial/examples/image_flat.cc (revision 0) +++ doc/tutorial/examples/image_flat.cc (revision 0) @@ -0,0 +1,12 @@ +# include <mln/core/image2d.hh> +# include <mln/core/image/flat_image.hh> +# include <mln/debug/println.hh> + + +int main() +{ + using namespace mln; + + flat_image<unsigned, box2d> ima(3, box2d(3,3)); + debug::println(ima); +} Index: mln/trait/ch_value.hh --- mln/trait/ch_value.hh (revision 2159) +++ mln/trait/ch_value.hh (working copy) @@ -98,6 +98,13 @@ typedef M< P, V > ret; }; + template < template <class, class> class M, typename I1, typename I2, + typename V > + struct ch_value_< M< tag::image_<I1>, tag::image_<I2> >, V > + { + typedef M< mln_ch_value(I1, V), mln_ch_value(I2, V) > ret; + }; + // For mln::value::stack_image<n,I>. template < template <unsigned, class> class M, unsigned n, typename I, typename V > Index: mln/core/macros.hh --- mln/core/macros.hh (revision 2159) +++ mln/core/macros.hh (working copy) @@ -49,10 +49,11 @@ // b -/// Shortcuts to access the bkd_iter type associated to T. +/// Shortcuts to access the element-backward-iterator type associated +/// to T. /// \{ -# define mln_bkd_iter(T) typename T::bkd_iter -# define mln_bkd_iter_(T) T::bkd_iter +# define mln_bkd_eiter(T) typename T::bkd_eiter +# define mln_bkd_eiter_(T) T::bkd_eiter /// \} /// Shortcuts to access the bkd_niter type associated to T. @@ -118,6 +119,12 @@ // e +/// Shortcuts to access the element-iterator type associated to T. +/// \{ +# define mln_eiter(T) typename T::eiter +# define mln_eiter_(T) T::eiter +/// \} + /// Shortcuts to access the element type associated to T. /// \{ # define mln_element(T) typename T::element @@ -139,10 +146,11 @@ // f -/// Shortcuts to access the fwd_iter type associated to T. +/// Shortcuts to access the element-forward-iterator type associated +/// to T. /// \{ -# define mln_fwd_iter(T) typename T::fwd_iter -# define mln_fwd_iter_(T) T::fwd_iter +# define mln_fwd_eiter(T) typename T::fwd_eiter +# define mln_fwd_eiter_(T) T::fwd_eiter /// \} /// Shortcuts to access the fwd_niter type associated to T. @@ -199,12 +207,6 @@ # define mln_invert_(T) T::invert /// \} -/// Shortcuts to access the iterator type associated to T. -/// \{ -# define mln_iter(T) typename T::iter -# define mln_iter_(T) T::iter -/// \} - // l Index: mln/core/internal/morpher_lvalue.hh --- mln/core/internal/morpher_lvalue.hh (revision 2159) +++ mln/core/internal/morpher_lvalue.hh (working copy) @@ -36,6 +36,10 @@ # include <mln/core/macros.hh> +# define mln_morpher_lvalue(I) typename internal::morpher_lvalue_<I>::ret + + + namespace mln { Index: mln/core/internal/image_identity.hh --- mln/core/internal/image_identity.hh (revision 2159) +++ mln/core/internal/image_identity.hh (working copy) @@ -143,7 +143,7 @@ typedef mln_rvalue(I) rvalue; /// Return type of read-write access. - typedef typename internal::morpher_lvalue_<I>::ret lvalue; + typedef mln_morpher_lvalue(I) lvalue; /// Give the set of values. Index: mln/core/image/extension_ima.hh --- mln/core/image/extension_ima.hh (revision 0) +++ mln/core/image/extension_ima.hh (revision 0) @@ -0,0 +1,254 @@ +// Copyright (C) 2008 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_CORE_IMAGE_EXTENSION_IMA_HH +# define MLN_CORE_IMAGE_EXTENSION_IMA_HH + +/*! + * \file mln/core/image/extension_ima.hh + * + * \brief Definition of a morpher that extends the domain of an image + * with a function. + * + * \todo Use the 'instant' mechanism. + */ + +# include <mln/core/internal/image_identity.hh> +# include <mln/metal/converts_to.hh> + + + +namespace mln +{ + + // Forward declaration. + template <typename I, typename J> struct extension_ima; + + + namespace internal + { + + /// \internal Data structure for \c mln::extension_ima<I, J>. + template <typename I, typename J> + struct data< extension_ima<I, J> > + { + data(I& ima, J& ext); + + I ima_; + J ext_; + }; + + } // end of namespace mln::internal + + + namespace trait + { + + template <typename I, typename J> + struct image_< extension_ima<I, J> > : image_< I > // Same as I except... + { + // ...these changes. + typedef trait::image::category::identity_morpher category; + typedef mln_internal_trait_image_speed_from(I) speed; // Un-fastest. + + // extended domain + typedef trait::image::ext_domain::extendable ext_domain; + typedef trait::image::ext_value::multiple ext_value; + typedef mln_trait_image_value_io(J) ext_io; + }; + + } // end of namespace mln::trait + + + + // FIXME: Doc! + + template <typename I, typename J> + class extension_ima + + : public internal::image_identity< I, mln_pset(I), extension_ima<I, J> >, + private mlc_converts_to(mln_value(J), mln_value(I))::check_t + { + public: + + /// Skeleton. + typedef extension_ima< tag::image_<I>, tag::image_<J> > skeleton; + // FIXME: OK when ch_value? + + + /// Return type of read-only access. + typedef mln_value(I) rvalue; + + + /// Constructor without argument. + extension_ima(); + + /// Constructor from an image \p ima and a function \p ext. + extension_ima(I& ima, J& ext); + + /// Deferred initialization from an image \p ima and a function \p + /// ext. + void init(I& ima, J& ext); + + + /// Test if \p p is valid. + // Tech note: the 'template' allows for multiple input. + template <typename P> + bool has(const P& p) const; + + + /// Read-only access to the image value located at site \p p; + mln_value(I) operator()(const mln_psite(I)& p) const; + + /// Read-write access to the image value located at site \p p. + mln_morpher_lvalue(I) operator()(const mln_psite(I)& p); + + + /// Read-only access to the extension domain (image). + mlc_const(J)& extension() const; + + /// Mutable access to the extension domain (image). This domain + /// can be modified if J a read-write image type. + J& extension(); + }; + + + + +# ifndef MLN_INCLUDE_ONLY + + // internal::data< extension_ima<I,S> > + + namespace internal + { + + template <typename I, typename J> + inline + data< extension_ima<I, J> >::data(I& ima, J& ext) + : ima_(ima), + ext_(ext) + { + } + + } // end of namespace mln::internal + + // extension_ima<I, J> + + template <typename I, typename J> + inline + extension_ima<I, J>::extension_ima() + { + } + + template <typename I, typename J> + inline + extension_ima<I, J>::extension_ima(I& ima, J& ext) + { + init(ima, ext); + } + + template <typename I, typename J> + inline + void + extension_ima<I, J>::init(I& ima, J& ext) + { + this->data_ = new internal::data< extension_ima<I, J> >(ima, ext); + } + + template <typename I, typename J> + template <typename P> + inline + bool + extension_ima<I, J>::has(const P& p) const + { + mln_precondition(this->has_data()); + mln_precondition(this->data_->ext_.has_data()); + return + this->data_->ima_.domain().has(p) + || this->data_->ext_.has(p); + } + + template <typename I, typename J> + inline + mln_value(I) + extension_ima<I, J>::operator()(const mln_psite(I)& p) const + { + mln_precondition(this->has_data()); + mln_precondition(has(p)); + // if-else is preferred to the ternary op to allow for the + // function result to convert towards the expected return type. + if (this->data_->ima_.domain().has(p)) + return this->data_->ima_(p); + else + return this->data_->ext_(p); + } + + template <typename I, typename J> + inline + mln_morpher_lvalue(I) + extension_ima<I, J>::operator()(const mln_psite(I)& p) + { + static mln_value(I) cpy; + mln_precondition(this->has_data()); + mln_precondition(has(p)); + // See the above comment about if-else v. ternary. + if (this->data_->ima_.domain().has(p)) + return this->data_->ima_(p); + else + { + // This hack makes this signature valid both in the image + // domain and in its extension. It works even if + // mln_morpher_lvalue(I) is a mutable reference. + cpy = this->data_->ext_(p); + return cpy; + } + } + + template <typename I, typename J> + inline + mlc_const(J)& + extension_ima<I, J>::extension() const + { + mln_precondition(this->has_data()); + return this->data_->ext_; + } + + template <typename I, typename J> + inline + J& + extension_ima<I, J>::extension() + { + mln_precondition(this->has_data()); + return this->data_->ext_; + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_CORE_IMAGE_EXTENSION_IMA_HH Index: mln/core/image/status.txt --- mln/core/image/status.txt (revision 2159) +++ mln/core/image/status.txt (working copy) @@ -57,6 +57,10 @@ ** identity morpher new instant +new extension_ima +new extension_fun +new extension_val + ok plain ok safe Index: mln/core/image/extension_fun.hh --- mln/core/image/extension_fun.hh (revision 0) +++ mln/core/image/extension_fun.hh (revision 0) @@ -0,0 +1,222 @@ +// Copyright (C) 2008 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_CORE_IMAGE_EXTENSION_FUN_HH +# define MLN_CORE_IMAGE_EXTENSION_FUN_HH + +/*! + * \file mln/core/image/extension_fun.hh + * + * \brief Definition of a morpher that extends the domain of an image + * with a function. + * + * \todo Deal with two-ways functions... + */ + +# include <mln/core/internal/image_identity.hh> +# include <mln/metal/converts_to.hh> + + + +namespace mln +{ + + // Forward declaration. + template <typename I, typename F> struct extension_fun; + + + namespace internal + { + + /// \internal Data structure for \c mln::extension_fun<I, F>. + template <typename I, typename F> + struct data< extension_fun<I, F> > + { + data(I& ima, const F& fun); + + I ima_; + const F fun_; + }; + + } // end of namespace mln::internal + + + namespace trait + { + + template <typename I, typename F> + struct image_< extension_fun<I, F> > : image_< I > // Same as I except... + { + // ...these changes. + typedef trait::image::category::identity_morpher category; + typedef mln_internal_trait_image_speed_from(I) speed; // Un-fastest. + + // extended domain + typedef trait::image::ext_domain::infinite ext_domain; + typedef trait::image::ext_value::multiple ext_value; + typedef trait::image::ext_io::read_only ext_io; + }; + + } // end of namespace mln::trait + + + + // FIXME: Doc! + + template <typename I, typename F> + class extension_fun + + : public internal::image_identity< I, mln_pset(I), extension_fun<I, F> >, + private mlc_converts_to(mln_result(F), mln_value(I))::check_t + { + public: + + /// Skeleton. + typedef extension_fun< tag::image_<I>, tag::function_<F> > skeleton; + // FIXME: OK when ch_value? + + + /// Return type of read-only access. + typedef mln_value(I) rvalue; + + + /// Constructor without argument. + extension_fun(); + + /// Constructor from an image \p ima and a function \p fun. + extension_fun(I& ima, const F& fun); + + /// Deferred initialization from an image \p ima and a function \p + /// fun. + void init(I& ima, const F& fun); + + + /// Test if \p p is valid. It returns always true. + // Tech note: the 'template' allows for multiple input. + template <typename P> + bool has(const P& p) const; + + + /// Read-only access to the image value located at site \p p; + mln_value(I) operator()(const mln_psite(I)& p) const; + + /// Read-write access to the image value located at site \p p. + mln_morpher_lvalue(I) operator()(const mln_psite(I)& p); + }; + + + + +# ifndef MLN_INCLUDE_ONLY + + // internal::data< extension_fun<I,S> > + + namespace internal + { + + template <typename I, typename F> + inline + data< extension_fun<I, F> >::data(I& ima, const F& fun) + : ima_(ima), + fun_(fun) + { + } + + } // end of namespace mln::internal + + // extension_fun<I, F> + + template <typename I, typename F> + inline + extension_fun<I, F>::extension_fun() + { + } + + template <typename I, typename F> + inline + extension_fun<I, F>::extension_fun(I& ima, const F& fun) + { + init(ima, fun); + } + + template <typename I, typename F> + inline + void + extension_fun<I, F>::init(I& ima, const F& fun) + { + this->data_ = new internal::data< extension_fun<I, F> >(ima, fun); + } + + template <typename I, typename F> + template <typename P> + inline + bool + extension_fun<I, F>::has(const P&) const + { + return true; + } + + template <typename I, typename F> + inline + mln_value(I) + extension_fun<I, F>::operator()(const mln_psite(I)& p) const + { + mln_precondition(this->has_data()); + // if-else is preferred to the ternary op to allow for the + // function result to convert towards the expected return type. + if (this->data_->ima_.domain().has(p)) + return this->data_->ima_(p); + else + return this->data_->fun_(p); + } + + template <typename I, typename F> + inline + mln_morpher_lvalue(I) + extension_fun<I, F>::operator()(const mln_psite(I)& p) + { + static mln_value(I) cpy; + mln_precondition(this->has_data()); + // See the above comment about if-else v. ternary. + if (this->data_->ima_.domain().has(p)) + return this->data_->ima_(p); + else + { + // This hack makes this signature valid both in the image + // domain and in its extension. It works even if + // mln_morpher_lvalue(I) is a mutable reference. + cpy = this->data_->fun_(p); + return cpy; + } + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_CORE_IMAGE_EXTENSION_FUN_HH Index: mln/core/image/flat_image.hh --- mln/core/image/flat_image.hh (revision 0) +++ mln/core/image/flat_image.hh (revision 0) @@ -0,0 +1,273 @@ +// Copyright (C) 2008 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_CORE_FLAT_IMAGE_HH +# define MLN_CORE_FLAT_IMAGE_HH + +/*! + * \file mln/core/flat_image.hh + * + * \brief Definition of a image with a signle value. + * + * \todo Zed: Address the values v. destination issue. + */ + +# include <mln/core/internal/image_primary.hh> + + +namespace mln +{ + + + // Forward declaration. + template <typename T, typename S> class flat_image; + + + namespace internal + { + + /// \internal Data structure for \c mln::flat_image<T,S>. + template <typename T, typename S> + struct data< flat_image<T,S> > + { + data(const T& val, const S& pset); + + T val_; + S pset_; + }; + + } // end of namespace mln::internal + + + + namespace trait + { + + template <typename T, typename S> + struct image_< flat_image<T,S> > : default_image_< T, flat_image<T,S> > + { + // misc + typedef trait::image::category::primary category; + typedef trait::image::speed::fast speed; + typedef trait::image::size::regular size; + + // value + typedef trait::image::value_access::direct value_access; + typedef trait::image::value_storage::one_block value_storage; + typedef trait::image::value_browsing::site_wise_only value_browsing; + typedef trait::image::value_io::read_only value_io; + + // site / domain + typedef trait::image::localization::basic_grid localization; // FIXME + typedef trait::image::dimension::two_d dimension; // FIXME + + // extended domain + typedef trait::image::ext_domain::infinite ext_domain; + typedef trait::image::ext_value::single ext_value; + typedef trait::image::ext_io::read_only ext_io; + }; + + } // end of namespace mln::trait + + + + // FIXME: Doc! + + template <typename T, typename S> + struct flat_image : public internal::image_primary< S, flat_image<T,S> > + { + /// Skeleton. + typedef flat_image< tag::value_<T>, tag::pset_<S> > skeleton; + + + /// Value associated type. + typedef T value; + + /// Return type of read-only access. + typedef const T& rvalue; + + /// Return type of read-write access. + typedef const T& lvalue; + + + /// Constructor without argument. + flat_image(); + + /// Constructor. + flat_image(const T& val, const S& pset); + + /// Initialization. + void init_(const T& val, const S& pset); + + /// Give the definition domain. + const S& domain() const; + + /// Test if \p p is valid: always return true. + bool has(const mln_psite(S)& p) const; + + + /// Read-only access to the image value located at point \p p. + const T& operator()(const mln_psite(S)& p) const; + + /// Read-write access to the image value located at point \p p. + const T& operator()(const mln_psite(S)& p); + + + // FIXME: Weird... + + /// Value_Set associated type. + typedef mln::value::set<T> vset; + + /// Give the set of values of the image. + const mln::value::set<T>& values() const; + + // end of FIXME + + + /// Change the image value. + void change_value(const T& val); + }; + + + + template <typename T, typename S, typename J> + void init_(tag::image_t, flat_image<T,S>& target, const J& model); + + + +# ifndef MLN_INCLUDE_ONLY + + // init_ + + template <typename T, typename S, typename J> + inline + void init_(tag::image_t, flat_image<T,S>& target, const J& model) + { + S pset; + init_(tag::domain, pset, model); + T dummy; + target.init_(dummy, pset); + } + + + // internal::data< flat_image<T,S> > + + namespace internal + { + + template <typename T, typename S> + inline + data< flat_image<T,S> >::data(const T& val, const S& pset) + : val_(val), + pset_(pset) + { + } + + } // end of namespace mln::internal + + + // flat_image<T,S> + + template <typename T, typename S> + inline + flat_image<T,S>::flat_image() + { + } + + template <typename T, typename S> + inline + flat_image<T,S>::flat_image(const T& val, const S& pset) + { + init_(val, pset); + } + + template <typename T, typename S> + inline + void + flat_image<T,S>::init_(const T& val, const S& pset) + { + mln_precondition(! this->has_data()); + this->data_ = new internal::data< flat_image<T,S> >(val, pset); + } + + template <typename T, typename S> + inline + const S& + flat_image<T,S>::domain() const + { + return this->data_->pset_; + } + + template <typename T, typename S> + inline + bool + flat_image<T,S>::has(const mln_psite(S)&) const + { + return true; + } + + template <typename T, typename S> + inline + const T& + flat_image<T,S>::operator()(const mln_psite(S)& p) const + { + mln_precondition(this->has_data()); + return this->data_->val_; + } + + template <typename T, typename S> + inline + const T& + flat_image<T,S>::operator()(const mln_psite(S)& p) + { + mln_precondition(this->has_data()); + return this->data_->val_; + } + + template <typename T, typename S> + inline + const mln::value::set<T>& + flat_image<T,S>::values() const + { + return vset::the(); + } + + template <typename T, typename S> + inline + void + flat_image<T,S>::change_value(const T& val) + { + mln_precondition(this->has_data()); + this->data_->val_ = val; + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_CORE_FLAT_IMAGE_HH Index: mln/core/image/extension_val.hh --- mln/core/image/extension_val.hh (revision 0) +++ mln/core/image/extension_val.hh (revision 0) @@ -0,0 +1,240 @@ +// Copyright (C) 2008 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_CORE_IMAGE_EXTENSION_VAL_HH +# define MLN_CORE_IMAGE_EXTENSION_VAL_HH + +/*! + * \file mln/core/image/extension_val.hh + * + * \brief Definition of a morpher that extends the domain of an image. + * + * \todo Use the 'instant' mechanism. + */ + +# include <mln/core/internal/image_identity.hh> +# include <mln/metal/converts_to.hh> + + + +namespace mln +{ + + // Forward declaration. + template <typename I> struct extension_val; + + + namespace internal + { + + /// \internal Data structure for \c mln::extension_val<I>. + template <typename I> + struct data< extension_val<I> > + { + data(I& ima, const mln_value(I)& val_); + + I ima_; + mln_value(I) val_; + }; + + } // end of namespace mln::internal + + + namespace trait + { + + template <typename I> + struct image_< extension_val<I> > : image_< I > // Same as I except... + { + // ...these changes. + typedef trait::image::category::identity_morpher category; + typedef mln_internal_trait_image_speed_from(I) speed; // Un-fastest. + + // extended domain + typedef trait::image::ext_domain::infinite ext_domain; + typedef trait::image::ext_value::single ext_value; + typedef trait::image::ext_io::read_write ext_io; + }; + + } // end of namespace mln::trait + + + + // FIXME: Doc! + + template <typename I> + class extension_val : public internal::image_identity< I, mln_pset(I), extension_val<I> > + { + public: + + /// Skeleton. + typedef extension_val< tag::image_<I> > skeleton; + // FIXME: OK when ch_value? + + + /// Return type of read-only access. + typedef mln_value(I) rvalue; + + + /// Constructor without argument. + extension_val(); + + /// Constructor from an image \p ima and a value \p val. + extension_val(I& ima, const mln_value(I)& val); + + /// Deferred initialization from an image \p ima and a value \p + /// val. + void init(I& ima, const mln_value(I)& val); + + + /// Test if \p p is valid. It returns always true. + // Tech note: the 'template' allows for multiple input. + template <typename P> + bool has(const P& p) const; + + + /// Read-only access to the image value located at site \p p; + mln_value(I) operator()(const mln_psite(I)& p) const; + + /// Read-write access to the image value located at site \p p. + mln_morpher_lvalue(I) operator()(const mln_psite(I)& p); + + + /// Read-only access to the value of the extension domain. + const mln_value(I)& extension_value() const; + + /// Change the value of the extension domain. + void change_extension_value(const mln_value(I)& val); + }; + + + + +# ifndef MLN_INCLUDE_ONLY + + // internal::data< extension_val<I,S> > + + namespace internal + { + + template <typename I> + inline + data< extension_val<I> >::data(I& ima, const mln_value(I)& val) + : ima_(ima), + val_(val) + { + } + + } // end of namespace mln::internal + + // extension_val<I> + + template <typename I> + inline + extension_val<I>::extension_val() + { + } + + template <typename I> + inline + extension_val<I>::extension_val(I& ima, const mln_value(I)& val) + { + init(ima, val); + } + + template <typename I> + inline + void + extension_val<I>::init(I& ima, const mln_value(I)& val) + { + this->data_ = new internal::data< extension_val<I> >(ima, val); + } + + template <typename I> + template <typename P> + inline + bool + extension_val<I>::has(const P&) const + { + return true; + } + + template <typename I> + inline + mln_value(I) + extension_val<I>::operator()(const mln_psite(I)& p) const + { + mln_precondition(this->has_data()); + // if-else is preferred to the ternary op to allow conversions. + if (this->data_->ima_.domain().has(p)) + return this->data_->ima_(p); + else + return this->data_->val_; + } + + template <typename I> + inline + mln_morpher_lvalue(I) + extension_val<I>::operator()(const mln_psite(I)& p) + { + static mln_value(I) cpy; + mln_precondition(this->has_data()); + // See the above comment about if-else v. ternary. + if (this->data_->ima_.domain().has(p)) + return this->data_->ima_(p); + else + { + // This hack makes the extension value non-modifiable. + cpy = this->data_->val_; + return cpy; + } + } + + template <typename I> + inline + const mln_value(I)& + extension_val<I>::extension_value() const + { + mln_precondition(this->has_data()); + return this->data_->val_; + } + + template <typename I> + inline + void + extension_val<I>::change_extension_value(const mln_value(I)& val) + { + mln_precondition(this->has_data()); + this->data_->val_ = val; + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_CORE_IMAGE_EXTENSION_VAL_HH Index: mln/core/image/instant.hh --- mln/core/image/instant.hh (revision 2159) +++ mln/core/image/instant.hh (working copy) @@ -28,7 +28,7 @@ #ifndef MLN_CORE_IMAGE_INSTANT_HH # define MLN_CORE_IMAGE_INSTANT_HH -/*! \file mln/core/instant.hh +/*! \file mln/core/image/instant.hh * * \brief Definition of a morpher that prevent an image from sharing * his data. Index: mln/core/site_set/p_key.hh --- mln/core/site_set/p_key.hh (revision 2159) +++ mln/core/site_set/p_key.hh (working copy) @@ -88,12 +88,12 @@ /// Forward Site_Iterator associated type. typedef p_double_piter<self_, - mln_fwd_iter(util::set<K>), + mln_fwd_eiter(util::set<K>), mln_fwd_piter(p_set<P>)> fwd_piter; /// Backward Site_Iterator associated type. typedef p_double_piter<self_, - mln_bkd_iter(util::set<K>), + mln_bkd_eiter(util::set<K>), mln_bkd_piter(p_set<P>)> bkd_piter; /// Site_Iterator associated type. @@ -439,7 +439,7 @@ // Update b_. { util::set<K> new_b; - mln_iter(util::set<K>) k(b_); + mln_eiter(util::set<K>) k(b_); for_all(k) new_b.insert(lut[k] = f(k)); b_ = new_b; @@ -570,7 +570,7 @@ } unsigned n = 0; - mln_iter(util::set<K>) key(b_); + mln_eiter(util::set<K>) key(b_); for_all(key) { typename s_t::const_iterator k_s = s_.find(key); Index: mln/core/site_set/p_mutable_array_of.hh --- mln/core/site_set/p_mutable_array_of.hh (revision 2159) +++ mln/core/site_set/p_mutable_array_of.hh (working copy) @@ -91,12 +91,12 @@ /// Forward Site_Iterator associated type. typedef p_double_piter<self_, - mln_fwd_iter(array_), + mln_fwd_eiter(array_), mln_fwd_piter(S)> fwd_piter; /// Backward Site_Iterator associated type. typedef p_double_piter<self_, - mln_bkd_iter(array_), + mln_bkd_eiter(array_), mln_bkd_piter(S)> bkd_piter; /// Site_Iterator associated type. Index: mln/core/site_set/p_set_of.hh --- mln/core/site_set/p_set_of.hh (revision 2159) +++ mln/core/site_set/p_set_of.hh (working copy) @@ -88,12 +88,12 @@ /// Forward Site_Iterator associated type. typedef p_double_piter<self_, - mln_fwd_iter(set_), + mln_fwd_eiter(set_), mln_fwd_piter(S)> fwd_piter; /// Backward Site_Iterator associated type. typedef p_double_piter<self_, - mln_bkd_iter(set_), + mln_bkd_eiter(set_), mln_bkd_piter(S)> bkd_piter; /// Site_Iterator associated type. Index: mln/core/safe.hh --- mln/core/safe.hh (revision 2159) +++ mln/core/safe.hh (working copy) @@ -84,7 +84,6 @@ template <typename I> class safe_image : public internal::image_identity< I, mln_pset(I), safe_image<I> > { - typedef internal::image_identity< I, mln_pset(I), safe_image<I> > super_; public: /// Skeleton. @@ -96,8 +95,7 @@ mln_rvalue(I) operator()(const mln_psite(I)& p) const; - typedef typename super_::lvalue lvalue; - lvalue operator()(const mln_psite(I)& p); + mln_morpher_lvalue(I) operator()(const mln_psite(I)& p); /// Const promotion via conversion. operator safe_image<const I>() const; Index: mln/core/routine/extend.hh --- mln/core/routine/extend.hh (revision 0) +++ mln/core/routine/extend.hh (revision 0) @@ -0,0 +1,157 @@ +// Copyright (C) 2008 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_CORE_ROUTINE_EXTEND_HH +# define MLN_CORE_ROUTINE_EXTEND_HH + +/*! + * \file mln/core/routine/extend.hh + * + * \brief Definition of a morpher that extends the domain of an image. + * + * \todo Use the 'instant' mechanism. + * \todo Deal with ambiguities. + */ + +# include <mln/core/image/extension_ima.hh> +# include <mln/core/image/extension_fun.hh> +# include <mln/core/image/extension_val.hh> + + + +namespace mln +{ + + + /// Routines for domain extension with a function. + + template <typename I, typename F> + extension_fun<const I, F> + extend(const Image<I>& ima, const Function_v2v<F>& fun); + + template <typename I, typename F> + extension_fun<I, F> + extend(Image<I>& ima, const Function_v2v<F>& fun); + + + /// Routines for domain extension with an image. + + template <typename I, typename J> + extension_ima<const I, const J> + extend(const Image<I>& ima, const Image<J>& ext); + + template <typename I, typename J> + extension_ima<I, J> + extend(Image<I>& ima, Image<J>& ext); + + + /// Routines for domain extension with a value. + + template <typename I> + extension_val<const I> + extend(const Image<I>& ima, const mln_value(I)& val); + + template <typename I> + extension_val<I> + extend(Image<I>& ima, const mln_value(I)& val); + + + +# ifndef MLN_INCLUDE_ONLY + + + // With a function. + + template <typename I, typename F> + inline + extension_fun<const I, F> + extend(const Image<I>& ima, const Function_v2v<F>& fun) + { + mlc_converts_to(mln_result(F), mln_value(I))::check(); + extension_fun<const I, F> tmp(exact(ima), exact(fun)); + return tmp; + } + + template <typename I, typename F> + inline + extension_fun<I, F> + extend(Image<I>& ima, const Function_v2v<F>& fun) + { + mlc_converts_to(mln_result(F), mln_value(I))::check(); + extension_fun<I, F> tmp(exact(ima), exact(fun)); + return tmp; + } + + + // With an image. + + template <typename I, typename J> + extension_ima<const I, const J> + extend(const Image<I>& ima, const Image<J>& ext) + { + mlc_converts_to(mln_value(J), mln_value(I))::check(); + extension_ima<const I, const J> tmp(exact(ima), exact(ext)); + return tmp; + } + + template <typename I, typename J> + extension_ima<I, J> + extend(Image<I>& ima, Image<J>& ext) + { + mlc_converts_to(mln_value(J), mln_value(I))::check(); + extension_ima<I, J> tmp(exact(ima), exact(ext)); + return tmp; + } + + + // With a value. + + template <typename I> + inline + extension_val<const I> + extend(const Image<I>& ima, const mln_value(I)& val) + { + extension_val<const I> tmp(exact(ima), val); + return tmp; + } + + template <typename I> + inline + extension_val<I> + extend(Image<I>& ima, const mln_value(I)& val) + { + extension_val<I> tmp(exact(ima), val); + return tmp; + } + + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_CORE_ROUTINE_EXTEND_HH Index: mln/core/routine/all.hh --- mln/core/routine/all.hh (revision 0) +++ mln/core/routine/all.hh (revision 0) @@ -0,0 +1,45 @@ +// Copyright (C) 2008 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_CORE_ROUTINE_ALL_HH +# define MLN_CORE_ROUTINE_ALL_HH + +/*! \file mln/core/routine/all.hh + * + * \brief File that includes all core routines. + * + * \todo Move files, update, and activate. + */ + + +// # include <mln/core/routine/clone.hh> +// # include <mln/core/routine/exact.hh> +# include <mln/core/routine/extend.hh> +// # include <mln/core/routine/initialize.hh> + + +#endif // ! MLN_CORE_ROUTINE_ALL_HH Index: mln/core/p_runs.hh --- mln/core/p_runs.hh (revision 2159) +++ mln/core/p_runs.hh (working copy) @@ -99,12 +99,12 @@ /// Forward Site_Iterator associated type. typedef p_double_piter<self_, - mln_fwd_iter(set_), + mln_fwd_eiter(set_), mln_fwd_piter(p_run<P>)> fwd_piter; /// Backward Site_Iterator associated type. typedef p_double_piter<self_, - mln_bkd_iter(set_), + mln_bkd_eiter(set_), mln_bkd_piter(p_run<P>)> bkd_piter; /// Site_Iterator associated type. Index: mln/util/set.hh --- mln/util/set.hh (revision 2159) +++ mln/util/set.hh (working copy) @@ -89,13 +89,13 @@ /// Forward iterator associated type. - typedef set_fwd_iter<T> fwd_iter; + typedef set_fwd_iter<T> fwd_eiter; /// Backward iterator associated type. - typedef set_bkd_iter<T> bkd_iter; + typedef set_bkd_iter<T> bkd_eiter; /// Iterator associated type. - typedef fwd_iter iter; + typedef fwd_eiter eiter; /*! \brief Insert an element \p elt into the set. Index: mln/util/array.hh --- mln/util/array.hh (revision 2159) +++ mln/util/array.hh (working copy) @@ -74,13 +74,13 @@ /// Forward iterator associated type. - typedef array_fwd_iter<T> fwd_iter; + typedef array_fwd_iter<T> fwd_eiter; /// Backward iterator associated type. - typedef array_bkd_iter<T> bkd_iter; + typedef array_bkd_iter<T> bkd_eiter; /// Iterator associated type. - typedef fwd_iter iter; + typedef fwd_eiter eiter; /// Constructor without arguments. Index: sandbox/geraud/p_runs__with_dedicated_piter.hh --- sandbox/geraud/p_runs__with_dedicated_piter.hh (revision 2159) +++ sandbox/geraud/p_runs__with_dedicated_piter.hh (working copy) @@ -31,10 +31,6 @@ /*! \file mln/core/p_runs.hh * * \brief Definition of a set of point runs. - * - * \todo Zed: Use p_double* stuff. - * - * \todo Zed: Test for unicity (see FIXMEs). */ # include <mln/accu/bbox.hh>
participants (1)
-
Thierry Geraud