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

Cleanup accu::image and add take_n_times.

	* mln/accu/image/take.hh: Copy to...
	* mln/accu/image/take_n_times.hh: ...this new file.
	Update.
	* mln/accu/image/all.hh: Update.
	* mln/accu/image/init.hh,
	* mln/accu/image/set_value.hh,
	* mln/accu/image/to_result.hh: Fix missing static checks.
	* mln/accu/image/take.hh (todo): New.
	(take_tests): New.
	(generic::take, take_fastest): Update.
	Fix missing static checks.

	* tests/accu/image/to_result.cc,
	* tests/accu/image/init.cc,
	* tests/accu/image/take.cc,
	* tests/accu/image/set_value.cc,
	* tests/accu/image/take_as_init.cc:
	Change debug log into quiet test.
	* tests/accu/image/take_n_times.cc: New.
	* tests/accu/image/Makefile.am: Update.

	* mln/border/resize_equal.hh: New.
	* mln/border/all.hh: Update.
	* tests/border/resize_equal.cc: New.
	* tests/border/resize.cc: Cleanup.
	* tests/border/Makefile.am: Update.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@3739 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 07d88f3a
2009-04-30 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Cleanup accu::image and add take_n_times.
* mln/accu/image/take.hh: Copy to...
* mln/accu/image/take_n_times.hh: ...this new file.
Update.
* mln/accu/image/all.hh: Update.
* mln/accu/image/init.hh,
* mln/accu/image/set_value.hh,
* mln/accu/image/to_result.hh: Fix missing static checks.
* mln/accu/image/take.hh (todo): New.
(take_tests): New.
(generic::take, take_fastest): Update.
Fix missing static checks.
* tests/accu/image/to_result.cc,
* tests/accu/image/init.cc,
* tests/accu/image/take.cc,
* tests/accu/image/set_value.cc,
* tests/accu/image/take_as_init.cc:
Change debug log into quiet test.
* tests/accu/image/take_n_times.cc: New.
* tests/accu/image/Makefile.am: Update.
* mln/border/resize_equal.hh: New.
* mln/border/all.hh: Update.
* tests/border/resize_equal.cc: New.
* tests/border/resize.cc: Cleanup.
* tests/border/Makefile.am: Update.
2009-04-30 Thierry Geraud <thierry.geraud@lrde.epita.fr>
 
