Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STYLE: Use ReadImage and WriteImage in a few iterator examples #3325

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 9 additions & 21 deletions Examples/Iterators/ImageRegionIterator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ main(int argc, char * argv[])
using IteratorType = itk::ImageRegionIterator<ImageType>;
// Software Guide : EndCodeSnippet

using ReaderType = itk::ImageFileReader<ImageType>;
using WriterType = itk::ImageFileWriter<ImageType>;

// Software Guide : BeginLatex
//
// Information about the subregion to copy is read from the command line.
Expand All @@ -108,7 +105,6 @@ main(int argc, char * argv[])
inputRegion.SetIndex(inputStart);
// Software Guide : EndCodeSnippet


// Software Guide : BeginLatex
//
// The destination region in the output image is defined using the input
Expand All @@ -129,12 +125,10 @@ main(int argc, char * argv[])
outputRegion.SetIndex(outputStart);
// Software Guide : EndCodeSnippet


auto reader = ReaderType::New();
reader->SetFileName(argv[1]);
ImageType::ConstPointer inputImage;
try
{
reader->Update();
inputImage = itk::ReadImage<ImageType>(argv[1]);
}
catch (const itk::ExceptionObject & err)
{
Expand All @@ -144,12 +138,12 @@ main(int argc, char * argv[])
}

// Check that the region is contained within the input image.
if (!reader->GetOutput()->GetRequestedRegion().IsInside(inputRegion))
if (!inputImage->GetRequestedRegion().IsInside(inputRegion))
{
std::cerr << "Error" << std::endl;
std::cerr << "The region " << inputRegion
<< "is not contained within the input image region "
<< reader->GetOutput()->GetRequestedRegion() << std::endl;
<< inputImage->GetRequestedRegion() << std::endl;
return EXIT_FAILURE;
}

Expand All @@ -170,9 +164,9 @@ main(int argc, char * argv[])
// Software Guide : BeginCodeSnippet
auto outputImage = ImageType::New();
outputImage->SetRegions(outputRegion);
const ImageType::SpacingType & spacing = reader->GetOutput()->GetSpacing();
const ImageType::PointType & inputOrigin = reader->GetOutput()->GetOrigin();
double outputOrigin[Dimension];
const ImageType::SpacingType & spacing = inputImage->GetSpacing();
const ImageType::PointType & inputOrigin = inputImage->GetOrigin();
double outputOrigin[Dimension];

for (unsigned int i = 0; i < Dimension; ++i)
{
Expand All @@ -184,7 +178,6 @@ main(int argc, char * argv[])
outputImage->Allocate();
// Software Guide : EndCodeSnippet


// Software Guide : BeginLatex
//
// \index{Iterators!construction of} \index{Iterators!and image regions}
Expand All @@ -199,7 +192,7 @@ main(int argc, char * argv[])
// Software Guide : EndLatex

// Software Guide : BeginCodeSnippet
ConstIteratorType inputIt(reader->GetOutput(), inputRegion);
ConstIteratorType inputIt(inputImage, inputRegion);
IteratorType outputIt(outputImage, outputRegion);

inputIt.GoToBegin();
Expand All @@ -213,7 +206,6 @@ main(int argc, char * argv[])
}
// Software Guide : EndCodeSnippet


// Software Guide : BeginLatex
//
// \index{Iterators!image dimensionality}
Expand All @@ -225,13 +217,9 @@ main(int argc, char * argv[])
//
// Software Guide : EndLatex

auto writer = WriterType::New();
writer->SetFileName(argv[2]);
writer->SetInput(outputImage);

try
{
writer->Update();
itk::WriteImage(outputImage, argv[2]);
}
catch (const itk::ExceptionObject & err)
{
Expand Down
12 changes: 2 additions & 10 deletions Examples/Iterators/ImageRegionIteratorWithIndex.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,11 @@ main(int argc, char * argv[])
using IteratorType = itk::ImageRegionIteratorWithIndex<ImageType>;
// Software Guide : EndCodeSnippet

using ReaderType = itk::ImageFileReader<ImageType>;
using WriterType = itk::ImageFileWriter<ImageType>;

ImageType::ConstPointer inputImage;
auto reader = ReaderType::New();
reader->SetFileName(argv[1]);
try
{
reader->Update();
inputImage = reader->GetOutput();
inputImage = itk::ReadImage<ImageType>(argv[1]);
}
catch (const itk::ExceptionObject & err)
{
Expand Down Expand Up @@ -149,12 +144,9 @@ main(int argc, char * argv[])
}
// Software Guide : EndCodeSnippet

auto writer = WriterType::New();
writer->SetFileName(argv[2]);
writer->SetInput(outputImage);
try
{
writer->Update();
itk::WriteImage(outputImage, argv[2]);
}
catch (const itk::ExceptionObject & err)
{
Expand Down
14 changes: 2 additions & 12 deletions Examples/Iterators/ImageSliceIteratorWithIndex.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,10 @@ main(int argc, char * argv[])
itk::ImageSliceConstIteratorWithIndex<ImageType3D>;
// Software Guide : EndCodeSnippet

using ReaderType = itk::ImageFileReader<ImageType3D>;
using WriterType = itk::ImageFileWriter<ImageType2D>;

ImageType3D::ConstPointer inputImage;
auto reader = ReaderType::New();
reader->SetFileName(argv[1]);
try
{
reader->Update();
inputImage = reader->GetOutput();
inputImage = itk::ReadImage<ImageType3D>(argv[1]);
}
catch (const itk::ExceptionObject & err)
{
Expand Down Expand Up @@ -187,7 +181,6 @@ main(int argc, char * argv[])
}
// Software Guide : EndCodeSnippet


// Software Guide : BeginLatex
//
// The \code{direction} array is now used to define the projection image
Expand Down Expand Up @@ -286,12 +279,9 @@ main(int argc, char * argv[])
}
// Software Guide : EndCodeSnippet

auto writer = WriterType::New();
writer->SetFileName(argv[2]);
writer->SetInput(outputImage);
try
{
writer->Update();
itk::WriteImage(outputImage, argv[2]);
}
catch (const itk::ExceptionObject & err)
{
Expand Down