Skip to content

Commit

Permalink
STYLE: Prefer C++11 type alias over typedef
Browse files Browse the repository at this point in the history
== http://en.cppreference.com/w/cpp/language/type_alias ==

Type alias is a name that refers to a previously defined type (similar
to typedef).

A type alias declaration introduces a name which can be used as a
synonym for the type denoted by type-id. It does not introduce a new
type and it cannot change the meaning of an existing type name. There is
no difference between a type alias declaration and typedef declaration.
This declaration may appear in block scope, class scope, or namespace
scope.

== https://www.quora.com/Is-using-typedef-in-C++-considered-a-bad-practice ==

While typedef is still available for backward compatibility, the new
Type Alias syntax 'using Alias = ExistingLongName;' is more consistent
with the flow of C++ than the old typedef syntax 'typedef
ExistingLongName Alias;', and it also works for templates (Type alias,
alias template (since C++11)), so leftover 'typedef' aliases will differ
in style from any alias templates.
  • Loading branch information
hjmjohnson committed Feb 13, 2018
1 parent 2b82c02 commit 5fc4461
Show file tree
Hide file tree
Showing 365 changed files with 2,023 additions and 2,187 deletions.
7 changes: 3 additions & 4 deletions Broken/EdgesAndGradients/CannyEdgeDetectionImageFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ int main(int argc, char *argv[])
upperThreshold = atof(argv[4]);
}

typedef itk::Image<double, 2> DoubleImageType;
using DoubleImageType = itk::Image<double, 2>;

typedef itk::ImageFileReader<DoubleImageType> ReaderType;
using ReaderType = itk::ImageFileReader<DoubleImageType>;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(argv[1]);

typedef itk::CannyEdgeDetectionImageFilter <DoubleImageType, DoubleImageType>
CannyEdgeDetectionImageFilterType;
using CannyEdgeDetectionImageFilterType = itk::CannyEdgeDetectionImageFilter <DoubleImageType, DoubleImageType>;

CannyEdgeDetectionImageFilterType::Pointer cannyFilter
= CannyEdgeDetectionImageFilterType::New();
Expand Down
16 changes: 8 additions & 8 deletions Broken/Functions/GaussianBlurImageFunctionFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ int main( int argc, char * argv[] )
ss >> maxKernelWidth;
}

typedef itk::Image< float, 2 > ImageType;
typedef itk::ImageFileReader< ImageType > ReaderType;
typedef itk::ImageRegionIterator< ImageType > IteratorType;
typedef itk::ImageRegionConstIterator< ImageType > ConstIteratorType;
using ImageType = itk::Image< float, 2 >;
using ReaderType = itk::ImageFileReader< ImageType >;
using IteratorType = itk::ImageRegionIterator< ImageType >;
using ConstIteratorType = itk::ImageRegionConstIterator< ImageType >;

ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( inputFileName );
Expand Down Expand Up @@ -65,16 +65,16 @@ int main( int argc, char * argv[] )
}
*/

typedef itk::GaussianBlurImageFunction< ImageType > GaussianBlurImageFunctionType;
using GaussianBlurImageFunctionType = itk::GaussianBlurImageFunction< ImageType >;
// SetFunctor seems to need an actual object (not a pointer), but we can't create one like this:
//GaussianBlurImageFunctionType gaussianFunction;

GaussianBlurImageFunctionType::Pointer gaussianFunction = GaussianBlurImageFunctionType::New();
//gaussianFunction->SetInputImage( reader->GetOutput() ); // Do we need to do this since we are going to do unaryFunctor->SetInput?


typedef itk::UnaryFunctorImageFilter<ImageType,ImageType,
GaussianBlurImageFunctionType> FilterType;
using FilterType = itk::UnaryFunctorImageFilter<ImageType,ImageType,
GaussianBlurImageFunctionType>;
FilterType::Pointer filter = FilterType::New();
filter->SetInput(reader->GetOutput());

Expand All @@ -86,7 +86,7 @@ int main( int argc, char * argv[] )

filter->Update();

typedef itk::ImageFileWriter < ImageType > WriterType;
using WriterType = itk::ImageFileWriter < ImageType >;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(outputFileName);
writer->SetInput(filter->GetOutput());
Expand Down
8 changes: 4 additions & 4 deletions Broken/ImageProcessing/GradientOfVectorImage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
int main(int argc, char * argv[])
{
// Setup types
typedef itk::CovariantVector<float, 2> VectorType;
typedef itk::Image<VectorType, 2> VectorImageType;
using VectorType = itk::CovariantVector<float, 2>;
using VectorImageType = itk::Image<VectorType, 2>;
VectorImageType::Pointer image = VectorImageType::New();

itk::Size<2> size;
Expand All @@ -32,8 +32,8 @@ int main(int argc, char * argv[])
}

