milena r1289: Move translate image into mln/core and add comment on some files

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-10-10 Guillaume Duhamel <guillaume.duhamel@lrde.epita.fr> Move translate image into mln/core and add comment on some files. New image. * translate_image.hh: New. Comment * concept/image.hh, * internal/image_domain_morpher.hh, * internal/image_identity.hh: New comment. * point.hh: Add operator -= between point and dpoint. --- concept/image.hh | 3 internal/image_domain_morpher.hh | 2 internal/image_identity.hh | 3 point.hh | 12 ++ translate_image.hh | 196 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 214 insertions(+), 2 deletions(-) Index: trunk/milena/mln/core/point.hh =================================================================== --- trunk/milena/mln/core/point.hh (revision 1288) +++ trunk/milena/mln/core/point.hh (revision 1289) @@ -117,6 +117,9 @@ /// Shifting by \p dp. point_<M,C>& operator+=(const dpoint& dp); + /// Shifting by \p the inverse of dp. + point_<M,C>& operator-=(const dpoint& dp); + /// Type of the array of coordinates. typedef metal::vec<M::dim, C> vec_t; @@ -187,6 +190,15 @@ } template <typename M, typename C> + point_<M,C>& + point_<M,C>::operator-=(const dpoint& dp) + { + for (unsigned i = 0; i < dim; ++i) + coord_[i] -= dp[i]; + return *this; + } + + template <typename M, typename C> point_<M,C>::operator typename internal::point_to_<M, C>::metal_vec () const { return coord_; // FIXME: Is-it OK? Index: trunk/milena/mln/core/translate_image.hh =================================================================== --- trunk/milena/mln/core/translate_image.hh (revision 0) +++ trunk/milena/mln/core/translate_image.hh (revision 1289) @@ -0,0 +1,196 @@ +// 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_TRANSLATE_IMAGE_HH +# define MLN_CORE_TRANSLATE_IMAGE_HH + +/*! \file mln/core/translate_image.hh + * + * \brief Definition of a translated image. + */ + +# include <cmath> + +# include <mln/core/internal/image_identity.hh> +# include <mln/core/box2d.hh> + + +namespace mln +{ + + // Fwd decl. + template <typename I> struct translate_image; + + namespace internal + { + + template <typename I> + struct data_< translate_image<I> > + { + data_(I& ima, const mln_dpoint(I) dp); + + I ima_; + box2d bb_; + const mln_dpoint(I) dp_; + }; + + } // end of namespace mln::internal + + + + namespace trait + { + + template <typename I> + struct image_< translate_image<I> > : default_image_morpher_< I, mln_value(I), + translate_image<I> > + { + + typedef trait::image::category::domain_morpher category; + + typedef mln_trait_image_io_from_(I) io; + + typedef mln_trait_image_data_from_(I) data; + + }; + + } // end of namespace mln::trait + + + + /*! \brief FIXME + * + */ + template <typename I> + struct translate_image : public mln::internal::image_identity_< I, mln_pset(I), translate_image<I> > + { + + typedef mln::internal::image_morpher_< I, mln_pset(I), translate_image<I> > super_; + + /// Return type of read-write access. + typedef typename internal::morpher_lvalue_<I>::ret lvalue; + + /// Skeleton. + typedef translate_image< tag::image_<I> > skeleton; + + /// Test if a pixel value is accessible at \p p. + using super_::has_data; + + /// Constructors. + translate_image(I& ima, const mln_dpoint(I) dp); + translate_image(); + + /// Return domain of translated_image. + const box2d& domain() const; + + /// Test if a pixel value is accessible at \p p. + bool owns_(const mln_psite(I)& ) const; + + /// Read-only access of pixel value at point site \p p. + mln_rvalue(I) operator()(const mln_psite(I)& p) const; + + /// Read and "write if possible" access of pixel value at point site \p p. + lvalue operator()(const mln_psite(I)& p); + }; + + + +# ifndef MLN_INCLUDE_ONLY + + namespace internal + { + + // internal::data_< translate_image<I,S> > + + template <typename I> + data_< translate_image<I> >::data_(I& ima, const mln_dpoint(I) dp) + : ima_ (ima), + dp_ (dp) + { + point2d start = ima.bbox ().pmin () + dp; + point2d end = ima.bbox ().pmax () + dp; + int x1 = start[0]; + int y1 = start[1]; + int x2 = end[0]; + int y2 = end[1]; + + bb_ = make::box2d (x1, y1, x2, y2); + } + + } // end of namespace mln::internal + + template <typename I> + translate_image<I>::translate_image(I& ima, const mln_dpoint(I) dp) + { + mln_precondition(ima.has_data()); + this->data_ = new internal::data_< translate_image<I> >(ima, dp); + } + + template <typename I> + translate_image<I>::translate_image() + { + } + + template <typename I> + bool translate_image<I>::owns_(const mln_psite(I)& p) const + { + mln_point(I) np = p - this->data_->dp_; + return this->data_->ima_.owns_(np); + } + + template <typename I> + mln_rvalue(I) + translate_image<I>::operator()(const mln_psite(I)& p) const + { + mln_assertion(this->owns_(p)); + mln_point(I) np = p - this->data_->dp_; + return this->data_->ima_(np); + } + + + template <typename I> + typename translate_image<I>::lvalue + translate_image<I>::operator()(const mln_psite(I)& p) + { + mln_assertion(this->owns_(p)); + mln_point(I) np = p - this->data_->dp_; + return this->data_->ima_(np); + } + + template <typename I> + const box2d& + translate_image<I>::domain() const + { + return this->data_->bb_; + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_CORE_TRANSLATE_IMAGE_HH Index: trunk/milena/mln/core/internal/image_identity.hh =================================================================== --- trunk/milena/mln/core/internal/image_identity.hh (revision 1288) +++ trunk/milena/mln/core/internal/image_identity.hh (revision 1289) @@ -76,10 +76,13 @@ /// Read-write access of pixel value at point site \p p. lvalue operator()(const mln_psite(S)& p); + // FIXME Matthieu: Doc! Cf. core/concept/doc/image const mln_pset(I)& domain() const; bool owns_(const mln_psite(I)& p) const; protected: + + /// Constructor. image_identity_(); }; Index: trunk/milena/mln/core/internal/image_domain_morpher.hh =================================================================== --- trunk/milena/mln/core/internal/image_domain_morpher.hh (revision 1288) +++ trunk/milena/mln/core/internal/image_domain_morpher.hh (revision 1289) @@ -73,7 +73,7 @@ /// 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. + /// Read and "write if possible" access of pixel value at point site \p p. lvalue operator()(const mln_psite(S)& p); protected: Index: trunk/milena/mln/core/concept/image.hh =================================================================== --- trunk/milena/mln/core/concept/image.hh (revision 1288) +++ trunk/milena/mln/core/concept/image.hh (revision 1289) @@ -82,7 +82,6 @@ typedef lvalue; typedef vset; - bool has_data() const; const vset& values() const; bool owns_(const psite& p) const; @@ -109,6 +108,8 @@ bool has(const psite& p) const; const box_<point>& bbox() const; std::size_t npoints() const; + + bool has_data() const; */ protected:
participants (1)
-
Guillaume Duhamel