VIGRA - VIGRA: MultiArrayView Class Template Reference

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

| MultiArrayView |

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

`#include <vigra/multi_array.hxx>`

List of all members.

## Public Types
enum | ActualDimension
typedef const value_type * | const_pointer
typedef const value_type & | const_reference
typedef vigra::detail::MultiIteratorChooser < C >::template Traverser < actual_dimension, T, T const &, T const * >::type | const_traverser
typedef MultiArrayShape < actual_dimension >::type | difference_type
typedef MultiArrayIndex | difference_type_1
typedef MultiArray< N, T > | matrix_type
typedef value_type * | pointer
typedef value_type & | reference
typedef difference_type | size_type
typedef vigra::detail::MultiIteratorChooser < C >::template Traverser < actual_dimension, T, T &, T * > ::type | traverser
typedef T | value_type
typedef MultiArrayView< N, T, C > | view_type
## Public Member Functions
template<unsigned int M>
MultiArrayView< N-1, T, typename vigra::detail::MaybeStrided< 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-1, T, StridedArrayTag > | bindInner (difference_type_1 d) const
template<unsigned int M>
MultiArrayView< N-M, T, StridedArrayTag > | bindInner (const TinyVector< MultiArrayIndex, M > &d) const
MultiArrayView< N-1, T, C > | bindOuter (difference_type_1 d) const
template<unsigned int M>
MultiArrayView< N-M, T, C > | bindOuter (const TinyVector< MultiArrayIndex, M > &d) const
difference_type_1 | coordinateToScanOrderIndex (const difference_type &d) const
template<class U, class CN>
void | copy (const MultiArrayView< N, U, CN > &rhs)
void | copy (const MultiArrayView &rhs)
pointer | data () const
difference_type_1 | elementCount () const
template<class U>
MultiArrayView & | init (const U &init)
bool | isInside (difference_type const &p) const
| MultiArrayView (const difference_type &shape, const difference_type &stride, pointer ptr)
| MultiArrayView (const difference_type &shape, pointer ptr)
| MultiArrayView ()
NormTraits< MultiArrayView > ::NormType | norm (int type=2, bool useSquaredNorm=true) const
template<class U, class C1>
bool | operator!= (MultiArrayView< N, U, C1 > const &rhs) const
const_reference | operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z, difference_type_1 u, difference_type_1 v) const
const_reference | operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z, difference_type_1 u) const
const_reference | operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z) const
const_reference | operator() (difference_type_1 x, difference_type_1 y) const
const_reference | operator() (difference_type_1 x) const
reference | operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z, difference_type_1 u, difference_type_1 v)
reference | operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z, difference_type_1 u)
reference | operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z)
reference | operator() (difference_type_1 x, difference_type_1 y)
reference | operator() (difference_type_1 x)
MultiArrayView & | operator*= (T const &rhs)
template<class U, class C1>
MultiArrayView & | operator*= (MultiArrayView< N, U, C1 > const &rhs)
MultiArrayView & | operator+= (T const &rhs)
template<class U, class C1>
MultiArrayView & | operator+= (MultiArrayView< N, U, C1 > const &rhs)
MultiArrayView & | operator-= (T const &rhs)
template<class U, class C1>
MultiArrayView & | operator-= (MultiArrayView< N, U, C1 > const &rhs)
MultiArrayView & | operator/= (T const &rhs)
template<class U, class C1>
MultiArrayView & | operator/= (MultiArrayView< N, U, C1 > const &rhs)
template<class U, class C1>
MultiArrayView & | operator= (MultiArrayView< N, U, C1 > const &rhs)
MultiArrayView & | operator= (MultiArrayView const &rhs)
template<class U, class C1>
bool | operator== (MultiArrayView< N, U, C1 > const &rhs) const
const_reference | operator[] (difference_type_1 d) const
reference | operator[] (difference_type_1 d)
const_reference | operator[] (const difference_type &d) const
reference | operator[] (const difference_type &d)
MultiArrayView< N, T, StridedArrayTag > | permuteDimensions (const difference_type &s) const
difference_type | scanOrderIndexToCoordinate (difference_type_1 d) const
difference_type_1 | shape (difference_type_1 n) const
const difference_type & | shape () const
difference_type_1 | size (difference_type_1 n) const
difference_type_1 | size () const
NormTraits< MultiArrayView > ::SquaredNormType | squaredNorm () const
difference_type_1 | stride (int n) const
const difference_type & | stride () const
MultiArrayView< N, T, StridedArrayTag > | stridearray (const difference_type &s) const
MultiArrayView | subarray (const difference_type &p, const difference_type &q) const
template<class T2, class C2>
void | swapData (MultiArrayView< N, T2, C2 > rhs)
void | swapData (MultiArrayView rhs)
MultiArrayView< 2, T, StridedArrayTag > | transpose () const
const_traverser | traverser_begin () const
traverser | traverser_begin ()
const_traverser | traverser_end () const
traverser | traverser_end ()
## Protected Attributes
pointer | m_ptr
difference_type | m_shape
difference_type | m_stride

## Detailed Description

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

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

This class implements the interface of both MultiArray and MultiArrayView. By default, MultiArrayViews are tagged as unstrided. If necessary, strided arrays are constructed automatically by calls to a variant of the bind...() function.

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 Wrap aref vigra::MultiArrayView in.

The template parameter are as follows

        N: the array dimension

        T: the type of the array elements

        C: a tag determining whether the array's inner dimension is strided
           or not. An array is unstrided if the array elements occupy consecutive
           memory location, strided if there is an offset in between (e.g.
           when a view is created that skips every other array element).
           The compiler can generate faster code for unstrided arrays.
           Possible values: UnstridedArrayTag (default), StridedArrayTag

