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

MultiArrayView< N, T, StrideTag > Class Template Reference

Base class for, and view to, vigra::MultiArray. More...

`#include <vigra/multi_array.hxx>`

Inheritance diagram for MultiArrayView< N, T, StrideTag >:

## Public Types

enum | ActualDimension
typedef StridedScanOrderIterator< actual_dimension, T, T const &, T const * > | const_iterator
typedef const value_type * | const_pointer
typedef const value_type & | const_reference
typedef vigra::detail::MultiIteratorChooser< StrideTag >::template Traverser< actual_dimension, T, Tconst &, Tconst * >::type | const_traverser
typedef MultiArrayShape< actual_dimension >::type | difference_type
typedef MultiArrayIndex | difference_type_1
typedef StridedScanOrderIterator< actual_dimension, T, T &, T * > | iterator
typedef difference_type | key_type
typedef MultiArray< N, T > | matrix_type
typedef value_type * | pointer
typedef value_type & | reference
typedef difference_type | size_type
typedef vigra::detail::MultiIteratorChooser< StrideTag >::template Traverser< actual_dimension, T, T &, T * >::type | traverser
typedef T | value_type
typedef MultiArrayView< N, T, StrideTag > | view_type

## Public Member Functions

bool | all () const
bool | any () const
iterator | begin ()
const_iterator | begin () const
template<unsigned int M>
MultiArrayView< N-1, T, typename vigra::detail::MaybeStrided< StrideTag, M >::type > | bind (difference_type_1 d) const
MultiArrayView< N-1, T, StridedArrayTag > | bindAt (difference_type_1 m, difference_type_1 d) const
MultiArrayView< N, typename ExpandElementResult< T >::type, StridedArrayTag > | bindElementChannel (difference_type_1 i) const
template<int M, class Index >
MultiArrayView< N-M, T, StridedArrayTag > | bindInner (const TinyVector< Index, M > &d) const
MultiArrayView< N-1, T, StridedArrayTag > | bindInner (difference_type_1 d) const
template<int M, class Index >
MultiArrayView< N-M, T, StrideTag > | bindOuter (const TinyVector< Index, M > &d) const
MultiArrayView< N-1, T, StrideTag > | bindOuter (difference_type_1 d) const
difference_type_1 | coordinateToScanOrderIndex (const difference_type &d) const
void | copy (const MultiArrayView &rhs)
template<class U , class CN >
void | copy (const MultiArrayView< N, U, CN > &rhs)
pointer | data () const
MultiArrayView< 1, T, StridedArrayTag > | diagonal () const
difference_type_1 | elementCount () const
iterator | end ()
const_iterator | end () const
MultiArrayView< N+1, typename ExpandElementResult< T >::type, StridedArrayTag > | expandElements (difference_type_1 d) const
bool | hasData () const
difference_type_1 | height () const
template<class U >
MultiArrayView & | init (const U &init)
MultiArrayView< N+1, T, StrideTag > | insertSingletonDimension (difference_type_1 i) const
bool | isInside (difference_type const &p) const
bool | isOutside (difference_type const &p) const
bool | isUnstrided (unsigned int dimension=N-1) const
template<class U >
void | meanVariance (U *mean, U *variance) const
void | minmax (T *minimum, T *maximum) const
| MultiArrayView ()
template<class ALLOC >
| MultiArrayView (BasicImage< T, ALLOC > const &image)
| MultiArrayView (const difference_type &shape, const difference_type &stride, const_pointer ptr)
| MultiArrayView (const difference_type &shape, const_pointer ptr)
template<class Stride >
| MultiArrayView (const MultiArrayView< N, T, Stride > &other)
MultiArrayView< N, Multiband< value_type >, StrideTag > | multiband () const
NormTraits< MultiArrayView >::NormType | norm (int type=2, bool useSquaredNorm=true) const
| operator MultiArrayView< N, T, StridedArrayTag > () const
template<class U , class C1 >
bool | operator!= (MultiArrayView< N, U, C1 > const &rhs) const
reference | operator() (difference_type_1 x)
const_reference | operator() (difference_type_1 x) const
reference | operator() (difference_type_1 x, difference_type_1 y)
const_reference | operator() (difference_type_1 x, difference_type_1 y) const
reference | operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z)
const_reference | operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z) const
reference | operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z, difference_type_1 u)
const_reference | operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z, difference_type_1 u) const
reference | operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z, difference_type_1 u, difference_type_1 v)
const_reference | operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z, difference_type_1 u, difference_type_1 v) const
template<class Expression >
MultiArrayView & | operator*= (multi_math::MultiMathOperand< Expression > const &rhs)
template<class U , class C1 >
MultiArrayView & | operator*= (MultiArrayView< N, U, C1 > const &rhs)
MultiArrayView & | operator*= (T const &rhs)
template<class Expression >
MultiArrayView & | operator+= (multi_math::MultiMathOperand< Expression > const &rhs)
template<class U , class C1 >
MultiArrayView & | operator+= (MultiArrayView< N, U, C1 > const &rhs)
MultiArrayView & | operator+= (T const &rhs)
template<class Expression >
MultiArrayView & | operator-= (multi_math::MultiMathOperand< Expression > const &rhs)
template<class U , class C1 >
MultiArrayView & | operator-= (MultiArrayView< N, U, C1 > const &rhs)
MultiArrayView & | operator-= (T const &rhs)
template<class Expression >
MultiArrayView & | operator/= (multi_math::MultiMathOperand< Expression > const &rhs)
template<class U , class C1 >
MultiArrayView & | operator/= (MultiArrayView< N, U, C1 > const &rhs)
MultiArrayView & | operator/= (T const &rhs)
template<class Expression >
MultiArrayView & | operator= (multi_math::MultiMathOperand< Expression > const &rhs)
MultiArrayView & | operator= (MultiArrayView const &rhs)
template<class U , class C1 >
MultiArrayView & | operator= (MultiArrayView< N, U, C1 > const &rhs)
MultiArrayView & | operator= (value_type const &v)
template<class U , class C1 >
bool | operator== (MultiArrayView< N, U, C1 > const &rhs) const
reference | operator[] (const difference_type &d)
const_reference | operator[] (const difference_type &d) const
template<int M>
MultiArrayView< N-M, T, StridedArrayTag > | operator[] (const TinyVector< MultiArrayIndex, M > &d) const
reference | operator[] (difference_type_1 d)
const_reference | operator[] (difference_type_1 d) const
MultiArrayView< N, T, StridedArrayTag > | permuteStridesAscending () const
MultiArrayView< N, T, StridedArrayTag > | permuteStridesDescending () const
template<class U >
U | product () const
void | reset ()
difference_type | scanOrderIndexToCoordinate (difference_type_1 d) const
const difference_type & | shape () const
difference_type_1 | shape (difference_type_1 n) const
difference_type_1 | size () const
difference_type_1 | size (difference_type_1 n) const
NormTraits< MultiArrayView >::SquaredNormType | squaredNorm () const
const difference_type & | stride () const
difference_type_1 | stride (int n) const
MultiArrayView< N, T, StridedArrayTag > | stridearray (const difference_type &s) const
difference_type | strideOrdering () const
MultiArrayView | subarray (difference_type p, difference_type q) const
template<class U >
U | sum () const
template<class U , class S >
void | sum (MultiArrayView< N, U, S > sums) const
void | swap (MultiArrayView &other)
void | swapData (MultiArrayView rhs)
template<class T2 , class C2 >
void | swapData (MultiArrayView< N, T2, C2 > rhs)
MultiArrayView< N, T, StridedArrayTag > | transpose () const
MultiArrayView< N, T, StridedArrayTag > | transpose (const difference_type &permutation) const
traverser | traverser_begin ()
const_traverser | traverser_begin () const
traverser | traverser_end ()
const_traverser | traverser_end () const
difference_type_1 | width () const

