639: Add backward iterators on neighborhoods and windows.

https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Roland Levillain <roland@lrde.epita.fr> Add backward iterators on neighborhoods and windows. * oln/core/gen/bkd_niter_neighb.hh, * oln/core/gen/bkd_qiter_win.hh: New. * oln/core/gen/fwd_niter_neighb.hh (oln::fwd_niter_neighb_<point_t>::fwd_niter_neighb_) (oln::fwd_niter_neighb_<point_t>::impl_next) * oln/core/gen/fwd_qiter_win.hh (oln::fwd_qiter_win_<point_t>::fwd_qiter_win_) (oln::fwd_qiter_win_<point_t>::impl_next): Initialize i_ using this->invalidate(). * oln/core/1d/aliases.hh (oln::bkd_qiter_win_): New forward declaration. (oln::bkd_qiter1d): New typedef. * oln/core/2d/aliases.hh (oln::bkd_qiter_win_): New forward declaration. (oln::bkd_qiter2d): New typedef. * oln/core/3d/aliases.hh (oln::bkd_qiter_win_): New forward declaration. (oln::bkd_qiter3d): New typedef. * oln/core/iterator_vtypes.hh (oln::single_vtype<image1d<T>, typedef_::bkd_qiter_type>) (oln::single_vtype<image2d<T>, typedef_::bkd_qiter_type>) (oln::single_vtype<image3d<T>, typedef_::bkd_qiter_type>): New vtypes. * oln/basics1d.hh (oln/core/gen/window.hh) (oln/core/gen/fwd_qiter_win.hh, oln/core/gen/bkd_qiter_win.hh): * oln/basics2d.hh (oln/core/gen/bkd_qiter_win.hh) * oln/basics3d.hh (oln/core/gen/window.hh) (oln/core/gen/fwd_qiter_win.hh, oln/core/gen/bkd_qiter_win.hh): Include them. * oln/Makefile.am (nobase_oln_HEADERS): Add core/gen/bkd_niter_neighb.hh and core/gen/bkd_qiter_win.hh. Makefile.am | 2 basics1d.hh | 4 basics2d.hh | 1 basics3d.hh | 4 core/1d/aliases.hh | 6 - core/2d/aliases.hh | 6 - core/3d/aliases.hh | 6 - core/gen/bkd_niter_neighb.hh | 200 +++++++++++++++++++++++++++++++++++++++++++ core/gen/bkd_qiter_win.hh | 181 ++++++++++++++++++++++++++++++++++++++ core/gen/fwd_niter_neighb.hh | 12 +- core/gen/fwd_qiter_win.hh | 6 - core/iterator_vtypes.hh | 42 +++------ 12 files changed, 426 insertions(+), 44 deletions(-) Index: oln/basics1d.hh --- oln/basics1d.hh (revision 638) +++ oln/basics1d.hh (working copy) @@ -44,6 +44,10 @@ # include <oln/core/gen/fwd_piter_bbox.hh> # include <oln/core/gen/bkd_piter_bbox.hh> +# include <oln/core/gen/window.hh> +# include <oln/core/gen/fwd_qiter_win.hh> +# include <oln/core/gen/bkd_qiter_win.hh> + # include <oln/core/gen/neighb.hh> # include <oln/core/1d/neighb1d.hh> Index: oln/core/iterator_vtypes.hh --- oln/core/iterator_vtypes.hh (revision 638) +++ oln/core/iterator_vtypes.hh (working copy) @@ -66,14 +66,12 @@ typedef fwd_qiter1d ret; }; - // FIXME : Not yet available. - -// /// bkd_qiter vtype of image1d. -// template <typename T> -// struct single_vtype< image1d<T>, typedef_::bkd_qiter_type > -// { -// typedef bkd_qiter1d ret; -// }; + /// bkd_qiter vtype of image1d. + template <typename T> + struct single_vtype< image1d<T>, typedef_::bkd_qiter_type > + { + typedef bkd_qiter1d ret; + }; /*------------------. @@ -104,14 +102,12 @@ typedef fwd_qiter2d ret; }; - // FIXME : Not yet available. - -// /// bkd_qiter vtype of image2d. -// template <typename T> -// struct single_vtype< image2d<T>, typedef_::bkd_qiter_type > -// { -// typedef bkd_qiter2d ret; -// }; + /// bkd_qiter vtype of image2d. + template <typename T> + struct single_vtype< image2d<T>, typedef_::bkd_qiter_type > + { + typedef bkd_qiter2d ret; + }; /*------------------. @@ -142,14 +138,12 @@ typedef fwd_qiter3d ret; }; - // FIXME : Not yet available. - -// /// bkd_qiter vtype of image3d. -// template <typename T> -// struct single_vtype< image3d<T>, typedef_::bkd_qiter_type > -// { -// typedef bkd_qiter3d ret; -// }; + /// bkd_qiter vtype of image3d. + template <typename T> + struct single_vtype< image3d<T>, typedef_::bkd_qiter_type > + { + typedef bkd_qiter3d ret; + }; /*--------------------------------------------. Index: oln/core/1d/aliases.hh --- oln/core/1d/aliases.hh (revision 638) +++ oln/core/1d/aliases.hh (working copy) @@ -45,8 +45,7 @@ template <typename T> class fwd_piter_bbox_; template <typename T> class bkd_piter_bbox_; template <typename P> class fwd_qiter_win_; -// FIXME: Not yet available. -// template <typename P> class bkd_qiter_win_; + template <typename P> class bkd_qiter_win_; /// \} @@ -67,8 +66,7 @@ typedef bkd_piter_bbox_<point1d> bkd_piter1d; typedef fwd_qiter_win_<point1d> fwd_qiter1d; -// FIXME: Not yet available. -// typedef bkd_qiter_win_<point1d> fwd_qiter1d; + typedef bkd_qiter_win_<point1d> bkd_qiter1d; typedef point1d_<float> point1df; typedef dpoint1d_<float> dpoint1df; Index: oln/core/2d/aliases.hh --- oln/core/2d/aliases.hh (revision 638) +++ oln/core/2d/aliases.hh (working copy) @@ -45,8 +45,7 @@ template <typename P> class fwd_piter_bbox_; template <typename P> class bkd_piter_bbox_; template <typename P> class fwd_qiter_win_; -// FIXME: Not yet available. -// template <typename P> class bkd_qiter_win_; + template <typename P> class bkd_qiter_win_; /// \} @@ -67,8 +66,7 @@ typedef bkd_piter_bbox_<point2d> bkd_piter2d; typedef fwd_qiter_win_<point2d> fwd_qiter2d; -// FIXME: Not yet available. -// typedef bkd_qiter_win_<point2d> fwd_qiter2d; + typedef bkd_qiter_win_<point2d> bkd_qiter2d; typedef point2d_<float> point2df; typedef dpoint2d_<float> dpoint2df; Index: oln/core/3d/aliases.hh --- oln/core/3d/aliases.hh (revision 638) +++ oln/core/3d/aliases.hh (working copy) @@ -45,8 +45,7 @@ template <typename T> class fwd_piter_bbox_; template <typename T> class bkd_piter_bbox_; template <typename P> class fwd_qiter_win_; -// FIXME: Not yet available. -// template <typename P> class bkd_qiter_win_; + template <typename P> class bkd_qiter_win_; /// \} @@ -67,8 +66,7 @@ typedef bkd_piter_bbox_<point3d> bkd_piter3d; typedef fwd_qiter_win_<point3d> fwd_qiter3d; -// FIXME: Not yet available. -// typedef bkd_qiter_win_<point3d> fwd_qiter3d; + typedef bkd_qiter_win_<point3d> bkd_qiter3d; typedef point3d_<float> point3df; typedef dpoint3d_<float> dpoint3df; Index: oln/core/gen/bkd_qiter_win.hh --- oln/core/gen/bkd_qiter_win.hh (revision 0) +++ oln/core/gen/bkd_qiter_win.hh (revision 0) @@ -0,0 +1,181 @@ +// Copyright (C) 2006 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 OLN_CORE_GEN_BKD_QITER_WIN_HH +# define OLN_CORE_GEN_BKD_QITER_WIN_HH + +# include <oln/core/abstract/iterator_on_points.hh> +# include <oln/core/abstract/window.hh> +# include <oln/core/gen/window.hh> + + +namespace oln +{ + + + // Backward declaration. + template <typename point_t> class bkd_qiter_win_; + + + // Super type declaration. + template <typename point_t> + struct set_super_type< bkd_qiter_win_<point_t> > + { + typedef bkd_qiter_win_<point_t> self_t; + typedef abstract::iterator_on_points<self_t> ret; + }; + + + /// Virtual types associated to oln::bkd_qiter_win_<point_t>. + template <typename point_t> + struct vtypes< bkd_qiter_win_<point_t> > + { + typedef point_t point_type; + typedef oln_type_of(point_t, grid) grid_type; + }; + + + + /// Abstract backward point iterator class. + template <typename point_t> + class bkd_qiter_win_ : public abstract::iterator_on_points< bkd_qiter_win_<point_t> > + { + typedef bkd_qiter_win_<point_t> self_t; + typedef abstract::iterator_on_points<self_t> super_t; + + typedef oln_type_of(point_t, dpoint) dpoint_t; + + public: + + template <typename P, typename W> + bkd_qiter_win_(const abstract::iterator_on_points<P>& it, + const abstract::window<W>& win); + + template <typename P, typename W> + bkd_qiter_win_(const abstract::point<P>& p, + const abstract::window<W>& win); + + void impl_start(); + + void impl_next(); + + void impl_invalidate(); + + bool impl_is_valid() const; + + point_t impl_to_point() const; + + const point_t* impl_point_adr() const; + + protected: + + const point_t* p_ref_; + window_<dpoint_t> win_; + int i_; + point_t p_; + + }; // end of class oln::bkd_qiter_win_<point_t> + + + +# ifndef OLN_INCLUDE_ONLY + + template <typename point_t> + template <typename P, typename W> + bkd_qiter_win_<point_t>::bkd_qiter_win_(const abstract::iterator_on_points<P>& it, + const abstract::window<W>& win) + : p_ref_(it.point_adr()), + win_(win.exact()) + { + precondition(win_.card() > 0); + this->invalidate(); + } + + template <typename point_t> + template <typename P, typename W> + bkd_qiter_win_<point_t>::bkd_qiter_win_(const abstract::point<P>& p, + const abstract::window<W>& win) + : p_ref_(&(p.exact())), + win_(win.exact()) + { + precondition(win_.card() > 0); + this->invalidate(); + } + + template <typename point_t> + void + bkd_qiter_win_<point_t>::impl_start() + { + i_ = int(win_.card()) - 1; + p_ = *p_ref_+ win_.dp(i_); + } + + template <typename point_t> + void + bkd_qiter_win_<point_t>::impl_next() + { + --i_; + if (i_ == -1) + return; + p_ = *p_ref_ + win_.dp(i_); + } + + template <typename point_t> + void + bkd_qiter_win_<point_t>::impl_invalidate() + { + i_ = -1; + } + + template <typename point_t> + bool + bkd_qiter_win_<point_t>::impl_is_valid() const + { + return i_ != -1; + } + + template <typename point_t> + point_t + bkd_qiter_win_<point_t>::impl_to_point() const + { + return p_; + } + + template <typename point_t> + const point_t* + bkd_qiter_win_<point_t>::impl_point_adr() const + { + return &p_; + } + +# endif + +} // end of namespace oln + + +#endif // ! OLN_CORE_GEN_BKD_QITER_WIN_HH + Index: oln/core/gen/fwd_niter_neighb.hh --- oln/core/gen/fwd_niter_neighb.hh (revision 638) +++ oln/core/gen/fwd_niter_neighb.hh (working copy) @@ -75,6 +75,8 @@ fwd_niter_neighb_(const abstract::iterator_on_points<P>& it, const abstract::topology<T>& topo); + // FIXME: To be possibly enabled later (still unsure about it). + // template <typename P, typename N> // fwd_niter_neighb_(const abstract::iterator_on_points<P>& it, // const abstract::neighborhood<N>& nbh) @@ -82,7 +84,7 @@ // nbh_(nbh.exact()) // { // precondition(nbh_.card() > 0); - // i_ = -1; + // this->invalidate(); // } // template <typename P, typename T> @@ -92,7 +94,7 @@ // nbh_(topo.exact().neighborhood()) // { // precondition(nbh_.card() > 0); - // i_ = -1; + // this->invalidate(); // } // template <typename P, typename N> @@ -102,7 +104,7 @@ // nbh_(nbh.exact()) // { // precondition(nbh_.card() > 0); - // i_ = -1; + // this->invalidate(); // } void impl_start(); @@ -139,7 +141,7 @@ nbh_(topo.exact().neighborhood()) { precondition(nbh_.card() > 0); - i_ = -1; + this->invalidate(); } template <typename point_t> @@ -157,7 +159,7 @@ ++i_; if (i_ == int(nbh_.card())) { - i_ = -1; + this->invalidate(); return; } p_ = *p_ref_ + nbh_.dp(i_); Index: oln/core/gen/fwd_qiter_win.hh --- oln/core/gen/fwd_qiter_win.hh (revision 638) +++ oln/core/gen/fwd_qiter_win.hh (working copy) @@ -112,7 +112,7 @@ win_(win.exact()) { precondition(win_.card() > 0); - i_ = -1; + this->invalidate(); } template <typename point_t> @@ -123,7 +123,7 @@ win_(win.exact()) { precondition(win_.card() > 0); - i_ = -1; + this->invalidate(); } template <typename point_t> @@ -141,7 +141,7 @@ ++i_; if (i_ == int(win_.card())) { - i_ = -1; + this->invalidate(); return; } p_ = *p_ref_ + win_.dp(i_); Index: oln/core/gen/bkd_niter_neighb.hh --- oln/core/gen/bkd_niter_neighb.hh (revision 0) +++ oln/core/gen/bkd_niter_neighb.hh (revision 0) @@ -0,0 +1,200 @@ +// Copyright (C) 2006 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 OLN_CORE_GEN_BKD_NITER_NEIGHB_HH +# define OLN_CORE_GEN_BKD_NITER_NEIGHB_HH + +# include <oln/core/abstract/topology.hh> +# include <oln/core/abstract/iterator_on_points.hh> +# include <oln/core/gen/neighb.hh> + + +namespace oln +{ + + + // Backward declaration. + template <typename point_t> class bkd_niter_neighb_; + + + // Super type declaration. + template <typename point_t> + struct set_super_type< bkd_niter_neighb_<point_t> > + { + typedef bkd_niter_neighb_<point_t> self_t; + typedef abstract::iterator_on_points<self_t> ret; + }; + + + /// Virtual types associated to oln::bkd_niter_neighb_<point_t>. + template <typename point_t> + struct vtypes< bkd_niter_neighb_<point_t> > + { + typedef point_t point_type; + typedef oln_type_of(point_t, grid) grid_type; + }; + + + + /// Abstract backward point iterator class. + template <typename point_t> + class bkd_niter_neighb_ : public abstract::iterator_on_points< bkd_niter_neighb_<point_t> > + { + typedef bkd_niter_neighb_<point_t> self_t; + typedef abstract::iterator_on_points<self_t> super_t; + + typedef oln_type_of(point_t, dpoint) dpoint_t; + + public: + + template <typename P, typename T> + bkd_niter_neighb_(const abstract::iterator_on_points<P>& it, + const abstract::topology<T>& topo); + + // FIXME: To be possibly enabled later (still unsure about it). + + // template <typename P, typename N> + // bkd_niter_neighb_(const abstract::iterator_on_points<P>& it, + // const abstract::neighborhood<N>& nbh) + // : p_ref_(it.point_adr()), + // nbh_(nbh.exact()) + // { + // precondition(nbh_.card() > 0); + // this->invalidate(); + // } + + // template <typename P, typename T> + // bkd_niter_neighb_(const abstract::point<P>& p, + // const abstract::topology<T>& topo) + // : p_ref_(&(p.exact())), + // nbh_(topo.exact().neighborhood()) + // { + // precondition(nbh_.card() > 0); + // this->invalidate(); + // } + + // template <typename P, typename N> + // bkd_niter_neighb_(const abstract::point<P>& p, + // const abstract::neighborhood<N>& nbh) + // : p_ref_(&(p.exact())), + // nbh_(nbh.exact()) + // { + // precondition(nbh_.card() > 0); + // this->invalidate(); + // } + + void impl_start(); + + void impl_next(); + + void impl_invalidate(); + + bool impl_is_valid() const; + + point_t impl_to_point() const; + + const point_t* impl_point_adr() const; + + protected: + + const point_t* p_ref_; + neighb_<dpoint_t> nbh_; + int i_; + point_t p_; + + }; // end of class oln::bkd_niter_neighb_<point_t> + + + + +# ifndef OLN_INCLUDE_ONLY + + template <typename point_t> + template <typename P, typename T> + bkd_niter_neighb_<point_t>::bkd_niter_neighb_(const abstract::iterator_on_points<P>& it, + const abstract::topology<T>& topo) + : p_ref_(it.point_adr()), + nbh_(topo.exact().neighborhood()) + { + precondition(nbh_.card() > 0); + this->invalidate(); + } + + template <typename point_t> + void + bkd_niter_neighb_<point_t>::impl_start() + { + i_ = int(nbh_.card()) - 1; + p_ = *p_ref_+ nbh_.dp(i_); + } + + template <typename point_t> + void + bkd_niter_neighb_<point_t>::impl_next() + { + --i_; + if (i_ == -1) + return; + p_ = *p_ref_ + nbh_.dp(i_); + } + + template <typename point_t> + void + bkd_niter_neighb_<point_t>::impl_invalidate() + { + i_ = -1; + } + + template <typename point_t> + bool + bkd_niter_neighb_<point_t>::impl_is_valid() const + { + return i_ != -1; + } + + template <typename point_t> + point_t + bkd_niter_neighb_<point_t>::impl_to_point() const + { + return p_; + } + + template <typename point_t> + const point_t* + bkd_niter_neighb_<point_t>::impl_point_adr() const + { + return &p_; + } + +# endif + + +} // end of namespace oln + + +#endif // ! OLN_CORE_GEN_BKD_NITER_NEIGHB_HH + Index: oln/basics2d.hh --- oln/basics2d.hh (revision 638) +++ oln/basics2d.hh (working copy) @@ -46,6 +46,7 @@ # include <oln/core/gen/window.hh> # include <oln/core/gen/fwd_qiter_win.hh> +# include <oln/core/gen/bkd_qiter_win.hh> # include <oln/core/gen/neighb.hh> # include <oln/core/2d/neighb2d.hh> Index: oln/Makefile.am --- oln/Makefile.am (revision 638) +++ oln/Makefile.am (working copy) @@ -104,7 +104,9 @@ core/gen/bbox.hh \ core/gen/bbox_bkd_piter.hh \ core/gen/bbox_fwd_piter.hh \ + core/gen/bkd_niter_neighb.hh \ core/gen/bkd_piter_bbox.hh \ + core/gen/bkd_qiter_win.hh \ core/gen/fwd_niter_neighb.hh \ core/gen/fwd_piter_bbox.hh \ core/gen/fwd_qiter_win.hh \ Index: oln/basics3d.hh --- oln/basics3d.hh (revision 638) +++ oln/basics3d.hh (working copy) @@ -44,6 +44,10 @@ # include <oln/core/gen/fwd_piter_bbox.hh> # include <oln/core/gen/bkd_piter_bbox.hh> +# include <oln/core/gen/window.hh> +# include <oln/core/gen/fwd_qiter_win.hh> +# include <oln/core/gen/bkd_qiter_win.hh> + # include <oln/core/gen/neighb.hh> # include <oln/core/3d/neighb3d.hh>
participants (1)
-
Roland Levillain