Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions Modules/Core/Common/include/itkCovariantVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,14 @@ class ITK_TEMPLATE_EXPORT CovariantVector:public FixedArray< T, NVectorDimension
CovariantVector & operator=(const CovariantVector &) = default;
CovariantVector & operator=(CovariantVector &&) = default;
~CovariantVector() = default;

/**
* Constructor to initialize entire vector to one value.
*/
explicit CovariantVector(const ValueType & r);
/* Inherit constructors from base class */
using Superclass::Superclass;

/** Pass-through constructor for the Array base class. Implicit casting is
* performed to initialize constructor from any another one of datatype. */
template< typename TVectorValueType >
CovariantVector(const CovariantVector< TVectorValueType,
NVectorDimension > & r):BaseArray(r) {}
CovariantVector(const ValueType r[Dimension]):BaseArray(r) {}

/** Assignment operator with implicit casting from another data type */
template< typename TCovariantVectorValueType >
Expand All @@ -129,9 +125,6 @@ class ITK_TEMPLATE_EXPORT CovariantVector:public FixedArray< T, NVectorDimension
return *this;
}

/** Pass-through assignment operator for the Array base class. */
CovariantVector & operator=(const ValueType r[NVectorDimension]);

/** Scalar operator*=. Scales elements by a scalar. */
template< typename Tt >
inline const Self & operator*=(const Tt & value)
Expand Down
18 changes: 0 additions & 18 deletions Modules/Core/Common/include/itkCovariantVector.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,6 @@

namespace itk
{
template< typename T, unsigned int TVectorDimension >
CovariantVector< T, TVectorDimension >
::CovariantVector(const ValueType & r)
{
for ( typename BaseArray::Iterator i = BaseArray::Begin(); i != BaseArray::End(); ++i )
{
*i = r;
}
}

template< typename T, unsigned int NVectorDimension >
CovariantVector< T, NVectorDimension > &
CovariantVector< T, NVectorDimension >
::operator=(const ValueType r[NVectorDimension])
{
BaseArray::operator=(r);
return *this;
}

template< typename T, unsigned int NVectorDimension >
const typename CovariantVector< T, NVectorDimension >::Self &
Expand Down
79 changes: 67 additions & 12 deletions Modules/Core/Common/include/itkFixedArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ template< typename TValue, unsigned int VLength = 3 >
class ITK_TEMPLATE_EXPORT FixedArray
{
public:
using Self = FixedArray;
/** Length constant */
static constexpr unsigned int Length = VLength;

Expand Down Expand Up @@ -139,27 +140,29 @@ class ITK_TEMPLATE_EXPORT FixedArray
~FixedArray() = default;

/** Conversion constructors */
FixedArray(const ValueType r[VLength]);
/** From C array. Values are copied individually instead of with a binary copy. This
* allows the ValueType's assignment operator to be executed. */
template<typename TScalarType>
FixedArray(const TScalarType (&r)[VLength])
{
for (unsigned int i = 0; i < VLength; ++i)
{
( *this )[i] = static_cast<TValue>(r[i]);
}
}

FixedArray(const ValueType & );

/** Constructor to initialize a fixed array from another of any data type */
template< typename TFixedArrayValueType >
FixedArray(const FixedArray< TFixedArrayValueType, VLength > & r)
explicit FixedArray(const FixedArray< TFixedArrayValueType, VLength > & r)
{
typename FixedArray< TFixedArrayValueType, VLength >::ConstIterator input = r.Begin();
Iterator i = this->Begin();
while ( i != this->End() )
for (unsigned int i = 0; i < VLength; ++i)
{
*i++ = static_cast< TValue >( *input++ );
( *this )[i] = static_cast<TValue>(r[i]);
}
}

template< typename TScalarValue >
FixedArray(const TScalarValue *r)
{
std::copy(r, r + this->Size(), this->GetDataPointer());
}

/** Operator= defined for a variety of types. */
template< typename TFixedArrayValueType >
FixedArray & operator=(const FixedArray< TFixedArrayValueType, VLength > & r)
Expand All @@ -176,8 +179,60 @@ class ITK_TEMPLATE_EXPORT FixedArray
return *this;
}

template<typename TScalarType>
FixedArray & operator=(const TScalarType (&r)[VLength])
{
for (unsigned int i = 0; i < VLength; ++i)
{
( *this )[i] = static_cast<TValue>(r[i]);
}
return *this;
}
/* Same as above, but providing extra checking to avoid copying if internal array already equal than input. */
FixedArray & operator=(const ValueType r[VLength]);

template< typename TFixedArrayValueType >
FixedArray & operator-(const FixedArray< TFixedArrayValueType, VLength > & input)
{
Self result;
for ( unsigned int i = 0; i < Dimension; i++ )
{
result[i] = ( *this )[i] - static_cast<TFixedArrayValueType>(input[i]);
}
return result;
}

template< typename TFixedArrayValueType >
FixedArray & operator-=(const FixedArray< TFixedArrayValueType, VLength > & input)
{
for ( unsigned int i = 0; i < Dimension; i++ )
{
( *this )[i] -= static_cast<TFixedArrayValueType>(input[i]);
}
return *this;
}

template< typename TFixedArrayValueType >
FixedArray & operator+(const FixedArray< TFixedArrayValueType, VLength > & input)
{
Self result;
for ( unsigned int i = 0; i < Dimension; i++ )
{
result[i] = ( *this )[i] + static_cast<TFixedArrayValueType>(input[i]);
}
return result;
}

template< typename TFixedArrayValueType >
FixedArray & operator+=(const FixedArray< TFixedArrayValueType, VLength > & input)
{
for ( unsigned int i = 0; i < Dimension; i++ )
{
( *this )[i] += static_cast<TFixedArrayValueType>(input[i]);
}
return *this;
}

/** Operators == and != are used to compare whether two arrays are equal.
* Note that arrays are equal when the number of components (size) is the
* same, and each component value is equal. */
Expand Down
18 changes: 0 additions & 18 deletions Modules/Core/Common/include/itkFixedArray.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,6 @@ FixedArray< TValue, VLength >
}
}