## Static Public Member Functions

static difference_type | strideOrdering (difference_type strides)

## Protected Attributes

pointer | m_ptr
difference_type | m_shape
difference_type | m_stride

## Detailed Description

template<unsigned int N, class T, class StrideTag>
class vigra::MultiArrayView< N, T, StrideTag >

Base class for, and view to, vigra::MultiArray.

This class implements the interface of both MultiArray and MultiArrayView. By default, MultiArrayViews are tagged as strided (using `StridedArrayTag` as third template parameter). This means that the array elements need not be consecutive in memory, making the view flexible to represent all kinds of subarrays and slices. In certain cases (which have become rare due to improvements of optimizer and processor technology), an array may be tagged with `UnstridedArrayTag` which indicates that the first array dimension is guaranteed to be unstrided, i.e. has consecutive elements in memory.

In addition to the member functions described here, `MultiArrayView` and its subclasses support arithmetic and algebraic functions via the module vigra::multi_math.

If you want to apply an algorithm requiring an image to a `MultiArrayView` of appropriate (2-dimensional) shape, you can create a vigra::BasicImageView that acts as a wrapper with the necessary interface – see Create BasicImageView from MultiArrayViews.

The template parameter are as follows

N: the array dimension
T: the type of the array elements
C: a tag determining if the array's inner dimension is strided
(the tag can be used to specialize algorithms for different memory
layouts, see \ref MultiArrayTags for details). Users normally need
not care about this parameter.
vigra::RGBValue
Class for a single RGB value.
Definition rgbvalue.hxx:128

#include <vigra/multi_array.hxx>
Namespace: vigra

Examples
  subimage.cxx.

## Member Typedef Documentation

## ◆ value_type

template<unsigned int N, class T , class StrideTag >

typedef T value_type

the array's value type

## ◆ reference

template<unsigned int N, class T , class StrideTag >

typedef value_type& reference

reference type (result of operator[])

## ◆ const_reference

template<unsigned int N, class T , class StrideTag >

typedef const value_type& const_reference

const reference type (result of operator[] const)

## ◆ pointer

template<unsigned int N, class T , class StrideTag >

typedef value_type* pointer

pointer type

## ◆ const_pointer

template<unsigned int N, class T , class StrideTag >

typedef const value_type* const_pointer

const pointer type

## ◆ difference_type

template<unsigned int N, class T , class StrideTag >

typedef MultiArrayShape<actual_dimension>::type difference_type

difference type (used for multi-dimensional offsets and indices)

## ◆ key_type

template<unsigned int N, class T , class StrideTag >

typedef difference_type key_type

key type (argument of index operator array[i] – same as difference_type)

## ◆ size_type

template<unsigned int N, class T , class StrideTag >

typedef difference_type size_type

size type

## ◆ difference_type_1

template<unsigned int N, class T , class StrideTag >

typedef MultiArrayIndex difference_type_1

difference and index type for a single dimension

## ◆ iterator

template<unsigned int N, class T , class StrideTag >

typedef StridedScanOrderIterator<actual_dimension, T, T &, T *> iterator

scan-order iterator (StridedScanOrderIterator) type

## ◆ const_iterator

template<unsigned int N, class T , class StrideTag >

typedef StridedScanOrderIterator<actual_dimension, T, T const &, T const *> const_iterator

const scan-order iterator (StridedScanOrderIterator) type

## ◆ traverser

template<unsigned int N, class T , class StrideTag >

typedef vigra::detail::MultiIteratorChooser<StrideTag>::template Traverser<actual_dimension,T,T&,T*>::type traverser

traverser (MultiIterator) type

## ◆ const_traverser

template<unsigned int N, class T , class StrideTag >

typedef vigra::detail::MultiIteratorChooser<StrideTag>::template Traverser<actual_dimension,T,Tconst&,Tconst*>::type const_traverser

const traverser (MultiIterator) type

## ◆ view_type

