2430: Add (dynamic) iterators on n-faces.

* mln/core/internal/p_complex_piter_base.hh (mln::internal::p_complex_piter_base_<I, S, P, E>::iter_): Set to protected. * mln/core/site_set/p_n_faces_piter.hh): New file. Include it... * mln/core/site_set/p_complex.hh: ...here. * tests/core/image/complex_image.cc: Exercise iterators on n-faces. --- milena/ChangeLog | 13 ++ milena/mln/core/internal/p_complex_piter_base.hh | 2 - milena/mln/core/site_set/p_complex.hh | 1 + milena/mln/core/site_set/p_n_faces_piter.hh | 200 ++++++++++++++++++++++ milena/tests/core/image/complex_image.cc | 13 ++ 5 files changed, 227 insertions(+), 2 deletions(-) create mode 100644 milena/mln/core/site_set/p_n_faces_piter.hh diff --git a/milena/ChangeLog b/milena/ChangeLog index 8f404c2..36b4640 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,18 @@ 2008-09-29 Roland Levillain <roland@lrde.epita.fr> + Add (dynamic) iterators on n-faces. + + * mln/core/internal/p_complex_piter_base.hh + (mln::internal::p_complex_piter_base_<I, S, P, E>::iter_): + Set to protected. + * mln/core/site_set/p_n_faces_piter.hh): New file. + Include it... + * mln/core/site_set/p_complex.hh: ...here. + * tests/core/image/complex_image.cc: Exercise iterators on + n-faces. + +2008-09-29 Roland Levillain <roland@lrde.epita.fr> + Help the compiler not to mix up classes and methods. * mln/topo/face.hh (mln::topo::face<D>::face_data): diff --git a/milena/mln/core/internal/p_complex_piter_base.hh b/milena/mln/core/internal/p_complex_piter_base.hh index 41cc29d..d906011 100644 --- a/milena/mln/core/internal/p_complex_piter_base.hh +++ b/milena/mln/core/internal/p_complex_piter_base.hh @@ -96,8 +96,6 @@ namespace mln protected: /// The psite corresponding to this iterator. using super_::p_; - - private: /// The underlying complex iterator. iter iter_; }; diff --git a/milena/mln/core/site_set/p_complex.hh b/milena/mln/core/site_set/p_complex.hh index 06fc8b2..3ef413a 100644 --- a/milena/mln/core/site_set/p_complex.hh +++ b/milena/mln/core/site_set/p_complex.hh @@ -37,6 +37,7 @@ # include <mln/core/site_set/complex_psite.hh> # include <mln/core/site_set/p_complex_piter.hh> +# include <mln/core/site_set/p_n_faces_piter.hh> // FIXME: Disabled (moved to the attic). # if 0 # include <mln/core/site_set/p_complex_faces_piter.hh> diff --git a/milena/mln/core/site_set/p_n_faces_piter.hh b/milena/mln/core/site_set/p_n_faces_piter.hh new file mode 100644 index 0000000..bcf2149 --- /dev/null +++ b/milena/mln/core/site_set/p_n_faces_piter.hh @@ -0,0 +1,200 @@ +// 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_CORE_SITE_SET_P_N_FACES_PITER_HH +# define MLN_CORE_SITE_SET_P_N_FACES_PITER_HH + +/// \file mln/core/site_set/p_n_faces_piter.hh +/// \brief Definition of point iterator on the n-faces of a +/// complex-based pset. + +# include <mln/core/site_set/p_complex.hh> +# include <mln/core/internal/p_complex_piter_base.hh> +# include <mln/topo/n_face_iter.hh> + +/* FIXME: Maybe we could factor these iterators again, by introducing + an implementation class having methods n() and set_n(). */ + + +namespace mln +{ + + /*----------------------------. + | p_n_faces_fwd_piter<D, P>. | + `----------------------------*/ + + /// \brief Forward iterator on the n-faces sites of an + /// mln::p_complex<D, P>. + template <unsigned D, typename P> + class p_n_faces_fwd_piter + : public internal::p_complex_piter_base_< topo::n_face_fwd_iter<D>, + p_complex<D, P>, + P, + p_n_faces_fwd_piter<D, P> > + { + typedef p_n_faces_fwd_piter<D, P> self_; + typedef internal::p_complex_piter_base_< topo::n_face_fwd_iter<D>, + p_complex<D, P>, + P, + self_ > super_; + + public: + /// Construction and assignment. + /// \{ + p_n_faces_fwd_piter(); + p_n_faces_fwd_piter(const p_complex<D, P>& pc, unsigned n); + /// \} + + /// \brief Accessors. + /// + /// Shortcuts to face_'s accessors. + /// \{ + unsigned n() const; + void set_n (unsigned n); + /// \} + }; + + + /*----------------------------. + | p_n_faces_bkd_piter<D, P>. | + `----------------------------*/ + + /// \brief Backward iterator on the n-faces sites of an + /// mln::p_complex<D, P>. + template <unsigned D, typename P> + class p_n_faces_bkd_piter + /* FIXME: Rename internal::p_complex_piter_base_ to something else, + as it is also used for p_faces piters! */ + : public internal::p_complex_piter_base_< topo::n_face_bkd_iter<D>, + p_complex<D, P>, + P, + p_n_faces_bkd_piter<D, P> > + { + typedef p_n_faces_bkd_piter<D, P> self_; + typedef internal::p_complex_piter_base_< topo::n_face_bkd_iter<D>, + p_complex<D, P>, + P, + self_ > super_; + + public: + /// Construction and assignment. + /// \{ + p_n_faces_bkd_piter(); + p_n_faces_bkd_piter(const p_complex<D, P>& pc, unsigned n); + /// \} + + /// \brief Accessors. + /// + /// Shortcuts to face_'s accessors. + /// \{ + unsigned n() const; + void set_n (unsigned n); + /// \} + }; + + + +# ifndef MLN_INCLUDE_ONLY + + /*----------------------------. + | p_n_faces_fwd_piter<D, P>. | + `----------------------------*/ + + template <unsigned D, typename P> + inline + p_n_faces_fwd_piter<D, P>::p_n_faces_fwd_piter() + { + } + + template <unsigned D, typename P> + inline + p_n_faces_fwd_piter<D, P>::p_n_faces_fwd_piter(const p_complex<D, P>& pc, + unsigned n) + : super_(pc) + { + mln_precondition(n <= D); + set_n(n); + } + + template <unsigned D, typename P> + inline + unsigned + p_n_faces_fwd_piter<D, P>::n() const + { + return this->iter_.n(); + } + + template <unsigned D, typename P> + inline + void + p_n_faces_fwd_piter<D, P>::set_n (unsigned n) + { + this->iter_.set_n(n); + } + + + /*----------------------------. + | p_n_faces_bkd_piter<D, P>. | + `----------------------------*/ + + template <unsigned D, typename P> + inline + p_n_faces_bkd_piter<D, P>::p_n_faces_bkd_piter() + { + } + + template <unsigned D, typename P> + inline + p_n_faces_bkd_piter<D, P>::p_n_faces_bkd_piter(const p_complex<D, P>& pc, + unsigned n) + : super_(pc) + { + mln_precondition(n <= D); + set_n(n); + } + + template <unsigned D, typename P> + inline + unsigned + p_n_faces_bkd_piter<D, P>::n() const + { + return this->iter_.n(); + } + + template <unsigned D, typename P> + inline + void + p_n_faces_bkd_piter<D, P>::set_n (unsigned n) + { + this->iter_.set_n(n); + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of mln + +#endif // ! MLN_CORE_SITE_SET_P_N_FACES_PITER_HH diff --git a/milena/tests/core/image/complex_image.cc b/milena/tests/core/image/complex_image.cc index 47233cb..59eba87 100644 --- a/milena/tests/core/image/complex_image.cc +++ b/milena/tests/core/image/complex_image.cc @@ -164,6 +164,19 @@ int main() // Iterators on n-faces (with n fixed in [0, D]). // // ----------------------------------------------- // + // Dynamic version. + for (unsigned n = 0; n <= D; ++n) + { + p_n_faces_fwd_piter<D, point2d> fwd_np(ima.domain(), n); + p_n_faces_bkd_piter<D, point2d> bkd_np(ima.domain(), n); + for_all_2(fwd_np, bkd_np) + std::cout << "ima(" << fwd_np << ") = " << ima(fwd_np) << '\t' + << "ima(" << bkd_np << ") = " << ima(bkd_np) + << std::endl; + std::cout << std::endl; + } + + // Static version. // FIXME: Disabled (moved to the attic). # if 0 // FIXME: Sugar the name of the iterator. -- 1.5.6.5
participants (1)
-
Roland Levillain