[ VIGRA Homepage | Class Index | Function Index | File Index | Main Page ]

details ReduceFunctor Class Template Reference VIGRA

Apply a functor to reduce the dimensionality of an array. More...

#include "vigra/inspectimage.hxx"


Public Types

typedef VALUETYPE argument_type
typedef VALUETYPE first_argument_type
typedef VALUETYPE second_argument_type
typedef VALUETYPE result_type

Public Methods

 ReduceFunctor (FUNCTOR const &f, VALUETYPE const &initial)
void reset ()
template<class T> void operator() (T const &v)
template<class T1, class T2> void operator() (T1 const &v1, T2 const &v2)
result_type const & operator() () const


Detailed Description


template<class FUNCTOR, class VALUETYPE>
class vigra::ReduceFunctor< FUNCTOR, VALUETYPE >

Apply a functor to reduce the dimensionality of an array.

This functor can be used to emulate the reduce standard function of functional programming using std::for_each() or inspectImage() and similar functions. This functor is initialized with a functor encoding the expression to be applied, and an accumulator storing the current state of the reduction. For each element of the array, the embedded functor is called with the accumulator and the current element(s) of the array. The result of the reduction is available by calling reduceFunctor().

Traits defined:

FunctorTraits::isUnaryAnalyser, FunctorTraits::isBinaryAnalyser and FunctorTraits::isInitializer are true (VigraTrueType)

Usage:

#include "vigra/inspectimage.hxx"
Namespace: vigra

    vigra::BImage img;
    ... // fill the image

    // create a functor to sum the elements of the image
    vigra::ReduceFunctor<std::plus<int>, int> sumElements(std::plus<int>, 0);
    
    vigra::inspectImage(srcImageRange(img), sumElements);

    cout << "The sum of the elements " << sumElements() << endl;

Required Interface:

    FUNCTOR f;
    VALUETYPE accumulator, current1, current2;
    
    f(accumulator, current1); // for inspectImage()
    f(accumulator, current1, current2); // for inspectTwoImages()


Member Typedef Documentation


typedef VALUETYPE argument_type

 

the functor's argument type when used as a unary inspector. (This is not strictly correct since the argument type is actuall a template parameter.)


typedef VALUETYPE first_argument_type

 

the functor's first argument type when used as a binary inspector. (This is not strictly correct since the argument type is actuall a template parameter.)


typedef VALUETYPE result_type

 

the functor's result type


typedef VALUETYPE second_argument_type

 

the functor's second argument type when used as a binary inspector. (This is not strictly correct since the argument type is actuall a template parameter.)


Constructor & Destructor Documentation


ReduceFunctor FUNCTOR const &    f,
VALUETYPE const &    initial
[inline]

 

create with the given functor and initial value initial for the accumulator.


Member Function Documentation


result_type const& operator()   const [inline]

 

return current value


void operator() T1 const &    v1,
T2 const &    v2
[inline]

 

Use ternary functor to connect given values with accumulator. The accumulator is used as the first argument, the values v1 ans v2 as the second and third.


void operator() T const &    v [inline]

 

Use binary functor to connect given value with the accumulator. The accumulator is used as the first argument, the value v as the second.


void reset   [inline]

 

Reset accumulator to the initial value.


The documentation for this class was generated from the following file:

© Ullrich Köthe (koethe@informatik.uni-hamburg.de)
Cognitive Systems Group, University of Hamburg, Germany

html generated using doxygen and Python
VIGRA 1.3.3 (18 Aug 2005)