18 #ifndef itkVariableLengthVector_h 19 #define itkVariableLengthVector_h 35 template <
typename TExpr1,
typename TExpr2,
typename TBinaryOp>
92 template<
typename TValue >
129 bool operator()(
unsigned int itkNotUsed(newSize),
unsigned int itkNotUsed(oldSize)) const ITK_NOEXCEPT
156 bool operator()(
unsigned int newSize,
unsigned int oldSize)
const ITK_NOEXCEPT
160 itkAssertInDebugAndIgnoreInReleaseMacro(newSize == oldSize &&
"SetSize is expected to never change the VariableLengthVector size...");
185 bool operator()(
unsigned int newSize,
unsigned int oldSize)
const ITK_NOEXCEPT
186 {
return newSize != oldSize; }
218 bool operator()(
unsigned int newSize,
unsigned int oldSize)
const ITK_NOEXCEPT
219 {
return newSize > oldSize; }
266 template <
typename TValue2>
268 unsigned int newSize,
unsigned int oldSize,
269 TValue2 * oldBuffer, TValue2 * newBuffer)
const ITK_NOEXCEPT
271 itkAssertInDebugAndIgnoreInReleaseMacro(newBuffer);
272 const std::size_t nb = std::min(newSize, oldSize);
273 itkAssertInDebugAndIgnoreInReleaseMacro(nb == 0 || (nb > 0 && oldBuffer != ITK_NULLPTR));
274 std::copy(oldBuffer, oldBuffer+nb, newBuffer);
297 template <
typename TValue2>
299 unsigned int itkNotUsed(newSize),
unsigned int itkNotUsed(oldSize),
300 TValue2 * itkNotUsed(oldBuffer), TValue2 * itkNotUsed(newBuffer)) const ITK_NOEXCEPT
349 bool LetArrayManageMemory =
false);
371 bool LetArrayManageMemory =
false);
392 template<
typename T >
400 itkAssertInDebugAndIgnoreInReleaseMacro(
m_Data != ITK_NULLPTR);
403 this->
m_Data[i] =
static_cast< ValueType
>( v[i] );
431 void Swap(Self & v) ITK_NOEXCEPT
440 #if defined(ITK_HAS_CXX11_RVREF) 458 Self &
operator=(Self && v) ITK_NOEXCEPT;
477 template <
typename TExpr1,
typename TExpr2,
typename TBinaryOp>
499 template <
typename TExpr1,
typename TExpr2,
typename TBinaryOp>
505 void Fill(TValue
const & v) ITK_NOEXCEPT;
519 template<
typename T >
529 ElementIdentifier
const N = v.
Size();
531 for ( ElementIdentifier i = 0; i < N; ++i )
533 this->
m_Data[i] =
static_cast< ValueType
>( v[i] );
564 Self &
FastAssign(
const Self & v) ITK_NOEXCEPT;
573 Self &
operator=(TValue
const & v) ITK_NOEXCEPT;
626 template <
typename TReallocatePolicy,
typename TKeepValuesPolicy>
628 TReallocatePolicy reallocatePolicy,
629 TKeepValuesPolicy keepValues);
641 void SetSize(
unsigned int sz,
bool destroyExistingData =
true)
646 if (destroyExistingData)
673 void SetData(TValue *data,
bool LetArrayManageMemory =
false) ITK_NOEXCEPT;
689 void SetData(TValue *data,
unsigned int sz,
bool LetArrayManageMemory =
false) ITK_NOEXCEPT;
717 void Reserve(ElementIdentifier size);
734 this->
m_Data[i] -=
static_cast< ValueType
>( 1.0 );
745 this->
m_Data[i] +=
static_cast< ValueType
>( 1.0 );
780 template<
typename T >
784 itkAssertInDebugAndIgnoreInReleaseMacro(
m_NumElements == v.GetSize() );
787 m_Data[i] -=
static_cast< ValueType
>( v[i] );
812 template<
typename T >
816 itkAssertInDebugAndIgnoreInReleaseMacro(
m_NumElements == v.GetSize() );
819 m_Data[i] +=
static_cast< ValueType
>( v[i] );
845 template <
typename TExpr1,
typename TExpr2,
typename TBinaryOp>
848 itkAssertInDebugAndIgnoreInReleaseMacro(rhs.Size() ==
Size());
851 m_Data[i] +=
static_cast<ValueType
>(rhs[i]);
866 template <
typename TExpr1,
typename TExpr2,
typename TBinaryOp>
869 itkAssertInDebugAndIgnoreInReleaseMacro(rhs.Size() ==
Size());
872 m_Data[i] -=
static_cast<ValueType
>(rhs[i]);
883 template<
typename T >
886 const ValueType & sc =
static_cast<ValueType
>(s);
914 template<
typename T >
917 const RealValueType sc = s;
920 m_Data[i] =
static_cast< ValueType
>(
921 static_cast< RealValueType
>(
m_Data[i] )
934 bool operator==(
const Self & v)
const ITK_NOEXCEPT;
936 bool operator!=(
const Self & v)
const ITK_NOEXCEPT;
939 RealValueType
GetNorm()
const ITK_NOEXCEPT;
965 template <
typename T>
966 struct IsArray : FalseType {};
969 template <
typename T>
972 template <
typename TExpr1,
typename TExpr2,
typename TBinaryOp>
973 struct IsArray<VariableLengthVectorExpression<TExpr1, TExpr2,TBinaryOp> > : TrueType {};
993 template <
typename TExpr>
struct GetType
1000 static Type Load(Type
const& v,
unsigned int idx) ITK_NOEXCEPT
1001 { (void)idx;
return v; }
1015 template <
typename TExpr1,
typename TExpr2>
1017 typename mpl::EnableIf<mpl::And<mpl::IsArray<TExpr1>, mpl::IsArray<TExpr2> >,
unsigned int>::Type
1018 GetSize(TExpr1
const& lhs, TExpr2
const& rhs) ITK_NOEXCEPT
1021 itkAssertInDebugAndIgnoreInReleaseMacro(lhs.Size() == rhs.Size());
1036 template <
typename TExpr1,
typename TExpr2>
1038 typename mpl::EnableIf<mpl::And<mpl::IsArray<TExpr1>, mpl::Not<mpl::IsArray<TExpr2> > >,
unsigned int>::Type
1039 GetSize(TExpr1
const& lhs, TExpr2
const& itkNotUsed(rhs)) ITK_NOEXCEPT
1053 template <
typename TExpr1,
typename TExpr2>
1055 typename mpl::EnableIf<mpl::And<mpl::IsArray<TExpr2>, mpl::Not<mpl::IsArray<TExpr1> > >,
unsigned int>::Type
1056 GetSize(TExpr1
const& itkNotUsed(lhs), TExpr2
const& rhs) ITK_NOEXCEPT
1061 template <
typename T>
1062 struct GetType<VariableLengthVector<T> >
1065 static Type Load(VariableLengthVector<T>
const& v,
unsigned int idx) ITK_NOEXCEPT
1068 template <
typename TExpr1,
typename TExpr2,
typename TBinaryOp>
1069 struct GetType<VariableLengthVectorExpression<TExpr1, TExpr2, TBinaryOp> >
1091 template <
typename TExpr1,
typename TExpr2>
1093 : mpl::Or< mpl::And<mpl::IsArray<TExpr1>, mpl::IsArray<TExpr2> >,
1094 mpl::And<mpl::IsArray<TExpr1>, mpl::IsNumber<TExpr2> >,
1095 mpl::And<mpl::IsNumber<TExpr1>, mpl::IsArray<TExpr2> >
1110 template <
typename TExpr1,
typename TExpr2>
1112 : mpl::Or< mpl::And<mpl::IsArray<TExpr1>, mpl::IsNumber<TExpr2> >,
1113 mpl::And<mpl::IsNumber<TExpr1>, mpl::IsArray<TExpr2> >
1128 template <
typename TExpr1,
typename TExpr2>
1130 : mpl::And<mpl::IsArray<TExpr1>, mpl::IsNumber<TExpr2> >
1161 template <
typename TExpr1,
typename TExpr2,
typename TBinaryOp>
1165 : m_lhs(lhs), m_rhs(rhs)
1170 (itk::mpl::IsBaseOf<Details::op::BinaryOperationConcept, TBinaryOp>::Value),
1171 "The Binary Operation shall inherit from BinaryOperationConcept");
1175 unsigned int Size() const ITK_NOEXCEPT{
return Details::GetSize(m_lhs, m_rhs); }
1178 typedef typename mpl::PromoteType<
1179 typename Details::GetType<TExpr1>::Type,
1180 typename Details::GetType<TExpr2>::Type>::Type
ResType;
1196 itkAssertInDebugAndIgnoreInReleaseMacro(idx <
Size());
1197 return TBinaryOp::Apply(
1198 Details::GetType<TExpr1>::Load(m_lhs, idx),
1199 Details::GetType<TExpr2>::Load(m_rhs, idx));
1204 RealValueType
GetNorm()
const ITK_NOEXCEPT;
1223 template <
typename TExpr1,
typename TExpr2>
1226 operator+(TExpr1
const& lhs, TExpr2
const& rhs) ITK_NOEXCEPT
1238 template <
typename TExpr1,
typename TExpr2>
1241 operator-(TExpr1
const& lhs, TExpr2
const& rhs) ITK_NOEXCEPT
1252 template <
typename TExpr1,
typename TExpr2>
1255 operator*(TExpr1
const& lhs, TExpr2
const& rhs) ITK_NOEXCEPT
1265 template <
typename TExpr1,
typename TExpr2>
1268 operator/(TExpr1
const& lhs, TExpr2
const& rhs) ITK_NOEXCEPT
1274 template <
typename TExpr1,
typename TExpr2,
typename TBinaryOp>
1275 std::ostream & operator<<(std::ostream &os, VariableLengthVectorExpression<TExpr1, TExpr2, TBinaryOp>
const& v)
1281 for (
unsigned int i = 1, N = v.Size(); i != N; ++i)
1295 template <
typename TExpr>
1297 typename mpl::EnableIf<mpl::IsArray<TExpr>,
typename TExpr::RealValueType>::Type
1300 return static_cast<typename TExpr::RealValueType
>(
1309 template <
typename TExpr>
1311 typename mpl::EnableIf<mpl::IsArray<TExpr>,
typename TExpr::RealValueType>::Type
1315 RealValueType sum = 0.0;
1316 for (
unsigned int i = 0, N=v.Size(); i < N; ++i )
1318 const RealValueType value = v[i];
1319 sum += value * value;
1331 template<
typename TValue >
1332 std::ostream & operator<<(std::ostream & os, const VariableLengthVector< TValue > & arr)
1334 const unsigned int length = arr.Size();
1335 const signed int last = (
unsigned int)length - 1;
1339 for (
signed int i = 0; i < last; ++i )
1341 os << arr[i] <<
", ";
1372 template <
typename T>
1385 #ifndef ITK_MANUAL_INSTANTIATION 1386 #include "itkVariableLengthVector.hxx" Self & operator/=(T s) noexcept
void swap(VariableLengthVector< T > &l_, VariableLengthVector< T > &r_) noexcept
unsigned int GetNumberOfElements(void) const noexcept
bool operator()(unsigned int newSize, unsigned int oldSize) const noexcept
mpl::EnableIf< mpl::IsArray< TExpr >, typename TExpr::RealValueType >::Type GetNorm(TExpr const &v) noexcept
void SetElement(unsigned int i, const TValue &value) noexcept
bool operator==(const Self &v) const noexcept
Self & operator++() noexcept
mpl::EnableIf< mpl::IsArray< TExpr >, typename TExpr::RealValueType >::Type GetSquaredNorm(TExpr const &v) noexcept
Self & operator+=(TValue s) noexcept
mpl::EnableIf< Details::op::CanBeAddedOrSubstracted< TExpr1, TExpr2 >, VariableLengthVectorExpression< TExpr1, TExpr2, Details::op::Plus > >::Type operator+(TExpr1 const &lhs, TExpr2 const &rhs) noexcept
bool operator!=(const Self &v) const noexcept
VariableLengthVector(const VariableLengthVector< T > &v)
Self & operator+=(VariableLengthVectorExpression< TExpr1, TExpr2, TBinaryOp > const &rhs) noexcept
void Reserve(ElementIdentifier size)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes...
bool operator()(unsigned int newSize, unsigned int oldSize) const noexcept
void operator()(unsigned int, unsigned int, TValue2 *, TValue2 *) const noexcept
bool operator()(unsigned int, unsigned int) const noexcept
mpl::EnableIf< Details::op::CanBeDivided< TExpr1, TExpr2 >, VariableLengthVectorExpression< TExpr1, TExpr2, Details::op::Div > >::Type operator/(TExpr1 const &lhs, TExpr2 const &rhs) noexcept
bool IsAProxy() const noexcept
RealValueType GetSquaredNorm() const noexcept
const TValue & GetElement(unsigned int i) const noexcept
unsigned int Size(void) const noexcept
void swap(Array< T > &a, Array< T > &b)
void Fill(TValue const &v) noexcept
Represents an array whose length can be defined at run-time.
Self & FastAssign(const Self &v) noexcept
unsigned int Size() const noexcept
Returns the size of the vector expression.
mpl::EnableIf< Details::op::CanBeAddedOrSubstracted< TExpr1, TExpr2 >, VariableLengthVectorExpression< TExpr1, TExpr2, Details::op::Sub > >::Type operator-(TExpr1 const &lhs, TExpr2 const &rhs) noexcept
TValue & operator[](unsigned int i) noexcept
const TValue * GetDataPointer() const noexcept
TValue * AllocateElements(ElementIdentifier size) const
VariableLengthVector Self
TValue const & operator[](unsigned int i) const noexcept
ElementIdentifier m_NumElements
void DestroyExistingData() noexcept
void Swap(Self &v) noexcept
Self & operator=(VariableLengthVectorExpression< TExpr1, TExpr2, TBinaryOp > const &rhs)
bool operator()(unsigned int newSize, unsigned int oldSize) const noexcept
Self & operator=(const VariableLengthVector< T > &v)
ResType operator[](unsigned int idx) const noexcept
Self & operator-=(TValue s) noexcept
NumericTraits< ResType >::RealType RealValueType
Real type of the elements.
bool m_LetArrayManageMemory
RealValueType GetNorm() const noexcept
void SetSize(unsigned int sz, bool destroyExistingData=true)
void SetData(TValue *data, bool LetArrayManageMemory=false) noexcept
Self & operator-() noexcept
VariableLengthVectorExpression(TExpr1 const &lhs, TExpr2 const &rhs) noexcept
mpl::EnableIf< Details::op::CanBeMultiplied< TExpr1, TExpr2 >, VariableLengthVectorExpression< TExpr1, TExpr2, Details::op::Mult > >::Type operator*(TExpr1 const &lhs, TExpr2 const &rhs) noexcept
NumericTraits< ValueType >::RealType RealValueType
#define itkStaticAssert(expr, str)
Self & operator-=(VariableLengthVectorExpression< TExpr1, TExpr2, TBinaryOp > const &rhs) noexcept
unsigned int GetSize(void) const noexcept
Self & operator--() noexcept
void SetSize(unsigned int sz, TReallocatePolicy reallocatePolicy, TKeepValuesPolicy keepValues)
Self & operator*=(T s) noexcept
void operator()(unsigned int newSize, unsigned int oldSize, TValue2 *oldBuffer, TValue2 *newBuffer) const noexcept
mpl::PromoteType< typename Details::GetType< TExpr1 >::Type, typename Details::GetType< TExpr2 >::Type >::Type ResType
Vector type of the Result Expression.
Self & operator*=(TValue s) noexcept
unsigned int ElementIdentifier