Skip to content

Commit

Permalink
STYLE: Use reange-baed loops from C++11
Browse files Browse the repository at this point in the history
C++11 Range based for loops can be used in

Used as a more readable equivalent to the traditional for loop operating over a
range of values, such as all elements in a container, in the forward direction..

Range based loopes are more explicit for only computing the
end location once for containers.

SRCDIR=/Users/johnsonhj/src/BT-11/ANTs #My local SRC
BLDDIR=/Users/johnsonhj/src/BT-11/ANTs-build #My local BLD

cd /Users/johnsonhj/src/BT-11/ANTs-build
run-clang-tidy.py -extra-arg=-D__clang__ -checks=-*,modernize-loop-convert  -header-filter=.* -fix
  • Loading branch information
hjmjohnson committed Nov 8, 2018
1 parent 827aff4 commit 0003573
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 39 deletions.
4 changes: 2 additions & 2 deletions Examples/ANTSJacobian.cxx
Expand Up @@ -181,9 +181,9 @@ ComputeJacobian(TDisplacementField* field, char* fnm, char* maskfn, bool uselog
if( projvec.length() > 2 )
{
antsjacobiansplit(projvec, 'x', v);
for( std::vector<std::string>::size_type i = 0; i < v.size(); ++i )
for(const auto & i : v)
{
std::cout << v[i] << '\n';
std::cout << i << '\n';
}
}

Expand Down
4 changes: 2 additions & 2 deletions Examples/ConvertImage.cxx
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Examples/CreateDTICohort.cxx
Expand Up @@ -604,9 +604,9 @@ int CreateDTICohort( itk::ants::CommandLineParser *parser )
if( applyISV )
{
vnl_vector<RealType> 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;
}
Expand Down
14 changes: 7 additions & 7 deletions Examples/ImageMath_Templates.hxx
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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() ) )
Expand Down
4 changes: 1 addition & 3 deletions Examples/LabelOverlapMeasures.cxx
Expand Up @@ -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 );
Expand Down
6 changes: 3 additions & 3 deletions Examples/PrintHeader.cxx
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions Examples/antsAI.cxx
Expand Up @@ -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<ImageType, RealType> ScalarInterpolatorType;
Expand Down
4 changes: 2 additions & 2 deletions Examples/antsMotionCorr.cxx
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions Examples/antsSliceRegularizedRegistration.cxx
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Examples/sccan.cxx
Expand Up @@ -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<ImageType> 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] );
Expand Down
4 changes: 2 additions & 2 deletions ImageRegistration/itkCrossCorrelationRegistrationFunction.cxx
Expand Up @@ -63,9 +63,9 @@ ::CrossCorrelationRegistrationFunction()

m_MovingImageInterpolator = static_cast<InterpolatorType *>(
interp.GetPointer() );
for( int i = 0; i < 5; i++ )
for(auto & finitediffimage : finitediffimages)
{
finitediffimages[i] = nullptr;
finitediffimage = nullptr;
}

m_NumberOfHistogramBins = 32;
Expand Down
4 changes: 2 additions & 2 deletions ImageRegistration/itkProbabilisticRegistrationFunction.cxx
Expand Up @@ -60,9 +60,9 @@ ::ProbabilisticRegistrationFunction()

m_MovingImageInterpolator = static_cast<InterpolatorType *>(
interp.GetPointer() );
for( int i = 0; i < 5; i++ )
for(auto & finitediffimage : finitediffimages)
{
finitediffimages[i] = nullptr;
finitediffimage = nullptr;
}

m_NumberOfHistogramBins = 32;
Expand Down
6 changes: 3 additions & 3 deletions ImageSegmentation/itkWeightedVotingFusionImageFilter.hxx
Expand Up @@ -625,11 +625,11 @@ WeightedVotingFusionImageFilter<TInputImage, TOutputImage>
W = vnl_svd<RealType>( 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;
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions Utilities/itkMultiScaleLaplacianBlobDetectorImageFilter.hxx
Expand Up @@ -91,13 +91,13 @@ void MultiScaleLaplacianBlobDetectorImageFilter<TInputImage>

typedef itk::LaplacianRecursiveGaussianImageFilter<InputImageType, RealImageType> 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;
Expand Down

0 comments on commit 0003573

Please sign in to comment.