
https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Roland Levillain <roland@lrde.epita.fr> Add a specialization of level::fill for value-wise random-accessible images. * tests/morphers/with_lut.cc (main): More static checking of the interface of an image with LUT. Test oln::level::fill on an image with LUT. * oln/level/fill.hh (level::fill(abstract:: mutable_image_being_value_wise_random_accessible<I>&)) (level::impl:: fill(abstract::mutable_image_being_value_wise_random_accessible<I>&)): New. * oln/core/typedefs.hh (oln_fwd_viter, oln_fwd_viter_) (oln_bkd_viter, oln_bkd_viter_, oln_viter, oln_viter_): New macros. * oln/core/gen/bkd_viter_lut.hh (bkd_viter_lut::bkd_viter_lut(const morpher::with_lut<Image, Lut>&)) * oln/core/gen/fwd_viter_lut.hh (fwd_viter_lut::fwd_viter_lut(const morpher::with_lut<Image, Lut>&)) New ctors. oln/core/gen/bkd_viter_lut.hh | 19 ++++++++++++++++++- oln/core/gen/fwd_viter_lut.hh | 21 +++++++++++++++++++-- oln/core/typedefs.hh | 14 +++++++++++++- oln/level/fill.hh | 26 ++++++++++++++++++++++++++ tests/morphers/with_lut.cc | 24 +++++++++++++++++------- 5 files changed, 93 insertions(+), 11 deletions(-) Index: tests/morphers/with_lut.cc --- tests/morphers/with_lut.cc (revision 708) +++ tests/morphers/with_lut.cc (working copy) @@ -114,7 +114,16 @@ add(1, white). add(2, c); + // Type of our image with look-up table. typedef oln::morpher::with_lut<image_t, lut_t> image_with_lut_t; + // Interface check. + mlc::assert_< + mlc_is_not_a_(image_with_lut_t, oln::abstract::mutable_image) + >::check(); + mlc::assert_< + mlc_is_a_(image_with_lut_t, + oln::abstract::mutable_image_being_value_wise_random_accessible) + >::check(); // FIXME: ``ima + lut'' doesn't work. Maybe a `using' statement is // required. image_with_lut_t ima_with_lut(ima, lut); @@ -149,14 +158,14 @@ // Check fwd_viter_lut. - oln_type_of_(image_with_lut_t, fwd_viter) fv(ima_with_lut.lut()); + oln_fwd_viter_(image_with_lut_t) fv(ima_with_lut); std::list<rgb8> fwd_values; std::cout << "values of lut (fwd) =" << std::endl; // Push the values to the *back* of the list. for_all (fv) fwd_values.push_back(fv); // Check bkd_viter_lut. - oln_type_of_(image_with_lut_t, bkd_viter) bv(ima_with_lut.lut()); + oln_bkd_viter_(image_with_lut_t) bv(ima_with_lut); std::list<rgb8> bkd_values; std::cout << "values of lut (bkd) =" << std::endl; // Push the values to the *front* of the list (i.e., in reverse order). @@ -166,9 +175,10 @@ assert (fwd_values == bkd_values); - // FIXME: To be enabled later, when oln::level::fill is specialized - // for abstract::mutable_image_being_value_wise_random_accessible. -#if 0 - oln::level::apply(ima_with_lut, fun); // 3 ops only !!! -#endif + // Test level::fill. + oln::debug::print(ima_with_lut); + std::cout << std::endl << std::endl; + // Three ops only! + oln::level::fill(ima_with_lut, blue); + oln::debug::print(ima_with_lut); } Index: oln/level/fill.hh --- oln/level/fill.hh (revision 708) +++ oln/level/fill.hh (working copy) @@ -32,6 +32,7 @@ # include <iostream> # include <oln/core/abstract/image.hh> +# include <oln/core/abstract/image/value_wise_accessibility/hierarchy.hh> # include <oln/core/abstract/iterator.hh> # include <oln/core/abstract/functions.hh> @@ -73,6 +74,11 @@ template <typename I, typename F> void fill(abstract::mutable_image<I>& input, const abstract::fun_p2v<F>& fun); + /// Fwd decl. + template <typename I> + void fill(abstract::mutable_image_being_value_wise_random_accessible<I>& input, + const oln_value(I)& value); + # ifndef OLN_INCLUDE_ONLY @@ -117,6 +123,18 @@ input(p) = fun.exact()(p); } + /// Version specialized for mutable images being value-wise + /// random accessible. + template <typename I> + void fill(abstract::mutable_image_being_value_wise_random_accessible<I>& input, + const oln_value(I)& value) + { + // FIXME: We should not need to call exact() here. + oln_viter(I) v(input.exact()); + for_all(v) + input.value(v) = value; + } + } // end of namespace oln::level::impl @@ -148,6 +166,14 @@ return impl::fill(input.exact(), fun); } + /// Facade. + template <typename I> + void fill(abstract::mutable_image_being_value_wise_random_accessible<I>& input, + const oln_value(I)& value) + { + return impl::fill(input.exact(), value); + } + # endif } // end of namespace oln::level Index: oln/core/typedefs.hh --- oln/core/typedefs.hh (revision 708) +++ oln/core/typedefs.hh (working copy) @@ -167,8 +167,9 @@ +/// Shortcuts formed such as "oln_something(T) means +/// oln_type_of(T, something)". /// \{ -/// Shortcuts formed such as "oln_something(T) means oln_type_of(T, something)". # define oln_dim(T) oln_type_of(T, dim) # define oln_dim_(T) oln_type_of_(T, dim) @@ -227,6 +228,14 @@ # define oln_bkd_niter(T) oln_type_of(T, bkd_niter) # define oln_bkd_niter_(T) oln_type_of_(T, bkd_niter) +# define oln_fwd_viter(T) oln_type_of(T, fwd_viter) +# define oln_fwd_viter_(T) oln_type_of_(T, fwd_viter) + +# define oln_bkd_viter(T) oln_type_of(T, bkd_viter) +# define oln_bkd_viter_(T) oln_type_of_(T, bkd_viter) + +/// Even shorter shortcuts. +/// \{ # define oln_piter(T) oln_type_of(T, fwd_piter) # define oln_piter_(T) oln_type_of_(T, fwd_piter) @@ -236,8 +245,11 @@ # define oln_niter(T) oln_type_of(T, fwd_niter) # define oln_niter_(T) oln_type_of_(T, fwd_niter) +# define oln_viter(T) oln_type_of(T, fwd_viter) +# define oln_viter_(T) oln_type_of_(T, fwd_viter) /// \} +/// \} // Fwd decls. Index: oln/core/gen/bkd_viter_lut.hh --- oln/core/gen/bkd_viter_lut.hh (revision 708) +++ oln/core/gen/bkd_viter_lut.hh (working copy) @@ -36,6 +36,9 @@ // Forward declaration. template <typename Lut> class bkd_viter_lut; + namespace morpher { + template <typename Image, typename Lut> struct with_lut; + } // end of namespace oln::morpher /// Super type declaration. @@ -74,8 +77,11 @@ typedef oln_type_of(self_t, value) value_type; public: - // Construct an uninitialized value iterator. + /// Construct a backward value iterator from a look-up table (LUT). bkd_viter_lut(const Lut& lut); + /// Construct a backward value iterator from an image having a LUT. + template <typename Image> + bkd_viter_lut(const morpher::with_lut<Image, Lut>& ima); /// Iterator manipulators. /// \{ @@ -116,6 +122,17 @@ this->invalidate(); } + template <typename Lut> + template <typename Image> + bkd_viter_lut<Lut>::bkd_viter_lut(const morpher::with_lut<Image, Lut>& ima) : + super_t(), + lut_(ima.lut()), + i_() + { + // Initialize underlying iterator (i.e., \a i_.) + this->invalidate(); + } + template <typename Exact> void bkd_viter_lut<Exact>::impl_start() Index: oln/core/gen/fwd_viter_lut.hh --- oln/core/gen/fwd_viter_lut.hh (revision 708) +++ oln/core/gen/fwd_viter_lut.hh (working copy) @@ -34,8 +34,11 @@ namespace oln { - // Forward declaration. + // Forward declarations. template <typename Lut> class fwd_viter_lut; + namespace morpher { + template <typename Image, typename Lut> struct with_lut; + } // end of namespace oln::morpher /// Super type declaration. @@ -74,8 +77,11 @@ typedef oln_type_of(self_t, value) value_type; public: - // Construct an uninitialized value iterator. + /// Construct a forward value iterator from a look-up table (LUT). fwd_viter_lut(const Lut& lut); + /// Construct a forward value iterator from an image having a LUT. + template <typename Image> + fwd_viter_lut(const morpher::with_lut<Image, Lut>& ima); /// Iterator manipulators. /// \{ @@ -116,6 +122,17 @@ this->invalidate(); } + template <typename Lut> + template <typename Image> + fwd_viter_lut<Lut>::fwd_viter_lut(const morpher::with_lut<Image, Lut>& ima) : + super_t(), + lut_(ima.lut()), + i_() + { + // Initialize underlying iterator (i.e., \a i_.) + this->invalidate(); + } + template <typename Exact> void fwd_viter_lut<Exact>::impl_start()