
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-10-08 Matthieu Garrigues <garrigues@lrde.epita.fr> Add hexa images. * mln/core/box2d_h.hh: New. * mln/core/dpoint2d_h.hh: New. * mln/core/hexa.hh: New. * mln/core/point2d_h.hh: New. * mln/make/box2d_h.hh: New. * mln/make/dpoint2d_h.hh: New. * mln/make/point2d_h.hh: New. * tests/hexa.cc: New, Fixme : write more tests. --- mln/core/box2d_h.hh | 58 ++++++++++++ mln/core/dpoint2d_h.hh | 68 ++++++++++++++ mln/core/hexa.hh | 230 +++++++++++++++++++++++++++++++++++++++++++++++++ mln/core/point2d_h.hh | 56 +++++++++++ mln/make/box2d_h.hh | 101 +++++++++++++++++++++ mln/make/dpoint2d_h.hh | 72 +++++++++++++++ mln/make/point2d_h.hh | 72 +++++++++++++++ tests/hexa.cc | 47 ++++++++++ 8 files changed, 704 insertions(+) Index: trunk/milena/tests/hexa.cc =================================================================== --- trunk/milena/tests/hexa.cc (revision 0) +++ trunk/milena/tests/hexa.cc (revision 1269) @@ -0,0 +1,47 @@ +// 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/hexa.cc + * + * \brief Tests on mln::hexa + */ + +#include <mln/core/image2d_b.hh> +#include <mln/core/hexa.hh> + +#include <mln/value/int_u8.hh> + +int main() +{ + using namespace mln; + using typename value::int_u8; + + typedef image2d_b<int_u8> I; + + I ima(3,3); + hexa< I > h(ima); +} Index: trunk/milena/mln/core/hexa.hh =================================================================== --- trunk/milena/mln/core/hexa.hh (revision 0) +++ trunk/milena/mln/core/hexa.hh (revision 1269) @@ -0,0 +1,230 @@ +// 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_HEXA_HH +# define MLN_CORE_HEXA_HH + + +/*! \file mln/core/hexa.hh + * + * \brief Definition of the mln::hexa class. + */ + +# include <mln/core/internal/image_domain_morpher.hh> +# include <mln/core/point2d_h.hh> + + +namespace mln +{ + // Fwd decl. + template <typename I> class hexa; + + + namespace internal + { + + template <typename I> + struct data_< hexa<I> > + { + data_(I& ima); + + I ima_; + }; + + } // end of namespace mln::internal + + + namespace trait + { + + template <typename I> + struct image_< hexa<I> > : default_image_morpher_< I, mln_value(I), + hexa<I> > + { + // private: + // typedef mln_trait_image_data(I) I_data_; + // typedef mlc_equal(I_data_, trait::data::linear) I_data_are_linear_; + // public: + + typedef trait::image::category::domain_morpher category; + + typedef trait::image::border::none border; // no more accessible border + + typedef mln_trait_image_io_from_(I) io; // un-write when I const + + typedef mln_trait_image_data_from_(I) data; + // typedef mlc_if( I_data_are_linear_, + // trait::data::stored, // if linear then just stored + // I_data_ ) data; // otherwise like I + }; + + } // end of namespace mln::trait + + + /*! \brief hexagonal image class. + * + * The parameter \c I is the type of the base image. This image class + * which handles hexagonal grid. + */ + template <typename I> + struct hexa : public internal::image_domain_morpher_< I, mln_pset(I), hexa<I> > + { + /// Skeleton. + typedef hexa< tag::image_<I> > skeleton; + + /// Value associated type. + typedef mln_value(I) value; + + /// Lvalue associated type. + typedef mln_value(I) lvalue; + + /// Return type of read-only access. + typedef mln_rvalue(I) rvalue; + + /// Point site type + typedef point2d_h psite; + + /// Constructor without argument. + hexa(); + + /// Constructor with an base image. + hexa(I& ima); + + /// Initialization. + void init_(I& ima); + + /// Give the definition domain. + const mln_pset(I)& domain() const; + + /// Test if \p p belongs to the image domain. + bool has(const psite& p) const; + bool owns_(const psite& p) const; + + /// Read-only access of pixel value at hexa point site \p p. + rvalue operator()(const point2d_h& p) const; + + /// Read-write access of pixel value at hexa point site \p p. + value operator()(const point2d_h& p); + }; + + template <typename I, typename J> + void init_(tag::image_t, hexa<I>& target, const J& model); + +# ifndef MLN_INCLUDE_ONLY + + + // init_ + + template <typename I, typename J> + void init_(tag::image_t, hexa<I>& target, const J& model) + { + I ima; + init_(tag::image, ima, model); + target.init_(ima); + } + + + + // internal::data_< hexa<I> > + + namespace internal + { + + template <typename I> + data_< hexa<I> >::data_(I& ima) + : ima_(ima) + { + } + + } // end of namespace mln::internal + + + template <typename I> + void + hexa<I>::init_(I& ima) + { + mln_precondition(! this->has_data()); + this->data_ = new internal::data_< hexa<I> >(ima); + } + + + + template <typename I> + hexa<I>::hexa() + { + } + + + template <typename I> + hexa<I>::hexa(I& ima) + { + this->init_(ima); + } + + template <typename I> + typename hexa<I>::rvalue + hexa<I>::operator()(const point2d_h& p) const + { + return this->data_->ima_(make::point2d(p[0] / 2, p[1] / 2)); + } + + template <typename I> + typename hexa<I>::value + hexa<I>::operator()(const point2d_h& p) + { + return this->data_->ima_(make::point2d(p[0] / 2, p[1] / 2)); + } + + template <typename I> + const mln_pset(I)& + hexa<I>::domain() const + { + return this->data_->ima_.domain(); + } + + template <typename I> + bool + hexa<I>::has(const psite& p) const + { + return this->data_->ima_.has(make::point2d(p[0] / 2, p[1] / 2)); + } + + + template <typename I> + bool + hexa<I>::owns_(const psite& p) const + { + return this->has(p); + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_CORE_HEXA_HH Index: trunk/milena/mln/core/dpoint2d_h.hh =================================================================== --- trunk/milena/mln/core/dpoint2d_h.hh (revision 0) +++ trunk/milena/mln/core/dpoint2d_h.hh (revision 1269) @@ -0,0 +1,68 @@ +// 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_DPOINT2D_H_HH +# define MLN_CORE_DPOINT2D_H_HH + +/*! \file mln/core/dpoint2d_h.hh + * + * \brief Definition of the mln::dpoint2d_h alias and of its + * construction routine. + */ + +# include <mln/core/dpoint.hh> + + +namespace mln +{ + + /*! \brief Type alias for a delta-point defined on the 2D square + * grid with integer coordinates. + */ + typedef dpoint_<grid::hexa, int> dpoint2d_h; + + +} // end of namespace mln + + +# include <mln/make/dpoint2d_h.hh> +# include <mln/core/point2d_h.hh> + + +namespace mln +{ + + // FIXME: Doc! + const dpoint2d_h up_h = make::dpoint2d_h( -1, 0 ); + const dpoint2d_h down_h = make::dpoint2d_h( +1, 0 ); + const dpoint2d_h left_h = make::dpoint2d_h( 0, -1 ); + const dpoint2d_h right_h = make::dpoint2d_h( 0, +1 ); + +} // end of namespace mln + + +#endif // ! MLN_CORE_DPOINT2D_H_HH Index: trunk/milena/mln/core/box2d_h.hh =================================================================== --- trunk/milena/mln/core/box2d_h.hh (revision 0) +++ trunk/milena/mln/core/box2d_h.hh (revision 1269) @@ -0,0 +1,58 @@ +// 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_BOX2D_HH +# define MLN_CORE_BOX2D_HH + +/*! \file mln/core/box2d.hh + * + * \brief Definition of the mln::box2d alias and of construction + * routines. + */ + +# include <mln/core/box.hh> +# include <mln/core/point2d_h.hh> + + +namespace mln +{ + + /*! \brief Type alias for a box defined on the 2D square grid with + * integer coordinates. + * + * \see mln::win::rectangle2d. + */ + typedef box_<point2d_h> box2d_h; + + +} // end of namespace mln + + +# include <mln/make/box2d_h.hh> + + +#endif // ! MLN_CORE_BOX2D_HH Index: trunk/milena/mln/core/point2d_h.hh =================================================================== --- trunk/milena/mln/core/point2d_h.hh (revision 0) +++ trunk/milena/mln/core/point2d_h.hh (revision 1269) @@ -0,0 +1,56 @@ +// 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_POINT2D_H_HH +# define MLN_CORE_POINT2D_H_HH + +/*! \file mln/core/point2d_h.hh + * + * \brief Definition of the mln::point2d_h alias and of its construction + * routine. + */ + +# include <mln/core/point.hh> + + +namespace mln +{ + + /*! \brief Type alias for a point defined on the 2D square grid with + * integer coordinates. + */ + typedef point_<grid::hexa, int> point2d_h; + + +} // end of namespace mln + + +# include <mln/make/point2d_h.hh> +# include <mln/core/dpoint2d_h.hh> + + +#endif // ! MLN_CORE_POINT2D_H_HH Index: trunk/milena/mln/make/box2d_h.hh =================================================================== --- trunk/milena/mln/make/box2d_h.hh (revision 0) +++ trunk/milena/mln/make/box2d_h.hh (revision 1269) @@ -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. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef MLN_MAKE_BOX2D_H_HH +# define MLN_MAKE_BOX2D_H_HH + +/*! \file mln/make/box2d_h.hh + * + * \brief Routines to construct an mln::box2d_h. + */ + +# include <mln/core/box2d_h.hh> +# include <mln/make/point2d_h.hh> + + +namespace mln +{ + + namespace make + { + + /*! \brief Create an mln::box2d_h. + * + * \param[in] nrows Number of rows. + * \param[in] ncols Number of columns. + * + * \pre \p nrows != 0 and \p ncols != 0. + * + * \return A 2D_H box. + */ + mln::box2d_h box2d_h(unsigned nrows, unsigned ncols); + + + /*! \brief Create an mln::box2d_h. + * + * \overload + * + * \param[in] min_row Index of the top most row. + * \param[in] min_col Index of the left most column. + * \param[in] max_row Index of the botton most row. + * \param[in] max_col Index of the right most column. + * + * \pre \p max_row >= \p min_row and \p max_col >= \p min_col. + * + * \return A 2D_H box. + */ + mln::box2d_h box2d_h(int min_row, int min_col, + int max_row, int max_col); + + +# ifndef MLN_INCLUDE_ONLY + + mln::box2d_h box2d_h(unsigned nrows, unsigned ncols) + { + mln_precondition(nrows != 0 && ncols != 0); + mln::box2d_h tmp(make::point2d_h(0, 0), + make::point2d_h(nrows - 1, ncols - 1)); + return tmp; + } + + mln::box2d_h box2d_h(int min_row, int min_col, + int max_row, int max_col) + { + mln_precondition(max_row >= min_row && max_col >= min_col); + mln::box2d_h tmp(make::point2d_h(min_row, min_col), + make::point2d_h(max_row, max_col)); + return tmp; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::make + +} // end of namespace mln + + +#endif // ! MLN_MAKE_BOX2D_H_HH Index: trunk/milena/mln/make/point2d_h.hh =================================================================== --- trunk/milena/mln/make/point2d_h.hh (revision 0) +++ trunk/milena/mln/make/point2d_h.hh (revision 1269) @@ -0,0 +1,72 @@ +// 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_MAKE_POINT2D_H_HH +# define MLN_MAKE_POINT2D_H_HH + +/*! \file mln/make/point2d_h.hh + * + * \brief Routine to construct an mln::point2d_h. + */ + +# include <mln/core/point2d_h.hh> + + +namespace mln +{ + + namespace make + { + + /*! \brief Create an mln::point2d_h. + * + * \param[in] row Row coordinate. + * \param[in] col Column coordinate. + * + * \return A 2D point. + */ + mln::point2d_h point2d_h(int row, int col); + + +# ifndef MLN_INCLUDE_ONLY + + mln::point2d_h point2d_h(int row, int col) + { + mln::point2d_h tmp; + tmp[0] = row; + tmp[1] = col; + return tmp; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::make + +} // end of namespace mln + + +#endif // ! MLN_MAKE_POINT2D_H_HH Index: trunk/milena/mln/make/dpoint2d_h.hh =================================================================== --- trunk/milena/mln/make/dpoint2d_h.hh (revision 0) +++ trunk/milena/mln/make/dpoint2d_h.hh (revision 1269) @@ -0,0 +1,72 @@ +// 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_MAKE_DPOINT2D_H_HH +# define MLN_MAKE_DPOINT2D_H_HH + +/*! \file mln/make/dpoint2d_h.hh + * + * \brief Routine to construct an mln::dpoint2d_h. + */ + +# include <mln/core/dpoint2d_h.hh> + + +namespace mln +{ + + namespace make + { + + /*! \brief Create an mln::dpoint2d_h. + * + * \param[in] row Row coordinate. + * \param[in] col Column coordinate. + * + * \return A 2D dpoint. + */ + mln::dpoint2d_h dpoint2d_h(int row, int col); + + +# ifndef MLN_INCLUDE_ONLY + + mln::dpoint2d_h dpoint2d_h(int row, int col) + { + mln::dpoint2d_h tmp; + tmp[0] = row; + tmp[1] = col; + return tmp; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::make + +} // end of namespace mln + + +#endif // ! MLN_MAKE_DPOINT2D_H_HH