
https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Add infinite point set type. * oln/core/internal/f_pset_plain.hh: Rename as... * oln/core/internal/f_pset_to_plain_image.hh: ...this. (include): Add f_grid_to_plain_image.hh. (f_pset_plain_, oln_f_pset_plain): Rename as... (f_pset_to_plain_image_, oln_f_pset_to_plain_image): ...these. (pset_to_plain_image__): New versions to handle op_<S, such_as, F> and gen_box<P>. * oln/core/gen/single_value_image.hh: Update. * oln/core/gen/infty_pset.hh, * oln/core/internal/f_grid_to_plain_image.hh, * oln/core/internal/f_grid_to_box.hh: New. * oln/core/internal/iterator_on_points_base.hh (iterator_on_points_base): Rename as... (iterator_on_points_base_): ...this. * oln/core/rle/rle_pset.hh, * oln/core/gen/dpoints_piter.hh, * oln/core/gen/image_pset_piter.hh, * oln/core/internal/box.hh, * oln/core/internal/point_set_std_based.hh, * oln/core/internal/piter_adaptor.hh: Update. * oln/draw/bresenham.hh (bresenham_): Rely on level::paste. (input): Rename as... (in_out): ...this. * oln/core/equipment.hh (oln_deduce): New. * oln/core/gen/pset_compare.hh (intersects): New. (op_leq_, op_less_): Rename as... (op_subset_, op_strict_subset_): ...these. (op_eq_, op_subset_, op_strict_subset_): New versions for infty_pset. (operator>=, operator>): Rely on op_subset_ and op_strict_subset_. * oln/core/gen/pset.hh: Cosmetic changes. * oln/core/gen/safe_image.hh (pset): Use infty_pset. (impl_points): New. * oln/core/internal/image_base.hh: Cosmetic change. * oln/core/internal/point_base.hh (set_all): New. core/equipment.hh | 3 core/gen/dpoints_piter.hh | 8 - core/gen/image_pset_piter.hh | 26 ++--- core/gen/infty_pset.hh | 130 ++++++++++++++++++++++++++++ core/gen/pset.hh | 6 - core/gen/pset_compare.hh | 139 +++++++++++++++++++++++-------- core/gen/safe_image.hh | 13 ++ core/gen/single_value_image.hh | 7 - core/internal/box.hh | 12 +- core/internal/f_grid_to_box.hh | 106 +++++++++++++++++++++++ core/internal/f_grid_to_plain_image.hh | 105 +++++++++++++++++++++++ core/internal/f_pset_to_plain_image.hh | 85 +++++++++++++++--- core/internal/image_base.hh | 2 core/internal/iterator_on_points_base.hh | 36 +++----- core/internal/piter_adaptor.hh | 6 - core/internal/point_base.hh | 61 ++----------- core/internal/point_set_std_based.hh | 14 +-- core/rle/rle_pset.hh | 18 ++-- draw/bresenham.hh | 23 ++--- 19 files changed, 615 insertions(+), 185 deletions(-) Index: oln/core/rle/rle_pset.hh --- oln/core/rle/rle_pset.hh (revision 921) +++ oln/core/rle/rle_pset.hh (working copy) @@ -100,7 +100,7 @@ /// number of point in the set unsigned npts; /// container of the set - std_container con_; + std_container con_; // FIXME: Add a &. /// pset box fbbox_<point> fb_; }; @@ -188,7 +188,7 @@ struct super_trait_< rle_pset_fwd_piter_<P> > { typedef rle_pset_fwd_piter_<P> current; - typedef internal::iterator_on_points_base<current> ret; + typedef internal::iterator_on_points_base_<current> ret; }; // Virtual types @@ -206,9 +206,9 @@ ** P must be a point type */ template <typename P> - class rle_pset_fwd_piter_ : public internal::iterator_on_points_base<rle_pset_fwd_piter_<P> > + class rle_pset_fwd_piter_ : public internal::iterator_on_points_base_<rle_pset_fwd_piter_<P> > { - typedef internal::iterator_on_points_base< rle_pset_fwd_piter_<P> > super; + typedef internal::iterator_on_points_base_< rle_pset_fwd_piter_<P> > super; typedef rle_pset_fwd_piter_<P> current; public: stc_using(point); @@ -251,7 +251,7 @@ void rle_pset_fwd_piter_<P>::impl_start() { - this->it_ = this->con_.begin(); + this->it_ = this->con_.begin(); // FIXME: Test if (this->it_ != this->con_.end())... this->ps_.start_ = this->it_->first; this->ps_.index_ = 0; } @@ -326,7 +326,7 @@ struct super_trait_< rle_pset_bkd_piter_<P> > { typedef rle_pset_bkd_piter_<P> current; - typedef internal::iterator_on_points_base<current> ret; + typedef internal::iterator_on_points_base_<current> ret; }; // Virtual type @@ -343,9 +343,9 @@ ** P must be a point type */ template <typename P> - class rle_pset_bkd_piter_ : public internal::iterator_on_points_base<rle_pset_bkd_piter_<P> > + class rle_pset_bkd_piter_ : public internal::iterator_on_points_base_<rle_pset_bkd_piter_<P> > { - typedef internal::iterator_on_points_base< rle_pset_bkd_piter_<P> > super; + typedef internal::iterator_on_points_base_< rle_pset_bkd_piter_<P> > super; typedef rle_pset_bkd_piter_<P> current; public: stc_using(point); @@ -386,7 +386,7 @@ void rle_pset_bkd_piter_<P>::impl_start() { - this->it_ = this->con_.rbegin(); + this->it_ = this->con_.rbegin(); // FIXME: Test if (this->it_ != this->con_.rend())... this->ps_.start_ = this->it_->first; this->ps_.index_ = this->it_->second - 1; } Index: oln/core/equipment.hh --- oln/core/equipment.hh (revision 921) +++ oln/core/equipment.hh (working copy) @@ -35,9 +35,12 @@ # include <stc/scoop-alt.hh> # endif + # define oln_typename_shortcut__(Type, Alias) typename Type::Alias +# define oln_deduce(Type, Alias_1, Alias_2) typename Type::Alias_1::Alias_2 + namespace oln { Index: oln/core/gen/pset_compare.hh --- oln/core/gen/pset_compare.hh (revision 921) +++ oln/core/gen/pset_compare.hh (working copy) @@ -51,6 +51,13 @@ template <typename L, typename R> bool operator >= (const Point_Set<L>& lhs, const Point_Set<R>& rhs); + template <typename B1, typename B2> + bool intersects (const Box<B1>& box1, const Box<B2>& box2); + + template <typename G> + class infty_pset; + + # ifndef OLN_INCLUDE_ONLY @@ -65,6 +72,13 @@ template <typename L, typename R> bool op_eq_(const Point_Set<L>& lhs, const Point_Set<R>& rhs) { + // first quick test + if (lhs.npoints() != rhs.npoints()) + return false; + // second quick test + if (not intersects(lhs.bbox(), rhs.bbox())) + return false; + // exhaustive test oln_piter(L) pl(lhs); oln_piter(R) pr(rhs); for (pl.start(), pr.start(); @@ -89,13 +103,40 @@ return lhs.pmin() = rhs.pmin() and lhs.pmax() = rhs.pmax(); } + // Versions with infinite set. + + template <typename S, typename G> + bool op_eq_(const Point_Set<S>&, const infty_pset<G>&) + { + return false; + } + + template <typename G, typename S> + bool op_eq_(const infty_pset<G>&, const Point_Set<S>&) + { + return false; + } + + template <typename G> + bool op_eq_(const infty_pset<G>&, const infty_pset<G>&) + { + return true; + } + // Point_Set L <= Point_Set R + // ------------------------------ + + // Generic version. template <typename L, typename R> - bool op_leq_(const Point_Set<L>& lhs, const Point_Set<R>& rhs) + bool op_subset_(const Point_Set<L>& lhs, const Point_Set<R>& rhs) { - if (lhs.npoints() > rhs.npoints()) // quick test + // first quick test + if (lhs.npoints() > rhs.npoints()) + return false; + // second quick test + if (not intersects(lhs.bbox(), rhs.bbox())) return false; // all points of lhs are IN rhs? oln_piter(R) p_rhs(rhs); @@ -111,63 +152,79 @@ return true; } - - // Point_Set L < Point_Set R + // Version for Boxes. template <typename L, typename R> - bool op_less_(const Point_Set<L>& lhs, const Point_Set<R>& rhs) + bool op_subset_(const Box<L>& lhs, const Box<R>& rhs) + { + for (unsigned i = 0; i < L::n; ++i) { - return op_leq_(lhs, rhs) and lhs.npoints() < rhs.npoints(); + if (lhs.pmin()[i] < rhs.pmin()[i] or lhs.pmax()[i] > rhs.pmax()[i]) + return false; + } + return true; } + // Versions with infinite set. + template <typename S, typename G> + bool op_subset_(const Point_Set<S>&, const infty_pset<G>&) + { + return true; + } + template <typename G> + bool op_subset_(const infty_pset<G>&, const infty_pset<G>&) + { + return true; + } + template <typename G, typename S> + bool op_subset_(const infty_pset<G>&, const Point_Set<S>&) + { + return false; + } - // Box L <= Box R. + // Point_Set L < Point_Set R + // ----------------------------- + + // Generic version. template <typename L, typename R> - bool op_leq_(const Box<L>& lhs, const Box<R>& rhs) + bool op_strict_subset_(const Point_Set<L>& lhs, const Point_Set<R>& rhs) { - for (unsigned i = 0; i < L::n; ++i) - { - if (lhs.pmin()[i] < rhs.pmin()[i] or lhs.pmax()[i] > rhs.pmax()[i]) - return false; - } - return true; + return op_subset_(lhs, rhs) and lhs.npoints() != rhs.npoints(); } - // Box L < Box R. + // Version for Boxes. template <typename L, typename R> - bool op_less_(const Box<L>& lhs, const Box<R>& rhs) + bool op_strict_subset_(const Box<L>& lhs, const Box<R>& rhs) { - return op_leq_(lhs, rhs) and lhs != rhs; + return op_subset_(lhs, rhs) and lhs != rhs; } - // Box L >= Box R. + // Versions with infinite set. - template <typename L, typename R> - bool op_geq_(const Box<L>& lhs, const Box<R>& rhs) - { - for (unsigned i = 0; i < L::n; ++i) + template <typename S, typename G> + bool op_strict_subset_(const Point_Set<S>&, const infty_pset<G>&) { - if (lhs.pmin()[i] > rhs.pmin()[i] or lhs.pmax()[i] < rhs.pmax()[i]) - return false; - } return true; } - // Box L > Box R. - - template <typename L, typename R> - bool op_greater_(const Box<L>& lhs, const Box<R>& rhs) + template <typename G> + bool op_strict_subset_(const infty_pset<G>&, const infty_pset<G>&) { - return op_geq_(lhs, rhs) and lhs != rhs; + return false; } + template <typename G, typename S> + bool op_strict_subset_(const infty_pset<G>&, const Point_Set<S>&) + { + return false; + } } // end of namespace oln::impl @@ -185,28 +242,42 @@ bool operator <= (const Point_Set<L>& lhs, const Point_Set<R>& rhs) { assert_same_grid_<L, R>::check(); - return impl::op_leq_(exact(lhs), exact(rhs)); + return impl::op_subset_(exact(lhs), exact(rhs)); } template <typename L, typename R> bool operator < (const Point_Set<L>& lhs, const Point_Set<R>& rhs) { assert_same_grid_<L, R>::check(); - return impl::op_less_(exact(lhs), exact(rhs)); + return impl::op_strict_subset_(exact(lhs), exact(rhs)); } template <typename L, typename R> bool operator >= (const Point_Set<L>& lhs, const Point_Set<R>& rhs) { assert_same_grid_<L, R>::check(); - return impl::op_geq_(exact(lhs), exact(rhs)); + return impl::op_subset_(exact(rhs), exact(lhs)); } template <typename L, typename R> bool operator > (const Point_Set<L>& lhs, const Point_Set<R>& rhs) { assert_same_grid_<L, R>::check(); - return impl::op_greater_(exact(lhs), exact(rhs)); + return impl::op_strict_subset_(exact(rhs), exact(lhs)); + } + + // Intersects. + + template <typename B1, typename B2> + bool intersects (const Box<B1>& box1, const Box<B2>& box2) + { + assert_same_grid_<B1, B2>::check(); + for (unsigned i = 0; i < B1::n; ++i) + { + if (box1.pmax()[i] < box2.pmin()[i] or box2.pmax()[i] < box1.pmin()[i]) + return false; + } + return true; } # endif // ! OLN_INCLUDE_ONLY Index: oln/core/gen/dpoints_piter.hh --- oln/core/gen/dpoints_piter.hh (revision 921) +++ oln/core/gen/dpoints_piter.hh (working copy) @@ -52,7 +52,7 @@ struct super_trait_< dpoints_fwd_piter_<P> > { typedef dpoints_fwd_piter_<P> current__; - typedef internal::iterator_on_points_base<current__> ret; + typedef internal::iterator_on_points_base_<current__> ret; }; @@ -66,7 +66,7 @@ // Forward point iterator class on a set of dpoints. template <typename P> - class dpoints_fwd_piter_ : public internal::iterator_on_points_base< dpoints_fwd_piter_<P> >, + class dpoints_fwd_piter_ : public internal::iterator_on_points_base_< dpoints_fwd_piter_<P> >, public internal::dpoints_fwd_piter_impl_<P> { public: @@ -99,7 +99,7 @@ struct super_trait_< dpoints_bkd_piter_<P> > { typedef dpoints_bkd_piter_<P> current__; - typedef internal::iterator_on_points_base<current__> ret; + typedef internal::iterator_on_points_base_<current__> ret; }; @@ -113,7 +113,7 @@ /// Backward point iterator class on a set of dpoints. template <typename P> - class dpoints_bkd_piter_ : public internal::iterator_on_points_base< dpoints_bkd_piter_<P> >, + class dpoints_bkd_piter_ : public internal::iterator_on_points_base_< dpoints_bkd_piter_<P> >, public internal::dpoints_bkd_piter_impl_<P> { public: Index: oln/core/gen/infty_pset.hh --- oln/core/gen/infty_pset.hh (revision 0) +++ oln/core/gen/infty_pset.hh (revision 0) @@ -0,0 +1,130 @@ +// Copyright (C) 2007 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_INFTY_PSET_HH +# define OLN_CORE_GEN_INFTY_PSET_HH + +# include <limits> +# include <oln/core/concept/grid.hh> +# include <oln/core/internal/f_grid_to_box.hh> +# include <oln/core/internal/point_set_base.hh> + + +namespace oln +{ + + // Fwd decl. + template <typename G> class infty_pset; + + + // Super type. + template <typename G> + struct super_trait_< infty_pset<G> > + { + typedef infty_pset<G> current__; + typedef internal::point_set_base_<current__> ret; + }; + + + // Virtual types. + template <typename G> + struct vtypes< infty_pset<G> > + { + typedef oln_f_grid_to_box(G) box; + typedef oln_point(box) point; + + // disabled! + typedef void fwd_piter; + typedef void bkd_piter; + }; + + + /// Infinite point set defined over a grid. + + template <typename G> + class infty_pset : public internal::point_set_base_< infty_pset<G> > + { + typedef infty_pset<G> current; + typedef internal::point_set_base_<current> super; + + public: + + stc_using(point); + stc_using(box); + + infty_pset(); + + unsigned impl_npoints() const; + bool impl_has(const point& p) const; + const box& impl_bbox() const; + + protected: + box b_; + + }; // end of class oln::infty_pset<G>. + + + +# ifndef OLN_INCLUDE_ONLY + + template <typename G> + infty_pset<G>::infty_pset() + { + typedef oln_coord(point) C; + point minus_infty, plus_infty; + minus_infty.set_all( std::numeric_limits<C>::min() ); + plus_infty. set_all( std::numeric_limits<C>::max() ); + this->b_ = init(from(minus_infty), to(plus_infty)); + } + + template <typename G> + unsigned + infty_pset<G>::impl_npoints() const + { + return std::numeric_limits<unsigned>::max(); + } + + template <typename G> + bool + infty_pset<G>::impl_has(const point&) const + { + return true; + } + + template <typename G> + const typename infty_pset<G>::box& + infty_pset<G>::impl_bbox() const + { + return this->b_; + } + +#endif // ! OLN_INCLUDE_ONLY + +} // end of namespace oln + + +#endif // ! OLN_CORE_GEN_INFTY_PSET_HH Index: oln/core/gen/pset.hh --- oln/core/gen/pset.hh (revision 921) +++ oln/core/gen/pset.hh (working copy) @@ -35,7 +35,7 @@ namespace oln { - /// Fwd decl. + // Fwd decl. template <typename P> class pset_; @@ -48,7 +48,7 @@ }; - /// Virtual types. + // Virtual types. template <typename P> struct vtypes< pset_<P> > { @@ -85,7 +85,7 @@ return *this; } -# endif +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/gen/single_value_image.hh --- oln/core/gen/single_value_image.hh (revision 921) +++ oln/core/gen/single_value_image.hh (working copy) @@ -30,7 +30,7 @@ # include <oln/core/internal/image_base.hh> # include <oln/core/internal/utils.hh> -# include <oln/core/internal/f_pset_plain.hh> +# include <oln/core/internal/f_pset_to_plain_image.hh> namespace oln @@ -56,7 +56,7 @@ typedef internal::pair<Ps, T> data; - typedef oln_f_pset_plain(Ps, T) plain; + typedef oln_f_pset_to_plain_image(Ps, T) plain; typedef single_value_image<Ps, pl::value> skeleton; }; @@ -79,7 +79,6 @@ typedef internal::image_base_<current> super; public: - stc_using(point); stc_using(rvalue); stc_using(data); @@ -119,7 +118,7 @@ single_value_image<Ps, T>::impl_owns_(const typename single_value_image<Ps, T>::point& p) const { assert(this->has_data()); - return this->data_->first.has(p); + return this->data_->first.has(p); // FIXME: or 'always true'? } template <typename Ps, typename T> Index: oln/core/gen/image_pset_piter.hh --- oln/core/gen/image_pset_piter.hh (revision 921) +++ oln/core/gen/image_pset_piter.hh (working copy) @@ -28,7 +28,7 @@ #ifndef OLN_CORE_GEN_IMAGE_PSET_PITER_HH # define OLN_CORE_GEN_IMAGE_PSET_PITER_HH -# include <oln/core/concept/iterator_on_points.hh> +# include <oln/core/internal/iterator_on_points_base.hh> # include <oln/core/concept/point_set.hh> # include <oln/core/concept/image.hh> @@ -36,52 +36,52 @@ namespace oln { - /// Fwd decls. + // Fwd decls. template <typename Ps> struct image_pset_fwd_piter_; template <typename Ps> struct image_pset_bkd_piter_; - /// Super types. + // Super types. template <typename Ps> struct super_trait_< image_pset_fwd_piter_<Ps> > { typedef image_pset_fwd_piter_<Ps> current__; - typedef Iterator_on_Points<current__> ret; + typedef internal::iterator_on_points_base_<current__> ret; }; template <typename Ps> struct super_trait_< image_pset_bkd_piter_<Ps> > { typedef image_pset_bkd_piter_<Ps> current__; - typedef Iterator_on_Points<current__> ret; + typedef internal::iterator_on_points_base_<current__> ret; }; - /// Virtual types. + // Virtual types. template <typename Ps> struct vtypes< image_pset_fwd_piter_<Ps> > { - typedef typename Ps::point point; + typedef oln_point(Ps) point; }; template <typename Ps> struct vtypes< image_pset_bkd_piter_<Ps> > { - typedef typename Ps::point point; + typedef oln_point(Ps) point; }; /// Class image_pset_fwd_piter_<Ps>. template <typename Ps> - class image_pset_fwd_piter_ : public Iterator_on_Points< image_pset_fwd_piter_<Ps> >, + class image_pset_fwd_piter_ : public internal::iterator_on_points_base_< image_pset_fwd_piter_<Ps> >, private mlc::assert_< mlc_is_a(Ps, Point_Set) > { typedef image_pset_fwd_piter_<Ps> current; - typedef Iterator_on_Points<current> super; + typedef internal::iterator_on_points_base_<current> super; public: stc_using(point); @@ -106,11 +106,11 @@ /// Class image_pset_bkd_piter_<Ps>. template <typename Ps> - class image_pset_bkd_piter_ : public Iterator_on_Points< image_pset_bkd_piter_<Ps> >, + class image_pset_bkd_piter_ : public internal::iterator_on_points_base_< image_pset_bkd_piter_<Ps> >, private mlc::assert_< mlc_is_a(Ps, Point_Set) > { typedef image_pset_fwd_piter_<Ps> current; - typedef Iterator_on_Points<current> super; + typedef internal::iterator_on_points_base_<current> super; public: stc_using(point); @@ -244,7 +244,7 @@ return i_.point_adr(); } -# endif +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/gen/safe_image.hh --- oln/core/gen/safe_image.hh (revision 921) +++ oln/core/gen/safe_image.hh (working copy) @@ -29,6 +29,7 @@ # define OLN_CORE_GEN_SAFE_IMAGE_HH # include <oln/core/internal/image_base.hh> +# include <oln/core/gen/infty_pset.hh> namespace oln @@ -47,6 +48,7 @@ typedef behavior::identity behavior; typedef internal::singleton<I> data; + typedef infty_pset< oln_grid(I) > pset; typedef safe_image< oln_plain(I) > plain; typedef safe_image< pl::rec<I> > skeleton; @@ -76,13 +78,16 @@ stc_using(lvalue); stc_using(value); stc_using(data); + stc_using(pset); stc_using(delegatee); safe_image(); safe_image(Mutable_Image<I>& ima); bool impl_owns_(const point& p) const; + const pset& impl_points() const; + // FIXME: Force this type to be read-only? rvalue impl_read(const point& p) const; lvalue impl_read_write(const point& p); void impl_write(const point& p, const value& v); @@ -126,6 +131,14 @@ } template <typename I> + const typename safe_image<I>::pset& + safe_image<I>::impl_points() const + { + static infty_pset<oln_grid(I)> infty_; + return infty_; + } + + template <typename I> typename safe_image<I>::rvalue safe_image<I>::impl_read(const typename safe_image<I>::point& p) const { Index: oln/core/internal/f_grid_to_plain_image.hh --- oln/core/internal/f_grid_to_plain_image.hh (revision 0) +++ oln/core/internal/f_grid_to_plain_image.hh (revision 0) @@ -0,0 +1,105 @@ +// Copyright (C) 2007 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_INTERNAL_F_GRID_TO_PLAIN_IMAGE_HH +# define OLN_CORE_INTERNAL_F_GRID_TO_PLAIN_IMAGE_HH + +# include <oln/core/concept/grid.hh> + + +#define oln_f_grid_to_plain_image(G, T) typename oln::internal::f_grid_to_plain_image_< G, T >::ret + + +namespace oln +{ + + /// \{ + /// Forward declarations. + + // Grid types. + + struct grid1d; + + struct grid2d; + struct grid2d_hex; + struct grid2d_tri; + + // FIXME: 3D... + + // Image types. + + template <typename T> class image1d; + template <typename T> class image2d; + + /// \} + + + + namespace internal + { + + // Fwd decl. + + template <typename G, typename T> struct f_grid_to_plain_image_; + + + /// \{ + /// Definitions. + + template <typename G, typename T> + struct grid_to_plain_image__; + + template <typename T> + struct grid_to_plain_image__< grid1d, T > + { + typedef image1d<T> ret; // FIXME: or image1d_b<T>? + }; + + template <typename T> + struct grid_to_plain_image__< grid2d, T > + { + typedef image2d<T> ret; // FIXME: or image2d_b<T>? + }; + + // FIXME: 2D hex/tri, 3D... + + /// \} + + + template <typename G, typename T> + struct f_grid_to_plain_image_ : private mlc::assert_< mlc_is_a(G, Grid) >, + public grid_to_plain_image__< G, T > + + { + }; + + } // end of namespace oln::internal + +} // end of namespace oln + + +#endif // ! OLN_CORE_INTERNAL_F_GRID_TO_PLAIN_IMAGE_HH Index: oln/core/internal/box.hh --- oln/core/internal/box.hh (revision 921) +++ oln/core/internal/box.hh (working copy) @@ -117,14 +117,14 @@ struct super_trait_< box_fwd_piter_<B> > { typedef box_fwd_piter_<B> current__; - typedef internal::iterator_on_points_base<current__> ret; + typedef internal::iterator_on_points_base_<current__> ret; }; template <typename B> struct super_trait_<box_bkd_piter_<B> > { typedef box_bkd_piter_<B> current__; - typedef internal::iterator_on_points_base<current__> ret; + typedef internal::iterator_on_points_base_<current__> ret; }; @@ -146,11 +146,11 @@ /// Class box_fwd_piter_<P>. template <typename B> - class box_fwd_piter_ : public internal::iterator_on_points_base< box_fwd_piter_<B> >, + class box_fwd_piter_ : public internal::iterator_on_points_base_< box_fwd_piter_<B> >, private mlc::assert_< mlc_is_a(B, Point_Set) > { typedef box_fwd_piter_<B> current; - typedef Iterator_on_Points<current> super; + typedef internal::iterator_on_points_base_<current> super; public: stc_using(point); @@ -172,11 +172,11 @@ /// Class box_bkd_piter_<B>. template <typename B> - class box_bkd_piter_ : public internal::iterator_on_points_base< box_bkd_piter_<B> >, + class box_bkd_piter_ : public internal::iterator_on_points_base_< box_bkd_piter_<B> >, private mlc::assert_< mlc_is_a(B, Point_Set) > { typedef box_bkd_piter_<B> current; - typedef Iterator_on_Points<current> super; + typedef internal::iterator_on_points_base_<current> super; public: stc_using(point); Index: oln/core/internal/f_grid_to_box.hh --- oln/core/internal/f_grid_to_box.hh (revision 0) +++ oln/core/internal/f_grid_to_box.hh (revision 0) @@ -0,0 +1,106 @@ +// Copyright (C) 2007 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_INTERNAL_F_GRID_TO_BOX_HH +# define OLN_CORE_INTERNAL_F_GRID_TO_BOX_HH + +# include <oln/core/concept/grid.hh> + + +#define oln_f_grid_to_box(G) typename oln::internal::f_grid_to_box_< G >::ret + + +namespace oln +{ + + /// \{ + /// Forward declarations. + + // Grid types. + + struct grid1d; + + struct grid2d; + struct grid2d_hex; + struct grid2d_tri; + + // FIXME: 3D... + + // Box types. + + struct box1d; + struct box2d; + template <typename P> class gen_box; + + /// \} + + + + namespace internal + { + + // Fwd decl. + + template <typename G> struct f_grid_to_; + + + /// \{ + /// Definitions. + + template <typename G> + struct grid_to_box__; + + template <> + struct grid_to_box__< grid1d > + { + typedef box1d ret; + }; + + template <> + struct grid_to_box__< grid2d > + { + typedef box2d ret; + }; + + // FIXME: 2D hex/tri, 3D... + + /// \} + + + template <typename G> + struct f_grid_to_box_ : private mlc::assert_< mlc_is_a(G, Grid) >, + public grid_to_box__< G > + + { + }; + + } // end of namespace oln::internal + +} // end of namespace oln + + +#endif // ! OLN_CORE_INTERNAL_F_GRID_TO_BOX_HH Index: oln/core/internal/point_set_std_based.hh --- oln/core/internal/point_set_std_based.hh (revision 921) +++ oln/core/internal/point_set_std_based.hh (working copy) @@ -176,14 +176,14 @@ struct super_trait_< pset_std_based_fwd_piter_<C> > { typedef pset_std_based_fwd_piter_<C> current__; - typedef internal::iterator_on_points_base<current__> ret; + typedef internal::iterator_on_points_base_<current__> ret; }; template <typename C> struct super_trait_< pset_std_based_bkd_piter_<C> > { typedef pset_std_based_bkd_piter_<C> current__; - typedef internal::iterator_on_points_base<current__> ret; + typedef internal::iterator_on_points_base_<current__> ret; }; @@ -206,10 +206,10 @@ // Class pset_std_based_fwd_piter_<C>. template <typename C> - class pset_std_based_fwd_piter_ : public internal::iterator_on_points_base< pset_std_based_fwd_piter_<C> > + class pset_std_based_fwd_piter_ : public internal::iterator_on_points_base_< pset_std_based_fwd_piter_<C> > { typedef pset_std_based_fwd_piter_<C> current; - typedef internal::iterator_on_points_base<current> super; + typedef internal::iterator_on_points_base_<current> super; public: stc_using(point); @@ -235,10 +235,10 @@ // Class pset_std_based_bkd_piter_<C>. template <typename C> - class pset_std_based_bkd_piter_ : public internal::iterator_on_points_base< pset_std_based_bkd_piter_<C> > + class pset_std_based_bkd_piter_ : public internal::iterator_on_points_base_< pset_std_based_bkd_piter_<C> > { typedef pset_std_based_bkd_piter_<C> current; - typedef internal::iterator_on_points_base<current> super; + typedef internal::iterator_on_points_base_<current> super; public: stc_using(point); @@ -374,7 +374,7 @@ } -# endif +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/internal/image_base.hh --- oln/core/internal/image_base.hh (revision 921) +++ oln/core/internal/image_base.hh (working copy) @@ -148,7 +148,7 @@ // Final. typedef stc::final< stc::is<Image> > category; - typedef stc::final <typename pset__::box> box; + typedef stc::final< oln_box(pset__) > box; typedef stc::final< oln_grid(point__) > grid; typedef stc::final< oln_dpoint(point__) > dpoint; typedef stc::final< oln_fwd_piter(pset__) > fwd_piter; Index: oln/core/internal/point_base.hh --- oln/core/internal/point_base.hh (revision 921) +++ oln/core/internal/point_base.hh (working copy) @@ -95,6 +95,7 @@ typedef xtd::vec<n, coord> vec_t; const vec_t& vec() const; vec_t& vec(); + void set_all(const coord& c); protected: point_base_(); @@ -148,15 +149,22 @@ } template <typename Exact> + void + point_base_<Exact>::set_all(const typename point_base_<Exact>::coord& c) + { + v_.set_all(c); + } + + template <typename Exact> point_base_<Exact>::point_base_() { } -# endif +# endif // ! OLN_INCLUDE_ONLY + } // end of namespace oln::internal - } // end of namespace oln::internal template <typename Exact> @@ -173,57 +181,10 @@ return ostr; } -# endif - - - -// /// internal::point_base_ + internal::dpoint_base_ -// template <typename P, typename D> -// struct case_ < xtd::op_plus, mlc::pair_<P,D>, -// oln::id::op_plus_pointnd_dpointnd > -// : where_< mlc::and_< mlc_is_a(P, internal::point_base_), -// mlc_is_a(D, internal::dpoint_base_) > > -// { -// typedef oln_vtype(P, coord) P_coord; -// typedef oln_vtype(D, coord) D_coord; -// typedef xtd_op_plus_trait(P_coord, D_coord) coord; -// typedef oln_vtype(P, dim) dim; -// typedef typename point_<mlc_value(dim), coord>::ret ret; -// }; - - -// /// internal::point_base_ - internal::dpoint_base_ -// template <typename P, typename D> -// struct case_ < xtd::op_minus, mlc::pair_<P,D>, -// oln::id::op_minus_pointnd_dpointnd > -// : where_< mlc::and_< mlc_is_a(P, internal::point_base_), -// mlc_is_a(D, internal::dpoint_base_) > > -// { -// typedef oln_vtype(P, coord) P_coord; -// typedef oln_vtype(D, coord) D_coord; -// typedef xtd_op_minus_trait(P_coord, D_coord) coord; -// typedef oln_vtype(P, dim) dim; -// typedef typename point_<mlc_value(dim), coord>::ret ret; -// }; - - -// /// internal::point_base_ - internal::point_base_ -// template <typename P1, typename P2> -// struct case_ < xtd::op_minus, mlc::pair_<P1,P2>, -// oln::id::op_minus_pointnd_pointnd > -// : where_< mlc::and_< mlc_is_a(P1, internal::point_base_), -// mlc_is_a(P2, internal::point_base_) > > -// { -// typedef oln_vtype(P1, coord) P1_coord; -// typedef oln_vtype(P2, coord) P2_coord; -// typedef xtd_op_minus_trait(P1_coord, P2_coord) coord; -// typedef oln_vtype(P1, dim) dim; -// typedef typename dpoint_<mlc_value(dim), coord>::ret ret; -// }; +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln - #endif // ! OLN_CORE_INTERNAL_POINT_BASE_HH Index: oln/core/internal/piter_adaptor.hh --- oln/core/internal/piter_adaptor.hh (revision 921) +++ oln/core/internal/piter_adaptor.hh (working copy) @@ -43,7 +43,7 @@ template <typename Exact> struct super_trait_< internal::piter_adaptor_<Exact> > { - typedef internal::iterator_on_points_base<Exact> ret; + typedef internal::iterator_on_points_base_<Exact> ret; }; @@ -65,9 +65,9 @@ // defined over other types of iterator on points. template <typename Exact> - class piter_adaptor_ : public internal::iterator_on_points_base<Exact> + class piter_adaptor_ : public internal::iterator_on_points_base_<Exact> { - typedef internal::iterator_on_points_base<Exact> super; + typedef internal::iterator_on_points_base_<Exact> super; public: stc_using(point); Index: oln/core/internal/f_pset_to_plain_image.hh --- oln/core/internal/f_pset_to_plain_image.hh (revision 921) +++ oln/core/internal/f_pset_to_plain_image.hh (working copy) @@ -25,41 +25,96 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLN_CORE_INTERNAL_F_PSET_PLAIN_HH -# define OLN_CORE_INTERNAL_F_PSET_PLAIN_HH +#ifndef OLN_CORE_INTERNAL_F_PSET_TO_PLAIN_IMAGE_HH +# define OLN_CORE_INTERNAL_F_PSET_TO_PLAIN_IMAGE_HH # include <oln/core/concept/point_set.hh> +# include <oln/core/internal/f_grid_to_plain_image.hh> -#define oln_f_pset_plain(Ps, T) typename oln::internal::f_pset_plain_< Ps, T >::ret +#define oln_f_pset_to_plain_image(Ps, T) typename oln::internal::f_pset_to_plain_image_< Ps, T >::ret namespace oln { - // Fwd decls. - struct grid2d; - template <typename P> class box_; + /// \{ + /// Forward declarations. + + // point set types + template <typename P> class gen_box; + class box1d; class box2d; - template <typename T> class image2d; - template <typename T> class image2d_b; + // FIXME: ... + + // gen + struct such_as; + struct restricted_to; + template <typename L, typename OpName, typename R> class op_; + + /// \} + namespace internal { - template <typename Gr, typename Ps, typename T> - struct f_pset_plain__; + // Fwd decl. + + template <typename Ps, typename T> struct f_pset_to_plain_image_; + + + /// \{ + /// Definitions. + + template <typename Ps, typename T> + struct pset_to_plain_image__ + { + typedef oln_f_grid_to_plain_image(oln_grid(Ps), T) I; + typedef op_< I, restricted_to, Ps > ret; + }; + + template <typename Ps, typename T> + struct pset_to_plain_image__< const Ps, T > + : + public pset_to_plain_image__< Ps, T > + { + }; + + template <typename T> + struct pset_to_plain_image__< box1d, T > + { + typedef oln_f_grid_to_plain_image(grid1d, T) ret; + }; template <typename T> - struct f_pset_plain__< grid2d, box2d, T > + struct pset_to_plain_image__< box2d, T > + { + typedef oln_f_grid_to_plain_image(grid2d, T) ret; + }; + + // ... + + template <typename P, typename T> + struct pset_to_plain_image__< gen_box<P>, T > { - typedef image2d/*_b*/<T> ret; // FIXME: this type is not always known! + typedef oln_f_grid_to_plain_image(oln_grid(P), T) ret; }; + template <typename S, typename F, typename T> + struct pset_to_plain_image__< op_<S, such_as, F>, T > + { + typedef op_<S, such_as, F> Ps; + typedef typename f_pset_to_plain_image_<S, T>::ret I; + typedef op_<I, restricted_to, Ps> ret; + }; + + /// \} + + template <typename Ps, typename T> - struct f_pset_plain_ : private mlc::assert_< mlc_is_a(Ps, Point_Set) >, - public f_pset_plain__< stc_type(Ps, grid), Ps, T > + struct f_pset_to_plain_image_ : private mlc::assert_< mlc_is_a(Ps, Point_Set) >, + public pset_to_plain_image__< Ps, T > { }; @@ -69,4 +124,4 @@ } // end of namespace oln -#endif // ! OLN_CORE_INTERNAL_F_PSET_PLAIN_HH +#endif // ! OLN_CORE_INTERNAL_F_PSET_TO_PLAIN_IMAGE_HH Index: oln/core/internal/iterator_on_points_base.hh --- oln/core/internal/iterator_on_points_base.hh (revision 921) +++ oln/core/internal/iterator_on_points_base.hh (working copy) @@ -30,60 +30,52 @@ # include <oln/core/concept/iterator_on_points.hh> + namespace oln { - // implementation - - - // Forward Declarations - - namespace internal { - template <typename Exact> - struct iterator_on_points_base; // FIXME: End with '_'! - } + // Fwd decl + namespace internal { template <typename Exact> struct iterator_on_points_base_; } // Super type - template <typename Exact> - struct super_trait_< internal::iterator_on_points_base<Exact> > + struct super_trait_< internal::iterator_on_points_base_<Exact> > { typedef Iterator_on_Points<Exact> ret; }; // Virtual types - template <typename Exact> - struct vtypes< internal::iterator_on_points_base<Exact> > + struct vtypes< internal::iterator_on_points_base_<Exact> > { + typedef stc::final< stc::is<Iterator_on_Points> > category; + typedef stc::abstract point; typedef stc_deferred(point) point__; - typedef stc::final<typename point__::grid> grid; - typedef stc::final<typename point__::coord> coord; - typedef stc::final<typename point__::dim> dim; - typedef stc::final<typename point__::dpoint> dpoint; + typedef stc::final< oln_grid(point__) > grid; + typedef stc::final< oln_coord(point__) > coord; + typedef stc::final< oln_dim(point__) > dim; + typedef stc::final< oln_dpoint(point__) > dpoint; }; namespace internal { - // iterator_on_points_base class template <typename Exact> - class iterator_on_points_base : public Iterator_on_Points<Exact> + class iterator_on_points_base_ : public Iterator_on_Points<Exact> { - protected: - iterator_on_points_base(); + iterator_on_points_base_(); }; # ifndef OLN_INCLUDE_ONLY template <typename Exact> - iterator_on_points_base<Exact>::iterator_on_points_base() + iterator_on_points_base_<Exact>::iterator_on_points_base_() { } Index: oln/draw/bresenham.hh --- oln/draw/bresenham.hh (revision 921) +++ oln/draw/bresenham.hh (working copy) @@ -29,10 +29,9 @@ # define OLN_DRAW_BRESENHAM_HH # include <oln/core/concept/image.hh> -# include <oln/core/gen/safe_image.hh> # include <oln/core/2d/line2d.hh> # include <oln/core/gen/single_value_image.hh> -// # include <oln/level/paste.hh> +# include <oln/level/paste.hh> @@ -45,7 +44,7 @@ // Fwd decl. template <typename I> - void bresenham(Mutable_Image<I>& input, + void bresenham(Mutable_Image<I>& in_out, const oln_point(I)& begin, const oln_point(I)& end, const oln_value(I)& value); @@ -56,18 +55,14 @@ { template <typename I> - void bresenham_(Mutable_Image<I>& input, + void bresenham_(Mutable_Image<I>& in_out, const oln_point(I)& begin, const oln_point(I)& end, const oln_value(I)& value) { - line2d l(begin, end); - safe_image<I> input_(input); -// // FIXME: rec pb. -// single_value_image<typename I::pset, oln_value(I)> tmp(input.points(), value); -// level::paste((tmp | l), input); - typename line2d::piter p(l); // FIXME: Generalize with an 'assign' routine... - for_all(p) - input_(p) = value; + line2d line(begin, end); + single_value_image<line2d, oln_value(I)> line_image(line, value); + level::paste(line_image, in_out); + // FIXME: Make it as simple as level::paste(line2d(begin, end) + value, in_out); } } // end of namespace oln::draw::impl @@ -75,11 +70,11 @@ // Facade. template <typename I> - void bresenham(Mutable_Image<I>& input, + void bresenham(Mutable_Image<I>& in_out, const oln_point(I)& begin, const oln_point(I)& end, const oln_value(I)& value) { - impl::bresenham_(exact(input), begin, end, value); + impl::bresenham_(exact(in_out), begin, end, value); } # endif // ! OLN_INCLUDE_ONLY