URL: https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
ChangeLog:
2008-09-15 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Move and update line_piter as box_runstart_piter.
* mln/core/line_piter.hh: Rename as...
* mln/core/box_runstart_piter.hh: ...this.
* tests/core/other/line_piter.cc: Rename as...
* tests/core/other/box_runstart_piter.cc: ...this.
---
mln/core/box_runstart_piter.hh | 165 +++++++++++++++++++++++++++++++++
tests/core/other/box_runstart_piter.cc | 89 +++++++++++++++++
2 files changed, 254 insertions(+)
Index: branches/cleanup-2008/milena/tests/core/other/line_piter.cc (deleted)
===================================================================
Index: branches/cleanup-2008/milena/tests/core/other/box_runstart_piter.cc
===================================================================
--- branches/cleanup-2008/milena/tests/core/other/box_runstart_piter.cc (revision 0)
+++ branches/cleanup-2008/milena/tests/core/other/box_runstart_piter.cc (revision 2271)
@@ -0,0 +1,89 @@
+// 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/other/box_runstart_piter.cc
+ *
+ * \brief Tests on mln::box_runstart_piter.
+ */
+#include <mln/core/alias/box1d.hh>
+#include <mln/core/alias/box2d.hh>
+#include <mln/core/alias/box3d.hh>
+#include <mln/core/box_runstart_piter.hh>
+
+int main()
+{
+ using namespace mln;
+
+ const unsigned border = 2;
+
+ /// Test with box1d
+ {
+ box1d b1(make::point1d(40), make::point1d(42));
+ box_runstart_piter<point1d> p1(b1);
+ for_all(p1)
+ {
+ mln_assertion(p1[0] == 40);
+ std::cout << p1 <<std::endl;
+ }
+ std::cout << "run_len : " << p1.run_length()<<std::endl;
+ mln_assertion(p1.run_length() == 3);
+ }
+
+
+ /// Test with box2d
+ {
+ box2d b2(make::point2d(1,2), make::point2d(5,8));
+ box_runstart_piter<point2d> p2(b2);
+ int i = 1;
+ for_all(p2)
+ {
+ mln_assertion(p2[1] == 2 && p2[0] == i++);
+ std::cout << p2 <<std::endl;
+ }
+ std::cout << "run_len : " << p2.run_length()<<std::endl;
+ mln_assertion(p2.run_length() == 7);
+ }
+
+// Test with image 3d
+ {
+ box3d b3(make::point3d(1,2,3), make::point3d(5,8,7));
+ box_runstart_piter<point3d> p3(b3);
+ int i = 1;
+ int j = 2;
+ for_all(p3)
+ {
+ std::cout << p3 << std::endl;
+ if (i++ == 5)
+ i = 1;
+ if (j++ == 8)
+ j = 2;
+ }
+ std::cout << "run_len : " << p3.run_length() << std::endl;
+ mln_assertion(p3.run_length() == 5);
+ }
+
+}
Index: branches/cleanup-2008/milena/mln/core/line_piter.hh (deleted)
===================================================================
Index: branches/cleanup-2008/milena/mln/core/box_runstart_piter.hh
===================================================================
--- branches/cleanup-2008/milena/mln/core/box_runstart_piter.hh (revision 0)
+++ branches/cleanup-2008/milena/mln/core/box_runstart_piter.hh (revision 2271)
@@ -0,0 +1,165 @@
+// 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_BOX_RUNSTART_PITER_HH
+# define MLN_CORE_BOX_RUNSTART_PITER_HH
+
+/*! \file mln/core/box_runstart_piter.hh
+ *
+ * \brief Definition of iterators on points by lines.
+ *
+ */
+
+# include <mln/core/internal/site_iterator_base.hh>
+# include <mln/core/site_set/box.hh>
+
+namespace mln
+{
+
+ /*! \brief A generic forward iterator on points by lines.
+ *
+ * The parameter \c P is the type of points.
+ */
+ template <typename P>
+ class box_runstart_piter :
+ public internal::site_set_iterator_base< box<P>,
+ box_runstart_piter<P> >
+ {
+ typedef box_runstart_piter<P> self_;
+ typedef internal::site_set_iterator_base< box<P>, self_ > super_;
+ public:
+
+ // Make definitions from super class available.
+ enum { dim = super_::dim };
+
+ /*! \brief Constructor.
+ *
+ * \param[in] b A box.
+ */
+ box_runstart_piter(const box<P>& b);
+
+ box_runstart_piter();
+
+ /// Test the iterator validity.
+ bool is_valid_() const;
+
+ /// Invalidate the iterator.
+ void invalidate_();
+
+ /// Start an iteration.
+ void start_();
+
+ /// Go to the next point.
+ void next_();
+
+ /// Give the lenght of the run
+ unsigned run_length() const;
+
+ private:
+ using super_::p_;
+ using super_::s_;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // box_runstart_piter<P>
+
+ template <typename P>
+ inline
+ box_runstart_piter<P>::box_runstart_piter()
+ {
+ }
+
+ template <typename P>
+ inline
+ box_runstart_piter<P>::box_runstart_piter(const box<P>& b)
+ {
+ this->change_target(b);
+ }
+
+ template <typename P>
+ inline
+ bool
+ box_runstart_piter<P>::is_valid_() const
+ {
+ return p_[0] != s_->pmax()[0] + 1;
+ }
+
+ template <typename P>
+ inline
+ void
+ box_runstart_piter<P>::invalidate_()
+ {
+ p_[0] = s_->pmax()[0] + 1;
+ }
+
+ template <typename P>
+ inline
+ void
+ box_runstart_piter<P>::start_()
+ {
+ p_ = s_->pmin();
+ }
+
+ template <typename P>
+ inline
+ void
+ box_runstart_piter<P>::next_()
+ {
+ // Do we want this run for image in 3d?
+ for (int c = dim - 2; c >= 0; --c)
+ {
+ if (p_[c] != s_->pmax()[c])
+ {
+ ++p_[c];
+ break;
+ }
+ else
+ p_[c] = s_->pmin()[c];
+ }
+
+ if (p_ == s_->pmin())
+ invalidate_();
+ }
+
+ template <typename P>
+ inline
+ unsigned
+ box_runstart_piter<P>::run_length() const
+ {
+ return s_->len(dim - 1);
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_BOX_RUNSTART_PITER_HH