
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox ChangeLog: 2009-02-03 Edwin Carlinet <carlinet@lrde.epita.fr> First tries of accus with specialisation. * accu.cc: New. * fredwin.cc: . --- accu.cc | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fredwin.cc | 96 ++++++++++++++++++++++++++++++++++++------------------------- 2 files changed, 149 insertions(+), 38 deletions(-) Index: trunk/milena/sandbox/edwin/accu.cc =================================================================== --- trunk/milena/sandbox/edwin/accu.cc (revision 0) +++ trunk/milena/sandbox/edwin/accu.cc (revision 3256) @@ -0,0 +1,91 @@ +template <typename E> +struct Accumulator : public object<E> +{ + typedef mln_vtypes(E, take_with) take_with; + + + +}; + +namespace accu +{ + template <typename T> + struct card : public Accumulator< card<T> > + { + void take(const T& elt) { ++c_; } + unsigned c_; + }; +} + + +namespace impl +{ + + template <typename I, template<typename E> class A> + void + algebraic(const Image<I>& input, + const Accumulator< A<point2d> >& acc) + { + const I& ima = exact(input); + + mln_piter(I) p(ima.domain()); + for_all(p) + acc.take(p); + } + + // fast implementation + template <typename I, template<typename E> class A> + void + leveling (const Image<I>& input, + const Accumulator< A< pix<I> > >& acc) + { + const I& ima = exact(input); + + mln_pixter(const I) px(ima); + for_all(px) + acc.take(px); + } + + // generic implementation + template <typename I, template<typename E> class A> + void + leveling (const Image<I>& input, + const Accumulator< A<point2d> >& acc) + { + const I& ima = exact(input); + + mln_piter(I) p(ima.domain()); + for_all(p) + acc.take(p); + } + + +} // impl + +namespace internal +{ + template <typename I, typename A> + void + leveling_dispatch(const Image<I>& input, + const Accumulator<A>& acc) + { + + //Si when_pix = use_only + // + + algebraic_dispatch(mlc_equal(mln_trait_image_speed(I), + trait::image::speed::fastest)::value, + input, + acc); + } + +} + +// Facade. + +template <typename M, typename I> +void +algebraic(const Image<I>& input, const Meta_Accumulator<M>& acc) // FIXME: on préfÚre Meta_Accumulator ! +{ + internal::algebraic_dispatch(input, acc); +} Index: trunk/milena/sandbox/edwin/fredwin.cc =================================================================== --- trunk/milena/sandbox/edwin/fredwin.cc (revision 3255) +++ trunk/milena/sandbox/edwin/fredwin.cc (revision 3256) @@ -1,5 +1,7 @@ +// TODO : ajouter un trait when_pix +// when_pix in {use_p template <typename E> struct Accumulator { @@ -46,15 +48,16 @@ + namespace impl { // Leveling // -------- - template <typename I, typename A> + template <typename I, typename PX> void - leveling(const Image<I>& input, const Accumulator<A>& acc) + leveling_generic(const Image<I>& input, const Accumulator<PX>& acc) { const I& ima = exact(input); // algo en resume : @@ -80,29 +83,15 @@ // spécialisation pour les images fastest - // Algebraic - // --------- - - - template <typename I, typename A> - void - generic_algebraic(const Image<I>& input, const Accumulator<A>& acc) - { - // algo en resume : - mln_piter(I) p(ima.domain()); - for_all(p) - acc.take(p); // psite - } - - template <typename I, typename A> - void - algebraic_fastest(const Image<I>& input, const Accumulator<A>& acc) - { - // algo en resume : - mln_pixter(const I) pxl(input); - for_all(pxl) - acc.take(pxl); - } + // template <typename I, typename A> +// void +// algebraic_fastest(const Image<I>& input, const Accumulator<A>& acc) +// { +// // algo en resume : +// mln_pixter(const I) pxl(input); +// for_all(pxl) +// acc.take(pxl); +// } // FIXME: pb: soit on passe du "site", soit du "pixel"... @@ -123,29 +112,60 @@ // FIXME: On veut qqch qui ressemble à : - template <typename I, typename A> +// template <typename I, typename A> +// void +// generic_algebraic_or_leveling(const Image<I>& input, const Accumulator<A>& acc) +// { +// const I& ima = exact(input); +// // algo en resume : +// mln_piter(I) p(ima.domain()); +// for_all(p) +// acc.take( FIXME ); +// } + +// template <typename I, typename A> +// void +// algebraic_or_leveling_fastest(const Image<I>& input, const Accumulator<A>& acc) +// { +// const I& ima = exact(input); +// // algo en resume : +// mln_pixter(const I) pxl(ima); +// for_all(pxl) +// acc.take( FIXME ); +// } + + + // FIXME: Mais ce n'est peut-être pas possible avec des + // Accumulator... + + // Algebraic + // --------- + + + template <typename I, template<typename E> typename A> void - generic_algebraic_or_leveling(const Image<I>& input, const Accumulator<A>& acc) + algebraic(const Image<I>& input, const Accumulator< A<point2d> >& acc) { + const I& ima = exact(input); + // algo en resume : mln_piter(I) p(ima.domain()); for_all(p) - acc.take( FIXME ); + acc.take(p); // psite } - template <typename I, typename A> + + + template <typename I, template<typename E> typename A> void - algebraic_or_leveling_fastest(const Image<I>& input, const Accumulator<A>& acc) + leveling (const Image<I>& input, const Accumulator< A< pix<I> > >& acc) { - // algo en resume : - mln_pixter(const I) pxl(input); - for_all(pxl) - acc.take( FIXME ); - } - + const I& ima = exact(input); - // FIXME: Mais ce n'est peut-être pas possible avec des - // Accumulator... + mln_pixter(const I) px(ima); + for_all(px) + acc.take(px); + } } // impl