Commit f26a1512 authored by Thierry Geraud's avatar Thierry Geraud
Browse files

Overload accu image set_value and clean up a bit.

	* mln/accu/image/set_value.hh (set_value_tests): New.
	(set_value, set_value_fastest, set_value_dispatch):
	Overload for 'res' as image.
	(set_value): Add static checks.
	Use set_value_tests.
	* mln/accu/image/take_as_init.hh (take_as_init_tests): New.
	(take_as_init): Update.
	(take_as_init_dispatch): Fix missing test over domains.
	* mln/accu/count.hh (trait): New overload.
	* tests/accu/image/set_value.cc: Augment.
	* tests/accu/image/take_as_init.cc: Augment.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@3746 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 5b74ff7a
2009-05-04 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Overload accu image set_value and clean up a bit.
* mln/accu/image/set_value.hh (set_value_tests): New.
(set_value, set_value_fastest, set_value_dispatch):
Overload for 'res' as image.
(set_value): Add static checks.
Use set_value_tests.
* mln/accu/image/take_as_init.hh (take_as_init_tests): New.
(take_as_init): Update.
(take_as_init_dispatch): Fix missing test over domains.
* mln/accu/count.hh (trait): New overload.
* tests/accu/image/set_value.cc: Augment.
* tests/accu/image/take_as_init.cc: Augment.
2009-05-04 Thierry Geraud <thierry.geraud@lrde.epita.fr>
 
