
2006-09-22 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr> Add image point iterators parameterized by the image topology; factor code into an internal class. * oln/core/gen/bbox_fwd_piter.hh: Change inheritance and move methods into... * oln/core/internal/bbox_fwd_piter.hh: ...this new class. * oln/core/gen/bbox_bkd_piter.hh: Change inheritance and move methods into... * oln/core/internal/bbox_bkd_piter.hh: ...this new class. * oln/core/gen/fwd_piter_bbox.hh: New. * oln/core/gen/bkd_piter_bbox.hh: New. Index: oln/core/gen/bbox_fwd_piter.hh =================================================================== --- oln/core/gen/bbox_fwd_piter.hh (revision 555) +++ oln/core/gen/bbox_fwd_piter.hh (working copy) @@ -29,9 +29,7 @@ #ifndef OLENA_CORE_GEN_BBOX_FWD_PITER_HH # define OLENA_CORE_GEN_BBOX_FWD_PITER_HH -# include <oln/core/abstract/iterator_on_points.hh> -# include <oln/core/abstract/point.hh> -# include <oln/core/gen/bbox.hh> +# include <oln/core/internal/bbox_fwd_piter.hh> namespace oln @@ -47,7 +45,7 @@ struct set_super_type< bbox_fwd_piter_<point> > { typedef bbox_fwd_piter_<point> self_t; - typedef abstract::iterator_on_points<self_t> ret; + typedef internal::bbox_fwd_piter<self_t> ret; }; @@ -63,107 +61,18 @@ /// Abstract forward point iterator class. template <typename point> - class bbox_fwd_piter_ : public abstract::iterator_on_points< bbox_fwd_piter_<point> >, + class bbox_fwd_piter_ : public internal::bbox_fwd_piter< bbox_fwd_piter_<point> >, private mlc::assert_< mlc_is_a(point, abstract::point) > { typedef bbox_fwd_piter_<point> self_t; - typedef abstract::iterator_on_points<self_t> super_t; + typedef internal::bbox_fwd_piter<self_t> super_t; public: bbox_fwd_piter_(const bbox_<point>& bb) - : p_(), - bb_(bb) + : super_t(bb) { - nop_ = bb_.pmax(); - ++nop_[0]; } - -// template <typename T> -// bbox_fwd_piter_(const abstract::topo<T>& t) -// { -// mlc::assert_< mlc_is_a(T, abstract::topo_with_bbox) >::check(); -// bb_ = t.exact().bbox(); -// nop_ = bb_.pmax(); -// ++nop_[0]; -// } - -// template <typename Data> -// bbox_fwd_piter_(const Data& data) -// : bb_(data.bbox()) -// { -// nop_ = bb_.pmax(); -// ++nop_[0]; -// } - - const bbox_<point>& bbox() const - { - return bb_; - } - - void impl_start() - { - p_ = bb_.pmin(); - invariant(implies(p_ != nop_, bb_.has(p_))); - } - - void impl_next() - { - invariant(implies(p_ != nop_, bb_.has(p_))); - for (int i = point::n - 1; i >= 0; --i) - if (p_[i] == bb_.pmax(i)) - p_[i] = bb_.pmin(i); - else - { - ++p_[i]; - break; - } - if (p_ == bb_.pmin()) - p_ = nop_; - } - - void impl_invalidate() - { - invariant(implies(p_ != nop_, bb_.has(p_))); - p_ = nop_; - } - - bool impl_is_valid() const - { - invariant(implies(p_ != nop_, bb_.has(p_))); - return p_ != nop_; - } - - point impl_to_point() const - { - return p_; - } - - const point* impl_point_adr() const - { - return &p_; - } - - void print(std::ostream& ostr) const - { - ostr << "{ bb=" << bb_ - << ", p=" << p_ - << ", nop=" << nop_ - << " }"; - } - - friend - std::ostream& operator<<(std::ostream& ostr, const bbox_fwd_piter_<point>& i) - { - i.print(ostr); - return ostr; - } - - protected: - - point p_; - bbox_<point> bb_; - point nop_; }; // end of class oln::bbox_fwd_piter_<point> Index: oln/core/gen/bbox_bkd_piter.hh =================================================================== --- oln/core/gen/bbox_bkd_piter.hh (revision 555) +++ oln/core/gen/bbox_bkd_piter.hh (working copy) @@ -29,9 +29,7 @@ #ifndef OLENA_CORE_GEN_BBOX_BKD_PITER_HH # define OLENA_CORE_GEN_BBOX_BKD_PITER_HH -# include <oln/core/abstract/iterator_on_points.hh> -# include <oln/core/abstract/point.hh> -# include <oln/core/gen/bbox.hh> +# include <oln/core/internal/bbox_bkd_piter.hh> namespace oln @@ -47,11 +45,11 @@ struct set_super_type< bbox_bkd_piter_<point> > { typedef bbox_bkd_piter_<point> self_t; - typedef abstract::iterator_on_points<self_t> ret; + typedef internal::bbox_bkd_piter<self_t> ret; }; - /// Virtual types associated to oln::bbox_<point>. + /// Virtual types associated to oln::bbox_bkd_piter_<point>. template <typename point> struct vtypes< bbox_bkd_piter_<point> > { @@ -63,76 +61,19 @@ /// Abstract forward point iterator class. template <typename point> - class bbox_bkd_piter_ : public abstract::iterator_on_points< bbox_bkd_piter_<point> >, + class bbox_bkd_piter_ : public internal::bbox_bkd_piter< bbox_bkd_piter_<point> >, private mlc::assert_< mlc_is_a(point, abstract::point) > { typedef bbox_bkd_piter_<point> self_t; - typedef abstract::iterator_on_points<self_t> super_t; + typedef internal::bbox_bkd_piter<self_t> super_t; public: bbox_bkd_piter_(const bbox_<point>& bb) - : p_(), - bb_(bb) + : super_t(bb) { - nop_ = bb_.pmin(); - --nop_[0]; } - - const bbox_<point>& bbox() const - { - return bb_; - } - - void impl_start() - { - p_ = bb_.pmax(); - invariant(implies(p_ != nop_, bb_.has(p_))); - } - - void impl_next() - { - invariant(implies(p_ != nop_, bb_.has(p_))); - for (int i = point::n - 1; i >= 0; --i) - if (p_[i] == bb_.pmin(i)) - p_[i] = bb_.pmax(i); - else - { - --p_[i]; - break; - } - if (p_ == bb_.pmax()) - p_ = nop_; - } - - void impl_invalidate() - { - invariant(implies(p_ != nop_, bb_.has(p_))); - p_ = nop_; - } - - bool impl_is_valid() const - { - invariant(implies(p_ != nop_, bb_.has(p_))); - return p_ != nop_; - } - - point impl_to_point() const - { - return p_; - } - - const point* impl_point_adr() const - { - return &p_; - } - - protected: - - point p_; - bbox_<point> bb_; - point nop_; - + }; // end of class oln::bbox_bkd_piter_<point> Index: oln/core/gen/fwd_piter_bbox.hh =================================================================== --- oln/core/gen/fwd_piter_bbox.hh (revision 0) +++ oln/core/gen/fwd_piter_bbox.hh (revision 0) @@ -0,0 +1,108 @@ +// Copyright (C) 2001, 2003, 2004, 2005, 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 OLENA_CORE_GEN_FWD_PITER_BBOX_HH +# define OLENA_CORE_GEN_FWD_PITER_BBOX_HH + +# include <oln/core/abstract/topology.hh> +# include <oln/core/internal/bbox_fwd_piter.hh> + + +namespace oln +{ + + + // Forward declaration. + template <typename topo> class fwd_piter_bbox_; + + + // Super type declaration. + template <typename topo> + struct set_super_type< fwd_piter_bbox_<topo> > + { + typedef fwd_piter_bbox_<topo> self_t; + typedef internal::bbox_fwd_piter<self_t> ret; + }; + + + /// Virtual types associated to oln::fwd_piter_bbox_<topo>. + template <typename topo> + struct vtypes< fwd_piter_bbox_<topo> > + { + typedef oln_type_of(topo, point) point_type; + typedef oln_type_of(topo, grid) grid_type; + }; + + + + /// Abstract forward point iterator class. + template <typename topo_t> + class fwd_piter_bbox_ : public internal::bbox_fwd_piter< fwd_piter_bbox_<topo_t> >, + private mlc::assert_< mlc_is_a(topo_t, abstract::topology) > + { + typedef fwd_piter_bbox_<topo_t> self_t; + typedef internal::bbox_fwd_piter<self_t> super_t; + + public: + + template <typename T> + fwd_piter_bbox_(const abstract::topology<T>& topo) + : super_t(topo.exact().bbox()), + topo_(topo.exact()) + { + } + + const topo_t& topo() const + { + return topo_; + } + + void print(std::ostream& ostr) const + { + ostr << "{ p=" << super_t::p_ + << " }"; + } + + friend + std::ostream& operator<<(std::ostream& ostr, const fwd_piter_bbox_<topo_t>& t) + { + t.print(ostr); + return ostr; + } + + protected: + + const topo_t& topo_; + + }; // end of class oln::fwd_piter_bbox_<point> + + +} // end of namespace oln + + +#endif // ! OLENA_CORE_GEN_FWD_PITER_BBOX_HH Index: oln/core/gen/bkd_piter_bbox.hh =================================================================== --- oln/core/gen/bkd_piter_bbox.hh (revision 0) +++ oln/core/gen/bkd_piter_bbox.hh (revision 0) @@ -0,0 +1,108 @@ +// Copyright (C) 2001, 2003, 2004, 2005, 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 OLENA_CORE_GEN_BKD_PITER_BBOX_HH +# define OLENA_CORE_GEN_BKD_PITER_BBOX_HH + +# include <oln/core/abstract/topology.hh> +# include <oln/core/internal/bbox_bkd_piter.hh> + + +namespace oln +{ + + + // Forward declaration. + template <typename topo> class bkd_piter_bbox_; + + + // Super type declaration. + template <typename topo> + struct set_super_type< bkd_piter_bbox_<topo> > + { + typedef bkd_piter_bbox_<topo> self_t; + typedef internal::bbox_bkd_piter<self_t> ret; + }; + + + /// Virtual types associated to oln::bkd_piter_bbox_<topo>. + template <typename topo> + struct vtypes< bkd_piter_bbox_<topo> > + { + typedef oln_type_of(topo, point) point_type; + typedef oln_type_of(topo, grid) grid_type; + }; + + + + /// Abstract forward point iterator class. + template <typename topo_t> + class bkd_piter_bbox_ : public internal::bbox_bkd_piter< bkd_piter_bbox_<topo_t> >, + private mlc::assert_< mlc_is_a(topo_t, abstract::topology) > + { + typedef bkd_piter_bbox_<topo_t> self_t; + typedef internal::bbox_bkd_piter<self_t> super_t; + + public: + + template <typename T> + bkd_piter_bbox_(const abstract::topology<T>& topo) + : super_t(topo.exact().bbox()), + topo_(topo.exact()) + { + } + + const topo_t& topo() const + { + return topo_; + } + + void print(std::ostream& ostr) const + { + ostr << "{ p=" << super_t::p_ + << " }"; + } + + friend + std::ostream& operator<<(std::ostream& ostr, const bkd_piter_bbox_<topo_t>& t) + { + t.print(ostr); + return ostr; + } + + protected: + + const topo_t& topo_; + + }; // end of class oln::bkd_piter_bbox_<point> + + +} // end of namespace oln + + +#endif // ! OLENA_CORE_GEN_BKD_PITER_BBOX_HH Index: oln/core/internal/bbox_fwd_piter.hh =================================================================== --- oln/core/internal/bbox_fwd_piter.hh (revision 0) +++ oln/core/internal/bbox_fwd_piter.hh (revision 0) @@ -0,0 +1,137 @@ +// Copyright (C) 2001, 2003, 2004, 2005, 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 OLENA_CORE_INTERNAL_BBOX_FWD_PITER_HH +# define OLENA_CORE_INTERNAL_BBOX_FWD_PITER_HH + +# include <oln/core/abstract/iterator_on_points.hh> +# include <oln/core/abstract/point.hh> +# include <oln/core/gen/bbox.hh> + + +namespace oln +{ + + + // Forward declaration. + namespace internal { + template <typename E> class bbox_fwd_piter; + } + + + // Super type declaration. + template <typename E> + struct set_super_type< internal::bbox_fwd_piter<E> > + { + typedef abstract::iterator_on_points<E> ret; + }; + + + + namespace internal + { + + /// Internal forward point iterator class; this class factors code. + template <typename E> + class bbox_fwd_piter : public abstract::iterator_on_points<E> + { + typedef oln_type_of(E, point) point_t; + + public: + + bbox_fwd_piter(const bbox_<point_t>& bb) + : p_(), + bb_(bb) + { + nop_ = bb_.pmax(); + ++nop_[0]; + } + + const bbox_<point_t>& bbox() const + { + return bb_; + } + + void impl_start() + { + p_ = bb_.pmin(); + invariant(implies(p_ != nop_, bb_.has(p_))); + } + + void impl_next() + { + invariant(implies(p_ != nop_, bb_.has(p_))); + for (int i = point_t::n - 1; i >= 0; --i) + if (p_[i] == bb_.pmax(i)) + p_[i] = bb_.pmin(i); + else + { + ++p_[i]; + break; + } + if (p_ == bb_.pmin()) + p_ = nop_; + } + + void impl_invalidate() + { + invariant(implies(p_ != nop_, bb_.has(p_))); + p_ = nop_; + } + + bool impl_is_valid() const + { + invariant(implies(p_ != nop_, bb_.has(p_))); + return p_ != nop_; + } + + point_t impl_to_point() const + { + return p_; + } + + const point_t* impl_point_adr() const + { + return &p_; + } + + protected: + + point_t p_; + bbox_<point_t> bb_; + point_t nop_; + + }; // end of class oln::internal::bbox_fwd_piter<E> + + + } // end of namespace oln::internal + +} // end of namespace oln + + +#endif // ! OLENA_CORE_INTERNAL_BBOX_FWD_PITER_HH Index: oln/core/internal/bbox_bkd_piter.hh =================================================================== --- oln/core/internal/bbox_bkd_piter.hh (revision 0) +++ oln/core/internal/bbox_bkd_piter.hh (revision 0) @@ -0,0 +1,137 @@ +// Copyright (C) 2001, 2003, 2004, 2005, 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 OLENA_CORE_INTERNAL_BBOX_BKD_PITER_HH +# define OLENA_CORE_INTERNAL_BBOX_BKD_PITER_HH + +# include <oln/core/abstract/iterator_on_points.hh> +# include <oln/core/abstract/point.hh> +# include <oln/core/gen/bbox.hh> + + +namespace oln +{ + + + // Forward declaration. + namespace internal { + template <typename E> class bbox_bkd_piter; + } + + + // Super type declaration. + template <typename E> + struct set_super_type< internal::bbox_bkd_piter<E> > + { + typedef abstract::iterator_on_points<E> ret; + }; + + + + namespace internal + { + + /// Internal backward point iterator class; this class factors code. + template <typename E> + class bbox_bkd_piter : public abstract::iterator_on_points<E> + { + typedef oln_type_of(E, point) point_t; + + public: + + bbox_bkd_piter(const bbox_<point_t>& bb) + : p_(), + bb_(bb) + { + nop_ = bb_.pmin(); + --nop_[0]; + } + + const bbox_<point_t>& bbox() const + { + return bb_; + } + + void impl_start() + { + p_ = bb_.pmax(); + invariant(implies(p_ != nop_, bb_.has(p_))); + } + + void impl_next() + { + invariant(implies(p_ != nop_, bb_.has(p_))); + for (int i = point_t::n - 1; i >= 0; --i) + if (p_[i] == bb_.pmin(i)) + p_[i] = bb_.pmax(i); + else + { + --p_[i]; + break; + } + if (p_ == bb_.pmax()) + p_ = nop_; + } + + void impl_invalidate() + { + invariant(implies(p_ != nop_, bb_.has(p_))); + p_ = nop_; + } + + bool impl_is_valid() const + { + invariant(implies(p_ != nop_, bb_.has(p_))); + return p_ != nop_; + } + + point_t impl_to_point() const + { + return p_; + } + + const point_t* impl_point_adr() const + { + return &p_; + } + + protected: + + point_t p_; + bbox_<point_t> bb_; + point_t nop_; + + }; // end of class oln::internal::bbox_bkd_piter<E> + + + } // end of namespace oln::internal + +} // end of namespace oln + + +#endif // ! OLENA_CORE_INTERNAL_BBOX_BKD_PITER_HH