diff --git a/Modules/Classification/CLMiniApps/CLMatchPointReg.cpp b/Modules/Classification/CLMiniApps/CLMatchPointReg.cpp index 12be20f840..074f86590f 100644 --- a/Modules/Classification/CLMiniApps/CLMatchPointReg.cpp +++ b/Modules/Classification/CLMiniApps/CLMatchPointReg.cpp @@ -1,168 +1,212 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkProperties.h" #include "mitkCommandLineParser.h" #include "mitkIOUtil.h" #include "mitkPreferenceListReaderOptionsFunctor.h" // MatchPoint #include #include #include #include #include #include #include #include #include #include #include #include // Qt #include #include #include //#include #include #include #include #include - -int main(int argc, char* argv[]) -{ +int main(int argc, char* argv[]) { mitkCommandLineParser parser; parser.setTitle("Dicom Loader"); parser.setCategory("Preprocessing Tools"); parser.setDescription(""); parser.setContributor("MBI"); parser.setArgumentPrefix("--","-"); // Add command line argument names parser.addArgument("help", "h",mitkCommandLineParser::Bool, "Help:", "Show this help text"); parser.addArgument("moving", "m", mitkCommandLineParser::InputDirectory, "Input folder:", "Input folder", us::Any(), false); parser.addArgument("fixed", "f", mitkCommandLineParser::InputDirectory, "Input folder:", "Input folder", us::Any(), false); parser.addArgument("output", "o", mitkCommandLineParser::OutputFile, "Output file:", "Output file", us::Any(), false); parser.addArgument("reader", "r", mitkCommandLineParser::Int, "Reader ID", "Reader Name", us::Any(), false); parser.addArgument("interpolation", "interp", mitkCommandLineParser::Int, "Reader ID", "Reader Name", us::Any(), false); + parser.addArgument("m1", "m1", mitkCommandLineParser::InputDirectory, "Input folder:", "Input folder", us::Any()); + parser.addArgument("o1", "o1", mitkCommandLineParser::OutputFile, "Output file:", "Output file", us::Any()); + parser.addArgument("m2", "m2", mitkCommandLineParser::InputDirectory, "Input folder:", "Input folder", us::Any()); + parser.addArgument("o2", "o2", mitkCommandLineParser::OutputFile, "Output file:", "Output file", us::Any()); + parser.addArgument("m3", "m3", mitkCommandLineParser::InputDirectory, "Input folder:", "Input folder", us::Any()); + parser.addArgument("o3", "o3", mitkCommandLineParser::OutputFile, "Output file:", "Output file", us::Any()); + parser.addArgument("m4", "m4", mitkCommandLineParser::InputDirectory, "Input folder:", "Input folder", us::Any()); + parser.addArgument("o4", "o4", mitkCommandLineParser::OutputFile, "Output file:", "Output file", us::Any()); + parser.addArgument("m5", "m5", mitkCommandLineParser::InputDirectory, "Input folder:", "Input folder", us::Any()); + parser.addArgument("o5", "o5", mitkCommandLineParser::OutputFile, "Output file:", "Output file", us::Any()); + parser.addArgument("m6", "m6", mitkCommandLineParser::InputDirectory, "Input folder:", "Input folder", us::Any()); + parser.addArgument("o6", "o6", mitkCommandLineParser::OutputFile, "Output file:", "Output file", us::Any()); + parser.addArgument("m7", "m7", mitkCommandLineParser::InputDirectory, "Input folder:", "Input folder", us::Any()); + parser.addArgument("o7", "o7", mitkCommandLineParser::OutputFile, "Output file:", "Output file", us::Any()); + parser.addArgument("m8", "m8", mitkCommandLineParser::InputDirectory, "Input folder:", "Input folder", us::Any()); + parser.addArgument("o8", "o8", mitkCommandLineParser::OutputFile, "Output file:", "Output file", us::Any()); + std::map parsedArgs = parser.parseArguments(argc, argv); QFileInfo fi(argv[0]); map::deployment::DLLDirectoryBrowser::Pointer browser = map::deployment::DLLDirectoryBrowser::New(); browser->addDLLSearchLocation(QDir::homePath().toStdString()); browser->addDLLSearchLocation(QDir::currentPath().toStdString()); browser->addDLLSearchLocation(fi.canonicalPath().toStdString()); browser->update(); auto dllList = browser->getLibraryInfos(); int id = 0; std::cout << std::endl << " --- Algorithm List --- " << std::endl; for (auto info : dllList) { std::cout << "Algorithm ID " << id << ": " << info->getAlgorithmUID().getName() << std::endl; ++id; } std::cout << std::endl << " --- Interpolation List --- " << std::endl; std::cout << "Interpolation ID 0: Linear Interpolation " << std::endl; std::cout << "Interpolation ID 1: Nearest Neighbour" << std::endl; std::cout << "Interpolation ID 2: BSpline 3D" << std::endl << std::endl; mitk::ImageMappingInterpolator::Type interpolationMode = mitk::ImageMappingInterpolator::Linear; if (parsedArgs.size()==0) return EXIT_FAILURE; // Show a help message if ( parsedArgs.count("help") || parsedArgs.count("h")) { std::cout << parser.helpText(); return EXIT_SUCCESS; } std::string movingFile = us::any_cast(parsedArgs["moving"]); std::string fixedFile = us::any_cast(parsedArgs["fixed"]); int selectedAlgorithm = us::any_cast(parsedArgs["reader"]); std::string outputPath = us::any_cast(parsedArgs["output"]); if (parsedArgs.count("interpolation")) { switch (us::any_cast(parsedArgs["interpolation"])) { case 0: interpolationMode = mitk::ImageMappingInterpolator::Linear; break; case 1: interpolationMode = mitk::ImageMappingInterpolator::NearestNeighbor; break; case 2: interpolationMode = mitk::ImageMappingInterpolator::BSpline_3; break; default: interpolationMode = mitk::ImageMappingInterpolator::Linear; } } mitk::Image::Pointer movingImage = mitk::IOUtil::Load(movingFile); mitk::Image::Pointer fixedImage = mitk::IOUtil::Load(fixedFile); + //std::cout << movingImage; + //std::cout << fixedImage; + auto dllInfo = dllList[selectedAlgorithm]; if (!dllInfo) { MITK_ERROR << "No valid algorithm is selected. Cannot load algorithm. ABORTING."; return -1; } ::map::deployment::DLLHandle::Pointer tempDLLHandle = ::map::deployment::openDeploymentDLL( dllInfo->getLibraryFilePath()); ::map::algorithm::RegistrationAlgorithmBase::Pointer tempAlgorithm = ::map::deployment::getRegistrationAlgorithm(tempDLLHandle); MITK_INFO << "Well...."; if (tempAlgorithm.IsNull()) { MITK_ERROR << "Error. Cannot load selected algorithm."; return -2; } mitk::MITKAlgorithmHelper helper(tempAlgorithm); helper.SetData(movingImage, fixedImage); auto registration = helper.GetRegistration(); MITK_INFO << "Well...."; mitk::Image::Pointer spResultData= mitk::ImageMappingHelper::map(movingImage, registration, false, // Use all Pixels 0.0, // Padding Value fixedImage->GetGeometry()->Clone().GetPointer(), // Ref. Geometry false, //!(this->m_allowUnregPixels), 0, // Error Value interpolationMode // Interpolator Type ); - MITK_INFO << "Well...."; mitk::IOUtil::Save(spResultData, outputPath); + std::vector inputList; + std::vector outputList; + inputList.push_back("m1"); inputList.push_back("m2"); inputList.push_back("m3"); inputList.push_back("m4"); inputList.push_back("m5"); + inputList.push_back("m6"); inputList.push_back("m7"); inputList.push_back("m8"); inputList.push_back("m9"); inputList.push_back("m10"); + outputList.push_back("o1"); outputList.push_back("o2"); outputList.push_back("o3"); outputList.push_back("o4"); outputList.push_back("o5"); + outputList.push_back("o6"); outputList.push_back("o7"); outputList.push_back("o8"); outputList.push_back("o9"); outputList.push_back("o10"); + for (std::size_t idx=0; idx < 8; ++idx) + { + if (parsedArgs.count(inputList[idx])) + { + std::string newMovingImagePath = us::any_cast(parsedArgs[inputList[idx]]); + mitk::Image::Pointer newMovingImage = mitk::IOUtil::Load(newMovingImagePath); + mitk::Image::Pointer newSpResultData = mitk::ImageMappingHelper::map(newMovingImage, + registration, + false, // Use all Pixels + 0.0, // Padding Value + fixedImage->GetGeometry()->Clone().GetPointer(), // Ref. Geometry + false, //!(this->m_allowUnregPixels), + 0, // Error Value + interpolationMode // Interpolator Type + ); + std::string newOutputImagePath = us::any_cast(parsedArgs[outputList[idx]]); + mitk::IOUtil::Save(newSpResultData, newOutputImagePath); + } + } + + return EXIT_SUCCESS; }