Skip to content

Commit

Permalink
Merge pull request #1422 from br-cpvc/upstream_20220906_1215
Browse files Browse the repository at this point in the history
ENH: graceful exit Atropos in case of non-existing input files
  • Loading branch information
cookpa authored Sep 7, 2022
2 parents e043d8a + 3dc16a7 commit 5e757c8
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions Examples/Atropos.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,23 @@ AtroposSegmentation(itk::ants::CommandLineParser * parser)
for (unsigned int k = 0; k < imageNames.size(); k++)
{
typename InputImageType::Pointer image;
ReadImage<InputImageType>(image, imageNames[k].c_str());
if (!ReadImage<InputImageType>(image, imageNames[k].c_str()))
{
std::cout << "Input prior probability image could not be read: " << imageNames[k] << std::endl;
return EXIT_FAILURE;
}
segmenter->SetPriorProbabilityImage(k + 1, image);
}
}
else
{
using VectorImageType = itk::VectorImage<PixelType, ImageDimension>;
typename VectorImageType::Pointer image;
ReadImage<VectorImageType>(image, filename.c_str());
if (!ReadImage<VectorImageType>(image, filename.c_str()))
{
std::cout << "Input prior probability image could not be read." << std::endl;
return EXIT_FAILURE;
}

if (image->GetNumberOfComponentsPerPixel() != segmenter->GetNumberOfTissueClasses())
{
Expand Down Expand Up @@ -260,7 +268,11 @@ AtroposSegmentation(itk::ants::CommandLineParser * parser)

std::string filename = initializationOption->GetFunction(0)->GetParameter(1);
typename LabelImageType::Pointer image;
ReadImage<LabelImageType>(image, filename.c_str());
if (!ReadImage<LabelImageType>(image, filename.c_str()))
{
std::cout << "Input prior label image could not be read." << std::endl;
return EXIT_FAILURE;
}
segmenter->SetPriorLabelImage(image);
}
else
Expand Down Expand Up @@ -373,7 +385,11 @@ AtroposSegmentation(itk::ants::CommandLineParser * parser)
try
{
typename LabelImageType::Pointer image;
ReadImage<LabelImageType>(image, maskOption->GetFunction(0)->GetName().c_str());
if (!ReadImage<LabelImageType>(image, maskOption->GetFunction(0)->GetName().c_str()))
{
std::cout << "Input mask image could not be read." << std::endl;
return EXIT_FAILURE;
}
segmenter->SetMaskImage(image);

// Check to see that the labels in the prior label image or the non-zero
Expand Down Expand Up @@ -600,7 +616,11 @@ AtroposSegmentation(itk::ants::CommandLineParser * parser)
imagename = imageOption->GetFunction(n)->GetName();
}
typename InputImageType::Pointer image;
ReadImage<InputImageType>(image, imagename.c_str());
if (!ReadImage<InputImageType>(image, imagename.c_str()))
{
std::cout << "Input intensity image could not be read." << std::endl;
return EXIT_FAILURE;
}
segmenter->SetIntensityImage(count, image);
if (imageOption->GetFunction(count)->GetNumberOfParameters() > 1)
{
Expand Down

0 comments on commit 5e757c8

Please sign in to comment.