URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-11-16 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add tracing for level algorithm and split specialization of level::transform.
* mln/level/compute.hh,
* mln/level/fill.hh,
* mln/level/median.hh,
* mln/level/paste.hh,
* mln/level/saturate.hh,
* mln/level/stretch.hh,
* mln/level/to_enc.hh,
* mln/level/was.median.hh: Add tracing for algorithm.
* mln/level/transform.hh: Remove specialization.
* mln/level/transform.spe.hh: New file for specialization for
transform.
---
compute.hh | 4 +
median.hh | 6 ++
saturate.hh | 12 +++++
stretch.hh | 8 +++
to_enc.hh | 4 +
transform.hh | 63 ++++++++++------------------
transform.spe.hh | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 178 insertions(+), 40 deletions(-)
Index: trunk/milena/mln/level/was.median.hh
===================================================================
Index: trunk/milena/mln/level/fill.hh
===================================================================
Index: trunk/milena/mln/level/saturate.hh
===================================================================
--- trunk/milena/mln/level/saturate.hh (revision 1493)
+++ trunk/milena/mln/level/saturate.hh (revision 1494)
@@ -87,9 +87,13 @@
template <typename I, typename O>
void saturate(const Image<I>& input, Image<O>& output)
{
+ trace::entering("level::saturate");
+
mln_precondition(exact(input).domain() == exact(output).domain());
fun::v2v::saturate<mln_value(O)> f;
level::transform(input, f, output);
+
+ trace::exiting("level::saturate");
}
template <typename I, typename O>
@@ -97,18 +101,26 @@
const mln_value(O)& min, const mln_value(O)& max,
Image<O>& output)
{
+ trace::entering("level::saturate");
+
mln_precondition(exact(input).domain() == exact(output).domain());
fun::v2v::saturate<mln_value(O)> f(min, max);
level::transform(input, f, output);
+
+ trace::exiting("level::saturate");
}
template <typename I>
void saturate_inplace(Image<I>& input,
const mln_value(I)& min, const mln_value(I)& max)
{
+ trace::entering("level::saturate_inplace");
+
mln_precondition(exact(input).has_data());
fun::v2v::saturate<mln_value(I)> f(min, max);
level::apply(input, f);
+
+ trace::exiting("level::saturate_inplace");
}
# endif // ! MLN_INCLUDE_ONLY
Index: trunk/milena/mln/level/median.hh
===================================================================
--- trunk/milena/mln/level/median.hh (revision 1493)
+++ trunk/milena/mln/level/median.hh (revision 1494)
@@ -261,7 +261,7 @@
{
median_dir(input, i, win.length(), output); // FIXME: Make 1 explicit!
}
-# endif
+# endif // ! MLN_CORE_WIN_LINE_HH
} // end of namespace mln::level::impl
@@ -273,8 +273,12 @@
void median(const Image<I>& input, const Window<W>& win,
Image<O>& output)
{
+ trace::entering("level::median");
+
mln_assertion(exact(output).domain() == exact(input).domain());
impl::median_(exact(input), exact(win), exact(output));
+
+ trace::exiting("level::median");
}
template <typename I, typename O>
Index: trunk/milena/mln/level/transform.spe.hh
===================================================================
--- trunk/milena/mln/level/transform.spe.hh (revision 0)
+++ trunk/milena/mln/level/transform.spe.hh (revision 1494)
@@ -0,0 +1,121 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// 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_LEVEL_TRANSFORM_SPE_HH
+# define MLN_LEVEL_TRANSFORM_SPE_HH
+
+/*! \file mln/level/transform.spe.hh
+ *
+ * \brief Specializations for mln::level::transform.
+ *
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/function.hh>
+
+# include <mln/value/set.hh>
+# include <mln/value/lut_vec.hh>
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+namespace mln
+{
+
+ namespace level
+ {
+
+
+ namespace impl
+ {
+
+
+ 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, typename O>
+ void transform_(metal::false_, // general case
+ const Image<I>& input_, const Function_v2v<F>& f_,
Image<O>& output_)
+ {
+ generic::transform_(input_, f_, output_);
+ }
+
+
+ template <typename I, typename F, typename O>
+ void transform_(metal::true_, // low quantization
+ const Image<I>& input_, const Function_v2v<F>& f_,
Image<O>& output_)
+ {
+ trace::entering("level::impl::transform");
+
+ const I& input = exact(input_);
+ const F& f = exact(f_);
+ O& output = exact(output_);
+
+ value::lut_vec<mln_vset(I), mln_result(F)> lut(input.values(), f);
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ output(p) = lut(input(p));
+
+ trace::exiting("level::impl::transform");
+ }
+
+
+ // FIXME: Handle the cases of fastest images.
+
+// template <typename I, typename F, typename O>
+// void transform(metal::true_, // low quantization
+// const Image<I>& input_, const Function_v2v<F>& f_,
Image<O>& output_)
+// {
+// const I& input = exact(input_);
+// const F& f = exact(f_);
+// O& output = exact(output_);
+
+// value::lut_vec<mln_vset(I), mln_result(F)> lut(input.values(), f);
+// mln_pixter(const I) pi(input); // FIXME
+// mln_pixter(O) po(output);
+// po.start();
+// for_all(pi)
+// {
+// po.val() = lut(pi.val());
+// po.next();
+// }
+// }
+
+ } // end of namespace mln::level::impl
+
+ } // end of namespace mln::level
+
+} // end of namespace mln
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+#endif // ! MLN_LEVEL_TRANSFORM_SPE_HH
Index: trunk/milena/mln/level/to_enc.hh
===================================================================
--- trunk/milena/mln/level/to_enc.hh (revision 1493)
+++ trunk/milena/mln/level/to_enc.hh (revision 1494)
@@ -60,8 +60,12 @@
template <typename I, typename O>
void to_enc(const Image<I>& input, Image<O>& output)
{
+ trace::entering("level::to_enc");
+
mln_precondition(exact(output).domain() == exact(input).domain());
level::transform(input, fun::v2v::enc< mln_value(I) >(), output);
+
+ trace::exiting("level::to_enc");
}
# endif // ! MLN_INCLUDE_ONLY
Index: trunk/milena/mln/level/transform.hh
===================================================================
--- trunk/milena/mln/level/transform.hh (revision 1493)
+++ trunk/milena/mln/level/transform.hh (revision 1494)
@@ -42,6 +42,10 @@
# include <mln/value/lut_vec.hh>
+// Specializations are in:
+# include <mln/level/transform.spe.hh>
+
+
namespace mln
{
@@ -74,65 +78,42 @@
namespace impl
{
- template <typename I, typename F, typename O>
- void transform(metal::false_, // general case
- const Image<I>& input_, const Function_v2v<F>& f_,
Image<O>& output_)
+ namespace generic
{
- const I& input = exact(input_);
- const F& f = exact(f_);
- O& output = exact(output_);
-
- mln_piter(I) p(input.domain());
- for_all(p)
- output(p) = f( input(p) );
- }
-
template <typename I, typename F, typename O>
- void transform(metal::true_, // low quantization
- const Image<I>& input_, const Function_v2v<F>& f_,
Image<O>& output_)
+ void transform_(const Image<I>& input_, const Function_v2v<F>& f_,
Image<O>& output_)
{
+ trace::entering("level::impl::generic::transform");
+
const I& input = exact(input_);
const F& f = exact(f_);
O& output = exact(output_);
- value::lut_vec<mln_vset(I), mln_result(F)> lut(input.values(), f);
mln_piter(I) p(input.domain());
for_all(p)
- output(p) = lut(input(p));
- }
-
+ output(p) = f( input(p) );
- // FIXME: Handle the cases of fastest images.
+ trace::exiting("level::impl::generic::transform");
+ }
-// template <typename I, typename F, typename O>
-// void transform(metal::true_, // low quantization
-// const Image<I>& input_, const Function_v2v<F>& f_,
Image<O>& output_)
-// {
-// const I& input = exact(input_);
-// const F& f = exact(f_);
-// O& output = exact(output_);
-
-// value::lut_vec<mln_vset(I), mln_result(F)> lut(input.values(), f);
-// mln_pixter(const I) pi(input); // FIXME
-// mln_pixter(O) po(output);
-// po.start();
-// for_all(pi)
-// {
-// po.val() = lut(pi.val());
-// po.next();
-// }
-// }
+ } // end of namespace mln::level::impl::generic
} // end of namespace mln::level::impl
+ // Facade.
+
template <typename I, typename F, typename O>
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::transform(mln_is_value_lowq(I)(),
+ impl::transform_(mln_is_value_lowq(I)(),
exact(input), exact(f), exact(output));
+
+ trace::exiting("level::transform");
}
@@ -140,10 +121,14 @@
mln_ch_value(I, mln_result(F))
transform(const Image<I>& input, const Function_v2v<F>& f)
{
+ 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);
+ transform_(input, f, output);
+
+ trace::exiting("level::transform");
return output;
}
Index: trunk/milena/mln/level/paste.hh
===================================================================
Index: trunk/milena/mln/level/stretch.hh
===================================================================
--- trunk/milena/mln/level/stretch.hh (revision 1493)
+++ trunk/milena/mln/level/stretch.hh (revision 1494)
@@ -66,6 +66,8 @@
void stretch(value::int_u<n>,
const Image<I>& input, Image<O>& output)
{
+ trace::entering("level::impl::stretch");
+
mln_value(I) min_, max_;
estim::min_max(input, min_, max_);
if (max_ == min_)
@@ -78,6 +80,8 @@
float b = (m * max - M * min) / (max - min);
fun::v2v::linear<float, float, int> f(a, b);
level::transform(input, f, output);
+
+ trace::exiting("level::impl::stretch");
}
} // end of namespace mln::level::impl
@@ -86,8 +90,12 @@
template <typename I, typename O>
void stretch(const Image<I>& input, Image<O>& output)
{
+ trace::entering("level::stretch");
+
mln_precondition(exact(output).domain() == exact(input).domain());
impl::stretch(mln_value(O)(), input, output);
+
+ trace::exiting("level::stretch");
}
# endif // ! MLN_INCLUDE_ONLY
Index: trunk/milena/mln/level/compute.hh
===================================================================
--- trunk/milena/mln/level/compute.hh (revision 1493)
+++ trunk/milena/mln/level/compute.hh (revision 1494)
@@ -72,10 +72,14 @@
mln_result(A)
compute(const Image<I>& input, const Accumulator<A>& a_)
{
+ trace::entering("level::compute");
+
mln_precondition(exact(input).has_data());
A a = exact(a_); // Cpy.
a.init();
level::take(input, a);
+
+ trace::exiting("level::compute");
return a.to_result();
}