/**
* Constructor assumes input points to array of correct size.
* Values are copied individually instead of with a binary copy. This
* allows the ValueType's assignment operator to be executed.
*/
template< typename TValue, unsigned int VLength >
FixedArray< TValue, VLength >
::FixedArray(const ValueType r[VLength])
{
ConstIterator input = r;
Iterator i = this->Begin();

while ( i != this->End() )
{
*i++ = *input++;
}
}

/**
* Assignment operator assumes input points to array of correct size.
* Values are copied individually instead of with a binary copy. This
Expand Down
12 changes: 6 additions & 6 deletions Modules/Core/Common/include/itkImageBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ class ITK_TEMPLATE_EXPORT ImageBase:public DataObject
* as SpacePrecisionType but may be set from float or double.
* \sa GetOrigin() */
itkSetMacro(Origin, PointType);
virtual void SetOrigin(const double origin[VImageDimension]);
virtual void SetOrigin(const float origin[VImageDimension]);
virtual void SetOrigin(const double (&origin)[VImageDimension]);
virtual void SetOrigin(const float (&origin)[VImageDimension]);

/** Set the direction cosines of the image. The direction cosines
* are vectors that point from one pixel to the next.
Expand Down Expand Up @@ -400,8 +400,8 @@ class ITK_TEMPLATE_EXPORT ImageBase:public DataObject
* transforms of the image.
* \sa GetSpacing() */
virtual void SetSpacing(const SpacingType & spacing);
virtual void SetSpacing(const double spacing[VImageDimension]);
virtual void SetSpacing(const float spacing[VImageDimension]);
virtual void SetSpacing(const double (&spacing)[VImageDimension]);
virtual void SetSpacing(const float (&spacing)[VImageDimension]);

