
https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Update of clone and impl::init_with_ mechanism. * mln/core/internal/image_base.hh (init_with_): New. (operator=, image_base_): New. * mln/core/image2d_b.hh: Remove op=, dtor, and cpy ctor. (init_with_): New overload. (init_with): Remove overload with nrows-ncols. * mln/core/sub_image.hh: New ctor. * mln/core/clone.hh: Update. * mln/border/get.hh: New. border/get.hh | 102 ++++++++++++++++++++++++++++++++++++++++++++ core/clone.hh | 33 +++----------- core/image2d_b.hh | 66 ++++++---------------------- core/internal/image_base.hh | 40 ++++++++++++++++- core/sub_image.hh | 8 +++ 5 files changed, 174 insertions(+), 75 deletions(-) Index: mln/core/internal/image_base.hh --- mln/core/internal/image_base.hh (revision 1152) +++ mln/core/internal/image_base.hh (working copy) @@ -55,11 +55,22 @@ } // end of namespace mln::internal + namespace impl + { + + /// Declaration of the general image initialization routine. + template <typename I, typename J> + void init_with_(Image<I>& target, const Image<J>& model); + + // FIXME: Say more about it! + + } // end of namespace mln::impl + + namespace internal { - /*! \brief Return the lvalue type when an image with type \c I is * morphed. * @@ -153,13 +164,22 @@ // FIXME: Add void init_data(..); + + /// Assignment operator. + image_base_& operator=(const image_base_& rhs); + + /// Copy constructor. + image_base_(const image_base_& rhs); + protected: image_base_(); + // Internal data, sharable by several images. util::tracked_ptr< internal::data_<E> > data_; }; + # ifndef MLN_INCLUDE_ONLY template <typename S, typename E> @@ -168,6 +188,24 @@ } template <typename S, typename E> + image_base_<S,E>::image_base_(const image_base_& rhs) + { + mln_precondition(exact(rhs).has_data()); // FIXME: Is-it too restrictive? + this->data_ = rhs.data_; + } + + template <typename S, typename E> + image_base_<S,E>& + image_base_<S,E>::operator=(const image_base_<S,E>& rhs) + { + mln_precondition(exact(rhs).has_data()); // FIXME: Is-it too restrictive? + if (& rhs = this) // || ! exact(rhs).has_data()) + return *this; + this->data_ = rhs.data_; + return *this; + } + + template <typename S, typename E> bool image_base_<S,E>::has_data() const { Index: mln/core/image2d_b.hh --- mln/core/image2d_b.hh (revision 1152) +++ mln/core/image2d_b.hh (working copy) @@ -40,6 +40,8 @@ # include <mln/value/set.hh> # include <mln/fun/i2v/all.hh> # include <mln/core/line_piter.hh> +# include <mln/border/get.hh> +# include <mln/debug/println.hh> // FIXME: @@ -142,23 +144,12 @@ /// 3). image2d_b(const box2d& b, unsigned bdr = border::thickness); - /// Copy constructor. - image2d_b(const image2d_b<T>& rhs); - /// Assignment operator. - image2d_b& operator=(const image2d_b<T>& rhs); - - /// Destructor. - ~image2d_b(); - - /// detach data from an image (free it if nobody else hold it) + /// Detach data from an image (free it if nobody else hold it). void destroy(); /// Initialize an empty image. - void init_with(int nrows, int ncols, unsigned bdr = border::thickness); - - /// Initialize an empty image. void init_with(const box2d& b, unsigned bdr = border::thickness); @@ -220,12 +211,21 @@ /// Give a hook to the value buffer. T* buffer(); + }; - private: + namespace impl + { - typedef internal::image_base_< box2d, image2d_b<T> > super; - }; + template <typename T, typename I> + void init_with_(image2d_b<T>& target, const I& model) + { + box2d b = model.domain(); + unsigned bdr = border::get(model); + target = image2d_b<T>(b, bdr); + } + + } // end of namespace mln::impl @@ -312,15 +312,7 @@ template <typename T> image2d_b<T>::image2d_b(int nrows, int ncols, unsigned bdr) { - init_with(nrows, ncols, bdr); - } - - template <typename T> - void - image2d_b<T>::init_with(int nrows, int ncols, unsigned bdr) - { - mln_precondition(! this->has_data()); - this->data_ = new internal::data_< image2d_b<T> >(make::box2d(nrows, ncols), bdr); + init_with(make::box2d(nrows, ncols), bdr); } template <typename T> @@ -338,27 +330,6 @@ } template <typename T> - image2d_b<T>::image2d_b(const image2d_b<T>& rhs) - { - } - - // assignment - - template <typename T> - image2d_b<T>& - image2d_b<T>::operator=(const image2d_b<T>& rhs) - { - mln_precondition(rhs.has_data()); - if (& rhs = this) - return *this; - - this->data_ = rhs.data_; - return *this; - } - - // methods - - template <typename T> const typename image2d_b<T>::vset& image2d_b<T>::values() const { @@ -446,11 +417,6 @@ } template <typename T> - image2d_b<T>::~image2d_b() - { - } - - template <typename T> const T* image2d_b<T>::buffer() const { Index: mln/core/sub_image.hh --- mln/core/sub_image.hh (revision 1152) +++ mln/core/sub_image.hh (working copy) @@ -63,6 +63,9 @@ /// Skeleton. typedef sub_image< tag::image<I>, tag::pset<S> > skeleton; + /// Constructor without argument. + sub_image(); + /// Constructor. sub_image(I& ima, const S& pset); @@ -109,6 +112,11 @@ } template <typename I, typename S> + sub_image<I,S>::sub_image() + { + } + + template <typename I, typename S> const S& sub_image<I,S>::domain() const { Index: mln/core/clone.hh --- mln/core/clone.hh (revision 1152) +++ mln/core/clone.hh (working copy) @@ -34,6 +34,7 @@ */ # include <mln/core/concept/image.hh> +# include <mln/level/fill.hh> namespace mln @@ -41,40 +42,24 @@ /*! Clone the image \p ima with the values of the image \p data. * - * \param[in,out] ima The image to be cloneed. - * \param[in] data The image. + * \param[in] ima The image to be cloneed. + * \result The clone. * - * \warning The definition domain of \p ima has to be included in - * the one of \p data. - * - * \pre \p ima.domain <= \p data.domain. - * - * \todo Use memcpy when possible. + * \pre ima.has_data */ template <typename I> - mln_concrete(I) clone(const Image<I>& ima); - + mln_concrete(I) clone(const Image<I>& model); # ifndef MLN_INCLUDE_ONLY - namespace impl - { - - template <typename I> - void clone_(mln_concrete(I)& result, const Image<I>& ima) - { - std::cerr << "oops" << std::endl; // FIXME: Fake code. - } - - } // end of namespace mln::impl - - template <typename I> - mln_concrete(I) clone(const Image<I>& ima) + mln_concrete(I) clone(const Image<I>& model) { + // FIXME: Add a static check that mln_concrete(I) actually *is* concrete... mln_concrete(I) tmp; - impl::clone_(ima, tmp); + impl::init_with_(tmp, exact(model)); + level::fill(tmp, model); return tmp; } Index: mln/border/get.hh --- mln/border/get.hh (revision 0) +++ mln/border/get.hh (revision 0) @@ -0,0 +1,102 @@ +// 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_BORDER_GET_HH +# define MLN_BORDER_GET_HH + +/*! \file mln/border/get.hh + * + * \brief FIXME. + */ + +# include <mln/core/internal/image_morpher.hh> + + +namespace mln +{ + + namespace border + { + + /*! Get the virtual (outer) border thickness of image \p ima. + * + * \param[in] ima The image. + * \result The border thickness (0 if there is no border). + */ + template <typename I> + unsigned get(const Image<I>& ima); + + +# ifndef MLN_INCLUDE_ONLY + + namespace impl + { + + template <typename I, typename S, typename E> + unsigned get__(const mln::internal::image_morpher_<I,S,E>& ima) + { + return border::get(ima.delegatee_()); + } + + template <typename S, typename E> + unsigned get__(const mln::internal::image_base_<S,E>& ima) + { + return 0; + } + + template <typename I> + unsigned get_(const Image<I>& ima) + { + return border::impl::get__(exact(ima)); + } + + template <typename I> + unsigned get_(const Fast_Image<I>& ima) + { + return exact(ima).border(); + } + + } // end of namespace mln::border::impl + + + // Facade. + + template <typename I> + unsigned get(const Image<I>& ima) + { + mln_precondition(exact(ima).has_data()); + return border::impl::get_(exact(ima)); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::border + +} // end of namespace mln + + +#endif // ! MLN_BORDER_GET_HH