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>());
528 namespace multi_math {
531 struct MultiMathOperand;
533 namespace math_detail {
535 template <
unsigned int N,
class T,
class C,
class E>
536 void assign(MultiArrayView<N, T, C>, MultiMathOperand<E>
const &);
538 template <
unsigned int N,
class T,
class C,
class E>
539 void plusAssign(MultiArrayView<N, T, C>, MultiMathOperand<E>
const &);
541 template <
unsigned int N,
class T,
class C,
class E>
542 void minusAssign(MultiArrayView<N, T, C>, MultiMathOperand<E>
const &);
544 template <
unsigned int N,
class T,
class C,
class E>
545 void multiplyAssign(MultiArrayView<N, T, C>, MultiMathOperand<E>
const &);
547 template <
unsigned int N,
class T,
class C,
class E>
548 void divideAssign(MultiArrayView<N, T, C>, MultiMathOperand<E>
const &);
550 template <
unsigned int N,
class T,
class A,
class E>
551 void assignOrResize(MultiArray<N, T, A> &, MultiMathOperand<E>
const &);
553 template <
unsigned int N,
class T,
class A,
class E>
554 void plusAssignOrResize(MultiArray<N, T, A> &, MultiMathOperand<E>
const &);
556 template <
unsigned int N,
class T,
class A,
class E>
557 void minusAssignOrResize(MultiArray<N, T, A> &, MultiMathOperand<E>
const &);
559 template <
unsigned int N,
class T,
class A,
class E>
560 void multiplyAssignOrResize(MultiArray<N, T, A> &, MultiMathOperand<E>
const &);
562 template <
unsigned int N,
class T,
class A,
class E>
563 void divideAssignOrResize(MultiArray<N, T, A> &, MultiMathOperand<E>
const &);
569 template <
class T>
class FindSum;
571 struct UnsuitableTypeForExpandElements {};
574 struct ExpandElementResult
576 typedef UnsuitableTypeForExpandElements type;
580 struct ExpandElementResult<
std::complex<T> >
590 struct ExpandElementResult<FFTWComplex<T> >
596 template <
class T,
int SIZE>
597 struct ExpandElementResult<TinyVector<T, SIZE> >
600 enum { size = SIZE };
603 template <
class T,
unsigned int R,
unsigned int G,
unsigned int B>
604 struct ExpandElementResult<RGBValue<T, R, G, B> >
610 #define VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(TYPE) \ 612 struct ExpandElementResult<TYPE> \ 618 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
bool)
619 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
char)
620 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
signed char)
621 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
signed short)
622 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
signed int)
623 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
signed long)
624 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
signed long long)
625 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
unsigned char)
626 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
unsigned short)
627 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
unsigned int)
628 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
unsigned long)
629 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
unsigned long long)
630 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
float)
631 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
double)
632 VIGRA_DEFINE_EXPAND_ELEMENT_RESULT(
long double)
634 #undef VIGRA_DEFINE_EXPAND_ELEMENT_RESULT 643 template <
unsigned int N,
class T,
class C>
644 struct NormTraits<MultiArrayView<N, T, C> >
646 typedef MultiArrayView<N, T, C> Type;
647 typedef typename NormTraits<T>::SquaredNormType SquaredNormType;
648 typedef typename SquareRootTraits<SquaredNormType>::SquareRootResult NormType;
651 template <
unsigned int N,
class T,
class A>
652 struct NormTraits<MultiArray<N, T, A> >
653 :
public NormTraits<typename MultiArray<N, T, A>::view_type>
655 typedef NormTraits<typename MultiArray<N, T, A>::view_type> BaseType;
656 typedef MultiArray<N, T, A> Type;
657 typedef typename BaseType::SquaredNormType SquaredNormType;
658 typedef typename BaseType::NormType NormType;
703 template <
unsigned int N,
class T,
class Str
ideTag>
763 typedef typename vigra::detail::MultiIteratorChooser <
764 StrideTag>::template Traverser <actual_dimension, T, T &, T *>::type
traverser;
768 typedef typename vigra::detail::MultiIteratorChooser <
769 StrideTag>::template Traverser <actual_dimension, T, T const &, T const *>::type
const_traverser;
781 return m_stride[0] <= 1;
791 typedef typename difference_type::value_type diff_zero_t;
809 template <
class U,
class CN>
812 template <
class U,
class CN>
818 template <
class U,
class CN>
830 : m_shape (diff_zero_t(0)), m_stride (diff_zero_t(0)), m_ptr (0)
837 template <
class Str
ide>
839 : m_shape (other.shape()),
840 m_stride (other.stride()),
843 vigra_precondition(other.checkInnerStride(StrideTag()),
844 "MultiArrayView<..., UnstridedArrayTag>(MultiArrayView const &): cannot create unstrided view from strided array.");
851 m_stride (detail::defaultStride<actual_dimension>(shape)),
852 m_ptr (const_cast<pointer>(ptr))
861 const difference_type &stride,
865 m_ptr (const_cast<pointer>(ptr))
867 vigra_precondition(checkInnerStride(StrideTag()),
868 "MultiArrayView<..., UnstridedArrayTag>::MultiArrayView(): First dimension of given array is not unstrided.");
873 template <
class ALLOC>
875 : m_shape (Shape2(image.width(), image.height())),
876 m_stride (detail::defaultStride<actual_dimension>(m_shape)),
877 m_ptr (const_cast<pointer>(image.data()))
891 m_shape = diff_zero_t(0);
892 m_stride = diff_zero_t(0);
914 template<
class Str
ide2>
925 template<
class U,
class C1>
928 vigra_precondition(this->shape() == rhs.
shape(),
929 "MultiArrayView::operator=(): shape mismatch.");
944 template<
class U,
class C1>
950 template<
class U,
class C1>
956 template<
class U,
class C1>
962 template<
class U,
class C1>
969 detail::copyAddScalarMultiArrayData(traverser_begin(), shape(), rhs, MetaInt<actual_dimension-1>());
977 detail::copySubScalarMultiArrayData(traverser_begin(), shape(), rhs, MetaInt<actual_dimension-1>());
985 detail::copyMulScalarMultiArrayData(traverser_begin(), shape(), rhs, MetaInt<actual_dimension-1>());
993 detail::copyDivScalarMultiArrayData(traverser_begin(), shape(), rhs, MetaInt<actual_dimension-1>());
1000 template<
class Expression>
1003 multi_math::math_detail::assign(*
this, rhs);
1010 template<
class Expression>
1013 multi_math::math_detail::plusAssign(*
this, rhs);
1020 template<
class Expression>
1023 multi_math::math_detail::minusAssign(*
this, rhs);
1030 template<
class Expression>
1033 multi_math::math_detail::multiplyAssign(*
this, rhs);
1040 template<
class Expression>
1043 multi_math::math_detail::divideAssign(*
this, rhs);
1049 reference operator[] (
const difference_type &d)
1051 VIGRA_ASSERT_INSIDE(d);
1052 return m_ptr [
dot (d, m_stride)];
1057 const_reference operator[] (
const difference_type &d)
const 1059 VIGRA_ASSERT_INSIDE(d);
1060 return m_ptr [
dot (d, m_stride)];
1068 return bindInner(d);
1083 VIGRA_ASSERT_INSIDE(scanOrderIndexToCoordinate(d));
1084 return m_ptr [detail::ScanOrderToOffset<actual_dimension>::exec(d, m_shape, m_stride)];
1099 VIGRA_ASSERT_INSIDE(scanOrderIndexToCoordinate(d));
1100 return m_ptr [detail::ScanOrderToOffset<actual_dimension>::exec(d, m_shape, m_stride)];
1107 difference_type result;
1108 detail::ScanOrderToCoordinate<actual_dimension>::exec(d, m_shape, result);
1116 return detail::CoordinateToScanOrder<actual_dimension>::exec(m_shape, d);
1121 reference operator() (difference_type_1 x)
1123 VIGRA_ASSERT_INSIDE(difference_type(x));
1124 return m_ptr [detail::CoordinatesToOffest<StrideTag>::exec(m_stride, x)];
1129 reference operator() (difference_type_1 x, difference_type_1 y)
1131 VIGRA_ASSERT_INSIDE(difference_type(x, y));
1132 return m_ptr [detail::CoordinatesToOffest<StrideTag>::exec(m_stride, x, y)];
1137 reference operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z)
1139 VIGRA_ASSERT_INSIDE(difference_type(x, y, z));
1140 return m_ptr [m_stride[0]*x + m_stride[1]*y + m_stride[2]*z];
1145 reference operator() (difference_type_1 x, difference_type_1 y,
1146 difference_type_1 z, difference_type_1 u)
1148 VIGRA_ASSERT_INSIDE(difference_type(x, y, z, u));
1149 return m_ptr [m_stride[0]*x + m_stride[1]*y + m_stride[2]*z + m_stride[3]*u];
1154 reference operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z,
1155 difference_type_1 u, difference_type_1 v)
1157 VIGRA_ASSERT_INSIDE(difference_type(x, y,z, u,v));
1158 return m_ptr [m_stride[0]*x + m_stride[1]*y + m_stride[2]*z + m_stride[3]*u + m_stride[4]*v];
1163 const_reference operator() (difference_type_1 x)
const 1165 VIGRA_ASSERT_INSIDE(difference_type(x));
1166 return m_ptr [detail::CoordinatesToOffest<StrideTag>::exec(m_stride, x)];
1171 const_reference operator() (difference_type_1 x, difference_type_1 y)
const 1173 VIGRA_ASSERT_INSIDE(difference_type(x, y));
1174 return m_ptr [detail::CoordinatesToOffest<StrideTag>::exec(m_stride, x, y)];
1179 const_reference operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z)
const 1181 VIGRA_ASSERT_INSIDE(difference_type(x,y,z));
1182 return m_ptr [m_stride[0]*x + m_stride[1]*y + m_stride[2]*z];
1187 const_reference operator() (difference_type_1 x, difference_type_1 y,
1188 difference_type_1 z, difference_type_1 u)
const 1190 VIGRA_ASSERT_INSIDE(difference_type(x,y,z,u));
1191 return m_ptr [m_stride[0]*x + m_stride[1]*y + m_stride[2]*z + m_stride[3]*u];
1196 const_reference operator() (difference_type_1 x, difference_type_1 y, difference_type_1 z,
1197 difference_type_1 u, difference_type_1 v)
const 1199 VIGRA_ASSERT_INSIDE(difference_type(x,y,z,u,v));
1200 return m_ptr [m_stride[0]*x + m_stride[1]*y + m_stride[2]*z + m_stride[3]*u + m_stride[4]*v];
1209 detail::copyScalarMultiArrayData(traverser_begin(), shape(), init, MetaInt<actual_dimension-1>());
1220 this->copyImpl(rhs);
1225 template <
class U,
class CN>
1228 this->copyImpl(rhs);
1255 std::swap(this->m_shape, other.
m_shape);
1256 std::swap(this->m_stride, other.
m_stride);
1257 std::swap(this->m_ptr, other.
m_ptr);
1274 template <
class T2,
class C2>
1288 difference_type s = vigra::detail::defaultStride<actual_dimension>(shape());
1289 for(
unsigned int k = 0; k <= dimension; ++k)
1290 if(stride(k) != s[k])
1309 template <
int M,
class Index>
1326 template <
int M,
class Index>
1346 template <
unsigned int M>
1347 MultiArrayView <N-1, T,
typename vigra::detail::MaybeStrided<StrideTag, M>::type >
1348 bind (difference_type_1 d)
const;
1364 MultiArrayView <N-1, T, StrideTag> bindOuter (difference_type_1 d)
const;
1397 bindAt (difference_type_1 m, difference_type_1 d)
const;
1417 vigra_precondition(0 <= i && i < ExpandElementResult<T>::size,
1418 "MultiArrayView::bindElementChannel(i): 'i' out of range.");
1419 return expandElements(0).bindInner(i);
1441 expandElements(difference_type_1 d)
const;
1473 insertSingletonDimension (difference_type_1 i)
const;
1530 detail::RelativeToAbsoluteCoordinate<actual_dimension-1>::exec(shape(), p);
1531 detail::RelativeToAbsoluteCoordinate<actual_dimension-1>::exec(shape(), q);
1532 const difference_type_1 offset =
dot (m_stride, p);
1545 difference_type shape = m_shape;
1546 for (
unsigned int i = 0; i < actual_dimension; ++i)
1547 shape[i] = (shape[i] + s[i] - 1) / s[i];
1569 difference_type shape(m_shape.begin(), ReverseCopy),
1570 stride(m_stride.begin(), ReverseCopy);
1595 return permuteDimensions(permutation);
1599 permuteDimensions (
const difference_type &s)
const;
1605 permuteStridesAscending()
const;
1611 permuteStridesDescending()
const;
1619 return strideOrdering(m_stride);
1626 static difference_type strideOrdering(difference_type strides);
1632 difference_type_1 ret = m_shape[0];
1633 for(
int i = 1; i < actual_dimension; ++i)
1643 return elementCount();
1655 difference_type_1
size (difference_type_1 n)
const 1663 difference_type_1
shape (difference_type_1 n)
const 1693 return m_stride [n];
1698 template <
class U,
class C1>
1701 if(this->shape() != rhs.
shape())
1703 return detail::equalityOfMultiArrays(traverser_begin(), shape(), rhs.
traverser_begin(), MetaInt<actual_dimension-1>());
1709 template <
class U,
class C1>
1719 for(
int d=0; d<actual_dimension; ++d)
1720 if(p[d] < 0 || p[d] >= shape(d))
1728 for(
int d=0; d<actual_dimension; ++d)
1729 if(p[d] < 0 || p[d] >= shape(d))
1740 detail::reduceOverMultiArray(traverser_begin(), shape(),
1742 detail::AllTrueReduceFunctor(),
1743 MetaInt<actual_dimension-1>());
1753 detail::reduceOverMultiArray(traverser_begin(), shape(),
1755 detail::AnyTrueReduceFunctor(),
1756 MetaInt<actual_dimension-1>());
1766 std::pair<T, T> res(NumericTraits<T>::max(), NumericTraits<T>::min());
1767 detail::reduceOverMultiArray(traverser_begin(), shape(),
1769 detail::MinmaxReduceFunctor(),
1770 MetaInt<actual_dimension-1>());
1771 *minimum = res.first;
1772 *maximum = res.second;
1782 typedef typename NumericTraits<U>::RealPromote R;
1784 triple<double, R, R> res(0.0, zero, zero);
1785 detail::reduceOverMultiArray(traverser_begin(), shape(),
1787 detail::MeanVarianceReduceFunctor(),
1788 MetaInt<actual_dimension-1>());
1790 *variance = res.third / res.first;
1805 U res = NumericTraits<U>::zero();
1806 detail::reduceOverMultiArray(traverser_begin(), shape(),
1808 detail::SumReduceFunctor(),
1809 MetaInt<actual_dimension-1>());
1838 template <
class U,
class S>
1842 destMultiArrayRange(sums),
1858 U res = NumericTraits<U>::one();
1859 detail::reduceOverMultiArray(traverser_begin(), shape(),
1861 detail::ProdReduceFunctor(),
1862 MetaInt<actual_dimension-1>());
1868 typename NormTraits<MultiArrayView>::SquaredNormType
1871 typedef typename NormTraits<MultiArrayView>::SquaredNormType SquaredNormType;
1872 SquaredNormType res = NumericTraits<SquaredNormType>::zero();
1873 detail::reduceOverMultiArray(traverser_begin(), shape(),
1875 detail::SquaredL2NormReduceFunctor(),
1876 MetaInt<actual_dimension-1>());
1893 typename NormTraits<MultiArrayView>::NormType
1894 norm(
int type = 2,
bool useSquaredNorm =
true)
const;
1903 pointer & unsafePtr()
1923 return iterator(*
this);
1931 return const_iterator(*
this);
1939 return begin().getEndIterator();
1947 return begin().getEndIterator();
1955 traverser ret (m_ptr, m_stride.begin (), m_shape.begin ());
1964 const_traverser ret (m_ptr, m_stride.begin (), m_shape.begin ());
1974 traverser ret (m_ptr, m_stride.begin (), m_shape.begin ());
1975 ret += m_shape [actual_dimension-1];
1985 const_traverser ret (m_ptr, m_stride.begin (), m_shape.begin ());
1986 ret += m_shape [actual_dimension-1];
1990 view_type view ()
const 1996 template <
unsigned int N,
class T,
class Str
ideTag>
2007 template <
unsigned int N,
class T,
class Str
ide1>
2008 template <
class Str
ide2>
2014 vigra_precondition(rhs.checkInnerStride(Stride1()),
2015 "MultiArrayView<..., UnstridedArrayTag>::operator=(MultiArrayView const &): cannot create unstrided view from strided array.");
2017 m_shape = rhs.shape();
2018 m_stride = rhs.stride();
2023 vigra_precondition(this->shape() == rhs.shape(),
2024 "MultiArrayView::operator=(MultiArrayView const &): shape mismatch.");
2025 this->copyImpl(rhs);
2029 template <
unsigned int N,
class T,
class Str
ideTag>
2034 vigra_precondition (shape () == rhs.shape (),
2035 "MultiArrayView::arraysOverlap(): shape mismatch.");
2037 last_element = first_element +
dot(this->m_shape -
difference_type(1), this->m_stride);
2039 rhs_first_element = rhs.data(),
2040 rhs_last_element = rhs_first_element +
dot(rhs.shape() -
difference_type(1), rhs.stride());
2041 return !(last_element < rhs_first_element || rhs_last_element < first_element);
2044 template <
unsigned int N,
class T,
class Str
ideTag>
2045 template <
class U,
class CN>
2049 if(!arraysOverlap(rhs))
2052 detail::copyMultiArrayData(rhs.traverser_begin(), shape(), traverser_begin(), MetaInt<actual_dimension-1>());
2059 detail::copyMultiArrayData(tmp.traverser_begin(), shape(), traverser_begin(), MetaInt<actual_dimension-1>());
2063 #define VIGRA_MULTI_ARRAY_COMPUTED_ASSIGNMENT(name, op) \ 2064 template <unsigned int N, class T, class StrideTag> \ 2065 template<class U, class C1> \ 2066 MultiArrayView<N, T, StrideTag> & \ 2067 MultiArrayView <N, T, StrideTag>::operator op(MultiArrayView<N, U, C1> const & rhs) \ 2069 vigra_precondition(this->shape() == rhs.shape(), "MultiArrayView::operator" #op "() size mismatch."); \ 2070 if(!arraysOverlap(rhs)) \ 2072 detail::name##MultiArrayData(rhs.traverser_begin(), shape(), traverser_begin(), MetaInt<actual_dimension-1>()); \ 2076 MultiArray<N, T> tmp(rhs); \ 2077 detail::name##MultiArrayData(tmp.traverser_begin(), shape(), traverser_begin(), MetaInt<actual_dimension-1>()); \ 2082 VIGRA_MULTI_ARRAY_COMPUTED_ASSIGNMENT(copyAdd, +=)
2083 VIGRA_MULTI_ARRAY_COMPUTED_ASSIGNMENT(copySub, -=)
2084 VIGRA_MULTI_ARRAY_COMPUTED_ASSIGNMENT(copyMul, *=)
2085 VIGRA_MULTI_ARRAY_COMPUTED_ASSIGNMENT(copyDiv, /=)
2087 #undef VIGRA_MULTI_ARRAY_COMPUTED_ASSIGNMENT 2089 template <
unsigned int N,
class T,
class Str
ideTag>
2090 template <
class U,
class CN>
2094 vigra_precondition (shape () == rhs.shape (),
2095 "MultiArrayView::swapData(): shape mismatch.");
2099 last_element = first_element +
dot(this->m_shape -
difference_type(1), this->m_stride);
2101 rhs_first_element = rhs.data(),
2102 rhs_last_element = rhs_first_element +
dot(rhs.shape() -
difference_type(1), rhs.stride());
2103 if(last_element < rhs_first_element || rhs_last_element < first_element)
2106 detail::swapDataImpl(traverser_begin(), shape(), rhs.traverser_begin(), MetaInt<actual_dimension-1>());
2118 template <
unsigned int N,
class T,
class Str
ideTag>
2122 difference_type shape, stride, check((
typename difference_type::value_type)0);
2123 for (
unsigned int i = 0; i < actual_dimension; ++i)
2125 shape[i] = m_shape[s[i]];
2126 stride[i] = m_stride[s[i]];
2130 "MultiArrayView::transpose(): every dimension must occur exactly once.");
2134 template <
unsigned int N,
class T,
class Str
ideTag>
2139 for(
int k=0; k<(int)N; ++k)
2141 for(
int k=0; k<(int)N-1; ++k)
2144 for(
int j=k+1; j<(int)N; ++j)
2146 if(stride[j] < stride[smallest])
2151 std::swap(stride[k], stride[smallest]);
2152 std::swap(permutation[k], permutation[smallest]);
2156 for(
unsigned int k=0; k<N; ++k)
2157 ordering[permutation[k]] = k;
2161 template <
unsigned int N,
class T,
class Str
ideTag>
2167 permutation[ordering[k]] = k;
2168 return permuteDimensions(permutation);
2171 template <
unsigned int N,
class T,
class Str
ideTag>
2177 permutation[N-1-ordering[k]] = k;
2178 return permuteDimensions(permutation);
2181 template <
unsigned int N,
class T,
class Str
ideTag>
2182 template <
int M,
class Index>
2187 stride.
init (m_stride.begin () + N-M, m_stride.
end ());
2189 static const int NNew = (N-M == 0) ? 1 : N-M;
2193 inner_shape [0] = 1;
2194 inner_stride [0] = 1;
2198 inner_shape.
init (m_shape.begin (), m_shape.end () - M);
2199 inner_stride.
init (m_stride.begin (), m_stride.end () - M);
2201 return MultiArrayView <N-M, T, StrideTag> (inner_shape, inner_stride, ptr);
2204 template <
unsigned int N,
class T,
class Str
ideTag>
2205 template <
int M,
class Index>
2210 stride.
init (m_stride.begin (), m_stride.end () - N + M);
2212 static const int NNew = (N-M == 0) ? 1 : N-M;
2216 outer_shape [0] = 1;
2217 outer_stride [0] = 1;
2221 outer_shape.
init (m_shape.begin () + M, m_shape.end ());
2222 outer_stride.
init (m_stride.begin () + M, m_stride.end ());
2225 (outer_shape, outer_stride, ptr);
2228 template <
unsigned int N,
class T,
class Str
ideTag>
2229 template <
unsigned int M>
2230 MultiArrayView <N-1, T,
typename detail::MaybeStrided<StrideTag, M>::type >
2233 static const int NNew = (N-1 == 0) ? 1 : N-1;
2243 std::copy (m_shape.begin (), m_shape.begin () + M, shape.
begin ());
2244 std::copy (m_shape.begin () + M+1, m_shape.end (),
2245 shape.
begin () + M);
2246 std::copy (m_stride.begin (), m_stride.begin () + M, stride.
begin ());
2247 std::copy (m_stride.begin () + M+1, m_stride.end (),
2248 stride.
begin () + M);
2250 return MultiArrayView <N-1, T,
typename detail::MaybeStrided<StrideTag, M>::type>
2251 (shape, stride, m_ptr + d * m_stride[M]);
2254 template <
unsigned int N,
class T,
class Str
ideTag>
2258 static const int NNew = (N-1 == 0) ? 1 : N-1;
2262 inner_shape [0] = 1;
2263 inner_stride [0] = 1;
2267 inner_shape.
init (m_shape.begin (), m_shape.end () - 1);
2268 inner_stride.
init (m_stride.begin (), m_stride.end () - 1);
2270 return MultiArrayView <N-1, T, StrideTag> (inner_shape, inner_stride,
2271 m_ptr + d * m_stride [N-1]);
2274 template <
unsigned int N,
class T,
class Str
ideTag>
2278 static const int NNew = (N-1 == 0) ? 1 : N-1;
2282 outer_shape [0] = 1;
2283 outer_stride [0] = 1;
2287 outer_shape.
init (m_shape.begin () + 1, m_shape.end ());
2288 outer_stride.
init (m_stride.begin () + 1, m_stride.end ());
2291 (outer_shape, outer_stride, m_ptr + d * m_stride [0]);
2294 template <
unsigned int N,
class T,
class Str
ideTag>
2298 vigra_precondition (
2299 n < static_cast <int> (N),
2300 "MultiArrayView <N, T, StrideTag>::bindAt(): dimension out of range.");
2301 static const int NNew = (N-1 == 0) ? 1 : N-1;
2311 std::copy (m_shape.begin (), m_shape.begin () + n, shape.
begin ());
2312 std::copy (m_shape.begin () + n+1, m_shape.
end (),
2313 shape.
begin () + n);
2314 std::copy (m_stride.begin (), m_stride.begin () + n, stride.
begin ());
2315 std::copy (m_stride.begin () + n+1, m_stride.
end (),
2316 stride.
begin () + n);
2319 (shape, stride, m_ptr + d * m_stride[n]);
2323 template <
unsigned int N,
class T,
class Str
ideTag>
2327 vigra_precondition(0 <= d && d <= static_cast <difference_type_1> (N),
2328 "MultiArrayView<N, ...>::expandElements(d): 0 <= 'd' <= N required.");
2330 int elementSize = ExpandElementResult<T>::size;
2332 for(
int k=0; k<d; ++k)
2334 newShape[k] = m_shape[k];
2335 newStrides[k] = m_stride[k]*elementSize;
2338 newShape[d] = elementSize;
2341 for(
unsigned k=d; k<N; ++k)
2343 newShape[k+1] = m_shape[k];
2344 newStrides[k+1] = m_stride[k]*elementSize;
2347 typedef typename ExpandElementResult<T>::type U;
2349 newShape, newStrides,
reinterpret_cast<U*
>(m_ptr));
2352 template <
unsigned int N,
class T,
class Str
ideTag>
2356 vigra_precondition (
2357 0 <= i && i <= static_cast <difference_type_1> (N),
2358 "MultiArrayView <N, T, StrideTag>::insertSingletonDimension(): index out of range.");
2360 std::copy (m_shape.begin (), m_shape.begin () + i, shape.
begin ());
2361 std::copy (m_shape.begin () + i, m_shape.end (), shape.
begin () + i + 1);
2362 std::copy (m_stride.begin (), m_stride.begin () + i, stride.
begin ());
2363 std::copy (m_stride.begin () + i, m_stride.end (), stride.
begin () + i + 1);
2370 template <
unsigned int N,
class T,
class Str
ideTag>
2371 typename NormTraits<MultiArrayView <N, T, StrideTag> >::NormType
2374 typedef typename NormTraits<MultiArrayView>::NormType NormType;
2380 NormType res = NumericTraits<NormType>::zero();
2381 detail::reduceOverMultiArray(traverser_begin(), shape(),
2383 detail::MaxNormReduceFunctor(),
2384 MetaInt<actual_dimension-1>());
2389 NormType res = NumericTraits<NormType>::zero();
2390 detail::reduceOverMultiArray(traverser_begin(), shape(),
2392 detail::L1NormReduceFunctor(),
2393 MetaInt<actual_dimension-1>());
2404 NormType normMax = NumericTraits<NormType>::zero();
2405 detail::reduceOverMultiArray(traverser_begin(), shape(),
2407 detail::MaxNormReduceFunctor(),
2408 MetaInt<actual_dimension-1>());
2409 if(normMax == NumericTraits<NormType>::zero())
2411 NormType res = NumericTraits<NormType>::zero();
2412 detail::reduceOverMultiArray(traverser_begin(), shape(),
2414 detail::WeightedL2NormReduceFunctor<NormType>(1.0/normMax),
2415 MetaInt<actual_dimension-1>());
2416 return sqrt(res)*normMax;
2420 vigra_precondition(
false,
"MultiArrayView::norm(): Unknown norm type.");
2421 return NumericTraits<NormType>::zero();
2432 template <
unsigned int N,
class T,
class Str
ideTag>
2433 inline typename NormTraits<MultiArrayView <N, T, StrideTag> >::SquaredNormType
2439 template <
unsigned int N,
class T,
class Str
ideTag>
2440 inline typename NormTraits<MultiArrayView <N, T, StrideTag> >::NormType
2473 template <
unsigned int N,
class T,
class A >
2475 :
public MultiArrayView <N, typename vigra::detail::ResolveMultiband<T>::type,
2476 typename vigra::detail::ResolveMultiband<T>::Stride>
2486 using view_type::actual_dimension;
2556 typedef typename difference_type::value_type diff_zero_t;
2565 void allocate (pointer &ptr, difference_type_1 s, const_reference init);
2571 void allocate (pointer &ptr, difference_type_1 s, U
const * init);
2576 template <
class U,
class Str
ideTag>
2581 void deallocate (pointer &ptr, difference_type_1 s);
2583 template <
class U,
class Str
ideTag>
2589 : view_type (difference_type (diff_zero_t(0)),
2590 difference_type (diff_zero_t(0)), 0)
2596 : view_type(difference_type (diff_zero_t(0)),
2597 difference_type (diff_zero_t(0)), 0),
2605 explicit MultiArray (difference_type_1 length,
2606 allocator_type
const & alloc = allocator_type());
2613 MultiArray (difference_type_1 width, difference_type_1 height,
2614 allocator_type
const & alloc = allocator_type());
2618 explicit MultiArray (
const difference_type &shape,
2619 allocator_type
const & alloc = allocator_type());
2623 MultiArray (
const difference_type &shape, const_reference init,
2624 allocator_type
const & alloc = allocator_type());
2630 allocator_type
const & alloc = allocator_type());
2634 MultiArray (
const difference_type &shape, const_pointer init,
2635 allocator_type
const & alloc = allocator_type());
2640 : view_type(rhs.m_shape, rhs.m_stride, 0),
2641 m_alloc (rhs.m_alloc)
2643 allocate (this->m_ptr, this->elementCount (), rhs.data ());
2648 template<
class Expression>
2649 MultiArray (multi_math::MultiMathOperand<Expression>
const & rhs,
2650 allocator_type
const & alloc = allocator_type())
2651 : view_type(difference_type (diff_zero_t(0)),
2652 difference_type (diff_zero_t(0)), 0),
2655 multi_math::math_detail::assignOrResize(*
this, rhs);
2660 template <
class U,
class Str
ideTag>
2662 allocator_type
const & alloc = allocator_type());
2669 MultiArray & operator= (
const MultiArray &rhs)
2672 this->copyOrReshape(rhs);
2681 template <
class U,
class Str
ideTag>
2684 this->copyOrReshape(rhs);
2693 return this->init(v);
2702 template <
class U,
class Str
ideTag>
2718 template <
class U,
class Str
ideTag>
2721 if(!this->hasData())
2722 this->reshape(rhs.
shape());
2733 template <
class U,
class Str
ideTag>
2739 this->reshape(rhs.
shape());
2749 template <
class U,
class Str
ideTag>
2755 this->reshape(rhs.
shape());
2793 template<
class Expression>
2794 MultiArray &
operator=(multi_math::MultiMathOperand<Expression>
const & rhs)
2796 multi_math::math_detail::assignOrResize(*
this, rhs);
2803 template<
class Expression>
2804 MultiArray &
operator+=(multi_math::MultiMathOperand<Expression>
const & rhs)
2806 multi_math::math_detail::plusAssignOrResize(*
this, rhs);
2813 template<
class Expression>
2814 MultiArray &
operator-=(multi_math::MultiMathOperand<Expression>
const & rhs)
2816 multi_math::math_detail::minusAssignOrResize(*
this, rhs);
2823 template<
class Expression>
2824 MultiArray &
operator*=(multi_math::MultiMathOperand<Expression>
const & rhs)
2826 multi_math::math_detail::multiplyAssignOrResize(*
this, rhs);
2833 template<
class Expression>
2834 MultiArray &
operator/=(multi_math::MultiMathOperand<Expression>
const & rhs)
2836 multi_math::math_detail::divideAssignOrResize(*
this, rhs);
2844 deallocate (this->m_ptr, this->elementCount ());
2853 view_type::init(init);
2863 reshape (shape, value_type());
2871 void reshape (
const difference_type &shape, const_reference init);
2878 void swap (MultiArray & other);
2915 static difference_type defaultStride(difference_type
const & shape)
2917 return vigra::detail::ResolveMultiband<T>::defaultStride(shape);
2921 template <
unsigned int N,
class T,
class A>
2923 allocator_type
const & alloc)
2924 : view_type(difference_type(length),
2925 defaultStride(difference_type(length)),
2929 allocate (this->m_ptr, this->elementCount (), value_type());
2932 template <
unsigned int N,
class T,
class A>
2934 allocator_type
const & alloc)
2935 : view_type(difference_type(width, height),
2936 defaultStride(difference_type(width, height)),
2940 allocate (this->m_ptr, this->elementCount (), value_type());
2943 template <
unsigned int N,
class T,
class A>
2945 allocator_type
const & alloc)
2947 defaultStride(shape),
2953 this->m_shape [0] = 1;
2954 this->m_stride [0] = 1;
2956 allocate (this->m_ptr, this->elementCount (), value_type());
2959 template <
unsigned int N,
class T,
class A>
2961 allocator_type
const & alloc)
2963 defaultStride(shape),
2969 this->m_shape [0] = 1;
2970 this->m_stride [0] = 1;
2972 allocate (this->m_ptr, this->elementCount (), init);
2975 template <
unsigned int N,
class T,
class A>
2977 allocator_type
const & alloc)
2979 defaultStride(shape),
2985 this->m_shape [0] = 1;
2986 this->m_stride [0] = 1;
2988 allocate (this->m_ptr, this->elementCount (), value_type());
2995 vigra_precondition(
false,
2996 "MultiArray(): invalid MultiArrayInitializationTag.");
3000 template <
unsigned int N,
class T,
class A>
3002 allocator_type
const & alloc)
3004 defaultStride(shape),
3010 this->m_shape [0] = 1;
3011 this->m_stride [0] = 1;
3013 allocate (this->m_ptr, this->elementCount (), init);
3016 template <
unsigned int N,
class T,
class A>
3017 template <
class U,
class Str
ideTag>
3019 allocator_type
const & alloc)
3020 : view_type(rhs.shape(),
3021 defaultStride(rhs.shape()),
3025 allocate (this->m_ptr, rhs);
3028 template <
unsigned int N,
class T,
class A>
3029 template <
class U,
class Str
ideTag>
3033 if (this->shape() == rhs.shape())
3042 template <
unsigned int N,
class T,
class A>
3044 const_reference initial)
3050 else if(new_shape == this->shape())
3052 this->init(initial);
3056 difference_type new_stride = defaultStride(new_shape);
3057 difference_type_1 new_size =
prod(new_shape);
3058 pointer new_ptr = pointer();
3059 allocate (new_ptr, new_size, initial);
3060 deallocate (this->m_ptr, this->elementCount ());
3061 this->m_ptr = new_ptr;
3062 this->m_shape = new_shape;
3063 this->m_stride = new_stride;
3068 template <
unsigned int N,
class T,
class A>
3074 this->view_type::swap(other);
3075 std::swap(this->m_alloc, other.m_alloc);
3078 template <
unsigned int N,
class T,
class A>
3080 const_reference init)
3087 ptr = m_alloc.
allocate ((
typename A::size_type)s);
3088 difference_type_1 i = 0;
3091 m_alloc.construct (ptr + i, init);
3094 for (difference_type_1 j = 0; j < i; ++j)
3095 m_alloc.destroy (ptr + j);
3096 m_alloc.deallocate (ptr, (
typename A::size_type)s);
3101 template <
unsigned int N,
class T,
class A>
3111 ptr = m_alloc.
allocate ((
typename A::size_type)s);
3112 difference_type_1 i = 0;
3114 for (; i < s; ++i, ++init)
3115 m_alloc.construct (ptr + i, *init);
3118 for (difference_type_1 j = 0; j < i; ++j)
3119 m_alloc.destroy (ptr + j);
3120 m_alloc.deallocate (ptr, (
typename A::size_type)s);
3125 template <
unsigned int N,
class T,
class A>
3126 template <
class U,
class Str
ideTag>
3129 difference_type_1 s = init.elementCount();
3135 ptr = m_alloc.
allocate ((
typename A::size_type)s);
3138 detail::uninitializedCopyMultiArrayData(init.traverser_begin(), init.shape(),
3139 p, m_alloc, MetaInt<actual_dimension-1>());
3142 for (pointer pp = ptr; pp < p; ++pp)
3143 m_alloc.destroy (pp);
3144 m_alloc.deallocate (ptr, (
typename A::size_type)s);
3149 template <
unsigned int N,
class T,
class A>
3154 for (difference_type_1 i = 0; i < s; ++i)
3155 m_alloc.destroy (ptr + i);
3156 m_alloc.
deallocate (ptr, (
typename A::size_type)s);
3166 template <
unsigned int N,
class T,
class Str
ideTag>
3167 inline triple<typename MultiArrayView<N,T,StrideTag>::const_traverser,
3172 return triple<typename MultiArrayView<N,T,StrideTag>::const_traverser,
3173 typename MultiArrayView<N,T,StrideTag>::difference_type,
3180 template <
unsigned int N,
class T,
class Str
ideTag,
class Accessor>
3181 inline triple<typename MultiArrayView<N,T,StrideTag>::const_traverser,
3182 typename MultiArrayView<N,T,StrideTag>::difference_type,
3186 return triple<typename MultiArrayView<N,T,StrideTag>::const_traverser,
3187 typename MultiArrayView<N,T,StrideTag>::difference_type,
3194 template <
unsigned int N,
class T,
class Str
ideTag>
3195 inline pair<typename MultiArrayView<N,T,StrideTag>::const_traverser,
3199 return pair<typename MultiArrayView<N,T,StrideTag>::const_traverser,
3205 template <
unsigned int N,
class T,
class Str
ideTag,
class Accessor>
3206 inline pair<typename MultiArrayView<N,T,StrideTag>::const_traverser,
3210 return pair<typename MultiArrayView<N,T,StrideTag>::const_traverser,
3215 template <
unsigned int N,
class T,
class Str
ideTag>
3216 inline triple<typename MultiArrayView<N,T,StrideTag>::traverser,
3217 typename MultiArrayView<N,T,StrideTag>::difference_type,
3221 return triple<typename MultiArrayView<N,T,StrideTag>::traverser,
3222 typename MultiArrayView<N,T,StrideTag>::difference_type,
3229 template <
unsigned int N,
class T,
class Str
ideTag,
class Accessor>
3230 inline triple<typename MultiArrayView<N,T,StrideTag>::traverser,
3231 typename MultiArrayView<N,T,StrideTag>::difference_type,
3235 return triple<typename MultiArrayView<N,T,StrideTag>::traverser,
3236 typename MultiArrayView<N,T,StrideTag>::difference_type,
3243 template <
unsigned int N,
class T,
class Str
ideTag>
3244 inline pair<typename MultiArrayView<N,T,StrideTag>::traverser,
3248 return pair<typename MultiArrayView<N,T,StrideTag>::traverser,
3254 template <
unsigned int N,
class T,
class Str
ideTag,
class Accessor>
3255 inline pair<typename MultiArrayView<N,T,StrideTag>::traverser,
3259 return pair<typename MultiArrayView<N,T,StrideTag>::traverser,
3266 template <
class PixelType,
class Accessor>
3267 inline triple<ConstStridedImageIterator<PixelType>,
3271 ConstStridedImageIterator<PixelType>
3273 return triple<ConstStridedImageIterator<PixelType>,
3274 ConstStridedImageIterator<PixelType>,
3279 template <
class PixelType,
class Accessor>
3280 inline pair<ConstStridedImageIterator<PixelType>, Accessor>
3283 ConstStridedImageIterator<PixelType>
3285 return pair<ConstStridedImageIterator<PixelType>, Accessor>
3289 template <
class PixelType,
class Accessor>
3290 inline triple<StridedImageIterator<PixelType>,
3294 StridedImageIterator<PixelType>
3296 return triple<StridedImageIterator<PixelType>,
3297 StridedImageIterator<PixelType>,
3302 template <
class PixelType,
class Accessor>
3303 inline pair<StridedImageIterator<PixelType>, Accessor>
3306 StridedImageIterator<PixelType>
3308 return pair<StridedImageIterator<PixelType>, Accessor>
3312 template <
class PixelType,
class Accessor>
3313 inline pair<StridedImageIterator<PixelType>, Accessor>
3316 StridedImageIterator<PixelType>
3318 return pair<StridedImageIterator<PixelType>, Accessor>
3324 template <
class PixelType>
3325 inline triple<ConstStridedImageIterator<PixelType>,
3326 ConstStridedImageIterator<PixelType>,
3330 ConstStridedImageIterator<PixelType>
3333 return triple<ConstStridedImageIterator<PixelType>,
3334 ConstStridedImageIterator<PixelType>,
3339 template <
class PixelType>
3340 inline triple<ConstImageIterator<PixelType>,
3345 ConstImageIterator<PixelType>
3348 return triple<ConstImageIterator<PixelType>,
3349 ConstImageIterator<PixelType>,
3354 template <
class PixelType>
3355 inline pair< ConstStridedImageIterator<PixelType>,
3359 ConstStridedImageIterator<PixelType>
3362 return pair<ConstStridedImageIterator<PixelType>,
3367 template <
class PixelType>
3368 inline pair< ConstImageIterator<PixelType>,
3372 ConstImageIterator<PixelType>
3375 return pair<ConstImageIterator<PixelType>,
3380 template <
class PixelType>
3381 inline triple< StridedImageIterator<PixelType>,
3382 StridedImageIterator<PixelType>,
3386 StridedImageIterator<PixelType>
3389 return triple<StridedImageIterator<PixelType>,
3390 StridedImageIterator<PixelType>,
3395 template <
class PixelType>
3396 inline triple< ImageIterator<PixelType>,
3401 ImageIterator<PixelType>
3404 return triple<ImageIterator<PixelType>,
3405 ImageIterator<PixelType>,
3410 template <
class PixelType>
3411 inline pair< StridedImageIterator<PixelType>,
3415 StridedImageIterator<PixelType>
3418 return pair<StridedImageIterator<PixelType>, Accessor>
3422 template <
class PixelType>
3423 inline pair< ImageIterator<PixelType>,
3427 ImageIterator<PixelType> ul(img.
data(), img.
stride(1));
3429 return pair<ImageIterator<PixelType>, Accessor>(ul, Accessor());
3432 template <
class PixelType>
3433 inline pair< ConstStridedImageIterator<PixelType>,
3437 ConstStridedImageIterator<PixelType>
3440 return pair<ConstStridedImageIterator<PixelType>, Accessor>
3444 template <
class PixelType>
3445 inline pair< ConstImageIterator<PixelType>,
3449 ConstImageIterator<PixelType>
3452 return pair<ConstImageIterator<PixelType>, Accessor>
3474 template <
class T,
class Str
ide>
3479 "makeBasicImageView(array): array must be unstrided along x (i.e. array.isUnstrided(0) == true).");
3496 vigra_precondition(array.stride(1) == array.shape(0),
3497 "makeBasicImageView(): cannot join strided dimensions");
3499 array.shape (0)*array.shape (1), array.shape (2), array.stride(2));
3510 template <
class T,
class Str
ide>
3514 vigra_precondition(array.
shape (0) == 3,
3515 "makeRGBImageView(): array.shape(0) must be 3.");
3517 "makeRGBImageView(array): array must be unstrided (i.e. array.isUnstrided() == true).");
3527 #undef VIGRA_ASSERT_INSIDE 3529 #endif // VIGRA_MULTI_ARRAY_HXX MultiArray & operator/=(multi_math::MultiMathOperand< Expression > const &rhs)
Definition: multi_array.hxx:2834
MultiArrayView< N, typename vigra::detail::ResolveMultiband< T >::type, typename vigra::detail::ResolveMultiband< T >::Stride > view_type
Definition: multi_array.hxx:2484
const value_type & const_reference
Definition: multi_array.hxx:727
MultiArrayView(const difference_type &shape, const difference_type &stride, const_pointer ptr)
Definition: multi_array.hxx:860
MultiArray & operator=(multi_math::MultiMathOperand< Expression > const &rhs)
Definition: multi_array.hxx:2794
MultiArrayView & operator=(multi_math::MultiMathOperand< Expression > const &rhs)
Definition: multi_array.hxx:1001
iterator end()
Definition: multi_array.hxx:1937
Sequential iterator for MultiArrayView.
Definition: multi_fwd.hxx:161
MultiArrayView & operator+=(T const &rhs)
Definition: multi_array.hxx:967
const_traverser traverser_end() const
Definition: multi_array.hxx:1983
MultiArray< N, T > matrix_type
Definition: multi_array.hxx:777
MultiArray< N, T, A > matrix_type
Definition: multi_array.hxx:2494
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
const_iterator end() const
Definition: multi_array.hxx:1945
const_reference operator[](difference_type_1 d) const
Definition: multi_array.hxx:1097
view_type::pointer pointer
Definition: multi_array.hxx:2502
MultiArrayShape< actual_dimension >::type difference_type
Definition: multi_array.hxx:739
difference_type_1 coordinateToScanOrderIndex(const difference_type &d) const
Definition: multi_array.hxx:1114
MultiArrayView & operator=(value_type const &v)
Definition: multi_array.hxx:936
const_traverser traverser_begin() const
Definition: multi_array.hxx:1962
MultiArray & operator+=(multi_math::MultiMathOperand< Expression > const &rhs)
Definition: multi_array.hxx:2804
MultiArray()
Definition: multi_array.hxx:2588
bool isInside(difference_type const &p) const
Definition: multi_array.hxx:1717
ActualDimension
Definition: multi_array.hxx:715
MultiArrayView< N, T, StrideTag > view_type
Definition: multi_array.hxx:773
const difference_type & stride() const
Definition: multi_array.hxx:1684
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:795
MultiArray(allocator_type const &alloc)
Definition: multi_array.hxx:2595
MultiArray & operator=(value_type const &v)
Definition: multi_array.hxx:2691
A allocator_type
Definition: multi_array.hxx:2490
view_type::iterator iterator
Definition: multi_array.hxx:2548
difference_type strideOrdering() const
Definition: multi_array.hxx:1617
reference operator[](difference_type_1 d)
Definition: multi_array.hxx:1081
MultiArrayView & operator-=(T const &rhs)
Definition: multi_array.hxx:975
difference_type size_type
Definition: multi_array.hxx:747
difference_type_1 stride(int n) const
Definition: multi_array.hxx:1691
bool operator==(MultiArrayView< N, U, C1 > const &rhs) const
Definition: multi_array.hxx:1699
bool isOutside(difference_type const &p) const
Definition: multi_array.hxx:1726
MultiArrayView & operator*=(multi_math::MultiMathOperand< Expression > const &rhs)
Definition: multi_array.hxx:1031
void deallocate(pointer &ptr, difference_type_1 s)
Definition: multi_array.hxx:3150
Definition: array_vector.hxx:954
FFTWComplex< R >::SquaredNormType squaredNorm(const FFTWComplex< R > &a)
squared norm (= squared magnitude)
Definition: fftw3.hxx:1044
allocator_type const & allocator() const
Definition: multi_array.hxx:2910
iterator begin()
Definition: multi_array.hxx:1921
bool hasData() const
Definition: multi_array.hxx:1913
MultiArrayView & operator/=(T const &rhs)
Definition: multi_array.hxx:991
void reshape(const difference_type &shape)
Definition: multi_array.hxx:2861
view_type::traverser traverser
Definition: multi_array.hxx:2530
bool isUnstrided(unsigned int dimension=N-1) const
Definition: multi_array.hxx:1286
MultiArrayView subarray(difference_type p, difference_type q) const
Definition: multi_array.hxx:1528
bool any() const
Definition: multi_array.hxx:1750
Initialize array by a linear sequence in scan order.
Definition: multi_fwd.hxx:105
void minmax(T *minimum, T *maximum) const
Definition: multi_array.hxx:1764
void reset()
Definition: multi_array.hxx:890
difference_type_1 size() const
Definition: multi_array.hxx:1641
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:3512
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
difference_type_1 shape(difference_type_1 n) const
Definition: multi_array.hxx:1663
MultiArrayView(const difference_type &shape, const_pointer ptr)
Definition: multi_array.hxx:849
MultiArrayView< N, T, StridedArrayTag > transpose() const
Definition: multi_array.hxx:1567
StridedScanOrderIterator< actual_dimension, T, T &, T * > iterator
Definition: multi_array.hxx:755
vigra::detail::MultiIteratorChooser< StrideTag >::template Traverser< actual_dimension, T, T const &, T const * >::type const_traverser
Definition: multi_array.hxx:769
MultiArrayView & operator/=(multi_math::MultiMathOperand< Expression > const &rhs)
Definition: multi_array.hxx:1041
view_type::difference_type difference_type
Definition: multi_array.hxx:2522
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:2649
Two dimensional size object.
Definition: diff2d.hxx:482
view_type::const_traverser const_traverser
Definition: multi_array.hxx:2534
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:764
MultiArrayView< N, T, StridedArrayTag > stridearray(const difference_type &s) const
Definition: multi_array.hxx:1543
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:1275
Definition: multi_fwd.hxx:63
void meanVariance(U *mean, U *variance) const
Definition: multi_array.hxx:1780
view_type::reference reference
Definition: multi_array.hxx:2510
NumericTraits< V >::Promote prod(TinyVectorBase< V, SIZE, D1, D2 > const &l)
product of the vector's elements
Definition: tinyvector.hxx:2097
bool all() const
Definition: multi_array.hxx:1737
BasicImageView< T > makeBasicImageView(MultiArrayView< 2, T, Stride > const &array)
Definition: multi_array.hxx:3476
MultiArrayIndex difference_type_1
Definition: multi_array.hxx:751
const difference_type & shape() const
Definition: multi_array.hxx:1648
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:2824
value_type & reference
Definition: multi_array.hxx:723
MultiArrayView & operator-=(multi_math::MultiMathOperand< Expression > const &rhs)
Definition: multi_array.hxx:1021
iterator begin()
Definition: tinyvector.hxx:861
bool operator==(FFTWComplex< R > const &a, const FFTWComplex< R > &b)
equal
Definition: fftw3.hxx:825
MultiArray & init(const U &init)
Definition: multi_array.hxx:2851
allocator_type m_alloc
Definition: multi_array.hxx:2560
MultiArrayView(const MultiArrayView< N, T, Stride > &other)
Definition: multi_array.hxx:838
U sum() const
Definition: multi_array.hxx:1803
void copy(const MultiArrayView< N, U, CN > &rhs)
Definition: multi_array.hxx:1226
BasicImage using foreign memory.
Definition: basicimageview.hxx:76
void copy(const MultiArrayView &rhs)
Definition: multi_array.hxx:1216
Definition: metaprogramming.hxx:116
view_type::size_type size_type
Definition: multi_array.hxx:2518
FFTWComplex< R > & operator*=(FFTWComplex< R > &a, const FFTWComplex< R > &b)
multiply-assignment
Definition: fftw3.hxx:875
MultiArrayView< N, typename ExpandElementResult< T >::type, StridedArrayTag > bindElementChannel(difference_type_1 i) const
Definition: multi_array.hxx:1415
view_type::const_pointer const_pointer
Definition: multi_array.hxx:2506
view_type::value_type value_type
Definition: multi_array.hxx:2498
Definition: metaprogramming.hxx:123
MultiArrayView< 1, T, StridedArrayTag > diagonal() const
Definition: multi_array.hxx:1504
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:719
U product() const
Definition: multi_array.hxx:1856
NormTraits< MultiArrayView >::NormType norm(int type=2, bool useSquaredNorm=true) const
Definition: multi_array.hxx:2372
difference_type_1 elementCount() const
Definition: multi_array.hxx:1630
Fundamental class template for images.
Definition: basicimage.hxx:475
void sum(MultiArrayView< N, U, S > sums) const
Definition: multi_array.hxx:1839
pointer m_ptr
Definition: multi_array.hxx:804
~MultiArray()
Definition: multi_array.hxx:2842
view_type::difference_type_1 difference_type_1
Definition: multi_array.hxx:2526
MultiArrayView & operator+=(multi_math::MultiMathOperand< Expression > const &rhs)
Definition: multi_array.hxx:1011
MultiArrayView & operator=(MultiArrayView< N, U, C1 > const &rhs)
Definition: multi_array.hxx:926
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:2639
Encapsulate read access to the values an iterator points to.
Definition: accessor.hxx:269
MultiArrayView< N, T, StridedArrayTag > transpose(const difference_type &permutation) const
Definition: multi_array.hxx:1593
MultiArrayView(BasicImage< T, ALLOC > const &image)
Definition: multi_array.hxx:874
difference_type_1 width() const
Definition: multi_array.hxx:1670
Base class for, and view to, vigra::MultiArray.
Definition: multi_array.hxx:704
bool operator!=(MultiArrayView< N, U, C1 > const &rhs) const
Definition: multi_array.hxx:1710
void transformMultiArray(...)
Transform a multi-dimensional array with a unary function or functor.
difference_type scanOrderIndexToCoordinate(difference_type_1 d) const
Definition: multi_array.hxx:1105
MultiArrayView & init(const U &init)
Definition: multi_array.hxx:1206
const_iterator begin() const
Definition: multi_array.hxx:1929
MultiArray & operator-=(multi_math::MultiMathOperand< Expression > const &rhs)
Definition: multi_array.hxx:2814
void swap(MultiArrayView &other)
Definition: multi_array.hxx:1251
void swapData(MultiArrayView rhs)
Definition: multi_array.hxx:1264
value_type * pointer
Definition: multi_array.hxx:731
FFTWComplex< R > & operator/=(FFTWComplex< R > &a, const FFTWComplex< R > &b)
divide-assignment
Definition: fftw3.hxx:884
traverser traverser_end()
Definition: multi_array.hxx:1972
Iterator to be used when pixels are to be skipped.
Definition: imageiterator.hxx:966
Class for a single RGB value.
Definition: accessor.hxx:938
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:759
view_type::const_iterator const_iterator
Definition: multi_array.hxx:2552
MultiArrayView & operator=(MultiArrayView const &rhs)
Definition: multi_array.hxx:907
MultiArrayView & operator*=(T const &rhs)
Definition: multi_array.hxx:983
difference_type m_stride
Definition: multi_array.hxx:800
void init(Iterator i, Iterator end)
Definition: tinyvector.hxx:708
pointer data() const
Definition: multi_array.hxx:1898
const value_type * const_pointer
Definition: multi_array.hxx:735
difference_type_1 size(difference_type_1 n) const
Definition: multi_array.hxx:1655
traverser traverser_begin()
Definition: multi_array.hxx:1953
SquareRootTraits< FixedPoint< IntBits, FracBits > >::SquareRootResult sqrt(FixedPoint< IntBits, FracBits > v)
square root.
Definition: fixedpoint.hxx:616
MultiArrayView< N, Multiband< value_type >, StrideTag > multiband() const
Definition: multi_array.hxx:1483
MultiArrayView()
Definition: multi_array.hxx:829
difference_type key_type
Definition: multi_array.hxx:743
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:2514
void allocate(pointer &ptr, difference_type_1 s, const_reference init)
Definition: multi_array.hxx:3079
NormTraits< MultiArrayView >::SquaredNormType squaredNorm() const
Definition: multi_array.hxx:1869
difference_type_1 height() const
Definition: multi_array.hxx:1677