/** Get the index (discrete) of a voxel from a physical point.
* Floating point index results are rounded to integers
Expand Down Expand Up @@ -732,14 +732,14 @@ class ITK_TEMPLATE_EXPORT ImageBase:public DataObject
void Graft(const DataObject *data) override;

private:
void InternalSetSpacing(const SpacingValueType spacing[VImageDimension])
void InternalSetSpacing(const SpacingValueType (&spacing)[VImageDimension])
{
SpacingType s(spacing);
this->SetSpacing(s);
}

template <typename TSpacingValue>
void InternalSetSpacing(const TSpacingValue spacing[VImageDimension])
void InternalSetSpacing(const TSpacingValue (&spacing)[VImageDimension])
{
Vector<TSpacingValue,VImageDimension> sf(spacing);
SpacingType s;
Expand Down
8 changes: 4 additions & 4 deletions Modules/Core/Common/include/itkImageBase.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ ImageBase< VImageDimension >
template< unsigned int VImageDimension >
void
ImageBase< VImageDimension >
::SetSpacing(const double spacing[VImageDimension])
::SetSpacing(const double (&spacing)[VImageDimension])
{
this->InternalSetSpacing(spacing);
}
Expand All @@ -129,7 +129,7 @@ ImageBase< VImageDimension >
template< unsigned int VImageDimension >
void
ImageBase< VImageDimension >
::SetSpacing(const float spacing[VImageDimension])
::SetSpacing(const float (&spacing)[VImageDimension])
{
this->InternalSetSpacing(spacing);
}
Expand All @@ -138,7 +138,7 @@ ImageBase< VImageDimension >
template< unsigned int VImageDimension >
void
ImageBase< VImageDimension >
::SetOrigin(const double origin[VImageDimension])
::SetOrigin(const double (&origin)[VImageDimension])
{
PointType p(origin);

Expand All @@ -149,7 +149,7 @@ ImageBase< VImageDimension >
template< unsigned int VImageDimension >
void
ImageBase< VImageDimension >
::SetOrigin(const float origin[VImageDimension])
::SetOrigin(const float (&origin)[VImageDimension])
{
Point< float, VImageDimension > of(origin);
PointType p;
Expand Down
13 changes: 2 additions & 11 deletions Modules/Core/Common/include/itkPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,11 @@ class ITK_TEMPLATE_EXPORT Point:public FixedArray< TCoordRep, NPointDimension >
Point & operator=(const Point &) = default;
Point & operator=(Point &&) = default;
~Point() = default;
/* Inherit constructors from base class */
using Superclass::Superclass;
/** Pass-through constructors for different type points. */
template< typename TPointValueType >
Point(const Point< TPointValueType, NPointDimension > & r):BaseArray(r) {}
/** Pass-through constructors for plain arrays. */
template< typename TPointValueType >
Point(const TPointValueType r[NPointDimension]):BaseArray(r) {}
Point(const ValueType r[NPointDimension]):BaseArray(r) {}
/** Pass-through constructors for single values */
template< typename TPointValueType >
Point(const TPointValueType & v):BaseArray(v) {}
Point(const ValueType & v):BaseArray(v) {}

/** Pass-through assignment operator for a plain array. */
Point & operator=(const ValueType r[NPointDimension]);

/** Compare two points for equality. */
bool
Expand Down
12 changes: 0 additions & 12 deletions Modules/Core/Common/include/itkPoint.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@