A couple of bug fix.
......@@ -40,6 +40,27 @@
namespace mln
{
// Forward declaration.
namespace accu { template <typename T> struct count; }
// Traits.
namespace trait
{
template <typename T>
struct accumulator_< accu::count<T> >
{
typedef accumulator::has_untake::yes has_untake;
typedef accumulator::has_set_value::yes has_set_value;
typedef accumulator::has_stop::no has_stop;
typedef accumulator::when_pix::use_pix when_pix;
};
} // end of namespace mln::trait
namespace accu
{
......
......@@ -49,28 +49,61 @@ namespace mln
template <typename I>
void
set_value(Image<I>& input,
const mln_deduce(I, value, result)& res);
set_value(Image<I>& input, const mln_deduce(I, value, result)& res);
template <typename I, typename J>
void
set_value(Image<I>& input, const Image<J>& res);
# ifndef MLN_INCLUDE_ONLY
// Tests.
namespace internal
{
template <typename I, typename J>
inline
void
set_value_tests(Image<I>& input_, const Image<J>& res_)
{
I& input = exact(input_);
const J& res = exact(res_);
mln_precondition(input.is_valid());
mln_precondition(res.is_valid());
mln_precondition(res.domain() <= input.domain());
(void) input;
(void) res;
}
} // end of namespace mln::accu::image::internal
namespace impl
{
// Generic version.
// Generic versions.
namespace generic
{
template <typename I>
inline
void
set_value(Image<I>& input_,
const mln_deduce(I, value, result)& res)
set_value(Image<I>& input_, const mln_deduce(I, value, result)& res)
{
trace::entering("accu::impl::image::generic::set_value");
mlc_is_a(mln_value(I), Accumulator)::check();
typedef mln_value(I) A;
mlc_is_a(A, Accumulator)::check();
mlc_equal(mln_trait_accumulator_has_set_value(A),
trait::accumulator::has_set_value::yes)::check();
I& input = exact(input_);
mln_precondition(input.is_valid());
......@@ -82,19 +115,47 @@ namespace mln
trace::exiting("accu::impl::image::generic::set_value");
}
template <typename I, typename J>
inline
void
set_value(Image<I>& input_, const Image<J>& res_)
{
trace::entering("accu::impl::image::generic::set_value");
typedef mln_value(I) A;
mlc_is_a(A, Accumulator)::check();
mlc_equal(mln_trait_accumulator_has_set_value(A),
trait::accumulator::has_set_value::yes)::check();
mlc_converts_to(mln_value(J), mln_deduce(I, value, result))::check();
I& input = exact(input_);
const J& res = exact(res_);
internal::set_value_tests(input, res);
mln_piter(I) p(res.domain());
for_all(p)
input(p).set_value(res(p));
trace::exiting("accu::impl::image::generic::set_value");
}
} // end of namespace mln::accu::image::impl::generic
// Fastest version.
// Fastest versions.
template <typename I>
inline
void
set_value_fastest(Image<I>& input_,
const mln_deduce(I, value, result)& res)
set_value_fastest(Image<I>& input_, const mln_deduce(I, value, result)& res)
{
trace::entering("accu::impl::image::set_value_fastest");
mlc_is_a(mln_value(I), Accumulator)::check();
typedef mln_value(I) A;
mlc_is_a(A, Accumulator)::check();
mlc_equal(mln_trait_accumulator_has_set_value(A),
trait::accumulator::has_set_value::yes)::check();
I& input = exact(input_);
mln_precondition(input.is_valid());
......@@ -106,6 +167,33 @@ namespace mln
trace::exiting("accu::impl::image::set_value_fastest");
}
template <typename I, typename J>
inline
void
set_value_fastest(Image<I>& input_, const Image<J>& res_)
{
trace::entering("accu::impl::image::set_value_fastest");
typedef mln_value(I) A;
mlc_is_a(A, Accumulator)::check();
mlc_equal(mln_trait_accumulator_has_set_value(A),
trait::accumulator::has_set_value::yes)::check();
mlc_converts_to(mln_value(J), mln_deduce(I, value, result))::check();
I& input = exact(input_);
const J& res = exact(res_);
internal::set_value_tests(input, res);
mln_precondition(res.domain() == input.domain());
mln_pixter(I) p_in(input);
mln_pixter(const J) p_res(res);
for_all_2(p_in, p_res)
p_in.val().set_value(p_res.val());
trace::exiting("accu::impl::image::set_value_fastest");
}
} // end of namespace mln::accu::image::impl
......@@ -115,43 +203,85 @@ namespace mln
namespace internal
{
template <typename I, typename V>
// 'res' as value.
template <typename I>
inline
void
set_value_dispatch(trait::image::speed::any,
Image<I>& input, const V& res)
Image<I>& input, const mln_deduce(I, value, result)& res)
{
impl::generic::set_value(input, res);
}
template <typename I, typename V>
template <typename I>
void
set_value_dispatch(trait::image::speed::fastest,
Image<I>& input, const V& res)
Image<I>& input, const mln_deduce(I, value, result)& res)
{
impl::set_value_fastest(input, res);
}
template <typename I, typename V>
template <typename I>
inline
void
set_value_dispatch(Image<I>& input, const mln_deduce(I, value, result)& res)
{
set_value_dispatch(mln_trait_image_speed(I)(),
input, res);
}
// 'res' as image.
template <typename I, typename J>
inline
void
set_value_dispatch(trait::image::speed::any,
trait::image::speed::any,
Image<I>& input, const Image<J>& res)
{
impl::generic::set_value(input, res);
}
template <typename I, typename J>
inline
void
set_value_dispatch(trait::image::speed::fastest,
trait::image::speed::fastest,
Image<I>& input, const Image<J>& res)
{
if (exact(res).domain() == exact(input).domain())
impl::set_value_fastest(input, res);
else
impl::generic::set_value(input, res);
}
template <typename I, typename J>
inline
void
set_value_dispatch(Image<I>& input, const V& res)
set_value_dispatch(Image<I>& input, const Image<J>& res)
{
set_value_dispatch(mln_trait_image_speed(I)(),
mln_trait_image_speed(J)(),
input, res);
}
} // end of namespace mln::accu::image::internal
// Facade.
// Facades.
template <typename I>
inline
void
set_value(Image<I>& input,
const mln_deduce(I, value, result)& res)
set_value(Image<I>& input, const mln_deduce(I, value, result)& res)
{
trace::entering("accu::image::set_value");
mlc_is_a(mln_value(I), Accumulator)::check();
typedef mln_value(I) A;
mlc_is_a(A, Accumulator)::check();
mlc_equal(mln_trait_accumulator_has_set_value(A),
trait::accumulator::has_set_value::yes)::check();
mln_precondition(exact(input).is_valid());
internal::set_value_dispatch(input, res);
......@@ -159,6 +289,25 @@ namespace mln
trace::exiting("accu::image::set_value");
}
template <typename I, typename J>
inline
void
set_value(Image<I>& input, const Image<J>& res)
{
trace::entering("accu::image::set_value");
typedef mln_value(I) A;
mlc_is_a(A, Accumulator)::check();
mlc_equal(mln_trait_accumulator_has_set_value(A),
trait::accumulator::has_set_value::yes)::check();
mlc_converts_to(mln_value(J), mln_deduce(I, value, result))::check();
internal::set_value_tests(input, res);
internal::set_value_dispatch(input, res);
trace::exiting("accu::image::set_value");
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::accu::image
......
......@@ -47,18 +47,41 @@ namespace mln
template <typename I>
void
take_as_init(Image<I>& input,
const mln_deduce(I, value, argument)& v);
take_as_init(Image<I>& input, const mln_deduce(I, value, argument)& v);
template <typename I, typename J>
void
take_as_init(Image<I>& input,
const Image<J>& values);
take_as_init(Image<I>& input, const Image<J>& values);
# ifndef MLN_INCLUDE_ONLY
// Tests.
namespace internal
{
template <typename I, typename J>
inline
void
take_as_init_tests(Image<I>& input_, const Image<J>& values_)
{
I& input = exact(input_);
const J& values = exact(values_);
mln_precondition(input.is_valid());
mln_precondition(values.is_valid());
mln_precondition(values.domain() <= input.domain());
(void) input;
(void) values;
}
} // end of namespace mln::accu::image::internal
namespace impl
{
......@@ -69,11 +92,12 @@ namespace mln
template <typename I>
void
take_as_init(Image<I>& input_,
const mln_deduce(I, value, argument)& v)
take_as_init(Image<I>& input_, const mln_deduce(I, value, argument)& v)
{
trace::entering("accu::impl::image::generic::take_as_init");
mlc_is_a(mln_value(I), Accumulator)::check();
I& input = exact(input_);
mln_precondition(input.is_valid());
......@@ -86,17 +110,20 @@ namespace mln
template <typename I, typename J>
void
take_as_init(Image<I>& input_,
const Image<J>& values_)
take_as_init(Image<I>& input_, const Image<J>& values_)
{
trace::entering("accu::impl::image::generic::take_as_init");
typedef mln_value(I) A;
mlc_is_a(A, Accumulator)::check();
mlc_converts_to(mln_value(J), mln_argument(A))::check();
I& input = exact(input_);
const I& values = exact(values_);
mln_precondition(input.is_valid());
mln_precondition(values.is_valid());
const J& values = exact(values_);
mln_piter(I) p(input.domain());
internal::take_as_init_tests(input, values);
mln_piter(I) p(values.domain());
for_all(p)
input(p).take_as_init(values(p));
......@@ -110,11 +137,12 @@ namespace mln
template <typename I>
void
take_as_init_fastest(Image<I>& input_,
const mln_deduce(I, value, argument)& v)
take_as_init_fastest(Image<I>& input_, const mln_deduce(I, value, argument)& v)
{
trace::entering("accu::impl::image::take_as_init_fastest");
mlc_is_a(mln_value(I), Accumulator)::check();
I& input = exact(input_);
mln_precondition(input.is_valid());
......@@ -127,15 +155,20 @@ namespace mln
template <typename I, typename J>
void
take_as_init_fastest(Image<I>& input_,
const Image<J>& values_)
take_as_init_fastest(Image<I>& input_, const Image<J>& values_)
{
trace::entering("accu::impl::image::take_as_init_fastest");
typedef mln_value(I) A;
mlc_is_a(A, Accumulator)::check();
mlc_converts_to(mln_value(J), mln_argument(A))::check();
I& input = exact(input_);
const I& values = exact(values_);
mln_precondition(input.is_valid());
mln_precondition(values.is_valid());
const J& values = exact(values_);
internal::take_as_init_tests(input, values);
// Extra test:
mln_precondition(values.domain() == input.domain());
mln_pixter(I) p_in(input);
mln_pixter(const J) p_v(values);
......@@ -202,7 +235,10 @@ namespace mln
trait::image::speed::fastest,
Image<I>& input, const Image<J>& values)
{
impl::take_as_init_fastest(input, values);
if (exact(values).domain() == exact(input).domain())
impl::take_as_init_fastest(input, values);
else
impl::generic::take_as_init(input, values);
}
template <typename I, typename J>
......@@ -224,8 +260,7 @@ namespace mln
template <typename I>
inline
void
take_as_init(Image<I>& input,
const mln_deduce(I, value, argument)& v)
take_as_init(Image<I>& input, const mln_deduce(I, value, argument)& v)
{
trace::entering("accu::image::take_as_init");
......@@ -240,8 +275,7 @@ namespace mln
template <typename I, typename J>
inline
void
take_as_init(Image<I>& input,
const Image<J>& values)
take_as_init(Image<I>& input, const Image<J>& values)
{
trace::entering("accu::image::take_as_init");
......@@ -249,10 +283,7 @@ namespace mln
mlc_is_a(A, Accumulator)::check();
mlc_converts_to(mln_value(J), mln_argument(A))::check();
mln_precondition(exact(input).is_valid());
mln_precondition(exact(values).is_valid());
// mln_precondition(exact(values).domain() == exact(input).domain());
internal::take_as_init_tests(input, values);
internal::take_as_init_dispatch(input, values);
trace::exiting("accu::image::take_as_init");
......
......@@ -47,4 +47,10 @@ int main()
accu::image::set_value(ima, 3);
mln_assertion(ima == (pw::cst(3u) | ima.domain()));
image2d<unsigned> res(1, 1);
res.at_(0, 0) = 51;
accu::image::set_value(ima, res);
mln_assertion(ima.at_(0, 0) == 51);
}
......@@ -50,4 +50,7 @@ int main()
accu::image::take_as_init(ima, ima);
mln_assertion(ima == (pw::cst(3) | ima.domain()));
accu::image::take_as_init(ima, pw::cst(3) | ima.domain());
mln_assertion(ima == (pw::cst(3) | ima.domain()));
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment