URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-11-09 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add clockwise neighborhood iterator.
* mln/core/clock_neighb.hh: New way to iterate on neighborhood.
* mln/core/clock_neighb2d.hh: New clock_neighb for 2d.
* tests/clock_neighb2d.cc: New test for that.
---
mln/core/clock_neighb.hh | 128 ++++++++++++++++++++++++++++
mln/core/clock_neighb2d.hh | 201 +++++++++++++++++++++++++++++++++++++++++++++
tests/clock_neighb2d.cc | 69 +++++++++++++++
3 files changed, 398 insertions(+)
Index: trunk/milena/tests/clock_neighb2d.cc
===================================================================
--- trunk/milena/tests/clock_neighb2d.cc (revision 0)
+++ trunk/milena/tests/clock_neighb2d.cc (revision 1457)
@@ -0,0 +1,69 @@
+// 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.
+
+#include <mln/core/image2d.hh>
+#include <mln/core/clock_neighb2d.hh>
+#include <mln/debug/println.hh>
+
+namespace mln
+{
+ template <typename I, typename N>
+ void test(Image<I>& input_,
+ const Neighborhood<N>& nbh)
+ {
+ I& input = exact (input_);
+ point2d p (1,1);
+ int v = 1;
+
+ mln_fwd_niter(N) n (nbh, p);
+
+ for_all (n)
+ {
+ input(n) = v++;
+ }
+
+ }
+
+}
+
+
+int main ()
+{
+ using namespace mln;
+
+
+ image2d<int> ima(3,3);
+ dpoint2d dp (1,0);
+
+ test(ima, cc8(dp));
+ debug::println(ima);
+
+ dpoint2d dp2 (-1,-1);
+
+ test(ima, cc8(dp2));
+ debug::println(ima);
+}
Index: trunk/milena/mln/core/clock_neighb.hh
===================================================================
--- trunk/milena/mln/core/clock_neighb.hh (revision 0)
+++ trunk/milena/mln/core/clock_neighb.hh (revision 1457)
@@ -0,0 +1,128 @@
+// 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_CLOCK_NEIGHB_HH
+# define MLN_CORE_CLOCK_NEIGHB_HH
+
+/*! \file mln/core/clock_neighb.hh
+ *
+ * \brief Definition of the generic neighborhood class mln::clock_neighb_.
+ */
+
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/internal/dpoints_base.hh>
+# include <mln/core/dpoint.hh>
+# include <mln/core/vec_p.hh>
+
+namespace mln
+{
+
+ // fwd decls
+ template <typename D> class dpoints_fwd_piter;
+ template <typename D> class dpoints_bkd_piter;
+
+
+ /*! \brief Generic neighborhood class.
+ *
+ * This neighborhood of window is just like a set of delta-points.
+ * The parameter is \c D, type of delta-point.
+ */
+ template <typename D>
+ struct clock_neighb_ : public Neighborhood< clock_neighb_ <D> >
+ {
+ /// Dpoint associated type.
+ typedef D dpoint;
+
+ /// Point associated type.
+ typedef mln_point(D) point;
+
+ /*! \brief Point_Iterator type to browse the points of a generic
+ * neighborhood w.r.t. the ordering of delta-points.
+ */
+ typedef dpoints_fwd_piter<D> fwd_niter;
+
+ /*! \brief Point_Iterator type to browse the points of a generic
+ * neighborhood w.r.t. the reverse ordering of delta-points.
+ */
+ typedef dpoints_bkd_piter<D> bkd_niter;
+
+ /*! \brief Same as fwd_niter.
+ */
+ typedef fwd_niter niter;
+
+ /*! \brief Constructor without argument.
+ *
+ * The constructed neighborhood is empty. You have to use insert()
+ * to proceed to the neighborhood definition.
+ */
+ clock_neighb_();
+
+ /*! \brief Insert a delta-point \p dp in the neighborhood
+ * definition.
+ *
+ * \param[in] dp The delta-point to insert.
+ *
+ * This method also insert the symmetrical delta-point, - \p dp,
+ * in the neighborhood definition; thus the client has not to
+ * ensure the symmetry property; that is automatic.
+ */
+ clock_neighb_<D>& append(const D& dp);
+ /// \}
+ const std::vector<D>& vect() const
+ {
+ return vec_;
+ }
+
+ std::vector<D> vec_;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename D>
+ clock_neighb_<D>::clock_neighb_()
+ {
+ }
+
+ template <typename D>
+ clock_neighb_<D>&
+ clock_neighb_<D>::append(const D& dp)
+ {
+ vec_.push_back(dp);
+ return *this;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+# include <mln/core/dpoints_piter.hh>
+
+
+#endif // ! MLN_CORE_CLOCK_NEIGHB_HH
Index: trunk/milena/mln/core/clock_neighb2d.hh
===================================================================
--- trunk/milena/mln/core/clock_neighb2d.hh (revision 0)
+++ trunk/milena/mln/core/clock_neighb2d.hh (revision 1457)
@@ -0,0 +1,201 @@
+// 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_CLOCK_NEIGHB2D_HH
+# define MLN_CORE_CLOCK_NEIGHB2D_HH
+
+/*! \file mln/core/clock_neighb2d.hh
+ *
+ * \brief Definition of the mln::clock_neighb2d alias and of some classical
+ * 2D clock_neighborhoods.
+ */
+
+# include <cmath>
+# include <mln/core/clock_neighb.hh>
+# include <mln/core/dpoint2d.hh>
+
+
+namespace mln
+{
+
+ /*! \brief Type alias for a clock_neighborhood defined on the 2D square
+ * grid with integer coordinates.
+ */
+ typedef clock_neighb_<dpoint2d> clock_neighb2d;
+
+
+ /*! \brief 4-connectivity clock_neighborhood on the 2D grid.
+ *
+ * - o -
+ * o x o
+ * - o -
+ *
+ * \return A clock_neighb2d.
+ */
+ const clock_neighb2d cc4(dpoint2d& dp);
+
+
+ /*! \brief 8-connectivity clock_neighborhood on the 2D grid.
+ *
+ * o o o
+ * o x o
+ * o o o
+ *
+ * \return A clock_neighb2d.
+ */
+ const clock_neighb2d cc8(dpoint2d& dp);
+
+
+// /*! \brief Horizontal 2-connectivity clock_neighborhood on the 2D grid.
+// *
+// * - - -
+// * o x o
+// * - - -
+// *
+// * \return A clock_neighb2d.
+// */
+// const clock_neighb2d& c2_row();
+
+
+// /*! \brief Vertical 2-connectivity clock_neighborhood on the 2D grid.
+// *
+// * - o -
+// * - x -
+// * - o -
+// *
+// * \return A clock_neighb2d.
+// */
+// const clock_neighb2d& c2_col();
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ const clock_neighb2d cc4(dpoint2d& dp)
+ {
+ static bool flower = true;
+ static clock_neighb2d it;
+ if (flower)
+ {
+ unsigned begin = 0;
+ std::vector<dpoint2d> v;
+ v.push_back(make::dpoint2d(0, 1));
+ v.push_back(make::dpoint2d(-1, 0));
+ v.push_back(make::dpoint2d(0, -1));
+ v.push_back(make::dpoint2d(1, 0));
+
+ std::vector<dpoint2d>::const_iterator ite = v.begin ();
+ for (; (ite != v.end ()) && (dp != *ite); ++ite, ++begin)
+ ;
+ mln_assertion (*ite != v.end ());
+ for (int i = begin; i < v.size(); ++i)
+ it.append(v[i]);
+ for (int i = 0; i < begin; ++i)
+ it.append(v[i]);
+
+ flower = false;
+ }
+ return it;
+ }
+
+
+ const clock_neighb2d cc8(dpoint2d& dp)
+ {
+// static bool flower = true;
+ clock_neighb2d it;
+// if (flower)
+// {
+ unsigned begin = 0;
+ std::vector<dpoint2d> v;
+ v.push_back(make::dpoint2d(0, 1));
+ v.push_back(make::dpoint2d(-1, 1));
+ v.push_back(make::dpoint2d(-1, 0));
+ v.push_back(make::dpoint2d(-1, -1));
+ v.push_back(make::dpoint2d(0, -1));
+ v.push_back(make::dpoint2d(1, -1));
+ v.push_back(make::dpoint2d(1, 0));
+ v.push_back(make::dpoint2d(1, 1));
+
+ std::vector<dpoint2d>::const_iterator ite = v.begin ();
+ for (; (ite != v.end ()) && (dp != *ite); ++ite, ++begin)
+ ;
+ // mln_assertion (*ite != v.end ());
+ for (int i = begin; i < v.size(); ++i)
+ it.append(v[i]);
+ for (int i = 0; i < begin; ++i)
+ it.append(v[i]);
+
+// flower = false;
+// }
+ return it;
+ }
+
+// const clock_neighb2d& c8()
+// {
+// static bool flower = true;
+// static clock_neighb2d it;
+// if (flower)
+// {
+// it.insert(make::dpoint2d(0, 1));
+// it.insert(make::dpoint2d(1,-1));
+// it.insert(make::dpoint2d(1, 0));
+// it.insert(make::dpoint2d(1, 1));
+// flower = false;
+// }
+// return it;
+// }
+
+// const clock_neighb2d& c2_row()
+// {
+// static bool flower = true;
+// static clock_neighb2d it;
+// if (flower)
+// {
+// it.insert(make::dpoint2d(0, 1));
+// flower = false;
+// }
+// return it;
+// }
+
+// const clock_neighb2d& c2_col()
+// {
+// static bool flower = true;
+// static clock_neighb2d it;
+// if (flower)
+// {
+// it.insert(make::dpoint2d(1, 0));
+// flower = false;
+// }
+// return it;
+// }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_CLOCK_NEIGHB2D_HH