From 1eb6613f1f3696d850297bcded74c41130b85022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Haitz=20Legarreta=20Gorro=C3=B1o?= Date: Thu, 4 Apr 2019 22:07:17 -0400 Subject: [PATCH] COMP: Fix compiler warnings Fix compiler warnings: use the type aliases and image dimensions constants properly defined in the class header for the image dimensionality. Fixes: ``` Modules/Remote/AnisotropicDiffusionLBR/include/ itkLinearAnisotropicDiffusionLBRImageFilter.hxx:108:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for( auto i = 1; i < Dimension; ++i ) ^ ``` errors. reported at: http://testing.cdash.org/viewBuildError.php?type=1&buildid=5840769 --- .../itkAnisotropicDiffusionLBRImageFilter.h | 7 +- .../itkAnisotropicDiffusionLBRImageFilter.hxx | 8 +- ...tkCoherenceEnhancingDiffusionImageFilter.h | 3 +- ...CoherenceEnhancingDiffusionImageFilter.hxx | 12 +-- ...LinearAnisotropicDiffusionLBRImageFilter.h | 21 ++--- ...nearAnisotropicDiffusionLBRImageFilter.hxx | 84 +++++++++---------- include/itkStructureTensorImageFilter.h | 14 ++-- 7 files changed, 77 insertions(+), 72 deletions(-) diff --git a/include/itkAnisotropicDiffusionLBRImageFilter.h b/include/itkAnisotropicDiffusionLBRImageFilter.h index 668ff02..8636f50 100644 --- a/include/itkAnisotropicDiffusionLBRImageFilter.h +++ b/include/itkAnisotropicDiffusionLBRImageFilter.h @@ -62,10 +62,11 @@ class AnisotropicDiffusionLBRImageFilter : public ImageToImageFilter< TImage, TI using PixelType = typename ImageType::PixelType; using ScalarType = TScalar; - static const unsigned int Dimension = ImageType::ImageDimension; + using ImageDimensionType = typename ImageType::ImageDimensionType; + static constexpr ImageDimensionType ImageDimension = ImageType::ImageDimension; - using TensorType = SymmetricSecondRankTensor< ScalarType, Dimension >; - using TensorImageType = Image< TensorType, Dimension >; + using TensorType = SymmetricSecondRankTensor< ScalarType, ImageDimension >; + using TensorImageType = Image< TensorType, ImageDimension >; using StructureTensorFilterType = StructureTensorImageFilter; using LinearDiffusionFilterType = LinearAnisotropicDiffusionLBRImageFilter; diff --git a/include/itkAnisotropicDiffusionLBRImageFilter.hxx b/include/itkAnisotropicDiffusionLBRImageFilter.hxx index 5743da3..b95d58d 100644 --- a/include/itkAnisotropicDiffusionLBRImageFilter.hxx +++ b/include/itkAnisotropicDiffusionLBRImageFilter.hxx @@ -54,7 +54,7 @@ AnisotropicDiffusionLBRImageFilter< TImage, TScalar > // const SpacingType unitSpacing(1); // Better below for non-uniform spacing. double minSpacing = referenceSpacing[0]; - for( unsigned int i = 1; i < Dimension; ++i ) + for( ImageDimensionType i = 1; i < ImageDimension; ++i ) { minSpacing = std::min(minSpacing,referenceSpacing[i]); } @@ -108,8 +108,8 @@ struct AnisotropicDiffusionLBRImageFilter< TImage, TScalar > S.ComputeEigenAnalysis(eigenValues,eigenVectors); // For convenience, eigenvalues are sorted by increasing order - Vector order; - for(int i=0; i<(int)Dimension; ++i) order[i]=i; + Vector order; + for(ImageDimensionType i=0; i < ImageDimension; ++i) order[i]=i; OrderingType ordering(eigenValues); @@ -119,7 +119,7 @@ struct AnisotropicDiffusionLBRImageFilter< TImage, TScalar > EigenValuesArrayType ev = this->eigenValuesFunctor->EigenValuesTransform(eigenValues); TensorType DiffusionTensor; - for(int i=0; i<(int)Dimension; ++i){ + for(ImageDimensionType i=0; i < ImageDimension; ++i){ DiffusionTensor(order[i],order[i]) = ev[i]; for(int j=0; j ::EigenValuesTransform(const EigenValuesArrayType & ev0) const { const ScalarType evMin = ev0[0]; - const ScalarType evMax = ev0[Dimension-1]; + const ScalarType evMax = ev0[InputImageDimension-1]; EigenValuesArrayType ev; switch(m_Enhancement) { // Weickert's filter. case CED: - for( unsigned int i = 0; i < Dimension; ++i ) + for( InputImageDimensionType i = 0; i < InputImageDimension; ++i ) { ev[i] = g_CED(evMax-ev0[i]); } @@ -56,7 +56,7 @@ CoherenceEnhancingDiffusionImageFilter< TImage, TScalar > // A variance, requiring stronger coherence. case cCED: - for( unsigned int i = 0; i < Dimension; ++i ) + for( InputImageDimensionType i = 0; i < InputImageDimension; ++i ) { ev[i] = g_CED( (evMax-ev0[i])/(1.+ev0[i]/m_Lambda) ); } @@ -64,7 +64,7 @@ CoherenceEnhancingDiffusionImageFilter< TImage, TScalar > // Weickert's filter. case EED: - for( unsigned int i = 0; i < Dimension; ++i ) + for( InputImageDimensionType i = 0; i < InputImageDimension; ++i ) { ev[i] = g_EED(ev0[i]-evMin); } @@ -72,7 +72,7 @@ CoherenceEnhancingDiffusionImageFilter< TImage, TScalar > // A variant, promoting diffusion in at least one direction at each point. case cEED: - for( unsigned int i = 0; i < Dimension; ++i ) + for( InputImageDimensionType i = 0; i < InputImageDimension; ++i ) { ev[i] = g_EED(ev0[i]); } @@ -80,7 +80,7 @@ CoherenceEnhancingDiffusionImageFilter< TImage, TScalar > // Isotropic tensors, closely related to Perona-Malik's approach. case Isotropic: - for( unsigned int i = 0; i < Dimension; ++i ) + for( InputImageDimensionType i = 0; i < InputImageDimension; ++i ) { ev[i] = g_EED(evMax); } diff --git a/include/itkLinearAnisotropicDiffusionLBRImageFilter.h b/include/itkLinearAnisotropicDiffusionLBRImageFilter.h index cfb76a2..29abca8 100644 --- a/include/itkLinearAnisotropicDiffusionLBRImageFilter.h +++ b/include/itkLinearAnisotropicDiffusionLBRImageFilter.h @@ -65,12 +65,13 @@ class LinearAnisotropicDiffusionLBRImageFilter: using ImageType = TImage; using PixelType = typename ImageType::PixelType; - static constexpr unsigned int Dimension = ImageType::ImageDimension; + using ImageDimensionType = typename ImageType::ImageDimensionType; + static constexpr ImageDimensionType ImageDimension = ImageType::ImageDimension; using ScalarType = TScalar; - using TensorType = SymmetricSecondRankTensor< ScalarType, Dimension >; - using TensorImageType = Image< TensorType, Dimension >; - using RegionType = ImageRegion< Dimension >; + using TensorType = SymmetricSecondRankTensor< ScalarType, ImageDimension >; + using TensorImageType = Image< TensorType, ImageDimension >; + using RegionType = ImageRegion< ImageDimension >; void SetInputImage(const ImageType* image); void SetInputTensor(const TensorImageType* tensorImage); @@ -94,14 +95,14 @@ class LinearAnisotropicDiffusionLBRImageFilter: typename ImageType::ConstPointer GetInputImage(); typename TensorImageType::ConstPointer GetInputTensor(); - using IndexType = Index; + using IndexType = Index; // ******* Containers for the stencils used in the discretization - static const unsigned int HalfStencilSize = (Dimension == 2) ? 3 : 6; + static const unsigned int HalfStencilSize = (ImageDimension == 2) ? 3 : 6; static const unsigned int StencilSize = 2 * HalfStencilSize; using StencilCoefficientsType = Vector; - using OffsetType = Offset; + using OffsetType = Offset; using StencilOffsetsType = Vector; using InternalSizeT = int; @@ -114,10 +115,10 @@ class LinearAnisotropicDiffusionLBRImageFilter: virtual void ImageUpdateLoop(); /// Automatically called by GenerateData using StencilType = std::pair< StencilBufferIndicesType, StencilCoefficientsType >; - using StencilImageType = Image< StencilType, Dimension >; + using StencilImageType = Image< StencilType, ImageDimension >; typename StencilImageType::Pointer m_StencilImage; - using ScalarImageType = Image; + using ScalarImageType = Image; typename ScalarImageType::Pointer m_DiagonalCoefficients; virtual ScalarType MaxStableTimeStep(); @@ -140,7 +141,7 @@ class LinearAnisotropicDiffusionLBRImageFilter: struct StencilFunctor; struct FunctorType; - using VectorType = Vector; + using VectorType = Vector; static ScalarType ScalarProduct(const TensorType &, const VectorType &, const VectorType &); }; diff --git a/include/itkLinearAnisotropicDiffusionLBRImageFilter.hxx b/include/itkLinearAnisotropicDiffusionLBRImageFilter.hxx index 333e5b2..69eac85 100644 --- a/include/itkLinearAnisotropicDiffusionLBRImageFilter.hxx +++ b/include/itkLinearAnisotropicDiffusionLBRImageFilter.hxx @@ -105,11 +105,11 @@ public: { region = region_; prod[0] = 1; - for( auto i = 1; i < Dimension; ++i ) + for( ImageDimensionType i = 1; i < ImageDimension; ++i ) { prod[i]=prod[i-1]*region.GetSize()[i-1]; } - for(auto i = 0; i < Dimension; ++i ) + for(ImageDimensionType i = 0; i < ImageDimension; ++i ) { invSpacing[i] = ScalarType(1) / spacing[i]; } @@ -118,7 +118,7 @@ public: InternalSizeT BufferIndex(const IndexType & x) const { IndexValueType ans=0; - for( auto i = 0; i < Dimension; ++i ) + for( ImageDimensionType i = 0; i < ImageDimension; ++i ) { ans += this->prod[i] * ( x[i] - this->region.GetIndex()[i] ); } @@ -133,15 +133,15 @@ public: // Diffusion tensors are homogeneous to the inverse of norms, and are thus rescaled with an inverse spacing. TensorType D; - for(auto i=0; iinvSpacing[i]*this->invSpacing[j]; - this->Stencil( Dispatch< Dimension >(), D, offsets, stencil.second ); + this->Stencil( Dispatch< ImageDimension >(), D, offsets, stencil.second ); InternalSizeT * yIndex = &stencil.first[0]; //Compute buffer offsets from geometrical offsets - for(auto i=0; i<(int)HalfStencilSize; ++i){ + for(unsigned int i=0; iregion.IsInside(y)){ @@ -163,24 +163,24 @@ protected: static void Stencil(const Dispatch< 2 > &, const TensorType & D, StencilOffsetsType & offsets, StencilCoefficientsType & coefficients) { // Construct a superbase, and make it obtuse with Selling's algorithm - VectorType sb[Dimension+1]; //SuperBase - for(auto i=0; i 0 ) { @@ -202,7 +202,7 @@ protected: std::cerr << "Warning: Selling's algorithm not stabilized." << std::endl; } - for( auto i = 0; i < 3; ++i ) + for( ImageDimensionType i = 0; i < 3; ++i ) { coefficients[i] = (-0.5)*ScalarProduct(D,sb[(i+1)%3],sb[(i+2)%3]); assert(coefficients[i]>=0); @@ -214,26 +214,26 @@ protected: static void Stencil(const Dispatch< 3 > &, const TensorType & D, StencilOffsetsType & offsets, StencilCoefficientsType & coefficients) { // Construct a superbase, and make it obtuse with Selling's algorithm - VectorType sb[Dimension+1]; - for(auto i=0; i 0 ){ const VectorType u=sb[i], v=sb[j]; - for(auto k=0,l=0; k<=Dimension; ++k) + for(auto k=0,l=0; k<=ImageDimension; ++k) if(k!=i && k!=j) sb[l++]=sb[k]+u; sb[2]=-u; @@ -248,40 +248,40 @@ protected: } // Computation of the weights - SymmetricSecondRankTensor Weights; - for(auto i=1; i Weights; + for(ImageDimensionType i=1; i !stencilIt.IsAtEnd(); ++stencilIt, ++diagIt) { - for(auto i = 0; i < (int)StencilSize; ++i) + for(unsigned int i = 0; i < StencilSize; ++i) { const InternalSizeT yIndex = stencilIt.Value().first[i]; if( yIndex != OutsideBufferIndex() ) @@ -452,7 +452,7 @@ LinearAnisotropicDiffusionLBRImageFilter< TImage, TScalar > ::ImageUpdate(ScalarType delta) { //Setting up iterators - ImageRegion region = GetRequestedRegion(); + ImageRegion region = GetRequestedRegion(); ImageRegionConstIterator inputIt(m_PreviousImage,region); ImageRegionIterator outputIt(m_NextImage,region); @@ -471,7 +471,7 @@ LinearAnisotropicDiffusionLBRImageFilter< TImage, TScalar > !inputIt.IsAtEnd(); ++inputIt, ++outputIt, ++stencilIt ) { - for( auto i = 0; i < (int)StencilSize; ++i ) + for( unsigned int i = 0; i < StencilSize; ++i ) { const InternalSizeT yIndex = stencilIt.Value().first[i]; if( yIndex != OutsideBufferIndex() ) @@ -514,13 +514,13 @@ LinearAnisotropicDiffusionLBRImageFilter< TImage, TScalar> const VectorType & v) { ScalarType result(0); - for( auto i = 0; i < Dimension; ++i ) + for( ImageDimensionType i = 0; i < ImageDimension; ++i ) { result += m(i,i) * u[i] * v[i]; } - for( auto i = 0; i < Dimension; ++i ) + for( ImageDimensionType i = 0; i < ImageDimension; ++i ) { - for( auto j = i+1; j < Dimension; ++j ) + for( ImageDimensionType j = i+1; j < ImageDimension; ++j ) { result += m(i,j) * (u[i] * v[j] + u[j] * v[i]); } diff --git a/include/itkStructureTensorImageFilter.h b/include/itkStructureTensorImageFilter.h index 2cb1163..bfed36f 100644 --- a/include/itkStructureTensorImageFilter.h +++ b/include/itkStructureTensorImageFilter.h @@ -65,13 +65,15 @@ class StructureTensorImageFilter: /// Run-time type information (and related methods). itkTypeMacro(StructureTensorImageFilter, Superclass); + using InputImageDimensionType = typename Superclass::InputImageType::ImageDimensionType; + static constexpr InputImageDimensionType InputImageDimension = Superclass::InputImageType::ImageDimension; + using ImageType = TImage; using PixelType = typename ImageType::PixelType; - static const unsigned int Dimension = ImageType::ImageDimension; using TensorImageType = TTensorImage; using TensorType = typename TensorImageType::PixelType; using ScalarType = typename TensorType::ComponentType; - using ScalarImageType = Image; + using ScalarImageType = Image; ///Parameter \f$\sigma\f$ of the structure tensor definition. itkSetMacro(NoiseScale, ScalarType); @@ -102,17 +104,17 @@ class StructureTensorImageFilter: void IntermediateFilter( const Dispatch< false > & ); typename TensorImageType::Pointer m_IntermediateResult; - using CovariantVectorType = CovariantVector; - using CovariantImageType = Image; + using CovariantVectorType = CovariantVector; + using CovariantImageType = Image; struct OuterFunctor { TensorType operator()(const CovariantVectorType & u) const { TensorType m; - for( unsigned int i = 0; i < Dimension; ++i ) + for( InputImageDimensionType i = 0; i < InputImageDimension; ++i ) { - for( unsigned int j = i; j < Dimension; ++j) + for( InputImageDimensionType j = i; j < InputImageDimension; ++j) { m(i,j) = u[i]*u[j]; }