namespace itk
{
/**
* Assignment from a plain array
*/
template< typename T, unsigned int TPointDimension >
Point< T, TPointDimension > &
Point< T, TPointDimension >
::operator=(const ValueType r[TPointDimension])
{
BaseArray::operator=(r);
return *this;
}

/**
* In place increment by a vector
*/
Expand Down
8 changes: 4 additions & 4 deletions Modules/Core/Common/include/itkSpecialCoordinatesImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,11 @@ class ITK_TEMPLATE_EXPORT SpecialCoordinatesImage:public ImageBase< VImageDimens
* special-coordinates image. Filters designed to produce a particular kind
* of special-coordinates image should do this automatically. */
void SetSpacing(const SpacingType &) override {}
void SetSpacing(const double[VImageDimension]) override {}
void SetSpacing(const float[VImageDimension]) override {}
void SetSpacing(const double(&)[VImageDimension]) override {}
void SetSpacing(const float(&)[VImageDimension]) override {}
void SetOrigin(const PointType) override {}
void SetOrigin(const double[VImageDimension]) override {}
void SetOrigin(const float[VImageDimension]) override {}
void SetOrigin(const double(&)[VImageDimension]) override {}
void SetOrigin(const float(&)[VImageDimension]) override {}

/* It is ILLEGAL in C++ to make a templated member function virtual! */
/* Therefore, we must just let templates take care of everything. */
Expand Down
17 changes: 4 additions & 13 deletions Modules/Core/Common/include/itkVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,13 @@ class ITK_TEMPLATE_EXPORT Vector:public FixedArray< T, NVectorDimension >
Vector & operator=(Vector &&) = default;
~Vector() = default;

#if !defined( ITK_LEGACY_FUTURE_REMOVE )
/** Constructor to initialize entire vector to one value.
* \warning Not intended to convert a scalar value into
* a Vector filled with that value.
* \deprecated */
Vector(const ValueType & r);
#else
/** Constructor to initialize entire vector to one value,
* if explicitly invoked. */
explicit Vector(const ValueType & r);
#endif
/* Inherit constructors from base class */
using Superclass::Superclass;

/** Pass-through constructor for the Array base class. */
template< typename TVectorValueType >
Vector(const Vector< TVectorValueType, NVectorDimension > & r):BaseArray(r) {}
Vector(const ValueType r[Dimension]):BaseArray(r) {}
Vector(const ValueType (&r)[Dimension]):BaseArray(r) {}

/** Pass-through assignment operator for the Array base class. */
template< typename TVectorValueType >
Expand All @@ -128,7 +119,7 @@ class ITK_TEMPLATE_EXPORT Vector:public FixedArray< T, NVectorDimension >
return *this;
}

Vector & operator=(const ValueType r[NVectorDimension]);
Vector & operator=(const ValueType (&r)[NVectorDimension]);

/** Scalar operator*=. Scales elements by a scalar. */
template< typename Tt >
Expand Down
12 changes: 1 addition & 11 deletions Modules/Core/Common/include/itkVector.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,10 @@

namespace itk
{
template< typename T, unsigned int TVectorDimension >
Vector< T, TVectorDimension >
::Vector(const ValueType & r)
{
for ( typename BaseArray::Iterator i = BaseArray::Begin(); i != BaseArray::End(); ++i )
{
*i = r;
}
}

template< typename T, unsigned int TVectorDimension >
Vector< T, TVectorDimension > &
Vector< T, TVectorDimension >
::operator=(const ValueType r[TVectorDimension])
::operator=(const ValueType (&r)[TVectorDimension])
{
BaseArray::operator=(r);
return *this;
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/QuadEdgeMesh/include/itkQuadEdgeMeshPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ITK_TEMPLATE_EXPORT QuadEdgeMeshPoint:public Point< TCoordRep, VPointDimen

QuadEdgeMeshPoint(const Superclass & r);

QuadEdgeMeshPoint(const ValueType r[VPointDimension]):Superclass(r)
QuadEdgeMeshPoint(const ValueType (&r)[VPointDimension]):Superclass(r)
{
this->Initialize();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ITK_TEMPLATE_EXPORT LineSpatialObjectPoint:
const VectorType & GetNormal(unsigned int index) const;

/** Set Normal */
void SetNormal(VectorType & normal, unsigned int index);
void SetNormal(const VectorType & normal, unsigned int index);

/** Copy one LineSpatialObjectPoint to another */
Self & operator=(const LineSpatialObjectPoint & rhs);
Expand Down
Loading