
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-09-28 Guillaume Duhamel <guillaume.duhamel@lrde.epita.fr> Add mesh_image in mln/core. * mesh_image.hh: New class of image. * mesh_p.hh: New. * mesh_p_piter.hh: New. * mesh_psite.hh: New. --- mesh_image.hh | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ mesh_p.hh | 119 +++++++++++++++++++++++++++++++++++++ mesh_p_piter.hh | 158 +++++++++++++++++++++++++++++++++++++++++++++++++ mesh_psite.hh | 101 +++++++++++++++++++++++++++++++ 4 files changed, 555 insertions(+) Index: trunk/milena/mln/core/mesh_psite.hh =================================================================== --- trunk/milena/mln/core/mesh_psite.hh (revision 0) +++ trunk/milena/mln/core/mesh_psite.hh (revision 1195) @@ -0,0 +1,101 @@ +// 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. +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef MLN_MESH_PSITE_HH +# define MLN_MESH_PSITE_HH + +/*! \file mln/core/mesh_p.hh + * + * \brief Definition of mln::mesh_psite. + */ + +namespace mln +{ + + template<typename P> class mesh_p; + + template<typename P> + struct mesh_psite : public Point_Site< mesh_psite<P> > + { + typedef mln_mesh(P) mesh; + enum { dim = P::dim }; + typedef P point; + typedef mln_dpoint(P) dpoint; + typedef mln_coord(P) coord; + + mesh_psite(unsigned i, mesh_p<P>* m_ptr); + P to_point() const; + operator P() const; + const point* pointer_() const; + coord operator[](unsigned i) const; + + unsigned i_; + mesh_p<P>* m_ptr_; + }; + +# ifndef MLN_INCLUDE_ONLY + + template<typename P> + mesh_psite<P>::mesh_psite(unsigned i, mesh_p<P>* m_ptr) + : i_(i) , + m_ptr_(m_ptr) + { + } + + template<typename P> + P + mesh_psite<P>::to_point() const + { + return m_ptr_->loc_[i_]; + } + + template<typename P> + mesh_psite<P>::operator P() const + { + return m_ptr_->loc_[i_]; + } + + template<typename P> + const P* + mesh_psite<P>::pointer_() const + { + return 0; + } + + template<typename P> + mln_coord(P) + mesh_psite<P>::operator[](unsigned i) const + { + return to_point()[i]; + } + +# endif // ! MLN_INCLUDE_ONLY + + +} // end of mln + +#endif // MLN_MESH_PSITE_HH Index: trunk/milena/mln/core/mesh_p.hh =================================================================== --- trunk/milena/mln/core/mesh_p.hh (revision 0) +++ trunk/milena/mln/core/mesh_p.hh (revision 1195) @@ -0,0 +1,119 @@ +// 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. +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef MLN_MESH_P_HH +# define MLN_MESH_P_HH + +# include <mln/core/concept/point.hh> +# include <mln/core/internal/point_set_base.hh> +# include <mln/accu/bbox.hh> +# include <mln/util/graph.hh> +# include <mln/core/mesh_psite.hh> +# include <mln/core/mesh_p_piter.hh> + +/*! \file mln/core/mesh_p.hh + * + * \brief Definition of mln::mesh_p. + */ + +namespace mln +{ + + template<typename P> class mesh_p_piter_; + + template<typename P> + struct mesh_p : public internal::point_set_base_< P, mesh_p<P> > + { + mesh_p (util::graph<void>& gr, + std::vector<P>& loc); + + /// Point_Site associated type. + typedef mesh_psite<P> psite; + + /// Forward Point_Iterator associated type. + typedef mesh_p_piter_<P> fwd_piter; + + /// Backward Point_Iterator associated type. + typedef mesh_p_piter_<P> bkd_piter; // FIXME + + std::size_t npoints() const; + + /// Give the exact bounding box. + const box_<P>& bbox() const; + + bool has(const psite& p) const; + + util::graph<void> gr_; + std::vector<P> loc_; + box_<P> bb_; + }; + +# ifndef MLN_INCLUDE_ONLY + + template<typename P> + mesh_p<P>::mesh_p (util::graph<void>& gr, + std::vector<P>& loc) + : gr_ (gr), + loc_ (loc) + { + accu::bbox<P> a; + for (unsigned i = 0; i < loc.size(); ++i) + a.take(loc[i]); + bb_ = a.to_result(); + } + + template<typename P> + std::size_t + mesh_p<P>::npoints() const + { + return this->gr_.nb_node_; + } + + template<typename P> + const box_<P>& + mesh_p<P>::bbox() const + { + return bb_; + } + + template<typename P> + bool + mesh_p<P>::has(const psite& p) const + { + for (unsigned i = 0; i < loc_.size(); ++i) + if (loc_[i] == p) + return true; + return false; + } + + +# endif // ! MLN_INCLUDE_ONLY + +} // end of mln + + +#endif // MLN_MESH_P_HH Index: trunk/milena/mln/core/mesh_p_piter.hh =================================================================== --- trunk/milena/mln/core/mesh_p_piter.hh (revision 0) +++ trunk/milena/mln/core/mesh_p_piter.hh (revision 1195) @@ -0,0 +1,158 @@ +// 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. +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef MLN_CORE_MESH_P_PITER_HH +# define MLN_CORE_MESH_P_PITER_HH + +# include <mln/core/internal/point_iterator_base.hh> +# include <mln/core/mesh_p.hh> + +/*! \file mln/core/mesh_psite.hh + * + * \brief Definition of a graph. + */ + +namespace mln +{ + + template<typename P> class mesh_p_piter_; + + template<typename P> + class mesh_p_piter_ : public internal::point_iterator_base_< P, mesh_p_piter_<P> > + { + typedef mesh_p_piter_<P> self_; + typedef internal::point_iterator_base_< P, self_ > super_; + + public: + + // Make definitions from super class available. + enum { dim = super_::dim }; + + mesh_p_piter_(const mesh_p<P>& s); + + /// Give a hook to the point address. + const P* pointer_() const; + + /// Read-only access to the \p i-th coordinate. + mln_coord(P) operator[](unsigned i) const; + + /// Test if the iterator is valid. + bool is_valid() const; + + /// Invalidate the iterator. + void invalidate(); + + /// Start an iteration. + void start(); + + /// Go to the next point. + void next_(); + + /// Convert the iterator into a point. + operator P() const; + + protected: + const std::vector<P>& loc_; + unsigned i_; + P p_; + }; + +# ifndef MLN_INCLUDE_ONLY + + template<typename P> + mesh_p_piter_<P>::mesh_p_piter_(const mesh_p<P>& s) + : loc_(s.loc_) + { + invalidate(); + } + + + template<typename P> + const P* + mesh_p_piter_<P>::pointer_() const + { + return & p_; + } + + + template<typename P> + mln_coord(P) + mesh_p_piter_<P>::operator[](unsigned i) const + { + return p_[i]; + } + + + template<typename P> + bool + mesh_p_piter_<P>::is_valid() const + { + return i_ != loc_.size(); + } + + + template<typename P> + void + mesh_p_piter_<P>::invalidate() + { + i_ = loc_.size(); + } + + + template<typename P> + void + mesh_p_piter_<P>::start() + { + i_ = 0; + if (is_valid()) + p_ = loc_[i_]; + } + + + template<typename P> + void + mesh_p_piter_<P>::next_() + { + ++i_; + if (is_valid()) + p_ = loc_[i_]; + } + + + template<typename P> + mesh_p_piter_<P>::operator P() const + { + mln_precondition(is_valid()); + return p_; + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of mln + + +#endif // MLN_MESH_P_PITER_HH Index: trunk/milena/mln/core/mesh_image.hh =================================================================== --- trunk/milena/mln/core/mesh_image.hh (revision 0) +++ trunk/milena/mln/core/mesh_image.hh (revision 1195) @@ -0,0 +1,177 @@ +// 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_MESH_IMAGE_HH +# define MLN_CORE_MESH_IMAGE_HH + +/*! \file mln/core/mesh_image.hh + * + * \brief Definition of an image class mesh_image. + */ + +# include <mln/core/internal/image_identity.hh> +# include <mln/metal/vec.hh> +# include <mln/core/mesh_p.hh> +# include <mln/core/mesh_psite.hh> +# include <vector> + +namespace mln +{ + + // Fwd decl. + template <typename P, typename V> struct mesh_image; + + namespace internal + { + + template <typename P, typename V> + struct data_< mesh_image<P, V> > + { + data_(mesh_p<P>& mesh, std::vector<V>& val); + + std::vector<V> val_; + mesh_p<P> mesh_; + }; + + } // end of namespace mln::internal + + /*! \brief FIXME + * + */ + template <typename P, typename V> + struct mesh_image : public internal::image_primary_< mesh_p<P>, mesh_image<P, V> > + { + + typedef mln::internal::image_base_< mesh_p<P>, mesh_image<P, V> > super_; + + /// Value associated type. + typedef V value; + + /// Return type of read-write access. + typedef V& lvalue; + + /// Return type of read-only access. + typedef const V& rvalue; + + /// Value set associated type. + typedef mln::value::set<value> vset; + + + /// Skeleton. + typedef mesh_image< tag::psite_<P>, tag::value_<V> > skeleton; + + /// Constructors. + mesh_image(mesh_p<P>& mesh, std::vector<V>& val); + mesh_image(); + + /// Read-only access of pixel value at point site \p p. + const V& operator()(const mesh_psite<P>& p) const; + + /// Read-write access of pixel value at point site \p p. + V& operator()(const mesh_psite<P>& p); + + /// Give the set of values of the image. + const vset& values() const; + + const std::vector<V>& data_values () const; + + const mesh_p<P>& domain() const; +}; + + + + +# ifndef MLN_INCLUDE_ONLY + + namespace internal + { + template <typename P, typename V> + data_< mesh_image<P, V> >::data_(mesh_p<P>& mesh, std::vector<V>& val) + : val_ (val), + mesh_ (mesh) + { + } + + } // end of namespace mln::internal + + template <typename P, typename V> + mesh_image<P, V>::mesh_image(mesh_p<P>& mesh, std::vector<V>& val) + { + this->data_ = new internal::data_< mesh_image<P, V> > (mesh, val); + } + + template <typename P, typename V> + mesh_image<P, V>::mesh_image() + { + } + + template <typename P, typename V> + const V& + mesh_image<P, V>::operator()(const mesh_psite<P>& p) const + { + mln_precondition(p.m_ptr_ == & this->data_->mesh_); + mln_precondition(p.i_ < this->data_->val_.size()); + return this->data_->val_[p.i_]; + } + + template <typename P, typename V> + V& + mesh_image<P, V>::operator()(const mesh_psite<P>& p) + { + mln_precondition(p.m_ptr_ == & this->data_->mesh_); + mln_precondition(p.i_ < this->data_->val_.size()); + return this->data_->val_[p.i_]; + } + + template <typename P, typename V> + const mln::value::set<V> & + mesh_image<P, V>::values() const + { + return vset::the(); + } + + template <typename P, typename V> + const std::vector<V>& + mesh_image<P, V>::data_values () const + { + return this->data_->val_; + } + + template <typename P, typename V> + const mesh_p<P>& + mesh_image<P, V>::domain() const + { + mln_precondition(this->has_data()); + return this->data_->mesh_; + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_CORE_MESH_IMAGE_HH