diff --git a/Examples/ANTSJacobian.cxx b/Examples/ANTSJacobian.cxx index ba81dcdc1..b6de75b2d 100644 --- a/Examples/ANTSJacobian.cxx +++ b/Examples/ANTSJacobian.cxx @@ -181,9 +181,9 @@ ComputeJacobian(TDisplacementField* field, char* fnm, char* maskfn, bool uselog if( projvec.length() > 2 ) { antsjacobiansplit(projvec, 'x', v); - for( std::vector::size_type i = 0; i < v.size(); ++i ) + for(const auto & i : v) { - std::cout << v[i] << '\n'; + std::cout << i << '\n'; } } diff --git a/Examples/ConvertImage.cxx b/Examples/ConvertImage.cxx index 2d1c1677f..d740f65c3 100644 --- a/Examples/ConvertImage.cxx +++ b/Examples/ConvertImage.cxx @@ -169,9 +169,9 @@ int ConvertImage( int argc, char *argv[] ) rescaleFileTypes.emplace_back(".bmp" ); bool isRescaleType = false; - for( unsigned int i = 0; i < rescaleFileTypes.size(); i++ ) + for(auto & rescaleFileType : rescaleFileTypes) { - if( strstr( argv[3], rescaleFileTypes[i].c_str() ) != nullptr ) + if( strstr( argv[3], rescaleFileType.c_str() ) != nullptr ) { isRescaleType = true; break; diff --git a/Examples/CreateDTICohort.cxx b/Examples/CreateDTICohort.cxx index 330c5f516..20b316ead 100644 --- a/Examples/CreateDTICohort.cxx +++ b/Examples/CreateDTICohort.cxx @@ -604,9 +604,9 @@ int CreateDTICohort( itk::ants::CommandLineParser *parser ) if( applyISV ) { vnl_vector R( ISV.cols() ); - for( unsigned int d = 0; d < R.size(); d++ ) + for(float & d : R) { - R[d] = randomizer->GetNormalVariate( 0.0, 1.0 ); + d = randomizer->GetNormalVariate( 0.0, 1.0 ); } eigenISVProjection = ISV * R; } diff --git a/Examples/ImageMath_Templates.hxx b/Examples/ImageMath_Templates.hxx index 67314a6bf..3df2bc067 100644 --- a/Examples/ImageMath_Templates.hxx +++ b/Examples/ImageMath_Templates.hxx @@ -10365,9 +10365,9 @@ int LabelThickness( int argc, char *argv[]) } } } - for( unsigned int i = 0; i < surface.size(); i++ ) + for(double i : surface) { - if( surface[i] > 0 ) + if( i > 0 ) { // std::cout << " S " << surface[i] << " V " << volume[i] << " T " << volume[i] / surface[i] * 2.0 << std::endl; } @@ -11647,12 +11647,12 @@ int MajorityVoting( int argc, char *argv[] ) fileExtensions.emplace_back(".nrrd" ); std::string outputMaskName; - for( unsigned int i = 0; i < fileExtensions.size(); i++ ) + for(auto & fileExtension : fileExtensions) { - if( outputName.find_last_of( fileExtensions[i] ) != std::string::npos ) + if( outputName.find_last_of( fileExtension ) != std::string::npos ) { outputMaskName = outputName.insert( - outputName.find_last_of( fileExtensions[i] ) - ( fileExtensions[i] ).length(), "_Mask" ); + outputName.find_last_of( fileExtension ) - fileExtension.length(), "_Mask" ); break; } } @@ -13226,9 +13226,9 @@ void getBlobCorrespondenceMatrix( unsigned int radval, typename TImage::Pointer weightsum += ( wt ); } } - for( unsigned int ii = 0; ii < weights.size(); ii++ ) + for(float & weight : weights) { - weights[ii] = weights[ii] / weightsum; + weight = weight / weightsum; } BlobPointer bestblob = nullptr; if( ( !blobs2.empty() ) && ( !blobs1.empty() ) ) diff --git a/Examples/LabelOverlapMeasures.cxx b/Examples/LabelOverlapMeasures.cxx index ce024e1a3..2368a9802 100644 --- a/Examples/LabelOverlapMeasures.cxx +++ b/Examples/LabelOverlapMeasures.cxx @@ -157,10 +157,8 @@ int LabelOverlapMeasures( int argc, char * argv[] ) << std::setw( 17 ) << "False negative" << std::setw( 17 ) << "False positive" << std::endl; - for( unsigned int i = 0; i < allLabels.size(); i++ ) + for(int label : allLabels) { - int label = allLabels[i]; - std::cout << std::setw( 10 ) << label; std::cout << std::setw( 17 ) << filter->GetTargetOverlap( label ); std::cout << std::setw( 17 ) << filter->GetUnionOverlap( label ); diff --git a/Examples/PrintHeader.cxx b/Examples/PrintHeader.cxx index e0a6f071e..8aeef4e52 100644 --- a/Examples/PrintHeader.cxx +++ b/Examples/PrintHeader.cxx @@ -284,11 +284,11 @@ int PrintHeader(int argc, char *argv[]) // For some weird reason, some of the strings returned by this method // contain '\0' characters. We will replace them by spaces std::ostringstream sout(""); - for( unsigned int i = 0; i < v_string.length(); i++ ) + for(char i : v_string) { - if( v_string[i] >= ' ' ) + if( i >= ' ' ) { - sout << v_string[i]; + sout << i; } } v_string = sout.str(); diff --git a/Examples/antsAI.cxx b/Examples/antsAI.cxx index daa81d3dd..79d945f0c 100644 --- a/Examples/antsAI.cxx +++ b/Examples/antsAI.cxx @@ -370,9 +370,9 @@ void GetBlobCorrespondenceMatrix( typename TImage::Pointer fixedImage, typename weightSum += ( weight ); } } - for( unsigned int i = 0; i < weights.size(); i++ ) + for(float & weight : weights) { - weights[i] /= weightSum; + weight /= weightSum; } typedef itk::LinearInterpolateImageFunction ScalarInterpolatorType; diff --git a/Examples/antsMotionCorr.cxx b/Examples/antsMotionCorr.cxx index 50244db5f..b582ef1af 100644 --- a/Examples/antsMotionCorr.cxx +++ b/Examples/antsMotionCorr.cxx @@ -410,13 +410,13 @@ AverageTimeImages( typename TImageIn::Pointer image_in, typename TImageOut::Poi typename OutImageType::PixelType fval = 0; typename ImageType::IndexType ind; typename OutImageType::IndexType spind = vfIter2.GetIndex(); - for( unsigned int xx = 0; xx < timelist.size(); xx++ ) + for(unsigned int & xx : timelist) { for( unsigned int yy = 0; yy < ImageDimension - 1; yy++ ) { ind[yy] = spind[yy]; } - ind[ImageDimension - 1] = timelist[xx]; + ind[ImageDimension - 1] = xx; fval += image_in->GetPixel(ind); } fval /= (double)timelist.size(); diff --git a/Examples/antsSliceRegularizedRegistration.cxx b/Examples/antsSliceRegularizedRegistration.cxx index 681138659..00b001040 100644 --- a/Examples/antsSliceRegularizedRegistration.cxx +++ b/Examples/antsSliceRegularizedRegistration.cxx @@ -550,9 +550,9 @@ int ants_slice_regularized_registration( itk::ants::CommandLineParser *parser ) { polydegree.resize( nparams, polydegree[ 0 ] ); } - for ( unsigned int pind = 0; pind < polydegree.size(); pind++ ) + for (unsigned int & pind : polydegree) { - if ( polydegree[pind] > (timedims-2) ) polydegree[pind] = timedims-2; + if ( pind > (timedims-2) ) pind = timedims-2; } // the fixed image slice is a reference image in 2D while the moving is a 2D slice image diff --git a/Examples/sccan.cxx b/Examples/sccan.cxx index f7e58b854..3acf641fe 100644 --- a/Examples/sccan.cxx +++ b/Examples/sccan.cxx @@ -1039,13 +1039,13 @@ void ConvertImageVecListToProjection( std::string veclist, std::string imagelist std::string fnmp = outname + std::string(".csv"); myfile.open(fnmp.c_str(), std::ios::out ); typedef itk::ImageRegionIteratorWithIndex Iterator; - for( unsigned int j = 0; j < image_fn_list.size(); j++ ) + for(auto & j : image_fn_list) { for( unsigned int k = 0; k < vec_fn_list.size(); k++ ) { double proj = 0, dotSum = 0, dotCounter = 0, dotTotal = 0; typename ReaderType::Pointer reader1 = ReaderType::New(); - reader1->SetFileName( image_fn_list[j] ); + reader1->SetFileName( j ); reader1->Update(); typename ReaderType::Pointer reader2 = ReaderType::New(); reader2->SetFileName( vec_fn_list[k] ); diff --git a/ImageRegistration/itkCrossCorrelationRegistrationFunction.cxx b/ImageRegistration/itkCrossCorrelationRegistrationFunction.cxx index c8325b379..f0f650095 100644 --- a/ImageRegistration/itkCrossCorrelationRegistrationFunction.cxx +++ b/ImageRegistration/itkCrossCorrelationRegistrationFunction.cxx @@ -63,9 +63,9 @@ ::CrossCorrelationRegistrationFunction() m_MovingImageInterpolator = static_cast( interp.GetPointer() ); - for( int i = 0; i < 5; i++ ) + for(auto & finitediffimage : finitediffimages) { - finitediffimages[i] = nullptr; + finitediffimage = nullptr; } m_NumberOfHistogramBins = 32; diff --git a/ImageRegistration/itkProbabilisticRegistrationFunction.cxx b/ImageRegistration/itkProbabilisticRegistrationFunction.cxx index 3f82ade28..b0f56e08a 100644 --- a/ImageRegistration/itkProbabilisticRegistrationFunction.cxx +++ b/ImageRegistration/itkProbabilisticRegistrationFunction.cxx @@ -60,9 +60,9 @@ ::ProbabilisticRegistrationFunction() m_MovingImageInterpolator = static_cast( interp.GetPointer() ); - for( int i = 0; i < 5; i++ ) + for(auto & finitediffimage : finitediffimages) { - finitediffimages[i] = nullptr; + finitediffimage = nullptr; } m_NumberOfHistogramBins = 32; diff --git a/ImageSegmentation/itkWeightedVotingFusionImageFilter.hxx b/ImageSegmentation/itkWeightedVotingFusionImageFilter.hxx index b7bab4e6d..476aff77a 100644 --- a/ImageSegmentation/itkWeightedVotingFusionImageFilter.hxx +++ b/ImageSegmentation/itkWeightedVotingFusionImageFilter.hxx @@ -625,11 +625,11 @@ WeightedVotingFusionImageFilter W = vnl_svd( MxBar ).solve( ones ); } - for( SizeValueType i = 0; i < W.size(); i++ ) + for(double & i : W) { - if( W[i] < 0.0 ) + if( i < 0.0 ) { - W[i] = 0.0; + i = 0.0; } } } diff --git a/Utilities/itkMultiScaleLaplacianBlobDetectorImageFilter.hxx b/Utilities/itkMultiScaleLaplacianBlobDetectorImageFilter.hxx index 26de72732..0c7302637 100644 --- a/Utilities/itkMultiScaleLaplacianBlobDetectorImageFilter.hxx +++ b/Utilities/itkMultiScaleLaplacianBlobDetectorImageFilter.hxx @@ -91,13 +91,13 @@ void MultiScaleLaplacianBlobDetectorImageFilter typedef itk::LaplacianRecursiveGaussianImageFilter LaplacianFilterType; typename LaplacianFilterType::Pointer laplacianFilter[3]; - for( unsigned int i = 0; i < 3; ++i ) + for(auto & i : laplacianFilter) { - laplacianFilter[i] = LaplacianFilterType::New(); + i = LaplacianFilterType::New(); // laplacianFilter[i]->SetNumberOfThreads( this->GetNumberOfThreads() ); - laplacianFilter[i]->SetInput( inputImage ); - laplacianFilter[i]->SetNormalizeAcrossScale( true ); - progress->RegisterInternalFilter( laplacianFilter[i], 1.0 / numberOfScales ); + i->SetInput( inputImage ); + i->SetNormalizeAcrossScale( true ); + progress->RegisterInternalFilter( i, 1.0 / numberOfScales ); } BlobHeapType blobs;