
URL: https://svn.lrde.epita.fr/svn/oln/trunk ChangeLog: 2009-02-12 Frederic Bour <bour@lrde.epita.fr> Add connected filters dispatcher (not tested).. * milena/sandbox/fred/Makefile: . * milena/sandbox/fred/connected_filter.hh: New. * milena/sandbox/fred/leveling_filter.hh: . * milena/sandbox/fred/mean.hh: . --- Makefile | 6 ++ connected_filter.hh | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++ leveling_filter.hh | 34 ++++++++------ mean.hh | 82 +++++++++++++++------------------- 4 files changed, 186 insertions(+), 59 deletions(-) Index: trunk/milena/sandbox/fred/connected_filter.hh =================================================================== --- trunk/milena/sandbox/fred/connected_filter.hh (revision 0) +++ trunk/milena/sandbox/fred/connected_filter.hh (revision 3357) @@ -0,0 +1,123 @@ +// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory +// (LRDE) +// +// 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_CANVAS_MORPHO_CONNECTED_FILTER_HH +# define MLN_CANVAS_MORPHO_CONNECTED_FILTER_HH + +/// \file mln/canvas/morpho/connected_filter.hh +/// +/// Connected filters dispatch (algebraic & leveling filters). +/// + +# include "leveling_filter.hh" +# include <mln/canvas/morpho/algebraic_filter.hh> +# include <mln/trait/accumulators.hh> + +namespace mln { + namespace canvas { + namespace morpho { + + // Facade Fwd Declaration + template <typename I, typename N, typename A> + mln_concrete(I) + connected_filter(const Image<I>& input, const Neighborhood<N>& nbh, + const Accumulator<A>& a, const typename A::result& lambda, bool increasing); + +# ifndef MLN_INCLUDE_ONLY + + // Dispatch. + namespace internal + { + + template <typename I, typename N, typename A> + inline + mln_concrete(I) + connected_filter_dispatch(mln::trait::accumulator::when_pix::use_none, + const Image<I>& input, const Neighborhood<N>& nbh, + const Accumulator<A>& a, const typename A::result& lambda, + bool increasing) + { + return algebraic_filter_dispatch(input, nbh, a, lambda, increasing); + } + + template <typename I, typename N, typename A> + inline + mln_concrete(I) + connected_filter_dispatch(mln::trait::accumulator::when_pix::use_p, + const Image<I>& input, const Neighborhood<N>& nbh, + const Accumulator<A>& a, const typename A::result& lambda, + bool increasing) + { + return algebraic_filter_dispatch(input, nbh, a, lambda, increasing); + } + + template <typename I, typename N, typename A> + inline + mln_concrete(I) + connected_filter_dispatch(mln::trait::accumulator::when_pix::use_v, + const Image<I>& input, const Neighborhood<N>& nbh, + const Accumulator<A>& a, const typename A::result& lambda, + bool increasing) + { + return leveling_filter_dispatch(input, nbh, a, lambda, increasing); + } + + template <typename I, typename N, typename A> + inline + mln_concrete(I) + connected_filter_dispatch(mln::trait::accumulator::when_pix::use_pix, + const Image<I>& input, const Neighborhood<N>& nbh, + const Accumulator<A>& a, const typename A::result& lambda, + bool increasing) + { + return leveling_filter_dispatch(input, nbh, a, lambda, increasing); + } + + } // end of namespace mln::canvas::morpho::internal + + +# endif // ! MLN_INCLUDE_ONLY + + // Facade. + + template <typename I, typename N, typename A> + mln_concrete(I) + connected_filter(const Image<I>& input, const Neighborhood<N>& nbh, + const Accumulator<A>& a, const typename A::result& lambda, bool increasing) + { + return internal::connected_filter_dispatch(mln_trait_accu_when_pix(A)(), + input, nbh, a, lambda, increasing); + } + + + } // end of namespace mln::canvas::morpho + } // end of namespace mln::canvas +} // end of namespace mln + + +#endif // ! MLN_CANVAS_MORPHO_CONNECTED_FILTER_HH Index: trunk/milena/sandbox/fred/leveling_filter.hh =================================================================== --- trunk/milena/sandbox/fred/leveling_filter.hh (revision 3356) +++ trunk/milena/sandbox/fred/leveling_filter.hh (revision 3357) @@ -59,10 +59,11 @@ namespace morpho { // Facade Fwd Declaration - template < typename I, typename N, typename A, typename L> + template <typename I, typename N, typename A> mln_concrete(I) leveling_filter(const Image<I>& input, const Neighborhood<N>& nbh, - const Accumulator<A>& a, L lambda, bool increasing); + const Accumulator<A>& a, const typename A::result& lambda, + bool increasing); # ifndef MLN_INCLUDE_ONLY @@ -86,10 +87,11 @@ return parent(x) = find_root(parent, parent(x)); } - template < typename I, typename N, typename S, typename A, typename L> + template <typename I, typename N, typename S, typename A> mln_concrete(I) leveling_filter(const Image<I>& input_, const Neighborhood<N>& nbh_, - const Site_Set<S>& s_, const Accumulator<A>& a_, L lambda) + const Site_Set<S>& s_, + const Accumulator<A>& a_, const typename A::result& lambda) { trace::entering("canvas::morpho::impl::generic::leveling_filter"); // FIXME: Test?! @@ -204,10 +206,11 @@ return parent.element(x) = find_root_fastest(parent, parent.element(x)); } - template < typename I, typename N, typename A, typename L> + template <typename I, typename N, typename A> mln_concrete(I) leveling_filter_fastest(const Image<I>& input_, const Neighborhood<N>& nbh_, - const util::array<unsigned>& s, const Accumulator<A>& a_, L lambda) + const util::array<unsigned>& s, + const Accumulator<A>& a_, const typename A::result& lambda) { trace::entering("canvas::morpho::impl::leveling_fastest"); @@ -305,11 +308,12 @@ { // Leveling - template < typename I, typename N, typename A, typename L> + template <typename I, typename N, typename A> mln_concrete(I) leveling_filter_dispatch(metal::false_, const Image<I>& input, const Neighborhood<N>& nbh, - const Accumulator<A>& a, L lambda, bool increasing) + const Accumulator<A>& a, const typename A::result& lambda, + bool increasing) { p_array < mln_psite(I) > s = increasing ? @@ -318,11 +322,12 @@ return impl::generic::leveling_filter(input, nbh, s, a, lambda); } - template < typename I, typename N, typename A, typename L> + template <typename I, typename N, typename A> mln_concrete(I) leveling_filter_dispatch(metal::true_, const Image<I>& input, const Neighborhood<N>& nbh, - const Accumulator<A>& a, L lambda, bool increasing) + const Accumulator<A>& a, const typename A::result& lambda, + bool increasing) { util::array<unsigned> s = increasing ? @@ -331,11 +336,11 @@ return impl::leveling_filter_fastest(input, nbh, s, a, lambda); } - template < typename I, typename N, typename A, typename L> + template <typename I, typename N, typename A> inline mln_concrete(I) leveling_filter_dispatch(const Image<I>& input, const Neighborhood<N>& nbh, - const Accumulator<A>& a, L lambda, bool increasing) + const Accumulator<A>& a, const typename A::result& lambda, bool increasing) { enum { @@ -357,11 +362,12 @@ // Facade. - template < typename I, typename N, typename A, typename L> + template <typename I, typename N, typename A> inline mln_concrete(I) leveling_filter(const Image<I>& input, const Neighborhood<N>& nbh, - const Accumulator<A>& a, L lambda, bool increasing) + const Accumulator<A>& a, const typename A::result& lambda, + bool increasing) { //FIXME: Do we need to check input validity ? return internal::leveling_filter_dispatch(input, nbh, a, lambda, increasing); Index: trunk/milena/sandbox/fred/Makefile =================================================================== --- trunk/milena/sandbox/fred/Makefile (revision 3356) +++ trunk/milena/sandbox/fred/Makefile (revision 3357) @@ -8,6 +8,7 @@ CXX=g++ LD=g++ LDFLAGS= +RM=rm $(TARGET): $(OBJS) $(LD) $(LDFLAGS) -o $@ $(OBJS) @@ -17,3 +18,8 @@ %.o: %.hh $(CXX) $(CXXFLAGS) -c $< + +all: $(TARGET) + +clean: + $(RM) -f $(TARGET) *.o *~ \ No newline at end of file Index: trunk/milena/sandbox/fred/mean.hh =================================================================== --- trunk/milena/sandbox/fred/mean.hh (revision 3356) +++ trunk/milena/sandbox/fred/mean.hh (revision 3357) @@ -69,15 +69,10 @@ namespace internal { - template <typename T, - typename S = mln_sum(T), - typename M = S> - struct accu_mean_set_value : public mln::accu::mean<T, S, M> + template <typename T, typename S> + struct sum_set_value : public mln::accu::sum<T, S> { - typedef mln::accu::mean<T, S, M> super; - typedef typename super::result result; - - void set_value(const result& v); + void set_value(const S& s); }; } @@ -85,23 +80,21 @@ /// Morphological (i.e. for pixel and pixel values) accumulator calculating mean. /// Valid for leveling algorithm. template <typename I> - class mean: public mln::accu::internal::base<typename internal::accu_mean_set_value<mln_value(I)>::result, mean<I> > + class mean: public mln::accu::internal::base<mln_sum(mln_value(I)), mean<I> > { public: typedef util::pix<I> argument; - typedef typename internal::accu_mean_set_value<mln_value(I)>::result result; - typedef typename internal::accu_mean_set_value<mln_value(I)>::q_result q_result; + typedef mln_value(I) value; + typedef mln_sum(value) result; mean(); - /// Manipulators. /// \{ void init(); - - void take(const mln_value(I)& v); + void take(const value& v); void take(const argument& t); - void take(const mean<I>& m); + void take(const mean<I>& other); void set_value(const result& r); /// \} @@ -110,37 +103,33 @@ result to_result() const; /// Check whether this accu is able to return a result. + /// Always true here. bool is_valid() const; protected: - /// The mean - internal::accu_mean_set_value<mln_value(I)> accu_; - }; - + accu::count<value> count_; + internal::sum_set_value<value,result> sum_; + }; # ifndef MLN_INCLUDE_ONLY namespace internal { - template <typename T, - typename S, - typename M> + template <typename T, typename S> void - accu_mean_set_value<T, S, M>::set_value(const typename internal::accu_mean_set_value<T, S, M>::result& v) + sum_set_value<T, S>::set_value(const S& s) { - // FIXME: bad - this->sum_.init(); - this->sum_.take(v * this->count_.to_result()); - } + this->s_ = s; + }; } template <typename I> inline - mean<I>::mean () : - accu_ () + mean<I>::mean() { + init(); } template <typename I> @@ -148,39 +137,41 @@ void mean<I>::init () { - accu_.init(); + count_.init(); + sum_.init(); } template <typename I> inline void - mean<I>::take (const mean<I>& accu) + mean<I>::take(const value& t) { - accu_.take(accu.accu_); + count_.take(t); + sum_.take(t); } template <typename I> inline void - mean<I>::take (const util::pix<I>& elt) + mean<I>::take(const argument& t) { - take(elt.v()); - }; + take(t.v()); + } template <typename I> inline void - mean<I>::take (const mln_value(I)& elt) + mean<I>::take(const mean<I>& other) { - accu_.take(elt); - }; + count_.take(other.count_); + sum_.take(other.sum_); + } template <typename I> - inline void - mean<I>::set_value(const typename mean<I>::result& r) + mean<I>::set_value(const result& r) { - accu_.set_value(r); + sum_.set_value(r * count_.to_result()); }; template <typename I> @@ -188,16 +179,17 @@ typename mean<I>::result mean<I>::to_result() const { - return accu_.to_result(); - }; + unsigned n = count_.to_result(); + return sum_.to_result() / n; + } template <typename I> inline bool mean<I>::is_valid() const { - return accu_.is_valid(); - }; + return count_.to_result() != 0; + } # endif // ! MLN_INCLUDE_ONLY