630: Add image accessors with indices.

2006-10-12 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr> Add image accessors with indices. * tests/at.cc: New. * oln/core/automatic/image1d.hh: New. * oln/core/automatic/image2d.hh: New. * oln/core/automatic/image3d.hh: New. * tests/Makefile.am (check_PROGRAMS): Add 'at'. Move io_pnm to get consistent with SOURCES list. (at_SOURCES): New. * oln/core/typedefs.hh (oln_psite, oln_psite_): New. * oln/core/automatic/image_being_mutable.hh (lvalue_t, psite_t): Remove; use oln_lvalue and oln_psite instead. (impl_op_readwrite): Update sig. * oln/core/abstract/image/dimension/1d.hh (at): New const method. (at, has_at): New methods that should be elsewhere; this is a hack. (image1d): Move ctor impl inside guards. * oln/core/abstract/image/dimension/2d.hh (at): New const method. (at, has_at): New methods that should be elsewhere; this is a hack. (image2d): Move ctor impl inside guards. * oln/core/abstract/image/dimension/3d.hh (at): New const method. (at, has_at): New methods that should be elsewhere; this is a hack. (image3d): Move ctor impl inside guards. * oln/core/abstract/point.hh (include): Add xtd/vec.hh. * oln/core/1d/neighb1d.hh (mk_c2): Update to mimic neighb2d. * oln/core/2d/image2d.hh (impl_at): New. * oln/core/3d/image3d.hh (impl_at): New. * oln/Makefile.am (nobase_oln_HEADERS): Update. * oln/morpher/internal/image_extension.hh (delegate): New mutable version. Index: tests/at.cc =================================================================== --- tests/at.cc (revision 0) +++ tests/at.cc (revision 0) @@ -0,0 +1,51 @@ +// 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. + +#include <cassert> +// FIXME: Don't include oln/basics2d.hh, which is too big. +// (Fix.) +#include <oln/basics1d.hh> +#include <oln/basics2d.hh> +#include <oln/morpher/add_neighborhood.hh> + + +int +main() +{ + using namespace oln; + + image2d<int> ima(1, 1); + point2d p(0, 0); + + (ima + c4).at(0, 0) = 51; + assert(ima(p) == 51); + + image1d<int> sig(1); + point1d i(0); + (sig + c2).at(0) = 51; + assert(sig(i) == 51); +} Index: tests/Makefile.am =================================================================== --- tests/Makefile.am (revision 629) +++ tests/Makefile.am (working copy) @@ -28,12 +28,15 @@ npoints \ window2d \ \ + at \ + \ + io_pnm \ + \ identity_morpher \ add_neighborhood_morpher \ morphers \ \ - fill \ - io_pnm + fill # Images and auxiliary structures. dpoint2d_SOURCES = dpoint2d.cc @@ -46,6 +49,9 @@ npoints_SOURCES = npoints.cc window2d_SOURCES = window2d.cc +# Methods. +at_SOURCES = at.cc + # I/O. io_pnm_SOURCES = io_pnm.cc Index: oln/core/typedefs.hh =================================================================== --- oln/core/typedefs.hh (revision 629) +++ oln/core/typedefs.hh (working copy) @@ -219,6 +219,9 @@ # define oln_point(T) oln_type_of(T, point) # define oln_point_(T) oln_type_of_(T, point) +# define oln_psite(T) oln_type_of(T, psite) +# define oln_psite_(T) oln_type_of_(T, psite) + # define oln_dpoint(T) oln_type_of(T, dpoint) # define oln_dpoint_(T) oln_type_of_(T, dpoint) Index: oln/core/automatic/image1d.hh =================================================================== --- oln/core/automatic/image1d.hh (revision 0) +++ oln/core/automatic/image1d.hh (revision 0) @@ -0,0 +1,151 @@ +// 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_AUTOMATIC_IMAGE1D_HH +# define OLN_CORE_AUTOMATIC_IMAGE1D_HH + +# include <oln/core/automatic/impl.hh> +# include <oln/morpher/tags.hh> +# include <oln/core/1d/point1d.hh> + + +namespace oln +{ + // Forward declaration. + namespace abstract + { + template <typename E> class image1d; + + } // end of namespace oln::abstract + + + namespace automatic + { + + + /// Default implementation corresponding to the interface + /// oln::abstract::image1d. + template <typename E, typename tag> + class set_impl<abstract::image1d, tag, E> : + public virtual stc::any__simple<E> + { + public: + + oln_rvalue(E) impl_at(const oln_coord(E)& index) const; + + // FIXME: Hack. + oln_lvalue(E)& impl_at(const oln_coord(E)& index); + bool impl_has_at(const oln_coord(E)& index) const; + + }; + + + + /// Implementation corresponding to the interface + /// oln::abstract::image1d for an identity morpher. + template <typename E> + class set_impl<abstract::image1d, morpher::tag::identity, E> : + public virtual stc::any__simple<E> + { + public: + + oln_rvalue(E) impl_at(const oln_coord(E)& index) const; + + // FIXME: Hack. + oln_lvalue(E)& impl_at(const oln_coord(E)& index); + bool impl_has_at(const oln_coord(E)& index) const; + + }; + + + +# ifndef OLN_INCLUDE_ONLY + + + // Default is: 1. convert (index) -> p then 2. call operator()(p). + + template <typename E, typename tag> + oln_rvalue(E) + set_impl<abstract::image1d, tag, E> + ::impl_at(const oln_coord(E)& index) const + { + point1d tmp(index); + return this->exact().operator()(tmp); + } + + template <typename E, typename tag> + oln_lvalue(E)& + set_impl<abstract::image1d, tag, E> + ::impl_at(const oln_coord(E)& index) + { + point1d tmp(index); + return this->exact().operator()(tmp); + } + + template <typename E, typename tag> + bool + set_impl<abstract::image1d, tag, E> + ::impl_has_at(const oln_coord(E)& index) const + { + point1d tmp(index); + return this->exact().has(tmp); + } + + + // For morphers: delegate. + + template <typename E> + oln_rvalue(E) + set_impl<abstract::image1d, morpher::tag::identity, E> + ::impl_at(const oln_coord(E)& index) const + { + return this->exact().delegate().at(index); + } + + template <typename E> + oln_lvalue(E)& + set_impl<abstract::image1d, morpher::tag::identity, E> + ::impl_at(const oln_coord(E)& index) + { + return this->exact().delegate().at(index); + } + + template <typename E> + bool + set_impl<abstract::image1d, morpher::tag::identity, E> + ::impl_has_at(const oln_coord(E)& index) const + { + return this->exact().delegate().has_at(index); + } + +# endif + + } // end of namespace oln::automatic + +} // end of namespace oln + +#endif // ! OLN_CORE_AUTOMATIC_IMAGE1D_HH Index: oln/core/automatic/image2d.hh =================================================================== --- oln/core/automatic/image2d.hh (revision 0) +++ oln/core/automatic/image2d.hh (revision 0) @@ -0,0 +1,151 @@ +// 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_AUTOMATIC_IMAGE2D_HH +# define OLN_CORE_AUTOMATIC_IMAGE2D_HH + +# include <oln/core/automatic/impl.hh> +# include <oln/morpher/tags.hh> +# include <oln/core/2d/point2d.hh> + + +namespace oln +{ + // Forward declaration. + namespace abstract + { + template <typename E> class image2d; + + } // end of namespace oln::abstract + + + namespace automatic + { + + + /// Default implementation corresponding to the interface + /// oln::abstract::image2d. + template <typename E, typename tag> + class set_impl<abstract::image2d, tag, E> : + public virtual stc::any__simple<E> + { + public: + + oln_rvalue(E) impl_at(const oln_coord(E)& row, const oln_coord(E)& col) const; + + // FIXME: Hack. + oln_lvalue(E)& impl_at(const oln_coord(E)& row, const oln_coord(E)& col); + bool impl_has_at(const oln_coord(E)& row, const oln_coord(E)& col) const; + + }; + + + + /// Implementation corresponding to the interface + /// oln::abstract::image2d for an identity morpher. + template <typename E> + class set_impl<abstract::image2d, morpher::tag::identity, E> : + public virtual stc::any__simple<E> + { + public: + + oln_rvalue(E) impl_at(const oln_coord(E)& row, const oln_coord(E)& col) const; + + // FIXME: Hack. + oln_lvalue(E)& impl_at(const oln_coord(E)& row, const oln_coord(E)& col); + bool impl_has_at(const oln_coord(E)& row, const oln_coord(E)& col) const; + + }; + + + +# ifndef OLN_INCLUDE_ONLY + + + // Default is: 1. convert (row, col) -> p then 2. call operator()(p). + + template <typename E, typename tag> + oln_rvalue(E) + set_impl<abstract::image2d, tag, E> + ::impl_at(const oln_coord(E)& row, const oln_coord(E)& col) const + { + point2d tmp(row, col); + return this->exact().operator()(tmp); + } + + template <typename E, typename tag> + oln_lvalue(E)& + set_impl<abstract::image2d, tag, E> + ::impl_at(const oln_coord(E)& row, const oln_coord(E)& col) + { + point2d tmp(row, col); + return this->exact().operator()(tmp); + } + + template <typename E, typename tag> + bool + set_impl<abstract::image2d, tag, E> + ::impl_has_at(const oln_coord(E)& row, const oln_coord(E)& col) const + { + point2d tmp(row, col); + return this->exact().has(tmp); + } + + + // For morphers: delegate. + + template <typename E> + oln_rvalue(E) + set_impl<abstract::image2d, morpher::tag::identity, E> + ::impl_at(const oln_coord(E)& row, const oln_coord(E)& col) const + { + return this->exact().delegate().at(row, col); + } + + template <typename E> + oln_lvalue(E)& + set_impl<abstract::image2d, morpher::tag::identity, E> + ::impl_at(const oln_coord(E)& row, const oln_coord(E)& col) + { + return this->exact().delegate().at(row, col); + } + + template <typename E> + bool + set_impl<abstract::image2d, morpher::tag::identity, E> + ::impl_has_at(const oln_coord(E)& row, const oln_coord(E)& col) const + { + return this->exact().delegate().has_at(row, col); + } + +# endif + + } // end of namespace oln::automatic + +} // end of namespace oln + +#endif // ! OLN_CORE_AUTOMATIC_IMAGE2D_HH Index: oln/core/automatic/image3d.hh =================================================================== --- oln/core/automatic/image3d.hh (revision 0) +++ oln/core/automatic/image3d.hh (revision 0) @@ -0,0 +1,175 @@ +// 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_AUTOMATIC_IMAGE3D_HH +# define OLN_CORE_AUTOMATIC_IMAGE3D_HH + +# include <oln/core/automatic/impl.hh> +# include <oln/morpher/tags.hh> +# include <oln/core/3d/point3d.hh> + + +namespace oln +{ + // Forward declaration. + namespace abstract + { + template <typename E> class image3d; + + } // end of namespace oln::abstract + + + namespace automatic + { + + + /// Default implementation corresponding to the interface + /// oln::abstract::image3d. + template <typename E, typename tag> + class set_impl<abstract::image3d, tag, E> : + public virtual stc::any__simple<E> + { + public: + + oln_rvalue(E) impl_at(const oln_coord(E)& slice, + const oln_coord(E)& row, + const oln_coord(E)& col) const; + + // FIXME: Hack. + oln_lvalue(E)& impl_at(const oln_coord(E)& slice, + const oln_coord(E)& row, + const oln_coord(E)& col); + bool impl_has_at(const oln_coord(E)& slice, + const oln_coord(E)& row, + const oln_coord(E)& col) const; + + }; + + + + /// Implementation corresponding to the interface + /// oln::abstract::image3d for an identity morpher. + template <typename E> + class set_impl<abstract::image3d, morpher::tag::identity, E> : + public virtual stc::any__simple<E> + { + public: + + oln_rvalue(E) impl_at(const oln_coord(E)& slice, + const oln_coord(E)& row, + const oln_coord(E)& col) const; + + // FIXME: Hack. + oln_lvalue(E)& impl_at(const oln_coord(E)& slice, + const oln_coord(E)& row, + const oln_coord(E)& col); + bool impl_has_at(const oln_coord(E)& slice, + const oln_coord(E)& row, + const oln_coord(E)& col) const; + + }; + + + +# ifndef OLN_INCLUDE_ONLY + + + // Default is: 1. convert (slice, row, col) -> p then 2. call operator()(p). + + template <typename E, typename tag> + oln_rvalue(E) + set_impl<abstract::image3d, tag, E> + ::impl_at(const oln_coord(E)& slice, + const oln_coord(E)& row, + const oln_coord(E)& col) const + { + point3d tmp(slice, row, col); + return this->exact().operator()(tmp); + } + + template <typename E, typename tag> + oln_lvalue(E)& + set_impl<abstract::image3d, tag, E> + ::impl_at(const oln_coord(E)& slice, + const oln_coord(E)& row, + const oln_coord(E)& col) + { + point3d tmp(slice, row, col); + return this->exact().operator()(tmp); + } + + template <typename E, typename tag> + bool + set_impl<abstract::image3d, tag, E> + ::impl_has_at(const oln_coord(E)& slice, + const oln_coord(E)& row, + const oln_coord(E)& col) const + { + point3d tmp(slice, row, col); + return this->exact().has(tmp); + } + + + // For morphers: delegate. + + template <typename E> + oln_rvalue(E) + set_impl<abstract::image3d, morpher::tag::identity, E> + ::impl_at(const oln_coord(E)& slice, + const oln_coord(E)& row, + const oln_coord(E)& col) const + { + return this->exact().delegate().at(slice, row, col); + } + + template <typename E> + oln_lvalue(E)& + set_impl<abstract::image3d, morpher::tag::identity, E> + ::impl_at(const oln_coord(E)& slice, + const oln_coord(E)& row, + const oln_coord(E)& col) + { + return this->exact().delegate().at(slice, row, col); + } + + template <typename E> + bool + set_impl<abstract::image3d, morpher::tag::identity, E> + ::impl_has_at(const oln_coord(E)& slice, + const oln_coord(E)& row, + const oln_coord(E)& col) const + { + return this->exact().delegate().has_at(slice, row, col); + } + +# endif + + } // end of namespace oln::automatic + +} // end of namespace oln + +#endif // ! OLN_CORE_AUTOMATIC_IMAGE3D_HH Index: oln/core/automatic/image_being_mutable.hh =================================================================== --- oln/core/automatic/image_being_mutable.hh (revision 629) +++ oln/core/automatic/image_being_mutable.hh (working copy) @@ -50,20 +50,17 @@ class set_impl<abstract::image_being_mutable, morpher::tag::identity, E> : public virtual stc::any__simple<E> { - private: - typedef oln_type_of(E, lvalue) lvalue_t; - typedef oln_type_of(E, psite) psite_t; - public: /// Accessor delegation. - lvalue_t& impl_op_readwrite(const psite_t& p) const; + oln_lvalue(E)& impl_op_readwrite(const oln_psite(E)& p); }; # ifndef OLN_INCLUDE_ONLY template <typename E> - typename set_impl<abstract::image_being_mutable, morpher::tag::identity, E>::lvalue_t& - set_impl<abstract::image_being_mutable, morpher::tag::identity, E>::impl_op_readwrite(const typename set_impl<abstract::image_being_mutable, morpher::tag::identity, E>::psite_t& p) const + oln_lvalue(E)& + set_impl<abstract::image_being_mutable, morpher::tag::identity, E> + ::impl_op_readwrite(const oln_psite(E)& p) { return this->exact().delegate().operator()(p); } Index: oln/core/abstract/image/dimension/1d.hh =================================================================== --- oln/core/abstract/image/dimension/1d.hh (revision 629) +++ oln/core/abstract/image/dimension/1d.hh (working copy) @@ -29,6 +29,7 @@ # define OLN_CORE_ABSTRACT_IMAGE_DIMENSION_1D_HH # include <oln/core/abstract/image.hh> +# include <oln/core/automatic/image1d.hh> namespace oln @@ -43,11 +44,50 @@ public virtual image<E>, public automatic::get_impl<image1d, E> { + public: + + oln_rvalue(E) at(const oln_coord(E)& index) const; + + // FIXME: Hack (should be elsewhere)! + oln_lvalue(E)& at(const oln_coord(E)& index); + bool has_at(const oln_coord(E)& index) const; + protected: /// Constructor (protected, empty). - image1d() {} + image1d(); }; + +# ifndef OLN_INCLUDE_ONLY + + template <typename E> + image1d<E>::image1d() + { + } + + template <typename E> + oln_rvalue(E) + image1d<E>::at(const oln_coord(E)& index) const + { + return this->exact().impl_at(index); + } + + template <typename E> + oln_lvalue(E)& + image1d<E>::at(const oln_coord(E)& index) + { + return this->exact().impl_at(index); + } + + template <typename E> + bool + image1d<E>::has_at(const oln_coord(E)& index) const + { + return this->exact().impl_has_at(index); + } + +# endif + } // end of namespace oln::abstract } // end of namespace oln Index: oln/core/abstract/image/dimension/2d.hh =================================================================== --- oln/core/abstract/image/dimension/2d.hh (revision 629) +++ oln/core/abstract/image/dimension/2d.hh (working copy) @@ -29,6 +29,7 @@ # define OLN_CORE_ABSTRACT_IMAGE_DIMENSION_2D_HH # include <oln/core/abstract/image.hh> +# include <oln/core/automatic/image2d.hh> namespace oln @@ -43,6 +44,14 @@ public virtual image<E>, public automatic::get_impl<image2d, E> { + public: + + oln_rvalue(E) at(const oln_coord(E)& row, const oln_coord(E)& col) const; + + // FIXME: Hack (should be elsewhere)! + oln_lvalue(E)& at(const oln_coord(E)& row, const oln_coord(E)& col); + bool has_at(const oln_coord(E)& row, const oln_coord(E)& col) const; + protected: /// Constructor (protected, empty). image2d(); @@ -56,6 +65,27 @@ { } + template <typename E> + oln_rvalue(E) + image2d<E>::at(const oln_coord(E)& row, const oln_coord(E)& col) const + { + return this->exact().impl_at(row, col); + } + + template <typename E> + oln_lvalue(E)& + image2d<E>::at(const oln_coord(E)& row, const oln_coord(E)& col) + { + return this->exact().impl_at(row, col); + } + + template <typename E> + bool + image2d<E>::has_at(const oln_coord(E)& row, const oln_coord(E)& col) const + { + return this->exact().impl_has_at(row, col); + } + # endif } // end of namespace oln::abstract Index: oln/core/abstract/image/dimension/3d.hh =================================================================== --- oln/core/abstract/image/dimension/3d.hh (revision 629) +++ oln/core/abstract/image/dimension/3d.hh (working copy) @@ -29,6 +29,7 @@ # define OLN_CORE_ABSTRACT_IMAGE_DIMENSION_3D_HH # include <oln/core/abstract/image.hh> +# include <oln/core/automatic/image3d.hh> namespace oln @@ -43,10 +44,61 @@ public virtual image<E>, public automatic::get_impl<image3d, E> { + public: + + oln_rvalue(E) at(const oln_coord(E)& slice, + const oln_coord(E)& row, + const oln_coord(E)& col) const; + + // FIXME: Hack (should be elsewhere)! + oln_lvalue(E)& at(const oln_coord(E)& slice, + const oln_coord(E)& row, + const oln_coord(E)& col); + bool has_at(const oln_coord(E)& slice, + const oln_coord(E)& row, + const oln_coord(E)& col) const; + protected: /// Constructor (protected, empty). - image3d() {} + image3d(); }; + + +# ifndef OLN_INCLUDE_ONLY + + template <typename E> + image3d<E>::image3d() + { + } + + template <typename E> + oln_rvalue(E) + image3d<E>::at(const oln_coord(E)& slice, + const oln_coord(E)& row, + const oln_coord(E)& col) const + { + return this->exact().impl_at(slice, row, col); + } + + template <typename E> + oln_lvalue(E)& + image3d<E>::at(const oln_coord(E)& slice, + const oln_coord(E)& row, + const oln_coord(E)& col) + { + return this->exact().impl_at(slice, row, col); + } + + template <typename E> + bool + image3d<E>::has_at(const oln_coord(E)& slice, + const oln_coord(E)& row, + const oln_coord(E)& col) const + { + return this->exact().impl_has_at(slice, row, col); + } + +# endif } // end of namespace oln::abstract Index: oln/core/abstract/point.hh =================================================================== --- oln/core/abstract/point.hh (revision 629) +++ oln/core/abstract/point.hh (working copy) @@ -29,6 +29,8 @@ #ifndef OLN_CORE_ABSTRACT_POINT_HH # define OLN_CORE_ABSTRACT_POINT_HH +# include <xtd/vec.hh> + # include <oln/core/typedefs.hh> # include <oln/core/traits_id.hh> # include <oln/core/abstract/dpoint.hh> Index: oln/core/1d/neighb1d.hh =================================================================== --- oln/core/1d/neighb1d.hh (revision 629) +++ oln/core/1d/neighb1d.hh (working copy) @@ -46,13 +46,9 @@ neighb1d mk_c2() { - static bool flower = true; - static neighb1d the_; - if (flower) - { - the_.add(dpoint1d(1)); - flower = false; - } + neighb1d the_; + the_ + .add(dpoint1d(1)); return the_; } @@ -67,7 +63,7 @@ # ifndef OLN_INCLUDE_ONLY - const neighb1d c2 = internal::mk_c2(); + const neighb1d c2 = internal::mk_c2(); # endif Index: oln/core/2d/image2d.hh =================================================================== --- oln/core/2d/image2d.hh (revision 629) +++ oln/core/2d/image2d.hh (working copy) @@ -93,7 +93,10 @@ const topo2d& impl_topo() const; T impl_op_read(const point2d& p) const; + T impl_at(int row, int col) const; + T& impl_op_readwrite(const point2d& p); + T& impl_at(int row, int col); T* adr_at(int row, int col); const T* adr_at(int row, int col) const; @@ -128,12 +131,14 @@ { } + template <typename T> const topo2d& image2d<T>::impl_topo() const { return topo_; } + template <typename T> T image2d<T>::impl_op_read(const point2d& p) const { @@ -143,6 +148,14 @@ } template <typename T> + T image2d<T>::impl_at(int row, int col) const + { + precondition(data_->has(row, col)); + return data_->operator()(row, col); + } + + + template <typename T> T& image2d<T>::impl_op_readwrite(const point2d& p) { precondition(data_ != 0); @@ -151,6 +164,14 @@ } template <typename T> + T& image2d<T>::impl_at(int row, int col) + { + precondition(data_->has(row, col)); + return data_->operator()(row, col); + } + + + template <typename T> T* image2d<T>::adr_at(int row, int col) { precondition(data_ != 0); Index: oln/core/3d/image3d.hh =================================================================== --- oln/core/3d/image3d.hh (revision 629) +++ oln/core/3d/image3d.hh (working copy) @@ -94,7 +94,10 @@ const topo3d& impl_topo() const; T impl_op_read(const point3d& p) const; + T impl_at(int slice, int row, int col) const; + T& impl_op_readwrite(const point3d& p); + T& impl_at(int slice, int row, int col); T* adr_at(int slice, int row, int col); const T* adr_at(int slice, int row, int col) const; @@ -106,7 +109,6 @@ }; - # ifndef OLN_INCLUDE_ONLY template <typename T> @@ -137,13 +139,16 @@ } template <typename T> - const topo3d& image3d<T>::impl_topo() const + const topo3d& + image3d<T>::impl_topo() const { return topo_; } + template <typename T> - T image3d<T>::impl_op_read(const point3d& p) const + T + image3d<T>::impl_op_read(const point3d& p) const { precondition(data_ != 0); precondition(topo_.has_large(p)); @@ -151,14 +156,33 @@ } template <typename T> - T& image3d<T>::impl_op_readwrite(const point3d& p) + T + image3d<T>::impl_at(int slice, int row, int col) const { + precondition(data_->has(slice, row, col)); + return data_->operator()(slice, row, col); + } + + + template <typename T> + T& + image3d<T>::impl_op_readwrite(const point3d& p) + { precondition(data_ != 0); precondition(topo_.has_large(p)); return data_->operator()(p.slice(), p.row(), p.col()); } template <typename T> + T& + image3d<T>::impl_at(int slice, int row, int col) + { + precondition(data_->has(slice, row, col)); + return data_->operator()(slice, row, col); + } + + + template <typename T> T* image3d<T>::adr_at(int slice, int row, int col) { precondition(data_ != 0); Index: oln/Makefile.am =================================================================== --- oln/Makefile.am (revision 629) +++ oln/Makefile.am (working copy) @@ -91,6 +91,9 @@ core/abstract/window.hh \ \ core/automatic/image.hh \ + core/automatic/image1d.hh \ + core/automatic/image2d.hh \ + core/automatic/image3d.hh \ core/automatic/image_being_mutable.hh \ core/automatic/image_being_random_accessible.hh \ core/automatic/image_having_neighborhood.hh \ Index: oln/morpher/internal/image_extension.hh =================================================================== --- oln/morpher/internal/image_extension.hh (revision 629) +++ oln/morpher/internal/image_extension.hh (working copy) @@ -86,7 +86,9 @@ // FIXME: Handle the constness. image_extension(const Image& image); + const Image& delegate() const; + Image& delegate(); protected: Image image_; @@ -109,6 +111,13 @@ return image_; } + template <typename Image, typename Exact> + Image& + image_extension<Image, Exact>::delegate() + { + return image_; + } + # endif } // end of namespace oln::morpher::internal
participants (1)
-
Thierry GERAUD