https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
Update the transform routine.
* tests/level/transform_full.cc: Update tests.
* mln/level/transform.spe.hh,
* mln/level/transform.hh: Update, output is now directly returned.
* mln/level/stretch.hh: Update.
mln/level/stretch.hh | 2
mln/level/transform.hh | 47 ++----
mln/level/transform.spe.hh | 296 ++++++++++++++++++------------------------
tests/level/transform_full.cc | 4
4 files changed, 147 insertions(+), 202 deletions(-)
Index: tests/level/transform_full.cc
--- tests/level/transform_full.cc (revision 2780)
+++ tests/level/transform_full.cc (working copy)
@@ -76,9 +76,9 @@
{
const I& ref = exact(ref_);
- I out (ref.domain());
+ mln_ch_value(I, mln_result_(mysqrt)) out;
{
- level::transform(ref, mysqrt(), out);
+ out = level::transform(ref, mysqrt());
mln_piter(I) p (ref.domain ());
for_all(p)
mln_assertion ((mln_value(I))(ref(p) % 42) == out(p) );
Index: mln/level/transform.spe.hh
--- mln/level/transform.spe.hh (revision 2780)
+++ mln/level/transform.spe.hh (working copy)
@@ -74,27 +74,29 @@
namespace generic
{
- template <typename I, typename F, typename O>
- void transform(const Image<I>& input_,
- const Function_v2v<F>& f_,
- Image<O>& output_);
+ template <typename I, typename F>
+ mln_ch_value(I, mln_result(F))
+ transform(const Image<I>& input_,
+ const Function_v2v<F>& f_);
}
-
- template <typename I, typename F, typename O>
- void transform_lowq(const Image<I>& input_,
- const Function_v2v<F>& f_,
- Image<O>& output_)
+ template <typename I, typename F>
+ mln_ch_value(I, mln_result(F))
+ transform_lowq(const Image<I>& input_,
+ const Function_v2v<F>& f_)
{
trace::entering("level::impl::transform_lowq");
const I& input = exact(input_);
const F& f = exact(f_);
- O& output = exact(output_);
+
+ mln_precondition(exact(input).has_data());
+ mln_ch_value(I, mln_result(F)) output;
+ initialize(output, input);
level::internal::transform_tests(input, f, output);
- mlc_is(mln_trait_image_pw_io(O),
+ mlc_is(mln_trait_image_pw_io(mln_ch_value(I, mln_result(F))),
trait::image::pw_io::read_write)::check();
value::lut_vec<mln_vset(I), mln_result(F)>
@@ -105,21 +107,26 @@
output(p) = lut(input(p));
trace::exiting("level::impl::transform_lowq");
+
+ return output;
}
- template <typename I, typename F, typename O>
- void transform_taken(const Image<I>& input_,
- const Function_v2v<F>& f_,
- Image<O>& output_)
+ template <typename I, typename F>
+ mln_ch_value(I, mln_result(F))
+ transform_taken(const Image<I>& input_,
+ const Function_v2v<F>& f_)
{
trace::entering("level::impl::transform_taken");
const I& input = exact(input_);
const F& f = exact(f_);
- O& output = exact(output_);
+
+ mln_precondition(exact(input).has_data());
+ mln_ch_value(I, mln_result(F)) output;
+ initialize(output, input);
level::internal::transform_tests(input, f, output);
- mlc_is(mln_trait_image_pw_io(O),
+ mlc_is(mln_trait_image_pw_io(mln_ch_value(I, mln_result(F))),
trait::image::pw_io::read_write)::check();
value::lut_vec<mln_vset(I), mln_result(F)>
@@ -130,47 +137,56 @@
output(p) = lut(input(p));
trace::exiting("level::impl::transform_taken");
+
+ return output;
}
- template <typename I, typename F, typename O>
- void transform_singleton(const Image<I>& input_,
- const Function_v2v<F>& f_,
- Image<O>& output_)
+ template <typename I, typename F>
+ mln_ch_value(I, mln_result(F))
+ transform_singleton(const Image<I>& input_,
+ const Function_v2v<F>& f_)
{
trace::entering("level::impl::transform_singleton");
const I& input = exact(input_);
const F& f = exact(f_);
- level::internal::transform_tests(input_, f_, output_);
- mln_precondition((mlc_is(mln_trait_image_pw_io(O),
- trait::image::pw_io::read_write)::value ||
- mlc_is(mln_trait_image_vw_io(O),
- trait::image::vw_io::read_write)::value));
+ mln_precondition(exact(input).has_data());
+ mln_ch_value(I, mln_result(F)) output;
+ initialize(output, input);
+
+ level::internal::transform_tests(input_, f_, output);
mln_result(F) val = f(input.val());
- fill_with_value(output_, val);
+ fill_with_value(output, val);
trace::exiting("level::impl::transform_singleton");
+
+ return output;
}
- template <typename I, typename F, typename O>
- void transform_fast(const Image<I>& input_,
- const Function_v2v<F>& f_,
- Image<O>& output_)
+ template <typename I, typename F>
+ mln_ch_value(I, mln_result(F))
+ transform_fast(const Image<I>& input_,
+ const Function_v2v<F>& f_)
{
trace::entering("level::impl::transform_fast");
+ typedef mln_ch_value(I, mln_result(F)) O;
+
const I& input = exact(input_);
const F& f = exact(f_);
- O& output = exact(output_);
+
+ mln_precondition(exact(input).has_data());
+ mln_ch_value(I, mln_result(F)) output;
+ initialize(output, input);
+
level::internal::transform_tests(input, f, output);
mln_pixter(const I) pi(input);
mln_pixter(O) po(output);
-
po.start();
for_all(pi)
{
@@ -179,20 +195,26 @@
}
trace::exiting("level::impl::transform_fast");
+
+ return output;
}
- template <typename I, typename F, typename O>
- void transform_fast_lowq(const Image<I>& input_,
- const Function_v2v<F>& f_,
- Image<O>& output_)
+ template <typename I, typename F>
+ mln_ch_value(I, mln_result(F))
+ transform_fast_lowq(const Image<I>& input_,
+ const Function_v2v<F>& f_)
{
trace::entering("level::impl::transform_fast_lowq");
+ typedef mln_ch_value(I, mln_result(F)) O;
const I& input = exact(input_);
const F& f = exact(f_);
- O& output = exact(output_);
+
+ mln_precondition(exact(input).has_data());
+ mln_ch_value(I, mln_result(F)) output;
+ initialize(output, input);
level::internal::transform_tests(input, f, output);
@@ -210,6 +232,8 @@
}
trace::exiting("level::impl::transform_fast_lowq");
+
+ return output;
}
@@ -220,208 +244,144 @@
{
/// Deal with image not updated
- template <typename I, typename F, typename O>
+ template <typename I, typename F>
inline
- void transform_dispatch_(mln::trait::undef,
+ mln_ch_value(I, mln_result(F))
+ transform_dispatch_(mln::trait::undef,
mln::trait::image::quant::any,
const Image<I>& input,
- const Function_v2v<F>& f,
- Image<O>& output)
+ const Function_v2v<F>& f)
{
- impl::generic::transform(input, f, output);
+ return impl::generic::transform(input, f);
}
- template <typename I, typename F, typename O>
+ template <typename I, typename F>
inline
- void transform_dispatch_(mln::trait::image::vw_set::any,
+ mln_ch_value(I, mln_result(F))
+ transform_dispatch_(mln::trait::image::vw_set::any,
mln::trait::image::quant::any,
const Image<I>& input,
- const Function_v2v<F>& f,
- Image<O>& output)
+ const Function_v2v<F>& f)
{
- impl::generic::transform(input, f, output);
+ return impl::generic::transform(input, f);
}
- template <typename I, typename F, typename O>
+ template <typename I, typename F>
inline
- void transform_dispatch_(mln::trait::image::vw_set::uni,
+ mln_ch_value(I, mln_result(F))
+ transform_dispatch_(mln::trait::image::vw_set::uni,
mln::trait::image::quant::any,
const Image<I>& input,
- const Function_v2v<F>& f,
- Image<O>& output)
+ const Function_v2v<F>& f)
{
- impl::transform_taken(input, f, output);
+ return impl::transform_taken(input, f);
}
- template <typename I, typename F, typename O>
+ template <typename I, typename F>
inline
- void transform_dispatch_(mln::trait::image::vw_set::none,
+ mln_ch_value(I, mln_result(F))
+ transform_dispatch_(mln::trait::image::vw_set::any,
mln::trait::image::quant::low,
const Image<I>& input,
- const Function_v2v<F>& f,
- Image<O>& output)
+ const Function_v2v<F>& f)
{
- impl::transform_lowq(input, f, output);
+ return impl::transform_lowq(input, f);
}
- template <typename I, typename F, typename O>
- inline
- void transform_dispatch_(mln::trait::image::quant::any,
- mln::trait::image::value_access::direct,
- mln::trait::image::value_access::direct,
- mln::trait::image::ext_domain::some,
- mln::trait::image::ext_domain::some,
- const Image<I>& input_,
- const Function_v2v<F>& f,
- Image<O>& output_)
- {
- const I& input = exact(input_);
- O& output = exact(output_);
-
- if (input.domain() == output.domain())
- transform_fast(input, f, output);
- else
- transform_dispatch_(mln_trait_image_vw_set(I)(),
- mln_trait_image_quant(I)(),
- input, f, output);
- }
-
- template <typename I, typename F, typename O>
+ /// FIXME check that is right
+ template <typename I, typename F>
inline
- void transform_dispatch_(mln::trait::image::quant::any,
- mln::trait::image::value_access::direct,
+ mln_ch_value(I, mln_result(F))
+ transform_dispatch_(mln::trait::image::quant::any,
mln::trait::image::value_access::direct,
- mln::trait::image::ext_domain::none,
- mln::trait::image::ext_domain::none,
const Image<I>& input,
- const Function_v2v<F>& f,
- Image<O>& output)
+ const Function_v2v<F>& f)
{
- transform_fast(input, f, output);
- }
-
- template <typename I, typename F, typename O>
- inline
- void transform_dispatch_(mln::trait::image::quant::low,
- mln::trait::image::value_access::direct,
- mln::trait::image::value_access::direct,
- mln::trait::image::ext_domain::some,
- mln::trait::image::ext_domain::some,
- const Image<I>& input_,
- const Function_v2v<F>& f,
- Image<O>& output_)
- {
- const I& input = exact(input_);
- O& output = exact(output_);
-
- if (input.domain() == output.domain())
- transform_fast_lowq(input, f, output);
- else
- transform_dispatch_(mln_trait_image_vw_set(I)(),
- mln_trait_image_quant(I)(),
- input, f, output);
+ return transform_fast(input, f);
}
- template <typename I, typename F, typename O>
+ /// FIXME check that is right
+ template <typename I, typename F>
inline
- void transform_dispatch_(mln::trait::image::quant::low,
+ mln_ch_value(I, mln_result(F))
+ transform_dispatch_(mln::trait::image::quant::low,
mln::trait::image::value_access::direct,
- mln::trait::image::value_access::direct,
- mln::trait::image::ext_domain::none,
- mln::trait::image::ext_domain::none,
const Image<I>& input,
- const Function_v2v<F>& f,
- Image<O>& output)
+ const Function_v2v<F>& f)
{
- transform_fast_lowq(input, f, output);
+ return transform_fast_lowq(input, f);
}
- template <typename I, typename F, typename O>
+
+ template <typename I, typename F>
inline
- void transform_dispatch_(mln::trait::image::quant::any,
- mln::trait::image::value_access::any,
+ mln_ch_value(I, mln_result(F))
+ transform_dispatch_(mln::trait::image::quant::any,
mln::trait::image::value_access::any,
- mln::trait::image::ext_domain::any,
- mln::trait::image::ext_domain::any,
const Image<I>& input,
- const Function_v2v<F>& f,
- Image<O>& output)
+ const Function_v2v<F>& f)
{
- transform_dispatch_(mln_trait_image_vw_set(I)(),
+ return transform_dispatch_(mln_trait_image_vw_set(I)(),
mln_trait_image_quant(I)(),
- input, f, output);
+ input, f);
}
- template <typename I, typename F, typename O>
+ template <typename I, typename F>
inline
- void transform_dispatch_(mln::trait::image::value_storage::any,
- mln::trait::image::value_storage::any,
+ mln_ch_value(I, mln_result(F))
+ transform_dispatch_(mln::trait::image::value_storage::any,
const Image<I>& input,
- const Function_v2v<F>& f,
- Image<O>& output)
+ const Function_v2v<F>& f)
{
- transform_dispatch_(mln_trait_image_vw_set(I)(),
+ return transform_dispatch_(mln_trait_image_vw_set(I)(),
mln_trait_image_quant(I)(),
- input, f, output);
+ input, f);
}
- template <typename I, typename F, typename O>
+ template <typename I, typename F>
inline
- void transform_dispatch_(mln::trait::image::value_storage::singleton,
- mln::trait::image::value_storage::any,
+ mln_ch_value(I, mln_result(F))
+ transform_dispatch_(mln::trait::image::value_storage::singleton,
const Image<I>& input,
- const Function_v2v<F>& f,
- Image<O>& output)
+ const Function_v2v<F>& f)
{
- transform_singleton(input, f, output);
+ return transform_singleton(input, f);
}
- template <typename I, typename F, typename O>
+ template <typename I, typename F>
inline
- void transform_dispatch_(mln::trait::image::value_storage::one_block,
- mln::trait::image::value_storage::one_block,
+ mln_ch_value(I, mln_result(F))
+ transform_dispatch_(mln::trait::image::value_storage::one_block,
const Image<I>& input_,
- const Function_v2v<F>& f_,
- Image<O>& output_)
+ const Function_v2v<F>& f_)
{
const I& input = exact(input_);
- O& output = exact(output_);
-
- /// Check basic properties
+ /// Check alignement property
if (mlc_is(mln_trait_image_value_alignement(I),
- trait::image::value_alignement::with_grid)::value &&
- mlc_is(mln_trait_image_value_alignement(O),
trait::image::value_alignement::with_grid)::value)
- {
- transform_dispatch_(mln_trait_image_quant(I)(),
+ return transform_dispatch_(mln_trait_image_quant(I)(),
mln_trait_image_value_access(I)(),
- mln_trait_image_value_access(O)(),
- mln_trait_image_ext_domain(I)(),
- mln_trait_image_ext_domain(O)(),
- input, f_, output);
- }
+ input, f_);
else
- transform_dispatch_(mln_trait_image_vw_set(I)(),
+ return transform_dispatch_(mln_trait_image_vw_set(I)(),
mln_trait_image_quant(I)(),
- input, f_, output);
+ input, f_);
}
- template <typename I, typename F, typename O>
- inline
- void transform_dispatch_(const Image<I>& input,
- const Function_v2v<F>& f,
- Image<O>& output)
- {
- transform_dispatch_(mln_trait_image_value_storage(I)(),
- mln_trait_image_value_storage(O)(),
- input, f, output);
+ template <typename I, typename F>
+ mln_ch_value(I, mln_result(F))
+ transform_dispatch_(const Image<I>& input,
+ const Function_v2v<F>& f)
+ {
+ return transform_dispatch_(mln_trait_image_value_storage(I)(),
+ input, f);
}
}
Index: mln/level/transform.hh
--- mln/level/transform.hh (revision 2780)
+++ mln/level/transform.hh (working copy)
@@ -93,11 +93,10 @@
(void) output;
// Properties check
- // FIXME: Re-activate!
-// mln_precondition((mlc_is(mln_trait_image_pw_io(O),
-// trait::image::pw_io::read_write)::value ||
-// mlc_is(mln_trait_image_vw_io(O),
-// trait::image::vw_io::read_write)::value));
+ mln_precondition((mlc_is(mln_trait_image_pw_io(O),
+ trait::image::pw_io::read_write)::value ||
+ mlc_is(mln_trait_image_vw_io(O),
+ trait::image::vw_io::read_write)::value));
// FIXME Convert test
mlc_converts_to(mln_result(F), mln_value(O))::check();
@@ -118,29 +117,31 @@
{
// Generic implementation.
- template <typename I, typename F, typename O>
+ template <typename I, typename F>
inline
- void transform(const Image<I>& input_, const Function_v2v<F>& f_,
- Image<O>& output_)
+ mln_ch_value(I, mln_result(F))
+ transform(const Image<I>& input_, const Function_v2v<F>& f_)
{
trace::entering("level::impl::generic::transform");
-
const I& input = exact(input_);
const F& f = exact(f_);
- O& output = exact(output_);
- level::internal::transform_tests(input, f, output);
+ mln_precondition(exact(input).has_data());
+ mln_ch_value(I, mln_result(F)) output;
+ initialize(output, input);
- mlc_is(mln_trait_image_pw_io(O),
+ level::internal::transform_tests(input, f, output);
+ mlc_is(mln_trait_image_pw_io(mln_ch_value(I, mln_result(F))),
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");
+
+ return output;
}
} // end of namespace mln::level::impl::generic
@@ -150,21 +151,6 @@
// Facade.
- template <typename I, typename F, typename O>
- inline
- 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));
-
- trace::exiting("level::transform");
- }
-
-
-
template <typename I, typename F>
inline
mln_ch_value(I, mln_result(F))
@@ -172,12 +158,11 @@
{
trace::entering("level::transform");
- mln_precondition(exact(input).has_data());
mln_ch_value(I, mln_result(F)) output;
- initialize(output, input);
- transform(input, f, output);
+ output = impl::internal::transform_dispatch_(exact(input), exact(f));
trace::exiting("level::transform");
+
return output;
}
Index: mln/level/stretch.hh
--- mln/level/stretch.hh (revision 2780)
+++ mln/level/stretch.hh (working copy)
@@ -81,7 +81,7 @@
float a = (M - m) / (max - min);
float b = (m * max - M * min) / (max - min);
fun::v2v::linear<float, float, int> f(a, b);
- level::transform(input, f, output);
+ output = level::transform(input, f);
}
trace::exiting("level::impl::stretch");
}