vigra - ReduceFunctor< FUNCTOR, VALUETYPE > Class Template Reference

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

| ReduceFunctor< FUNCTOR, VALUETYPE > Class Template Reference Functors To Inspect Images |

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 | result_type
typedef VALUETYPE | second_argument_type

## Public Member Functions
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
| ReduceFunctor (FUNCTOR const &f, VALUETYPE const &initial)
void | reset ()

## 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 actually 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 actually a template parameter.)

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 actually a template parameter.)

typedef VALUETYPE result_type

the functor's result type

## Constructor & Destructor Documentation

ReduceFunctor | ( | FUNCTOR const & | f,
|  | VALUETYPE const & | initial
| ) |  |

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

## Member Function Documentation

void reset | ( | ) |  |

Reset accumulator to the initial value.

void operator() | ( | T const & | v) |  |

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 operator() | ( | T1 const & | v1,
|  | T2 const & | v2
| ) |  |

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.

result_type const& operator() | ( | ) |  | const

return current value

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

- vigra/inspectimage.hxx

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany | html generated using doxygen and Python vigra 1.10.0 (Thu Jan 8 2015)