#include <vigra/multi_array.hxx>

Namespace: vigra

## Member Typedef Documentation

typedef const value_type* const_pointer

const pointer type

Reimplemented in Matrix, MultiArray, and MultiArray< 2, T, ALLOC >.

typedef const value_type& const_reference

const reference type (result of operator[] const)

Reimplemented in Matrix, MultiArray, and MultiArray< 2, T, ALLOC >.

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

const traverser (MultiIterator) type

Reimplemented in MultiArray, and MultiArray< 2, T, ALLOC >.

typedef MultiArrayShape<actual_dimension>::type difference_type

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

Reimplemented in Matrix, MultiArray, and MultiArray< 2, T, ALLOC >.

typedef MultiArrayIndex difference_type_1

difference and index type for a single dimension

Reimplemented in Matrix, MultiArray, and MultiArray< 2, T, ALLOC >.

typedef MultiArray<N, T> matrix_type

the matrix type associated with this array.

Reimplemented in Matrix, MultiArray, and MultiArray< 2, T, ALLOC >.

typedef value_type* pointer

pointer type

Reimplemented in Matrix, MultiArray, and MultiArray< 2, T, ALLOC >.

typedef value_type& reference

reference type (result of operator[])

Reimplemented in Matrix, MultiArray, and MultiArray< 2, T, ALLOC >.

typedef difference_type size_type

size type

Reimplemented in MultiArray, and MultiArray< 2, T, ALLOC >.

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

traverser (MultiIterator) type

Reimplemented in MultiArray, and MultiArray< 2, T, ALLOC >.

typedef T value_type

the array's value type

Reimplemented in Matrix, MultiArray, and MultiArray< 2, T, ALLOC >.

typedef MultiArrayView<N, T, C> view_type

the view type associated with this array.

Reimplemented in Matrix, MultiArray, and MultiArray< 2, T, ALLOC >.

## Member Enumeration Documentation

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

default constructor: create an empty image of size 0.

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

construct from shape and pointer

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

construct from shape, strides (offset of a sample to the next) for every dimension) and pointer

## Member Function Documentation

MultiArrayView< N-1, T, typename detail::MaybeStrided< 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);

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

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

MultiArrayView< N-M, T, StridedArrayTag > bindInner | ( | const TinyVector< MultiArrayIndex, 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<int, 2>(12, 10));

MultiArrayView< N-1, T, C > 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);

MultiArrayView< N-M, T, C > bindOuter | ( | const TinyVector< MultiArrayIndex, 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<int, 2>(12, 10));

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

convert coordinate to scan-order index.

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

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

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

pointer data | ( |  | ) | const

return the pointer to the image data

difference_type_1 elementCount | ( |  | ) | const

number of the elements in the array.

Reimplemented in Matrix.

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

Init with a constant.

Reimplemented in Matrix, MultiArray, and MultiArray< 2, T, ALLOC >.

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

check whether the given point is in the array range.

NormTraits< MultiArrayView< N, T, C > >::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()`.

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.

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.

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.

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.

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

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

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

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

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.

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.

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

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

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

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

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

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

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

Multiply-assignment of a scalar.

Reimplemented in MultiArray, and MultiArray< 2, T, ALLOC >.

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

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

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

Add-assignment of a scalar.

Reimplemented in MultiArray, and MultiArray< 2, T, ALLOC >.

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

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

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

Subtract-assignment of a scalar.

Reimplemented in MultiArray, and MultiArray< 2, T, ALLOC >.

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

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

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

Divide-assignment of a scalar.

Reimplemented in MultiArray, and MultiArray< 2, T, ALLOC >.

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

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

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

Assignment of a differently typed MultiArrayView. Fails with `PreconditionViolation` exception when the shapes do not match.

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

Assignment. There are 3 cases:

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

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

check whether two arrays are elementwise equal.

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.

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.

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

array access.

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

array access.

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

permute the dimensions of the array. The function exchanges the meaning of the dimensions without copying the data. In case of a 2-dimensional array, this is simply array transposition. In higher dimensions, there are more possibilities.

Usage:

                typedef MultiArray<2, double>::difference_type Shape;
                MultiArray<2, double> array(10, 20);

                MultiArray<2, double, StridedArrayTag> transposed = array.permuteDimensions(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));

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

convert scan-order index to coordinate.

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

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

const difference_type& shape | ( |  | ) | const

return the array's shape.

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

return the array's size at a certain dimension.

difference_type_1 size | ( |  | ) | const

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

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

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

Reimplemented in Matrix.

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

return the array's stride at a certain dimension.

const difference_type& stride | ( |  | ) | const

return the array's stride for every dimension.

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 layed out (interleaved) rgb image into a single band image.

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

create a rectangular subarray that spans between the points p and q, where p is in the subarray, q not.

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

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.

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

swap the data between two MultiArrayView objects.

The shapes of the two array must match.

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

transpose a 2-dimensional array. Use only if N==2.

Usage:

                typedef MultiArray<2, double>::difference_type Shape;
                MultiArray<2, double> array(10, 20);

                MultiArray<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));

Reimplemented in Matrix.

const_traverser traverser_begin | ( |  | ) | const

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

traverser traverser_begin | ( |  | ) |

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

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.

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.

## Member Data Documentation

pointer m_ptr`[protected]`

pointer to the image.

difference_type m_shape`[protected]`

the shape of the image pointed to is stored here.

difference_type m_stride`[protected]`

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

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.6.0 (13 Aug 2008)