diff --git a/Modules/ExampleModule/cmdapps/ExampleCmdApp.cpp b/Modules/ExampleModule/cmdapps/ExampleCmdApp.cpp index a0fb949..5c0f616 100644 --- a/Modules/ExampleModule/cmdapps/ExampleCmdApp.cpp +++ b/Modules/ExampleModule/cmdapps/ExampleCmdApp.cpp @@ -1,145 +1,145 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include #include #include #include #include /** \brief Example command-line app that demonstrates the example image filter * * This command-line app will take the first given image and add the * provided offset to each voxel. */ int main(int argc, char* argv[]) { mitkCommandLineParser parser; // Set general information about your command-line app parser.setCategory("Example Cmd App Category"); parser.setTitle("Example Cmd App"); parser.setContributor("CAMIC"); parser.setDescription( "This command-line app takes the given image and adds the provided offset to each voxel."); // How should arguments be prefixed parser.setArgumentPrefix("--", "-"); // Add arguments. Unless specified otherwise, each argument is optional. // See mitkCommandLineParser::addArgument() for more information. parser.addArgument( "input", "i", - mitkCommandLineParser::InputFile, + mitkCommandLineParser::File, "Input Image", "Any image format known to MITK.", us::Any(), false); parser.addArgument( "output", "o", - mitkCommandLineParser::OutputFile, + mitkCommandLineParser::File, "Output file", "Where to save the output.", us::Any(), false); parser.addArgument( "offset", "f", mitkCommandLineParser::Int, "Offset", "the offset integer to add to each voxel.", us::Any(), false); parser.addArgument( // optional "verbose", "v", mitkCommandLineParser::Bool, "Verbose Output", "Whether to produce verbose output"); // Parse arguments. This method returns a mapping of long argument names to // their values. auto parsedArgs = parser.parseArguments(argc, argv); if (parsedArgs.empty()) return EXIT_FAILURE; // Just exit, usage information was already printed. if (parsedArgs["input"].Empty() || parsedArgs["output"].Empty() || parsedArgs["offset"].Empty()) { MITK_INFO << parser.helpText(); return EXIT_FAILURE; } // Parse, cast and set required arguments auto inFilename = us::any_cast(parsedArgs["input"]); auto outFilename = us::any_cast(parsedArgs["output"]); auto offset = us::any_cast(parsedArgs["offset"]); // Default values for optional arguments auto verbose = false; // Parse, cast and set optional arguments if (parsedArgs.end() != parsedArgs.find("verbose")) verbose = us::any_cast(parsedArgs["verbose"]); try { if (verbose) MITK_INFO << "Read input file"; auto inImage = mitk::IOUtil::Load(inFilename); if (inImage.IsNull()) { MITK_ERROR << "Could not read \"" << inFilename << "\"!"; return EXIT_FAILURE; } if (verbose) MITK_INFO << "Add offset to image"; auto exampleFilter = ExampleImageFilter::New(); exampleFilter->SetInput(inImage); exampleFilter->SetOffset(offset); exampleFilter->Update(); auto outImage = exampleFilter->GetOutput(); if (nullptr == outImage) { MITK_ERROR << "Image processing failed!"; return EXIT_FAILURE; } if (verbose) MITK_INFO << "Write output file"; mitk::IOUtil::Save(outImage, outFilename); return EXIT_SUCCESS; } catch (const std::exception &e) { MITK_ERROR << e.what(); return EXIT_FAILURE; } catch (...) { MITK_ERROR << "Unexpected error!"; return EXIT_FAILURE; } }