template<unsigned int N, class T , class StrideTag >

typedef MultiArrayView<N, T, StrideTag> view_type

the view type associated with this array.

## ◆ matrix_type

template<unsigned int N, class T , class StrideTag >

typedef MultiArray<N, T> matrix_type

the matrix type associated with this array.

## Member Enumeration Documentation

## ◆ ActualDimension

template<unsigned int N, class T , class StrideTag >

enum ActualDimension

the array's actual dimensionality. This ensures that MultiArrayView can also be used for scalars (that is, when `N == 0`). Calculated as:

actual_dimension = (N==0) ? 1 : N

## Constructor & Destructor Documentation

## ◆ MultiArrayView() [1/5]

template<unsigned int N, class T , class StrideTag >

MultiArrayView | ( |  | ) |

default constructor: create an invalid view, i.e. hasData() returns false and size() is zero.

## ◆ MultiArrayView() [2/5]

template<unsigned int N, class T , class StrideTag >
template<class Stride >

MultiArrayView | ( | const MultiArrayView< N, T, Stride > & | other | ) |

construct from another array view. Throws a precondition error if this array has UnstridedArrayTag, but the innermost dimension of other is strided.

## ◆ MultiArrayView() [3/5]

template<unsigned int N, class T , class StrideTag >

MultiArrayView | ( | const difference_type & | shape,
|  | const_pointer | ptr
| ) |  |

construct from shape and pointer

## ◆ MultiArrayView() [4/5]

template<unsigned int N, class T , class StrideTag >

MultiArrayView | ( | const difference_type & | shape,
|  | const difference_type & | stride,
|  | const_pointer | ptr
| ) |  |

Construct from shape, strides (offset of a sample to the next) for every dimension, and pointer. (Note that strides are not given in bytes, but in offset steps of the respective pointer type.)

## ◆ MultiArrayView() [5/5]

template<unsigned int N, class T , class StrideTag >
template<class ALLOC >

MultiArrayView | ( | BasicImage< T, ALLOC > const & | image | ) |

Construct from an old-style BasicImage.

## Member Function Documentation

## ◆ operator MultiArrayView< N, T, StridedArrayTag >()

template<unsigned int N, class T , class StrideTag >

operator MultiArrayView< N, T, StridedArrayTag > | ( |  | ) | const

Conversion to a strided view.

## ◆ reset()

template<unsigned int N, class T , class StrideTag >

void reset | ( |  | ) |

Reset this `MultiArrayView` to an invalid state (as after default construction). Can e.g. be used prior to assignment to make a view object point to new data.

## ◆ operator=() [1/4]

template<unsigned int N, class T , class StrideTag >

MultiArrayView & operator= | ( | MultiArrayView< N, T, StrideTag > const & | rhs | ) |

Assignment. There are 3 cases:

- When this `MultiArrayView` does not point to valid data (e.g. after default construction), it becomes a new view of rhs.
- Otherwise, when the shapes of the two arrays match, the contents (i.e. the elements) of rhs are copied.
- Otherwise, a `PreconditionViolation` exception is thrown.

## ◆ operator=() [2/4]

template<unsigned int N, class T , class StrideTag >
template<class U , class C1 >

MultiArrayView & operator= | ( | MultiArrayView< N, U, C1 > const & | rhs | ) |

Assignment of a differently typed MultiArrayView. It copies the elements ofrhs or fails with `PreconditionViolation` exception when the shapes do not match.

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

template<unsigned int N, class T , class StrideTag >

MultiArrayView & operator= | ( | value_type const & | v | ) |

Assignment of a scalar. Equivalent to MultiArrayView::init(v).

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

template<unsigned int N, class T , class StrideTag >
template<class U , class C1 >

MultiArrayView & operator+= | ( | MultiArrayView< N, U, C1 > const & | rhs | ) |

Add-assignment of a compatible MultiArrayView. Fails with `PreconditionViolation` exception when the shapes do not match.

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

template<unsigned int N, class T , class StrideTag >
template<class U , class C1 >

MultiArrayView & operator-= | ( | MultiArrayView< N, U, C1 > const & | rhs | ) |

Subtract-assignment of a compatible MultiArrayView. Fails with `PreconditionViolation` exception when the shapes do not match.

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

template<unsigned int N, class T , class StrideTag >
template<class U , class C1 >

MultiArrayView & operator*= | ( | MultiArrayView< N, U, C1 > const & | rhs | ) |

Multiply-assignment of a compatible MultiArrayView. Fails with `PreconditionViolation` exception when the shapes do not match.

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

template<unsigned int N, class T , class StrideTag >
template<class U , class C1 >

MultiArrayView & operator/= | ( | MultiArrayView< N, U, C1 > const & | rhs | ) |

Divide-assignment of a compatible MultiArrayView. Fails with `PreconditionViolation` exception when the shapes do not match.

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

template<unsigned int N, class T , class StrideTag >

MultiArrayView & operator+= | ( | T const & | rhs | ) |

Add-assignment of a scalar.

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

template<unsigned int N, class T , class StrideTag >

MultiArrayView & operator-= | ( | T const & | rhs | ) |

Subtract-assignment of a scalar.

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

template<unsigned int N, class T , class StrideTag >

MultiArrayView & operator*= | ( | T const & | rhs | ) |

Multiply-assignment of a scalar.

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

template<unsigned int N, class T , class StrideTag >

MultiArrayView & operator/= | ( | T const & | rhs | ) |

Divide-assignment of a scalar.

## ◆ operator=() [4/4]

template<unsigned int N, class T , class StrideTag >
template<class Expression >

MultiArrayView & operator= | ( | multi_math::MultiMathOperand< Expression > const & | rhs | ) |

Assignment of an array expression. Fails with `PreconditionViolation` exception when the shapes do not match.

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

template<unsigned int N, class T , class StrideTag >
template<class Expression >

