https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
Update transform routine interface.
* tests/level/transform.cc: Update test.
* mln/trait/ch_value.hh: Add a specialization for flat image.
* mln/level/transform.hh: Update transform interface.
mln/level/transform.hh | 19 +++++----
mln/trait/ch_value.hh | 16 ++++++--
tests/level/transform.cc | 93 +++++++++++++++++++++++++++++------------------
3 files changed, 83 insertions(+), 45 deletions(-)
Index: tests/level/transform.cc
--- tests/level/transform.cc (revision 2681)
+++ tests/level/transform.cc (working copy)
@@ -32,15 +32,24 @@
#include <cmath>
+#include <mln/core/image/image1d.hh>
#include <mln/core/image/image2d.hh>
+#include <mln/core/image/image3d.hh>
+#include <mln/pw/image.hh>
#include <mln/core/image/flat_image.hh>
#include <mln/core/image/image_if.hh>
+#include <mln/level/fill.hh>
#include <mln/level/transform.hh>
-#include <mln/debug/iota.hh>
+#include <mln/level/paste.hh>
+
#include <mln/core/var.hh>
#include <mln/fun/p2b/chess.hh>
+#include <mln/fun/p2v/iota.hh>
+
+#include <mln/debug/iota.hh>
+#include <mln/debug/println.hh>
struct mysqrt : mln::Function_v2v<mysqrt>
{
@@ -56,56 +65,79 @@
int main()
{
using namespace mln;
- const unsigned size = 1000;
+ const unsigned size = 50;
+ /// image 1d test
+ {
+ image1d<unsigned short> ima(size);
+ image1d<unsigned short> out(size);
+
+ debug::iota(ima);
+ out = level::transform(ima, mysqrt());
+
+ box_fwd_piter_<point1d> p(out.domain());
+ for_all(p)
+ mln_assertion((unsigned short)std::sqrt(ima(p)) == out(p));
+ }
+
+
+ /// image 2d test
{
image2d<unsigned short> ima(size, size);
image2d<unsigned short> out(size, size);
- (std::cout << "iota... ").flush();
debug::iota(ima);
- std::cout << "done" << std::endl;
+ out = level::transform(ima, mysqrt());
- (std::cout << "transform... ").flush();
- level::transform(ima, mysqrt(), out);
- std::cout << "done" << std::endl;
-
- (std::cout << "checking... ").flush();
box_fwd_piter_<point2d> p(out.domain());
for_all(p)
mln_assertion((unsigned short)std::sqrt(ima(p)) == out(p));
- std::cout << "done" << std::endl;
}
+ /// Another image2d test
{
- flat_image<short, box2d> ima(5, make::box2d(size, size));
- image2d<unsigned short> out(size, size);
+ image2d<unsigned short> ima(size, size);
- (std::cout << "fill... ").flush();
level::fill_with_value(ima, 51);
- std::cout << "done" << std::endl;
+ level::transform(ima, mysqrt());
- (std::cout << "transform... ").flush();
- level::transform(ima, mysqrt(), out);
- std::cout << "done" << std::endl;
+ }
- (std::cout << "checking... ").flush();
- box2d::piter p(out.domain());
+ /// image 3d test
+ {
+ image3d<unsigned short> ima(size, size, size);
+ image3d<unsigned short> out(size, size, size);
+
+ debug::iota(ima);
+ out = level::transform(ima, mysqrt());
+
+ box_fwd_piter_<point3d> p(out.domain());
for_all(p)
mln_assertion((unsigned short)std::sqrt(ima(p)) == out(p));
- std::cout << "done" << std::endl;
}
+ /// pw image test
{
- image2d<unsigned short> ima(size, size);
- (std::cout << "fill... ").flush();
+ const pw::image<fun::p2v::iota_t, box2d> ima(fun::p2v::iota,
+ make::box2d(2,2, 5,5));
+ image2d<short unsigned int> out(8, 8);
+
+ level::fill(out, 0);
+ out = level::transform(ima, mysqrt());
+ }
+
+ // flat image test
+ {
+ flat_image<short, box2d> ima(5, make::box2d(size, size));
+ image2d<unsigned short> out(size, size);
+
level::fill_with_value(ima, 51);
- std::cout << "done" << std::endl;
+ out = level::transform(ima, mysqrt());
- (std::cout << "transform... ").flush();
- level::transform(ima, mysqrt());
- std::cout << "done" << std::endl;
+ box2d::piter p(out.domain());
+ for_all(p)
+ mln_assertion((unsigned short)std::sqrt(ima(p)) == out(p));
}
{
@@ -117,19 +149,12 @@
II ima_if = ima | fun::p2b::chess;
level::fill_with_value(ima, 0);
- (std::cout << "iota... ").flush();
debug::iota(ima);
- std::cout << "done" << std::endl;;
-
- (std::cout << "transform... ").flush();
- level::transform(ima_if, mysqrt(), out);
- std::cout << "done" << std::endl;
+ out = level::transform(ima_if, mysqrt());
- (std::cout << "checking... ").flush();
II::piter p(ima_if.domain());
for_all(p)
mln_assertion((unsigned short)std::sqrt(ima_if(p)) == out(p));
- std::cout << "done" << std::endl;
}
}
Index: mln/trait/ch_value.hh
--- mln/trait/ch_value.hh (revision 2681)
+++ mln/trait/ch_value.hh (working copy)
@@ -157,11 +157,21 @@
typename V >
struct ch_value_< M< tag::function_<F>, tag::pset_<S> >, V
>
{
- typedef typename S::mesh mesh;
- // FIXME: from_psite instead? coord=int!?
- typedef typename image_from_mesh< mesh, V >::ret ret;
+ // FIXME: what about S::site having no grid?
+ typedef mln_deduce(S, site, grid) grid;
+ typedef typename image_from_mesh< grid, V >::ret ret;
};
+ template < template <class, class> class M, typename T, typename S,
+ typename V >
+ struct ch_value_< M< tag::value_<T>, tag::pset_<S> >, V
>
+ {
+ // FIXME: what about S::site having no grid?
+ typedef mln_deduce(S, site, grid) grid;
+ typedef typename image_from_mesh< grid, V >::ret ret;
+ };
+
+
template < template <class, class> class M, typename I, typename F,
typename V >
struct ch_value_< M< tag::image_<I>, tag::function_<F> >, V
>
Index: mln/level/transform.hh
--- mln/level/transform.hh (revision 2681)
+++ mln/level/transform.hh (working copy)
@@ -132,37 +132,40 @@
level::internal::transform_tests(input, f, output);
- // FIXME: Re-activate!
-// mlc_is(mln_trait_image_pw_io(O),
-// trait::image::pw_io::read_write)::check();
+ mlc_is(mln_trait_image_pw_io(O),
+ trait::image::pw_io::read_write)::check();
mln_piter(I) p(input.domain());
for_all(p)
output(p) = f( input(p) );
+
trace::exiting("level::impl::generic::transform");
}
} // end of namespace mln::level::impl::generic
- } // end of namespace mln::level::impl
// Facade.
+ namespace internal
+ {
template <typename I, typename F, typename O>
inline
- void transform(const Image<I>& input, const Function_v2v<F>& f,
+ void transform_(const Image<I>& input, const Function_v2v<F>&
f,
Image<O>& output)
{
trace::entering("level::transform");
mln_precondition(exact(output).domain() >= exact(input).domain());
- impl::internal::transform_dispatch(exact(input), exact(f),
- exact(output));
+ transform_dispatch(exact(input), exact(f), exact(output));
trace::exiting("level::transform");
}
+ }
+
+ } // end of namespace mln::level::impl
template <typename I, typename F>
@@ -175,7 +178,7 @@
mln_precondition(exact(input).has_data());
mln_ch_value(I, mln_result(F)) output;
initialize(output, input);
- transform(input, f, output);
+ impl::internal::transform_(input, f, output);
trace::exiting("level::transform");
return output;