2005-07-04 Thierry GERAUD theo@tegucigalpa.lrde.epita.fr
Add 'rawness' characteristic (ability to reference data at p) to images. Add corresponding attribute access object mechanism. * oln/funobj/decl_attr.hh: New file. * oln/funobj/abstract/accessor.hh: New file. * oln/core/abstract/image_rawness.hh: New file. * oln/core/gen/mfun.hh: New file. * oln/core/gen/attr.hh: New file. * oln/makefile.src: Update. * oln/core/typedefs.hh: Update. * oln/core/abstract/image.hh: Update. * oln/core/abstract/image_entry.hh: Update. * oln/core/pw/image.hh: Update.
* oln/funobj/abstract/unary.hh: (munary::operator()): Make it more general. * oln/core/abstract/image_neighbness.hh (impl_nbh_get()): Move from class body to default impl. * oln/core/abstract/data_storage.hh (at): New methods. * oln/core/abstract/image_with_data.hh (impl_at): Likewise. * oln/core/abstract/image_by_delegation.hh (set_props): Add image_constness_type. (ctors): Accept a box as input. * oln/core/2d/array2d.hh (impl_at): New methods. (impl_set, impl_get): Add fixme. * oln/core/pw/unary_op.hh (ctor): Relax static check. * oln/core/gen/image_with_nbh.hh: Add fixme. * oln/core/gen/internal/value_box.hh: Add fixme. * oln/morpho/dilation.hh (local): Add include. * oln/morpho/erosion.hh (local): Add include. (impl::erosion_): Add fixme. * oln/morpho/thick_gradient.hh (gradient_beucher): Rename as... (thick_gradient_beucher): ...This.
Index: ChangeLog =================================================================== --- ChangeLog (revision 225) +++ ChangeLog (working copy) @@ -1,3 +1,15 @@ +2005-07-04 Thierry GERAUD theo@tegucigalpa.lrde.epita.fr + + Add 'rawness' characteristic (ability to reference data at p) + to images. Add corresponding attribute access object mechanism. + + * oln/funobj/decl_attr.hh: New file. + * oln/funobj/abstract/accessor.hh: New file. + * oln/core/abstract/image_rawness.hh: New file. + * oln/core/gen/mfun.hh: New file. + * oln/core/gen/attr.hh: New file. + + 2005-06-27 Christophe Berger christophe@lrde.epita.fr
* oln/appli/astro/tree_coherance_checks.hh: Remove. Index: oln/funobj/decl_attr.hh =================================================================== --- oln/funobj/decl_attr.hh (revision 0) +++ oln/funobj/decl_attr.hh (revision 0) @@ -0,0 +1,174 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_FUNOBJ_DECL_ATTR_HH +# define OLENA_CORE_FUNOBJ_DECL_ATTR_HH + +# include <mlc/is_a.hh> +# include <oln/funobj/abstract/accessor.hh> +# include <oln/funobj/abstract/unary.hh> +# include <oln/core/gen/attr.hh> + + +/// Macro oln_decl_attr. + +# define oln_decl_attr(ATTR) \ + \ +namespace oln \ +{ \ + \ + namespace a_ { \ + \ + struct ATTR : public f_::abstract::accessor< ATTR > \ + { \ + template <typename T> \ + struct type \ + { \ + typedef typename T::ATTR##_type ret; \ + }; \ + template <typename T> \ + typename T::ATTR##_type& operator()(T& t) const \ + { \ + return t.ATTR; \ + } \ + template <typename T> \ + const typename T::ATTR##_type& operator()(const T& t) const \ + { \ + return t.ATTR; \ + } \ + }; \ + \ + } \ + \ + template <typename I> \ + attr<a_::ATTR, I> a_##ATTR(abstract::image<I>& input) \ + { \ + mlc_is_a(I, abstract::raw_image)::ensure(); \ + attr<a_::ATTR, I> tmp(input); \ + return tmp; \ + } \ + \ + template <typename I> \ + attr<a_::ATTR, const I> a_##ATTR(const abstract::image<I>& input) \ + { \ + mlc_is_a(I, abstract::raw_image)::ensure(); \ + attr<a_::ATTR, const I> tmp(input); \ + return tmp; \ + } \ + \ +} \ +struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n + + + + +// Dummy code for testing purpose. + +namespace oln +{ + + namespace a_ { + + struct dummy : public f_::abstract::accessor< dummy > + { + template <typename T> + struct type + { + typedef typename T::dummy_type ret; + }; + template <typename T> + typename T::dummy_type& operator()(T& t) const + { + return t.dummy; + } + template <typename T> + const typename T::dummy_type& operator()(const T& t) const + { + return t.dummy; + } + }; + + } // end of namespace oln::a_ + + + template <typename I> + attr<a_::dummy, I> a_dummy(abstract::image<I>& input) + { + mlc_is_a(I, abstract::raw_image)::ensure(); + attr<a_::dummy, I> tmp(input); + return tmp; + } + + template <typename I> + attr<a_::dummy, const I> a_dummy(const abstract::image<I>& input) + { + mlc_is_a(I, abstract::raw_image)::ensure(); + attr<a_::dummy, const I> tmp(input); + return tmp; + } + + + // f_::a_dummy_<T> as a pure function + + namespace f_ { + template <typename T> struct a_dummy_; + } + + template <typename T> + struct set_super_type < f_::a_dummy_<T> > { typedef f_::abstract::unary< f_::a_dummy_<T> > ret; }; + + template <typename T> + struct set_props < category::fun1, f_::a_dummy_<T> > + { + typedef typename T::dummy_type res_type; + typedef T arg_type; + }; + + namespace f_ { + + template <typename T> + struct a_dummy_ : public oln_super_of_(f_::a_dummy_<T>) + { + const typename T::dummy_type impl_unop(const T& t) const + { + return t.dummy; + } + }; + + } // end of namespace oln::f_ + + // f_dummy as a pure meta function + + typedef f_::unary_meta<f_::a_dummy_> fa_dummy_type; + static fa_dummy_type fa_dummy; + + +} // end of namespace oln + + + +#endif // ! OLENA_CORE_FUNOBJ_DECL_ATTR_HH Index: oln/funobj/abstract/accessor.hh =================================================================== --- oln/funobj/abstract/accessor.hh (revision 0) +++ oln/funobj/abstract/accessor.hh (revision 0) @@ -0,0 +1,56 @@ +// Copyright (C) 2001, 2004, 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_FUNOBJ_ACCESSOR_HH +# define OLENA_CORE_FUNOBJ_ACCESSOR_HH + +# include <mlc/any.hh> + + +namespace oln { + + namespace f_ { + + namespace abstract { + + /// Accessor. + + template <typename A> + struct accessor : public mlc::any<A> + { + protected: + accessor() {} + }; + + } // end of namespace oln::f_::abstract + + } // end of namespace oln::f_ + +} // end of namespace oln + + +#endif // ! OLENA_CORE_FUNOBJ_ACCESSOR_HH Index: oln/funobj/abstract/unary.hh =================================================================== --- oln/funobj/abstract/unary.hh (revision 225) +++ oln/funobj/abstract/unary.hh (working copy) @@ -30,10 +30,19 @@
# include <mlc/any.hh> # include <mlc/contract.hh> +# include <mlc/if.hh> +# include <mlc/is_a.hh> # include <ntg/all.hh> # include <oln/core/abstract/image.hh> +# include <oln/core/gen/internal/value_box.hh> +# include <oln/core/pw/abstract/function.hh>
+// FIXME: break cycling dependance due to... +// FIXME: ...the recursive classes oln::pw::unary_op and oln::f_::abstract::munary
+// # include <oln/core/pw/unary_op.hh> + + // Macros.
# define oln_fun1_type_of(Fun1Type, Alias) \ @@ -112,23 +121,116 @@ } };
+ // munary
+ namespace internal { + + // FIXME: move to internal/? + + struct arg_is_a_value_box; + struct arg_is_a_point_wise_function; + struct arg_is_an_image; + struct arg_is_a_value; + + template <typename E, typename Arg, typename arg_kind> + struct munary_on; + + // on a value box + template <typename E, typename I> + struct munary_on <E, oln::value_box<I>, arg_is_a_value_box> + { + typedef typename munary_result<E, oln_type_of(I, value)>::ret ret; + static const ret exec(const E& target, const oln::value_box<I>& arg) + { + return target.impl_unop(arg.value()); + } + }; + + // on a point-wise function +// template <typename E, typename F> +// struct munary_on <E, oln::pw::abstract::function<F>, arg_is_a_point_wise_function> +// { +// typedef oln::pw::unary_op<E,F> ret; +// static const ret exec(const E& target, const oln::pw::abstract::function<F>& arg) +// { +// oln::pw::unary_op<E,F> tmp(arg); +// return tmp; +// } +// }; + + // on a (regular) value + template <typename E, typename T> + struct munary_on <E, T, arg_is_a_value> + { + typedef typename munary_result<E, T>::ret ret; + static const ret exec(const E& target, const T& arg) + { + return target.impl_unop(arg); + } + }; + + // on an image + template <typename E, typename I> + struct munary_on <E, oln::abstract::image<I>, arg_is_an_image> + { + // FIXME: fake code here + typedef int ret; + static const ret exec(const E& target, const oln::abstract::image<I>& arg) + { + return 0; + } + }; + + template <typename E, typename Arg> + struct munary_helper + { + // arg_kind + typedef typename + mlc::if_< mlc_is_a(Arg, oln::value_box), + arg_is_a_value_box, typename + mlc::if_< mlc_is_a(Arg, oln::pw::abstract::function), + arg_is_a_point_wise_function, typename + mlc::if_< mlc_is_a(Arg, oln::abstract::image), + arg_is_an_image, + arg_is_a_value + >::ret + >::ret + >::ret + arg_kind; + // ret + typedef typename munary_on<E, Arg, arg_kind>::ret ret; + // exec + static const ret exec(const E& target, const Arg& arg) + { + return munary_on<E, Arg, arg_kind>::exec(target, arg); + } + }; + + } // end of namespace oln::f_::abstract::internal + + template <typename E> struct munary : public mlc::any<E> { template <typename T> - const typename munary_result<E,T>::ret + struct helper : public internal::munary_helper<E,T> + { + // using internal::munary_helper<E,T>::ret; + // using internal::munary_helper<E,T>::exec; + }; + template <typename T> + const typename helper<T>::ret operator()(const T& arg) const { - return this->exact().impl_unop(arg); + return helper<T>::exec(this->exact(), arg); } protected: munary() {} };
- } // end of namespace oln::abstract + } // end of namespace oln::f_::abstract
@@ -157,6 +259,7 @@ static F<T> f; return f(arg); } + };
Index: oln/core/typedefs.hh =================================================================== --- oln/core/typedefs.hh (revision 225) +++ oln/core/typedefs.hh (working copy) @@ -101,6 +101,7 @@ mlc_decl_typedef(image_dimension_type); mlc_decl_typedef(image_typeness_type); mlc_decl_typedef(image_valuedness_type); + mlc_decl_typedef(image_rawness_type);
// extension in image_operators mlc_decl_typedef(output_type); Index: oln/core/abstract/image.hh =================================================================== --- oln/core/abstract/image.hh (revision 225) +++ oln/core/abstract/image.hh (working copy) @@ -48,9 +48,9 @@ { template <typename I> class image_without_nbh; template <typename I> class readonly_image; + template <typename I> class raw_image; }
- namespace category { struct image; @@ -81,6 +81,7 @@
typedef is_aabstract::image_without_nbh image_neighbness_type; typedef is_aabstract::readonly_image image_constness_type; + typedef mlc::undefined_type image_rawness_type; typedef mlc::undefined_type image_dimension_type;
//... @@ -112,6 +113,7 @@
typedef oln_type_of(I, image_neighbness) image_neighbness_type; typedef oln_type_of(I, image_constness) image_constness_type; + typedef oln_type_of(I, image_rawness) image_rawness_type; typedef oln_type_of(I, image_dimension) image_dimension_type;
//... @@ -139,6 +141,7 @@
<< "\t image_neighbness_type = " << mlc_to_string(image_neighbness_type) << std::endl << "\t image_constness_type = " << mlc_to_string(image_constness_type) << std::endl + << "\t image_rawness_type = " << mlc_to_string(image_rawness_type) << std::endl << "\t image_dimension_type = " << mlc_to_string(image_dimension_type) << std::endl
<< "}" << std::endl; @@ -162,6 +165,7 @@
mlc::is_ok< image_neighbness_type >::ensure(); mlc::is_ok< image_constness_type >::ensure(); + mlc::is_ok< image_rawness_type >::ensure(); mlc::is_ok< image_dimension_type >::ensure(); } }; Index: oln/core/abstract/image_rawness.hh =================================================================== --- oln/core/abstract/image_rawness.hh (revision 0) +++ oln/core/abstract/image_rawness.hh (revision 0) @@ -0,0 +1,137 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_ABSTRACT_IMAGE_RAWNESS_HH +# define OLENA_CORE_ABSTRACT_IMAGE_RAWNESS_HH + +# include <oln/core/abstract/image.hh> + + +// image +// +// ^ +// | +// --------------- +// | | +// +// raw_image ... + + + +/*! \namespace oln +** \brief oln namespace. +*/ +namespace oln { + + + /*! \namespace oln::abstract + ** \brief oln::abstract namespace. + */ + namespace abstract { + + + + + /*! \class abstract::raw_image<E> + ** + ** Class of images whose data are read-only. + */ + + + template <typename E> + struct raw_image : public virtual image<E>, + public internal::get_image_impl < raw_image<E>, E > + { + public: + + typedef oln_type_of(E, point) point_type; + typedef oln_type_of(E, value_storage) value_storage_type; + + value_storage_type& at(const point_type& p) + { +# ifdef OLNTRACE + inc_ncalls("set", *this); +# endif // ! OLNTRACE + return this->exact().impl_at(p); + } + + const value_storage_type& at(const point_type& p) const + { +# ifdef OLNTRACE + inc_ncalls("get", *this); +# endif // ! OLNTRACE + return this->exact().impl_at(p); + } + + protected: + + /*! \brief Constructor (protected, empty). + */ + raw_image() {} + }; + + + template <typename E> + struct not_raw_image : public virtual image<E> + { + protected: + not_raw_image() {} + }; + + + + namespace internal { + + template <typename E> + struct set_image_impl < raw_image<E>, E> : public virtual image_impl<E> + { + /// typedefs + typedef typename image_impl<E>::D D; + typedef oln_type_of(D, point) point_type; + typedef oln_type_of(D, value_storage) value_storage_type; + + value_storage_type& at(const point_type& p) + { + return this->delegate().at(p); + } + + const value_storage_type& at(const point_type& p) const + { + return this->delegate().at(p); + } + }; + + } // end of namespace oln::abstract::internal + + + + } // end of namespace oln::abstract + +} // end of namespace oln + + +#endif // ! OLENA_CORE_ABSTRACT_IMAGE_RAWNESS_HH Index: oln/core/abstract/image_neighbness.hh =================================================================== --- oln/core/abstract/image_neighbness.hh (revision 225) +++ oln/core/abstract/image_neighbness.hh (working copy) @@ -42,30 +42,25 @@
template <typename E> - struct image_with_nbh : public virtual image<E> + struct image_with_nbh : public virtual image<E>, + public internal::get_image_impl < image_with_nbh<E>, E > { public:
typedef oln_type_of(E, neighb) neighb_type;
- const neighb_type& nbh_get() const // FIXME: rename (?) + const neighb_type& nbh_get() const // FIXME: rename { return this->exact().impl_nbh_get(); }
- //FIXME: is it the right way ? - const neighb_type& impl_nbh_get() const - { - return this->exact().delegate().nbh_get(); - } - protected:
image_with_nbh() {}
~image_with_nbh() { -// mlc_check_method_impl(E, const neighb_type&, nbh_get, , const); +// mlc_check_method_impl(E, const neighb_type&, nbh, , const); } };
@@ -78,6 +73,24 @@ };
+ + namespace internal { + + template <typename E> + struct set_image_impl < image_with_nbh<E>, E> : public virtual image_impl<E> + { + typedef typename image_impl<E>::D D; + typedef oln_type_of(D, neighb) neighb_type; + + const neighb_type& impl_nbh_get() const + { + return this->exact().delegate().nbh_get(); + } + }; + + } // end of namespace oln::abstract::internal + + } // end of namespace oln::abstract
} // end of namespace oln Index: oln/core/abstract/data_storage.hh =================================================================== --- oln/core/abstract/data_storage.hh (revision 225) +++ oln/core/abstract/data_storage.hh (working copy) @@ -140,7 +140,7 @@ return this->exact().impl_hold(p); }
- const data_type get(const point_type& p) const + const data_type get(const point_type& p) const // FIXME: remove (obsolete) { precondition(this->has_data()); precondition(this->hold_large(p)); @@ -150,7 +150,7 @@ return this->exact().impl_get(p); }
- void set(const point_type& p, const data_type& v) + void set(const point_type& p, const data_type& v) // FIXME: remove (obsolete) { precondition(this->has_data()); precondition(this->hold_large(p)); @@ -160,15 +160,26 @@ this->exact().impl_set(p, v); }
+ const data_type& at(const point_type& p) const + { + precondition(this->has_data()); + precondition(this->hold_large(p)); +# ifdef OLNTRACE + inc_ncalls("data_get", *this); +# endif // ! OLNTRACE + return this->exact().impl_at(p); + }
- // FIXME: commented below cause unused... -// void set_data(const data_type& v) -// { -// precondition(this->has_data()); -// this->exact().impl_set_data(v); -// } + data_type& at(const point_type& p) + { + precondition(this->has_data()); + precondition(this->hold_large(p)); +# ifdef OLNTRACE + inc_ncalls("data_set", *this); +# endif // ! OLNTRACE + return this->exact().impl_at(p); + }
- // polymorphic method with default
bool hold_large(const point_type& p) const @@ -198,7 +209,8 @@ mlc_check_method_impl(E, unsigned long, npoints, , const); mlc_check_method_impl(E, bool, hold, const point_type&, const); mlc_check_method_impl(E, const data_type, get, const point_type&, const); - mlc_check_method_impl(E, void, set_data, const data_type&, ); + mlc_check_method_impl(E, const data_type&, at, const point_type&, const); + mlc_check_method_impl(E, data_type&, at, const point_type&, ); mlc_check_method_impl(E, bool, hold_large, const point_type&, const); mlc_check_method_impl_2(E, void, resize_border, size_t, bool, ); mlc_check_method_impl_2(E, void, set, const point_type&, const data_type&, ); Index: oln/core/abstract/image_entry.hh =================================================================== --- oln/core/abstract/image_entry.hh (revision 225) +++ oln/core/abstract/image_entry.hh (working copy) @@ -33,6 +33,7 @@ # include <oln/core/abstract/image_neighbness.hh> # include <oln/core/abstract/image_typeness.hh> # include <oln/core/abstract/image_valuedness.hh> +# include <oln/core/abstract/image_rawness.hh>
@@ -58,6 +59,7 @@ public oln_type_of_(E, image_constness) ::template instantiated_with<E>::ret, public oln_type_of_(E, image_dimension) ::template instantiated_with<E>::ret, public oln_type_of_(E, image_neighbness) ::template instantiated_with<E>::ret, + public oln_type_of_(E, image_rawness) ::template instantiated_with<E>::ret, // ... public typeness::inheritance_switch<E>, public valuedness::inheritance_switch<E> Index: oln/core/abstract/image_with_data.hh =================================================================== --- oln/core/abstract/image_with_data.hh (revision 225) +++ oln/core/abstract/image_with_data.hh (working copy) @@ -55,6 +55,7 @@ { // intrusive property: typedef is_aabstract::readwrite_image image_constness_type; + typedef is_aabstract::raw_image image_rawness_type; typedef E concrete_type; };
@@ -84,6 +85,7 @@ typedef oln_type_of(E, size) size_type; typedef oln_type_of(E, point) point_type; typedef oln_type_of(E, value) value_type; + typedef oln_type_of(E, value_storage) value_storage_type; typedef oln_type_of(E, storage) storage_type;
@@ -190,6 +192,15 @@ (const_cast<storage_type&>(*this->data_)).resize_border(new_border, copy_border); }
+ value_storage_type& impl_at(const point_type& p) + { + return this->data_->at(p); + } + + const value_storage_type& impl_at(const point_type& p) const + { + return this->data_->at(p); + }
protected:
Index: oln/core/abstract/image_by_delegation.hh =================================================================== --- oln/core/abstract/image_by_delegation.hh (revision 225) +++ oln/core/abstract/image_by_delegation.hh (working copy) @@ -54,6 +54,7 @@ : public get_props< category::image, I > { typedef I delegated_type; + // FIXME: what about storage_type? };
template <typename I, typename E> @@ -61,6 +62,8 @@ : public get_props< category::image, I > { typedef I delegated_type; + typedef is_aabstract::readonly_image image_constness_type; + // FIXME: what about storage_type? };
@@ -80,12 +83,20 @@ this->exact_ptr = (E*)(void*)(this); }
+ // FIXME: this ctor should be removed. image_by_delegation(abstract::image<I>& image) : image_(image.exact()) { this->exact_ptr = (E*)(void*)(this); }
+ /// Ctor with an image (in a box). + image_by_delegation(box<I> image) : + image_(image) + { + this->exact_ptr = (E*)(void*)(this); + } + image_by_delegation(const image_by_delegation& rhs) : image_(rhs.image_) { @@ -122,12 +133,20 @@ this->exact_ptr = (E*)(void*)(this); }
+ // FIXME: this ctor should be removed. image_by_delegation(const abstract::image<I>& ima) : image_(ima.exact()) { this->exact_ptr = (E*)(void*)(this); }
+ /// Ctor with an image (in a box). + image_by_delegation(box<const I> image) : + image_(image) + { + this->exact_ptr = (E*)(void*)(this); + } + image_by_delegation(const image_by_delegation& rhs) : image_(rhs.image()) { Index: oln/core/2d/array2d.hh =================================================================== --- oln/core/2d/array2d.hh (revision 225) +++ oln/core/2d/array2d.hh (working copy) @@ -201,18 +201,30 @@ p.col() < size_.ncols() + size_.border(); }
- const T impl_get(const point2d& p) const + const T impl_get(const point2d& p) const // FIXME: remove (obsolete) { invariant_(); return array_[p.row()][p.col()]; }
- void impl_set(const point2d& p, const T& v) + void impl_set(const point2d& p, const T& v) // FIXME: remove (obsolete) { invariant_(); array_[p.row()][p.col()] = v; }
+ const T& impl_at(const point2d& p) const + { + invariant_(); + return array_[p.row()][p.col()]; + } + + T& impl_at(const point2d& p) + { + invariant_(); + return array_[p.row()][p.col()]; + } + // FIXME: should be impl_ here; and call should be defined in storage_type template <typename T2, typename A, typename V> void call(const point2d& p, Index: oln/core/pw/image.hh =================================================================== --- oln/core/pw/image.hh (revision 225) +++ oln/core/pw/image.hh (working copy) @@ -61,6 +61,8 @@
// FIXME: EXTREMELY AWFUL!!! we do not know if it is 2d... typedef is_aabstract::image2d image_dimension_type; + typedef is_aabstract::readonly_image image_constness_type; + typedef is_aabstract::not_raw_image image_rawness_type;
typedef grid2d grid_type; typedef fwd_piter2d piter_type; Index: oln/core/pw/unary_op.hh =================================================================== --- oln/core/pw/unary_op.hh (revision 225) +++ oln/core/pw/unary_op.hh (working copy) @@ -68,7 +68,8 @@ super_type(arg), fun() { - mlc_is_a(F, f_::unary_meta)::ensure(); + mlc_is_a(F, f_::abstract::munary)::ensure(); +// mlc_is_a(F, f_::unary_meta)::ensure(); }
typedef oln_pw_type_of(self_type, point) point_type; Index: oln/core/gen/image_with_nbh.hh =================================================================== --- oln/core/gen/image_with_nbh.hh (revision 225) +++ oln/core/gen/image_with_nbh.hh (working copy) @@ -149,6 +149,9 @@ return tmp; }
+ // FIXME: add the 'const' version... + + } // end of namespace oln
Index: oln/core/gen/mfun.hh =================================================================== --- oln/core/gen/mfun.hh (revision 0) +++ oln/core/gen/mfun.hh (revision 0) @@ -0,0 +1,122 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_GEN_MFUN_HH +# define OLENA_CORE_GEN_MFUN_HH + +# include <oln/core/abstract/image_by_delegation.hh> +# include <oln/core/ch_value_type.hh> +# include <oln/funobj/abstract/unary.hh> +# include <oln/utils/record.hh> + + + +namespace oln { + + // fwd decl + template <typename F, typename I> struct mfun; + + // super type + template <typename F, typename I> + struct set_super_type < mfun<F, I> > + { + typedef abstract::image_by_delegation< const I, mfun<F, I> > ret; + }; + + // set props + template <typename F, typename I> + struct set_props < category::image, mfun<F, I> > + { + typedef is_aabstract::not_raw_image image_rawness_type; + + typedef oln_type_of(I, value) I_value_type; + typedef typename f_::munary_result<F, I_value_type>::ret value_type; + typedef oln_ch_concrete_type(I, value_type) concrete_type; + + typedef mlc::no_type value_storage_type; + typedef mlc::no_type storage_type; // FIXME: senseless? + }; + + + template <typename F, typename I> + struct mfun : public abstract::image_by_delegation < const I, mfun<F, I> > + { + typedef mfun<F, I> self_type; + typedef abstract::image_by_delegation < const I, self_type > super_type; + + typedef oln_type_of(self_type, point) point_type; + typedef oln_type_of(self_type, value) value_type; + + public: + + mfun() + { + } + + mfun(box<const I> image) : + super_type(image) + { + } + + mfun(box<const I> image, F f) : + super_type(image), + f(f) + { + } + + mfun(box<const I> image, const std::string& name) : + super_type(image) + { + registering(*this, name); + } + + mfun(box<const I> image, F f, const std::string& name) : + super_type(image), + f(f) + { + registering(*this, name); + } + + // get + + const value_type impl_get(const point_type& p) const + { + return f(this->delegate().get(p)); + } + + // FIXME: what about the methods "call(*)"? + + protected: + + F f; + }; + + +} // end of namespace oln + + +#endif // ! OLENA_CORE_GEN_MFUN_HH Index: oln/core/gen/attr.hh =================================================================== --- oln/core/gen/attr.hh (revision 0) +++ oln/core/gen/attr.hh (revision 0) @@ -0,0 +1,125 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_GEN_ATTR_HH +# define OLENA_CORE_GEN_ATTR_HH + +# include <oln/core/abstract/image_by_delegation.hh> +# include <oln/core/ch_value_type.hh> +# include <oln/utils/record.hh> + + +namespace oln { + + // fwd decl + template <typename A, typename I> struct attr; + + // super type + template <typename A, typename I> + struct set_super_type < attr<A, I> > + { + typedef abstract::image_by_delegation< I, attr<A, I> > ret; + }; + + // set props + template <typename A, typename I> + struct set_props < category::image, attr<A, I> > + { + typedef oln_type_of(I, value_storage) I_value_storage; + + typedef typename A::template type<I_value_storage>::ret value_type; + typedef value_type value_storage_type; + typedef oln_ch_concrete_type(I, value_type) concrete_type; + + typedef mlc::no_type storage_type; // FIXME: senseless? + }; + + + template <typename A, typename I> + struct attr : public abstract::image_by_delegation < I, attr<A, I> > + { + typedef attr<A, I> self_type; + typedef abstract::image_by_delegation < I, self_type > super_type; + + typedef oln_type_of(self_type, point) point_type; + typedef oln_type_of(self_type, value) value_type; + typedef oln_type_of(self_type, value_storage) value_storage_type; + + public: + + attr() + { + } + + attr(box<I> image) : + super_type(image) + { + mlc_is_a(I, abstract::raw_image)::ensure(); + } + + attr(box<I> image, const std::string& name) : + super_type(image) + { + registering(*this, name); + } + + // .at(p) + + value_storage_type& impl_at(const point_type& p) + { + return a_of(this->delegate().at(p)); + } + + const value_storage_type& impl_at(const point_type& p) const + { + return a_of(this->delegate().at(p)); + } + + // get/set + + void impl_set(const point_type& p, const value_type& v) + { + a_of(this->delegate().at(p)) = v; + } + + const value_type impl_get(const point_type& p) const + { + return a_of(this->delegate().get(p)); + } + + // FIXME: what about the methods "call(*)"? + + protected: + + A a_of; + }; + + +} // end of namespace oln + + +#endif // ! OLENA_CORE_GEN_ATTR_HH Index: oln/core/gen/internal/value_box.hh =================================================================== --- oln/core/gen/internal/value_box.hh (revision 225) +++ oln/core/gen/internal/value_box.hh (working copy) @@ -33,6 +33,7 @@ # include <oln/core/abstract/image.hh>
+// FIXME: not coherent cause in internal/ but not internal::
/*! \namespace oln Index: oln/makefile.src =================================================================== --- oln/makefile.src (revision 225) +++ oln/makefile.src (working copy) @@ -79,6 +79,7 @@ core/abstract/image_like_.hh \ core/abstract/image_neighbness.hh \ core/abstract/image_operator.hh \ + core/abstract/image_rawness.hh \ core/abstract/image_typeness.hh \ core/abstract/image_valuedness.hh \ core/abstract/image_with_data.hh \ @@ -105,9 +106,11 @@ core/compose.hh \ core/coord.hh \ \ + core/gen/attr.hh \ core/gen/identity.hh \ core/gen/image_with_nbh.hh \ core/gen/internal/value_box.hh \ + core/gen/mfun.hh \ core/gen/regular_bkd_niter.hh \ core/gen/regular_bkd_qiter.hh \ core/gen/regular_fwd_niter.hh \ @@ -138,11 +141,13 @@ fancy/iota.hh \ fancy/print.hh \ \ + funobj/abstract/accessor.hh \ funobj/abstract/binary.hh \ funobj/abstract/unary.hh \ funobj/accum.hh \ funobj/arith.hh \ funobj/cmp.hh \ + funobj/decl_attr.hh \ funobj/infsup.hh \ funobj/invert.hh \ funobj/logic.hh \ Index: oln/morpho/dilation.hh =================================================================== --- oln/morpho/dilation.hh (revision 225) +++ oln/morpho/dilation.hh (working copy) @@ -32,6 +32,7 @@
# include <oln/utils/record.hh> # include <oln/basics.hh> +# include <oln/morpho/local.hh> # include <oln/core/2d/window2d.hh>
Index: oln/morpho/erosion.hh =================================================================== --- oln/morpho/erosion.hh (revision 225) +++ oln/morpho/erosion.hh (working copy) @@ -32,6 +32,7 @@
# include <oln/utils/record.hh> # include <oln/basics.hh> +# include <oln/morpho/local.hh> # include <oln/core/2d/window2d.hh>
@@ -62,6 +63,8 @@ registering(input, "input");
oln_type_of(I, concrete) output(input.size(), "output"); + // FIXME: the use of .info() instead of .size() above would allow to create + // output with the proper neighborhood if input is an image_with_nbh...
oln_type_of(I, fwd_piter) p(input.size()); for_all_p (p) Index: oln/morpho/thick_gradient.hh =================================================================== --- oln/morpho/thick_gradient.hh (revision 225) +++ oln/morpho/thick_gradient.hh (working copy) @@ -30,8 +30,6 @@
# include <oln/morpho/dilation.hh> # include <oln/morpho/erosion.hh> -# include <oln/morpho/elementary_dilation.hh> -# include <oln/morpho/elementary_erosion.hh> # include <oln/morpho/temp.hh>
@@ -43,8 +41,8 @@ /// Beucher thick gradient.
template<typename I, typename W> - oln_type_of(I, concrete) gradient_beucher(const abstract::image<I>& input, - const abstract::window<W>& win) + oln_type_of(I, concrete) thick_gradient_beucher(const abstract::image<I>& input, + const abstract::window<W>& win) { mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();