
https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Add type of ''image restricted_to a subset''. * tests/core/subset.cc: New. * tests/core/Makefile.am: Update. * oln/debug/println.hh: New. * oln/core/internal/op_image_restricted_to_pset.hh: New. * oln/debug/print.hh: Fix copyright. * oln/core/concept/image.hh (bbox): Provide a final impl. * oln/core/rle/rle_image.hh, * oln/core/concept/image_identity.hh, * oln/core/sparse/sparse_image.hh, * oln/core/1d/image1d.hh * oln/core/1d/image1d_b.hh * oln/core/2d/image2d.hh * oln/core/2d/image2d_b.hh: Update. * oln/core/concept/neighborhood.hh (oln_decl_op_plus): Move to... * oln/core/gen/neighb.hh: ...this file. * oln/core/gen/op.hh (oln_decl_op_restricted_to, restricted_to): New. * oln/core/internal/point_set_base.hh (category): New. * oln/core/internal/op_image_plus_nbh.hh: Add static assert. * oln/core/internal/image_base.hh (include): Add op_image_restricted_to_pset.hh. oln/core/1d/image1d.hh | 9 - oln/core/1d/image1d_b.hh | 8 oln/core/2d/image2d.hh | 9 - oln/core/2d/image2d_b.hh | 8 oln/core/concept/image.hh | 9 - oln/core/concept/image_identity.hh | 8 oln/core/concept/neighborhood.hh | 4 oln/core/gen/neighb.hh | 6 oln/core/gen/op.hh | 2 oln/core/internal/image_base.hh | 15 + oln/core/internal/op_image_plus_nbh.hh | 5 oln/core/internal/op_image_restricted_to_pset.hh | 200 +++++++++++++++++++++++ oln/core/internal/point_set_base.hh | 2 oln/core/rle/rle_image.hh | 9 - oln/core/sparse/sparse_image.hh | 8 oln/debug/print.hh | 2 oln/debug/println.hh | 61 +++++++ tests/core/Makefile.am | 2 tests/core/subset.cc | 43 ++++ 19 files changed, 340 insertions(+), 70 deletions(-) Index: tests/core/Makefile.am --- tests/core/Makefile.am (revision 876) +++ tests/core/Makefile.am (working copy) @@ -26,6 +26,7 @@ image2d \ neighb2d \ npoints \ + subset \ window2d \ at @@ -36,6 +37,7 @@ image2d_SOURCES = image2d.cc neighb2d_SOURCES = neighb2d.cc npoints_SOURCES = npoints.cc +subset_SOURCES = subset.cc window2d_SOURCES = window2d.cc # Methods. Index: tests/core/subset.cc --- tests/core/subset.cc (revision 0) +++ tests/core/subset.cc (revision 0) @@ -0,0 +1,43 @@ +// 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. + +#include <cassert> +#include <oln/core/2d/image2d.hh> +#include <oln/core/2d/neighb2d.hh> + + +int main() +{ + using namespace oln; + + image2d<int> ima(5, 5); + + point2d p(1,1), q(3,3); + box2d b = init(from(p), to(q)); + + assert((ima | b).points().npoints() = 9); // FIXME: looks weird +} Index: oln/debug/println.hh --- oln/debug/println.hh (revision 0) +++ oln/debug/println.hh (revision 0) @@ -0,0 +1,61 @@ +// 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_DEBUG_PRINTLN_HH +# define OLN_DEBUG_PRINTLN_HH + +# include <oln/debug/print.hh> + + +namespace oln +{ + + namespace debug + { + + template <typename I> + void println(const Image<I>& input, std::ostream& ostr = std::cout); + + +# ifndef OLN_INCLUDE_ONLY + + template <typename I> + void println(const Image<I>& input, std::ostream& ostr) + { + print(exact(input), ostr); + ostr << std::endl; + } + +# endif // ! OLN_INCLUDE_ONLY + + + } // end of namespace oln::debug + +} // end of namespace oln + + +#endif // ! OLN_DEBUG_PRINTLN_HH Index: oln/debug/print.hh --- oln/debug/print.hh (revision 876) +++ oln/debug/print.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2006 EPITA Research and Development Laboratory +// Copyright (C) 2006, 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 Index: oln/core/rle/rle_image.hh --- oln/core/rle/rle_image.hh (revision 876) +++ oln/core/rle/rle_image.hh (working copy) @@ -80,7 +80,6 @@ ** ** method: ** pset impl_points() const : return image pset - ** box impl_bbox() const : return image bbox ** bool impl_has(const point& p) const : rle_image has p? ** bool impl_owns_(const psite& p) const : same has impl_has ** void insert(const point& p, unsigned len, value val) : insert a new range on the image @@ -105,7 +104,6 @@ rle_image(); pset impl_points() const; - box impl_bbox() const; bool impl_has(const point& p) const; bool impl_owns_(const psite& p) const; void insert(const point& p, unsigned len, value val); @@ -130,13 +128,6 @@ } template <typename P, typename T> - typename rle_image<P, T>::box - rle_image<P, T>::impl_bbox() const - { - return this->data_->first.bbox(); - } - - template <typename P, typename T> bool rle_image<P, T>::impl_has(const typename rle_image<P, T>::point& p) const { Index: oln/core/concept/image.hh --- oln/core/concept/image.hh (revision 876) +++ oln/core/concept/image.hh (working copy) @@ -134,9 +134,11 @@ bool owns_(const psite& p) const; rvalue operator()(const psite& p) const; - box bbox() const; pset points() const; + // With final impl: + box bbox() const; + protected: Image(); }; @@ -357,7 +359,7 @@ typename Image<Exact>::box Image<Exact>::bbox() const { - return exact(this)->impl_bbox(); + return this->points().bbox(); // Final impl. } template <typename Exact> @@ -551,8 +553,7 @@ { } -# endif - +# endif // OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/concept/neighborhood.hh --- oln/core/concept/neighborhood.hh (revision 876) +++ oln/core/concept/neighborhood.hh (working copy) @@ -29,8 +29,6 @@ # define OLN_CORE_CONCEPT_NEIGHBORHOOD_HH # include <oln/core/equipment.hh> -# include <oln/core/internal/op_image_plus_nbh.hh> - @@ -52,8 +50,6 @@ }; // end of oln::Neighborhood<Exact> - oln_decl_op_plus(Image, Neighborhood); - # ifndef OLN_INCLUDE_ONLY Index: oln/core/concept/image_identity.hh --- oln/core/concept/image_identity.hh (revision 876) +++ oln/core/concept/image_identity.hh (working copy) @@ -54,7 +54,6 @@ bool impl_owns_(const psite& p) const; rvalue impl_read(const psite& p) const; - box impl_bbox() const; pset impl_points() const; }; @@ -193,13 +192,6 @@ } template <typename Exact> - typename set_impl< Image, behavior::identity, Exact >::box - set_impl< Image, behavior::identity, Exact >::impl_bbox() const - { - return exact(this)->image().bbox(); - } - - template <typename Exact> typename set_impl< Image, behavior::identity, Exact >::pset set_impl< Image, behavior::identity, Exact >::impl_points() const { Index: oln/core/sparse/sparse_image.hh --- oln/core/sparse/sparse_image.hh (revision 876) +++ oln/core/sparse/sparse_image.hh (working copy) @@ -83,7 +83,6 @@ sparse_image(); pset impl_points() const; - box impl_bbox() const; bool impl_has(const point& p) const; bool impl_owns_(const psite& p) const; void insert(const point& p, unsigned len, const std::vector<value>& val); @@ -109,13 +108,6 @@ } template <typename P, typename T> - typename sparse_image<P, T>::box - sparse_image<P, T>::impl_bbox() const - { - return this->data_->first.bbox(); - } - - template <typename P, typename T> bool sparse_image<P, T>::impl_has(const typename sparse_image<P, T>::point& p) const { Index: oln/core/1d/image1d.hh --- oln/core/1d/image1d.hh (revision 876) +++ oln/core/1d/image1d.hh (working copy) @@ -97,7 +97,6 @@ std::size_t impl_npoints() const; - box1d impl_bbox() const; box1d impl_points() const; }; @@ -176,19 +175,13 @@ } template <typename T> - box1d image1d<T>::impl_bbox() const + box1d image1d<T>::impl_points() const { assert(this->has_data()); box1d b(this->data_->imin(), this->data_->imax()); return b; } - template <typename T> - box1d image1d<T>::impl_points() const - { - return this->bbox(); - } - # endif Index: oln/core/1d/image1d_b.hh --- oln/core/1d/image1d_b.hh (revision 876) +++ oln/core/1d/image1d_b.hh (working copy) @@ -105,7 +105,6 @@ std::size_t impl_npoints() const; - box1d impl_bbox() const; box1d impl_points() const; unsigned border() const; @@ -184,13 +183,6 @@ } template <typename T> - box1d image1d_b<T>::impl_bbox() const - { - assert(this->has_data()); - return this->data_->third; - } - - template <typename T> box1d image1d_b<T>::impl_points() const { assert(this->has_data()); Index: oln/core/2d/image2d.hh --- oln/core/2d/image2d.hh (revision 876) +++ oln/core/2d/image2d.hh (working copy) @@ -100,7 +100,6 @@ std::size_t impl_npoints() const; - box2d impl_bbox() const; box2d impl_points() const; }; @@ -203,7 +202,7 @@ } template <typename T> - box2d image2d<T>::impl_bbox() const + box2d image2d<T>::impl_points() const { assert(this->has_data()); point2d @@ -213,12 +212,6 @@ return b; } - template <typename T> - box2d image2d<T>::impl_points() const - { - return this->bbox(); - } - template <typename T, typename D> bool init_(image2d<T>* this_, const D& dat) { Index: oln/core/2d/image2d_b.hh --- oln/core/2d/image2d_b.hh (revision 876) +++ oln/core/2d/image2d_b.hh (working copy) @@ -146,7 +146,6 @@ std::size_t impl_npoints() const; - box2d impl_bbox() const; box2d impl_points() const; unsigned border() const; @@ -244,13 +243,6 @@ } template <typename T> - box2d image2d_b<T>::impl_bbox() const - { - assert(this->has_data()); - return this->data_->box; - } - - template <typename T> box2d image2d_b<T>::impl_points() const { assert(this->has_data()); Index: oln/core/gen/neighb.hh --- oln/core/gen/neighb.hh (revision 876) +++ oln/core/gen/neighb.hh (working copy) @@ -31,12 +31,18 @@ # include <oln/core/internal/dpoints_impl.hh> # include <oln/core/internal/neighborhood_base.hh> +# include <oln/core/internal/op_image_plus_nbh.hh> namespace oln { + // Op. + oln_decl_op_plus(Image, Neighborhood); + + + // Fwd decl. template <typename Dp> class neighb_; Index: oln/core/gen/op.hh --- oln/core/gen/op.hh (revision 876) +++ oln/core/gen/op.hh (working copy) @@ -73,6 +73,7 @@ # define oln_decl_op_plus(Lconcept, Rconcept) oln_decl_op_(plus, Lconcept, +, Rconcept) # define oln_decl_op_such_as(Lconcept, Rconcept) oln_decl_op_(such_as, Lconcept, |, Rconcept) +# define oln_decl_op_restricted_to(Lconcept, Rconcept) oln_decl_op_( restricted_to, Lconcept, |, Rconcept) // ... @@ -104,6 +105,7 @@ struct plus; struct such_as; + struct restricted_to; /// \} Index: oln/core/internal/point_set_base.hh --- oln/core/internal/point_set_base.hh (revision 876) +++ oln/core/internal/point_set_base.hh (working copy) @@ -58,6 +58,8 @@ typedef stc_deferred(point) point__; typedef stc_deferred(fwd_piter) fwd_piter__; + typedef stc::final< stc::is<Point_Set> > category; + typedef stc::final< box_<point__> > box; typedef stc::final<stc_type(point__, grid)> grid; typedef stc::final<fwd_piter__> piter; Index: oln/core/internal/op_image_restricted_to_pset.hh --- oln/core/internal/op_image_restricted_to_pset.hh (revision 0) +++ oln/core/internal/op_image_restricted_to_pset.hh (revision 0) @@ -0,0 +1,200 @@ +// 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_OP_IMAGE_RESTRICTED_TO_PSET_HH +# define OLN_CORE_INTERNAL_OP_IMAGE_RESTRICTED_TO_PSET_HH + +# include <oln/core/internal/image_base.hh> +# include <oln/core/concept/point_set.hh> +# include <oln/core/gen/op.hh> + + +namespace oln +{ + +# define current \ + special_op_< stc::is<Image>, I, restricted_to, stc::is<Point_Set>, S > + + +// /// Fwd decls. +// template <typename Exact> struct Image; +// template <typename Exact> struct Point_Set; + + + /// Super type. + template <typename I, typename S> + struct super_trait_< internal::current > + { + typedef internal::image_extension_< op_<I, restricted_to, S> > ret; + }; + + + /// Virtual types. + template <typename I, typename S> + struct vtypes< internal::current > + { + typedef op_<I, restricted_to, S> Exact; + typedef stc_type(I, point) point__; + + typedef I delegatee; + typedef internal::pair<I,S> data; + + typedef S pset; + + typedef op_<oln_plain(I), restricted_to, S> plain; + typedef op_<pl::rec<I>, restricted_to, S> skeleton; + }; + + + namespace internal + { + + /// Implementation class the result of "Image I | Point_Set S". + + template <typename I, typename S> + class special_op_< stc::is<Image>, I, restricted_to, stc::is<Point_Set>, S > + : + public internal::image_extension_< op_<I, restricted_to, S> > + { + typedef internal::image_extension_< op_<I, restricted_to, S> > super; + public: + stc_using(pset); + stc_using(box); + stc_using(data); + stc_using(delegatee); + + delegatee& impl_image(); + const delegatee& impl_image() const; + + pset impl_points() const; + + protected: + special_op_(); + special_op_(I& ima, S& subset); + }; + + } // end of namespace oln::internal + + + // init + + template <typename I, typename S, typename D> + bool init_(internal::current* target, const D& dat); + + template <typename S, typename I> + bool init(Point_Set<S>& target, + with_t, + const internal::current& dat); + + template <typename I, typename S> + bool init(Image<I>& target, + with_t, + const internal::current& dat); + + + +# ifndef OLN_INCLUDE_ONLY + + namespace internal + { + + template <typename I, typename S> + current::special_op_() + { + } + + template <typename I, typename S> + current::special_op_(I& ima, S& subset) + { + this->data_ = new data(ima, subset); + } + + template <typename I, typename S> + typename current::delegatee& + current::impl_image() + { + assert(this->has_data()); + return this->data_->first; + } + + template <typename I, typename S> + const typename current::delegatee& + current::impl_image() const + { + assert(this->has_data()); + return this->data_->first; + } + + template <typename I, typename S> + typename current::pset + current::impl_points() const + { + assert(this->has_data()); + return this->data_->second; + } + + } // end of namespace oln::internal + + + // init + + template <typename I, typename S, typename D> + bool init_(internal::current* this_, const D& dat) + { + precondition(not this_->has_data()); + this_->data__() = new typename op_<I, restricted_to, S>::data; + bool image_ok = init(this_->data__()->first, with, dat); + bool subset_ok = init(this_->data__()->second, with, dat); + postcondition(image_ok); + postcondition(subset_ok); + return image_ok and subset_ok; + } + + template <typename S, typename I> + bool init_(Point_Set<S>* this_, + const internal::current& data) + { + *this_ = data.points(); + return true; + } + + template <typename I, typename S> + bool init(Image<I>* this_, + const internal::current& data) + { + *this_ = data.image(); + return true; + } + +# endif // OLN_INCLUDE_ONLY + +# undef current + +} // end of namespace oln + + +#endif // ! OLN_CORE_INTERNAL_OP_IMAGE_RESTRICTED_TO_PSET_HH Index: oln/core/internal/op_image_plus_nbh.hh --- oln/core/internal/op_image_plus_nbh.hh (revision 876) +++ oln/core/internal/op_image_plus_nbh.hh (working copy) @@ -84,7 +84,8 @@ template <typename I, typename N> class special_op_< stc::is<Image>, I, plus, stc::is<Neighborhood>, N > : - public internal::image_extension_< op_<I, plus, N> > + public internal::image_extension_< op_<I, plus, N> >, + private mlc::assert_< mlc_is_not_a(I, Image_with_Nbh) > // FIXME: Add err msg. { typedef internal::image_extension_< op_<I, plus, N> > super; public: @@ -167,8 +168,6 @@ // init - // FIXME: N is nbh? - template <typename I, typename N, typename D> bool init_(internal::current* this_, const D& dat) { Index: oln/core/internal/image_base.hh --- oln/core/internal/image_base.hh (revision 876) +++ oln/core/internal/image_base.hh (working copy) @@ -461,8 +461,21 @@ } // end of namespace oln -// FIXME: Bad! + + +/// \{ +/// FIXME: Bad! + # include <oln/core/internal/f_ch_value.hh> +# include <oln/core/internal/op_image_restricted_to_pset.hh> + +namespace oln +{ + oln_decl_op_restricted_to(Image, Point_Set); + +} // end of namespace oln + +/// \}