diff --git a/Modules/Core/Common/include/itkCovariantVector.h b/Modules/Core/Common/include/itkCovariantVector.h index 28424dc13ef..81b7a1db3fd 100644 --- a/Modules/Core/Common/include/itkCovariantVector.h +++ b/Modules/Core/Common/include/itkCovariantVector.h @@ -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 > @@ -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) diff --git a/Modules/Core/Common/include/itkCovariantVector.hxx b/Modules/Core/Common/include/itkCovariantVector.hxx index 6e9b86354b1..20058714c17 100644 --- a/Modules/Core/Common/include/itkCovariantVector.hxx +++ b/Modules/Core/Common/include/itkCovariantVector.hxx @@ -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 & diff --git a/Modules/Core/Common/include/itkFixedArray.h b/Modules/Core/Common/include/itkFixedArray.h index b52867fdbfa..dffa5b9c9ae 100644 --- a/Modules/Core/Common/include/itkFixedArray.h +++ b/Modules/Core/Common/include/itkFixedArray.h @@ -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; @@ -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 + FixedArray(const TScalarType (&r)[VLength]) + { + for (unsigned int i = 0; i < VLength; ++i) + { + ( *this )[i] = static_cast(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(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) @@ -176,8 +179,60 @@ class ITK_TEMPLATE_EXPORT FixedArray return *this; } + template + FixedArray & operator=(const TScalarType (&r)[VLength]) + { + for (unsigned int i = 0; i < VLength; ++i) + { + ( *this )[i] = static_cast(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(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(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(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(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. */ diff --git a/Modules/Core/Common/include/itkFixedArray.hxx b/Modules/Core/Common/include/itkFixedArray.hxx index 04728a712e5..0aa70985344 100644 --- a/Modules/Core/Common/include/itkFixedArray.hxx +++ b/Modules/Core/Common/include/itkFixedArray.hxx @@ -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 diff --git a/Modules/Core/Common/include/itkImageBase.h b/Modules/Core/Common/include/itkImageBase.h index ef8b0ec30e7..30e39db3d7b 100644 --- a/Modules/Core/Common/include/itkImageBase.h +++ b/Modules/Core/Common/include/itkImageBase.h @@ -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. @@ -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 @@ -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 - void InternalSetSpacing(const TSpacingValue spacing[VImageDimension]) + void InternalSetSpacing(const TSpacingValue (&spacing)[VImageDimension]) { Vector sf(spacing); SpacingType s; diff --git a/Modules/Core/Common/include/itkImageBase.hxx b/Modules/Core/Common/include/itkImageBase.hxx index e12e9f401e9..851cfabe118 100644 --- a/Modules/Core/Common/include/itkImageBase.hxx +++ b/Modules/Core/Common/include/itkImageBase.hxx @@ -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); } @@ -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); } @@ -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); @@ -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; diff --git a/Modules/Core/Common/include/itkPoint.h b/Modules/Core/Common/include/itkPoint.h index 024259349b7..ce5e68fabcd 100644 --- a/Modules/Core/Common/include/itkPoint.h +++ b/Modules/Core/Common/include/itkPoint.h @@ -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 diff --git a/Modules/Core/Common/include/itkPoint.hxx b/Modules/Core/Common/include/itkPoint.hxx index d17d7a02823..46b3b7e1870 100644 --- a/Modules/Core/Common/include/itkPoint.hxx +++ b/Modules/Core/Common/include/itkPoint.hxx @@ -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 */ diff --git a/Modules/Core/Common/include/itkSpecialCoordinatesImage.h b/Modules/Core/Common/include/itkSpecialCoordinatesImage.h index c4ccd65b420..1383e81f94a 100644 --- a/Modules/Core/Common/include/itkSpecialCoordinatesImage.h +++ b/Modules/Core/Common/include/itkSpecialCoordinatesImage.h @@ -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. */ diff --git a/Modules/Core/Common/include/itkVector.h b/Modules/Core/Common/include/itkVector.h index fb0bf43b52c..84234602afe 100644 --- a/Modules/Core/Common/include/itkVector.h +++ b/Modules/Core/Common/include/itkVector.h @@ -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 > @@ -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 > diff --git a/Modules/Core/Common/include/itkVector.hxx b/Modules/Core/Common/include/itkVector.hxx index 33bc7beccc8..e0179fdc918 100644 --- a/Modules/Core/Common/include/itkVector.hxx +++ b/Modules/Core/Common/include/itkVector.hxx @@ -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; diff --git a/Modules/Core/QuadEdgeMesh/include/itkQuadEdgeMeshPoint.h b/Modules/Core/QuadEdgeMesh/include/itkQuadEdgeMeshPoint.h index 7ec5f7f11af..58110015bb3 100644 --- a/Modules/Core/QuadEdgeMesh/include/itkQuadEdgeMeshPoint.h +++ b/Modules/Core/QuadEdgeMesh/include/itkQuadEdgeMeshPoint.h @@ -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(); } diff --git a/Modules/Core/SpatialObjects/include/itkLineSpatialObjectPoint.h b/Modules/Core/SpatialObjects/include/itkLineSpatialObjectPoint.h index 3f84402b4dc..2897aa28c76 100644 --- a/Modules/Core/SpatialObjects/include/itkLineSpatialObjectPoint.h +++ b/Modules/Core/SpatialObjects/include/itkLineSpatialObjectPoint.h @@ -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); diff --git a/Modules/Core/SpatialObjects/include/itkLineSpatialObjectPoint.hxx b/Modules/Core/SpatialObjects/include/itkLineSpatialObjectPoint.hxx index 9801f536ebe..53b35d1efa6 100644 --- a/Modules/Core/SpatialObjects/include/itkLineSpatialObjectPoint.hxx +++ b/Modules/Core/SpatialObjects/include/itkLineSpatialObjectPoint.hxx @@ -72,7 +72,7 @@ LineSpatialObjectPoint< TPointDimension > template< unsigned int TPointDimension > void LineSpatialObjectPoint< TPointDimension > -::SetNormal(VectorType & normal, unsigned int index) +::SetNormal(const VectorType & normal, unsigned int index) { m_NormalArray[index] = normal; } diff --git a/Modules/Core/SpatialObjects/include/itkMetaLineConverter.hxx b/Modules/Core/SpatialObjects/include/itkMetaLineConverter.hxx index 29248a8a1fc..745818e0dcb 100644 --- a/Modules/Core/SpatialObjects/include/itkMetaLineConverter.hxx +++ b/Modules/Core/SpatialObjects/include/itkMetaLineConverter.hxx @@ -74,23 +74,13 @@ MetaLineConverter< NDimensions > LinePointType pnt; using PointType = typename LinePointType::PointType; - PointType point; using NormalType = typename LinePointType::VectorType; - - for ( unsigned int ii = 0; ii < ndims; ii++ ) - { - point[ii] = ( *it2 )->m_X[ii]; - } - + const PointType point(( *it2 )->m_X); pnt.SetPosition(point); for ( unsigned int ii = 0; ii < ndims - 1; ii++ ) { - NormalType normal; - for ( unsigned int jj = 0; jj < ndims; jj++ ) - { - normal[jj] = ( *it2 )->m_V[ii][jj]; - } + const NormalType normal(( *it2 )->m_V[ii]); pnt.SetNormal(normal, ii); } diff --git a/Modules/Filtering/ImageGrid/include/itkResampleImageFilter.h b/Modules/Filtering/ImageGrid/include/itkResampleImageFilter.h index 1178317ff99..4ddd325c226 100644 --- a/Modules/Filtering/ImageGrid/include/itkResampleImageFilter.h +++ b/Modules/Filtering/ImageGrid/include/itkResampleImageFilter.h @@ -218,14 +218,14 @@ class ITK_TEMPLATE_EXPORT ResampleImageFilter : /** Set the output image spacing. */ itkSetMacro(OutputSpacing, SpacingType); - virtual void SetOutputSpacing(const double *values); + virtual void SetOutputSpacing(const double (&values)[ImageDimension]); /** Get the output image spacing. */ itkGetConstReferenceMacro(OutputSpacing, SpacingType); /** Set the output image origin. */ itkSetMacro(OutputOrigin, OriginPointType); - virtual void SetOutputOrigin(const double *values); + virtual void SetOutputOrigin(const double (&values)[ImageDimension]); /** Get the output image origin. */ itkGetConstReferenceMacro(OutputOrigin, OriginPointType); diff --git a/Modules/Filtering/ImageGrid/include/itkResampleImageFilter.hxx b/Modules/Filtering/ImageGrid/include/itkResampleImageFilter.hxx index 6ae700ca19e..3d480a8b935 100644 --- a/Modules/Filtering/ImageGrid/include/itkResampleImageFilter.hxx +++ b/Modules/Filtering/ImageGrid/include/itkResampleImageFilter.hxx @@ -75,7 +75,7 @@ template< typename TInputImage, typename TTransformPrecisionType > void ResampleImageFilter< TInputImage, TOutputImage, TInterpolatorPrecisionType, TTransformPrecisionType > -::SetOutputSpacing(const double *spacing) +::SetOutputSpacing(const double (&spacing)[ImageDimension]) { SpacingType s; for(unsigned int i = 0; i < TOutputImage::ImageDimension; ++i) @@ -91,7 +91,7 @@ template< typename TInputImage, typename TTransformPrecisionType > void ResampleImageFilter< TInputImage, TOutputImage, TInterpolatorPrecisionType, TTransformPrecisionType > -::SetOutputOrigin(const double *origin) +::SetOutputOrigin(const double (&origin)[ImageDimension]) { OriginPointType p(origin); diff --git a/Modules/Filtering/ImageSources/test/itkGaborImageSourceTest.cxx b/Modules/Filtering/ImageSources/test/itkGaborImageSourceTest.cxx index 00ebc7d7bab..fa9f0967ca9 100644 --- a/Modules/Filtering/ImageSources/test/itkGaborImageSourceTest.cxx +++ b/Modules/Filtering/ImageSources/test/itkGaborImageSourceTest.cxx @@ -53,7 +53,7 @@ int itkGaborImageSourceTestHelper( char* outputFilename, bool calculcateImaginar gaborImage->SetSigma( sigma ); TEST_SET_GET_VALUE( sigma, gaborImage->GetSigma() ); - typename GaborSourceType::ArrayType mean = 0.1; + typename GaborSourceType::ArrayType mean = static_cast(0.1); gaborImage->SetMean( mean ); TEST_SET_GET_VALUE( mean, gaborImage->GetMean() ); diff --git a/Modules/IO/SpatialObjects/test/itkReadWriteSpatialObjectTest.cxx b/Modules/IO/SpatialObjects/test/itkReadWriteSpatialObjectTest.cxx index a8abe811e30..2128fc47c5c 100644 --- a/Modules/IO/SpatialObjects/test/itkReadWriteSpatialObjectTest.cxx +++ b/Modules/IO/SpatialObjects/test/itkReadWriteSpatialObjectTest.cxx @@ -934,21 +934,21 @@ int itkReadWriteSpatialObjectTest(int argc, char* argv[]) { if(itk::Math::NotExactlyEquals((*pit).GetPosition()[d], value)) { - std::cout<<" [FAILED]"<SetOutputOrigin( fixedImage->GetOrigin() ); resample->SetOutputSpacing( fixedImage->GetSpacing() ); resample->SetOutputDirection( fixedImage->GetDirection() ); - resample->SetDefaultPixelValue( itk::NumericTraits::ZeroValue() ); + resample->SetDefaultPixelValue( static_cast(itk::NumericTraits::ZeroValue()) ); resample->Update(); //write out the displacement field