Fix wrong update in morpho attribute card.
......@@ -50,6 +50,7 @@ namespace mln
# include <mln/accu/image/set_value.hh>
# include <mln/accu/image/take_as_init.hh>
# include <mln/accu/image/take.hh>
# include <mln/accu/image/take_n_times.hh>
# include <mln/accu/image/to_result.hh>
......
......@@ -67,6 +67,8 @@ namespace mln
{
trace::entering("accu::impl::image::generic::init");
mlc_is_a(mln_value(I), Accumulator)::check();
I& input = exact(input_);
mln_precondition(input.is_valid());
......@@ -87,6 +89,8 @@ namespace mln
init_fastest(Image<I>& input_)
{
trace::entering("accu::impl::image::init_fastest");
mlc_is_a(mln_value(I), Accumulator)::check();
I& input = exact(input_);
mln_precondition(input.is_valid());
......
......@@ -31,6 +31,8 @@
/// \file mln/accu/image/set_value.hh
///
/// Set the values of an image of accumulators.
///
/// \todo Add "set_value(Image<I>& input, const Image<J>& values)".
# include <mln/core/concept/accumulator.hh>
# include <mln/core/concept/image.hh>
......@@ -51,7 +53,6 @@ namespace mln
const mln_deduce(I, value, result)& res);
# ifndef MLN_INCLUDE_ONLY
namespace impl
......@@ -69,6 +70,8 @@ namespace mln
{
trace::entering("accu::impl::image::generic::set_value");
mlc_is_a(mln_value(I), Accumulator)::check();
I& input = exact(input_);
mln_precondition(input.is_valid());
......@@ -90,6 +93,8 @@ namespace mln
const mln_deduce(I, value, result)& res)
{
trace::entering("accu::impl::image::set_value_fastest");
mlc_is_a(mln_value(I), Accumulator)::check();
I& input = exact(input_);
mln_precondition(input.is_valid());
......
......@@ -32,9 +32,12 @@
///
/// Update an image of accumulators by taking the contents of another
/// image.
///
/// \todo Add "take(input, arg_value)".
# include <mln/core/concept/accumulator.hh>
# include <mln/core/concept/image.hh>
# include <mln/border/resize_equal.hh>
namespace mln
......@@ -54,6 +57,34 @@ namespace mln
# ifndef MLN_INCLUDE_ONLY
// Tests.
namespace internal
{
template <typename I, typename J>
void
take_tests(Image<I>& input_, const Image<J>& arg_)
{
I& input = exact(input_);
const J& arg = exact(arg_);
mln_precondition(input.is_valid());
mln_precondition(arg.is_valid());
mln_precondition(arg.domain() <= input.domain());
(void) input;
(void) arg;
}
} // end of namespace mln::accu::image::internal
// Implementations.
namespace impl
{
......@@ -68,12 +99,13 @@ namespace mln
{
trace::entering("accu::impl::image::generic::take");
mlc_is_a(mln_value(I), Accumulator)::check();
mlc_converts_to(mln_value(J), mln_deduce(I, value, argument))::check();
I& input = exact(input_);
const J& arg = exact(arg_);
mln_precondition(input.is_valid());
mln_precondition(arg.is_valid());
mln_precondition(arg.domain() <= input.domain());
internal::take_tests(input, arg);
mln_piter(J) p(arg.domain());
for_all(p)
......@@ -92,13 +124,18 @@ namespace mln
take_fastest(Image<I>& input_, const Image<J>& arg_)
{
trace::entering("accu::impl::image::take_fastest");
mlc_is_a(mln_value(I), Accumulator)::check();
mlc_converts_to(mln_value(J), mln_deduce(I, value, argument))::check();
I& input = exact(input_);
const J& arg = exact(arg_);
mln_precondition(input.is_valid());
mln_precondition(arg.is_valid());
internal::take_tests(input, arg);
// Extra (stronger) test.
mln_precondition(arg.domain() == input.domain());
border::resize_equal(input, arg);
mln_pixter(I) p_in(input);
mln_pixter(const J) p_arg(arg);
......@@ -159,16 +196,12 @@ namespace mln
trace::entering("accu::image::take");
mlc_is_a(mln_value(I), Accumulator)::check();
mlc_converts_to(mln_value(J),
mln_deduce(I, value, argument))::check();
mlc_converts_to(mln_value(J), mln_deduce(I, value, argument))::check();
I& input = exact(input_);
const J& arg = exact(arg_);
mln_precondition(input.is_valid());
mln_precondition(arg.is_valid());
mln_precondition(arg.domain() <= input.domain());
internal::take_tests(input, arg);
internal::take_dispatch(input, arg);
trace::exiting("accu::image::take");
......
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef MLN_ACCU_IMAGE_TAKE_N_TIMES_HH
# define MLN_ACCU_IMAGE_TAKE_N_TIMES_HH
/// \file mln/accu/image/take_n_times.hh
///
/// Update an image of accumulators by taking the contents of another
/// image with a multiplicity.
///
/// \todo Add "take(input, n, arg_value)".
# include <mln/core/concept/accumulator.hh>
# include <mln/core/concept/image.hh>
# include <mln/border/resize.hh>
namespace mln
{
namespace accu
{
namespace image
{
template <typename I, typename J, typename K>
void
take_n_times(Image<I>& input, const Image<J>& n_times, const Image<K>& arg);
# ifndef MLN_INCLUDE_ONLY
// Tests.
namespace internal
{
template <typename I, typename J, typename K>
void
take_n_times_tests(Image<I>& input_, const Image<J>& n_times_, const Image<K>& arg_)
{
I& input = exact(input_);
const J& n_times = exact(n_times_);
const K& arg = exact(arg_);
mln_precondition(input.is_valid());
mln_precondition(n_times.is_valid());
mln_precondition(arg.is_valid());
mln_precondition(arg.domain() <= input.domain());
mln_precondition(arg.domain() <= n_times.domain());
(void) input;
(void) n_times;
(void) arg;
}
} // end of namespace mln::accu::image::internal
// Implementations.
namespace impl
{
// Generic version.
namespace generic
{
template <typename I, typename J, typename K>
void
take_n_times(Image<I>& input_, const Image<J>& n_times_, const Image<K>& arg_)
{
trace::entering("accu::impl::image::generic::take_n_times");
mlc_is_a(mln_value(I), Accumulator)::check();
mlc_converts_to(mln_value(J), unsigned)::check();
mlc_converts_to(mln_value(K), mln_deduce(I, value, argument))::check();
I& input = exact(input_);
const J& n_times = exact(n_times_);
const K& arg = exact(arg_);
internal::take_n_times_tests(input, n_times, arg);
mln_piter(J) p(arg.domain());
for_all(p)
input(p).take_n_times(n_times(p), arg(p));
trace::exiting("accu::impl::image::generic::take_n_times");
}
} // end of namespace mln::accu::image::impl::generic
// Fastest version.
template <typename I, typename J, typename K>
void
take_n_times_fastest(Image<I>& input_, const Image<J>& n_times_, const Image<K>& arg_)
{
trace::entering("accu::impl::image::take_n_times_fastest");
mlc_is_a(mln_value(I), Accumulator)::check();
mlc_converts_to(mln_value(J), unsigned)::check();
mlc_converts_to(mln_value(K), mln_deduce(I, value, argument))::check();
I& input = exact(input_);
const J& n_times = exact(n_times_);
const K& arg = exact(arg_);
internal::take_n_times_tests(input, n_times, arg);
// Extra (stronger) tests.
mln_precondition(arg.domain() == input.domain());
mln_precondition(arg.domain() == n_times.domain());
border::resize(n_times, input.border());
border::resize(arg, input.border());
mln_pixter(I) p_in(input);
mln_pixter(const J) p_ntm(n_times);
mln_pixter(const K) p_arg(arg);
for_all_3(p_in, p_ntm, p_arg)
p_in.val().take_n_times( p_ntm.val(), p_arg.val() );
trace::exiting("accu::impl::image::take_n_times_fastest");
}
} // end of namespace mln::accu::image::impl
// Dispatch.
namespace internal
{
template <typename I, typename J, typename K>
void
take_n_times_dispatch(trait::image::speed::any,
trait::image::speed::any,
trait::image::speed::any,
Image<I>& input, const Image<J>& n_times, const Image<K>& arg)
{
impl::generic::take_n_times(input, n_times, arg);
}
template <typename I, typename J, typename K>
void
take_n_times_dispatch(trait::image::speed::fastest,
trait::image::speed::fastest,
trait::image::speed::fastest,
Image<I>& input, const Image<J>& n_times, const Image<K>& arg)
{
if (exact(n_times).domain() == exact(input).domain() &&
exact(arg) .domain() == exact(input).domain())
impl::take_n_times_fastest(input, n_times, arg);
else
impl::generic::take_n_times(input, n_times, arg);
}
template <typename I, typename J, typename K>
void
take_n_times_dispatch(Image<I>& input, const Image<J>& n_times, const Image<K>& arg)
{
take_n_times_dispatch(mln_trait_image_speed(I)(),
mln_trait_image_speed(J)(),
mln_trait_image_speed(K)(),
input, n_times, arg);
}
} // end of namespace mln::accu::image::internal
// Facade.
template <typename I, typename J, typename K>
void
take_n_times(Image<I>& input_, const Image<J>& n_times_, const Image<K>& arg_)
{
trace::entering("accu::image::take_n_times");
mlc_is_a(mln_value(I), Accumulator)::check();
mlc_converts_to(mln_value(J), unsigned)::check();
mlc_converts_to(mln_value(K), mln_deduce(I, value, argument))::check();
I& input = exact(input_);
const J& n_times = exact(n_times_);
const K& arg = exact(arg_);
internal::take_n_times_tests(input, n_times, arg);
internal::take_n_times_dispatch(input, n_times, arg);
trace::exiting("accu::image::take_n_times");
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::accu::image
} // end of namespace mln::accu
} // end of namespace mln
#endif // ! MLN_ACCU_IMAGE_TAKE_N_TIMES_HH
......@@ -67,6 +67,8 @@ namespace mln
{
trace::entering("accu::impl::image::generic::to_result");
mlc_is_a(mln_value(I), Accumulator)::check();
const I& input = exact(input_);
mln_precondition(input.is_valid());
......@@ -92,6 +94,8 @@ namespace mln
to_result_fastest(const Image<I>& input_)
{
trace::entering("accu::impl::image::to_result_fastest");
mlc_is_a(mln_value(I), Accumulator)::check();
const I& input = exact(input_);
mln_precondition(input.is_valid());
......
// Copyright (C) 2007 EPITA Research and Development Laboratory
// Copyright (C) 2007, 2009 EPITA Research and Development Laboratory
// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
......@@ -28,10 +29,9 @@
#ifndef MLN_BORDER_ALL_HH
# define MLN_BORDER_ALL_HH
/*! \file mln/border/all.hh
*
* \brief File that includes all border-related routines.
*/
/// \file mln/border/all.hh
///
/// File that includes all border-related routines.
namespace mln
......@@ -60,6 +60,7 @@ namespace mln
# include <mln/border/get.hh>
# include <mln/border/mirror.hh>
# include <mln/border/resize.hh>
# include <mln/border/resize_equal.hh>
# include <mln/border/thickness.hh>
......
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef MLN_BORDER_RESIZE_EQUAL_HH
# define MLN_BORDER_RESIZE_EQUAL_HH
/// \file mln/border/resize_equal.hh
///
/// Define a function that resizes the virtual border of a couple of
/// images so that they eventually have the same border thickness.
# include <mln/border/resize.hh>
namespace mln
{
namespace border
{
// FIXEM: Doc!
template <typename I, typename J>
void
resize_equal(const Image<I>& ima1, const Image<J>& ima2);
# ifndef MLN_INCLUDE_ONLY
template <typename I, typename J>
inline
void
resize_equal(const Image<I>& ima1_, const Image<J>& ima2_)
{
trace::entering("border::resize_equal");
// Static checks.
mlc_equal(mln_trait_image_ext_domain(I),
trait::image::ext_domain::extendable)::check();
mlc_equal(mln_trait_image_ext_domain(J),
trait::image::ext_domain::extendable)::check();
const I& ima1 = exact(ima1_);
const J& ima2 = exact(ima2_);
// Dynamic tests.
mln_precondition(ima1.is_valid());
mln_precondition(ima2.is_valid());
mln_precondition(ima2.domain() == ima1.domain());
unsigned
b1 = border::get(ima1),
b2 = border::get(ima2);
if (b2 > b1)
border::resize(ima1, b2);
else
if (b1 > b2)
border::resize(ima2, b1);
// else no-op when b2 == b1.
trace::exiting("border::resize_equal");
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::border
} // end of namespace mln
#endif // ! MLN_BORDER_RESIZE_EQUAL_HH
......@@ -7,12 +7,14 @@ check_PROGRAMS = \
set_value \
take \
take_as_init \
take_n_times \
to_result
init_SOURCES = init.cc
set_value_SOURCES = set_value.cc
take_SOURCES = take.cc
take_as_init_SOURCES = take_as_init.cc
take_n_times_SOURCES = take_n_times.cc
to_result_SOURCES = to_result.cc
TESTS = $(check_PROGRAMS)
......@@ -30,6 +30,10 @@
/// Tests on mln::accu::image::init.
#include <mln/core/image/image2d.hh>
#include <mln/level/compare.hh>
#include <mln/pw/cst.hh>
#include <mln/pw/image.hh>
#include <mln/accu/count.hh>
#include <mln/accu/image/init.hh>
......@@ -42,4 +46,5 @@ int main()
image2d<A> ima(2, 2);
accu::image::init(ima);
mln_assertion(ima == (pw::cst(0u) | ima.domain()));
}
......@@ -33,7 +33,9 @@
#include <mln/accu/count.hh>
#include <mln/accu/image/set_value.hh>
#include <mln/debug/println.hh>
#include <mln/level/compare.hh>
#include <mln/pw/cst.hh>
#include <mln/pw/image.hh>