MultiArrayView & operator+= | ( | multi_math::MultiMathOperand< Expression > const & | rhs | ) |

Add-assignment of an array expression. Fails with `PreconditionViolation` exception when the shapes do not match.

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

template<unsigned int N, class T , class StrideTag >
template<class Expression >

MultiArrayView & operator-= | ( | multi_math::MultiMathOperand< Expression > const & | rhs | ) |

Subtract-assignment of an array expression. Fails with `PreconditionViolation` exception when the shapes do not match.

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

template<unsigned int N, class T , class StrideTag >
template<class Expression >

MultiArrayView & operator*= | ( | multi_math::MultiMathOperand< Expression > const & | rhs | ) |

Multiply-assignment of an array expression. Fails with `PreconditionViolation` exception when the shapes do not match.

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

template<unsigned int N, class T , class StrideTag >
template<class Expression >

MultiArrayView & operator/= | ( | multi_math::MultiMathOperand< Expression > const & | rhs | ) |

Divide-assignment of an array expression. Fails with `PreconditionViolation` exception when the shapes do not match.

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

template<unsigned int N, class T , class StrideTag >

reference operator[] | ( | const difference_type & | d | ) |

array access.

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

template<unsigned int N, class T , class StrideTag >

const_reference operator[] | ( | const difference_type & | d | ) | const

array access.

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

template<unsigned int N, class T , class StrideTag >
template<int M>

MultiArrayView< N-M, T, StridedArrayTag > operator[] | ( | const TinyVector< MultiArrayIndex, M > & | d | ) | const

equivalent to bindInner(), when M < N.

## ◆ operator[]() [4/5]

template<unsigned int N, class T , class StrideTag >

reference operator[] | ( | difference_type_1 | d | ) |

Array access in scan-order sense. Mostly useful to support standard indexing for 1-dimensional multi-arrays, but works for any N. Use scanOrderIndexToCoordinate() and coordinateToScanOrderIndex() for conversion between indices and coordinates.

Note: This function should not be used in the inner loop, because the conversion of the scan order index into a memory address is expensive (it must take into account that memory may not be consecutive for subarrays and/or strided arrays). Always prefer operator() if possible.

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

template<unsigned int N, class T , class StrideTag >

const_reference operator[] | ( | difference_type_1 | d | ) | const

Array access in scan-order sense. Mostly useful to support standard indexing for 1-dimensional multi-arrays, but works for any N. Use scanOrderIndexToCoordinate() and coordinateToScanOrderIndex() for conversion between indices and coordinates.

Note: This function should not be used in the inner loop, because the conversion of the scan order index into a memory address is expensive (it must take into account that memory may not be consecutive for subarrays and/or strided arrays). Always prefer operator() if possible.

## ◆ scanOrderIndexToCoordinate()

template<unsigned int N, class T , class StrideTag >

difference_type scanOrderIndexToCoordinate | ( | difference_type_1 | d | ) | const

convert scan-order index to coordinate.

## ◆ coordinateToScanOrderIndex()

template<unsigned int N, class T , class StrideTag >

difference_type_1 coordinateToScanOrderIndex | ( | const difference_type & | d | ) | const

convert coordinate to scan-order index.

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

template<unsigned int N, class T , class StrideTag >

reference operator() | ( | difference_type_1 | x | ) |

1D array access. Use only if N == 1.

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

template<unsigned int N, class T , class StrideTag >

reference operator() | ( | difference_type_1 | x,
|  | difference_type_1 | y
| ) |  |

2D array access. Use only if N == 2.

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

template<unsigned int N, class T , class StrideTag >

reference operator() | ( | difference_type_1 | x,
|  | difference_type_1 | y,
|  | difference_type_1 | z
| ) |  |

3D array access. Use only if N == 3.

## ◆ operator()() [4/10]

template<unsigned int N, class T , class StrideTag >

reference operator() | ( | difference_type_1 | x,
|  | difference_type_1 | y,
|  | difference_type_1 | z,
|  | difference_type_1 | u
| ) |  |

4D array access. Use only if N == 4.

## ◆ operator()() [5/10]

template<unsigned int N, class T , class StrideTag >

reference operator() | ( | difference_type_1 | x,
|  | difference_type_1 | y,
|  | difference_type_1 | z,
|  | difference_type_1 | u,
|  | difference_type_1 | v
| ) |  |

5D array access. Use only if N == 5.

## ◆ operator()() [6/10]

template<unsigned int N, class T , class StrideTag >

const_reference operator() | ( | difference_type_1 | x | ) | const

1D const array access. Use only if N == 1.

## ◆ operator()() [7/10]

template<unsigned int N, class T , class StrideTag >

const_reference operator() | ( | difference_type_1 | x,
|  | difference_type_1 | y
| ) |  | const

2D const array access. Use only if N == 2.

## ◆ operator()() [8/10]

template<unsigned int N, class T , class StrideTag >

const_reference operator() | ( | difference_type_1 | x,
|  | difference_type_1 | y,
|  | difference_type_1 | z
| ) |  | const

3D const array access. Use only if N == 3.

## ◆ operator()() [9/10]

template<unsigned int N, class T , class StrideTag >

const_reference operator() | ( | difference_type_1 | x,
|  | difference_type_1 | y,
|  | difference_type_1 | z,
|  | difference_type_1 | u
| ) |  | const

4D const array access. Use only if N == 4.

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

template<unsigned int N, class T , class StrideTag >

const_reference operator() | ( | difference_type_1 | x,
|  | difference_type_1 | y,
|  | difference_type_1 | z,
|  | difference_type_1 | u,
|  | difference_type_1 | v
| ) |  | const

5D const array access. Use only if N == 5.

## ◆ init()

template<unsigned int N, class T , class StrideTag >
template<class U >

MultiArrayView & init | ( | const U & | init | ) |

Init with a constant.

## ◆ copy() [1/2]

template<unsigned int N, class T , class StrideTag >

