* mln/core/box_runend_piter.hh: New iterator.
* tests/core/other/Makefile.am, * tests/core/other/box_runend_piter.cc: New test.
--- milena/ChangeLog | 9 ++ milena/mln/core/box_runend_piter.hh | 178 +++++++++++++++++++++++++++ milena/tests/core/other/Makefile.am | 2 + milena/tests/core/other/box_runend_piter.cc | 41 ++++++ 4 files changed, 230 insertions(+), 0 deletions(-) create mode 100644 milena/mln/core/box_runend_piter.hh create mode 100644 milena/tests/core/other/box_runend_piter.cc
diff --git a/milena/ChangeLog b/milena/ChangeLog index cdfda50..f835a42 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,12 @@ +2009-11-09 Guillaume Lazzara z@lrde.epita.fr + + Add box_runend_piter. + + * mln/core/box_runend_piter.hh: New iterator. + + * tests/core/other/Makefile.am, + * tests/core/other/box_runend_piter.cc: New test. + 2009-11-03 Guillaume Lazzara z@lrde.epita.fr
* mln/value/label_32.hh: New. diff --git a/milena/mln/core/box_runend_piter.hh b/milena/mln/core/box_runend_piter.hh new file mode 100644 index 0000000..a0b1d32 --- /dev/null +++ b/milena/mln/core/box_runend_piter.hh @@ -0,0 +1,178 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see http://www.gnu.org/licenses/. +// +// As a special exception, you may use this file as part of a free +// software project 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_RUNEND_PITER_HH +# define MLN_CORE_BOX_RUNEND_PITER_HH + +/// \file +/// +/// Definition of iterators on points by lines. + +# include <mln/core/internal/site_iterator_base.hh> +# include <mln/core/site_set/box.hh> + + +#define mln_box_runend_piter(I) typename mln::box_runend_piter<mln_psite(I)> +#define mln_box_runend_piter_(I) mln::box_runend_piter<mln_psite(I)> + + +namespace mln +{ + + /*! \brief A generic backward iterator on points by lines. + * + * The parameter \c P is the type of points. + */ + template <typename P> + class box_runend_piter : + public internal::site_set_iterator_base< box<P>, + box_runend_piter<P> > + { + typedef box_runend_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_runend_piter(const box<P>& b); + + /// Delayed initialization. + void init_(const box<P>& b); + + box_runend_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_runend_piter<P> + + template <typename P> + inline + box_runend_piter<P>::box_runend_piter() + { + } + + template <typename P> + inline + box_runend_piter<P>::box_runend_piter(const box<P>& b) + { + init_(b); + } + + template <typename P> + inline + void + box_runend_piter<P>::init_(const box<P>& b) + { + this->change_target(b); + } + + + template <typename P> + inline + bool + box_runend_piter<P>::is_valid_() const + { + return p_[0] != static_cast<mln_coord(P)>(s_->pmin()[0] - 1); + } + + template <typename P> + inline + void + box_runend_piter<P>::invalidate_() + { + p_[0] = static_cast<mln_coord(P)>(s_->pmin()[0] - 1); + } + + template <typename P> + inline + void + box_runend_piter<P>::start_() + { + p_ = s_->pmax(); + } + + template <typename P> + inline + void + box_runend_piter<P>::next_() + { + // Do we want this run for image in 3d? + for (int c = dim - 2; c >= 0; --c) + { + if (p_[c] != s_->pmin()[c]) + { + --p_[c]; + break; + } + else + p_[c] = s_->pmax()[c]; + } + + if (p_ == s_->pmax()) + invalidate_(); + } + + template <typename P> + inline + unsigned + box_runend_piter<P>::run_length() const + { + return s_->len(dim - 1); + } + + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_CORE_BOX_RUNEND_PITER_HH diff --git a/milena/tests/core/other/Makefile.am b/milena/tests/core/other/Makefile.am index b86e4e3..9443837 100644 --- a/milena/tests/core/other/Makefile.am +++ b/milena/tests/core/other/Makefile.am @@ -21,6 +21,7 @@ include $(top_srcdir)/milena/tests/tests.mk
check_PROGRAMS = \ box_runstart_piter \ + box_runend_piter \ category \ dpoints_pixter \ graph_elt_neighborhood \ @@ -40,6 +41,7 @@ check_PROGRAMS = \ w_window
box_runstart_piter_SOURCES = box_runstart_piter.cc +box_runend_piter_SOURCES = box_runend_piter.cc category_SOURCES = category.cc dpoints_pixter_SOURCES = dpoints_pixter.cc graph_elt_neighborhood_SOURCES = graph_elt_neighborhood.cc diff --git a/milena/tests/core/other/box_runend_piter.cc b/milena/tests/core/other/box_runend_piter.cc new file mode 100644 index 0000000..fe7cb43 --- /dev/null +++ b/milena/tests/core/other/box_runend_piter.cc @@ -0,0 +1,41 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see http://www.gnu.org/licenses/. +// +// As a special exception, you may use this file as part of a free +// software project 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/alias/box2d.hh> +#include <mln/core/box_runend_piter.hh> + + +int main() +{ + using namespace mln; + + box2d b(3,3); + box_runend_piter<point2d> p(b); + unsigned i = 2; + for_all(p) + mln_assertion(p == point2d(i, 2)); + + mln_assertion(p.run_length() == 3); +}