
https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Nicolas Ballas <ballas@lrde.epita.fr> Add run image type encoded by image type. * tests/core/value_enc_image.cc: tests. * mln/core/pset_array.hh: Fix a mistake. * mln/core/value_enc_image.hh: New image type. mln/core/pset_array.hh | 4 mln/core/value_enc_image.hh | 243 ++++++++++++++++++++++++++++++++++++++++++ tests/core/value_enc_image.cc | 47 ++++++++ 3 files changed, 292 insertions(+), 2 deletions(-) Index: tests/core/value_enc_image.cc --- tests/core/value_enc_image.cc (revision 0) +++ tests/core/value_enc_image.cc (revision 0) @@ -0,0 +1,47 @@ +// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE) +// +// 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/core/rle_image.cc + * + * \brief Test on mln::core::value_enc_image.hh. + */ + +#include <mln/core/image2d.hh> +#include <mln/core/value_enc_image.hh> + + +int main() +{ + using namespace mln; + + /// Basic tests + { + typedef value_enc_image<point2d, int> ima_type; + + ima_type ima(); + } +} Index: mln/core/pset_array.hh --- mln/core/pset_array.hh (revision 1905) +++ mln/core/pset_array.hh (working copy) @@ -129,8 +129,8 @@ bool pset_array<Pset>::has(const typename pset_array<Pset>::psite& ps) const { - mln_precondition(ps.to_index() < con_.size()); - return con_[ps.to_index()].has(ps.to_psite()); + return ps.to_index() < con_.size() && + con_[ps.to_index()].has(ps.to_psite()); } template <typename Pset> Index: mln/core/value_enc_image.hh --- mln/core/value_enc_image.hh (revision 0) +++ mln/core/value_enc_image.hh (revision 0) @@ -0,0 +1,243 @@ +// Copyright (C) 2007, 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_VALUE_ENC_IMAGE_CC_ +# define MLN_CORE_VALUE_ENC_IMAGE_CC_ + +/*! \file mln/core/value_enc_image.hh + * + * \brief FIXME + */ + +# include <mln/core/internal/image_primary.hh> + +# include <mln/core/pset_array.hh> +# include <mln/core/pset_array_psite.hh> +# include <mln/core/p_runs.hh> + +# include <vector> + +namespace mln +{ + + // Fwd decl. + template <typename P, typename T> struct value_enc_image; + + + namespace internal + { + + /// \internal Data structure for \c mln::rle_image<P,T>. + template <typename P, typename T> + struct data_< value_enc_image<P, T> > + { + data_(); + + /// Image values. + std::vector<T> values_; + + /// domain of the image + pset_array< p_runs_<P> > domain_; + }; + + } // end of namespace mln::internal + + + namespace trait + { + + template <typename P, typename T> + struct image_< value_enc_image<P,T> > : + default_image_< T, rle_image<P,T> > + { + typedef trait::image::category::primary category; + + typedef trait::image::access::browsing access; + + // FIXME: Put the right dimension. + typedef trait::image::space::two_d space; + + typedef trait::image::size::regular size; + typedef trait::image::support::aligned support; + + typedef trait::image::border::none border; + typedef trait::image::data::linear data; + typedef trait::image::io::read_only io; + typedef trait::image::speed::slow speed; + }; + + } // end of namespace mln::trait + + + /*! \brief Value encoded image. + * FIXME + */ + template <typename P, typename T> + class value_enc_image : + public internal::image_primary_< pset_array_psite< runs_psite<P> >, + value_enc_image<P, T> > + { + public: + + /// Value related typedefs + typedef T value; + typedef T& lvalue; + typedef const T rvalue; + typedef mln::value::set<T> vset; + + /// Domain related typedefs + typedef pset_array_psite< runs_psite<P> > psite; + typedef pset_array< p_runs_<P> > pset; + + /// Skeleton. + typedef value_enc_image< tag::psite_<P>, tag::value_<T> > skeleton; + + + value_enc_image(); + + /// Add a new range to the image. + void insert(const p_runs_<P>& pr, T value); + + /*! \brief Tell if the image has the given point site. + * + * \return True if the image has the point site, else false. + */ + bool has(const psite& ps) const; + + /// Read-only access to the image value located at the site \site. + rvalue operator() (const psite& site) const; + + /// Read-write access to the image value located at the site \site. + lvalue operator() (const psite& site); + + /// Test if this image has been initialized. + bool has_data() const; + + /// Give the set of values of the image. + const vset& values() const; + + /// Give the definition domain. + const pset& domain() const; + + }; + + +# ifndef MLN_INCLUDE_ONLY + + namespace internal + { + + // internal::data_< value_enc_image<P, T> > + + template <typename P, typename T> + inline + data_< value_enc_image<P,T> >::data_() + { + } + + } // end of namespace mln::internal + + + template <typename P, typename T> + inline + value_enc_image<P, T>::value_enc_image() + { + this->data_ = new internal::data_< value_enc_image<P,T> >(); + } + + template <typename P, typename T> + inline + bool + value_enc_image<P, T>::has_data() const + { + return this->data_->values_.size() != 0; + } + + template <typename P, typename T> + inline + const typename value_enc_image<P, T>::vset& + value_enc_image<P, T>::values() const + { + return vset::the(); + } + + template <typename P, typename T> + inline + void + value_enc_image<P, T>::insert(const p_runs_<P>& pr, T value) + { + if (!this->has_data()) + this->data_ = new internal::data_< value_enc_image<P,T> >(); + + this->data_->domain_.insert(pr); + this->data_->values_.push_back(value); + } + + template <typename P, typename T> + inline + bool + value_enc_image<P, T>::has(const typename value_enc_image<P, T>::psite& site) const + { + return this->data_.domain_.has(site); + } + + template <typename P, typename T> + inline + typename value_enc_image<P, T>::rvalue + value_enc_image<P, T>::operator() (const typename value_enc_image<P, T>::psite& site) + const + { + mln_precondition(this->has(site)); + + return this->data_->values_[site.to_index()]; + } + + template <typename P, typename T> + inline + typename value_enc_image<P, T>::lvalue + value_enc_image<P, T>::operator() (const typename value_enc_image<P, T>::psite& site) + { + mln_precondition(this->has(site)); + + return this->data_->values_[site.to_index()]; + } + + template <typename P, typename T> + inline + const typename value_enc_image<P, T>::pset& + value_enc_image<P, T>::domain() const + { + return this->data_->domain_; + } + +# endif // ! MLN_INCLUDE_ONLY + + +} // end of namespace mln + + +#endif // ! MLN_CORE_VALUE_ENC_IMAGE_CC_