void copy | ( | const MultiArrayView< N, T, StrideTag > & | rhs | ) |

Copy the data of the right-hand array (array shapes must match).

## ◆ copy() [2/2]

template<unsigned int N, class T , class StrideTag >
template<class U , class CN >

void copy | ( | const MultiArrayView< N, U, CN > & | rhs | ) |

Copy the data of the right-hand array (array shapes must match).

## ◆ swap()

template<unsigned int N, class T , class StrideTag >

void swap | ( | MultiArrayView< N, T, StrideTag > & | other | ) |

Swap the pointers, shaes and strides between two array views.

This function must be used with care. Never swap a MultiArray (which owns data) with a MultiArrayView:

MultiArray<2, int> a(3,2), b(3,2);
MultiArrayView<2, int> va(a);
va.swap(b); // danger!

Now, `a` and `b` refer to the same memory. This may lead to a crash in their destructor, and in any case leaks `b`'s original memory. Only use swap() on copied MultiArrayViews:

MultiArray<2, int> a(3,2), b(3,2);
MultiArrayView<2, int> va(a), vb(b);
va.swap(vb); // OK

## ◆ swapData() [1/2]

template<unsigned int N, class T , class StrideTag >

void swapData | ( | MultiArrayView< N, T, StrideTag > | rhs | ) |

swap the data between two MultiArrayView objects.

The shapes of the two array must match.

## ◆ swapData() [2/2]

template<unsigned int N, class T , class StrideTag >
template<class T2 , class C2 >

void swapData | ( | MultiArrayView< N, T2, C2 > | rhs | ) |

swap the data between two MultiArrayView objects.

The shapes of the two array must match.

## ◆ isUnstrided()

template<unsigned int N, class T , class StrideTag >

bool isUnstrided | ( | unsigned int | dimension = `N-1` | ) | const

check whether the array is unstrided (i.e. has consecutive memory) up to the given dimension.

dimension can range from 0 ... N-1. If a certain dimension is unstrided, all lower dimensions are also unstrided.

## ◆ bindOuter() [1/2]

template<unsigned int N, class T , class StrideTag >
template<int M, class Index >

MultiArrayView< N-M, T, StrideTag > bindOuter | ( | const TinyVector< Index, M > & | d | ) | const

bind the M outmost dimensions to certain indices. this reduces the dimensionality of the image to max { 1, N-M }.

Usage:

// create a 3D array of size 40x30x20
typedef MultiArray<3, double>::difference_type Shape;
MultiArray<3, double> array3(Shape(40, 30, 20));
// get a 1D array by fixing index 1 to 12, and index 2 to 10
MultiArrayView <1, double> array1 = array3.bindOuter(TinyVector<MultiArrayIndex, 2>(12, 10));

## ◆ bindInner() [1/2]

template<unsigned int N, class T , class StrideTag >
template<int M, class Index >

MultiArrayView< N-M, T, StridedArrayTag > bindInner | ( | const TinyVector< Index, M > & | d | ) | const

bind the M innermost dimensions to certain indices. this reduces the dimensionality of the image to max { 1, N-M }.

Usage:

// create a 3D array of size 40x30x20
typedef MultiArray<3, double>::difference_type Shape;
MultiArray<3, double> array3(Shape(40, 30, 20));
// get a 1D array by fixing index 0 to 12, and index 1 to 10
MultiArrayView <1, double, StridedArrayTag> array1 = array3.bindInner(TinyVector<MultiArrayIndex, 2>(12, 10));

## ◆ bind()

template<unsigned int N, class T , class StrideTag >
template<unsigned int M>

MultiArrayView< N-1, T, typename vigra::detail::MaybeStrided< StrideTag, M >::type > bind | ( | difference_type_1 | d | ) | const

bind dimension M to index d. this reduces the dimensionality of the image to max { 1, N-1 }.

Usage:

// create a 3D array of size 40x30x20
typedef MultiArray<3, double>::difference_type Shape;
MultiArray<3, double> array3(Shape(40, 30, 20));
// get a 2D array by fixing index 1 to 12
MultiArrayView <2, double> array2 = array3.bind<1>(12);
// get a 2D array by fixing index 0 to 23
MultiArrayView <2, double, StridedArrayTag> array2a = array3.bind<0>(23);

## ◆ bindOuter() [2/2]

template<unsigned int N, class T , class StrideTag >

MultiArrayView< N - 1, T, StrideTag > bindOuter | ( | difference_type_1 | d | ) | const

bind the outmost dimension to a certain index. this reduces the dimensionality of the image to max { 1, N-1 }.

Usage:

// create a 3D array of size 40x30x20
typedef MultiArray<3, double>::difference_type Shape;
MultiArray<3, double> array3(Shape(40, 30, 20));
// get a 2D array by fixing the outermost index (i.e. index 2) to 12
MultiArrayView <2, double> array2 = array3.bindOuter(12);

## ◆ bindInner() [2/2]

template<unsigned int N, class T , class StrideTag >

MultiArrayView< N - 1, T, StridedArrayTag > bindInner | ( | difference_type_1 | d | ) | const

bind the innermost dimension to a certain index. this reduces the dimensionality of the image to max { 1, N-1 }.

Usage:

// create a 3D array of size 40x30x20
typedef MultiArray<3, double>::difference_type Shape;
MultiArray<3, double> array3(Shape(40, 30, 20));
// get a 2D array by fixing the innermost index (i.e. index 0) to 23
MultiArrayView <2, double, StridedArrayTag> array2 = array3.bindInner(23);

## ◆ bindAt()

template<unsigned int N, class T , class StrideTag >

MultiArrayView< N - 1, T, StridedArrayTag > bindAt | ( | difference_type_1 | m,
|  | difference_type_1 | d
| ) |  | const

bind dimension m to index d. this reduces the dimensionality of the image to max { 1, N-1 }.

Usage:

