Skip to content

Commit

Permalink
STYLE: Use the WriteImage convenience function in Core/Common/test
Browse files Browse the repository at this point in the history
Reduced boilerplate code by calling the convenience function.
  • Loading branch information
N-Dekker authored and hjmjohnson committed Dec 9, 2020
1 parent 60b0984 commit 4e87206
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 52 deletions.
6 changes: 1 addition & 5 deletions Modules/Core/Common/test/itkImageDuplicatorTest2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ itkImageDuplicatorTest2(int argc, char * argv[])

using ReaderType = itk::ImageFileReader<ImageType>;
ReaderType::Pointer reader = ReaderType::New();
using WriterType = itk::ImageFileWriter<ImageType>;
WriterType::Pointer writer = WriterType::New();
using DuplicatorType = itk::ImageDuplicator<ImageType>;
DuplicatorType::Pointer dup = DuplicatorType::New();
using AbsType = itk::AbsImageFilter<ImageType, ImageType>;
Expand Down Expand Up @@ -69,9 +67,7 @@ itkImageDuplicatorTest2(int argc, char * argv[])
dup->Update();
ImageType::ConstPointer dupImage = dup->GetOutput();

writer->SetInput(dupImage);
writer->SetFileName(argv[2]);
writer->Update();
itk::WriteImage(dupImage, argv[2]);
std::cout << "Test SUCCESS" << std::endl;
}
catch (const itk::ExceptionObject & e)
Expand Down
8 changes: 2 additions & 6 deletions Modules/Core/Common/test/itkImageRandomIteratorTest2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,9 @@ itkImageRandomIteratorTest2(int argc, char * argv[])
using PixelType = unsigned long;

using ImageType = itk::Image<PixelType, ImageDimension>;
using WriterType = itk::ImageFileWriter<ImageType>;

ImageType::Pointer image = ImageType::New();

WriterType::Pointer writer = WriterType::New();

ImageType::SizeType size;

size[0] = 1000;
Expand Down Expand Up @@ -84,9 +81,8 @@ itkImageRandomIteratorTest2(int argc, char * argv[])
++counter;
}

writer->SetInput(image);
writer->SetFileName(argv[1]);
writer->Update();

itk::WriteImage(image, argv[1]);

if (argc > 4)
{
Expand Down
8 changes: 1 addition & 7 deletions Modules/Core/Common/test/itkStreamingImageFilterTest3.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,7 @@ itkStreamingImageFilterTest3(int argc, char * argv[])
streamer->SetNumberOfStreamDivisions(numberOfStreamDivisions);
streamer->SetRegionSplitter(splitter);


using WriterType = itk::ImageFileWriter<ImageType>;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(outputFilename);
writer->SetInput(streamer->GetOutput());
writer->Update();

itk::WriteImage(streamer->GetOutput(), outputFilename);

unsigned int expectedNumberOfStreams =
splitter->GetNumberOfSplits(streamer->GetOutput()->GetLargestPossibleRegion(), numberOfStreamDivisions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,9 @@ itkSymmetricSecondRankTensorImageReadTest(int ac, char * av[])
++itr;
}

using MatrixWriterType = itk::ImageFileWriter<MatrixImageType>;

MatrixWriterType::Pointer matrixWriter = MatrixWriterType::New();

matrixWriter->SetInput(matrixImage);
matrixWriter->SetFileName(av[1]);

try
{
matrixWriter->Update();
itk::WriteImage(matrixImage, av[1]);
}
catch (const itk::ExceptionObject & excp)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,9 @@ itkSymmetricSecondRankTensorImageWriteReadTest(int ac, char * av[])
++itr;
}

using TensorWriterType = itk::ImageFileWriter<TensorImageType>;

TensorWriterType::Pointer tensorWriter = TensorWriterType::New();

tensorWriter->SetInput(tensorImageInput);
tensorWriter->SetFileName(av[1]);

try
{
tensorWriter->Update();
itk::WriteImage(tensorImageInput, av[1]);
}
catch (const itk::ExceptionObject & excp)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,6 @@ class CommandIterationUpdate : public itk::Command
}
};

template <typename TImage>
void
WriteImage(const TImage * out, const char * filename)
{
using WriterType = itk::ImageFileWriter<TImage>;
typename WriterType::Pointer w = WriterType::New();
w->SetInput(out);
w->SetFileName(filename);
try
{
w->Update();
}
catch (const itk::ExceptionObject & error)
{
std::cerr << error << std::endl;
}
}

template <typename TValue>
TValue
Convert(std::string optionString)
Expand Down

0 comments on commit 4e87206

Please sign in to comment.