cleanup-2008 2653: Make extension images and cast image work with fill_with_value routine.

https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Nicolas Ballas <ballas@lrde.epita.fr> Make extension images and cast image work with fill_with_value routine. * tests/level/fill_with_value.cc: Add tests. * mln/core/image/status.txt: Update documentation. * mln/core/image/extension_fun.hh, * mln/core/image/cast_image.hh, * mln/core/image/extension_ima.hh, * mln/core/image/extension_val.hh: Fix properties. * mln/level/fill_with_value.spe.hh: Fix dispatch. * mln/level/fill_with_value.hh: Add a static tests. mln/core/image/cast_image.hh | 26 +++++++++++++++- mln/core/image/extension_fun.hh | 1 mln/core/image/extension_ima.hh | 1 mln/core/image/extension_val.hh | 1 mln/core/image/status.txt | 6 +++ mln/level/fill_with_value.hh | 5 +-- mln/level/fill_with_value.spe.hh | 27 +++++++++++++---- tests/level/fill_with_value.cc | 61 +++++++++++++++++++++++++++++++++++++-- 8 files changed, 114 insertions(+), 14 deletions(-) Index: tests/level/fill_with_value.cc --- tests/level/fill_with_value.cc (revision 2653) +++ tests/level/fill_with_value.cc (working copy) @@ -30,27 +30,55 @@ * \brief Tests on mln::level::fill_with_value */ + #include <mln/level/fill_with_value.hh> +#include <mln/core/image/image1d.hh> #include <mln/core/image/image2d.hh> +#include <mln/core/image/image3d.hh> #include <mln/core/image/flat_image.hh> #include <mln/core/image/image_if.hh> +#include <mln/core/image/sub_image.hh> +#include <mln/core/image/extension_val.hh> +#include <mln/value/rgb8.hh> #include <mln/fun/p2b/chess.hh> +#include <mln/make/box2d.hh> + int main() { using namespace mln; - const unsigned size = 100; + const unsigned size = 50; { - image2d<unsigned char> ima(size, size); + typedef image1d<unsigned char> I; + I ima(size); level::fill_with_value(ima, 51); - box2d::piter p(ima.domain()); + mln_piter_(I) p(ima.domain()); + for_all(p) + mln_assertion(ima(p) == 51); + } + + + { + typedef image2d<unsigned char> I; + I ima(size, size); + level::fill_with_value(ima, 51); + mln_piter_(I) p(ima.domain()); for_all(p) mln_assertion(ima(p) == 51); } + { + typedef image3d<value::rgb8> I; + I ima(size, size, size); + level::fill_with_value(ima, value::rgb8(255, 0, 255)); + mln_piter_(I) p(ima.domain()); + for_all(p) + mln_assertion(ima(p) == value::rgb8(255, 0, 255)); + } + { flat_image<short, box2d> ima(5, make::box2d(2, 3)); @@ -75,4 +103,31 @@ for_all(p) mln_assertion(ima_if(p) == 42); } + + { + typedef image2d<int> I; + typedef sub_image< image2d<int>, box2d > II; + I ima(size, size); + II sub_ima(ima, make::box2d(4,4, 10,10)); + + level::fill_with_value(sub_ima, 5); + + II::piter p(sub_ima.domain()); + for_all(p) + mln_assertion(sub_ima(p) == 5); + } + + { + typedef image2d<int> I; + typedef extension_val< image2d<int> > II; + I ima(size, size); + II extend_ima(ima, 5); + + level::fill_with_value(extend_ima, 51); + + II::piter p(extend_ima.domain()); + for_all(p) + mln_assertion(extend_ima(p) == 51); + } + } Index: mln/core/image/extension_fun.hh --- mln/core/image/extension_fun.hh (revision 2653) +++ mln/core/image/extension_fun.hh (working copy) @@ -74,6 +74,7 @@ // ...these changes. typedef trait::image::category::identity_morpher category; typedef mln_internal_trait_image_speed_from(I) speed; // Un-fastest. + typedef trait::image::value_access::indirect value_access; // extended domain typedef trait::image::ext_domain::infinite ext_domain; Index: mln/core/image/cast_image.hh --- mln/core/image/cast_image.hh (revision 2653) +++ mln/core/image/cast_image.hh (working copy) @@ -65,10 +65,34 @@ namespace trait { + template <typename T, typename I, typename value_io> + struct cast_image_trait_selector : + default_image_morpher< I, T, cast_image_<T,I> > + { + typedef trait::image::vw_io::none vw_io; + typedef trait::image::vw_set::none vw_set; + }; + + template <typename T, typename I> + struct cast_image_trait_selector<T, I, trait::image::vw_io::read> : + default_image_morpher< I, T, cast_image_<T,I> > + { + typedef trait::image::vw_io::read vw_io; + }; + + template <typename T, typename I> + struct cast_image_trait_selector<T, I, trait::image::vw_io::read_write> : + default_image_morpher< I, T, cast_image_<T,I> > + { + typedef trait::image::vw_io::read vw_io; + }; + template <typename T, typename I> - struct image_< cast_image_<T,I> > : default_image_morpher< I, T, cast_image_<T,I> > + struct image_< cast_image_<T,I> > : + cast_image_trait_selector<T, I, mln_trait_image_vw_io(I)> { typedef trait::image::value_io::read_only value_io; + typedef trait::image::pw_io::read pw_io; }; } // end of namespace mln::trait Index: mln/core/image/status.txt --- mln/core/image/status.txt (revision 2653) +++ mln/core/image/status.txt (working copy) @@ -20,6 +20,8 @@ ok image1d ok image3d +ok flat_image + ** run-based KO mono_obased_rle_image @@ -39,7 +41,7 @@ ** value morpher -OK cast_image +ok cast_image KO value::stack_image ** domain morpher @@ -63,6 +65,8 @@ ok plain ok safe +ok extended + KO decorated_image KO interpolated Index: mln/core/image/extension_ima.hh --- mln/core/image/extension_ima.hh (revision 2653) +++ mln/core/image/extension_ima.hh (working copy) @@ -75,6 +75,7 @@ // ...these changes. typedef trait::image::category::identity_morpher category; typedef mln_internal_trait_image_speed_from(I) speed; // Un-fastest. + typedef trait::image::value_access::indirect value_access; // extended domain typedef trait::image::ext_domain::extendable ext_domain; Index: mln/core/image/extension_val.hh --- mln/core/image/extension_val.hh (revision 2653) +++ mln/core/image/extension_val.hh (working copy) @@ -73,6 +73,7 @@ // ...these changes. typedef trait::image::category::identity_morpher category; typedef mln_internal_trait_image_speed_from(I) speed; // Un-fastest. + typedef trait::image::value_access::indirect value_access; // extended domain typedef trait::image::ext_domain::infinite ext_domain; Index: mln/level/fill_with_value.spe.hh --- mln/level/fill_with_value.spe.hh (revision 2653) +++ mln/level/fill_with_value.spe.hh (working copy) @@ -142,22 +142,37 @@ { template <typename I, typename V> - void fill_with_value_dispatch(trait::image::value_storage::one_block, - trait::image::vw_io::any, + void fill_with_value_dispatch(trait::image::value_access::direct, Image<I>& ima, const V& val) { - if ((mlc_is(mln_trait_image_pw_io(I), + 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) + trait::image::vw_io::read_write)::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_access::any, + Image<I>& ima, const V& val) + { + impl::generic::fill_with_value(ima, val); + } + + + + template <typename I, typename V> + void fill_with_value_dispatch(trait::image::value_storage::one_block, + trait::image::vw_io::any, + Image<I>& ima, const V& val) + { + fill_with_value_dispatch(mln_trait_image_value_access(I)(), + 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) Index: mln/level/fill_with_value.hh --- mln/level/fill_with_value.hh (revision 2653) +++ mln/level/fill_with_value.hh (working copy) @@ -102,9 +102,8 @@ I& ima = exact(ima_); internal::fill_with_value_tests(ima, val); - // FIXME: activate this test - //mlc_is(mln_trait_image_pw_io(I), - //trait::image::pw_io::read_write)::check(); + mlc_is(mln_trait_image_pw_io(I), + trait::image::pw_io::read_write)::check(); mln_value(I) v = exact(val); mln_piter(I) p(ima.domain());
participants (1)
-
Nicolas Ballas