cleanup-2008 2547: Reactivate dispatch in the fill_with_value algorithm.

https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Nicolas Ballas <ballas@lrde.epita.fr> Reactivate dispatch in the fill_with_value algorithm. * tests/level/fill_with_value.cc: Update. * mln/trait/images.hh, * mln/core/image/flat_image.hh, * mln/core/image/image1d.hh, * mln/core/image/image3d.hh: Update properties. * mln/level/fill_with_value.spe.hh: Add dispatch. * mln/level/fill_with_value.hh: Comment irrelevant tests. mln/core/image/flat_image.hh | 28 ++++++++++ mln/core/image/image1d.hh | 4 + mln/core/image/image3d.hh | 4 + mln/level/fill_with_value.hh | 6 +- mln/level/fill_with_value.spe.hh | 100 +++++++++++++++++++++++++++++++++++---- mln/trait/images.hh | 8 +++ tests/level/fill_with_value.cc | 34 ++++++++++++- 7 files changed, 171 insertions(+), 13 deletions(-) Index: tests/level/fill_with_value.cc --- tests/level/fill_with_value.cc (revision 2547) +++ tests/level/fill_with_value.cc (working copy) @@ -30,19 +30,49 @@ * \brief Tests on mln::level::fill_with_value */ -#include <mln/core/image/image2d.hh> #include <mln/level/fill_with_value.hh> +#include <mln/core/image/image2d.hh> +#include <mln/core/image/flat_image.hh> +#include <mln/core/image/image_if.hh> + +#include <mln/fun/p2b/chess.hh> int main() { using namespace mln; - const unsigned size = 100; + { image2d<unsigned char> ima(size, size); level::fill_with_value(ima, 51); box2d::piter p(ima.domain()); for_all(p) mln_assertion(ima(p) == 51); } + + + { + flat_image<short, box2d> ima(5, make::box2d(2, 3)); + level::fill_with_value(ima, 51); + box2d::piter p(ima.domain()); + for_all(p) + mln_assertion(ima(p) == 51); + } + + + { + typedef image2d<unsigned char> I; + typedef image_if<I, fun::p2b::chess_t> II; + + I ima(size, size); + level::fill_with_value(ima, 51); + + II ima_if = ima | fun::p2b::chess; + level::fill_with_value(ima_if, 42); + + II::piter p(ima_if.domain()); + for_all(p) + mln_assertion(ima_if(p) == 42); + } +} Index: mln/trait/images.hh --- mln/trait/images.hh (revision 2547) +++ mln/trait/images.hh (working copy) @@ -59,6 +59,10 @@ # define mln_trait_image_value_storage(I) typename mln::trait::image_< I >::value_storage # define mln_trait_image_value_browsing(I) typename mln::trait::image_< I >::value_browsing # define mln_trait_image_value_io(I) typename mln::trait::image_< I >::value_io +# define mln_trait_image_pw_io(I) typename mln::trait::image_< I >::pw_io +# define mln_trait_image_vw_io(I) typename mln::trait::image_< I >::vw_io +# define mln_trait_image_vw_set(I) typename mln::trait::image_< I >::vw_set +# define mln_trait_image_value_alignement(I) typename mln::trait::image_< I>::value_alignement # define mln_trait_image_localization(I) typename mln::trait::image_< I >::localization # define mln_trait_image_dimension(I) typename mln::trait::image_< I >::dimension @@ -122,12 +126,16 @@ typedef undef size; // value + typedef undef vw_io; + typedef undef vw_set; + typedef undef value_alignement; typedef undef value_access; typedef undef value_storage; typedef undef value_browsing; typedef undef value_io; // site + typedef undef pw_io; typedef undef localization; typedef undef dimension; Index: mln/core/image/flat_image.hh --- mln/core/image/flat_image.hh (revision 2547) +++ mln/core/image/flat_image.hh (working copy) @@ -77,12 +77,16 @@ typedef trait::image::size::regular size; // value + typedef trait::image::vw_io::read_write vw_io; + typedef trait::image::vw_set::none vw_set; typedef trait::image::value_access::direct value_access; - typedef trait::image::value_storage::one_block value_storage; + typedef trait::image::value_storage::singleton value_storage; typedef mln::trait::image::value_browsing::value_wise value_browsing; + typedef trait::image::value_alignement::with_grid value_alignement; typedef trait::image::value_io::read_only value_io; // site / domain + typedef trait::image::pw_io::read pw_io; typedef trait::image::localization::basic_grid localization; // FIXME typedef trait::image::dimension::two_d dimension; // FIXME @@ -140,6 +144,8 @@ /// Change the image value. void change_value(const T& old_val, const T& new_val); + const T& val() const; + T& val(); }; @@ -248,6 +254,26 @@ this->data_->val_ = new_val; } + template <typename T, typename S> + inline + const T& + flat_image<T,S>::val() const + { + mln_precondition(this->has_data()); + return this->data_->val_; + } + + template <typename T, typename S> + inline + T& + flat_image<T,S>::val() + { + mln_precondition(this->has_data()); + return this->data_->val_; + } + + + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln Index: mln/core/image/image1d.hh --- mln/core/image/image1d.hh (revision 2547) +++ mln/core/image/image1d.hh (working copy) @@ -93,12 +93,16 @@ typedef trait::image::size::regular size; // value + typedef trait::image::vw_io::none vw_io; + typedef trait::image::vw_set::none vw_set; typedef trait::image::value_access::direct value_access; typedef trait::image::value_storage::one_block value_storage; typedef trait::image::value_browsing::site_wise_only value_browsing; + typedef trait::image::value_alignement::with_grid value_alignement; typedef trait::image::value_io::read_write value_io; // site / domain + typedef trait::image::pw_io::read_write pw_io; typedef trait::image::localization::basic_grid localization; typedef trait::image::dimension::one_d dimension; Index: mln/core/image/image3d.hh --- mln/core/image/image3d.hh (revision 2547) +++ mln/core/image/image3d.hh (working copy) @@ -96,12 +96,16 @@ typedef trait::image::size::regular size; // value + typedef trait::image::vw_io::none vw_io; + typedef trait::image::vw_set::none vw_set; typedef trait::image::value_access::direct value_access; typedef trait::image::value_storage::one_block value_storage; typedef trait::image::value_browsing::site_wise_only value_browsing; + typedef trait::image::value_alignement::with_grid value_alignement; typedef trait::image::value_io::read_write value_io; // site / domain + typedef trait::image::pw_io::read_write pw_io; typedef trait::image::localization::basic_grid localization; typedef trait::image::dimension::three_d dimension; Index: mln/level/fill_with_value.spe.hh --- mln/level/fill_with_value.spe.hh (revision 2547) +++ mln/level/fill_with_value.spe.hh (working copy) @@ -37,6 +37,7 @@ # error "Forbidden inclusion of *.spe.hh" # endif // ! MLN_LEVEL_FILL_WITH_VALUE_HH +# include <mln/level/memset_.hh> # ifndef MLN_INCLUDE_ONLY @@ -80,11 +81,7 @@ I& ima = exact(ima_); internal::fill_with_value_tests(ima, val); - // level::memset_(ima, ima.point_at_index(0), v, ima.nelements()); - const unsigned n = ima.nelements(); - mln_value(I)* ptr = ima.buffer(); - for (unsigned i = 0; i < n; ++i) - *ptr++ = val; + level::memset_(ima, ima.point_at_index(0), val, ima.nelements()); trace::exiting("level::impl::fill_with_value_one_block"); } @@ -98,16 +95,31 @@ I& ima = exact(ima_); internal::fill_with_value_tests(ima, val); - mln_viter(I) v(ima.values()); + mln_viter(I) v(ima.cells()); for_all(v) v.change_to(val); trace::exiting("level::impl::fill_with_value_cell_wise"); } + template <typename I, typename V> + inline + void fill_with_value_singleton(Image<I>& ima_, const V& val) + { + trace::entering("level::impl::fill_with_value_singleton"); + + I& ima = exact(ima_); + internal::fill_with_value_tests(ima, val); + + ima.val() = val; + + trace::exiting("level::impl::fill_with_value_singleton"); + } + } // end of namespace mln::level::impl + // Dispatch. // --------- @@ -115,12 +127,84 @@ { template <typename I, typename V> - inline - void fill_with_value_dispatch(Image<I>& ima, const V& val) + void fill_with_value_dispatch(trait::image::value_storage::one_block, + trait::image::vw_io::any, + Image<I>& ima, const V& val) + { + if ((mlc_is(mln_trait_image_pw_io(I), + trait::image::pw_io::read_write)::value || + mlc_is(mln_trait_image_vw_io(I), + trait::image::vw_io::read_write)::value) && + mlc_is(mln_trait_image_value_access(I), + trait::image::value_access::direct)::value) + impl::fill_with_value_one_block(ima, val); + else + impl::generic::fill_with_value(ima, val); + } + + template <typename I, typename V> + void fill_with_value_dispatch(trait::image::value_storage::singleton, + trait::image::vw_io::any, + Image<I>& ima, const V& val) + { + if ((mlc_is(mln_trait_image_pw_io(I), + trait::image::pw_io::read_write)::value || + mlc_is(mln_trait_image_vw_io(I), + trait::image::vw_io::read_write)::value) && + mlc_is(mln_trait_image_value_access(I), + trait::image::value_access::direct)::value) + impl::fill_with_value_singleton(ima, val); + } + + template <typename I, typename V> + void fill_with_value_dispatch(trait::image::value_storage::piecewise, + trait::image::vw_io::any, + Image<I>& ima, const V& val) + { + /// FIXME + } + + + template <typename I, typename V> + void fill_with_value_dispatch(trait::image::value_storage::disrupted, + trait::image::vw_io::read_write, + Image<I>& ima, const V& val) + { + impl::fill_with_value_cell_wise(ima, val); + } + + + + template <typename I, typename V> + void fill_with_value_dispatch(trait::image::value_storage::disrupted, + trait::image::vw_io::read, + Image<I>& ima, const V& val) + { + impl::generic::fill_with_value(ima, val); + } + + + /// FIXME: + // This specialization is only here to deal with image which have + // non-updated properties (vw_io). + template <typename I, typename V> + void fill_with_value_dispatch(trait::image::value_storage::any, + trait::undef, + Image<I>& ima, const V& val) { impl::generic::fill_with_value(ima, val); } + + + template <typename I, typename V> + void fill_with_value_dispatch(Image<I>& ima, const V& val) + { + fill_with_value_dispatch(mln_trait_image_value_storage(I)(), + mln_trait_image_vw_io(I)(), + ima, val); + } + } // end of namespace mln::level::internal Index: mln/level/fill_with_value.hh --- mln/level/fill_with_value.hh (revision 2547) +++ mln/level/fill_with_value.hh (working copy) @@ -84,8 +84,10 @@ // is not defined. (void) ima; - mlc_is(mln_trait_image_value_io(I), - mln::trait::image::value_io::read_write)::check(); + // FIXME + //mlc_is(mln_trait_image_value_io(I), + //mln::trait::image::value_io::read_write)::check(); + mlc_converts_to(mln_exact(V), mln_value(I))::check(); mln_precondition(exact(ima).has_data()); }
participants (1)
-
Nicolas Ballas