milena r1176: Add image_identity test

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-09-25 Matthieu Garrigues <garrigues@lrde.epita.fr> Test a diamond inherance for image_identity * sandbox/garrigues/image_identity/image_domain_morpher.hh: New. * sandbox/garrigues/image_identity/image_identity.cc: New. * sandbox/garrigues/image_identity/image_identity.hh: New. * sandbox/garrigues/image_identity/image_value_morpher.hh: New. * sandbox/garrigues/image_identity/interpolated.cc: New. * sandbox/garrigues/image_identity/interpolated.hh: New. * sandbox/garrigues/image_identity: New. --- image_domain_morpher.hh | 122 +++++++++++++++++++++++++++++++ image_identity.cc | 9 ++ image_identity.hh | 77 +++++++++++++++++++ image_value_morpher.hh | 95 ++++++++++++++++++++++++ interpolated.cc | 70 ++++++++++++++++++ interpolated.hh | 185 ++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 558 insertions(+) Index: trunk/milena/sandbox/garrigues/image_identity/image_identity.cc =================================================================== --- trunk/milena/sandbox/garrigues/image_identity/image_identity.cc (revision 0) +++ trunk/milena/sandbox/garrigues/image_identity/image_identity.cc (revision 1176) @@ -0,0 +1,9 @@ +namespace sandbox +{ + +} + +int main() +{ + +} Index: trunk/milena/sandbox/garrigues/image_identity/image_domain_morpher.hh =================================================================== --- trunk/milena/sandbox/garrigues/image_identity/image_domain_morpher.hh (revision 0) +++ trunk/milena/sandbox/garrigues/image_identity/image_domain_morpher.hh (revision 1176) @@ -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 virtual 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: trunk/milena/sandbox/garrigues/image_identity/image_value_morpher.hh =================================================================== --- trunk/milena/sandbox/garrigues/image_identity/image_value_morpher.hh (revision 0) +++ trunk/milena/sandbox/garrigues/image_identity/image_value_morpher.hh (revision 1176) @@ -0,0 +1,95 @@ +// 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 virtual image_morpher_<I, mln_pset(I), E> + { + public: + + const mln_pset(I)& domain() const; + bool owns_(const mln_psite(I)& p) const; + + 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); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::internal + +} // end of namespace mln + + +#endif // ! MLN_CORE_INTERNAL_IMAGE_VALUE_MORPHER_HH Index: trunk/milena/sandbox/garrigues/image_identity/interpolated.hh =================================================================== --- trunk/milena/sandbox/garrigues/image_identity/interpolated.hh (revision 0) +++ trunk/milena/sandbox/garrigues/image_identity/interpolated.hh (revision 1176) @@ -0,0 +1,185 @@ +// 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_INTERPOLATED_HH +# define MLN_CORE_INTERPOLATED_HH + +/*! \file mln/core/interpolated.hh + * + * \brief Definition of an image class FIXME + */ + +# include <cmath> + +# include "image_identity.hh" +# include <mln/metal/vec.hh> + + +namespace mln +{ + + // Fwd decl. + template <typename I> struct interpolated; + + namespace internal + { + + template <typename I> + struct data_< interpolated<I> > + { + data_(I& ima); + + I ima_; + }; + + } // end of namespace mln::internal + + /*! \brief FIXME + * + */ + template <typename I> + struct interpolated : public mln::internal::image_identity_< I, mln_pset(I), interpolated<I> > + { + + typedef mln::internal::image_identity_< I, mln_pset(I), interpolated<I> > super_; + + /// Point_Site associated type. + typedef mln_psite(I) psite; + + /// Value associated type. + typedef mln_value(I) value; + + /// Return type of read-write access. + typedef mln_lvalue(I) lvalue; // FIXME: Depends on lvalue presence in I. + + /// Return type of read-only access. + typedef mln_rvalue(I) rvalue; + + /// Value set associated type. + typedef mln::value::set<value> vset; + + + /// Skeleton. + typedef interpolated< tag::image_<I> > skeleton; + + + /// Constructors. + interpolated(I& ima); + interpolated(); + + + /// Test if this image has been initialized. + bool has_data() const; + + /// Test if a pixel value is accessible at \p p. + using super_::owns_; + + /// Test if a pixel value is accessible at \p v. + bool owns_(const mln::metal::vec<I::point::dim, float>& v) const; + + /// Read-only access of pixel value at point site \p p. + /// Mutable access is only OK for reading (not writing). + using super_::operator(); + + mln_value(I) operator()(const mln::metal::vec<I::point::dim, float>& v) const; + + + /// Give the set of values of the image. + const vset& values() const; + }; + + + +# ifndef MLN_INCLUDE_ONLY + + namespace internal + { + + // internal::data_< interpolated<I,S> > + + template <typename I> + data_< interpolated<I> >::data_(I& ima) + : ima_(ima) + { + } + + } // end of namespace mln::internal + + template <typename I> + interpolated<I>::interpolated(I& ima) + { + mln_precondition(ima.has_data()); + this->data_ = new internal::data_< interpolated<I> >(ima); + } + + template <typename I> + interpolated<I>::interpolated() + { + } + + template <typename I> + bool interpolated<I>::has_data() const + { + mln_invariant(this->data_->ima_.has_data()); + return true; + } + + template <typename I> + bool interpolated<I>::owns_(const mln::metal::vec<I::point::dim, float>& v) const + { + mln_point(I) p; + for (unsigned i = 0; i < I::point::dim; ++i) + p[i] = static_cast<int>(round(v[i])); + return this->data_->ima_.owns_(p); + } + + template <typename I> + mln_value(I) + interpolated<I>::operator()(const mln::metal::vec<I::point::dim, float>& v) const + { + mln_point(I) p; + for (unsigned i = 0; i < I::point::dim; ++i) + p[i] = static_cast<int>(round(v[i])); + mln_assertion(this->data_->ima_.owns_(p)); + return this->data_->ima_(p); + } + + // FIXME : Should we remove this method? (and inherit it from + // identity morpher) + template <typename I> + const mln::value::set<mln_value(I) >& + interpolated<I>::values() const + { + return vset::the(); + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_CORE_INTERPOLATED_HH Index: trunk/milena/sandbox/garrigues/image_identity/image_identity.hh =================================================================== --- trunk/milena/sandbox/garrigues/image_identity/image_identity.hh (revision 0) +++ trunk/milena/sandbox/garrigues/image_identity/image_identity.hh (revision 1176) @@ -0,0 +1,77 @@ +// 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_IDENTITY_HH +# define MLN_CORE_INTERNAL_IMAGE_IDENTITY_HH + +/*! \file mln/core/internal/image_identity.hh + * + * \brief Definition of a base class for image morphers w.r.t. identity. + */ + +# include "image_value_morpher.hh" +# include "image_domain_morpher.hh" + +namespace mln +{ + + namespace internal + { + + + /*! \brief A base class for image morphers w.r.t. identity. + * + * Parameter \p S is a point set type. + * + * \internal + */ + template <typename I, typename S, typename E> + class image_identity_ : public image_domain_morpher_<I, S, E>, + public image_value_morpher_<I, E> + { + public: + + protected: + image_identity_(); + }; + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I, typename S, typename E> + image_identity_<I,S,E>::image_identity_() + { + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::internal + +} // end of namespace mln + + +#endif // ! MLN_CORE_INTERNAL_IMAGE_IDENTITY_HH Index: trunk/milena/sandbox/garrigues/image_identity/interpolated.cc =================================================================== --- trunk/milena/sandbox/garrigues/image_identity/interpolated.cc (revision 0) +++ trunk/milena/sandbox/garrigues/image_identity/interpolated.cc (revision 1176) @@ -0,0 +1,70 @@ +// 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. + +/*! \file tests/image2d_b.cc + * + * \brief Tests on mln::image2d_b. + */ + + +#include <iostream> +#include <mln/core/image2d_b.hh> +#include "interpolated.hh" + +#include <mln/metal/vec.hh> + +#include <mln/level/fill.hh> + +#include <mln/debug/println.hh> + + + +int main() +{ + using namespace mln; + + const unsigned nrows = 4; + const unsigned ncols = 4; + const unsigned border = 4; + + image2d_b<float> f(nrows, ncols, border); + float tab[] = {1., 3., 5., 7., + 4., 7., 10., 13., + 7., 11., 15., 19., + 10., 15., 20., 25.}; + level::fill(f, tab); + + interpolated< image2d_b<float> > inter(f); + + metal::vec<2, float> v1 = make::vec(2.3, 0.6); + metal::vec<2, float> v2 = make::vec(3.2, 1.8); + + debug::println(f); + + std::cout << v1 << " : " << inter(v1) << std::endl; + std::cout << v2 << " : " << inter(v2) << std::endl; +}
participants (1)
-
Matthieu Garrigues