37 #ifndef VIGRA_MULTI_ARRAY_HXX 38 #define VIGRA_MULTI_ARRAY_HXX 42 #include "accessor.hxx" 43 #include "tinyvector.hxx" 44 #include "rgbvalue.hxx" 45 #include "basicimage.hxx" 46 #include "imageiterator.hxx" 47 #include "numerictraits.hxx" 48 #include "multi_iterator.hxx" 49 #include "multi_pointoperators.hxx" 50 #include "metaprogramming.hxx" 51 #include "mathutil.hxx" 52 #include "algorithm.hxx" 55 #ifdef VIGRA_CHECK_BOUNDS 56 #define VIGRA_ASSERT_INSIDE(diff) \ 57 vigra_precondition(this->isInside(diff), "Index out of bounds") 59 #define VIGRA_ASSERT_INSIDE(diff) 81 template <
class Str
ideTag,
unsigned int N>
84 typedef StrideTag type;
87 template <
class Str
ideTag>
88 struct MaybeStrided <StrideTag, 0>
90 typedef StridedArrayTag type;
106 struct MultiIteratorChooser;
120 struct MultiIteratorChooser <StridedArrayTag>
122 template <
unsigned int N,
class T,
class REFERENCE,
class POINTER>
125 typedef StridedMultiIterator <N, T, REFERENCE, POINTER> type;
128 template <
unsigned int N,
class T,
class REFERENCE,
class POINTER>
131 typedef StridedScanOrderIterator <N, T, REFERENCE, POINTER> type;
134 template <
class Iter,
class View>
135 static Iter constructIterator(View * v)
153 struct MultiIteratorChooser <UnstridedArrayTag>
155 template <
unsigned int N,
class T,
class REFERENCE,
class POINTER>
158 typedef MultiIterator <N, T, REFERENCE, POINTER> type;
161 template <
unsigned int N,
class T,
class REFERENCE,
class POINTER>
164 typedef POINTER type;
167 template <
class Iter,
class View>
168 static Iter constructIterator(View * v)
180 template <
class DestIterator,
class Shape,
class T>
182 initMultiArrayData(DestIterator d, Shape
const & shape, T
const & init, MetaInt<0>)
184 DestIterator dend = d + shape[0];
191 template <
class DestIterator,
class Shape,
class T,
int N>
193 initMultiArrayData(DestIterator d, Shape
const & shape, T
const & init, MetaInt<N>)
195 DestIterator dend = d + shape[N];
198 initMultiArrayData(d.begin(), shape, init, MetaInt<N-1>());
203 #define VIGRA_COPY_MULTI_ARRAY_DATA(name, op) \ 204 template <class SrcIterator, class Shape, class DestIterator> \ 206 name##MultiArrayData(SrcIterator s, Shape const & shape, DestIterator d, MetaInt<0>) \ 208 for(MultiArrayIndex i=0; i < shape[0]; ++i, ++s, ++d) \ 210 *d op detail::RequiresExplicitCast<typename DestIterator::value_type>::cast(*s); \ 214 template <class Ref, class Ptr, class Shape, class DestIterator> \ 216 name##MultiArrayData(MultiIterator<1, UInt8, Ref, Ptr> si, Shape const & shape, DestIterator d, MetaInt<0>) \ 219 for(MultiArrayIndex i=0; i < shape[0]; ++i, ++s, ++d) \ 221 *d op detail::RequiresExplicitCast<typename DestIterator::value_type>::cast(*s); \ 225 template <class SrcIterator, class Shape, class DestIterator, int N> \ 227 name##MultiArrayData(SrcIterator s, Shape const & shape, DestIterator d, MetaInt<N>) \ 229 for(MultiArrayIndex i=0; i < shape[N]; ++i, ++s, ++d) \ 231 name##MultiArrayData(s.begin(), shape, d.begin(), MetaInt<N-1>()); \ 235 template <class DestIterator, class Shape, class T> \ 237 name##ScalarMultiArrayData(DestIterator d, Shape const & shape, T const & init, MetaInt<0>) \ 239 for(MultiArrayIndex i=0; i < shape[0]; ++i, ++d) \ 241 *d op detail::RequiresExplicitCast<typename DestIterator::value_type>::cast(init); \ 245 template <class DestIterator, class Shape, class T, int N> \ 247 name##ScalarMultiArrayData(DestIterator d, Shape const & shape, T const & init, MetaInt<N>) \ 249 for(MultiArrayIndex i=0; i < shape[N]; ++i, ++d) \ 251 name##ScalarMultiArrayData(d.begin(), shape, init, MetaInt<N-1>()); \ 255 VIGRA_COPY_MULTI_ARRAY_DATA(copy, =)
256 VIGRA_COPY_MULTI_ARRAY_DATA(copyAdd, +=)
257 VIGRA_COPY_MULTI_ARRAY_DATA(copySub, -=)
258 VIGRA_COPY_MULTI_ARRAY_DATA(copyMul, *=)
259 VIGRA_COPY_MULTI_ARRAY_DATA(copyDiv, /=)
261 #undef VIGRA_COPY_MULTI_ARRAY_DATA 263 template <
class SrcIterator,
class Shape,
class T,
class ALLOC>
265 uninitializedCopyMultiArrayData(SrcIterator s, Shape
const & shape, T * & d, ALLOC & a, MetaInt<0>)
267 SrcIterator send = s + shape[0];
268 for(; s < send; ++s, ++d)
270 a.construct(d, static_cast<T const &>(*s));
275 template <
class Ref,
class Ptr,
class Shape,
class T,
class ALLOC>
277 uninitializedCopyMultiArrayData(MultiIterator<1, UInt8, Ref, Ptr> si, Shape
const & shape, T * & d, ALLOC & a, MetaInt<0>)
279 Ptr s = &(*si), send = s + shape[0];
280 for(; s < send; ++s, ++d)
282 a.construct(d, static_cast<T const &>(*s));
286 template <
class SrcIterator,
class Shape,
class T,
class ALLOC,
int N>
288 uninitializedCopyMultiArrayData(SrcIterator s, Shape
const & shape, T * & d, ALLOC & a, MetaInt<N>)
290 SrcIterator send = s + shape[N];
293 uninitializedCopyMultiArrayData(s.begin(), shape, d, a, MetaInt<N-1>());
297 template <
class SrcIterator,
class Shape,
class T,
class Functor>
299 reduceOverMultiArray(SrcIterator s, Shape
const & shape, T & result, Functor
const & f, MetaInt<0>)
301 SrcIterator send = s + shape[0];
308 template <
class SrcIterator,
class Shape,
class T,
class Functor,
int N>
310 reduceOverMultiArray(SrcIterator s, Shape
const & shape, T & result, Functor
const & f, MetaInt<N>)
312 SrcIterator send = s + shape[N];
315 reduceOverMultiArray(s.begin(), shape, result, f, MetaInt<N-1>());
319 struct MaxNormReduceFunctor
321 template <
class T,
class U>
322 void operator()(T & result, U
const & u)
const 330 struct L1NormReduceFunctor
332 template <
class T,
class U>
333 void operator()(T & result, U
const & u)
const 339 struct SquaredL2NormReduceFunctor
341 template <
class T,
class U>
342 void operator()(T & result, U
const & u)
const 349 struct WeightedL2NormReduceFunctor
353 WeightedL2NormReduceFunctor(T s)
358 void operator()(T & result, U
const & u)
const 364 struct SumReduceFunctor
366 template <
class T,
class U>
367 void operator()(T & result, U
const & u)
const 373 struct ProdReduceFunctor
375 template <
class T,
class U>
376 void operator()(T & result, U
const & u)
const 382 struct MinmaxReduceFunctor
384 template <
class T,
class U>
385 void operator()(T & result, U
const & u)
const 389 if(result.second < u)
394 struct MeanVarianceReduceFunctor
396 template <
class T,
class U>
397 void operator()(T & result, U
const & u)
const 400 typename T::second_type t1 = u - result.second;
401 typename T::second_type t2 = t1 / result.first;
403 result.third += (result.first-1.0)*t1*t2;
407 struct AllTrueReduceFunctor
409 template <
class T,
class U>
410 void operator()(T & result, U
const & u)
const 412 result = result && (u != NumericTraits<U>::zero());
416 struct AnyTrueReduceFunctor
418 template <
class T,
class U>
419 void operator()(T & result, U
const & u)
const 421 result = result || (u != NumericTraits<U>::zero());
425 template <
class SrcIterator,
class Shape,
class DestIterator>
427 equalityOfMultiArrays(SrcIterator s, Shape
const & shape, DestIterator d, MetaInt<0>)
429 SrcIterator send = s + shape[0];
430 for(; s < send; ++s, ++d)
438 template <
class SrcIterator,
class Shape,
class DestIterator,
int N>
440 equalityOfMultiArrays(SrcIterator s, Shape
const & shape, DestIterator d, MetaInt<N>)
442 SrcIterator send = s + shape[N];
443 for(; s < send; ++s, ++d)
445 if(!equalityOfMultiArrays(s.begin(), shape, d.begin(), MetaInt<N-1>()))
452 template <
class SrcIterator,
class Shape,
class DestIterator>
454 swapDataImpl(SrcIterator s, Shape
const & shape, DestIterator d, MetaInt<0>)
456 SrcIterator send = s + shape[0];
457 for(; s < send; ++s, ++d)
461 template <
class SrcIterator,
class Shape,
class DestIterator,
int N>
463 swapDataImpl(SrcIterator s, Shape
const & shape, DestIterator d, MetaInt<N>)
465 SrcIterator send = s + shape[N];
466 for(; s < send; ++s, ++d)
467 swapDataImpl(s.begin(), shape, d.begin(), MetaInt<N-1>());
480 namespace multi_math {
483 struct MultiMathOperand;
485 namespace math_detail {
487 template <
unsigned int N,
class T,
class C,
class E>
488 void assign(MultiArrayView<N, T, C>, MultiMathOperand<E>
const &);
490 template <
unsigned int N,
class T,
class C,
class E>
491 void plusAssign(MultiArrayView<N, T, C>, MultiMathOperand<E>
const &);
493 template <
unsigned int N,
class T,
class C,
class E>
494 void minusAssign(MultiArrayView<N, T, C>, MultiMathOperand<E>
const &);
496 template <
unsigned int N,
class T,
class C,
class E>
497 void multiplyAssign(MultiArrayView<N, T, C>, MultiMathOperand<E>
const &);
499 template <
unsigned int N,
class T,
class C,
class E>
500 void divideAssign(MultiArrayView<N, T, C>, MultiMathOperand<E>
const &);
502 template <
unsigned int N,
class T,
class A,
class E>
503 void assignOrResize(MultiArray<N, T, A> &, MultiMathOperand<E>
const &);
505 template <
unsigned int N,
class T,
class A,
class E>
506 void plusAssignOrResize(MultiArray<N, T, A> &, MultiMathOperand<E>
const &);
508 template <
unsigned int N,
class T,
class A,
class E>
509 void minusAssignOrResize(MultiArray<N, T, A> &, MultiMathOperand<E>
const &);
511 template <
unsigned int N,
class T,
class A,
class E>
512 void multiplyAssignOrResize(MultiArray<N, T, A> &, MultiMathOperand<E>
const &);
514 template <
unsigned int N,
class T,
class A,
class E>
515 void divideAssignOrResize(MultiArray<N, T, A> &, MultiMathOperand<E>
const &);
521 template <
class T>
class FindSum;
523 struct UnsuitableTypeForExpandElements {};
526 struct ExpandElementResult
528 typedef UnsuitableTypeForExpandElements type;
532 struct ExpandElementResult<
std::complex<T> >
542 struct ExpandElementResult<FFTWComplex<T> >
548 template <
class T,
int SIZE>
549 struct ExpandElementResult<TinyVector<T, SIZE> >
552 enum { size = SIZE };
555 template <
class T,
unsigned int R,
unsigned int G,
unsigned int B>
556 struct ExpandElementResult<RGBValue<T, R, G, B> >
562 #define VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(TYPE) \ 564 struct ExpandElementResult<TYPE> \ 570 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
bool)
571 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
char)
572 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
signed char)
573 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
signed short)
574 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
signed int)
575 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
signed long)
576 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
signed long long)
577 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
unsigned char)
578 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
unsigned short)
579 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
unsigned int)
580 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
unsigned long)
581 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
unsigned long long)
582 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
float)
583 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
double)
584 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
long double)
586 #undef VIGRA_DEFINE_EXPAND_ELEMENT_RESULT 595 template <
unsigned int N,
class T,
class C>
596 struct NormTraits<MultiArrayView<N, T, C> >
598 typedef MultiArrayView<N, T, C> Type;
599 typedef typename NormTraits<T>::SquaredNormType SquaredNormType;
600 typedef typename SquareRootTraits<SquaredNormType>::SquareRootResult NormType;
603 template <
unsigned int N,
class T,
class A>
604 struct NormTraits<MultiArray<N, T, A> >
605 :
public NormTraits<typename MultiArray<N, T, A>::view_type>
607 typedef NormTraits<typename MultiArray<N, T, A>::view_type> BaseType;
608 typedef MultiArray<N, T, A> Type;
609 typedef typename BaseType::SquaredNormType SquaredNormType;
610 typedef typename BaseType::NormType NormType;
651 template <
unsigned int N,
class T,
class Str
ideTag>
711 typedef typename vigra::detail::MultiIteratorChooser <
712 StrideTag>::template Traverser <actual_dimension, T, T &, T *>::type
traverser;
716 typedef typename vigra::detail::MultiIteratorChooser <
717 StrideTag>::template Traverser <actual_dimension, T, T const &, T const *>::type
const_traverser;
729 return m_stride[0] <= 1;
739 typedef typename difference_type::value_type diff_zero_t;
757 template <
class U,
class CN>
760 template <
class U,
class CN>
766 template <
class U,
class CN>
778 : m_shape (diff_zero_t(0)), m_stride (diff_zero_t(0)), m_ptr (0)
785 template <
class Str
ide>
787 : m_shape (other.shape()),
788 m_stride (other.stride()),
791 vigra_precondition(other.checkInnerStride(StrideTag()),
792 "MultiArrayView<..., UnstridedArrayTag>(MultiArrayView const &): cannot create unstrided view from strided array.");
799 m_stride (detail::defaultStride<actual_dimension>(shape)),
800 m_ptr (const_cast<pointer>(ptr))
809 const difference_type &stride,
813 m_ptr (const_cast<pointer>(ptr))
815 vigra_precondition(checkInnerStride(StrideTag()),
816 "MultiArrayView<..., UnstridedArrayTag>::MultiArrayView(): First dimension of given array is not unstrided.");
821 template <
class ALLOC>
823 : m_shape (
Shape2(image.width(), image.height())),
824 m_stride (detail::defaultStride<actual_dimension>(m_shape)),
825 m_ptr (const_cast<pointer>(image.data()))
839 m_shape = diff_zero_t(0);
840 m_stride = diff_zero_t(0);
862 template<
class Str
ide2>
873 template<
class U,
class C1>
876 vigra_precondition(this->shape() == rhs.
shape(),
877 "MultiArrayView::operator=(): shape mismatch.");
892 template<
class U,
class C1>
898 template<
class U,
class C1>
904 template<
class U,
class C1>
910 template<
class U,
class C1>
917 detail::copyAddScalarMultiArrayData(traverser_begin(), shape(), rhs, MetaInt<actual_dimension-1>());
925 detail::copySubScalarMultiArrayData(traverser_begin(), shape(), rhs, MetaInt<actual_dimension-1>());
933 detail::copyMulScalarMultiArrayData(traverser_begin(), shape(), rhs, MetaInt<actual_dimension-1>());
941 detail::copyDivScalarMultiArrayData(traverser_begin(), shape(), rhs, MetaInt<actual_dimension-1>());
948 template<
class Expression>
951 multi_math::math_detail::assign(*
this, rhs);
958 template<
class Expression>
961 multi_math::math_detail::plusAssign(*
this, rhs);
968 template<
class Expression>
971 multi_math::math_detail::minusAssign(*
this, rhs);
978 template<
class Expression>
981 multi_math::math_detail::multiplyAssign(*
this, rhs);
988 template<
class Expression>
991 multi_math::math_detail::divideAssign(*
this, rhs);
997 reference operator[] (
const difference_type &d)
999 VIGRA_ASSERT_INSIDE(d);
1000 return m_ptr [
dot (d, m_stride)];
1005 const_reference operator[] (
const difference_type &d)
const 1007 VIGRA_ASSERT_INSIDE(d);
1008 return m_ptr [
dot (d, m_stride)];
1016 return bindInner(d);
1031 VIGRA_ASSERT_INSIDE(scanOrderIndexToCoordinate(d));
1032 return m_ptr [detail::ScanOrderToOffset<actual_dimension>::exec(d, m_shape, m_stride)];
1047 VIGRA_ASSERT_INSIDE(scanOrderIndexToCoordinate(d));
1048 return m_ptr [detail::ScanOrderToOffset<actual_dimension>::exec(d, m_shape, m_stride)];
1055 difference_type result;
1056 detail::ScanOrderToCoordinate<actual_dimension>::exec(d, m_shape, result);
1064 return detail::CoordinateToScanOrder<actual_dimension>::exec(m_shape, d);
1069 reference operator() (difference_type_1 x)
1071 VIGRA_ASSERT_INSIDE(difference_type(x));
1072 return m_ptr [detail::CoordinatesToOffest<StrideTag>::exec(m_stride, x)];
1077 reference operator() (difference_type_1 x, difference_type_1 y)
1079 VIGRA_ASSERT_INSIDE(difference_type(x, y));
1080 return m_ptr [detail::CoordinatesToOffest<StrideTag>::exec(m_stride, x, y)];
1085 reference operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z)
1087 VIGRA_ASSERT_INSIDE(difference_type(x, y, z));
1088 return m_ptr [m_stride[0]*x + m_stride[1]*y + m_stride[2]*z];
1093 reference operator() (difference_type_1 x, difference_type_1 y,
1094 difference_type_1 z, difference_type_1 u)
1096 VIGRA_ASSERT_INSIDE(difference_type(x, y, z, u));
1097 return m_ptr [m_stride[0]*x + m_stride[1]*y + m_stride[2]*z + m_stride[3]*u];
1102 reference operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z,
1103 difference_type_1 u, difference_type_1 v)
1105 VIGRA_ASSERT_INSIDE(difference_type(x, y,z, u,v));
1106 return m_ptr [m_stride[0]*x + m_stride[1]*y + m_stride[2]*z + m_stride[3]*u + m_stride[4]*v];
1111 const_reference operator() (difference_type_1 x)
const 1113 VIGRA_ASSERT_INSIDE(difference_type(x));
1114 return m_ptr [detail::CoordinatesToOffest<StrideTag>::exec(m_stride, x)];
1119 const_reference operator() (difference_type_1 x, difference_type_1 y)
const 1121 VIGRA_ASSERT_INSIDE(difference_type(x, y));
1122 return m_ptr [detail::CoordinatesToOffest<StrideTag>::exec(m_stride, x, y)];
1127 const_reference operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z)
const 1129 VIGRA_ASSERT_INSIDE(difference_type(x,y,z));
1130 return m_ptr [m_stride[0]*x + m_stride[1]*y + m_stride[2]*z];
1135 const_reference operator() (difference_type_1 x, difference_type_1 y,
1136 difference_type_1 z, difference_type_1 u)
const 1138 VIGRA_ASSERT_INSIDE(difference_type(x,y,z,u));
1139 return m_ptr [m_stride[0]*x + m_stride[1]*y + m_stride[2]*z + m_stride[3]*u];
1144 const_reference operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z,
1145 difference_type_1 u, difference_type_1 v)
const 1147 VIGRA_ASSERT_INSIDE(difference_type(x,y,z,u,v));
1148 return m_ptr [m_stride[0]*x + m_stride[1]*y + m_stride[2]*z + m_stride[3]*u + m_stride[4]*v];
1157 detail::copyScalarMultiArrayData(traverser_begin(), shape(), init, MetaInt<actual_dimension-1>());
1168 this->copyImpl(rhs);
1173 template <
class U,
class CN>
1176 this->copyImpl(rhs);
1203 std::swap(this->m_shape, other.
m_shape);
1204 std::swap(this->m_stride, other.
m_stride);
1205 std::swap(this->m_ptr, other.
m_ptr);
1222 template <
class T2,
class C2>
1236 difference_type s = vigra::detail::defaultStride<actual_dimension>(shape());
1237 for(
unsigned int k = 0; k <= dimension; ++k)
1238 if(stride(k) != s[k])
1257 template <
int M,
class Index>
1274 template <
int M,
class Index>
1294 template <
unsigned int M>
1295 MultiArrayView <N-1, T,
typename vigra::detail::MaybeStrided<StrideTag, M>::type >
1296 bind (difference_type_1 d)
const;
1312 MultiArrayView <N-1, T, StrideTag> bindOuter (difference_type_1 d)
const;
1345 bindAt (difference_type_1 m, difference_type_1 d)
const;
1365 vigra_precondition(0 <= i && i < ExpandElementResult<T>::size,
1366 "MultiArrayView::bindElementChannel(i): 'i' out of range.");
1367 return expandElements(0).bindInner(i);
1389 expandElements(difference_type_1 d)
const;
1421 insertSingletonDimension (difference_type_1 i)
const;
1478 detail::RelativeToAbsoluteCoordinate<actual_dimension-1>::exec(shape(), p);
1479 detail::RelativeToAbsoluteCoordinate<actual_dimension-1>::exec(shape(), q);
1480 const difference_type_1 offset =
dot (m_stride, p);
1493 difference_type shape = m_shape;
1494 for (
unsigned int i = 0; i < actual_dimension; ++i)
1495 shape[i] = (shape[i] + s[i] - 1) / s[i];
1517 difference_type shape(m_shape.begin(), ReverseCopy),
1518 stride(m_stride.begin(), ReverseCopy);
1543 return permuteDimensions(permutation);
1547 permuteDimensions (
const difference_type &s)
const;
1553 permuteStridesAscending()
const;
1559 permuteStridesDescending()
const;
1567 return strideOrdering(m_stride);
1574 static difference_type strideOrdering(difference_type strides);
1580 difference_type_1 ret = m_shape[0];
1581 for(
int i = 1; i < actual_dimension; ++i)
1591 return elementCount();
1603 difference_type_1
size (difference_type_1 n)
const 1611 difference_type_1
shape (difference_type_1 n)
const 1641 return m_stride [n];
1646 template <
class U,
class C1>
1649 if(this->shape() != rhs.
shape())
1651 return detail::equalityOfMultiArrays(traverser_begin(), shape(), rhs.
traverser_begin(), MetaInt<actual_dimension-1>());
1657 template <
class U,
class C1>
1667 for(
int d=0; d<actual_dimension; ++d)
1668 if(p[d] < 0 || p[d] >= shape(d))
1676 for(
int d=0; d<actual_dimension; ++d)
1677 if(p[d] < 0 || p[d] >= shape(d))
1688 detail::reduceOverMultiArray(traverser_begin(), shape(),
1690 detail::AllTrueReduceFunctor(),
1691 MetaInt<actual_dimension-1>());
1701 detail::reduceOverMultiArray(traverser_begin(), shape(),
1703 detail::AnyTrueReduceFunctor(),
1704 MetaInt<actual_dimension-1>());
1714 std::pair<T, T> res(NumericTraits<T>::max(), NumericTraits<T>::min());
1715 detail::reduceOverMultiArray(traverser_begin(), shape(),
1717 detail::MinmaxReduceFunctor(),
1718 MetaInt<actual_dimension-1>());
1719 *minimum = res.first;
1720 *maximum = res.second;
1730 typedef typename NumericTraits<U>::RealPromote R;
1732 triple<double, R, R> res(0.0, zero, zero);
1733 detail::reduceOverMultiArray(traverser_begin(), shape(),
1735 detail::MeanVarianceReduceFunctor(),
1736 MetaInt<actual_dimension-1>());
1738 *variance = res.third / res.first;
1753 U res = NumericTraits<U>::zero();
1754 detail::reduceOverMultiArray(traverser_begin(), shape(),
1756 detail::SumReduceFunctor(),
1757 MetaInt<actual_dimension-1>());
1786 template <
class U,
class S>
1790 destMultiArrayRange(sums),
1806 U res = NumericTraits<U>::one();
1807 detail::reduceOverMultiArray(traverser_begin(), shape(),
1809 detail::ProdReduceFunctor(),
1810 MetaInt<actual_dimension-1>());
1816 typename NormTraits<MultiArrayView>::SquaredNormType
1819 typedef typename NormTraits<MultiArrayView>::SquaredNormType SquaredNormType;
1820 SquaredNormType res = NumericTraits<SquaredNormType>::zero();
1821 detail::reduceOverMultiArray(traverser_begin(), shape(),
1823 detail::SquaredL2NormReduceFunctor(),
1824 MetaInt<actual_dimension-1>());
1841 typename NormTraits<MultiArrayView>::NormType
1842 norm(
int type = 2,
bool useSquaredNorm =
true)
const;
1851 pointer & unsafePtr()
1871 return iterator(*
this);
1879 return const_iterator(*
this);
1887 return begin().getEndIterator();
1895 return begin().getEndIterator();
1903 traverser ret (m_ptr, m_stride.begin (), m_shape.begin ());
1912 const_traverser ret (m_ptr, m_stride.begin (), m_shape.begin ());
1922 traverser ret (m_ptr, m_stride.begin (), m_shape.begin ());
1923 ret += m_shape [actual_dimension-1];
1933 const_traverser ret (m_ptr, m_stride.begin (), m_shape.begin ());
1934 ret += m_shape [actual_dimension-1];
1938 view_type view ()
const 1944 template <
unsigned int N,
class T,
class Str
ideTag>
1955 template <
unsigned int N,
class T,
class Str
ide1>
1956 template <
class Str
ide2>
1962 vigra_precondition(rhs.checkInnerStride(Stride1()),
1963 "MultiArrayView<..., UnstridedArrayTag>::operator=(MultiArrayView const &): cannot create unstrided view from strided array.");
1965 m_shape = rhs.shape();
1966 m_stride = rhs.stride();
1971 vigra_precondition(this->shape() == rhs.shape(),
1972 "MultiArrayView::operator=(MultiArrayView const &): shape mismatch.");
1973 this->copyImpl(rhs);
1977 template <
unsigned int N,
class T,
class Str
ideTag>
1982 vigra_precondition (shape () == rhs.shape (),
1983 "MultiArrayView::arraysOverlap(): shape mismatch.");
1985 last_element = first_element +
dot(this->m_shape -
difference_type(1), this->m_stride);
1987 rhs_first_element = rhs.data(),
1988 rhs_last_element = rhs_first_element +
dot(rhs.shape() -
difference_type(1), rhs.stride());
1989 return !(last_element < rhs_first_element || rhs_last_element < first_element);
1992 template <
unsigned int N,
class T,
class Str
ideTag>
1993 template <
class U,
class CN>
1997 if(!arraysOverlap(rhs))
2000 detail::copyMultiArrayData(rhs.traverser_begin(), shape(), traverser_begin(), MetaInt<actual_dimension-1>());
2007 detail::copyMultiArrayData(tmp.traverser_begin(), shape(), traverser_begin(), MetaInt<actual_dimension-1>());
2011 #define VIGRA_MULTI_ARRAY_COMPUTED_ASSIGNMENT(name, op) \ 2012 template <unsigned int N, class T, class StrideTag> \ 2013 template<class U, class C1> \ 2014 MultiArrayView<N, T, StrideTag> & \ 2015 MultiArrayView <N, T, StrideTag>::operator op(MultiArrayView<N, U, C1> const & rhs) \ 2017 vigra_precondition(this->shape() == rhs.shape(), "MultiArrayView::operator" #op "() size mismatch."); \ 2018 if(!arraysOverlap(rhs)) \ 2020 detail::name##MultiArrayData(rhs.traverser_begin(), shape(), traverser_begin(), MetaInt<actual_dimension-1>()); \ 2024 MultiArray<N, T> tmp(rhs); \ 2025 detail::name##MultiArrayData(tmp.traverser_begin(), shape(), traverser_begin(), MetaInt<actual_dimension-1>()); \ 2030 VIGRA_MULTI_ARRAY_COMPUTED_ASSIGNMENT(copyAdd, +=)
2031 VIGRA_MULTI_ARRAY_COMPUTED_ASSIGNMENT(copySub, -=)
2032 VIGRA_MULTI_ARRAY_COMPUTED_ASSIGNMENT(copyMul, *=)
2033 VIGRA_MULTI_ARRAY_COMPUTED_ASSIGNMENT(copyDiv, /=)
2035 #undef VIGRA_MULTI_ARRAY_COMPUTED_ASSIGNMENT 2037 template <
unsigned int N,
class T,
class Str
ideTag>
2038 template <
class U,
class CN>
2042 vigra_precondition (shape () == rhs.shape (),
2043 "MultiArrayView::swapData(): shape mismatch.");
2047 last_element = first_element +
dot(this->m_shape -
difference_type(1), this->m_stride);
2049 rhs_first_element = rhs.data(),
2050 rhs_last_element = rhs_first_element +
dot(rhs.shape() -
difference_type(1), rhs.stride());
2051 if(last_element < rhs_first_element || rhs_last_element < first_element)
2054 detail::swapDataImpl(traverser_begin(), shape(), rhs.traverser_begin(), MetaInt<actual_dimension-1>());
2066 template <
unsigned int N,
class T,
class Str
ideTag>
2070 difference_type shape, stride, check((
typename difference_type::value_type)0);
2071 for (
unsigned int i = 0; i < actual_dimension; ++i)
2073 shape[i] = m_shape[s[i]];
2074 stride[i] = m_stride[s[i]];
2078 "MultiArrayView::transpose(): every dimension must occur exactly once.");
2082 template <
unsigned int N,
class T,
class Str
ideTag>
2087 for(
int k=0; k<(int)N; ++k)
2089 for(
int k=0; k<(int)N-1; ++k)
2092 for(
int j=k+1; j<(int)N; ++j)
2094 if(stride[j] < stride[smallest])
2099 std::swap(stride[k], stride[smallest]);
2100 std::swap(permutation[k], permutation[smallest]);
2104 for(
unsigned int k=0; k<N; ++k)
2105 ordering[permutation[k]] = k;
2109 template <
unsigned int N,
class T,
class Str
ideTag>
2115 permutation[ordering[k]] = k;
2116 return permuteDimensions(permutation);
2119 template <
unsigned int N,
class T,
class Str
ideTag>
2125 permutation[N-1-ordering[k]] = k;
2126 return permuteDimensions(permutation);
2129 template <
unsigned int N,
class T,
class Str
ideTag>
2130 template <
int M,
class Index>
2135 stride.
init (m_stride.begin () + N-M, m_stride.
end ());
2137 static const int NNew = (N-M == 0) ? 1 : N-M;
2141 inner_shape [0] = 1;
2142 inner_stride [0] = 1;
2146 inner_shape.
init (m_shape.begin (), m_shape.end () - M);
2147 inner_stride.
init (m_stride.begin (), m_stride.end () - M);
2149 return MultiArrayView <N-M, T, StrideTag> (inner_shape, inner_stride, ptr);
2152 template <
unsigned int N,
class T,
class Str
ideTag>
2153 template <
int M,
class Index>
2158 stride.
init (m_stride.begin (), m_stride.end () - N + M);
2160 static const int NNew = (N-M == 0) ? 1 : N-M;
2164 outer_shape [0] = 1;
2165 outer_stride [0] = 1;
2169 outer_shape.
init (m_shape.begin () + M, m_shape.end ());
2170 outer_stride.
init (m_stride.begin () + M, m_stride.end ());
2173 (outer_shape, outer_stride, ptr);
2176 template <
unsigned int N,
class T,
class Str
ideTag>
2177 template <
unsigned int M>
2178 MultiArrayView <N-1, T,
typename detail::MaybeStrided<StrideTag, M>::type >
2181 static const int NNew = (N-1 == 0) ? 1 : N-1;
2191 std::copy (m_shape.begin (), m_shape.begin () + M, shape.
begin ());
2192 std::copy (m_shape.begin () + M+1, m_shape.end (),
2193 shape.
begin () + M);
2194 std::copy (m_stride.begin (), m_stride.begin () + M, stride.
begin ());
2195 std::copy (m_stride.begin () + M+1, m_stride.end (),
2196 stride.
begin () + M);
2198 return MultiArrayView <N-1, T,
typename detail::MaybeStrided<StrideTag, M>::type>
2199 (shape, stride, m_ptr + d * m_stride[M]);
2202 template <
unsigned int N,
class T,
class Str
ideTag>
2206 static const int NNew = (N-1 == 0) ? 1 : N-1;
2210 inner_shape [0] = 1;
2211 inner_stride [0] = 1;
2215 inner_shape.
init (m_shape.begin (), m_shape.end () - 1);
2216 inner_stride.
init (m_stride.begin (), m_stride.end () - 1);
2218 return MultiArrayView <N-1, T, StrideTag> (inner_shape, inner_stride,
2219 m_ptr + d * m_stride [N-1]);
2222 template <
unsigned int N,
class T,
class Str
ideTag>
2226 static const int NNew = (N-1 == 0) ? 1 : N-1;
2230 outer_shape [0] = 1;
2231 outer_stride [0] = 1;
2235 outer_shape.
init (m_shape.begin () + 1, m_shape.end ());
2236 outer_stride.
init (m_stride.begin () + 1, m_stride.end ());
2239 (outer_shape, outer_stride, m_ptr + d * m_stride [0]);
2242 template <
unsigned int N,
class T,
class Str
ideTag>
2246 vigra_precondition (
2247 n < static_cast <int> (N),
2248 "MultiArrayView <N, T, StrideTag>::bindAt(): dimension out of range.");
2249 static const int NNew = (N-1 == 0) ? 1 : N-1;
2259 std::copy (m_shape.begin (), m_shape.begin () + n, shape.
begin ());
2260 std::copy (m_shape.begin () + n+1, m_shape.
end (),
2261 shape.
begin () + n);
2262 std::copy (m_stride.begin (), m_stride.begin () + n, stride.
begin ());
2263 std::copy (m_stride.begin () + n+1, m_stride.
end (),
2264 stride.
begin () + n);
2267 (shape, stride, m_ptr + d * m_stride[n]);
2271 template <
unsigned int N,
class T,
class Str
ideTag>
2275 vigra_precondition(0 <= d && d <= static_cast <difference_type_1> (N),
2276 "MultiArrayView<N, ...>::expandElements(d): 0 <= 'd' <= N required.");
2278 int elementSize = ExpandElementResult<T>::size;
2280 for(
int k=0; k<d; ++k)
2282 newShape[k] = m_shape[k];
2283 newStrides[k] = m_stride[k]*elementSize;
2286 newShape[d] = elementSize;
2289 for(
int k=d; k<N; ++k)
2291 newShape[k+1] = m_shape[k];
2292 newStrides[k+1] = m_stride[k]*elementSize;
2295 typedef typename ExpandElementResult<T>::type U;
2297 newShape, newStrides,
reinterpret_cast<U*
>(m_ptr));
2300 template <
unsigned int N,
class T,
class Str
ideTag>
2304 vigra_precondition (
2305 0 <= i && i <= static_cast <difference_type_1> (N),
2306 "MultiArrayView <N, T, StrideTag>::insertSingletonDimension(): index out of range.");
2308 std::copy (m_shape.begin (), m_shape.begin () + i, shape.
begin ());
2309 std::copy (m_shape.begin () + i, m_shape.end (), shape.
begin () + i + 1);
2310 std::copy (m_stride.begin (), m_stride.begin () + i, stride.
begin ());
2311 std::copy (m_stride.begin () + i, m_stride.end (), stride.
begin () + i + 1);
2318 template <
unsigned int N,
class T,
class Str
ideTag>
2319 typename NormTraits<MultiArrayView <N, T, StrideTag> >::NormType
2322 typedef typename NormTraits<MultiArrayView>::NormType NormType;
2328 NormType res = NumericTraits<NormType>::zero();
2329 detail::reduceOverMultiArray(traverser_begin(), shape(),
2331 detail::MaxNormReduceFunctor(),
2332 MetaInt<actual_dimension-1>());
2337 NormType res = NumericTraits<NormType>::zero();
2338 detail::reduceOverMultiArray(traverser_begin(), shape(),
2340 detail::L1NormReduceFunctor(),
2341 MetaInt<actual_dimension-1>());
2352 NormType normMax = NumericTraits<NormType>::zero();
2353 detail::reduceOverMultiArray(traverser_begin(), shape(),
2355 detail::MaxNormReduceFunctor(),
2356 MetaInt<actual_dimension-1>());
2357 if(normMax == NumericTraits<NormType>::zero())
2359 NormType res = NumericTraits<NormType>::zero();
2360 detail::reduceOverMultiArray(traverser_begin(), shape(),
2362 detail::WeightedL2NormReduceFunctor<NormType>(1.0/normMax),
2363 MetaInt<actual_dimension-1>());
2364 return sqrt(res)*normMax;
2368 vigra_precondition(
false,
"MultiArrayView::norm(): Unknown norm type.");
2369 return NumericTraits<NormType>::zero();
2380 template <
unsigned int N,
class T,
class Str
ideTag>
2381 inline typename NormTraits<MultiArrayView <N, T, StrideTag> >::SquaredNormType
2387 template <
unsigned int N,
class T,
class Str
ideTag>
2388 inline typename NormTraits<MultiArrayView <N, T, StrideTag> >::NormType
2421 template <
unsigned int N,
class T,
class A >
2423 :
public MultiArrayView <N, typename vigra::detail::ResolveMultiband<T>::type,
2424 typename vigra::detail::ResolveMultiband<T>::Stride>
2434 using view_type::actual_dimension;
2504 typedef typename difference_type::value_type diff_zero_t;
2513 void allocate (pointer &ptr, difference_type_1 s, const_reference init);
2519 void allocate (pointer &ptr, difference_type_1 s, U
const * init);
2524 template <
class U,
class Str
ideTag>
2529 void deallocate (pointer &ptr, difference_type_1 s);
2531 template <
class U,
class Str
ideTag>
2537 : view_type (difference_type (diff_zero_t(0)),
2538 difference_type (diff_zero_t(0)), 0)
2544 : view_type(difference_type (diff_zero_t(0)),
2545 difference_type (diff_zero_t(0)), 0),
2553 explicit MultiArray (difference_type_1 length,
2554 allocator_type
const & alloc = allocator_type());
2561 MultiArray (difference_type_1 width, difference_type_1 height,
2562 allocator_type
const & alloc = allocator_type());
2566 explicit MultiArray (
const difference_type &shape,
2567 allocator_type
const & alloc = allocator_type());
2571 MultiArray (
const difference_type &shape, const_reference init,
2572 allocator_type
const & alloc = allocator_type());
2578 allocator_type
const & alloc = allocator_type());
2582 MultiArray (
const difference_type &shape, const_pointer init,
2583 allocator_type
const & alloc = allocator_type());
2588 : view_type(rhs.m_shape, rhs.m_stride, 0),
2589 m_alloc (rhs.m_alloc)
2591 allocate (this->m_ptr, this->elementCount (), rhs.data ());
2596 template<
class Expression>
2597 MultiArray (multi_math::MultiMathOperand<Expression>
const & rhs,
2598 allocator_type
const & alloc = allocator_type())
2599 : view_type(difference_type (diff_zero_t(0)),
2600 difference_type (diff_zero_t(0)), 0),
2603 multi_math::math_detail::assignOrResize(*
this, rhs);
2608 template <
class U,
class Str
ideTag>
2610 allocator_type
const & alloc = allocator_type());
2617 MultiArray & operator= (
const MultiArray &rhs)
2620 this->copyOrReshape(rhs);
2629 template <
class U,
class Str
ideTag>
2632 this->copyOrReshape(rhs);
2641 return this->init(v);
2650 template <
class U,
class Str
ideTag>
2666 template <
class U,
class Str
ideTag>
2669 if(!this->hasData())
2670 this->reshape(rhs.
shape());
2681 template <
class U,
class Str
ideTag>
2687 this->reshape(rhs.
shape());
2697 template <
class U,
class Str
ideTag>
2703 this->reshape(rhs.
shape());
2741 template<
class Expression>
2742 MultiArray &
operator=(multi_math::MultiMathOperand<Expression>
const & rhs)
2744 multi_math::math_detail::assignOrResize(*
this, rhs);
2751 template<
class Expression>
2752 MultiArray &
operator+=(multi_math::MultiMathOperand<Expression>
const & rhs)
2754 multi_math::math_detail::plusAssignOrResize(*
this, rhs);
2761 template<
class Expression>
2762 MultiArray &
operator-=(multi_math::MultiMathOperand<Expression>
const & rhs)
2764 multi_math::math_detail::minusAssignOrResize(*
this, rhs);
2771 template<
class Expression>
2772 MultiArray &
operator*=(multi_math::MultiMathOperand<Expression>
const & rhs)
2774 multi_math::math_detail::multiplyAssignOrResize(*
this, rhs);
2781 template<
class Expression>
2782 MultiArray &
operator/=(multi_math::MultiMathOperand<Expression>
const & rhs)
2784 multi_math::math_detail::divideAssignOrResize(*
this, rhs);
2792 deallocate (this->m_ptr, this->elementCount ());
2801 view_type::init(init);
2811 reshape (shape, value_type());
2819 void reshape (
const difference_type &shape, const_reference init);
2826 void swap (MultiArray & other);
2863 static difference_type defaultStride(difference_type
const & shape)
2865 return vigra::detail::ResolveMultiband<T>::defaultStride(shape);
2869 template <
unsigned int N,
class T,
class A>
2871 allocator_type
const & alloc)
2872 : view_type(difference_type(length),
2873 defaultStride(difference_type(length)),
2877 allocate (this->m_ptr, this->elementCount (), value_type());
2880 template <
unsigned int N,
class T,
class A>
2882 allocator_type
const & alloc)
2883 : view_type(difference_type(width, height),
2884 defaultStride(difference_type(width, height)),
2888 allocate (this->m_ptr, this->elementCount (), value_type());
2891 template <
unsigned int N,
class T,
class A>
2893 allocator_type
const & alloc)
2895 defaultStride(shape),
2901 this->m_shape [0] = 1;
2902 this->m_stride [0] = 1;
2904 allocate (this->m_ptr, this->elementCount (), value_type());
2907 template <
unsigned int N,
class T,
class A>
2909 allocator_type
const & alloc)
2911 defaultStride(shape),
2917 this->m_shape [0] = 1;
2918 this->m_stride [0] = 1;
2920 allocate (this->m_ptr, this->elementCount (), init);
2923 template <
unsigned int N,
class T,
class A>
2925 allocator_type
const & alloc)
2927 defaultStride(shape),
2933 this->m_shape [0] = 1;
2934 this->m_stride [0] = 1;
2936 allocate (this->m_ptr, this->elementCount (), value_type());
2943 vigra_precondition(
false,
2944 "MultiArray(): invalid MultiArrayInitializationTag.");
2948 template <
unsigned int N,
class T,
class A>
2950 allocator_type
const & alloc)
2952 defaultStride(shape),
2958 this->m_shape [0] = 1;
2959 this->m_stride [0] = 1;
2961 allocate (this->m_ptr, this->elementCount (), init);
2964 template <
unsigned int N,
class T,
class A>
2965 template <
class U,
class Str
ideTag>
2967 allocator_type
const & alloc)
2968 : view_type(rhs.shape(),
2969 defaultStride(rhs.shape()),
2973 allocate (this->m_ptr, rhs);
2976 template <
unsigned int N,
class T,
class A>
2977 template <
class U,
class Str
ideTag>
2981 if (this->shape() == rhs.shape())
2990 template <
unsigned int N,
class T,
class A>
2992 const_reference initial)
2998 else if(new_shape == this->shape())
3000 this->init(initial);
3004 difference_type new_stride = defaultStride(new_shape);
3005 difference_type_1 new_size =
prod(new_shape);
3006 pointer new_ptr = pointer();
3007 allocate (new_ptr, new_size, initial);
3008 deallocate (this->m_ptr, this->elementCount ());
3009 this->m_ptr = new_ptr;
3010 this->m_shape = new_shape;
3011 this->m_stride = new_stride;
3016 template <
unsigned int N,
class T,
class A>
3022 this->view_type::swap(other);
3023 std::swap(this->m_alloc, other.m_alloc);
3026 template <
unsigned int N,
class T,
class A>
3028 const_reference init)
3035 ptr = m_alloc.
allocate ((
typename A::size_type)s);
3036 difference_type_1 i = 0;
3039 m_alloc.construct (ptr + i, init);
3042 for (difference_type_1 j = 0; j < i; ++j)
3043 m_alloc.destroy (ptr + j);
3044 m_alloc.deallocate (ptr, (
typename A::size_type)s);
3049 template <
unsigned int N,
class T,
class A>
3059 ptr = m_alloc.
allocate ((
typename A::size_type)s);
3060 difference_type_1 i = 0;
3062 for (; i < s; ++i, ++init)
3063 m_alloc.construct (ptr + i, *init);
3066 for (difference_type_1 j = 0; j < i; ++j)
3067 m_alloc.destroy (ptr + j);
3068 m_alloc.deallocate (ptr, (
typename A::size_type)s);
3073 template <
unsigned int N,
class T,
class A>
3074 template <
class U,
class Str
ideTag>
3077 difference_type_1 s = init.elementCount();
3083 ptr = m_alloc.
allocate ((
typename A::size_type)s);
3086 detail::uninitializedCopyMultiArrayData(init.traverser_begin(), init.shape(),
3087 p, m_alloc, MetaInt<actual_dimension-1>());
3090 for (pointer pp = ptr; pp < p; ++pp)
3091 m_alloc.destroy (pp);
3092 m_alloc.deallocate (ptr, (
typename A::size_type)s);
3097 template <
unsigned int N,
class T,
class A>
3102 for (difference_type_1 i = 0; i < s; ++i)
3103 m_alloc.destroy (ptr + i);
3104 m_alloc.
deallocate (ptr, (
typename A::size_type)s);
3114 template <
unsigned int N,
class T,
class Str
ideTag>
3115 inline triple<typename MultiArrayView<N,T,StrideTag>::const_traverser,
3120 return triple<typename MultiArrayView<N,T,StrideTag>::const_traverser,
3121 typename MultiArrayView<N,T,StrideTag>::difference_type,
3128 template <
unsigned int N,
class T,
class Str
ideTag,
class Accessor>
3129 inline triple<typename MultiArrayView<N,T,StrideTag>::const_traverser,
3130 typename MultiArrayView<N,T,StrideTag>::difference_type,
3134 return triple<typename MultiArrayView<N,T,StrideTag>::const_traverser,
3135 typename MultiArrayView<N,T,StrideTag>::difference_type,
3142 template <
unsigned int N,
class T,
class Str
ideTag>
3143 inline pair<typename MultiArrayView<N,T,StrideTag>::const_traverser,
3147 return pair<typename MultiArrayView<N,T,StrideTag>::const_traverser,
3153 template <
unsigned int N,
class T,
class Str
ideTag,
class Accessor>
3154 inline pair<typename MultiArrayView<N,T,StrideTag>::const_traverser,
3158 return pair<typename MultiArrayView<N,T,StrideTag>::const_traverser,
3163 template <
unsigned int N,
class T,
class Str
ideTag>
3164 inline triple<typename MultiArrayView<N,T,StrideTag>::traverser,
3165 typename MultiArrayView<N,T,StrideTag>::difference_type,
3169 return triple<typename MultiArrayView<N,T,StrideTag>::traverser,
3170 typename MultiArrayView<N,T,StrideTag>::difference_type,
3177 template <
unsigned int N,
class T,
class Str
ideTag,
class Accessor>
3178 inline triple<typename MultiArrayView<N,T,StrideTag>::traverser,
3179 typename MultiArrayView<N,T,StrideTag>::difference_type,
3183 return triple<typename MultiArrayView<N,T,StrideTag>::traverser,
3184 typename MultiArrayView<N,T,StrideTag>::difference_type,
3191 template <
unsigned int N,
class T,
class Str
ideTag>
3192 inline pair<typename MultiArrayView<N,T,StrideTag>::traverser,
3196 return pair<typename MultiArrayView<N,T,StrideTag>::traverser,
3202 template <
unsigned int N,
class T,
class Str
ideTag,
class Accessor>
3203 inline pair<typename MultiArrayView<N,T,StrideTag>::traverser,
3207 return pair<typename MultiArrayView<N,T,StrideTag>::traverser,
3214 template <
class PixelType,
class Accessor>
3215 inline triple<ConstStridedImageIterator<PixelType>,
3219 ConstStridedImageIterator<PixelType>
3221 return triple<ConstStridedImageIterator<PixelType>,
3222 ConstStridedImageIterator<PixelType>,
3227 template <
class PixelType,
class Accessor>
3228 inline pair<ConstStridedImageIterator<PixelType>, Accessor>
3231 ConstStridedImageIterator<PixelType>
3233 return pair<ConstStridedImageIterator<PixelType>, Accessor>
3237 template <
class PixelType,
class Accessor>
3238 inline triple<StridedImageIterator<PixelType>,
3242 StridedImageIterator<PixelType>
3244 return triple<StridedImageIterator<PixelType>,
3245 StridedImageIterator<PixelType>,
3250 template <
class PixelType,
class Accessor>
3251 inline pair<StridedImageIterator<PixelType>, Accessor>
3254 StridedImageIterator<PixelType>
3256 return pair<StridedImageIterator<PixelType>, Accessor>
3260 template <
class PixelType,
class Accessor>
3261 inline pair<StridedImageIterator<PixelType>, Accessor>
3264 StridedImageIterator<PixelType>
3266 return pair<StridedImageIterator<PixelType>, Accessor>
3272 template <
class PixelType>
3273 inline triple<ConstStridedImageIterator<PixelType>,
3274 ConstStridedImageIterator<PixelType>,
3278 ConstStridedImageIterator<PixelType>
3281 return triple<ConstStridedImageIterator<PixelType>,
3282 ConstStridedImageIterator<PixelType>,
3287 template <
class PixelType>
3288 inline triple<ConstImageIterator<PixelType>,
3293 ConstImageIterator<PixelType>
3296 return triple<ConstImageIterator<PixelType>,
3297 ConstImageIterator<PixelType>,
3302 template <
class PixelType>
3303 inline pair< ConstStridedImageIterator<PixelType>,
3307 ConstStridedImageIterator<PixelType>
3310 return pair<ConstStridedImageIterator<PixelType>,
3315 template <
class PixelType>
3316 inline pair< ConstImageIterator<PixelType>,
3320 ConstImageIterator<PixelType>
3323 return pair<ConstImageIterator<PixelType>,
3328 template <
class PixelType>
3329 inline triple< StridedImageIterator<PixelType>,
3330 StridedImageIterator<PixelType>,
3334 StridedImageIterator<PixelType>
3337 return triple<StridedImageIterator<PixelType>,
3338 StridedImageIterator<PixelType>,
3343 template <
class PixelType>
3344 inline triple< ImageIterator<PixelType>,
3349 ImageIterator<PixelType>
3352 return triple<ImageIterator<PixelType>,
3353 ImageIterator<PixelType>,
3358 template <
class PixelType>
3359 inline pair< StridedImageIterator<PixelType>,
3363 StridedImageIterator<PixelType>
3366 return pair<StridedImageIterator<PixelType>, Accessor>
3370 template <
class PixelType>
3371 inline pair< ImageIterator<PixelType>,
3375 ImageIterator<PixelType> ul(img.
data(), img.
stride(1));
3377 return pair<ImageIterator<PixelType>, Accessor>(ul, Accessor());
3380 template <
class PixelType>
3381 inline pair< ConstStridedImageIterator<PixelType>,
3385 ConstStridedImageIterator<PixelType>
3388 return pair<ConstStridedImageIterator<PixelType>, Accessor>
3392 template <
class PixelType>
3393 inline pair< ConstImageIterator<PixelType>,
3397 ConstImageIterator<PixelType>
3400 return pair<ConstImageIterator<PixelType>, Accessor>
3422 template <
class T,
class Str
ide>
3427 "makeBasicImageView(array): array must be unstrided (i.e. array.isUnstrided() == true).");
3444 vigra_precondition(array.stride(1) == array.shape(0),
3445 "makeBasicImageView(): cannot join strided dimensions");
3447 array.shape (0)*array.shape (1), array.shape (2), array.stride(2));
3458 template <
class T,
class Str
ide>
3462 vigra_precondition(array.
shape (0) == 3,
3463 "makeRGBImageView(): array.shape(0) must be 3.");
3465 "makeRGBImageView(array): array must be unstrided (i.e. array.isUnstrided() == true).");
3475 #undef VIGRA_ASSERT_INSIDE 3477 #endif // VIGRA_MULTI_ARRAY_HXX MultiArray & operator/=(multi_math::MultiMathOperand< Expression > const &rhs)
Definition: multi_array.hxx:2782
MultiArrayView< N, typename vigra::detail::ResolveMultiband< T >::type, typename vigra::detail::ResolveMultiband< T >::Stride > view_type
Definition: multi_array.hxx:2432
const value_type & const_reference
Definition: multi_array.hxx:675
MultiArrayView(const difference_type &shape, const difference_type &stride, const_pointer ptr)
Definition: multi_array.hxx:808
MultiArray & operator=(multi_math::MultiMathOperand< Expression > const &rhs)
Definition: multi_array.hxx:2742
void sum(MultiArrayView< N, U, S > sums) const
Definition: multi_array.hxx:1787
MultiArrayView & operator=(multi_math::MultiMathOperand< Expression > const &rhs)
Definition: multi_array.hxx:949
iterator end()
Definition: multi_array.hxx:1885
Sequential iterator for MultiArrayView.
Definition: multi_fwd.hxx:161
MultiArrayView & operator+=(T const &rhs)
Definition: multi_array.hxx:915
MultiArray< N, T > matrix_type
Definition: multi_array.hxx:725
MultiArray< N, T, A > matrix_type
Definition: multi_array.hxx:2442
PromoteTraits< V1, V2 >::Promote dot(RGBValue< V1, RIDX1, GIDX1, BIDX1 > const &r1, RGBValue< V2, RIDX2, GIDX2, BIDX2 > const &r2)
dot product
Definition: rgbvalue.hxx:906
view_type::pointer pointer
Definition: multi_array.hxx:2450
MultiArrayShape< actual_dimension >::type difference_type
Definition: multi_array.hxx:687
MultiArrayView & operator=(value_type const &v)
Definition: multi_array.hxx:884
MultiArray & operator+=(multi_math::MultiMathOperand< Expression > const &rhs)
Definition: multi_array.hxx:2752
MultiArray()
Definition: multi_array.hxx:2536
const difference_type & shape() const
Definition: multi_array.hxx:1596
ActualDimension
Definition: multi_array.hxx:663
MultiArrayView< N, T, StrideTag > view_type
Definition: multi_array.hxx:721
void linearSequence(Iterator first, Iterator last, Value start, Value step)
Fill an array with a sequence of numbers.
Definition: algorithm.hxx:208
MultiArrayInitializationTag
Initialize a MultiArray in a standard way.
Definition: multi_fwd.hxx:104
difference_type m_shape
Definition: multi_array.hxx:743
MultiArray(allocator_type const &alloc)
Definition: multi_array.hxx:2543
difference_type_1 width() const
Definition: multi_array.hxx:1618
MultiArray & operator=(value_type const &v)
Definition: multi_array.hxx:2639
A allocator_type
Definition: multi_array.hxx:2438
U product() const
Definition: multi_array.hxx:1804
view_type::iterator iterator
Definition: multi_array.hxx:2496
reference operator[](difference_type_1 d)
Definition: multi_array.hxx:1029
MultiArrayView & operator-=(T const &rhs)
Definition: multi_array.hxx:923
difference_type size_type
Definition: multi_array.hxx:695
MultiArrayView & operator*=(multi_math::MultiMathOperand< Expression > const &rhs)
Definition: multi_array.hxx:979
pointer data() const
Definition: multi_array.hxx:1846
void deallocate(pointer &ptr, difference_type_1 s)
Definition: multi_array.hxx:3098
Definition: array_vector.hxx:954
difference_type_1 elementCount() const
Definition: multi_array.hxx:1578
FFTWComplex< R >::SquaredNormType squaredNorm(const FFTWComplex< R > &a)
squared norm (= squared magnitude)
Definition: fftw3.hxx:1044
iterator begin()
Definition: multi_array.hxx:1869
MultiArrayView & operator/=(T const &rhs)
Definition: multi_array.hxx:939
void reshape(const difference_type &shape)
Definition: multi_array.hxx:2809
view_type::traverser traverser
Definition: multi_array.hxx:2478
Initialize array by a linear sequence in scan order.
Definition: multi_fwd.hxx:105
void reset()
Definition: multi_array.hxx:838
Standard 2D random access const iterator for images that store the data as a linear array...
Definition: imageiterator.hxx:893
BasicImageView< RGBValue< T > > makeRGBImageView(MultiArrayView< 3, T, Stride > const &array)
Definition: multi_array.hxx:3460
std::ptrdiff_t MultiArrayIndex
Definition: multi_fwd.hxx:60
Find the sum of the pixel values in an image or ROI.
Definition: inspectimage.hxx:1143
MultiArrayView(const difference_type &shape, const_pointer ptr)
Definition: multi_array.hxx:797
Definition: accessor.hxx:43
const_iterator begin() const
Definition: multi_array.hxx:1877
StridedScanOrderIterator< actual_dimension, T, T &, T * > iterator
Definition: multi_array.hxx:703
vigra::detail::MultiIteratorChooser< StrideTag >::template Traverser< actual_dimension, T, T const &, T const * >::type const_traverser
Definition: multi_array.hxx:717
MultiArrayView & operator/=(multi_math::MultiMathOperand< Expression > const &rhs)
Definition: multi_array.hxx:989
NormTraits< MultiArrayView >::NormType norm(int type=2, bool useSquaredNorm=true) const
Definition: multi_array.hxx:2320
MultiArrayView< N, T, StridedArrayTag > transpose() const
Definition: multi_array.hxx:1515
view_type::difference_type difference_type
Definition: multi_array.hxx:2470
void meanVariance(U *mean, U *variance) const
Definition: multi_array.hxx:1728
FFTWComplex< R > & operator-=(FFTWComplex< R > &a, const FFTWComplex< R > &b)
subtract-assignment
Definition: fftw3.hxx:867
MultiArray(multi_math::MultiMathOperand< Expression > const &rhs, allocator_type const &alloc=allocator_type())
Definition: multi_array.hxx:2597
Two dimensional size object.
Definition: diff2d.hxx:482
view_type::const_traverser const_traverser
Definition: multi_array.hxx:2482
Const iterator to be used when pixels are to be skipped.
Definition: imageiterator.hxx:1026
FFTWComplex< R >::NormType norm(const FFTWComplex< R > &a)
norm (= magnitude)
Definition: fftw3.hxx:1037
vigra::detail::MultiIteratorChooser< StrideTag >::template Traverser< actual_dimension, T, T &, T * >::type traverser
Definition: multi_array.hxx:712
difference_type_1 size() const
Definition: multi_array.hxx:1589
FFTWComplex< R > & operator+=(FFTWComplex< R > &a, const FFTWComplex< R > &b)
add-assignment
Definition: fftw3.hxx:859
void swapData(MultiArrayView< N, T2, C2 > rhs)
Definition: multi_array.hxx:1223
NormTraits< MultiArrayView >::SquaredNormType squaredNorm() const
Definition: multi_array.hxx:1817
Definition: multi_fwd.hxx:63
bool operator==(MultiArrayView< N, U, C1 > const &rhs) const
Definition: multi_array.hxx:1647
view_type::reference reference
Definition: multi_array.hxx:2458
NumericTraits< V >::Promote prod(TinyVectorBase< V, SIZE, D1, D2 > const &l)
product of the vector's elements
Definition: tinyvector.hxx:2097
BasicImageView< T > makeBasicImageView(MultiArrayView< 2, T, Stride > const &array)
Definition: multi_array.hxx:3424
MultiArrayIndex difference_type_1
Definition: multi_array.hxx:699
MultiArrayView< N, Multiband< value_type >, StrideTag > multiband() const
Definition: multi_array.hxx:1431
const difference_type & stride() const
Definition: multi_array.hxx:1632
bool any() const
Definition: multi_array.hxx:1698
bool operator!=(MultiArrayView< N, U, C1 > const &rhs) const
Definition: multi_array.hxx:1658
NumericTraits< V >::Promote sum(TinyVectorBase< V, SIZE, D1, D2 > const &l)
sum of the vector's elements
Definition: tinyvector.hxx:2073
MultiArray & operator*=(multi_math::MultiMathOperand< Expression > const &rhs)
Definition: multi_array.hxx:2772
value_type & reference
Definition: multi_array.hxx:671
MultiArrayView & operator-=(multi_math::MultiMathOperand< Expression > const &rhs)
Definition: multi_array.hxx:969
const_reference operator[](difference_type_1 d) const
Definition: multi_array.hxx:1045
difference_type_1 stride(int n) const
Definition: multi_array.hxx:1639
iterator begin()
Definition: tinyvector.hxx:861
bool isInside(difference_type const &p) const
Definition: multi_array.hxx:1665
difference_type_1 coordinateToScanOrderIndex(const difference_type &d) const
Definition: multi_array.hxx:1062
bool operator==(FFTWComplex< R > const &a, const FFTWComplex< R > &b)
equal
Definition: fftw3.hxx:825
const_iterator end() const
Definition: multi_array.hxx:1893
MultiArray & init(const U &init)
Definition: multi_array.hxx:2799
MultiArrayView< 1, T, StridedArrayTag > diagonal() const
Definition: multi_array.hxx:1452
allocator_type m_alloc
Definition: multi_array.hxx:2508
void minmax(T *minimum, T *maximum) const
Definition: multi_array.hxx:1712
MultiArrayView(const MultiArrayView< N, T, Stride > &other)
Definition: multi_array.hxx:786
void copy(const MultiArrayView< N, U, CN > &rhs)
Definition: multi_array.hxx:1174
BasicImage using foreign memory.
Definition: basicimageview.hxx:74
void copy(const MultiArrayView &rhs)
Definition: multi_array.hxx:1164
difference_type scanOrderIndexToCoordinate(difference_type_1 d) const
Definition: multi_array.hxx:1053
Definition: metaprogramming.hxx:105
allocator_type const & allocator() const
Definition: multi_array.hxx:2858
MultiArrayView< N, typename ExpandElementResult< T >::type, StridedArrayTag > bindElementChannel(difference_type_1 i) const
Definition: multi_array.hxx:1363
view_type::size_type size_type
Definition: multi_array.hxx:2466
FFTWComplex< R > & operator*=(FFTWComplex< R > &a, const FFTWComplex< R > &b)
multiply-assignment
Definition: fftw3.hxx:875
difference_type_1 size(difference_type_1 n) const
Definition: multi_array.hxx:1603
view_type::const_pointer const_pointer
Definition: multi_array.hxx:2454
view_type::value_type value_type
Definition: multi_array.hxx:2446
Definition: metaprogramming.hxx:112
const_traverser traverser_begin() const
Definition: multi_array.hxx:1910
Class for fixed size vectors.This class contains an array of size SIZE of the specified VALUETYPE...
Definition: accessor.hxx:940
T value_type
Definition: multi_array.hxx:667
MultiArrayShape< 2 >::type Shape2
shape type for MultiArray<2, T>
Definition: multi_shape.hxx:254
MultiArrayView< N, T, StridedArrayTag > transpose(const difference_type &permutation) const
Definition: multi_array.hxx:1541
Fundamental class template for images.
Definition: basicimage.hxx:473
bool hasData() const
Definition: multi_array.hxx:1861
pointer m_ptr
Definition: multi_array.hxx:752
~MultiArray()
Definition: multi_array.hxx:2790
difference_type_1 height() const
Definition: multi_array.hxx:1625
view_type::difference_type_1 difference_type_1
Definition: multi_array.hxx:2474
MultiArrayView & operator+=(multi_math::MultiMathOperand< Expression > const &rhs)
Definition: multi_array.hxx:959
MultiArrayShape< 1 >::type Shape1
shape type for MultiArray<1, T>
Definition: multi_shape.hxx:253
MultiArrayView & operator=(MultiArrayView< N, U, C1 > const &rhs)
Definition: multi_array.hxx:874
Standard 2D random access iterator for images that store the data in a linear array.
Definition: imageiterator.hxx:848
MultiArray(const MultiArray &rhs)
Definition: multi_array.hxx:2587
Encapsulate read access to the values an iterator points to.
Definition: accessor.hxx:269
MultiArrayView(BasicImage< T, ALLOC > const &image)
Definition: multi_array.hxx:822
bool isUnstrided(unsigned int dimension=N-1) const
Definition: multi_array.hxx:1234
Base class for, and view to, vigra::MultiArray.
Definition: multi_array.hxx:652
void transformMultiArray(...)
Transform a multi-dimensional array with a unary function or functor.
MultiArrayView & init(const U &init)
Definition: multi_array.hxx:1154
MultiArray & operator-=(multi_math::MultiMathOperand< Expression > const &rhs)
Definition: multi_array.hxx:2762
void swap(MultiArrayView &other)
Definition: multi_array.hxx:1199
void swapData(MultiArrayView rhs)
Definition: multi_array.hxx:1212
value_type * pointer
Definition: multi_array.hxx:679
FFTWComplex< R > & operator/=(FFTWComplex< R > &a, const FFTWComplex< R > &b)
divide-assignment
Definition: fftw3.hxx:884
traverser traverser_end()
Definition: multi_array.hxx:1920
MultiArrayView subarray(difference_type p, difference_type q) const
Definition: multi_array.hxx:1476
Iterator to be used when pixels are to be skipped.
Definition: imageiterator.hxx:966
Class for a single RGB value.
Definition: accessor.hxx:938
bool all() const
Definition: multi_array.hxx:1685
Encapsulate access to the values an iterator points to.
Definition: accessor.hxx:133
StridedScanOrderIterator< actual_dimension, T, T const &, T const * > const_iterator
Definition: multi_array.hxx:707
bool isOutside(difference_type const &p) const
Definition: multi_array.hxx:1674
view_type::const_iterator const_iterator
Definition: multi_array.hxx:2500
MultiArrayView & operator=(MultiArrayView const &rhs)
Definition: multi_array.hxx:855
MultiArrayView & operator*=(T const &rhs)
Definition: multi_array.hxx:931
difference_type m_stride
Definition: multi_array.hxx:748
void init(Iterator i, Iterator end)
Definition: tinyvector.hxx:708
U sum() const
Definition: multi_array.hxx:1751
const value_type * const_pointer
Definition: multi_array.hxx:683
difference_type_1 shape(difference_type_1 n) const
Definition: multi_array.hxx:1611
traverser traverser_begin()
Definition: multi_array.hxx:1901
SquareRootTraits< FixedPoint< IntBits, FracBits > >::SquareRootResult sqrt(FixedPoint< IntBits, FracBits > v)
square root.
Definition: fixedpoint.hxx:616
MultiArrayView< N, T, StridedArrayTag > stridearray(const difference_type &s) const
Definition: multi_array.hxx:1491
MultiArrayView()
Definition: multi_array.hxx:777
difference_type key_type
Definition: multi_array.hxx:691
V const & min(TinyVectorBase< V, SIZE, D1, D2 > const &l)
minimum element
Definition: tinyvector.hxx:2161
view_type::const_reference const_reference
Definition: multi_array.hxx:2462
void allocate(pointer &ptr, difference_type_1 s, const_reference init)
Definition: multi_array.hxx:3027
const_traverser traverser_end() const
Definition: multi_array.hxx:1931
difference_type strideOrdering() const
Definition: multi_array.hxx:1565