
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Add the sub_image_if image type. * doc/tutorial/examples/sub_image_if.cc: New. * mln/core/image/sub_image_if.hh: New. * mln/fun/p2b/has.hh: New. Misc. * mln/core/image/translate_image.hh (lvalue): Use the recent macro. (operator()): Likewise. * mln/core/image/t_image.hh: Likewise. * mln/core/internal/image_base.hh: Fix doc. Layout; group value-related material. (hook_data_, id_): Move impl into guards. * mln/core/internal/image_morpher.hh: Add some doc. * mln/core/internal/image_domain_morpher.hh: Fix doc. (lvalue): Use the recent macro. (values): Layout; group value-related material. doc/tutorial/examples/sub_image_if.cc | 101 ++++++++++++ mln/core/image/sub_image_if.hh | 246 ++++++++++++++++++++++++++++++ mln/core/image/t_image.hh | 8 mln/core/image/translate_image.hh | 8 mln/core/internal/image_base.hh | 49 ++++- mln/core/internal/image_domain_morpher.hh | 16 + mln/core/internal/image_morpher.hh | 7 mln/fun/p2b/has.hh | 134 ++++++++++++++++ 8 files changed, 543 insertions(+), 26 deletions(-) Index: doc/tutorial/examples/sub_image_if.cc --- doc/tutorial/examples/sub_image_if.cc (revision 0) +++ doc/tutorial/examples/sub_image_if.cc (revision 0) @@ -0,0 +1,101 @@ +# include <mln/core/image/image2d.hh> +# include <mln/core/image/sub_image_if.hh> + +# include <mln/core/image/sub_image.hh> +# include <mln/core/image/image_if.hh> + +# include <mln/pw/all.hh> +# include <mln/core/var.hh> + +# include <mln/core/alias/neighb2d.hh> +# include <mln/labeling/blobs.hh> +# include <mln/geom/bbox.hh> + +# include <mln/level/fill.hh> +# include <mln/debug/println.hh> + + +template <typename I> +void foo(const I& input) +{ + using namespace mln; + + std::cout << std::endl << "foo!" << std::endl << std::endl; + + typedef mln_ch_value(I, float) O; + +// p_if< box2d, +// fun::p2b::has< image_if< image2d<float>, F> > +// > + +// p_if< box2d, +// fun::p2b::has< image_if< image2d_int_u8, F > > +// > + + + + // type of " mln_ch_value(I, float) " + +// sub_image_if< I = image_if< image2d<float>, F > +// S = box2d > +// +// where: +// +// F = fun::neq_p2b_expr_< pw::value_< image2d<value::int_u<8u> > >, +// pw::cst_<unsigned int> > +// >, + + O output; + initialize(output, input); + level::fill(output, 9); + + std::cout << geom::bbox(output) << std::endl; + debug::println(output); +} + + + +int main() +{ + using namespace mln; + using value::int_u8; + + bool vals[6][5] = { + {0, 1, 1, 0, 0}, + {0, 1, 1, 0, 0}, + {0, 0, 0, 0, 0}, + {1, 1, 0, 1, 0}, + {1, 0, 1, 1, 1}, + {1, 0, 0, 0, 0} + }; + image2d<bool> ima = make::image2d(vals); + debug::println(ima); + + int_u8 nlabels; + image2d<int_u8> lab = labeling::blobs(ima, c4(), nlabels); + debug::println(lab); + + mln_VAR(lab_0, lab | (pw::value(lab) != pw::cst(0u))); + debug::println(lab_0); + +// box2d b = geom::bbox(lab | (pw::value(lab) == pw::cst(3u))); +// std::cout << b << std::endl; + + +// { +// mln_VAR(temp, lab | (pw::value(lab) == pw::cst(3u))); +// std::cout << temp.un_if().bbox() << std::endl; +// debug::println(temp); +// std::cout << geom::bbox(lab | (pw::value(lab) == pw::cst(3u))) << std::endl; + +// foo(temp); +// } + + box2d bb = make::box2d(2,1, 5,4); + debug::println(lab / bb); + + mln_VAR(lab_3, lab_0 / bb); + debug::println(lab_3); + + foo(lab_3); +} Index: mln/core/image/translate_image.hh --- mln/core/image/translate_image.hh (revision 2193) +++ mln/core/image/translate_image.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 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 @@ -105,7 +105,7 @@ typedef line_piter_<mln_psite(I)> line_piter; /// Return type of read-write access. - typedef typename internal::morpher_lvalue_<I>::ret lvalue; + typedef mln_morpher_lvalue(I) lvalue; /// Skeleton. typedef translate_image< tag::image_<I> > skeleton; @@ -127,7 +127,7 @@ mln_rvalue(I) operator()(const mln_psite(I)& p) const; /// Read and "write if possible" access of pixel value at point site \p p. - lvalue operator()(const mln_psite(I)& p); + mln_morpher_lvalue(I) operator()(const mln_psite(I)& p); }; @@ -192,7 +192,7 @@ template <typename I> inline - typename translate_image<I>::lvalue + mln_morpher_lvalue(I) translate_image<I>::operator()(const mln_psite(I)& p) { mln_assertion(this->has(p)); Index: mln/core/image/t_image.hh --- mln/core/image/t_image.hh (revision 2193) +++ mln/core/image/t_image.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 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 @@ -95,7 +95,7 @@ typedef mln_value(I) value; /// Type returned by the read-write pixel value operator. - typedef typename internal::morpher_lvalue_<I>::ret lvalue; + typedef mln_morpher_lvalue(I) lvalue; /// Return type of read-only access. typedef mln_rvalue(I) rvalue; @@ -136,7 +136,7 @@ mln_rvalue(I) operator()(const mln_psite(I)& p) const; /// Read-write access of pixel value at point site \p p. - lvalue operator()(const mln_psite(I)& p); + mln_morpher_lvalue(I) operator()(const mln_psite(I)& p); /// Give the set of values of the image. const vset& values() const; @@ -257,7 +257,7 @@ template <typename I> inline - typename internal::morpher_lvalue_<I>::ret + mln_morpher_lvalue(I) t_image<I>::operator()(const mln_psite(I)& p) { mln_precondition(this->has(p)); Index: mln/core/image/sub_image_if.hh --- mln/core/image/sub_image_if.hh (revision 0) +++ mln/core/image/sub_image_if.hh (revision 0) @@ -0,0 +1,246 @@ +// Copyright (C) 2008 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 MLN_CORE_IMAGE_SUB_IMAGE_IF_HH +# define MLN_CORE_IMAGE_SUB_IMAGE_IF_HH + +/*! + * \file mln/core/image/sub_image_if.hh + * + * \brief FIXME DOC! + * + * \todo Activate preconditions. + */ + +# include <mln/core/internal/image_domain_morpher.hh> +# include <mln/core/site_set/p_if.hh> +# include <mln/fun/p2b/has.hh> + +# include <mln/debug/println.hh> + + +namespace mln +{ + + + // Forward declaration. + template <typename I, typename S> class sub_image_if; + + + namespace internal + { + + /// \internal Data structure for \c mln::sub_image_if<I,S>. + template <typename I, typename S> + struct data< sub_image_if<I,S> > + { + data(I& ima, const S& s); + + I ima_; + p_if< S, fun::p2b::has<I> > s_; + }; + + } // end of namespace mln::internal + + + + namespace trait + { + + template <typename I, typename S> + struct image_< sub_image_if<I,S> > : default_image_morpher< I, + mln_value(I), + sub_image_if<I,S> > + { +// private: +// typedef mln_trait_image_data(I) I_data_; +// typedef mlc_equal(I_data_, trait::data::linear) I_data_are_linear_; +// public: + + typedef trait::image::category::domain_morpher category; + + typedef trait::image::ext_domain::none ext_domain; // No extension of domain. + typedef trait::image::ext_value::irrelevant ext_value; + typedef trait::image::ext_io::irrelevant ext_io; + + typedef trait::image::value_storage::disrupted value_storage; + // HOT FIXME: except if S is a Box + }; + + } // end of namespace mln::trait + + + + // FIXME: Doc! + + template <typename I, typename S> + struct sub_image_if : public internal::image_domain_morpher< I, + p_if< S, fun::p2b::has<I> >, + sub_image_if<I,S> > + { + /// Skeleton. + typedef sub_image_if< tag::image_<I>, tag::pset_<S> > skeleton; + + /// Constructor without argument. + sub_image_if(); + + /// Constructor. + sub_image_if(I& ima, const S& s); + + /// Initialization. + void init_(I& ima, const S& s); + + /// Give the definition domain. + const p_if< S, fun::p2b::has<I> >& domain() const; + +// /// Const promotion via conversion. +// operator sub_image_if<const I, S>() const; + }; + + + + + + template <typename I, typename S> + sub_image_if<const I, S> + operator / (const Image<I>& ima, const Site_Set<S>& s); + + + template <typename I, typename S> + sub_image_if<I, S> + operator / (Image<I>& ima, const Site_Set<S>& s); + + + template <typename I, typename S, typename J> + void init_(tag::image_t, sub_image_if<I,S>& target, const J& model); + + + +# ifndef MLN_INCLUDE_ONLY + + // init_ + + template <typename I, typename S, typename J> + inline + void init_(tag::image_t, sub_image_if<I,S>& target, const J& model) + { + I ima; + init_(tag::image, ima, model); + S s; + init_(tag::domain, s, model); + target.init_(ima, s); + } + + + // internal::data< sub_image_if<I,S> > + + namespace internal + { + + template <typename I, typename S> + inline + data< sub_image_if<I,S> >::data(I& ima, const S& s) + : ima_(ima) + { + typedef fun::p2b::has<I> F; + F f(ima); + s_ = p_if<S,F>(s, f); + } + + } // end of namespace mln::internal + + + // sub_image_if<I,S> + + template <typename I, typename S> + inline + sub_image_if<I,S>::sub_image_if() + { + } + + template <typename I, typename S> + inline + sub_image_if<I,S>::sub_image_if(I& ima, const S& s) + { + init_(ima, s); + } + + template <typename I, typename S> + inline + void + sub_image_if<I,S>::init_(I& ima, const S& s) + { + mln_precondition(! this->has_data()); + this->data_ = new internal::data< sub_image_if<I,S> >(ima, s); + } + + template <typename I, typename S> + inline + const p_if< S, fun::p2b::has<I> >& + sub_image_if<I,S>::domain() const + { + return this->data_->s_; + } + +// template <typename I, typename S> +// inline +// sub_image_if<I,S>::operator sub_image_if<const I, S>() const +// { +// sub_image_if<const I, S> tmp(this->data_->ima_, +// this->data_->s_); +// return tmp; +// } + + + // Operators. + + template <typename I, typename S> + inline + sub_image_if<const I, S> + operator / (const Image<I>& ima, const Site_Set<S>& s) + { + // FIXME: mln_precondition(set::inter(ima.domain(), s) != 0); + sub_image_if<const I, S> tmp(exact(ima), exact(s)); + return tmp; + } + + template <typename I, typename S> + inline + sub_image_if<I, S> + operator / (Image<I>& ima, const Site_Set<S>& s) + { + // FIXME: mln_precondition(set::inter(ima.domain(), s) != 0); + sub_image_if<I, S> tmp(exact(ima), exact(s)); + return tmp; + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_CORE_IMAGE_SUB_IMAGE_IF_HH Index: mln/core/internal/image_base.hh --- mln/core/internal/image_base.hh (revision 2193) +++ mln/core/internal/image_base.hh (working copy) @@ -73,14 +73,24 @@ /// \internal A base class for images. + /// Parameter \p T is the image value type. /// Parameter \p S is the image site set type. - /// Parameter \p V is the image value type. template <typename T, typename S, typename E> struct image_base : public image_checked_<E> { + /// Value associated type. + typedef T value; + + /// Eligible-value-set associated type. + typedef mln::value::set<T> t_eligible_value_set; + + // Return the set of the image eligigle values + const t_eligible_value_set& values_eligible() const; + + /// Site_Set associated type. typedef S pset; @@ -102,8 +112,6 @@ /// fwd_piter. typedef fwd_piter piter; - /// associated type. - typedef mln::value::set<T> t_eligible_value_set; /// Test if \p p belongs to the image domain. @@ -117,23 +125,28 @@ // FIXME: Add void init_data(..); - // Return the set of the image eligigle values - const t_eligible_value_set& values_eligible() const; - /// Assignment operator. + /// Assignment operator (performs a shallow assignment). image_base& operator=(const image_base& rhs); - /// Copy constructor. + /// Copy constructor (performs a shallow copy). image_base(const image_base& rhs); + /// Give an identifier of this image. When several image + /// variables designate the same image, they share the same + /// identifier. + const void* id_() const; + + /// Detach data from an image (free it if nobody else hold it). void destroy(); - const util::tracked_ptr< internal::data<E> >& hook_data_() const { return data_; } - - const void* id_() const { return data_.ptr_; } + /// Hook to the image data. + const util::tracked_ptr< internal::data<E> >& hook_data_() const; protected: + + /// Constructor without argument. image_base(); // Internal data, sharable by several images. @@ -173,6 +186,14 @@ template <typename T, typename S, typename E> inline + const void* + image_base<T, S, E>::id_() const + { + return data_.ptr_; + } + + template <typename T, typename S, typename E> + inline bool image_base<T, S, E>::has_data() const { @@ -215,6 +236,14 @@ data_.clean_(); } + template <typename T, typename S, typename E> + inline + const util::tracked_ptr< internal::data<E> >& + image_base<T, S, E>::hook_data_() const + { + return data_; + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::internal Index: mln/core/internal/image_morpher.hh --- mln/core/internal/image_morpher.hh (revision 2193) +++ mln/core/internal/image_morpher.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 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 @@ -46,13 +46,13 @@ /*! \internal A base class for images that are morphers. Parameter * \c I is the underlying-morphed image type. - * */ template <typename I, typename T, typename S, typename E> class image_morpher : public image_base<T, S, E> { public: + /// Delegatee associated type. typedef I delegatee; /// Return the delegatee_ pointer; default code. @@ -64,7 +64,8 @@ /* \brief Test if this image has been initialized; default impl. * * This default impl is stronger than the one inherited from - * image_base. + * image_base because it also tests that the morphed image is + * also initialized. */ bool has_data() const; Index: mln/core/internal/image_domain_morpher.hh --- mln/core/internal/image_domain_morpher.hh (revision 2193) +++ mln/core/internal/image_domain_morpher.hh (working copy) @@ -44,7 +44,10 @@ /*! \internal A base class for image morphers w.r.t. domain. - * Parameter \p S is a point set type. + * + * Parameter \p I is the morphed image type. + * Parameter \p S is the morpher site set type. + * Parameter \p E is the exact (morpher image) type. * */ template <typename I, typename S, typename E> @@ -55,6 +58,10 @@ /// Value_Set associated type. typedef mln_vset(I) vset; + /// Give the set of values. + const vset& values() const; + + /// Value associated type. typedef mln_value(I) value; @@ -62,12 +69,9 @@ typedef mln_rvalue(I) rvalue; /// Return type of read-write access. - typedef typename internal::morpher_lvalue_<I>::ret lvalue; + typedef mln_morpher_lvalue(I) lvalue; - /// Give the set of values. - const vset& values() const; - /// Read-only access of pixel value at point site \p p. rvalue operator()(const mln_psite(S)& p) const; @@ -75,6 +79,8 @@ lvalue operator()(const mln_psite(S)& p); protected: + + /// Constructor (protected) without argument. image_domain_morpher(); }; Index: mln/fun/p2b/has.hh --- mln/fun/p2b/has.hh (revision 0) +++ mln/fun/p2b/has.hh (revision 0) @@ -0,0 +1,134 @@ +// Copyright (C) 2008 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 MLN_FUN_P2B_HAS_HH +# define MLN_FUN_P2B_HAS_HH + +/*! \file mln/fun/p2b/has.hh + * + * \brief Function "psite-> bool" that maps the call "ima.has(p)". + */ + +# include <mln/core/concept/function.hh> +# include <mln/metal/const.hh> +# include <mln/metal/unconst.hh> + + +namespace mln +{ + + namespace fun + { + + namespace p2b + { + + // FIXME: Doc! + + template <typename I> + struct has : public Function_p2b< has<I> > + { + /// Result associated type. + typedef bool result; + + /// Apply the function on the psite \p p. + bool operator()(const mln_psite(I)& p) const; + + + /// Constructor without argument. + has(); + + /// Constructor from an image \p ima. + has(mlc_const(I)& ima); + + + /// Copy constructor. + has(const has<I>& rhs); + + /// Assignment operator. + has<I>& operator=(const has<I>& rhs); + + private: + mlc_const(I) ima_; + typedef Function_p2b< has<I> > super_; + }; + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I> + inline + bool + has<I>::operator()(const mln_psite(I)& p) const + { + return ima_.has(p); + } + + template <typename I> + inline + has<I>::has() + : ima_() + { + } + + template <typename I> + inline + has<I>::has(mlc_const(I)& ima) + : ima_(ima) + { + } + + template <typename I> + inline + has<I>::has(const has<I>& rhs) + : Function_v2v< has<I> >(), // Please g++. + super_(), + ima_(rhs.ima_) + { + } + + template <typename I> + inline + has<I>& + has<I>::operator=(const has<I>& rhs) + { + if (&rhs == this) + return *this; + const_cast<mlc_unconst(I)&>(this->ima_) = rhs.ima_; + return *this; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::fun::p2b + + } // end of namespace mln::fun + +} // end of namespace mln + + +#endif // ! MLN_FUN_P2B_HAS_HH