https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Make subdirectory histo ready for rereading.
* tests/histo/compute.cc: Activate code.
Remove debug code.
* mln/trait/value_.hh (mln_value_card_from_): Fix macro.
* mln/histo/compute.hh: Split file contents with...
* mln/histo/compute.spe.hh: ...this new file.
* mln/value/int_s.hh (card, max): Fix definitions.
mln/histo/compute.hh | 28 ++++++++++-------
mln/histo/compute.spe.hh | 50 ++++++++++++-------------------
mln/trait/value_.hh | 4 +-
mln/value/int_s.hh | 4 +-
tests/histo/compute.cc | 74 ++++++++++++++++++++---------------------------
5 files changed, 73 insertions(+), 87 deletions(-)
Index: tests/histo/compute.cc
--- tests/histo/compute.cc (revision 1527)
+++ tests/histo/compute.cc (working copy)
@@ -48,57 +48,49 @@
using namespace mln;
using value::int_u8;
-// // Test on 'bool'.
-// {
-// accu::histo< value::set<bool> > h;
-
-// for (unsigned i = 0; i < 5; ++i)
-// h.take(false);
-// for (unsigned i = 0; i < 2; ++i)
-// h.take(true);
-// h.untake(true);
-
-// mln_assertion(h[0] * 10 + h[1] = 51);
-// mln_assertion(h(false) * 10 + h(true) = 51);
-// }
-
-// // Test on 'int_u8'.
-// {
-// image2d<int_u8> ima(3, 3);
-// debug::iota(ima);
-// ima.at(0,0) = 2;
-
-// histo::data< value::set<int_u8> > h = histo::compute(ima);
-// std::ostringstream oss;
-// oss << h;
-// mln_assertion(oss.str() = "2:2 3:1 4:1 5:1 6:1 7:1 8:1 9:1 ");
-
-// int_u8 i = 2;
-// mln_assertion(h(i) = 2);
-// }
+ // Test on 'bool'.
+ {
+ accu::histo< value::set<bool> > h;
+
+ for (unsigned i = 0; i < 5; ++i)
+ h.take(false);
+ for (unsigned i = 0; i < 2; ++i)
+ h.take(true);
+ h.untake(true);
+
+ mln_assertion(h[0] * 10 + h[1] = 51);
+ mln_assertion(h(false) * 10 + h(true) = 51);
+ }
- // Test on 'int_s5'.
+ // Test on 'int_u8'.
{
- typedef value::int_s<5> int_s5;
- image2d<int_s5> ima(3, 3);
+ image2d<int_u8> ima(3, 3);
debug::iota(ima);
ima.at(0,0) = 2;
- std::cout << "int_s5: "
- << value::props< int_s5 >::min() << ' '
- << value::props< int_s5 >::max() << ' '
- << value::props< int_s5 >::card_ << std::endl;
+ histo::data< value::set<int_u8> > h = histo::compute(ima);
+ std::ostringstream oss;
+ oss << h;
+ mln_assertion(oss.str() = "2:2 3:1 4:1 5:1 6:1 7:1 8:1 9:1 ");
- debug::println(ima);
+ int_u8 i = 2;
+ mln_assertion(h(i) = 2);
+ }
+ // Test on 'int_s5'; the value set is { -15, .., -1, 0, 1, .., 15 }
+ // the corresponding indices are: 0 .. 14 15 16 .. 30
+ {
+ typedef value::int_s<5> int_s5;
+ image2d<int_s5> ima(3, 3);
+ debug::iota(ima);
histo::data< value::set<int_s5> > h = histo::compute(ima);
- std::cout << "nvalues = " << h.vset().nvalues() <<
std::endl;
- std::cout << h << std::endl;
+ mln_assertion(h.vset().nvalues() = 31);
- for (unsigned i = 0; i < h.vset().nvalues(); ++i)
- std::cout << i << ':' << h[i] << ' ';
- std::cout << std::endl;
+ for (unsigned i = 0; i <= 15; ++i) // values from -15 to 0
+ mln_assertion(h[i] = 0);
+ for (unsigned i = 25; i <= 30; ++i) // values from 10 to 15
+ mln_assertion(h[i] = 0);
}
}
Index: mln/trait/value_.hh
--- mln/trait/value_.hh (revision 1527)
+++ mln/trait/value_.hh (working copy)
@@ -68,10 +68,10 @@
mln::trait::value::quant::low)
# define mln_value_card_from_(N) \
- N <= 16 \
+ (N <= 16 \
? mlc_pow_int((N <= 16 ? 2 : 1), \
(N <= 16 ? N : 1)) \
- : 0
+ : 0)
Index: mln/histo/compute.spe.hh
--- mln/histo/compute.spe.hh (revision 1524)
+++ mln/histo/compute.spe.hh (working copy)
@@ -25,17 +25,16 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_HISTO_COMPUTE_HH
-# define MLN_HISTO_COMPUTE_HH
+#ifndef MLN_HISTO_COMPUTE_SPE_HH
+# define MLN_HISTO_COMPUTE_SPE_HH
-/*! \file mln/histo/compute.hh
+/*! \file mln/histo/compute.spe.hh
*
- * \brief Routine to compute an histogram.
+ * \brief Specializations of histogram computation.
*/
-# include <mln/core/concept/image.hh>
-# include <mln/histo/data.hh>
+# ifndef MLN_INCLUDE_ONLY
namespace mln
{
@@ -43,28 +42,25 @@
namespace histo
{
- /// Compute the histogram of image \p input.
- template <typename I>
- data<mln_vset(I)> compute(const Image<I>& input);
-
-
-# ifndef MLN_INCLUDE_ONLY
-
namespace impl
{
+ namespace generic
+ {
template <typename I>
- data<mln_vset(I)> compute(trait::image::speed::any, const I& input)
+ data<mln_vset(I)> compute_(const I& input);
+ }
+
+ template <typename I>
+ data<mln_vset(I)>
+ compute_(trait::image::speed::any, const I& input)
{
- data<mln_vset(I)> h(input.values());
- mln_piter(I) p(input.domain());
- for_all(p)
- ++h(input(p));
- return h;
+ return generic::compute_(input);
}
template <typename I>
- data<mln_vset(I)> compute(trait::image::speed::fastest, const I& input)
+ data<mln_vset(I)>
+ compute_(trait::image::speed::fastest, const I& input)
{
data<mln_vset(I)> h(input.values());
mln_pixter(const I) p(input);
@@ -75,19 +71,11 @@
} // end of namespace mln::histo::impl
-
- template <typename I>
- data<mln_vset(I)> compute(const Image<I>& input)
- {
- mln_precondition(exact(input).has_data());
- return impl::compute(mln_trait_image_speed(I)(), exact(input));
- }
-
-# endif // ! MLN_INCLUDE_ONLY
-
} // end of namespace mln::histo
} // end of namespace mln
+# endif // ! MLN_INCLUDE_ONLY
+
-#endif // ! MLN_HISTO_COMPUTE_HH
+#endif // ! MLN_HISTO_COMPUTE_SPE_HH
Index: mln/histo/compute.hh
--- mln/histo/compute.hh (revision 1527)
+++ mln/histo/compute.hh (working copy)
@@ -37,6 +37,10 @@
# include <mln/histo/data.hh>
+// Specializations are in:
+# include <mln/histo/compute.spe.hh>
+
+
namespace mln
{
@@ -53,8 +57,11 @@
namespace impl
{
+ namespace generic
+ {
+
template <typename I>
- data<mln_vset(I)> compute(trait::image::speed::any, const I& input)
+ data<mln_vset(I)> compute_(const I& input)
{
data<mln_vset(I)> h(input.values());
mln_piter(I) p(input.domain());
@@ -63,15 +70,7 @@
return h;
}
- template <typename I>
- data<mln_vset(I)> compute(trait::image::speed::fastest, const I& input)
- {
- data<mln_vset(I)> h(input.values());
- mln_pixter(const I) p(input);
- for_all(p)
- ++h(p.val());
- return h;
- }
+ } // end of namespace mln::histo::impl::generic
} // end of namespace mln::histo::impl
@@ -79,8 +78,15 @@
template <typename I>
data<mln_vset(I)> compute(const Image<I>& input)
{
+ trace::entering("histo::compute");
+ mlc_equal(mln_trait_image_quant(I), mln::trait::image::quant::low)::check();
mln_precondition(exact(input).has_data());
- return impl::compute(mln_trait_image_speed(I)(), exact(input));
+
+ data<mln_vset(I)> h = impl::compute_(mln_trait_image_speed(I)(),
+ exact(input));
+
+ trace::exiting("histo::compute");
+ return h;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/value/int_s.hh
--- mln/value/int_s.hh (revision 1527)
+++ mln/value/int_s.hh (working copy)
@@ -77,14 +77,14 @@
enum {
nbits = n,
- card = mln_value_card_from_(n)
+ card = mln_value_card_from_(n) - 1
};
typedef trait::value::nature::integer nature;
typedef trait::value::kind::data kind;
typedef mln_value_quant_from_(card) quant;
- static const self_ max() { return card / 2 - 1; }
+ static const self_ max() { return mln_value_card_from_(n) / 2 - 1; }
static const self_ min() { return - max(); }
static const self_ epsilon() { return 0; }