From 04438e5d4bb44c4b85efd5e8ad2f411c17151f0b Mon Sep 17 00:00:00 2001 From: "Christian P. V. Christoffersen" <88783438+br-cpvc@users.noreply.github.com> Date: Tue, 6 Sep 2022 12:14:48 +0200 Subject: [PATCH 1/2] graceful exit Atropos in case of non-existing input files --- Examples/Atropos.cxx | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Examples/Atropos.cxx b/Examples/Atropos.cxx index bc0d7ac63..778f6ffe0 100644 --- a/Examples/Atropos.cxx +++ b/Examples/Atropos.cxx @@ -206,7 +206,11 @@ AtroposSegmentation(itk::ants::CommandLineParser * parser) for (unsigned int k = 0; k < imageNames.size(); k++) { typename InputImageType::Pointer image; - ReadImage(image, imageNames[k].c_str()); + if (!ReadImage(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); } } @@ -373,7 +377,11 @@ AtroposSegmentation(itk::ants::CommandLineParser * parser) try { typename LabelImageType::Pointer image; - ReadImage(image, maskOption->GetFunction(0)->GetName().c_str()); + if (!ReadImage(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 @@ -600,7 +608,11 @@ AtroposSegmentation(itk::ants::CommandLineParser * parser) imagename = imageOption->GetFunction(n)->GetName(); } typename InputImageType::Pointer image; - ReadImage(image, imagename.c_str()); + if (!ReadImage(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) { From 3dc16a772770ca18ad6505c1c9540e7b44bd3317 Mon Sep 17 00:00:00 2001 From: "Christian P. V. Christoffersen" <88783438+br-cpvc@users.noreply.github.com> Date: Wed, 7 Sep 2022 10:41:08 +0000 Subject: [PATCH 2/2] fixup! graceful exit Atropos in case of non-existing input files --- Examples/Atropos.cxx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Examples/Atropos.cxx b/Examples/Atropos.cxx index 778f6ffe0..28158c4cb 100644 --- a/Examples/Atropos.cxx +++ b/Examples/Atropos.cxx @@ -218,7 +218,11 @@ AtroposSegmentation(itk::ants::CommandLineParser * parser) { using VectorImageType = itk::VectorImage; typename VectorImageType::Pointer image; - ReadImage(image, filename.c_str()); + if (!ReadImage(image, filename.c_str())) + { + std::cout << "Input prior probability image could not be read." << std::endl; + return EXIT_FAILURE; + } if (image->GetNumberOfComponentsPerPixel() != segmenter->GetNumberOfTissueClasses()) { @@ -264,7 +268,11 @@ AtroposSegmentation(itk::ants::CommandLineParser * parser) std::string filename = initializationOption->GetFunction(0)->GetParameter(1); typename LabelImageType::Pointer image; - ReadImage(image, filename.c_str()); + if (!ReadImage(image, filename.c_str())) + { + std::cout << "Input prior label image could not be read." << std::endl; + return EXIT_FAILURE; + } segmenter->SetPriorLabelImage(image); } else