https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Factor code for erosion on lines.
* mln/accu/transform_directional.hh (include): Layout.
(output): Fix typedef.
* mln/accu/transform_diagonal.hh: Likewise.
Fix declaration signature.
* tests/accu/transform_directional.cc: New.
* tests/accu/transform_diagonal.cc: New.
* mln/accu/all.hh: Update.
* mln/morpho/erosion.spe.hh
(erosion_dispatch_wrt_win): Handle the case win.size == 1.
Remove useless qualif morpho::.
(erosion_dispatch_wrt_win): Factor code for hline2d and vline2d
into...
(erosion_dispatch_line): ...this new overloaded routine.
(erosion_dispatch_diagonal): Remove check on kind::logic cause it
also works on this case.
To be consistent:
* mln/accu/snake_2d.hh: Rename as...
* mln/accu/transform_snake.hh: ...this.
* mln/morpho/erosion.spe.hh (erosion_arbitrary_2d): Update.
* mln/morpho/includes.hh: Update.
* tests/accu/snake_2d.cc: Rename as...
* tests/accu/transform_snake.cc: ...this.
* tests/accu/Makefile.am: Update.
mln/accu/all.hh | 5 +-
mln/accu/transform_diagonal.hh | 15 +++---
mln/accu/transform_directional.hh | 5 +-
mln/accu/transform_snake.hh | 64 ++++++++++++++--------------
mln/morpho/erosion.spe.hh | 82 +++++++-----------------------------
mln/morpho/includes.hh | 3 -
tests/accu/Makefile.am | 8 ++-
tests/accu/transform_diagonal.cc | 23 +++++++---
tests/accu/transform_directional.cc | 12 +++--
tests/accu/transform_snake.cc | 8 +--
10 files changed, 98 insertions(+), 127 deletions(-)
Index: tests/accu/transform_snake.cc
--- tests/accu/transform_snake.cc (revision 2882)
+++ tests/accu/transform_snake.cc (working copy)
@@ -25,12 +25,12 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file tests/accu/snake_2d.cc
+/// \file tests/accu/transform_snake.cc
///
-/// Tests on mln::accu::snake_2d.
+/// Tests on mln::accu::transform_snake.
#include <mln/core/image/image2d.hh>
-#include <mln/accu/snake_2d.hh>
+#include <mln/accu/transform_snake.hh>
#include <mln/accu/count.hh>
#include <mln/win/rectangle2d.hh>
#include <mln/pw/all.hh>
@@ -45,7 +45,7 @@
win::rectangle2d rec(3, 3);
image2d<unsigned>
- out = accu::snake_2d(accu::meta::count(), ima, rec),
+ out = accu::transform_snake(accu::meta::count(), ima, rec),
ref(ima.domain());
mln_assertion(out == (pw::cst(rec.size()) | ima.domain()));
Property changes on: tests/accu/transform_snake.cc
___________________________________________________________________
Added: svn:mergeinfo
Index: tests/accu/transform_diagonal.cc
--- tests/accu/transform_diagonal.cc (revision 2882)
+++ tests/accu/transform_diagonal.cc (working copy)
@@ -25,14 +25,13 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file tests/accu/snake_2d.cc
+/// \file tests/accu/transform_diagonal.cc
///
-/// Tests on mln::accu::snake_2d.
+/// Tests on mln::accu::transform_diagonal.
#include <mln/core/image/image2d.hh>
-#include <mln/accu/snake_2d.hh>
+#include <mln/accu/transform_diagonal.hh>
#include <mln/accu/count.hh>
-#include <mln/win/rectangle2d.hh>
#include <mln/pw/all.hh>
#include <mln/level/compare.hh>
@@ -42,11 +41,21 @@
using namespace mln;
image2d<int> ima(4, 5);
- win::rectangle2d rec(3, 3);
+ {
+ win::diag2d w(3);
image2d<unsigned>
- out = accu::snake_2d(accu::meta::count(), ima, rec),
+ out = accu::transform_diagonal(accu::meta::count(), ima, w),
ref(ima.domain());
+ mln_assertion(out == (pw::cst(w.size()) | ima.domain()));
+ }
+
+ {
+ win::backdiag2d w(3);
+ image2d<unsigned>
+ out = accu::transform_diagonal(accu::meta::count(), ima, w),
+ ref(ima.domain());
+ mln_assertion(out == (pw::cst(w.size()) | ima.domain()));
+ }
- mln_assertion(out == (pw::cst(rec.size()) | ima.domain()));
}
Property changes on: tests/accu/transform_diagonal.cc
___________________________________________________________________
Added: svn:mergeinfo
Index: tests/accu/Makefile.am
--- tests/accu/Makefile.am (revision 2882)
+++ tests/accu/Makefile.am (working copy)
@@ -19,8 +19,10 @@
nil \
pair \
rank \
- snake_2d \
transform \
+ transform_diagonal \
+ transform_directional \
+ transform_snake \
tuple
all_accus_SOURCES = all_accus.cc
@@ -39,8 +41,10 @@
nil_SOURCES = nil.cc
pair_SOURCES = pair.cc
rank_SOURCES = rank.cc
-snake_2d_SOURCES = snake_2d.cc
transform_SOURCES = transform.cc
+transform_diagonal_SOURCES = transform_diagonal.cc
+transform_directional_SOURCES = transform_directional.cc
+transform_snake_SOURCES = transform_snake.cc
tuple_SOURCES = tuple.cc
TESTS = $(check_PROGRAMS)
Index: tests/accu/transform_directional.cc
--- tests/accu/transform_directional.cc (revision 2882)
+++ tests/accu/transform_directional.cc (working copy)
@@ -25,12 +25,12 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file tests/accu/snake_2d.cc
+/// \file tests/accu/transform_directional.cc
///
-/// Tests on mln::accu::snake_2d.
+/// Tests on mln::accu::transform_directional.
#include <mln/core/image/image2d.hh>
-#include <mln/accu/snake_2d.hh>
+#include <mln/accu/transform_directional.hh>
#include <mln/accu/count.hh>
#include <mln/win/rectangle2d.hh>
#include <mln/pw/all.hh>
@@ -44,9 +44,11 @@
image2d<int> ima(4, 5);
win::rectangle2d rec(3, 3);
+ for (unsigned dir = 0; dir < 2; ++dir)
+ {
image2d<unsigned>
- out = accu::snake_2d(accu::meta::count(), ima, rec),
+ out = accu::transform_directional(accu::meta::count(), ima, rec, dir),
ref(ima.domain());
-
mln_assertion(out == (pw::cst(rec.size()) | ima.domain()));
}
+}
Property changes on: tests/accu/transform_directional.cc
___________________________________________________________________
Added: svn:mergeinfo
Index: mln/accu/transform_directional.hh
--- mln/accu/transform_directional.hh (revision 2882)
+++ mln/accu/transform_directional.hh (working copy)
@@ -40,6 +40,7 @@
#include <mln/core/concept/image.hh>
#include <mln/core/concept/meta_accumulator.hh>
#include <mln/core/alias/window2d.hh>
+# include <mln/win/diff.hh>
#include <mln/win/shift.hh>
#include <mln/geom/delta.hh>
#include <mln/literal/zero.hh>
@@ -119,7 +120,7 @@
const I& input;
const W& win;
- mln_concrete(I) output;
+ mln_ch_value(I, mln_result(A)) output;
A accu;
enum { dim = I::site::dim };
@@ -190,7 +191,7 @@
const I& input;
const W& win;
- mln_concrete(I) output;
+ mln_ch_value(I, mln_result(A)) output;
A accu;
mln_psite(I) p;
Index: mln/accu/all.hh
--- mln/accu/all.hh (revision 2882)
+++ mln/accu/all.hh (working copy)
@@ -80,9 +80,12 @@
// Routines.
# include <mln/accu/convolve.hh>
-# include <mln/accu/snake_2d.hh>
# include <mln/accu/transform.hh>
# include <mln/accu/transform_stop.hh>
+# include <mln/accu/transform_directional.hh>
+# include <mln/accu/transform_diagonal.hh>
+# include <mln/accu/transform_snake.hh>
+
#endif // ! MLN_ACCU_ALL_HH
Index: mln/accu/transform_diagonal.hh
--- mln/accu/transform_diagonal.hh (revision 2882)
+++ mln/accu/transform_diagonal.hh (working copy)
@@ -40,6 +40,7 @@
#include <mln/core/concept/image.hh>
#include <mln/core/concept/meta_accumulator.hh>
#include <mln/core/alias/window2d.hh>
+#include <mln/win/diff.hh>
#include <mln/win/shift.hh>
#include <mln/geom/delta.hh>
#include <mln/extension/adjust.hh>
@@ -62,15 +63,13 @@
template <typename A, typename I, typename W>
mln_ch_value(I, mln_result(A))
transform_diagonal(const Accumulator<A>&,
- const Image<I>& input, const Window<W>& win,
- unsigned dir);
+ const Image<I>& input, const Window<W>& win);
template <typename A, typename I, typename W>
mln_ch_value(I, mln_accu_with(A, mln_value(I))::result)
transform_diagonal(const Meta_Accumulator<A>&,
- const Image<I>& input, const Window<W>& win,
- unsigned dir);
+ const Image<I>& input, const Window<W>& win);
@@ -110,7 +109,7 @@
const I& input;
const W& win;
- mln_concrete(I) output;
+ mln_ch_value(I, mln_result(A)) output;
A accu;
mln_psite(I) p;
@@ -174,7 +173,7 @@
const I& input;
const W& win;
- mln_concrete(I) output;
+ mln_ch_value(I, mln_result(A)) output;
A accu;
mln_psite(I) p;
@@ -241,7 +240,7 @@
const I& input;
const W& win;
- mln_concrete(I) output;
+ mln_ch_value(I, mln_result(A)) output;
A accu;
mln_psite(I) p;
@@ -304,7 +303,7 @@
const I& input;
const W& win;
- mln_concrete(I) output;
+ mln_ch_value(I, mln_result(A)) output;
A accu;
mln_psite(I) p;
Index: mln/accu/transform_snake.hh
--- mln/accu/transform_snake.hh (revision 2882)
+++ mln/accu/transform_snake.hh (working copy)
@@ -25,15 +25,13 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_ACCU_SNAKE_2D_HH
-# define MLN_ACCU_SNAKE_2D_HH
+#ifndef MLN_ACCU_TRANSFORM_SNAKE_HH
+# define MLN_ACCU_TRANSFORM_SNAKE_HH
-/// \file mln/accu/snake_2d.hh
+/// \file mln/accu/transform_snake.hh
///
/// Run an accumulator in a snake-like browsing.
///
-/// \todo Rename as transform_snake_2d.
-///
/// \todo Make it n-D.
///
/// \todo Split dispatch and impl.
@@ -47,6 +45,8 @@
#include <mln/win/shift.hh>
#include <mln/geom/delta.hh>
#include <mln/extension/adjust.hh>
+
+# include <mln/canvas/browsing/snake_fwd.hh>
#include <mln/canvas/browsing/snake_generic.hh>
@@ -60,12 +60,12 @@
template <typename A, typename I, typename W>
mln_ch_value(I, mln_result(A))
- snake_2d(const Accumulator<A>&, const Image<I>& input, const
Window<W>& win);
+ transform_snake(const Accumulator<A>&, const Image<I>& input,
const Window<W>& win);
template <typename A, typename I, typename W>
mln_ch_value(I, mln_accu_with(A, mln_value(I))::result)
- snake_2d(const Meta_Accumulator<A>&, const Image<I>& input, const
Window<W>& win);
+ transform_snake(const Meta_Accumulator<A>&, const Image<I>&
input, const Window<W>& win);
@@ -76,7 +76,7 @@
template <typename I, typename W>
- void snake_2d_tests(const Image<I>& input_, const Window<W>&
win_)
+ void transform_snake_tests(const Image<I>& input_, const
Window<W>& win_)
{
const I& input = exact(input_);
const W& win = exact(win_);
@@ -93,9 +93,9 @@
// Functor.
template <typename I, typename W, typename A>
- struct snake_2d_functor
+ struct transform_snake_functor
{
- typedef snake_2d_functor<I,W, A> self;
+ typedef transform_snake_functor<I,W, A> self;
typedef void (self::*move_fun)();
typedef mln_deduce(I, psite, delta) dpsite;
@@ -129,7 +129,7 @@
std::vector<move_fun> moves;
std::vector<dpsite> dps;
- snake_2d_functor(const Image<I>& input, const Window<W>& win)
+ transform_snake_functor(const Image<I>& input, const Window<W>&
win)
: input(exact(input)),
win(exact(win)),
accu(),
@@ -245,15 +245,15 @@
// Functor (fastest version).
template <typename I, typename W, typename A>
- struct snake_2d_fastest_functor
+ struct transform_snake_fastest_functor
{
- typedef snake_2d_fastest_functor<I,W,A> self;
+ typedef transform_snake_fastest_functor<I,W,A> self;
typedef void (self::*move_fun)();
typedef mln_deduce(I, psite, delta) dpsite;
const I& input;
const W& win;
- mln_concrete(I) output;
+ mln_ch_value(I, mln_result(A)) output;
A accu;
mln_psite(I) p;
@@ -282,7 +282,7 @@
std::vector<move_fun> moves;
std::vector<dpsite> dps;
- snake_2d_fastest_functor(const I& input, const W& win)
+ transform_snake_fastest_functor(const I& input, const W& win)
: input(input),
win(win),
accu(),
@@ -393,11 +393,11 @@
template <typename A, typename I, typename W>
inline
mln_ch_value(I, mln_result(A))
- snake_2d_dispatch(trait::image::speed::any,
+ transform_snake_dispatch(trait::image::speed::any,
const Accumulator<A>& /* FIXME a */,
const Image<I>& input, const Window<W>& win)
{
- typedef snake_2d_functor<I, W, A> F;
+ typedef transform_snake_functor<I, W, A> F;
F f(exact(input), exact(win)); // FIXME: Pass a to f.
canvas::browsing::snake_generic(f);
return f.output;
@@ -406,11 +406,11 @@
template <typename A, typename I, typename W>
inline
mln_ch_value(I, mln_result(A))
- snake_2d_dispatch(trait::image::speed::fastest,
+ transform_snake_dispatch(trait::image::speed::fastest,
const Accumulator<A>& /* FIXME a*/,
const Image<I>& input, const Window<W>& win)
{
- typedef snake_2d_fastest_functor<I, W, A> F;
+ typedef transform_snake_fastest_functor<I, W, A> F;
F f(exact(input), exact(win)); // FIXME: Pass a to f.
canvas::browsing::snake_generic(f);
return f.output;
@@ -419,10 +419,10 @@
template <typename A, typename I, typename W>
inline
mln_ch_value(I, mln_result(A))
- snake_2d_dispatch(const Accumulator<A>& a,
+ transform_snake_dispatch(const Accumulator<A>& a,
const Image<I>& input, const Window<W>& win)
{
- return snake_2d_dispatch(mln_trait_image_speed(I)(),
+ return transform_snake_dispatch(mln_trait_image_speed(I)(),
a, input, win);
}
@@ -434,18 +434,18 @@
template <typename A, typename I, typename W>
inline
mln_ch_value(I, mln_result(A))
- snake_2d(const Accumulator<A>& a,
+ transform_snake(const Accumulator<A>& a,
const Image<I>& input, const Window<W>& win)
{
- trace::entering("accu::snake_2d");
+ trace::entering("accu::transform_snake");
- internal::snake_2d_tests(input, win);
+ internal::transform_snake_tests(input, win);
extension::adjust(input, geom::delta(win) + 1);
mln_ch_value(I, mln_result(A)) output;
- output = internal::snake_2d_dispatch(a, input, win);
+ output = internal::transform_snake_dispatch(a, input, win);
- trace::exiting("accu::snake_2d");
+ trace::exiting("accu::transform_snake");
return output;
}
@@ -453,21 +453,21 @@
template <typename A, typename I, typename W>
inline
mln_ch_value(I, mln_accu_with(A, mln_value(I))::result)
- snake_2d(const Meta_Accumulator<A>& a,
+ transform_snake(const Meta_Accumulator<A>& a,
const Image<I>& input, const Window<W>& win)
{
- trace::entering("accu::snake_2d");
+ trace::entering("accu::transform_snake");
- internal::snake_2d_tests(input, win);
+ internal::transform_snake_tests(input, win);
typedef mln_accu_with(A, mln_value(I)) A_;
A_ a_ = accu::unmeta(exact(a), mln_value(I)());
extension::adjust(input, geom::delta(win) + 1);
mln_ch_value(I, mln_result(A_)) output;
- output = internal::snake_2d_dispatch(a_, input, win);
+ output = internal::transform_snake_dispatch(a_, input, win);
- trace::exiting("accu::snake_2d");
+ trace::exiting("accu::transform_snake");
return output;
}
@@ -479,4 +479,4 @@
} // end of namespace mln
-#endif // ! MLN_ACCU_SNAKE_2D_HH
+#endif // ! MLN_ACCU_TRANSFORM_SNAKE_HH
Index: mln/morpho/erosion.spe.hh
--- mln/morpho/erosion.spe.hh (revision 2882)
+++ mln/morpho/erosion.spe.hh (working copy)
@@ -39,18 +39,9 @@
# include <mln/win/octagon2d.hh>
# include <mln/win/rectangle2d.hh>
-# include <mln/win/shift.hh>
-# include <mln/win/diff.hh>
-
# include <mln/accu/min_h.hh>
# include <mln/accu/line.hh>
-# include <mln/canvas/browsing/snake_fwd.hh>
-# include <mln/canvas/browsing/snake_generic.hh>
-# include <mln/canvas/browsing/directional.hh>
-# include <mln/canvas/browsing/diagonal2d.hh>
-# include <mln/canvas/browsing/backdiagonal2d.hh>
-
/// \file mln/morpho/erosion.spe.hh
///
@@ -269,7 +260,7 @@
A a;
extension::adjust_fill(input, geom::delta(win) + 1, a);
- mln_concrete(I) output = accu::snake_2d(a, input, win);
+ mln_concrete(I) output = accu::transform_snake(a, input, win);
trace::exiting("morpho::impl:erosion_arbitrary_2d");
return output;
@@ -408,9 +399,10 @@
mln_concrete(I)
erosion_dispatch_wrt_win(const I& input, const win::rectangle2d& win)
{
+ if (win.size() == 1)
+ return clone(input);
if (win.size() <= 9) // FIXME: Hard-coded!
return erosion_dispatch_for_generic(input, win);
- else
return impl::erosion_rectangle2d(input, win);
}
@@ -420,74 +412,35 @@
erosion_dispatch_wrt_win(const I& input, const win::octagon2d& win)
{
if (win.length() < 5)
- return morpho::impl::erosion_arbitrary_2d(input, win);
+ return impl::erosion_arbitrary_2d(input, win);
else
return impl::erosion_octagon2d(input, win);
}
- /// Handling win::hline2d.
- /// \{
-
- template <typename I>
- mln_concrete(I)
- erosion_dispatch_wrt_win(metal::true_,
- const I& input, const win::hline2d& win)
- {
- return impl::erosion_directional(input, win, 1);
- }
-
- template <typename I>
- mln_concrete(I)
- erosion_dispatch_wrt_win(metal::false_,
- const I& input, const win::hline2d& win)
- {
- return erosion_dispatch_for_generic(input, win);
- }
-
- template <typename I>
- mln_concrete(I)
- erosion_dispatch_wrt_win(const I& input, const win::hline2d& win)
- {
- if (win.size() == 1)
- return clone(input);
- else if (win.size() == 3)
- return erosion_dispatch_for_generic(input, win);
- else
- {
- enum { test = mlc_is_a(mln_pset(I), Box)::value
- && mlc_equal(mln_trait_image_quant(I),
- mln::trait::image::quant::low)::value };
- return erosion_dispatch_wrt_win(metal::bool_<test>(),
- input, win);
- }
- }
-
- /// \}
-
- /// Handling win::vline2d.
+ /// Handling win::line(s).
/// \{
- template <typename I>
+ template <typename I, typename W>
mln_concrete(I)
- erosion_dispatch_wrt_win(metal::true_,
- const I& input, const win::vline2d& win)
+ erosion_dispatch_line(metal::true_,
+ const I& input, const W& win)
{
- return impl::erosion_directional(input, win, 0);
+ return impl::erosion_directional(input, win, W::dir);
}
- template <typename I>
+ template <typename I, typename W>
mln_concrete(I)
- erosion_dispatch_wrt_win(metal::false_,
- const I& input, const win::vline2d& win)
+ erosion_dispatch_line(metal::false_,
+ const I& input, const W& win)
{
return erosion_dispatch_for_generic(input, win);
}
- template <typename I>
+ template <typename I, typename M, unsigned i, typename C>
mln_concrete(I)
- erosion_dispatch_wrt_win(const I& input, const win::vline2d& win)
+ erosion_dispatch_wrt_win(const I& input, const win::line<M,i,C>&
win)
{
if (win.size() == 1)
return clone(input);
@@ -498,7 +451,7 @@
enum { test = mlc_is_a(mln_pset(I), Box)::value
&& mlc_equal(mln_trait_image_quant(I),
mln::trait::image::quant::low)::value };
- return erosion_dispatch_wrt_win(metal::bool_<test>(),
+ return erosion_dispatch_line(metal::bool_<test>(),
input, win);
}
}
@@ -537,9 +490,7 @@
return erosion_dispatch_for_generic(input, win);
else
{
- enum { test = mlc_is_not(mln_trait_image_kind(I),
- mln::trait::image::kind::logic)::value
- && mlc_is_a(mln_pset(I), Box)::value
+ enum { test = mlc_is_a(mln_pset(I), Box)::value
&& mlc_equal(mln_trait_image_quant(I),
mln::trait::image::quant::low)::value };
return erosion_dispatch_diagonal(metal::bool_<test>(),
@@ -565,6 +516,7 @@
/// \}
+
// The dispatch entry point.
template <typename I, typename W>
Index: mln/morpho/includes.hh
--- mln/morpho/includes.hh (revision 2882)
+++ mln/morpho/includes.hh (working copy)
@@ -51,11 +51,12 @@
# include <mln/accu/max_h.hh>
# include <mln/accu/rank.hh>
-# include <mln/accu/snake_2d.hh>
# include <mln/accu/transform.hh>
# include <mln/accu/transform_stop.hh>
+
# include <mln/accu/transform_directional.hh>
# include <mln/accu/transform_diagonal.hh>
+# include <mln/accu/transform_snake.hh>
# include <mln/fun/v2v/saturate.hh>