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

Public Types | Public Member Functions | List of all members
ReduceFunctor< FUNCTOR, VALUETYPE > Class Template Reference

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

result_type const & | operator() () const
template<class T>
void | operator() (T const &v)
template<class T1, class T2>
void | operator() (T1 const &v1, T2 const &v2)
| 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;
vigra::ReduceFunctor
Apply a functor to reduce the dimensionality of an array.
Definition inspectimage.hxx:1926
vigra::inspectImage
void inspectImage(...)
Apply read-only functor to every pixel in the image.
vigra::BImage
BasicImage< UInt8 > BImage
Definition stdimage.hxx:62

Required Interface:

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

## Member Typedef Documentation

## ◆ argument_type

template<class FUNCTOR, class VALUETYPE>

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.)

## ◆ first_argument_type

template<class FUNCTOR, class VALUETYPE>

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.)

## ◆ second_argument_type

template<class FUNCTOR, class VALUETYPE>

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.)

## ◆ result_type

template<class FUNCTOR, class VALUETYPE>

typedef VALUETYPE result_type

the functor's result type

## Constructor & Destructor Documentation

## ◆ ReduceFunctor()

template<class FUNCTOR, class VALUETYPE>

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

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

## Member Function Documentation

## ◆ reset()

template<class FUNCTOR, class VALUETYPE>

void reset | ( |  | ) |

Reset accumulator to the initial value.

## ◆ operator()() [1/3]

template<class FUNCTOR, class VALUETYPE>
template<class T>

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.

## ◆ operator()() [2/3]

template<class FUNCTOR, class VALUETYPE>
template<class T1, class T2>

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.

## ◆ operator()() [3/3]

template<class FUNCTOR, class VALUETYPE>

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.12.4