URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-02-05 Edwin Carlinet <carlinet(a)lrde.epita.fr>
Fix bugs for algebraic filter and cleaning.
* edwin/accu.cc: Separate and make clean.
* edwin/accu_trait.hh: Test use_p and use_whatever traits.
* edwin/algebraic.hh: Algebraic filter.
* edwin/card.hh: Card accumulator.
* edwin/fredwin.cc: Remove.
* edwin/leveling.hh: Leveling filter.
---
accu.cc | 161 +++++++---------------------------------------------------
accu_trait.hh | 3 -
algebraic.hh | 67 ++++++++++++++++++++++++
card.hh | 33 +++++++++++
leveling.hh | 99 +++++++++++++++++++++++++++++++++++
5 files changed, 221 insertions(+), 142 deletions(-)
Index: trunk/milena/sandbox/edwin/fredwin.cc (deleted)
===================================================================
Index: trunk/milena/sandbox/edwin/accu.cc
===================================================================
--- trunk/milena/sandbox/edwin/accu.cc (revision 3303)
+++ trunk/milena/sandbox/edwin/accu.cc (revision 3304)
@@ -1,155 +1,27 @@
-# include <mln/metal/equal.hh>
-# include <mln/metal/if.hh>
-# include <mln/metal/is_const.hh>
-
-# include <mln/core/concept/image.hh>
-# include <mln/accu/all.hh>
-# include <mln/util/pix.hh>
-# include <mln/make/pix.hh>
-# include "accu_trait.hh"
-
-using namespace mln;
-
-namespace mln
-{
-
- namespace morpho
- {
-
- namespace accu
- {
- template <typename T>
- struct card : public mln::accu::internal::base< unsigned, card<T> >
- {
- typedef T argument;
- void init () { c_ = 0; };
- void take (const card<T>& elt) { ++c_; };
- void take (const T& elt) { ++c_; };
- void take (const mln_value(T)& v) { ++c_; };
- unsigned to_result() const { return c_; };
- operator unsigned () const { return c_; };
- bool is_valid () const { return true; };
- card () { init(); };
-
- private:
- unsigned c_;
- };
- } // accu
- } // morpho
-
-
- namespace impl
- {
-
- template <typename I, typename A>
- void
- algebraic(const Image<I>& input,
- Accumulator<A>& acc)
- {
- const I& ima = exact(input);
- A& accu = exact (acc);
-
- mln_piter(I) p(ima.domain());
- for_all(p)
- accu.take(p);
- }
-
- // fast implementation
- template <typename I, typename A>
- void
- leveling_fast (const Image<I>& input,
- Accumulator<A>& acc)
- {
- const I& ima = exact(input);
- A& accu = exact (acc);
-
- mln_pixter(const I) px(ima);
- for_all(px)
- accu.take (px.val ());
- }
-
- // generic implementation
- template <typename I, typename A>
- void
- leveling (const Image<I>& input,
- Accumulator<A>& acc)
- {
- const I& ima = exact(input);
- A& accu = exact (acc);
-
- mln_piter(I) p(ima.domain());
- for_all(p)
- accu.take (mln::make::pix(ima, p));
- }
-
- } // impl
-
- namespace internal
- {
- template <typename I, typename A>
- void
- leveling_dispatch(metal::false_,
- const Image<I>& input,
- Accumulator<A>& acc)
- {
- impl::leveling(input, acc);
- }
-
- template <typename I, typename A>
- inline
- void
- leveling_dispatch(metal::true_,
- const Image<I>& input,
- Accumulator<A>& acc)
- {
- impl::leveling_fast(input, acc);
- }
-
- template <typename I, typename A>
- inline
- void
- leveling_dispatch(const Image<I>& input,
- Accumulator<A>& acc)
- {
- enum {
- test = (mlc_equal(mln_trait_image_speed(I),
- trait::image::speed::fastest)::value &&
- mlc_equal(mln_trait_accu_when_pix(A),
- trait::accu::when_pix::use_v)::value)
- };
- leveling_dispatch(metal::bool_<test>(), input, acc);
- }
-
- } // internal
-
-} //mln
-
-// Facade.
-
-template <typename I, typename A>
-void
-leveling(const Image<I>& input,
- Accumulator<A>& acc)
-{
- mln::internal::leveling_dispatch(input, acc);
-}
-
-
-# include <mln/accu/all.hh>
# include <mln/core/image/image2d.hh>
-
# include <mln/debug/iota.hh>
# include <mln/debug/println.hh>
# include <mln/core/var.hh>
# include <mln/util/timer.hh>
+
+# include "accu_trait.hh"
+# include "accu_trait.hh"
+# include "card.hh"
+# include "card.hh"
+# include "algebraic.hh"
+# include "algebraic.hh"
+# include "leveling.hh"
+# include "leveling.hh"
+
+
int main()
{
using namespace mln;
typedef image2d<int> I;
I ima(1000, 1000);
- mln::morpho::accu::card<util::pix<I> > acc;
+ mln::morpho::accu::card<point2d> acc;
float elapsed;
mln::util::timer chrono;
@@ -160,6 +32,14 @@
acc.init();
chrono.start();
for (int i = 0; i < 50; i++)
+ algebraic(ima, acc);
+ elapsed = chrono.stop();
+
+ std::cout << "(alge) " << elapsed << "s : "
<< acc.to_result() << std::endl;
+ /*
+ acc.init();
+ chrono.start();
+ for (int i = 0; i < 50; i++)
leveling(ima, acc);
elapsed = chrono.stop();
@@ -180,5 +60,6 @@
elapsed = chrono.stop();
std::cout << "(fast) " << elapsed << "s : "
<< acc.to_result() << std::endl;
+ */
}
Index: trunk/milena/sandbox/edwin/leveling.hh
===================================================================
--- trunk/milena/sandbox/edwin/leveling.hh (revision 0)
+++ trunk/milena/sandbox/edwin/leveling.hh (revision 3304)
@@ -0,0 +1,99 @@
+#ifndef LEVELING_HH_
+# define LEVELING_HH_
+
+
+# include "accu_trait.hh"
+# include <mln/metal/equal.hh>
+# include <mln/accu/all.hh>
+# include <mln/core/concept/image.hh>
+# include <mln/util/pix.hh>
+# include <mln/make/pix.hh>
+
+using namespace mln;
+
+namespace mln
+{
+ namespace impl
+ {
+ // fast implementation
+ template <typename I, typename A>
+ void
+ leveling_fast (const Image<I>& input,
+ Accumulator<A>& acc)
+ {
+ const I& ima = exact(input);
+ A& accu = exact (acc);
+
+ mln_pixter(const I) px(ima);
+ for_all(px)
+ accu.take (px.val ());
+ }
+
+ // generic implementation
+ template <typename I, typename A>
+ void
+ leveling (const Image<I>& input,
+ Accumulator<A>& acc)
+ {
+ const I& ima = exact(input);
+ A& accu = exact (acc);
+
+ mln_piter(I) p(ima.domain());
+ for_all(p)
+ accu.take (mln::make::pix(ima, p));
+ }
+
+ } // mln::impl
+
+ namespace internal
+ {
+ template <typename I, typename A>
+ void
+ leveling_dispatch(metal::false_,
+ const Image<I>& input,
+ Accumulator<A>& acc)
+ {
+ impl::leveling(input, acc);
+ }
+
+ template <typename I, typename A>
+ inline
+ void
+ leveling_dispatch(metal::true_,
+ const Image<I>& input,
+ Accumulator<A>& acc)
+ {
+ impl::leveling_fast(input, acc);
+ }
+
+ template <typename I, typename A>
+ inline
+ void
+ leveling_dispatch(const Image<I>& input,
+ Accumulator<A>& acc)
+ {
+ enum {
+ test = (mlc_equal(mln_trait_image_speed(I),
+ trait::image::speed::fastest)::value &&
+ mlc_equal(mln_trait_accu_when_pix(A),
+ trait::accu::when_pix::use_v)::value)
+ };
+ leveling_dispatch(metal::bool_<test>(), input, acc);
+ }
+
+ } // mln::internal
+
+} //mln
+
+
+// Facade.
+template <typename I, typename A>
+void
+leveling(const Image<I>& input,
+ Accumulator<A>& acc)
+{
+ mln::internal::leveling_dispatch(input, acc);
+}
+
+
+#endif /* !LEVELING_HH_ */
Index: trunk/milena/sandbox/edwin/algebraic.hh
===================================================================
--- trunk/milena/sandbox/edwin/algebraic.hh (revision 0)
+++ trunk/milena/sandbox/edwin/algebraic.hh (revision 3304)
@@ -0,0 +1,67 @@
+#ifndef ALGEBRAIC_HH_
+# define ALGEBRAIC_HH_
+
+# include "accu_trait.hh"
+# include <mln/metal/equal.hh>
+# include <mln/accu/all.hh>
+# include <mln/core/concept/image.hh>
+
+namespace mln
+{
+ namespace impl
+ {
+ template <typename I, typename A>
+ void
+ algebraic(const Image<I>& input,
+ Accumulator<A>& acc)
+ {
+ const I& ima = exact(input);
+ A& accu = exact (acc);
+
+ mln_piter(I) p(ima.domain());
+ for_all(p)
+ accu.take(p);
+ }
+ } // impl
+
+ namespace internal
+ {
+ template <typename I, typename A>
+ inline
+ void
+ algebraic_dispatch(metal::true_,
+ const Image<I>& input,
+ Accumulator<A>& acc)
+ {
+ impl::algebraic(input, acc);
+ }
+
+ template <typename I, typename A>
+ inline
+ void
+ algebraic_dispatch(const Image<I>& input,
+ Accumulator<A>& acc)
+ {
+ enum {
+ test = (mlc_equal(mln_trait_accu_when_pix(A),
+ trait::accu::when_pix::use_p)::value ||
+ mlc_equal(mln_trait_accu_when_pix(A),
+ trait::accu::when_pix::use_whatever)::value)
+ };
+ algebraic_dispatch(metal::bool_<test>(), input, acc);
+ }
+
+ } // mln::internal
+
+} //mln
+
+
+template <typename I, typename A>
+void
+algebraic(const mln::Image<I>& input,
+ mln::Accumulator<A>& acc)
+{
+ mln::internal::algebraic_dispatch(input, acc);
+}
+
+#endif /* !ALGEBRAIC_HH_ */
Index: trunk/milena/sandbox/edwin/card.hh
===================================================================
--- trunk/milena/sandbox/edwin/card.hh (revision 0)
+++ trunk/milena/sandbox/edwin/card.hh (revision 3304)
@@ -0,0 +1,33 @@
+#ifndef CARD_HH_
+# define CARD_HH_
+
+# include <mln/accu/all.hh>
+
+namespace mln
+{
+ namespace morpho
+ {
+ namespace accu
+ {
+ template <typename T>
+ struct card : public mln::accu::internal::base< unsigned, card<T> >
+ {
+ typedef T argument;
+
+ card () { init(); };
+ void init () { c_ = 0; };
+ void take (const card<T>& accu) { c_ += accu.c_; };
+ void take (const T& elt) { ++c_; };
+ unsigned to_result() const { return c_; };
+ bool is_valid () const { return true; };
+
+ private:
+ unsigned c_;
+ };
+ } // mln::morpho::accu
+ } // mln::morpho
+} // mln
+
+#endif /* !CARD_HH_ */
+
+
Index: trunk/milena/sandbox/edwin/accu_trait.hh
===================================================================
--- trunk/milena/sandbox/edwin/accu_trait.hh (revision 3303)
+++ trunk/milena/sandbox/edwin/accu_trait.hh (revision 3304)
@@ -3,7 +3,6 @@
# include <mln/trait/undef.hh>
-
# define mln_trait_accu_when_pix(A) typename trait::accu::accu_traits<A>::when_pix
@@ -41,7 +40,7 @@
template <typename T>
struct accu_traits< mln::morpho::accu::card <T> >
{
- typedef when_pix::use_v when_pix;
+ typedef when_pix::use_p when_pix;
};
} //accu