620: Add new facilities to access to components such as row, col, etc.

2006-10-11 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr> Add new facilities to access to components such as row, col, etc. * oln/core/spe/row.hh: New. * oln/core/spe/col.hh: New. * oln/core/spe/slice.hh: New. * oln/debug/print.hh (print): Use min_row, etc. (include): Update. * oln/core/typedefs.hh (index_comp_type): New. (row_comp_type, col_comp_type, slice_comp_type): New. (vec_type): New. * oln/core/abstract/iterator_on_points.hh (coord_type): New. * oln/core/abstract/point.hh (vec_type): New. (vec): New. * oln/core/1d/dpoint1d.hh (index_comp_type): New. * oln/core/1d/point1d.hh (index_comp_type): New. * oln/core/2d/dpoint2d.hh (row_comp_type, col_comp_type): New. * oln/core/2d/point2d.hh (row_comp_type, col_comp_type): New. * oln/core/3d/dpoint3d.hh (slice_comp_type, row_comp_type, col_comp_type): New. * oln/core/3d/point3d.hh (slice_comp_type, row_comp_type, col_comp_type): New. * oln/core/internal/point_nd.hh (vec_t): New. (vec): Rename as... (impl_vec): this. * oln/basics2d.hh (include): Update. * oln/basics3d.hh (include): Update. * oln/Makefile.am (nobase_oln_HEADERS): Update. Index: oln/debug/print.hh =================================================================== --- oln/debug/print.hh (revision 619) +++ oln/debug/print.hh (working copy) @@ -32,6 +32,8 @@ # include <oln/core/abstract/image.hh> # include <oln/core/abstract/image/hybrid/classical.hh> # include <oln/core/abstract/iterator.hh> +# include <oln/core/spe/row.hh> +# include <oln/core/spe/col.hh> # include <oln/core/2d/point2d.hh> @@ -50,6 +52,7 @@ template <typename I> void println(const abstract::image<I>& input, std::ostream& ostr = std::cout); + # ifndef OLN_INCLUDE_ONLY namespace impl @@ -82,9 +85,9 @@ void print(const abstract::classical_2d_image<I>& input, std::ostream& ostr) { - for (int row = input.pmin().row(); row <= input.pmax().row(); ++row) + for (int row = min_row(input); row <= max_row(input); ++row) { - for (int col = input.pmin().col(); col <= input.pmax().col(); ++col) + for (int col = min_col(input); col <= max_col(input); ++col) { point2d p(row, col); if (input.has(p)) Index: oln/core/typedefs.hh =================================================================== --- oln/core/typedefs.hh (revision 619) +++ oln/core/typedefs.hh (working copy) @@ -74,7 +74,12 @@ mlc_decl_typedef(grid_type); + mlc_decl_typedef(index_comp_type); + mlc_decl_typedef(row_comp_type); + mlc_decl_typedef(col_comp_type); + mlc_decl_typedef(slice_comp_type); + /*------------. | Iterators. | `------------*/ @@ -182,6 +187,7 @@ `-----------------*/ mlc_decl_typedef(dim_type); + mlc_decl_typedef(vec_type); /*------------------------------------. Index: oln/core/spe/row.hh =================================================================== --- oln/core/spe/row.hh (revision 0) +++ oln/core/spe/row.hh (revision 0) @@ -0,0 +1,155 @@ +// 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_SPE_ROW_HH +# define OLN_CORE_SPE_ROW_HH + +# include <mlc/value.hh> +# include <oln/core/abstract/point.hh> +# include <oln/core/abstract/dpoint.hh> +# include <oln/core/abstract/point_set.hh> +# include <oln/core/abstract/image.hh> +# include <oln/core/abstract/iterator_on_points.hh> + + +namespace oln +{ + + template <typename P> + oln_coord(P) row(const abstract::point<P>& p); + + template <typename P> + oln_coord(P)& row(abstract::point<P>& p); + + + template <typename D> + oln_coord(D) row(const abstract::dpoint<D>& dp); + + template <typename D> + oln_coord(D)& row(abstract::dpoint<D>& dp); + + + template <typename It> + oln_coord(It) row(const abstract::iterator_on_points<It>& it); + + + template <typename Ps> + oln_coord(Ps) min_row(const abstract::point_set_having_bbox<Ps>& ps); + + template <typename Ps> + oln_coord(Ps) max_row(const abstract::point_set_having_bbox<Ps>& ps); + + + template <typename I> + oln_coord(I) min_row(const abstract::image_having_bbox<I>& ima); + + template <typename I> + oln_coord(I) max_row(const abstract::image_having_bbox<I>& ima); + + + +# ifndef OLN_INCLUDE_ONLY + + // From point. + + template <typename P> + oln_coord(P) row(const abstract::point<P>& p) + { + typedef oln_type_of(P, row_comp) comp_t; + return p.vec()[mlc_value(comp_t)]; + } + + template <typename P> + oln_coord(P)& row(abstract::point<P>& p) + { + typedef oln_type_of(P, row_comp) comp_t; + return p.vec()[mlc_value(comp_t)]; + } + + // From dpoint. + + template <typename D> + oln_coord(D) row(const abstract::dpoint<D>& p) + { + typedef oln_type_of(D, row_comp) comp_t; + return p.vec()[mlc_value(comp_t)]; + } + + template <typename D> + oln_coord(D)& row(abstract::dpoint<D>& p) + { + typedef oln_type_of(D, row_comp) comp_t; + return p.vec()[mlc_value(comp_t)]; + } + + // From iterator. + + template <typename P> + oln_coord(P) row(const abstract::iterator_on_points<P>& it) + { + typedef oln_deduce_type_of(P, point, row_comp) comp_t; + return it.to_point().vec()[mlc_value(comp_t)]; + } + + // From point set. + + template <typename Ps> + oln_coord(Ps) min_row(const abstract::point_set_having_bbox<Ps>& ps) + { + typedef oln_deduce_type_of(Ps, point, row_comp) comp_t; + return ps.pmin().vec()[mlc_value(comp_t)]; + } + + template <typename Ps> + oln_coord(Ps) max_row(const abstract::point_set_having_bbox<Ps>& ps) + { + typedef oln_deduce_type_of(Ps, point, row_comp) comp_t; + return ps.pmax().vec()[mlc_value(comp_t)]; + } + + // From image. + + template <typename I> + oln_coord(I) min_row(const abstract::image_having_bbox<I>& ps) + { + typedef oln_deduce_type_of(I, point, row_comp) comp_t; + return ps.pmin().vec()[mlc_value(comp_t)]; + } + + template <typename I> + oln_coord(I) max_row(const abstract::image_having_bbox<I>& ps) + { + typedef oln_deduce_type_of(I, point, row_comp) comp_t; + return ps.pmax().vec()[mlc_value(comp_t)]; + } + +# endif + +} // end of namespace oln + + +#endif // ! OLN_CORE_SPE_ROW_HH Index: oln/core/spe/col.hh =================================================================== --- oln/core/spe/col.hh (revision 0) +++ oln/core/spe/col.hh (revision 0) @@ -0,0 +1,155 @@ +// 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_SPE_COL_HH +# define OLN_CORE_SPE_COL_HH + +# include <mlc/value.hh> +# include <oln/core/abstract/point.hh> +# include <oln/core/abstract/dpoint.hh> +# include <oln/core/abstract/point_set.hh> +# include <oln/core/abstract/image.hh> +# include <oln/core/abstract/iterator_on_points.hh> + + +namespace oln +{ + + template <typename P> + oln_coord(P) col(const abstract::point<P>& p); + + template <typename P> + oln_coord(P)& col(abstract::point<P>& p); + + + template <typename D> + oln_coord(D) col(const abstract::dpoint<D>& dp); + + template <typename D> + oln_coord(D)& col(abstract::dpoint<D>& dp); + + + template <typename It> + oln_coord(It) col(const abstract::iterator_on_points<It>& it); + + + template <typename Ps> + oln_coord(Ps) min_col(const abstract::point_set_having_bbox<Ps>& ps); + + template <typename Ps> + oln_coord(Ps) max_col(const abstract::point_set_having_bbox<Ps>& ps); + + + template <typename I> + oln_coord(I) min_col(const abstract::image_having_bbox<I>& ima); + + template <typename I> + oln_coord(I) max_col(const abstract::image_having_bbox<I>& ima); + + + +# ifndef OLN_INCLUDE_ONLY + + // From point. + + template <typename P> + oln_coord(P) col(const abstract::point<P>& p) + { + typedef oln_type_of(P, col_comp) comp_t; + return p.vec()[mlc_value(comp_t)]; + } + + template <typename P> + oln_coord(P)& col(abstract::point<P>& p) + { + typedef oln_type_of(P, col_comp) comp_t; + return p.vec()[mlc_value(comp_t)]; + } + + // From dpoint. + + template <typename D> + oln_coord(D) col(const abstract::dpoint<D>& p) + { + typedef oln_type_of(D, col_comp) comp_t; + return p.vec()[mlc_value(comp_t)]; + } + + template <typename D> + oln_coord(D)& col(abstract::dpoint<D>& p) + { + typedef oln_type_of(D, col_comp) comp_t; + return p.vec()[mlc_value(comp_t)]; + } + + // From iterator. + + template <typename P> + oln_coord(P) col(const abstract::iterator_on_points<P>& it) + { + typedef oln_deduce_type_of(P, point, col_comp) comp_t; + return it.to_point().vec()[mlc_value(comp_t)]; + } + + // From point set. + + template <typename Ps> + oln_coord(Ps) min_col(const abstract::point_set_having_bbox<Ps>& ps) + { + typedef oln_deduce_type_of(Ps, point, col_comp) comp_t; + return ps.pmin().vec()[mlc_value(comp_t)]; + } + + template <typename Ps> + oln_coord(Ps) max_col(const abstract::point_set_having_bbox<Ps>& ps) + { + typedef oln_deduce_type_of(Ps, point, col_comp) comp_t; + return ps.pmax().vec()[mlc_value(comp_t)]; + } + + // From image. + + template <typename I> + oln_coord(I) min_col(const abstract::image_having_bbox<I>& ps) + { + typedef oln_deduce_type_of(I, point, col_comp) comp_t; + return ps.pmin().vec()[mlc_value(comp_t)]; + } + + template <typename I> + oln_coord(I) max_col(const abstract::image_having_bbox<I>& ps) + { + typedef oln_deduce_type_of(I, point, col_comp) comp_t; + return ps.pmax().vec()[mlc_value(comp_t)]; + } + +# endif + +} // end of namespace oln + + +#endif // ! OLN_CORE_SPE_COL_HH Index: oln/core/spe/slice.hh =================================================================== --- oln/core/spe/slice.hh (revision 0) +++ oln/core/spe/slice.hh (revision 0) @@ -0,0 +1,155 @@ +// 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_SPE_SLICE_HH +# define OLN_CORE_SPE_SLICE_HH + +# include <mlc/value.hh> +# include <oln/core/abstract/point.hh> +# include <oln/core/abstract/dpoint.hh> +# include <oln/core/abstract/point_set.hh> +# include <oln/core/abstract/image.hh> +# include <oln/core/abstract/iterator_on_points.hh> + + +namespace oln +{ + + template <typename P> + oln_coord(P) slice(const abstract::point<P>& p); + + template <typename P> + oln_coord(P)& slice(abstract::point<P>& p); + + + template <typename D> + oln_coord(D) slice(const abstract::dpoint<D>& dp); + + template <typename D> + oln_coord(D)& slice(abstract::dpoint<D>& dp); + + + template <typename It> + oln_coord(It) slice(const abstract::iterator_on_points<It>& it); + + + template <typename Ps> + oln_coord(Ps) min_slice(const abstract::point_set_having_bbox<Ps>& ps); + + template <typename Ps> + oln_coord(Ps) max_slice(const abstract::point_set_having_bbox<Ps>& ps); + + + template <typename I> + oln_coord(I) min_slice(const abstract::image_having_bbox<I>& ima); + + template <typename I> + oln_coord(I) max_slice(const abstract::image_having_bbox<I>& ima); + + + +# ifndef OLN_INCLUDE_ONLY + + // From point. + + template <typename P> + oln_coord(P) slice(const abstract::point<P>& p) + { + typedef oln_type_of(P, slice_comp) comp_t; + return p.vec()[mlc_value(comp_t)]; + } + + template <typename P> + oln_coord(P)& slice(abstract::point<P>& p) + { + typedef oln_type_of(P, slice_comp) comp_t; + return p.vec()[mlc_value(comp_t)]; + } + + // From dpoint. + + template <typename D> + oln_coord(D) slice(const abstract::dpoint<D>& p) + { + typedef oln_type_of(D, slice_comp) comp_t; + return p.vec()[mlc_value(comp_t)]; + } + + template <typename D> + oln_coord(D)& slice(abstract::dpoint<D>& p) + { + typedef oln_type_of(D, slice_comp) comp_t; + return p.vec()[mlc_value(comp_t)]; + } + + // From iterator. + + template <typename P> + oln_coord(P) slice(const abstract::iterator_on_points<P>& it) + { + typedef oln_deduce_type_of(P, point, slice_comp) comp_t; + return it.to_point().vec()[mlc_value(comp_t)]; + } + + // From point set. + + template <typename Ps> + oln_coord(Ps) min_slice(const abstract::point_set_having_bbox<Ps>& ps) + { + typedef oln_deduce_type_of(Ps, point, slice_comp) comp_t; + return ps.pmin().vec()[mlc_value(comp_t)]; + } + + template <typename Ps> + oln_coord(Ps) max_slice(const abstract::point_set_having_bbox<Ps>& ps) + { + typedef oln_deduce_type_of(Ps, point, slice_comp) comp_t; + return ps.pmax().vec()[mlc_value(comp_t)]; + } + + // From image. + + template <typename I> + oln_coord(I) min_slice(const abstract::image_having_bbox<I>& ps) + { + typedef oln_deduce_type_of(I, point, slice_comp) comp_t; + return ps.pmin().vec()[mlc_value(comp_t)]; + } + + template <typename I> + oln_coord(I) max_slice(const abstract::image_having_bbox<I>& ps) + { + typedef oln_deduce_type_of(I, point, slice_comp) comp_t; + return ps.pmax().vec()[mlc_value(comp_t)]; + } + +# endif + +} // end of namespace oln + + +#endif // ! OLN_CORE_SPE_SLICE_HH Index: oln/core/abstract/iterator_on_points.hh =================================================================== --- oln/core/abstract/iterator_on_points.hh (revision 619) +++ oln/core/abstract/iterator_on_points.hh (working copy) @@ -56,7 +56,14 @@ typedef mlc::undefined point_type; }; + template <typename E> + struct single_vtype< abstract::iterator_on_points<E>, typedef_::coord_type > + { + typedef oln_type_of(E, point) point_t; + typedef oln_type_of(point_t, coord) ret; + }; + namespace abstract { Index: oln/core/abstract/point.hh =================================================================== --- oln/core/abstract/point.hh (revision 619) +++ oln/core/abstract/point.hh (working copy) @@ -60,9 +60,18 @@ typedef mlc::undefined dpoint_type; typedef mlc::undefined coord_type; typedef mlc::undefined dim_type; + typedef mlc::undefined vec_type; }; + template <typename E> + struct single_vtype< abstract::point<E>, typedef_::vec_type > + { + typedef oln_type_of(E, coord) coord_t; + typedef oln_type_of(E, dim) dim_t; + typedef xtd::vec<mlc_value(dim_t), coord_t> ret; + }; + namespace abstract { @@ -72,6 +81,7 @@ public oln::type { typedef oln_type_of(E, dpoint) dpoint_t; + typedef oln_type_of(E, vec) vec_t; public: @@ -197,6 +207,10 @@ /// \} + const vec_t& vec() const; + vec_t& vec(); + + ~point() { // FIXME: See code below. @@ -388,8 +402,23 @@ } template <typename E> + const typename point<E>::vec_t& + point<E>::vec() const + { + return this->exact().impl_vec(); + } + + template <typename E> + typename point<E>::vec_t& + point<E>::vec() + { + return this->exact().impl_vec(); + } + + template <typename E> point<E>::point() - {} + { + } // template <typename E> // point<E>::~point() Index: oln/core/1d/dpoint1d.hh =================================================================== --- oln/core/1d/dpoint1d.hh (revision 619) +++ oln/core/1d/dpoint1d.hh (working copy) @@ -56,6 +56,8 @@ typedef point1d point_type; typedef C coord_type; typedef mlc::uint_<1> dim_type; + + typedef mlc::uint_<0> index_comp_type; }; Index: oln/core/1d/point1d.hh =================================================================== --- oln/core/1d/point1d.hh (revision 619) +++ oln/core/1d/point1d.hh (working copy) @@ -65,6 +65,8 @@ typedef dpoint1d dpoint_type; typedef C coord_type; typedef mlc::uint_<1> dim_type; + + typedef mlc::uint_<0> index_comp_type; }; Index: oln/core/2d/dpoint2d.hh =================================================================== --- oln/core/2d/dpoint2d.hh (revision 619) +++ oln/core/2d/dpoint2d.hh (working copy) @@ -56,6 +56,9 @@ typedef point2d point_type; typedef C coord_type; typedef mlc::uint_<2> dim_type; + + typedef mlc::uint_<0> row_comp_type; + typedef mlc::uint_<1> col_comp_type; }; Index: oln/core/2d/point2d.hh =================================================================== --- oln/core/2d/point2d.hh (revision 619) +++ oln/core/2d/point2d.hh (working copy) @@ -65,6 +65,9 @@ typedef dpoint2d dpoint_type; typedef C coord_type; typedef mlc::uint_<2> dim_type; + + typedef mlc::uint_<0> row_comp_type; + typedef mlc::uint_<1> col_comp_type; }; Index: oln/core/3d/dpoint3d.hh =================================================================== --- oln/core/3d/dpoint3d.hh (revision 619) +++ oln/core/3d/dpoint3d.hh (working copy) @@ -56,6 +56,10 @@ typedef point3d point_type; typedef C coord_type; typedef mlc::uint_<3> dim_type; + + typedef mlc::uint_<0> slice_comp_type; + typedef mlc::uint_<1> row_comp_type; + typedef mlc::uint_<2> col_comp_type; }; Index: oln/core/3d/point3d.hh =================================================================== --- oln/core/3d/point3d.hh (revision 619) +++ oln/core/3d/point3d.hh (working copy) @@ -65,6 +65,10 @@ typedef dpoint3d dpoint_type; typedef C coord_type; typedef mlc::uint_<3> dim_type; + + typedef mlc::uint_<0> slice_comp_type; + typedef mlc::uint_<1> row_comp_type; + typedef mlc::uint_<2> col_comp_type; }; Index: oln/core/internal/point_nd.hh =================================================================== --- oln/core/internal/point_nd.hh (revision 619) +++ oln/core/internal/point_nd.hh (working copy) @@ -74,12 +74,11 @@ typedef oln_type_of(E, dim) dim; typedef oln_type_of(E, coord) coord_t; typedef oln_type_of(E, dpoint) dpoint_t; + typedef oln_type_of(E, vec) vec_t; - public: enum { n = mlc_value(dim) }; - typedef xtd::vec<n,coord_t> vec_t; coord_t operator[](unsigned i) const; coord_t& operator[](unsigned i); @@ -98,7 +97,8 @@ dpoint_t impl_minus(const self_t& rhs) const; - const vec_t& vec() const; + const vec_t& impl_vec() const; + vec_t& impl_vec(); protected: @@ -185,12 +185,19 @@ template <typename E> const typename point_nd<E>::vec_t& - point_nd<E>::vec() const + point_nd<E>::impl_vec() const { return v_; } template <typename E> + typename point_nd<E>::vec_t& + point_nd<E>::impl_vec() + { + return v_; + } + + template <typename E> point_nd<E>::point_nd() {} Index: oln/basics2d.hh =================================================================== --- oln/basics2d.hh (revision 619) +++ oln/basics2d.hh (working copy) @@ -54,5 +54,8 @@ # include <oln/core/fwd_piter.hh> +# include <oln/core/spe/row.hh> +# include <oln/core/spe/col.hh> + #endif // ! OLN_BASICS2D_HH Index: oln/Makefile.am =================================================================== --- oln/Makefile.am (revision 619) +++ oln/Makefile.am (working copy) @@ -114,6 +114,10 @@ core/gen/topo_lbbox.hh \ core/gen/window.hh \ \ + core/spe/col.hh \ + core/spe/row.hh \ + core/spe/slice.hh \ + \ core/internal/bbox_bkd_piter.hh \ core/internal/bbox_fwd_piter.hh \ core/internal/dpoint_nd.hh \ Index: oln/basics3d.hh =================================================================== --- oln/basics3d.hh (revision 619) +++ oln/basics3d.hh (working copy) @@ -51,5 +51,9 @@ # include <oln/core/3d/image3d.hh> +# include <oln/core/spe/slice.hh> +# include <oln/core/spe/row.hh> +# include <oln/core/spe/col.hh> + #endif // ! OLN_BASICS3D_HH
participants (1)
-
Thierry GERAUD