milena r3761: Correct typo errors, rename storage_ to state, update thrubin morpher

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2009-05-06 Frederic Bour <bour@lrde.epita.fr> Correct typo errors, rename storage_ to state, update thrubin morpher. * mln/core/concept/meta_function.hh: Add mln_fun_withbin for binary metafunction. * mln/core/image/thrubin_morpher.hh: Correct implementation of thrubin_morpher.hh. * mln/core/image/thru_morpher.hh: Typos correction. * mln/fun/binary.hh, * mln/fun/binary_param.hh: Renamed storage_get to state. * mln/fun/math/inf.hh, * mln/fun/math/sup.hh: Correct bug when working on two different types. * mln/fun/spe/binary.hh, * mln/fun/spe/unary.hh, * mln/fun/unary.hh, * mln/fun/unary_param.hh: Renamed storage_get to state. * mln/trait/next/solve_proxy.hh: Added one inclusion to prevent errors. * sandbox/fred/tests/thru.cc: Added test for thrubin. --- mln/core/concept/meta_function.hh | 9 - mln/core/image/thru_morpher.hh | 21 ++- mln/core/image/thrubin_morpher.hh | 206 ++++++++++++++++---------------------- mln/fun/binary.hh | 14 +- mln/fun/binary_param.hh | 2 mln/fun/math/inf.hh | 10 - mln/fun/math/sup.hh | 8 - mln/fun/spe/binary.hh | 16 ++ mln/fun/spe/unary.hh | 18 ++- mln/fun/unary.hh | 18 +-- mln/fun/unary_param.hh | 4 mln/trait/next/solve_proxy.hh | 2 sandbox/fred/tests/thru.cc | 12 +- 13 files changed, 178 insertions(+), 162 deletions(-) Index: trunk/milena/mln/trait/next/solve_proxy.hh =================================================================== --- trunk/milena/mln/trait/next/solve_proxy.hh (revision 3760) +++ trunk/milena/mln/trait/next/solve_proxy.hh (revision 3761) @@ -37,6 +37,8 @@ # include <mln/core/concept/proxy.hh> # include <mln/core/concept/proxy.hxx> +# include <mln/trait/next/solve.hh> + namespace mln { Index: trunk/milena/mln/core/image/thru_morpher.hh =================================================================== --- trunk/milena/mln/core/image/thru_morpher.hh (revision 3760) +++ trunk/milena/mln/core/image/thru_morpher.hh (revision 3761) @@ -123,12 +123,14 @@ typedef mln_psite(I) psite; /// Value associated type. - typedef typename F::result value; + typedef mln_result(F) value; /// Return type of read-only access. - typedef typename F::result rvalue; + typedef value rvalue; + typedef value lvalue; // Workaround for write operator() rvalue operator()(const mln_psite(I)& p) const; + rvalue operator()(const mln_psite(I)& p); }; @@ -221,7 +223,7 @@ thru_image<I, F>::thru_image(I& ima) { mln_precondition(ima.is_valid()); - init_(ima, mln_value(I)()); + init_(ima, F()); } template <typename I, typename F> @@ -256,6 +258,15 @@ template <typename I, typename F> inline + typename thru_image_read<I, F>::rvalue + thru_image_read<I, F>::operator()(const mln_psite(I)& p) + { + mln_precondition(this->is_valid()); + return this->data_->f_(this->data_->ima_(p)); + } + + template <typename I, typename F> + inline typename thru_image_write<I, F>::lvalue thru_image_write<I, F>::operator()(const mln_psite(I)& p) { @@ -287,7 +298,7 @@ thru(const mln::Meta_Function<M>& f, Image<I>& ima) { typedef mln_fun_with(M, mln_value(I)) F; - thru_image<I, F> tmp(exact(ima), F()); + thru_image<I, F> tmp(exact(ima), F(exact(f).state())); return tmp; } @@ -297,7 +308,7 @@ thru(const mln::Meta_Function<M>& f, const Image<I>& ima) { typedef mln_fun_with(M, mln_value(I)) F; - thru_image<const I, F> tmp(exact(ima), F()); + thru_image<const I, F> tmp(exact(ima), F(exact(f).state())); return tmp; } Index: trunk/milena/mln/core/image/thrubin_morpher.hh =================================================================== --- trunk/milena/mln/core/image/thrubin_morpher.hh (revision 3760) +++ trunk/milena/mln/core/image/thrubin_morpher.hh (revision 3761) @@ -43,7 +43,7 @@ { // Forward declaration. - template <typename I, typename F> struct thrubin_image; + template <typename I1, typename I2, typename F> struct thrubin_image; namespace internal { @@ -53,7 +53,7 @@ { data(I1& ima1, I2& ima2, const F& f); - I1 ima1_; + I1 ima_; I2 ima2_; F f_; }; @@ -65,94 +65,68 @@ { template <typename I1, typename I2, typename F> - struct image_< thrubin_image<I1, I2, F> > : image_< typename mln::internal::thrubin_find_impl<I1, , F>::ret > // Same as I except... + struct image_< thrubin_image<I1, I2, F> > : image_< I1 > // Same as I except... { // ...these changes. typedef trait::image::category::value_morpher category; - typedef mln_internal_trait_image_speed_from(I) speed; // Un-fastest. + typedef mln_internal_trait_image_speed_from(I1) speed; // Un-fastest. typedef trait::image::value_access::computed value_access; typedef trait::image::vw_io::read vw_io; }; } // end of namespace mln::trait - - - // FIXME: Doc! - - namespace internal - { - - template <typename I, typename F> - class thrubin_image_read : public internal::image_value_morpher< I, typename F::result, thrubin_image<I,F> > + /// \brief Morphes values from two images through a binary function. + /// + /// \ingroup modimagevaluemorpher + template <typename I1, typename I2, typename F> + class thrubin_image : public internal::image_value_morpher< I1, typename F::result, thrubin_image<I1,I2,F> > { public: + thrubin_image(); + thrubin_image(I1& ima1, I2& ima2); + thrubin_image(I1& ima1, I2& ima2, const F& f); + /// Skeleton. - typedef thrubin_image<tag::image_<I>, F> skeleton; + typedef thrubin_image<tag::image_<I1>, tag::image_<I2>, F> skeleton; /// Point_Site associated type. - typedef mln_psite(I) psite; + typedef mln_psite(I1) psite; /// Value associated type. - typedef typename F::result value; + typedef mln_result(F) value; /// Return type of read-only access. - typedef typename F::result rvalue; - - rvalue operator()(const mln_psite(I)& p) const; - - }; - - // Inheritance from read ?! - template <typename I, typename F> - class thrubin_image_write : public thrubin_image_read<I,F> - { - public: - - /// Type returned by the read-write pixel value operator. -// typedef typename F::template lresult<typename F::argument>::ret lvalue; - typedef typename F::lresult lvalue; - - using thrubin_image_read<I,F>::operator(); - lvalue operator()(const mln_psite(I)& p); - - }; - } - - /// \brief Morphes values from two images through a binary function. - /// - /// \ingroup modimagevaluemorpher - template <typename I, typename F> - class thrubin_image : public internal::thrubin_find_impl<I, F>::ret - { - public: + typedef value rvalue; + typedef value lvalue; // Workaround for write operator() - thrubin_image(); - thrubin_image(I& ima); - thrubin_image(I& ima, const F& f); + rvalue operator()(const mln_psite(I1)& p) const; + rvalue operator()(const mln_psite(I1)& p); - void init_(I& ima, const F& f); + void init_(I1& ima1, I2& ima2, const F& f); /// Const promotion via conversion. - operator thrubin_image<const I, F>() const; + operator thrubin_image<const I1, const I2, F>() const; }; - template <typename I, typename F> - thrubin_image<I, F> thrubin(const mln::Function<F>& f, - Image<I>& ima); - - template <typename I, typename F> - const thrubin_image<const I, F> thrubin(const mln::Function<F>& f, - const Image<I>& ima); - - template <typename I, typename M> - thrubin_image<I, mln_fun_with(M, mln_value(I))> - thrubin(const mln::Meta_Function<M>& f, Image<I>& ima); - - template <typename I, typename M> - const thrubin_image<const I, mln_fun_with(M, mln_value(I))> - thrubin(const mln::Meta_Function<M>& f, const Image<I>& ima); + template <typename I1, typename I2, typename F> + thrubin_image<I1, I2, F> + thru(const mln::Function<F>& f, + Image<I1>& ima1, Image<I2>& ima2); + + template <typename I1, typename I2, typename F> + const thrubin_image<const I1, const I2, F> + thru(const mln::Function<F>& f, + const Image<I1>& ima1, const Image<I2>& ima2); + + template <typename I1, typename I2, typename M> + thrubin_image<I1, I2, mln_fun_withbin(M, mln_value(I1), mln_value(I2))> + thru(const mln::Meta_Function<M>& f, Image<I1>& ima1, Image<I1>& ima2); + + template <typename I1, typename I2, typename M> + const thrubin_image<const I1, const I2, mln_fun_withbin(M, mln_value(I1), mln_value(I2))> + thru(const mln::Meta_Function<M>& f, const Image<I1>& ima1, const Image<I2>& ima2); # ifndef MLN_INCLUDE_ONLY @@ -161,10 +135,10 @@ namespace internal { - template <typename I, typename F> + template <typename I1, typename I2, typename F> inline - data< thrubin_image<I, F> >::data(I& ima, const F& f) - : ima_(ima), + data< thrubin_image<I1, I2, F> >::data(I1& ima1, I2& ima2, const F& f) + : ima_(ima1), ima2_(ima2), f_(f) { } @@ -173,102 +147,102 @@ // thrubin_image<I> - template <typename I, typename F> + template <typename I1, typename I2, typename F> inline - thrubin_image<I, F>::thrubin_image() + thrubin_image<I1, I2, F>::thrubin_image() { } - template <typename I, typename F> + template <typename I1, typename I2, typename F> inline - thrubin_image<I, F>::thrubin_image(I& ima, const F& f) + thrubin_image<I1, I2, F>::thrubin_image(I1& ima1, I2& ima2, const F& f) { - mln_precondition(ima.is_valid()); - init_(ima, f); + mln_precondition(ima1.is_valid()); + mln_precondition(ima2.is_valid()); + init_(ima1, ima2, f); } - template <typename I, typename F> + template <typename I1, typename I2, typename F> inline - thrubin_image<I, F>::thrubin_image(I& ima) + thrubin_image<I1, I2, F>::thrubin_image(I1& ima1, I2& ima2) { - mln_precondition(ima.is_valid()); - init_(ima, mln_value(I)()); + mln_precondition(ima1.is_valid()); + mln_precondition(ima2.is_valid()); + init_(ima1, ima2, F()); } - template <typename I, typename F> + template <typename I1, typename I2, typename F> inline void - thrubin_image<I, F>::init_(I& ima, const F& f) + thrubin_image<I1, I2, F>::init_(I1& ima1, I2& ima2, const F& f) { mln_precondition(! this->is_valid()); - mln_precondition(ima.is_valid()); - this->data_ = new internal::data< thrubin_image<I, F> >(ima, f); + mln_precondition(ima1.is_valid()); + mln_precondition(ima2.is_valid()); + this->data_ = new internal::data< thrubin_image<I1, I2, F> >(ima1, ima2, f); } - template <typename I, typename F> + template <typename I1, typename I2, typename F> inline - thrubin_image<I, F>::operator thrubin_image<const I, F>() const + thrubin_image<I1, I2, F>::operator thrubin_image<const I1, const I2, F>() const { - thrubin_image<const I, F> tmp(this->data_->ima_, this->data_->f_); + thrubin_image<const I1, const I2, F> tmp(this->data_->ima_, this->data_->ima2_, this->data_->f_); return tmp; } - namespace internal - { - - template <typename I, typename F> + template <typename I1, typename I2, typename F> inline - typename thrubin_image_read<I, F>::rvalue - thrubin_image_read<I, F>::operator()(const mln_psite(I)& p) const + typename thrubin_image<I1, I2, F>::rvalue + thrubin_image<I1, I2, F>::operator()(const mln_psite(I1)& p) const { mln_precondition(this->is_valid()); - return this->data_->f_(this->data_->ima_(p)); + return this->data_->f_(this->data_->ima_(p), this->data_->ima2_(p)); } - template <typename I, typename F> + template <typename I1, typename I2, typename F> inline - typename thrubin_image_write<I, F>::lvalue - thrubin_image_write<I, F>::operator()(const mln_psite(I)& p) + typename thrubin_image<I1, I2, F>::rvalue + thrubin_image<I1, I2, F>::operator()(const mln_psite(I1)& p) { mln_precondition(this->is_valid()); - return this->data_->f_(this->data_->ima_(p)); - } - + return this->data_->f_(this->data_->ima_(p), this->data_->ima2_(p)); } // thrubin - template <typename I, typename F> - thrubin_image<I, F> thrubin(const mln::Function<F>& f, - Image<I>& ima) + template <typename I1, typename I2, typename F> + thrubin_image<I1, I2, F> + thru(const mln::Function<F>& f, + Image<I1>& ima1, Image<I2>& ima2) { - thrubin_image<I, F> tmp(exact(ima), exact(f)); + thrubin_image<I1, I2, F> tmp(exact(ima1), exact(ima2), exact(f).state()); return tmp; } - template <typename I, typename F> - thrubin_image<const I, F> thrubin(const mln::Function<F>& f, - const Image<I>& ima) + template <typename I1, typename I2, typename F> + const thrubin_image<const I1, const I2, F> + thru(const mln::Function<F>& f, + const Image<I1>& ima1, const Image<I2>& ima2) { - thrubin_image<const I, F> tmp(exact(ima), exact(f)); + thrubin_image<const I1, const I2, F> tmp(exact(ima1), exact(ima2), exact(f).state()); return tmp; } - template <typename I, typename M> - thrubin_image<I, mln_fun_with(M, mln_value(I))> - thrubin(const mln::Meta_Function<M>& f, Image<I>& ima) + template <typename I1, typename I2, typename M> + thrubin_image<I1, I2, mln_fun_withbin(M, mln_value(I1), mln_value(I2))> + thru(const mln::Meta_Function<M>& f, Image<I1>& ima1, Image<I2>& ima2) { - typedef mln_fun_with(M, mln_value(I)) F; - thrubin_image<I, F> tmp(exact(ima), F()); + typedef mln_fun_withbin(M, mln_value(I1), mln_value(I2)) F; + thrubin_image<I1, I2, F> tmp(exact(ima1), exact(ima2), F(exact(f).state())); return tmp; } - template <typename I, typename M> - thrubin_image<const I, mln_fun_with(M, mln_value(I))> - thrubin(const mln::Meta_Function<M>& f, const Image<I>& ima) + template <typename I1, typename I2, typename M> + const thrubin_image<const I1, const I2, mln_fun_withbin(M, mln_value(I1), mln_value(I2))> + thru(const mln::Meta_Function<M>& f, const Image<I1>& ima1, const Image<I2>& ima2) { - typedef mln_fun_with(M, mln_value(I)) F; - thrubin_image<const I, F> tmp(exact(ima), F()); + typedef mln_fun_withbin(M, mln_value(I1), mln_value(I2)) F; + thrubin_image<const I1, const I2, F> tmp(exact(ima1), exact(ima2), F(exact(f).state())); return tmp; } Index: trunk/milena/mln/core/concept/meta_function.hh =================================================================== --- trunk/milena/mln/core/concept/meta_function.hh (revision 3760) +++ trunk/milena/mln/core/concept/meta_function.hh (revision 3761) @@ -35,23 +35,24 @@ # include <mln/core/concept/object.hh> # include <mln/core/concept/function.hh> - # define mln_fun_with(F, T) \ typename F::template with< T >::ret # define mln_fun_with_(F, T) \ F::with< T >::ret +# define mln_fun_withbin(F, T1, T2) \ +typename F::template with< T1, T2 >::ret + +# define mln_fun_withbin_(F, T1, T2) \ +F::with< T1, T2 >::ret # define mln_fun_result(F, T) \ typename F::template with< T >::ret::result - # define mln_fun_result_(F, T) \ F::with< T >::ret::result - - namespace mln { Index: trunk/milena/mln/fun/spe/binary.hh =================================================================== --- trunk/milena/mln/fun/spe/binary.hh (revision 3760) +++ trunk/milena/mln/fun/spe/binary.hh (revision 3761) @@ -93,17 +93,27 @@ result operator () (const argument1& a, const argument2& b) const { - return def::read(storage_, a, b); + return def::read(state_, a, b); } template <typename U> void init(const U& value) { - storage_ = mln::trait::function::internal::introspect::has_storage_t<def, void>::compute(value); + state_ = mln::trait::function::internal::introspect::has_storage_t<def, void>::compute(value); + } + + stored<storage>& state() + { + return state_; + } + + const stored<storage>& state() const + { + return state_; } protected: - mln::fun::stored<storage> storage_; + mln::fun::stored<storage> state_; }; } // end of namespace mln::fun::spe::impl Index: trunk/milena/mln/fun/spe/unary.hh =================================================================== --- trunk/milena/mln/fun/spe/unary.hh (revision 3760) +++ trunk/milena/mln/fun/spe/unary.hh (revision 3761) @@ -233,17 +233,27 @@ result operator () (const argument& value) const { - return def::read(this->storage_, value); + return def::read(this->state_, value); } template <typename U> void init(const U& value) { - storage_ = mln::trait::function::internal::introspect::has_storage_t<def, void>::compute(value); + state_ = mln::trait::function::internal::introspect::has_storage_t<def, void>::compute(value); }; + stored<storage>& state() + { + return state_; + } + + const stored<storage>& state() const + { + return state_; + } + protected: - storage storage_; + stored<storage> state_; }; template <typename Fun, typename T> @@ -262,7 +272,7 @@ void set(lvalue l, const typename super::result& r) const { - super::def::write(this->storage_, l, r); + super::def::write(this->state(), l, r); } using super::operator (); Index: trunk/milena/mln/fun/math/sup.hh =================================================================== --- trunk/milena/mln/fun/math/sup.hh (revision 3760) +++ trunk/milena/mln/fun/math/sup.hh (revision 3761) @@ -47,12 +47,12 @@ { template <typename T> - struct set_binary_<mln::fun::sup, mln::Object, T, mln::Object, T> + struct set_binary_<mln::fun::sup, mln::Object, T1, mln::Object, T2> { typedef set_binary_ ret; - typedef T result; - typedef T argument1; - typedef T argument2; + typedef mln_trait_promote(T1, T2) result; + typedef T1 argument1; + typedef T2 argument2; static result read(const argument1& a, const argument1& b) { Index: trunk/milena/mln/fun/math/inf.hh =================================================================== --- trunk/milena/mln/fun/math/inf.hh (revision 3760) +++ trunk/milena/mln/fun/math/inf.hh (revision 3761) @@ -46,13 +46,13 @@ namespace next { - template <typename T> - struct set_binary_<mln::fun::inf, mln::Object, T, mln::Object, T> + template <typename T1, typename T2> + struct set_binary_<mln::fun::inf, mln::Object, T1, mln::Object, T2> { typedef set_binary_ ret; - typedef T result; - typedef T argument1; - typedef T argument2; + typedef mln_trait_promote(T1, T2) result; + typedef T1 argument1; + typedef T2 argument2; static result read(const argument1& a, const argument1& b) { Index: trunk/milena/mln/fun/unary.hh =================================================================== --- trunk/milena/mln/fun/unary.hh (revision 3760) +++ trunk/milena/mln/fun/unary.hh (revision 3761) @@ -71,19 +71,19 @@ template <typename T> typename with<T>::ret::template lresult_with<T>::ret operator()(T& v) const { - return typename with<T>::ret(storage_get()).apply_rw(v); + return typename with<T>::ret(state()).apply_rw(v); } template <typename T, typename R> void set(T& v, const R& r) const { - typename with<T>::ret(storage_).set(v, r); + typename with<T>::ret(state()).set(v, r); } template <typename U> void init(const U& value) { - storage_ = mln::trait::function::internal::introspect::has_storage_t<flag, void>::compute(value); + state_ = mln::trait::function::internal::introspect::has_storage_t<flag, void>::compute(value); }; unary() @@ -96,18 +96,18 @@ this->init(param); } - stored<storage>& storage_get() + stored<storage>& state() { - return storage_; + return state_; } - const stored<storage>& storage_get() const + const stored<storage>& state() const { - return storage_; + return state_; } protected: - stored<storage> storage_; + stored<storage> state_; }; } // end of namespace mln::fun @@ -128,7 +128,7 @@ static typename ret::result call(const F& f, const T& v) { - return ret(f.storage_get())(v); + return ret(f.state())(v); } }; Index: trunk/milena/mln/fun/unary_param.hh =================================================================== --- trunk/milena/mln/fun/unary_param.hh (revision 3760) +++ trunk/milena/mln/fun/unary_param.hh (revision 3761) @@ -41,6 +41,10 @@ template <typename F, typename Param, typename Storage = void, typename E = F> struct unary_param: unary< unary_param<F,Param,Storage,E>, E> { + typedef F flag; + typedef Param param; + typedef Storage storage; + unary_param() { } Index: trunk/milena/mln/fun/binary.hh =================================================================== --- trunk/milena/mln/fun/binary.hh (revision 3760) +++ trunk/milena/mln/fun/binary.hh (revision 3761) @@ -54,13 +54,13 @@ template <typename T1, typename T2> typename with<T1, T2>::ret::result operator()(const T1& a, const T2& b) const { - return typename with<T1, T2>::ret(storage_)(a, b); + return typename with<T1, T2>::ret(state())(a, b); } template <typename U> void init(const U& value) { - storage_ = mln::trait::function::internal::introspect::has_storage_t<flag, void>::compute(value); + state_ = mln::trait::function::internal::introspect::has_storage_t<flag, void>::compute(value); }; binary() @@ -73,18 +73,18 @@ this->init(param); } - stored<storage>& storage_get() + stored<storage>& state() { - return storage_; + return state_; } - const stored<storage>& storage_get() const + const stored<storage>& state() const { - return storage_; + return state_; } protected: - stored<storage> storage_; + stored<storage> state_; }; } // end of namespace mln::fun Index: trunk/milena/mln/fun/binary_param.hh =================================================================== --- trunk/milena/mln/fun/binary_param.hh (revision 3760) +++ trunk/milena/mln/fun/binary_param.hh (revision 3761) @@ -42,6 +42,8 @@ struct binary_param: binary<binary_param<F,Param,Storage>, E> { typedef F flag; + typedef Param param; + typedef Storage storage; binary_param() { Index: trunk/milena/sandbox/fred/tests/thru.cc =================================================================== --- trunk/milena/sandbox/fred/tests/thru.cc (revision 3760) +++ trunk/milena/sandbox/fred/tests/thru.cc (revision 3761) @@ -2,12 +2,14 @@ #include <mln/fun/v2v/convert.hh> #include <mln/fun/math/cos.hh> #include <mln/core/image/thru_morpher.hh> +#include <mln/core/image/thrubin_morpher.hh> #include <mln/fun/compose.hh> #include <mln/core/var.hh> #include <mln/core/image/image2d.hh> #include <mln/fun/point/row.hh> +#include <mln/fun/math/inf.hh> #include <mln/value/int_u8.hh> #include <mln/debug/all.hh> @@ -23,24 +25,24 @@ using namespace mln; fun::cos cos; + fun::inf inf; + typedef image2d<float> I; I ima(5, 5); - image2d<value::int_u8> tmp(5, 5); + + debug::iota(tmp); data::fill_with_image(ima, tmp); debug::println(ima); debug::println(thru(cos, ima)); + debug::println(thru(inf, ima, tmp)); mln_VAR(ima2, thru(cos(cos), ima)); - data::fill_with_image(ima2, tmp); - mln::fun::row row; - mln_piter_(I) p(ima.domain()); - for_all(p) std::cout << row(p);
participants (1)
-
Frederic Bour