// create a 3D array of size 40x30x20
typedef MultiArray<3, double>::difference_type Shape;
MultiArray<3, double> array3(Shape(40, 30, 20));
// get a 2D array by fixing index 2 to 15
MultiArrayView <2, double, StridedArrayTag> array2 = array3.bindAt(2, 15);

## ◆ bindElementChannel()

template<unsigned int N, class T , class StrideTag >

MultiArrayView< N, typename ExpandElementResult< T >::type, StridedArrayTag > bindElementChannel | ( | difference_type_1 | i | ) | const

Create a view to channel 'i' of a vector-like value type. Possible value types (of the original array) are: TinyVector, RGBValue, FFTWComplex, and `std::complex`. The list can be extended to any type whose memory layout is equivalent to a fixed-size C array, by specializing `ExpandElementResult`.

Usage:

MultiArray<2, RGBValue<float> > rgb_image(Shape2(w, h));
MultiArrayView<2, float, StridedArrayTag> red = rgb_image.bindElementChannel(0);
MultiArrayView<2, float, StridedArrayTag> green = rgb_image.bindElementChannel(1);
MultiArrayView<2, float, StridedArrayTag> blue = rgb_image.bindElementChannel(2);

## ◆ expandElements()

template<unsigned int N, class T , class StrideTag >

MultiArrayView< N+1, typename ExpandElementResult< T >::type, StridedArrayTag > expandElements | ( | difference_type_1 | d | ) | const

Create a view where a vector-like element type is expanded into a new array dimension. The new dimension is inserted at index position 'd', which must be between 0 and N inclusive.

Possible value types of the original array are: TinyVector, RGBValue, FFTWComplex, `std::complex`, and the built-in number types (in this case, `expandElements` is equivalent to `insertSingletonDimension`). The list of supported types can be extended to any type whose memory layout is equivalent to a fixed-size C array, by specializing `ExpandElementResult`.

Usage:

MultiArray<2, RGBValue<float> > rgb_image(Shape2(w, h));
MultiArrayView<3, float, StridedArrayTag> multiband_image = rgb_image.expandElements(2);

## ◆ insertSingletonDimension()

template<unsigned int N, class T , class StrideTag >

MultiArrayView< N+1, T, StrideTag > insertSingletonDimension | ( | difference_type_1 | i | ) | const

Add a singleton dimension (dimension of length 1).

Singleton dimensions don't change the size of the data, but introduce a new index that can only take the value 0. This is mainly useful for the 'reduce mode' of transformMultiArray() and combineTwoMultiArrays(), because these functions require the source and destination arrays to have the same number of dimensions.

The range of i must be `0 <= i <= N`. The new dimension will become the i'th index, and the old indices from i upwards will shift one place to the right.

Usage:

Suppose we want have a 2D array and want to create a 1D array that contains the row average of the first array.

typedef MultiArrayShape<2>::type Shape2;
MultiArray<2, double> original(Shape2(40, 30));
typedef MultiArrayShape<1>::type Shape1;
MultiArray<1, double> rowAverages(Shape1(30));
// temporarily add a singleton dimension to the destination array
transformMultiArray(srcMultiArrayRange(original),
destMultiArrayRange(rowAverages.insertSingletonDimension(0)),
FindAverage<double>());
vigra::TinyVector
Class for fixed size vectors.
Definition tinyvector.hxx:1008
vigra::transformMultiArray
void transformMultiArray(...)
Transform a multi-dimensional array with a unary function or functor.

## ◆ multiband()

template<unsigned int N, class T , class StrideTag >

MultiArrayView< N, Multiband< value_type >, StrideTag > multiband | ( |  | ) | const

create a multiband view for this array.

The type `MultiArrayView<N, Multiband<T> >` tells VIGRA algorithms which recognize the `Multiband` modifier to interpret the outermost (last) dimension as a channel dimension. In effect, these algorithms will treat the data as a set of (N-1)-dimensional arrays instead of a single N-dimensional array.

## ◆ diagonal()

template<unsigned int N, class T , class StrideTag >

MultiArrayView< 1, T, StridedArrayTag > diagonal | ( |  | ) | const

Create a view to the diagonal elements of the array.

This produces a 1D array view whose size equals the size of the shortest dimension of the original array.

Usage:

// create a 3D array of size 40x30x20
typedef MultiArray<3, double>::difference_type Shape;
MultiArray<3, double> array3(Shape(40, 30, 20));
// get a view to the diagonal elements
MultiArrayView <1, double, StridedArrayTag> diagonal = array3.diagonal();
assert(diagonal.shape(0) == 20);
vigra::MultiArrayView::diagonal
MultiArrayView< 1, T, StridedArrayTag > diagonal() const
Definition multi_array.hxx:1504
vigra::MultiArrayView::shape
const difference_type & shape() const
Definition multi_array.hxx:1648

## ◆ subarray()

template<unsigned int N, class T , class StrideTag >

MultiArrayView subarray | ( | difference_type | p,
|  | difference_type | q
| ) |  | const

create a rectangular subarray that spans between the points p and q, where p is in the subarray, q not. If an element of p or q is negative, it is subtracted from the correspongng shape.

Usage:

// create a 3D array of size 40x30x20
typedef MultiArray<3, double>::difference_type Shape;
MultiArray<3, double> array3(Shape(40, 30, 20));
// get a subarray set is smaller by one element at all sides
MultiArrayView <3, double> subarray = array3.subarray(Shape(1,1,1), Shape(39, 29, 19));
// specifying the end point with a vector of '-1' is equivalent
MultiArrayView <3, double> subarray2 = array3.subarray(Shape(1,1,1), Shape(-1, -1, -1));
vigra::MultiArrayView::subarray
MultiArrayView subarray(difference_type p, difference_type q) const
Definition multi_array.hxx:1528
vigra::TinyVectorBase::subarray
TinyVectorView< VALUETYPE, TO-FROM > subarray() const
Definition tinyvector.hxx:887

