
https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Change image base impl classes. New intermediate classes. * mln/core/internal/image_domain_morpher.hh: New. * mln/core/internal/image_value_morpher.hh: New. * mln/core/internal/image_morpher.hh: New. * mln/core/internal/image_base.hh (owns_): New. * mln/core/image2d_b.hh (init_with): Update. * mln/core/cast_image.hh: Change inheritance. * mln/core/sub_image.hh: Likewise. cast_image.hh | 56 +++++------------ image2d_b.hh | 3 internal/image_base.hh | 14 +++- internal/image_domain_morpher.hh | 122 +++++++++++++++++++++++++++++++++++++++ internal/image_morpher.hh | 120 ++++++++++++++++++++++++++++++++++++++ internal/image_value_morpher.hh | 104 +++++++++++++++++++++++++++++++++ sub_image.hh | 36 ++++++----- 7 files changed, 396 insertions(+), 59 deletions(-) Index: mln/core/internal/image_domain_morpher.hh --- mln/core/internal/image_domain_morpher.hh (revision 0) +++ mln/core/internal/image_domain_morpher.hh (revision 0) @@ -0,0 +1,122 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef MLN_CORE_INTERNAL_IMAGE_DOMAIN_MORPHER_HH +# define MLN_CORE_INTERNAL_IMAGE_DOMAIN_MORPHER_HH + +/*! \file mln/core/internal/image_domain_morpher.hh + * + * \brief Definition of a base class for image morphers w.r.t. domain. + */ + +# include <mln/core/internal/image_morpher.hh> + + +namespace mln +{ + + namespace internal + { + + + /*! \brief A base class for image morphers w.r.t. domain. + * + * Parameter \p S is a point set type. + * + * \internal + */ + template <typename I, typename S, typename E> + class image_domain_morpher_ : public image_morpher_<I, S, E> + { + public: + + /// Value_Set associated type. + typedef mln_vset(I) vset; + + /// Value associated type. + typedef mln_value(I) value; + + /// Return type of read-only access. + typedef mln_rvalue(I) rvalue; + + /// Return type of read-write access. + typedef typename internal::morpher_lvalue_<I>::ret lvalue; + + + /// Give the set of values. + const vset& values() const; + + /// Read-only access of pixel value at point site \p p. + rvalue operator()(const mln_psite(S)& p) const; + + /// Read-write access of pixel value at point site \p p. + lvalue operator()(const mln_psite(S)& p); + + protected: + image_domain_morpher_(); + }; + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I, typename S, typename E> + image_domain_morpher_<I,S,E>::image_domain_morpher_() + { + } + + template <typename I, typename S, typename E> + const mln_vset(I)& + image_domain_morpher_<I,S,E>::values() const + { + mln_precondition(this->delegatee_() != 0); + return this->delegatee_()->values(); + } + + template <typename I, typename S, typename E> + mln_rvalue(I) + image_domain_morpher_<I,S,E>::operator()(const mln_psite(S)& p) const + { + mln_precondition(this->delegatee_() != 0); + return this->delegatee_()->operator()(p); + } + + template <typename I, typename S, typename E> + typename image_domain_morpher_<I,S,E>::lvalue + image_domain_morpher_<I,S,E>::operator()(const mln_psite(S)& p) + { + mln_precondition(this->delegatee_() != 0); + return this->delegatee_()->operator()(p); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::internal + +} // end of namespace mln + + +#endif // ! MLN_CORE_INTERNAL_IMAGE_DOMAIN_MORPHER_HH Index: mln/core/internal/image_value_morpher.hh --- mln/core/internal/image_value_morpher.hh (revision 0) +++ mln/core/internal/image_value_morpher.hh (revision 0) @@ -0,0 +1,104 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef MLN_CORE_INTERNAL_IMAGE_VALUE_MORPHER_HH +# define MLN_CORE_INTERNAL_IMAGE_VALUE_MORPHER_HH + +/*! \file mln/core/internal/image_value_morpher.hh + * + * \brief Definition of a base class for image morphers w.r.t. value. + */ + +# include <mln/core/internal/image_morpher.hh> + + +namespace mln +{ + + namespace internal + { + + + /*! \brief A base class for image morphers w.r.t. value. + * + * Parameter \p S is a point set type. + * + * \internal + */ + template <typename I, typename E> + class image_value_morpher_ : public image_morpher_<I, mln_pset(I), E> + { + public: + + const mln_pset(I)& domain() const; + bool owns_(const mln_psite(I)& p) const; + + bool has_data() const; // Default impl. + + protected: + image_value_morpher_(); + }; + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I, typename E> + image_value_morpher_<I,E>::image_value_morpher_() + { + } + + template <typename I, typename E> + const mln_pset(I)& + image_value_morpher_<I,E>::domain() const + { + mln_precondition(this->delegatee_() != 0); + return this->delegatee_()->domain(); + } + + template <typename I, typename E> + bool + image_value_morpher_<I,E>::owns_(const mln_psite(I)& p) const + { + mln_precondition(this->delegatee_() != 0); + return this->delegatee_()->owns_(p); + } + + template <typename I, typename E> + bool + image_value_morpher_<I,E>::has_data() const + { + return this->delegatee_() != 0 && this->delegatee_()->has_data(); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::internal + +} // end of namespace mln + + +#endif // ! MLN_CORE_INTERNAL_IMAGE_VALUE_MORPHER_HH Index: mln/core/internal/image_base.hh --- mln/core/internal/image_base.hh (revision 1145) +++ mln/core/internal/image_base.hh (working copy) @@ -123,15 +123,15 @@ /// Test if \p p belongs to the image domain. bool has(const psite& p) const; + // FIXME: Keep this default (owns_ is based on has)? + bool owns_(const psite& p) const; + /// Give a bounding box of the image domain. const box_<point>& bbox() const; /// Give the number of points of the image domain. std::size_t npoints() const; - - // FIXME: Add owns_(p) based on has(p)? - protected: image_base_(); }; @@ -153,6 +153,14 @@ } template <typename S, typename E> + bool + image_base_<S,E>::owns_(const psite& p) const + { + mln_precondition(exact(this)->has_data()); + return exact(this)->has(p); + } + + template <typename S, typename E> const box_<mln_point(S)>& image_base_<S,E>::bbox() const { Index: mln/core/internal/image_morpher.hh --- mln/core/internal/image_morpher.hh (revision 0) +++ mln/core/internal/image_morpher.hh (revision 0) @@ -0,0 +1,120 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef MLN_CORE_INTERNAL_IMAGE_MORPHER_HH +# define MLN_CORE_INTERNAL_IMAGE_MORPHER_HH + +/*! \file mln/core/internal/image_morpher.hh + * + * \brief Definition of a base class for image morphers. + */ + +# include <mln/core/internal/image_base.hh> +# include <mln/metal/const.hh> + + +namespace mln +{ + + namespace internal + { + + /*! \brief A base class for images that are morphers. + * + * Parameter \c I is the underlying-morphed image type. + * + * \internal + */ + template <typename I, typename S, typename E> + class image_morpher_ : public image_base_<S, E> + { + public: + + typedef I delegatee; + + /// Return the delegatee_ pointer. + mlc_const(I)* delegatee_() const; + + /// Return the delegatee_ pointer (non-const version). + I* delegatee_(); + + /// Convertion to the underlying (morphed) image. + operator I() const; // FIXME: Dangerous? + + /// Default for has_data is "delegatee has data". + bool has_data() const; + + protected: + image_morpher_(); + }; + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I, typename S, typename E> + image_morpher_<I,S,E>::image_morpher_() + { + } + + template <typename I, typename S, typename E> + mlc_const(I)* + image_morpher_<I,S,E>::delegatee_() const + { + return exact(this)->impl_delegatee_(); + } + + template <typename I, typename S, typename E> + I* + image_morpher_<I,S,E>::delegatee_() + { + return exact(this)->impl_delegatee_(); + } + + template <typename I, typename S, typename E> + image_morpher_<I,S,E>::operator I() const + { + mln_precondition(exact(this)->has_data()); + mln_precondition(this->delegatee_() != 0); // FIXME: Redundant? + return * this->delegatee_(); + } + + template <typename I, typename S, typename E> + bool + image_morpher_<I,S,E>::has_data() const + { + mln_precondition(this->delegatee_() != 0); // FIXME: Redundant? + return this->delegatee_()->has_data(); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::internal + +} // end of namespace mln + + +#endif // ! MLN_CORE_INTERNAL_IMAGE_MORPHER_HH Index: mln/core/image2d_b.hh --- mln/core/image2d_b.hh (revision 1145) +++ mln/core/image2d_b.hh (working copy) @@ -145,7 +145,8 @@ void init_with(const Image<I>& other) { mln_precondition(data_ = 0); - data_ = new image2d_b_data<T>(other.domain().bbox()); // FIXME: border? + mln_precondition(exact(other).has_data()); + data_ = new image2d_b_data<T>(exact(other).bbox()); // FIXME: border? } Index: mln/core/cast_image.hh --- mln/core/cast_image.hh (revision 1145) +++ mln/core/cast_image.hh (working copy) @@ -33,7 +33,7 @@ * \brief Definition of an image class FIXME */ -# include <mln/core/concept/image.hh> +# include <mln/core/internal/image_value_morpher.hh> # include <mln/value/set.hh> # include <mln/value/cast.hh> @@ -45,15 +45,10 @@ * */ template <typename T, typename I> - class cast_image_ : public mln::internal::image_base_< mln_pset(I), cast_image_<T,I> > + class cast_image_ : public internal::image_value_morpher_< I, cast_image_<T,I> > { - typedef cast_image_<T,I> self_; - typedef mln::internal::image_base_<mln_pset(I), self_> super_; public: - typedef mln_psite(super_) psite; - - /// Value associated type. typedef T value; @@ -75,24 +70,18 @@ cast_image_(const Image<I>& ima); - /// Test if this image has been initialized. - bool has_data() const; - - /// Test if a pixel value is accessible at \p p. - bool owns_(const psite& p) const; - - /// Give the definition domain. - const mln_pset(I)& domain() const; - /// Read-only access of pixel value at point site \p p. - T operator()(const psite& p) const; + T operator()(const mln_psite(I)& p) const; /// Mutable access is only OK for reading (not writing). - T operator()(const psite& p); + T operator()(const mln_psite(I)& p); /// Give the set of values of the image. const vset& values() const; + /// Access to delegatee pointer. + const I* impl_delegatee_() const; + protected: const I& ima_; }; @@ -120,28 +109,8 @@ } template <typename T, typename I> - bool cast_image_<T,I>::has_data() const - { - mln_invariant(ima_.has_data()); - return true; - } - - template <typename T, typename I> - bool cast_image_<T,I>::owns_(const psite& p) const - { - return ima_.owns_(p); - } - - template <typename T, typename I> - const mln_pset(I)& - cast_image_<T,I>::domain() const - { - return ima_.domain(); - } - - template <typename T, typename I> T - cast_image_<T,I>::operator()(const psite& p) const + cast_image_<T,I>::operator()(const mln_psite(I)& p) const { mln_precondition(ima_.owns_(p)); return mln::value::cast<T>( ima_(p) ); @@ -149,7 +118,7 @@ template <typename T, typename I> T - cast_image_<T,I>::operator()(const psite& p) + cast_image_<T,I>::operator()(const mln_psite(I)& p) { return mln::value::cast<T>( ima_(p) ); } @@ -161,6 +130,13 @@ return vset::the(); } + template <typename T, typename I> + const I* + cast_image_<T,I>::impl_delegatee_() const + { + return & ima_; + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln Index: mln/core/sub_image.hh --- mln/core/sub_image.hh (revision 1145) +++ mln/core/sub_image.hh (working copy) @@ -28,7 +28,7 @@ #ifndef MLN_CORE_SUB_IMAGE_HH # define MLN_CORE_SUB_IMAGE_HH -# include <mln/core/internal/image_adaptor.hh> +# include <mln/core/internal/image_domain_morpher.hh> namespace mln @@ -37,11 +37,8 @@ // FIXME: Doc! template <typename I, typename S> - class sub_image : public internal::image_adaptor_< I, - sub_image<I,S>, - S > + class sub_image : public internal::image_domain_morpher_< I, S, sub_image<I,S> > { - typedef internal::image_adaptor_<I, sub_image<I,S>, S> super_; public: /// Skeleton. @@ -49,14 +46,16 @@ sub_image(I& ima, const S& pset); - bool owns_(const mln_psite(I)& p) const; - const S& domain() const; /// Const promotion via convertion. operator sub_image<const I, S>() const; + mlc_const(I)* impl_delegatee_() const; + I* impl_delegatee_(); + protected: + I& ima_; const S& pset_; }; @@ -74,19 +73,12 @@ template <typename I, typename S> sub_image<I,S>::sub_image(I& ima, const S& pset) - : super_(ima), + : ima_(ima), pset_(pset) { } template <typename I, typename S> - bool - sub_image<I,S>::owns_(const mln_psite(I)& p) const - { - return this->domain().has(p); - } - - template <typename I, typename S> const S& sub_image<I,S>::domain() const { @@ -100,6 +92,20 @@ return tmp; } + template <typename I, typename S> + mlc_const(I)* + sub_image<I,S>::impl_delegatee_() const + { + return & ima_; + } + + template <typename I, typename S> + I* + sub_image<I,S>::impl_delegatee_() + { + return & ima_; + } + // operator template <typename I, typename S>