diff --git a/Modules/DiffusionImaging/MiniApps/MiniAppManager.cpp b/Modules/DiffusionImaging/MiniApps/MiniAppManager.cpp old mode 100755 new mode 100644 index 59ce19a2d6..9c751c7657 --- a/Modules/DiffusionImaging/MiniApps/MiniAppManager.cpp +++ b/Modules/DiffusionImaging/MiniApps/MiniAppManager.cpp @@ -1,96 +1,117 @@ /*=================================================================== 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 "MiniAppManager.h" #include MiniAppManager* MiniAppManager::GetInstance() { static MiniAppManager instance; return &instance; } // Attention: Name of the miniApp must be the last argument!!! // it will be cut off from the rest of the arguments and then // the app will be run int MiniAppManager::RunMiniApp(int argc, char* argv[]) { int threadNum = itk::MultiThreader::GetGlobalMaximumNumberOfThreads(); if (threadNum>12) threadNum = 12; itk::MultiThreader::SetGlobalDefaultNumberOfThreads(threadNum); try { std::string nameOfMiniApp; std::map< std::string, MiniAppFunction >::iterator it = m_Functions.begin(); if( argc < 2) { + std::cout << "Generated XML:" << std::endl; + std::cout << this->CreateXML() << std::endl; + std::cout << "Please choose the mini app to execute: " << std::endl; for(int i=0; it != m_Functions.end(); ++i,++it) { std::cout << "(" << i << ")" << " " << it->first << std::endl; } std::cout << "Please select: "; int choose; std::cin >> choose; it = m_Functions.begin(); std::advance(it, choose); if( it != m_Functions.end() ) nameOfMiniApp = it->first; } else { nameOfMiniApp = argv[1]; //--argc; } it = m_Functions.find(nameOfMiniApp); if(it == m_Functions.end()) { std::ostringstream s; s << "MiniApp (" << nameOfMiniApp << ") not found!"; throw std::invalid_argument(s.str().c_str()); } // MITK_INFO << "Start " << nameOfMiniApp << " .."; MiniAppFunction func = it->second; return func( argc, argv ); } catch(std::exception& e) { MITK_ERROR << e.what(); } catch(...) { MITK_ERROR << "Unknown error occurred"; } return EXIT_FAILURE; } ///////////////////// // MiniAppFunction // ///////////////////// MiniAppManager::MiniAppFunction MiniAppManager::AddFunction(const std::string& name, MiniAppFunction func) { m_Functions.insert( std::pair(name, func) ); return func; } + +std::string MiniAppManager::CreateXML() const +{ + std::ostringstream output; + + output << "" << std::endl; + + std::map::const_iterator it = m_Functions.begin(); + + for (; it != m_Functions.end(); ++it) + { + output << " first << "\"/>" << std::endl; + } + + output << "" << std::endl; + + return output.str(); +} diff --git a/Modules/DiffusionImaging/MiniApps/MiniAppManager.h b/Modules/DiffusionImaging/MiniApps/MiniAppManager.h old mode 100755 new mode 100644 index ea9afddf9f..39210b0b0a --- a/Modules/DiffusionImaging/MiniApps/MiniAppManager.h +++ b/Modules/DiffusionImaging/MiniApps/MiniAppManager.h @@ -1,38 +1,40 @@ #ifndef MiniAppManager_h #define MiniAppManager_h #include struct MiniAppManager { public: typedef int (*MiniAppFunction)(int argc, char* argv[]); public: static MiniAppManager* GetInstance(); // Attention: Name of the miniApp must be the last argument!!! // it will be cut off from the rest of the arguments and then // the app will be run int RunMiniApp(int argc, char* argv[]); // // Add miniApp // MiniAppFunction AddFunction(const std::string& name, MiniAppFunction func); + std::string CreateXML() const; + protected: std::map< std::string, MiniAppFunction > m_Functions; }; // // Register miniApps // #define RegisterDiffusionMiniApp(functionName) \ static MiniAppManager::MiniAppFunction MiniApp##functionName = \ MiniAppManager::GetInstance()->AddFunction(#functionName, &functionName) #endif