## ◆ stridearray()

template<unsigned int N, class T , class StrideTag >

MultiArrayView< N, T, StridedArrayTag > stridearray | ( | const difference_type & | s | ) | const

apply an additional striding to the image, thereby reducing the shape of the array. for example, multiplying the stride of dimension one by three turns an appropriately laid out (interleaved) rgb image into a single band image.

## ◆ transpose() [1/2]

template<unsigned int N, class T , class StrideTag >

MultiArrayView< N, T, StridedArrayTag > transpose | ( |  | ) | const

Transpose an array. If N==2, this implements the usual matrix transposition. For N > 2, it reverses the order of the indices.

Usage:

typedef MultiArray<2, double>::difference_type Shape;
MultiArray<2, double> array(10, 20);
MultiArrayView<2, double, StridedArrayTag> transposed = array.transpose();
for(int i=0; i<array.shape(0), ++i)
for(int j=0; j<array.shape(1); ++j)
assert(array(i, j) == transposed(j, i));

## ◆ transpose() [2/2]

template<unsigned int N, class T , class StrideTag >

MultiArrayView< N, T, StridedArrayTag > transpose | ( | const difference_type & | permutation | ) | const

Permute the dimensions of the array. The function exchanges the orer of the array's axes without copying the data. Argumentpermutation specifies the desired order such that `permutation[k] = j` means that axis `j` in the original array becomes axis `k` in the transposed array.

Usage:

typedef MultiArray<2, double>::difference_type Shape;
MultiArray<2, double> array(10, 20);
MultiArrayView<2, double, StridedArrayTag> transposed = array.transpose(Shape(1,0));
for(int i=0; i<array.shape(0), ++i)
for(int j=0; j<array.shape(1); ++j)
assert(array(i, j) == transposed(j, i));

## ◆ permuteStridesAscending()

template<unsigned int N, class T , class StrideTag >

MultiArrayView< N, T, StridedArrayTag > permuteStridesAscending | ( |  | ) | const

Permute the dimensions of the array so that the strides are in ascending order. Determines the appropriate permutation and then calls permuteDimensions().

## ◆ permuteStridesDescending()

template<unsigned int N, class T , class StrideTag >

MultiArrayView< N, T, StridedArrayTag > permuteStridesDescending | ( |  | ) | const

Permute the dimensions of the array so that the strides are in descending order. Determines the appropriate permutation and then calls permuteDimensions().

## ◆ strideOrdering() [1/2]

template<unsigned int N, class T , class StrideTag >

difference_type strideOrdering | ( |  | ) | const

Compute the ordering of the strides in this array. The result is describes the current permutation of the axes relative to the standard ascending stride order.

## ◆ strideOrdering() [2/2]

template<unsigned int N, class T , class StrideTag >

MultiArrayView< N, T, StrideTag >::difference_type strideOrdering | ( | difference_type | strides | ) |

static

Compute the ordering of the given strides. The result is describes the current permutation of the axes relative to the standard ascending stride order.

## ◆ elementCount()

template<unsigned int N, class T , class StrideTag >

difference_type_1 elementCount | ( |  | ) | const

number of the elements in the array.

## ◆ size() [1/2]

template<unsigned int N, class T , class StrideTag >

difference_type_1 size | ( |  | ) | const

number of the elements in the array. Same as `elementCount()`. Mostly useful to support the std::vector interface.

## ◆ shape() [1/2]

template<unsigned int N, class T , class StrideTag >

const difference_type & shape | ( |  | ) | const

return the array's shape.

Examples
  transpose.cxx.

## ◆ size() [2/2]

template<unsigned int N, class T , class StrideTag >

difference_type_1 size | ( | difference_type_1 | n | ) | const

return the array's size at a certain dimension.

## ◆ shape() [2/2]

template<unsigned int N, class T , class StrideTag >

difference_type_1 shape | ( | difference_type_1 | n | ) | const

return the array's shape at a certain dimension (same as `size(n)`).

## ◆ width()

template<unsigned int N, class T , class StrideTag >

difference_type_1 width | ( |  | ) | const

return the array's width (same as `shape(0)`).

## ◆ height()

template<unsigned int N, class T , class StrideTag >

difference_type_1 height | ( |  | ) | const

return the array's height (same as `shape(1)`).

## ◆ stride() [1/2]

template<unsigned int N, class T , class StrideTag >

const difference_type & stride | ( |  | ) | const

return the array's stride for every dimension.

## ◆ stride() [2/2]

template<unsigned int N, class T , class StrideTag >

difference_type_1 stride | ( | int | n | ) | const

return the array's stride at a certain dimension.

## ◆ operator==()

template<unsigned int N, class T , class StrideTag >
template<class U , class C1 >

bool operator== | ( | MultiArrayView< N, U, C1 > const & | rhs | ) | const

check whether two arrays are elementwise equal.

## ◆ operator!=()

template<unsigned int N, class T , class StrideTag >
template<class U , class C1 >

bool operator!= | ( | MultiArrayView< N, U, C1 > const & | rhs | ) | const

check whether two arrays are not elementwise equal. Also true when the two arrays have different shapes.

## ◆ isInside()

template<unsigned int N, class T , class StrideTag >

bool isInside | ( | difference_type const & | p | ) | const

check whether the given point is in the array range.

## ◆ isOutside()

template<unsigned int N, class T , class StrideTag >

bool isOutside | ( | difference_type const & | p | ) | const

check whether the given point is not in the array range.

## ◆ all()

template<unsigned int N, class T , class StrideTag >

bool all | ( |  | ) | const

Check if the array contains only non-zero elements (or if all elements are 'true' if the value type is 'bool').

## ◆ any()

template<unsigned int N, class T , class StrideTag >

bool any | ( |  | ) | const

Check if the array contains a non-zero element (or an element that is 'true' if the value type is 'bool').

## ◆ minmax()

template<unsigned int N, class T , class StrideTag >