// Create and setup a gradient filter
typedef itk::GradientImageFilter<
VectorImageType, VectorType> GradientFilterType;
using GradientFilterType = itk::GradientImageFilter<
VectorImageType, VectorType>;
GradientFilterType::Pointer gradientFilter = GradientFilterType::New();
gradientFilter->SetInput(image);
gradientFilter->Update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include "itkTranslationTransform.h"
#include "itkLinearInterpolateImageFunction.h"

//typedef itk::Image< unsigned char, 2> ImageType;
typedef itk::Image< float, 2> ImageType;
//using ImageType = itk::Image< unsigned char, 2>;
using ImageType = itk::Image< float, 2>;

int main( int argc, char *argv[] )
{
Expand All @@ -30,10 +30,10 @@ int main( int argc, char *argv[] )
//ImageType::Pointer movingImage = randomImageSource2->GetOutput();
ImageType::Pointer movingImage = randomImageSource1->GetOutput();

typedef itk::TranslationTransform<double, 2> TranslationTransformType; // This cannot be float for some reason?
using TranslationTransformType = itk::TranslationTransform<double, 2>; // This cannot be float for some reason?
TranslationTransformType::Pointer transform = TranslationTransformType::New();

typedef itk::MutualInformationImageToImageMetric<ImageType, ImageType > MetricType;
using MetricType = itk::MutualInformationImageToImageMetric<ImageType, ImageType >;

MetricType::Pointer metric = MetricType::New();

Expand Down
6 changes: 3 additions & 3 deletions Broken/Images/ConnectedThresholdImageFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "vtkInteractorStyleImage.h"
#include "vtkRenderer.h"

typedef itk::Image< PixelType, Dimension > ImageType;
using ImageType = itk::Image< PixelType, Dimension >;

static void CreateImage(ImageType::Pointer image);

Expand All @@ -21,7 +21,7 @@ int main( int argc, char *argv[])
ImageType::Pointer image = ImageType::New();
CreateImage(image);

typedef itk::ConnectedThresholdImageFilter<ImageType, ImageType> ConnectedFilterType;
using ConnectedFilterType = itk::ConnectedThresholdImageFilter<ImageType, ImageType>;
ConnectedFilterType::Pointer connectedThreshold = ConnectedFilterType::New();
float lower = 95.0;
float upper = 105.0;
Expand All @@ -47,7 +47,7 @@ int main( int argc, char *argv[])
connectedThreshold->SetInput(image);

// Visualize
typedef itk::ImageToVTKImageFilter<ImageType> ConnectorType;
using ConnectorType = itk::ImageToVTKImageFilter<ImageType>;
ConnectorType::Pointer connector2 = ConnectorType::New();
connector2->SetInput(image2);

Expand Down
12 changes: 6 additions & 6 deletions Broken/Images/GradientImageFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@ int main(int argc, char * argv[])
std::string inputFilename = argv[1];

// Setup types
typedef itk::Image< float, 2 > FloatImageType;
typedef itk::Image< unsigned char, 2 > UnsignedCharImageType;
using FloatImageType = itk::Image< float, 2 >;
using UnsignedCharImageType = itk::Image< unsigned char, 2 >;

// Create and setup a reader
typedef itk::ImageFileReader< UnsignedCharImageType > ReaderType;
using ReaderType = itk::ImageFileReader< UnsignedCharImageType >;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( inputFilename.c_str() );

// Create and setup a gradient filter
typedef itk::GradientImageFilter<
UnsignedCharImageType, float> GradientFilterType;
using GradientFilterType = itk::GradientImageFilter<
UnsignedCharImageType, float>;
GradientFilterType::Pointer gradientFilter = GradientFilterType::New();
gradientFilter->SetInput( reader->GetOutput() );
gradientFilter->Update();

// Visualize original image
typedef itk::ImageToVTKImageFilter<UnsignedCharImageType> ConnectorType;
using ConnectorType = itk::ImageToVTKImageFilter<UnsignedCharImageType>;
ConnectorType::Pointer originalConnector = ConnectorType::New();
originalConnector->SetInput(reader->GetOutput());

Expand Down
9 changes: 4 additions & 5 deletions Broken/Images/InPlace.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "vtkInteractorStyleImage.h"
#include "vtkRenderer.h"

typedef itk::Image< unsigned char, 2 > ImageType;
using ImageType = itk::Image< unsigned char, 2 >;

static void ApplyThresholding(ImageType::Pointer image);

Expand All @@ -25,7 +25,7 @@ int main(int argc, char *argv[])

std::string inputFilename = argv[1];

typedef itk::ImageFileReader<ImageType> ReaderType;
using ReaderType = itk::ImageFileReader<ImageType>;
ReaderType::Pointer reader = ReaderType::New();

reader->SetFileName(inputFilename.c_str());
Expand All @@ -36,7 +36,7 @@ int main(int argc, char *argv[])
ApplyThresholding(image);

// Visualize
typedef itk::ImageToVTKImageFilter<ImageType> ConnectorType;
using ConnectorType = itk::ImageToVTKImageFilter<ImageType>;
ConnectorType::Pointer connector = ConnectorType::New();
connector->SetInput(image);

Expand Down Expand Up @@ -74,8 +74,7 @@ int main(int argc, char *argv[])
void ApplyThresholding(ImageType::Pointer image)
{

typedef itk::BinaryThresholdImageFilter <ImageType, ImageType>
BinaryThresholdImageFilterType;
using BinaryThresholdImageFilterType = itk::BinaryThresholdImageFilter <ImageType, ImageType>;

BinaryThresholdImageFilterType::Pointer thresholdFilter
= BinaryThresholdImageFilterType::New();
Expand Down
14 changes: 7 additions & 7 deletions Broken/Images/NormalizedCorrelationImageFilterMasked.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#include <iostream>
#include <string>

typedef itk::Image<unsigned char, 2> ImageType;
typedef itk::Image<unsigned char, 2> MaskType;
typedef itk::Image<float, 2> FloatImageType;
using ImageType = itk::Image<unsigned char, 2>;
using MaskType = itk::Image<unsigned char, 2>;
using FloatImageType = itk::Image<float, 2>;

void CreateMask(MaskType* const mask);
void CreateImage(ImageType* const image);
Expand Down Expand Up @@ -71,7 +71,7 @@ int main(int argc, char *argv[])

// Perform normalized correlation
// <input type, mask type, output type>
typedef itk::NormalizedCorrelationImageFilter<ImageType, MaskType, FloatImageType, unsigned char> CorrelationFilterType;
using CorrelationFilterType = itk::NormalizedCorrelationImageFilter<ImageType, MaskType, FloatImageType, unsigned char>;
CorrelationFilterType::Pointer correlationFilter = CorrelationFilterType::New();
correlationFilter->SetInput(image2);
correlationFilter->SetMaskImage(mask);
Expand All @@ -80,15 +80,15 @@ int main(int argc, char *argv[])

WriteImage(correlationFilter->GetOutput(), "correlation.mha");

typedef itk::RescaleIntensityImageFilter<FloatImageType, ImageType> RescaleFilterType;
using RescaleFilterType = itk::RescaleIntensityImageFilter<FloatImageType, ImageType>;
RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New();
rescaleFilter->SetInput(correlationFilter->GetOutput());
rescaleFilter->SetOutputMinimum(0);
rescaleFilter->SetOutputMaximum(255);
rescaleFilter->Update();
WriteImage(rescaleFilter->GetOutput(), "correlation.png");

typedef itk::MinimumMaximumImageCalculator<FloatImageType> MinimumMaximumImageCalculatorType;
using MinimumMaximumImageCalculatorType = itk::MinimumMaximumImageCalculator<FloatImageType>;
MinimumMaximumImageCalculatorType::Pointer minimumMaximumImageCalculatorFilter = MinimumMaximumImageCalculatorType::New ();
minimumMaximumImageCalculatorFilter->SetImage(correlationFilter->GetOutput());
minimumMaximumImageCalculatorFilter->Compute();
Expand Down Expand Up @@ -190,7 +190,7 @@ void CreateImageOfSquare(ImageType* const image, const itk::Index<2>& cornerOfSq
template <typename TImage>
void WriteImage(const TImage* const image, const std::string& filename)
{
typedef itk::ImageFileWriter<TImage> WriterType;
using WriterType = itk::ImageFileWriter<TImage>;
typename WriterType::Pointer writer = WriterType::New();
writer->SetFileName(filename);
writer->SetInput(image);
Expand Down
6 changes: 3 additions & 3 deletions Broken/Images/RegionGrowImageFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "vtkInteractorStyleImage.h"
#include "vtkRenderer.h"

typedef itk::Image< PixelType, Dimension > ImageType;
using ImageType = itk::Image< PixelType, Dimension >;

static void CreateImage(ImageType::Pointer image);

Expand All @@ -21,7 +21,7 @@ int main( int argc, char *argv[])
ImageType::Pointer image = ImageType::New();
CreateImage(image);

typedef itk::RegionGrowImageFilter<ImageType, ImageType> RegionGrowImageFilterType;
using RegionGrowImageFilterType = itk::RegionGrowImageFilter<ImageType, ImageType>;
RegionGrowImageFilterType::Pointer regionGrow = RegionGrowImageFilterType::New();
float lower = 95.0;
float upper = 105.0;
Expand All @@ -47,7 +47,7 @@ int main( int argc, char *argv[])
regionGrow->SetInput(image);

// Visualize
typedef itk::ImageToVTKImageFilter<ImageType> ConnectorType;
using ConnectorType = itk::ImageToVTKImageFilter<ImageType>;
ConnectorType::Pointer connector2 = ConnectorType::New();
connector2->SetInput(image2);

Expand Down
4 changes: 2 additions & 2 deletions Broken/Images/VTKImageToImageFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ int main(int argc, char*argv[])
luminanceFilter->SetInputConnection(reader->GetOutputPort());
luminanceFilter->Update();

typedef itk::Image<unsigned char, 2> ImageType;
using ImageType = itk::Image<unsigned char, 2>;

typedef itk::VTKImageToImageFilter<ImageType> VTKImageToImageType;
using VTKImageToImageType = itk::VTKImageToImageFilter<ImageType>;

VTKImageToImageType::Pointer vtkImageToImageFilter = VTKImageToImageType::New();
vtkImageToImageFilter->SetInput(luminanceFilter->GetOutput());
Expand Down
6 changes: 3 additions & 3 deletions Broken/SimpleOperations/MetaDataDictionary.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <itkImageFileWriter.h>
#include <itkImageFileReader.h>

typedef itk::Image<unsigned char, 2> ImageType;
using ImageType = itk::Image<unsigned char, 2>;

static void CreateImage(ImageType::Pointer image);

Expand Down Expand Up @@ -36,14 +36,14 @@ int main(int, char*[])
}

// Write the image (and the data) to a file
typedef itk::ImageFileWriter< ImageType > WriterType;
using WriterType = itk::ImageFileWriter< ImageType >;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName("test.mhd");
writer->SetInput(image);
writer->Update();

// Read the image (and data) from the file
typedef itk::ImageFileReader<ImageType> ReaderType;
using ReaderType = itk::ImageFileReader<ImageType>;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName("test.mhd");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
int main(int, char*[])
{
unsigned int numberOfClasses = 2;
typedef itk::Vector< double, 1 > MeasurementVectorType;
typedef itk::Statistics::ListSample< MeasurementVectorType > SampleType;
using MeasurementVectorType = itk::Vector< double, 1 >;
using SampleType = itk::Statistics::ListSample< MeasurementVectorType >;
SampleType::Pointer sample = SampleType::New();

typedef itk::Statistics::NormalVariateGenerator NormalGeneratorType;
using NormalGeneratorType = itk::Statistics::NormalVariateGenerator;
NormalGeneratorType::Pointer normalGenerator = NormalGeneratorType::New();

normalGenerator->Initialize(101);
Expand All @@ -36,7 +36,7 @@ int main(int, char*[])
sample->PushBack( mv );
}

typedef itk::Array< double > ParametersType;
using ParametersType = itk::Array< double >;
ParametersType params1( 2 );

std::vector< ParametersType > initialParameters( numberOfClasses );
Expand All @@ -49,18 +49,18 @@ int main(int, char*[])
params2[1] = 50.0;
initialParameters[1] = params2;

typedef itk::Statistics::GaussianMixtureModelComponent< SampleType > ComponentType;
using ComponentType = itk::Statistics::GaussianMixtureModelComponent< SampleType >;

std::vector< ComponentType::Pointer > components;
for ( unsigned int i = 0 ; i < numberOfClasses ; i++ )
for ( unsigned int i = 0; i < numberOfClasses; i++ )
{
components.push_back( ComponentType::New() );
components[i]->SetSample( sample );
components[i]->SetParameters( initialParameters[i] );
}

typedef itk::Statistics::ExpectationMaximizationMixtureModelEstimator<
SampleType > EstimatorType;
using EstimatorType = itk::Statistics::ExpectationMaximizationMixtureModelEstimator<
SampleType >;
EstimatorType::Pointer estimator = EstimatorType::New();

estimator->SetSample(sample);
Expand Down
Loading

0 comments on commit 5fc4461

Please sign in to comment.