diff --git a/Modules/MatchPointRegistration/algorithms/mitkMultiModalRigidHeadNeckRegistrationAlgorithm.h b/Modules/MatchPointRegistration/algorithms/mitkMultiModalRigidHeadNeckRegistrationAlgorithm.h index b73c05ab33..64661706e1 100644 --- a/Modules/MatchPointRegistration/algorithms/mitkMultiModalRigidHeadNeckRegistrationAlgorithm.h +++ b/Modules/MatchPointRegistration/algorithms/mitkMultiModalRigidHeadNeckRegistrationAlgorithm.h @@ -1,28 +1,28 @@ /*============================================================================ 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. ============================================================================*/ #ifndef mitkMultiModalRigidHeadNeckRegistrationAlgorithm_h #define mitkMultiModalRigidHeadNeckRegistrationAlgorithm_h -#include "mapDiscreteElements.h" -#include "mapITKRigid3DMattesMIHeadNeckRegistrationAlgorithmTemplate.h" -#include "mapConfigure.h" +#include <mapDiscreteElements.h> +#include <mapITKRigid3DMattesMIHeadNeckRegistrationAlgorithmTemplate.h> +#include <mapConfigure.h> -#include "mitkMultiModalRigidHeadNeckRegistrationAlgorithm_ProfileResource.h" +#include <mitkMultiModalRigidHeadNeckRegistrationAlgorithm_ProfileResource.h> namespace mitk { template <class TImageType> using MultiModalRigidHeadNeckRegistrationAlgorithm = typename map::algorithm::boxed::MultiModalRigidHeadNeckRegistrationAlgorithm<TImageType, ::map::algorithm::mitkMultiModalRigidHeadNeckRegistrationAlgorithmUIDPolicy>; } -#endif \ No newline at end of file +#endif diff --git a/Modules/MatchPointRegistration/algorithms/mitkMultiModalRigidSlabbedHeadRegistrationAlgorithm.h b/Modules/MatchPointRegistration/algorithms/mitkMultiModalRigidSlabbedHeadRegistrationAlgorithm.h index 925c5484a2..71674fe153 100644 --- a/Modules/MatchPointRegistration/algorithms/mitkMultiModalRigidSlabbedHeadRegistrationAlgorithm.h +++ b/Modules/MatchPointRegistration/algorithms/mitkMultiModalRigidSlabbedHeadRegistrationAlgorithm.h @@ -1,28 +1,28 @@ /*============================================================================ 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. ============================================================================*/ #ifndef mitkMultiModalRigidSlabbedHeadRegistrationAlgorithm_h #define mitkMultiModalRigidSlabbedHeadRegistrationAlgorithm_h -#include "mapDiscreteElements.h" -#include "mapITKRigid3DMattesMISlabbedHeadRegistrationAlgorithmTemplate.h" -#include "mapConfigure.h" +#include <mapDiscreteElements.h> +#include <mapITKRigid3DMattesMISlabbedHeadRegistrationAlgorithmTemplate.h> +#include <mapConfigure.h> -#include "mitkMultiModalRigidSlabbedHeadRegistrationAlgorithm_ProfileResource.h" +#include <mitkMultiModalRigidSlabbedHeadRegistrationAlgorithm_ProfileResource.h> namespace mitk { template <class TImageType> using MultiModalRigidSlabbedHeadRegistrationAlgorithm = typename map::algorithm::boxed::MultiModalRigidSlabbedHeadRegistrationAlgorithm<TImageType, ::map::algorithm::mitkMultiModalRigidSlabbedHeadRegistrationAlgorithmUIDPolicy>; } -#endif \ No newline at end of file +#endif diff --git a/Modules/MatchPointRegistration/cmdapps/MapImageMiniApp.cpp b/Modules/MatchPointRegistration/cmdapps/MapImageMiniApp.cpp index 6159b4d6d4..3b57cb5023 100644 --- a/Modules/MatchPointRegistration/cmdapps/MapImageMiniApp.cpp +++ b/Modules/MatchPointRegistration/cmdapps/MapImageMiniApp.cpp @@ -1,281 +1,286 @@ /*============================================================================ 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. ============================================================================*/ // std includes #include <string> #include <numeric> // itk includes -#include "itksys/SystemTools.hxx" +//#include <itksys/SystemTools.hxx> // CTK includes -#include "mitkCommandLineParser.h" +#include <mitkCommandLineParser.h> // MITK includes #include <mitkIOUtil.h> #include <mitkPreferenceListReaderOptionsFunctor.h> #include <mitkMAPRegistrationWrapper.h> #include <mitkMAPAlgorithmHelper.h> #include <mitkImageStitchingHelper.h> -std::string inFileName = ""; -std::string regFileName = ""; -std::string outFileName = ""; -std::string refGeometryFileName = ""; +struct Settings +{ + std::string inFileName = ""; + std::string regFileName = ""; + std::string outFileName = ""; + std::string refGeometryFileName = ""; -mitk::Image::ConstPointer inputImage; -mitk::MAPRegistrationWrapper::ConstPointer registration; -mitk::BaseGeometry::Pointer refGeometry; -mitk::ImageMappingInterpolator::Type interpolatorType = mitk::ImageMappingInterpolator::Linear; -double paddingValue = 0; -std::vector<unsigned int> superSamplingFactors; + mitk::ImageMappingInterpolator::Type interpolatorType = mitk::ImageMappingInterpolator::Linear; + double paddingValue = 0; + std::vector<unsigned int> superSamplingFactors; +}; void setupParser(mitkCommandLineParser& parser) { // set general information about your MiniApp parser.setCategory("Registration Tools"); parser.setTitle("Map Image"); parser.setDescription("MiniApp that allows to map a image into a given output geometry by using a given registration."); parser.setContributor("MIC, German Cancer Research Center (DKFZ)"); //! [create parser] //! [add arguments] // how should arguments be prefixed parser.setArgumentPrefix("--", "-"); // add each argument, unless specified otherwise each argument is optional // see mitkCommandLineParser::addArgument for more information parser.beginGroup("Required I/O parameters"); parser.addArgument( "input", "i", mitkCommandLineParser::File, "Input image", "Path to the input images that should be mapped", us::Any(), false, false, false, mitkCommandLineParser::Input); parser.addArgument("output", "o", mitkCommandLineParser::File, "Output file path", "Path to the maped image.", us::Any(), false, false, false, mitkCommandLineParser::Output); parser.endGroup(); parser.beginGroup("Optional parameters"); parser.addArgument( "registration", "r", mitkCommandLineParser::File, "Registration filee", "Path to the registration that should be used. If no registration is specified, an identity transform is assumed.", us::Any(), true, false, false, mitkCommandLineParser::Input); parser.addArgument("template", "t", mitkCommandLineParser::File, "Output template image.", "File path to an image that serves as template for the output geometry. If no template is specified, the geometry of the input image will be used.", us::Any(), false, false, false, mitkCommandLineParser::Input); parser.addArgument( "registrations", "r", mitkCommandLineParser::StringList, "Registration files", "Pathes to the registrations that should be used to map the input images. If this parameter is not set, identity transforms are assumed. If this parameter is set, it must have the same number of entries then the parameter inputs. If you want to use and identity transform for a specific input, specify an empty string. The application assumes that inputs and registrations have the same order, so the n-th input should use thr n-th registration.", us::Any(), true, false, false, mitkCommandLineParser::Input); parser.addArgument("interpolator", "n", mitkCommandLineParser::Int, "Interpolator type", "Interpolator used for mapping the images. Default: 2; allowed values: 1: Nearest Neighbour, 2: Linear, 3: BSpline 3, 4: WSinc Hamming, 5: WSinc Welch", us::Any(2), true); parser.addArgument("padding", "p", mitkCommandLineParser::Float, "Padding value", "Value used for output voxels that are not covered by any input image.", us::Any(0.), true); parser.addArgument("super-sampling", "s", mitkCommandLineParser::StringList, "Super sampling factor", "Value used for super sampling of the result. E.g. factor 2 will lead to a doubled resolution compared to the used template. If not specified, no super sampling will be done.", us::Any(), true); parser.addArgument("help", "h", mitkCommandLineParser::Bool, "Help:", "Show this help text"); parser.endGroup(); //! [add arguments] } -bool configureApplicationSettings(std::map<std::string, us::Any> parsedArgs) +bool configureApplicationSettings(std::map<std::string, us::Any> parsedArgs, Settings& settings) { try { if (parsedArgs.size() == 0) return false; - inFileName = us::any_cast<std::string>(parsedArgs["input"]); - outFileName = us::any_cast<std::string>(parsedArgs["output"]); + settings.inFileName = us::any_cast<std::string>(parsedArgs["input"]); + settings.outFileName = us::any_cast<std::string>(parsedArgs["output"]); if (parsedArgs.count("template")) { - refGeometryFileName = us::any_cast<std::string>(parsedArgs["template"]); + settings.refGeometryFileName = us::any_cast<std::string>(parsedArgs["template"]); } if (parsedArgs.count("registration")) { - regFileName = us::any_cast<std::string>(parsedArgs["registration"]); + settings.regFileName = us::any_cast<std::string>(parsedArgs["registration"]); } if (parsedArgs.count("interpolator")) { auto interpolator = us::any_cast<int>(parsedArgs["interpolator"]); - interpolatorType = static_cast<mitk::ImageMappingInterpolator::Type>(interpolator); + settings.interpolatorType = static_cast<mitk::ImageMappingInterpolator::Type>(interpolator); } if (parsedArgs.count("padding")) { - paddingValue = us::any_cast<float>(parsedArgs["padding"]); + settings.paddingValue = us::any_cast<float>(parsedArgs["padding"]); } - superSamplingFactors.clear(); + settings.superSamplingFactors.clear(); if (parsedArgs.count("super-sampling")) { try { auto samplingStrings = us::any_cast<mitkCommandLineParser::StringContainerType>(parsedArgs["super-sampling"]); if (samplingStrings.size() != 1 && samplingStrings.size() != 3) { std::cerr << "Error. Invalid number of super sampling parameters provided. Either give one (for isometric super sampling) or 3."; return false; } for (const auto& samplingstr : samplingStrings) { - superSamplingFactors.push_back(std::stoul(samplingstr)); + settings.superSamplingFactors.push_back(std::stoul(samplingstr)); } - if (superSamplingFactors.size() == 1) + if (settings.superSamplingFactors.size() == 1) { - superSamplingFactors.push_back(superSamplingFactors[0]); - superSamplingFactors.push_back(superSamplingFactors[0]); + settings.superSamplingFactors.push_back(settings.superSamplingFactors[0]); + settings.superSamplingFactors.push_back(settings.superSamplingFactors[0]); } } catch (...) { std::cerr << "Error. Invalid super sampling parameter provided."; throw; } } } catch (...) { return false; } return true; } int main(int argc, char* argv[]) { + mitk::Image::ConstPointer inputImage; + mitk::MAPRegistrationWrapper::ConstPointer registration; + mitk::BaseGeometry::Pointer refGeometry; + + Settings settings; mitkCommandLineParser parser; setupParser(parser); mitk::PreferenceListReaderOptionsFunctor readerFilterFunctor = mitk::PreferenceListReaderOptionsFunctor({ "MITK DICOM Reader v2 (autoselect)" }, { "" }); const std::map<std::string, us::Any>& parsedArgs = parser.parseArguments(argc, argv); - if (!configureApplicationSettings(parsedArgs)) + if (!configureApplicationSettings(parsedArgs, settings)) { MITK_ERROR << "Command line arguments are invalid. To see the correct usage please call with -h or --help to show the help information."; return EXIT_FAILURE; }; // Show a help message if (parsedArgs.count("help") || parsedArgs.count("h")) { std::cout << parser.helpText(); return EXIT_SUCCESS; } std::cout << std::endl << "*******************************************" << std::endl; - std::cout << "Input file: " << inFileName << std::endl; - std::cout << "Output file: " << outFileName << std::endl; + std::cout << "Input file: " << settings.inFileName << std::endl; + std::cout << "Output file: " << settings.outFileName << std::endl; std::cout << "Registration: "; - if (regFileName.empty()) + if (settings.regFileName.empty()) std::cout << "None (Identity)" << std::endl; else - std::cout << regFileName << std::endl; + std::cout << settings.regFileName << std::endl; std::cout << "Template: "; - if (refGeometryFileName.empty()) + if (settings.refGeometryFileName.empty()) std::cout << "None (is input geometry)" << std::endl; else - std::cout << refGeometryFileName << std::endl; - std::cout << "Padding value: " << paddingValue << std::endl; - std::cout << "Interpolation type: " << interpolatorType << std::endl; + std::cout << settings.refGeometryFileName << std::endl; + std::cout << "Padding value: " << settings.paddingValue << std::endl; + std::cout << "Interpolation type: " << settings.interpolatorType << std::endl; //check for super/sub sampling - if (!superSamplingFactors.empty() && (superSamplingFactors.size() != 1 || superSamplingFactors[0] != 1)) + if (!settings.superSamplingFactors.empty() && (settings.superSamplingFactors.size() != 1 || settings.superSamplingFactors[0] != 1)) { std::cout << "Super sampling:"; - for (auto value : superSamplingFactors) + for (auto value : settings.superSamplingFactors) { std::cout << " " << value; } std::cout << std::endl; } //! [do processing] try { std::cout << "Load input data..." << std::endl; - inputImage = mitk::IOUtil::Load<mitk::Image>(inFileName); + inputImage = mitk::IOUtil::Load<mitk::Image>(settings.inFileName); if (inputImage.IsNull()) { MITK_ERROR << "Cannot load input image."; return EXIT_FAILURE; } std::cout << "Load registration..." << std::endl; - if (regFileName.empty()) + if (settings.regFileName.empty()) { std::cout << " associated registration: identity" << std::endl; registration = mitk::GenerateIdentityRegistration3D().GetPointer(); } else { - registration = mitk::IOUtil::Load<mitk::MAPRegistrationWrapper>(regFileName); + registration = mitk::IOUtil::Load<mitk::MAPRegistrationWrapper>(settings.regFileName); } if (registration.IsNull()) { MITK_ERROR << "Cannot load registration."; return EXIT_FAILURE; } - if (refGeometryFileName != "") + if (settings.refGeometryFileName != "") { std::cout << "Load reference image..." << std::endl; - auto refImage = mitk::IOUtil::Load<mitk::Image>(refGeometryFileName, &readerFilterFunctor); + auto refImage = mitk::IOUtil::Load<mitk::Image>(settings.refGeometryFileName, &readerFilterFunctor); if (refImage.IsNotNull()) { refGeometry = refImage->GetGeometry(); } else { MITK_ERROR << "Cannot load reference geometry image."; return EXIT_FAILURE; } } else { refGeometry = inputImage->GetGeometry(); } //check for super/sub sampling - if (!superSamplingFactors.empty() && (superSamplingFactors.size()!=1 || superSamplingFactors[0]!=1)) + if (!settings.superSamplingFactors.empty() && (settings.superSamplingFactors.size()!=1 || settings.superSamplingFactors[0]!=1)) { refGeometry = mitk::ImageMappingHelper::GenerateSuperSampledGeometry(refGeometry, - superSamplingFactors[0], - superSamplingFactors[1], - superSamplingFactors[2]); + settings.superSamplingFactors[0], + settings.superSamplingFactors[1], + settings.superSamplingFactors[2]); } std::cout << "Map the images ..." << std::endl; - auto output = mitk::ImageMappingHelper::map(inputImage, registration, false, paddingValue, refGeometry, true, 0, interpolatorType); + auto output = mitk::ImageMappingHelper::map(inputImage, registration, false, settings.paddingValue, refGeometry, true, 0, settings.interpolatorType); - std::cout << "Save output image: " << outFileName << std::endl; + std::cout << "Save output image: " << settings.outFileName << std::endl; - mitk::IOUtil::Save(output, outFileName); + mitk::IOUtil::Save(output, settings.outFileName); std::cout << "Processing finished." << std::endl; return EXIT_SUCCESS; } catch (const std::exception& e) { MITK_ERROR << e.what(); return EXIT_FAILURE; } catch (...) { MITK_ERROR << "Unexpected error encountered."; return EXIT_FAILURE; } } diff --git a/Modules/MatchPointRegistration/cmdapps/MatchImageMiniApp.cpp b/Modules/MatchPointRegistration/cmdapps/MatchImageMiniApp.cpp index c7d5f0de2c..bbcb447ea4 100644 --- a/Modules/MatchPointRegistration/cmdapps/MatchImageMiniApp.cpp +++ b/Modules/MatchPointRegistration/cmdapps/MatchImageMiniApp.cpp @@ -1,314 +1,318 @@ /*============================================================================ 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 "mitkCommandLineParser.h" #include <mitkIOUtil.h> #include <mitkPreferenceListReaderOptionsFunctor.h> #include <mitkMAPRegistrationWrapper.h> #include <mitkMAPAlgorithmHelper.h> #include <mitkPointSet.h> #include <mitkImageTimeSelector.h> #include <itkStdStreamLogOutput.h> // MatchPoint #include <mapRegistrationAlgorithmInterface.h> #include <mapAlgorithmEvents.h> #include <mapAlgorithmWrapperEvent.h> #include <mapExceptionObjectMacros.h> #include <mapImageRegistrationAlgorithmInterface.h> #include <mapPointSetRegistrationAlgorithmInterface.h> #include <mapMaskedRegistrationAlgorithmInterface.h> #include <mapConvert.h> #include <mapDeploymentDLLAccess.h> #include <mapDeploymentDLLHandle.h> #include <mapRegistrationBase.h> -std::string movingFileName; -std::string targetFileName; -std::string outFileName; -std::string algFileName; +struct Settings +{ + std::string movingFileName = ""; + std::string targetFileName = ""; + std::string outFileName = ""; + std::string algFileName = ""; +}; void SetupParser(mitkCommandLineParser& parser) { parser.setTitle("Image Matcher"); parser.setCategory("Registration Tools"); parser.setDescription(""); parser.setContributor("MIC, German Cancer Research Center (DKFZ)"); parser.setArgumentPrefix("--", "-"); // Add command line argument names parser.beginGroup("Required I/O parameters"); parser.addArgument( "moving", "m", mitkCommandLineParser::File, "Moving image files", "Path to the data that should be registred into the target space.", us::Any(), false, false, false, mitkCommandLineParser::Input); parser.addArgument( "target", "t", mitkCommandLineParser::File, "Tareget image files", "Path to the data that should be the target data on which the moving data should be registered.", us::Any(), false, false, false, mitkCommandLineParser::Input); parser.addArgument( "algorithm", "a", mitkCommandLineParser::File, "Registration algorithm", "Path to the registration algorithm that should be used for registration.", us::Any(), false, false, false, mitkCommandLineParser::Input); parser.addArgument("output", "o", mitkCommandLineParser::File, "Output file path", "Path to the generated registration.", us::Any(), false, false, false, mitkCommandLineParser::Output); parser.endGroup(); parser.beginGroup("Optional parameters"); parser.addArgument("template", "t", mitkCommandLineParser::File, "Output template image.", "File path to an image that serves as template for the output geometry.", us::Any(), false, false, false, mitkCommandLineParser::Input); parser.addArgument( "registrations", "r", mitkCommandLineParser::StringList, "Registration files", "Pathes to the registrations that should be used to map the input images. If this parameter is not set, identity transforms are assumed. If this parameter is set, it must have the same number of entries then the parameter inputs. If you want to use and identity transform for a specific input, specify an empty string. The application assumes that inputs and registrations have the same order, so the n-th input should use thr n-th registration.", us::Any(), true, false, false, mitkCommandLineParser::Input); parser.addArgument("help", "h", mitkCommandLineParser::Bool, "Help:", "Show this help text"); parser.endGroup(); } -bool ConfigureApplicationSettings(std::map<std::string, us::Any> parsedArgs) +bool ConfigureApplicationSettings(std::map<std::string, us::Any> parsedArgs, Settings& settings) { try { if (parsedArgs.size() == 0) return false; - movingFileName = us::any_cast<std::string>(parsedArgs["moving"]); - targetFileName = us::any_cast<std::string>(parsedArgs["target"]); - outFileName = us::any_cast<std::string>(parsedArgs["output"]); - algFileName = us::any_cast<std::string>(parsedArgs["algorithm"]); + settings.movingFileName = us::any_cast<std::string>(parsedArgs["moving"]); + settings.targetFileName = us::any_cast<std::string>(parsedArgs["target"]); + settings.outFileName = us::any_cast<std::string>(parsedArgs["output"]); + settings.algFileName = us::any_cast<std::string>(parsedArgs["algorithm"]); } catch (...) { return false; } return true; } -map::deployment::RegistrationAlgorithmBasePointer loadAlgorithm() +map::deployment::RegistrationAlgorithmBasePointer loadAlgorithm(const Settings& settings) { map::deployment::RegistrationAlgorithmBasePointer spAlgorithmBase = nullptr; std::cout << std::endl << "Load registration algorithm..." << std::endl; map::deployment::DLLHandle::Pointer spHandle = nullptr; - spHandle = map::deployment::openDeploymentDLL(algFileName); + spHandle = map::deployment::openDeploymentDLL(settings.algFileName); if (spHandle.IsNull()) { mapDefaultExceptionStaticMacro(<< "Cannot open deployed registration algorithm file."); } std::cout << "... libary opened..." << std::endl; std::cout << "Algorithm information: " << std::endl; spHandle->getAlgorithmUID().Print(std::cout, 2); std::cout << std::endl; //Now load the algorthm from DLL spAlgorithmBase = map::deployment::getRegistrationAlgorithm(spHandle); if (spAlgorithmBase.IsNotNull()) { std::cout << "... done" << std::endl << std::endl; } else { mapDefaultExceptionStaticMacro(<< "Cannot create algorithm instance"); } return spAlgorithmBase; }; mitk::Image::Pointer ExtractFirstFrame(const mitk::Image* dynamicImage) { mitk::ImageTimeSelector::Pointer imageTimeSelector = mitk::ImageTimeSelector::New(); imageTimeSelector->SetInput(dynamicImage); imageTimeSelector->SetTimeNr(0); imageTimeSelector->UpdateLargestPossibleRegion(); return imageTimeSelector->GetOutput(); } void OnMapAlgorithmEvent(::itk::Object*, const itk::EventObject& event, void*) { const map::events::AlgorithmEvent* pAlgEvent = dynamic_cast<const map::events::AlgorithmEvent*>(&event); const map::events::AlgorithmWrapperEvent* pWrapEvent = dynamic_cast<const map::events::AlgorithmWrapperEvent*>(&event); const map::events::InitializingAlgorithmEvent* pInitEvent = dynamic_cast<const map::events::InitializingAlgorithmEvent*>(&event); const map::events::StartingAlgorithmEvent* pStartEvent = dynamic_cast<const map::events::StartingAlgorithmEvent*>(&event); const map::events::StoppingAlgorithmEvent* pStoppingEvent = dynamic_cast<const map::events::StoppingAlgorithmEvent*>(&event); const map::events::StoppedAlgorithmEvent* pStoppedEvent = dynamic_cast<const map::events::StoppedAlgorithmEvent*>(&event); const map::events::FinalizingAlgorithmEvent* pFinalizingEvent = dynamic_cast<const map::events::FinalizingAlgorithmEvent*>(&event); const map::events::FinalizedAlgorithmEvent* pFinalizedEvent = dynamic_cast<const map::events::FinalizedAlgorithmEvent*>(&event); if (pInitEvent) { std::cout <<"Initializing algorithm ..." << std::endl; } else if (pStartEvent) { std::cout <<"Starting algorithm ..." << std::endl; } else if (pStoppingEvent) { std::cout <<"Stopping algorithm ..." << std::endl; } else if (pStoppedEvent) { std::cout <<"Stopped algorithm ..." << std::endl; if (!pStoppedEvent->getComment().empty()) { std::cout <<"Stopping condition: " << pStoppedEvent->getComment() << std::endl; } } else if (pFinalizingEvent) { std::cout <<"Finalizing algorithm and results ..." << std::endl; } else if (pFinalizedEvent) { std::cout <<"Finalized algorithm ..." << std::endl; } else if (pAlgEvent && !pWrapEvent) { std::cout << pAlgEvent->getComment() << std::endl; } } int main(int argc, char* argv[]) { std::cout << "MitkRegistrationMiniApp - Generic light weight image registration tool based on MatchPoint." << std::endl; + Settings settings; mitkCommandLineParser parser; SetupParser(parser); const std::map<std::string, us::Any>& parsedArgs = parser.parseArguments(argc, argv); - if (!ConfigureApplicationSettings(parsedArgs)) + if (!ConfigureApplicationSettings(parsedArgs, settings)) { MITK_ERROR << "Command line arguments are invalid. To see the correct usage please call with -h or --help to show the help information."; return EXIT_FAILURE; }; // Show a help message if (parsedArgs.count("help") || parsedArgs.count("h")) { std::cout << parser.helpText(); return EXIT_SUCCESS; } std::cout << std::endl << "*******************************************" << std::endl; - std::cout << "Moving file: " << movingFileName << std::endl; - std::cout << "Target file: " << targetFileName << std::endl; - std::cout << "Output file: " << outFileName << std::endl; - std::cout << "Algorithm location: " << algFileName << std::endl; + std::cout << "Moving file: " << settings.movingFileName << std::endl; + std::cout << "Target file: " << settings.targetFileName << std::endl; + std::cout << "Output file: " << settings.outFileName << std::endl; + std::cout << "Algorithm location: " << settings.algFileName << std::endl; //load algorithm try { - auto algorithm = loadAlgorithm(); + auto algorithm = loadAlgorithm(settings); auto command = ::itk::CStyleCommand::New(); command->SetCallback(OnMapAlgorithmEvent); algorithm->AddObserver(::map::events::AlgorithmEvent(), command); std::cout << "Load moving data..." << std::endl; - auto movingImage = mitk::IOUtil::Load<mitk::Image>(movingFileName); + auto movingImage = mitk::IOUtil::Load<mitk::Image>(settings.movingFileName); if (movingImage.IsNull()) { MITK_ERROR << "Cannot load moving image."; return EXIT_FAILURE; } if (movingImage->GetTimeSteps() > 1) { movingImage = mitk::SelectImageByTimeStep(movingImage, 0)->Clone(); //we have to clone because SelectImageByTimeStep //only generates as new view of the data and we //are overwriting the only smartpointer to the source. std::cout << "Moving image has multiple time steps. Use first time step for registartion." << std::endl; } std::cout << "Load target data..." << std::endl; - auto targetImage = mitk::IOUtil::Load<mitk::Image>(targetFileName); + auto targetImage = mitk::IOUtil::Load<mitk::Image>(settings.targetFileName); if (targetImage.IsNull()) { MITK_ERROR << "Cannot load target image."; return EXIT_FAILURE; } if (targetImage->GetTimeSteps() > 1) { targetImage = mitk::SelectImageByTimeStep(targetImage, 0)->Clone(); //we have to clone because SelectImageByTimeStep //only generates as new view of the data and we //are overwriting the only smartpointer to the source. std::cout << "Target image has multiple time steps. Use first time step for registartion." << std::endl; } std::cout << "Start registration...." << std::endl; mitk::MAPAlgorithmHelper helper(algorithm); helper.SetData(movingImage, targetImage); ::itk::StdStreamLogOutput::Pointer spStreamLogOutput = ::itk::StdStreamLogOutput::New(); spStreamLogOutput->SetStream(std::cout); map::core::Logbook::addAdditionalLogOutput(spStreamLogOutput); auto registration = helper.GetRegistration(); // wrap the registration in a data node if (registration.IsNull()) { MITK_ERROR << "No valid registration generated"; return EXIT_FAILURE; } auto regWrapper = mitk::MAPRegistrationWrapper::New(registration); std::cout << "Store registration...." << std::endl; - mitk::IOUtil::Save(regWrapper, outFileName); + mitk::IOUtil::Save(regWrapper, settings.outFileName); } catch (const std::exception& e) { MITK_ERROR << e.what(); return EXIT_FAILURE; } catch (...) { MITK_ERROR << "Unexpected error encountered."; return EXIT_FAILURE; } return EXIT_SUCCESS; }