void minmax | ( | T * | minimum,
|  | T * | maximum
| ) |  | const

Find the minimum and maximum element in this array. See Feature Accumulators for a general feature extraction framework.

## ◆ meanVariance()

template<unsigned int N, class T , class StrideTag >
template<class U >

void meanVariance | ( | U * | mean,
|  | U * | variance
| ) |  | const

Compute the mean and variance of the values in this array. See Feature Accumulators for a general feature extraction framework.

## ◆ sum() [1/2]

template<unsigned int N, class T , class StrideTag >
template<class U >

U sum | ( |  | ) | const

Compute the sum of the array elements.

You must provide the type of the result by an explicit template parameter:

MultiArray<2, UInt8> A(width, height);
double sum = A.sum<double>();
vigra::MultiArrayView::width
difference_type_1 width() const
Definition multi_array.hxx:1670
vigra::MultiArrayView::height
difference_type_1 height() const
Definition multi_array.hxx:1677
vigra::MultiArrayView::sum
U sum() const
Definition multi_array.hxx:1803

## ◆ sum() [2/2]

template<unsigned int N, class T , class StrideTag >
template<class U , class S >

void sum | ( | MultiArrayView< N, U, S > | sums | ) | const

Compute the sum of the array elements over selected axes.

- sums must have the same shape as this array, except for the axes along which the sum is to be accumulated. These axes must be singletons. Note that you must include `multi_pointoperators.hxx` for this function to work.

Usage:

#include <vigra/multi_array.hxx>
#include <vigra/multi_pointoperators.hxx>
MultiArray<2, double> A(Shape2(rows, cols));
... // fill A
// make the first axis a singleton to sum over the first index
MultiArray<2, double> rowSums(Shape2(1, cols));
A.sum(rowSums);
// this is equivalent to
transformMultiArray(srcMultiArrayRange(A),
destMultiArrayRange(rowSums),
FindSum<double>());

## ◆ product()

template<unsigned int N, class T , class StrideTag >
template<class U >

U product | ( |  | ) | const

Compute the product of the array elements.

You must provide the type of the result by an explicit template parameter:

MultiArray<2, UInt8> A(width, height);
double prod = A.product<double>();
vigra::prod
NumericTraits< V >::Promote prod(TinyVectorBase< V, SIZE, D1, D2 > const &l)
product of the vector's elements
Definition tinyvector.hxx:2097

## ◆ squaredNorm()

template<unsigned int N, class T , class StrideTag >

NormTraits< MultiArrayView >::SquaredNormType squaredNorm | ( |  | ) | const

Compute the squared Euclidean norm of the array (sum of squares of the array elements).

## ◆ norm()

template<unsigned int N, class T , class StrideTag >

NormTraits< MultiArrayView< N, T, StrideTag > >::NormType norm | ( | int | type = `2`,
|  | bool | useSquaredNorm = `true`
| ) |  | const

Compute various norms of the array. The norm is determined by parameter type:

- type == 0: maximum norm (L-infinity): maximum of absolute values of the array elements
- type == 1: Manhattan norm (L1): sum of absolute values of the array elements
- type == 2: Euclidean norm (L2): square root of `squaredNorm()` when useSquaredNorm is `true`,
  or direct algorithm that avoids underflow/overflow otherwise.

Parameter useSquaredNorm has no effect when type != 2. Defaults: compute L2 norm as square root of `squaredNorm()`.

## ◆ data()

template<unsigned int N, class T , class StrideTag >

pointer data | ( |  | ) | const

return the pointer to the image data

## ◆ hasData()

template<unsigned int N, class T , class StrideTag >

bool hasData | ( |  | ) | const

returns true iff this view refers to valid data, i.e. data() is not a NULL pointer. (this is false after default construction.)

## ◆ begin() [1/2]

template<unsigned int N, class T , class StrideTag >

iterator begin | ( |  | ) |

returns a scan-order iterator pointing to the first array element.

## ◆ begin() [2/2]

template<unsigned int N, class T , class StrideTag >

const_iterator begin | ( |  | ) | const

returns a const scan-order iterator pointing to the first array element.

## ◆ end() [1/2]

template<unsigned int N, class T , class StrideTag >

iterator end | ( |  | ) |

returns a scan-order iterator pointing beyond the last array element.

## ◆ end() [2/2]

template<unsigned int N, class T , class StrideTag >

const_iterator end | ( |  | ) | const

returns a const scan-order iterator pointing beyond the last array element.

## ◆ traverser_begin() [1/2]

template<unsigned int N, class T , class StrideTag >

traverser traverser_begin | ( |  | ) |

returns the N-dimensional MultiIterator pointing to the first element in every dimension.

## ◆ traverser_begin() [2/2]

template<unsigned int N, class T , class StrideTag >

const_traverser traverser_begin | ( |  | ) | const

returns the N-dimensional MultiIterator pointing to the const first element in every dimension.

## ◆ traverser_end() [1/2]

template<unsigned int N, class T , class StrideTag >

traverser traverser_end | ( |  | ) |

returns the N-dimensional MultiIterator pointing beyond the last element in dimension N, and to the first element in every other dimension.

## ◆ traverser_end() [2/2]

template<unsigned int N, class T , class StrideTag >

const_traverser traverser_end | ( |  | ) | const

returns the N-dimensional const MultiIterator pointing beyond the last element in dimension N, and to the first element in every other dimension.

## Member Data Documentation

## ◆ m_shape

template<unsigned int N, class T , class StrideTag >

difference_type m_shape

protected

the shape of the image pointed to is stored here.

## ◆ m_stride

template<unsigned int N, class T , class StrideTag >

difference_type m_stride

protected

the strides (offset of a sample to the next) for every dimension are stored here.

## ◆ m_ptr

template<unsigned int N, class T , class StrideTag >

pointer m_ptr

protected

pointer to the image.

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

- vigra/multi_array.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.11.1