2511: Add a complex relative iterator iterating on its center only.

* mln/topo/center_only_iter.hh: New. * tests/topo/complex.cc: Exercise this iterator. --- milena/ChangeLog | 7 ++ milena/mln/topo/center_only_iter.hh | 134 +++++++++++++++++++++++++++++++++++ milena/tests/topo/complex.cc | 14 ++++ 3 files changed, 155 insertions(+), 0 deletions(-) create mode 100644 milena/mln/topo/center_only_iter.hh diff --git a/milena/ChangeLog b/milena/ChangeLog index 5097f23..5375a7d 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,12 @@ 2008-10-04 Roland Levillain <roland@lrde.epita.fr> + Add a complex relative iterator iterating on its center only. + + * mln/topo/center_only_iter.hh: New. + * tests/topo/complex.cc: Exercise this iterator. + +2008-10-04 Roland Levillain <roland@lrde.epita.fr> + Fix initialization and access to values in mln::complex_image. * mln/core/image/complex_image.hh diff --git a/milena/mln/topo/center_only_iter.hh b/milena/mln/topo/center_only_iter.hh new file mode 100644 index 0000000..d55ffca --- /dev/null +++ b/milena/mln/topo/center_only_iter.hh @@ -0,0 +1,134 @@ +// Copyright (C) 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. +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef MLN_TOPO_CENTER_ONLY_ITER_HH +# define MLN_TOPO_CENTER_ONLY_ITER_HH + +/// \file mln/topo/center_only_iter.hh +/// +/// \brief Definition of a complex relative iterator iterating on its +/// center (reference face) only. +/// +/// \see mln/topo/centered_iter_adapter.hh + +# include <mln/topo/internal/complex_relative_iterator_base.hh> +# include <mln/topo/face.hh> + + +namespace mln +{ + + namespace topo + { + + // Forward declaration. + template <unsigned D> class face; + + + /*----------------------------. + | topo::center_only_iter<D>. | + `----------------------------*/ + + /** \brief Iterator on all the adjacent (n-1)-faces of the n-face + of an mln::complex<D>. + + \arg \p D The dimension of the complex this iterator belongs to. + + mln::topo::center_only_iter inherits from + mln::topo::internal::forward_complex_relative_iterator_base, + but it could inherit from + mln::topo::internal::backward_complex_relative_iterator_base + as well, since it always contains a single element, the + center/reference face (and the traversal order is + meaningless). + + This iterator is essentially used to implement other iterators. + \see mln::topo::centered_iter_adapter + \see mln::complex_lower_window + \see mln::complex_higher_window + \see mln::complex_lower_higher_window */ + template <unsigned D> + class center_only_iter + : public internal::forward_complex_relative_iterator_base< face<D>, + center_only_iter<D> > + { + private: + typedef center_only_iter<D> self_; + typedef internal::forward_complex_relative_iterator_base< face<D>, + self_ > super_; + + public: + /// Construction. + /// \{ + center_only_iter(); + template <typename Fref> + center_only_iter(const Fref& f_ref); + /// \} + + /// Compute the set of faces adjacent to the reference face. + void update_adj_faces_(); + }; + + + +# ifndef MLN_INCLUDE_ONLY + + /*----------------------------. + | topo::center_only_iter<D>. | + `----------------------------*/ + + template <unsigned D> + inline + center_only_iter<D>::center_only_iter() + { + } + + template <unsigned D> + template <typename Fref> + inline + center_only_iter<D>::center_only_iter(const Fref& f_ref) + : super_(f_ref) + { + } + + template <unsigned D> + inline + void + center_only_iter<D>::update_adj_faces_() + { + mln_precondition(this->c_); + this->adj_faces_.clear(); + this->adj_faces_.push_back(*this->c_); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::topo + +} // end of namespace mln + +#endif // ! MLN_TOPO_CENTER_ONLY_ITER_HH diff --git a/milena/tests/topo/complex.cc b/milena/tests/topo/complex.cc index 9e559de..92d0398 100644 --- a/milena/tests/topo/complex.cc +++ b/milena/tests/topo/complex.cc @@ -33,6 +33,7 @@ #include <iostream> #include <mln/topo/complex.hh> +#include <mln/topo/center_only_iter.hh> using namespace mln; @@ -324,6 +325,19 @@ int main() face<D>'s. ----------------------------------------------------------------- */ + + /*------------------. + | Other iterators. | + `------------------*/ + + // For each face, iterate on itself. (This iterator is not + // interesting as-is, but is useful when combined with others, + // e.g. in topo::centered_iter_adapter). + topo::center_only_iter<D> center(fwd_f); + for_all(fwd_f) + for_all(center) + std::cout << " " << center << std::endl; + std::cout << std::endl; } -- 1.6.0.1
participants (1)
-
Roland Levillain