diff --git a/Code/Wrappers/CommandLine/CMakeLists.txt b/Code/Wrappers/CommandLine/CMakeLists.txt index bf407ff3e90a09f8d83e8173b7b19b1c69590aef..9bbf503301921982bb139d2757968167345eb606 100644 --- a/Code/Wrappers/CommandLine/CMakeLists.txt +++ b/Code/Wrappers/CommandLine/CMakeLists.txt @@ -12,4 +12,18 @@ install(TARGETS OTBWrapperCommandLine LIBRARY DESTINATION ${OTB_INSTALL_LIB_DIR_CM24} ARCHIVE DESTINATION ${OTB_INSTALL_LIB_DIR_CM24}) - \ No newline at end of file + + +set( SRCS + otbApplicationLauncherCommandLine.cxx ) + +add_executable(otbApplicationLauncherCommandLine ${SRCS}) +target_link_libraries(otbApplicationLauncherCommandLine + OTBWrapperCommandLine + OTBApplicationEngine + ${QT_LIBRARIES}) + +install(TARGETS otbApplicationLauncherCommandLine + RUNTIME DESTINATION ${OTB_INSTALL_BIN_DIR_CM24} + LIBRARY DESTINATION ${OTB_INSTALL_LIB_DIR_CM24} + ARCHIVE DESTINATION ${OTB_INSTALL_LIB_DIR_CM24}) diff --git a/Code/Wrappers/CommandLine/otbApplicationCommandLine.cxx b/Code/Wrappers/CommandLine/otbApplicationCommandLine.cxx deleted file mode 100644 index dbef8783e25c6f51e34926203a804ec3cbf177ae..0000000000000000000000000000000000000000 --- a/Code/Wrappers/CommandLine/otbApplicationCommandLine.cxx +++ /dev/null @@ -1,90 +0,0 @@ -/*========================================================================= - - Program: ORFEO Toolbox - Language: C++ - Date: $Date$ - Version: $Revision$ - - - Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. - See OTBCopyright.txt for details. - - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - - =========================================================================*/ - -#include "otbWrapperApplication.h" -#include "otbWrapperApplicationRegistry.h" -#include "itksys/SystemTools.hxx" - -using otb::Wrapper::Application; -using otb::Wrapper::ApplicationRegistry; - -int main(int argc, char* argv[]) -{ - /* - if (argc < 2) - { - std::cerr << "Usage : " << argv[0] << " module_name [module_path]" << std::endl; - return EXIT_FAILURE; - } - - std::string moduleName = argv[1]; - - // Get the module path list - std::list<std::string> modulePathList; - if (argc > 2) - { - std::copy(argv + 2, argv + argc, std::back_inserter(modulePathList)); - - // Load the path in the environment - std::string specificEnv("ITK_AUTOLOAD_PATH="); - std::list<std::string>::const_iterator it = modulePathList.begin(); - while( it != modulePathList.end() ) - { - std::string modulePath = *it; - - specificEnv += *it; - ++it; - if (it != modulePathList.end()) - specificEnv += ":"; - } - - // do NOT use putenv() directly, since the string memory must be managed carefully - itksys::SystemTools::PutEnv(specificEnv.c_str()); - } - - // Reload factories to take into account new path - itk::ObjectFactoryBase::ReHash(); - - // Create module - Application::Pointer app = ApplicationRegistry::CreateApplication(moduleName); - if (app.IsNull()) - { - std::cerr << "Could not find application " << moduleName << std::endl; - - const char* modulePath = itksys::SystemTools::GetEnv("ITK_AUTOLOAD_PATH"); - std::cout << "Module search path : " << (modulePath ? modulePath : "") << std::endl; - - std::vector<std::string> list = ApplicationRegistry::GetAvailableApplications(); - - std::cout << "Available applications : " << (list.empty() ? "None" : "") << std::endl; - for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it) - { - std::cout << " " << *it << std::endl; - } - return EXIT_FAILURE; - } - - // Create GUI based on module - QtWidgetView* gui = new QtWidgetView(app); - gui->CreateGui(); - - // Start event processing loop - return qtApp.exec(); - */ - return 1; -} diff --git a/Code/Wrappers/CommandLine/otbApplicationLauncherCommandLine.cxx b/Code/Wrappers/CommandLine/otbApplicationLauncherCommandLine.cxx new file mode 100644 index 0000000000000000000000000000000000000000..5bfa374d9c013525d07b3e8d0e4e27931ceaf500 --- /dev/null +++ b/Code/Wrappers/CommandLine/otbApplicationLauncherCommandLine.cxx @@ -0,0 +1,63 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + + =========================================================================*/ + +#include "otbWrapperCommandLineLauncher.h" + + +int main(int argc, char* argv[]) +{ + if (argc < 2) + { + std::cerr << "Usage : " << argv[0] << " module_name module_path [arguments]" << std::endl; + return EXIT_FAILURE; + } + + + // Construct the string expression + std::string exp; + for( unsigned int i=1; i<argc; i++) + { + if( i!= argc-1) + { + exp.append(argv[i]); + exp.append(" "); + } + else + { + exp.append(argv[i]); + } + + } + + typedef otb::Wrapper::CommandLineLauncher LauncherType; + LauncherType::Pointer launcher = LauncherType::New(); + + if (launcher->Load( exp ) == true ) + { + if (launcher->ExecuteAndWriteOutput() == false) + { + return EXIT_FAILURE; + } + } + else + { + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} diff --git a/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx b/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx index 8825cab383adc3390c9c2898b1e3b5c78f3a5749..3e8bf888f200f6bb61ef9d12c9f6c759cf55214e 100644 --- a/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx +++ b/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx @@ -35,6 +35,7 @@ #include "otbWrapperInputImageListParameter.h" #include "otbWrapperStringListParameter.h" +#include "otbStreamingImageFileWriter.h" #include "otbWrapperApplicationRegistry.h" #include "otbWrapperApplication.h" @@ -48,7 +49,7 @@ namespace otb namespace Wrapper { -CommandLineLauncher::CommandLineLauncher() : m_Expression("") + CommandLineLauncher::CommandLineLauncher() : m_Expression(""), m_FilterWatcherList(), m_WriterWatcherList() { m_Application = NULL; m_Parser = CommandLineParser::New(); @@ -84,7 +85,7 @@ CommandLineLauncher::Load() if( this->CheckUnicity() == false ) { std::cerr<<"ERROR: At least one key is not unique in the expression..."<<std::endl; - return false; + return false; } if ( this->LoadPath() == false ) @@ -109,7 +110,7 @@ CommandLineLauncher::Execute() m_Application->Execute(); return true; -} +} bool @@ -131,7 +132,7 @@ CommandLineLauncher::BeforeExecute() { if( m_Application.IsNull() ) { - itkExceptionMacro("No application loaded"); + itkExceptionMacro("No application loaded"); } // if help is asked... @@ -159,6 +160,40 @@ CommandLineLauncher::BeforeExecute() return false; } + // Check for the progress report + bool doProgressReport = true; + if( m_Parser->IsAttributExists( "--progress", m_Expression ) == true ) + { + std::vector<std::string> val; + val = m_Parser->GetAttribut( "--progress", m_Expression ); + if( val.size() != 1) + { + std::cerr<<"Invalid progress argument, must be unique value..."<<std::endl; + return false; + } + if( val[0] == "1" || val[0] == "true") + { + doProgressReport = true; + } + else if( val[0] == "0" || val[0] == "false") + { + doProgressReport = false; + } + else + { + std::cerr<<"Invalid progress argument, must be 0, 1, false or true..."<<std::endl; + // Force to reload the application, the LoadParameters can change wrong values + this->LoadApplication(); + this->DisplayHelp(); + return false; + } + } + + if( doProgressReport == true ) + { + this->LinkWatchers(); + } + return true; } @@ -174,7 +209,7 @@ CommandLineLauncher::LoadPath() // Contain paths into a string, separating each path with ":" m_Path = std::string(""); for( unsigned i=0; i<pathList.size(); i++) - { + { m_Path.append(pathList[i]); m_Path.append(":"); } @@ -197,7 +232,7 @@ CommandLineLauncher::LoadApplication() std::string moduleName; if( m_Parser->GetModuleName( moduleName, m_Expression ) != CommandLineParser::OK ) { - std::cerr << "ERROR: LoadApplication, no module found..." <<std::endl; + std::cerr << "ERROR: LoadApplication, no module found..." <<std::endl; return; } @@ -275,8 +310,8 @@ CommandLineLauncher::LoadParameters() // Single value parameter - if( type == ParameterType_Choice || type == ParameterType_Float || type == ParameterType_Int || type == ParameterType_Radius - || type == ParameterType_Directory || type == ParameterType_String || type == ParameterType_Filename || type == ParameterType_InputComplexImage + if( type == ParameterType_Choice || type == ParameterType_Float || type == ParameterType_Int || type == ParameterType_Radius + || type == ParameterType_Directory || type == ParameterType_String || type == ParameterType_Filename || type == ParameterType_InputComplexImage || type == ParameterType_InputImage || type == ParameterType_InputVectorData || type == ParameterType_OutputImage || type == ParameterType_OutputVectorData ) { m_Application->SetParameterString( param->GetKey(), values[0] ); @@ -301,6 +336,50 @@ CommandLineLauncher::LoadParameters() } +void +CommandLineLauncher::LinkWatchers() +{ + /* + m_FilterWatcherList.clear(); + m_WriterWatcherList.clear(); + // Link internall filters watcher + for( unsigned int i=0; i<m_Application->GetInternalProcessList().size(); i++ ) + { + //std::cout<<"BRRRRRRRRRRRRRRR"<<std::endl; + //StandardFilterWatcher watch(m_Application->GetInternalProcessList()[i], m_Application->GetInternalProcessListName()[i]); + //m_FilterWatcherList.push_back( watch ); + } + + // Link output image writers watchers + std::vector<std::string> paramList = m_Application->GetParametersKeys(true); + std::vector<std::string>::const_iterator it = paramList.begin(); + std::cout<<"BRRRRRRRRRRRRRRR"<<std::endl; + for ( ; it != paramList.end(); ++it) + { + if (m_Application->GetParameterType(*it) == ParameterType_OutputImage) + { + std::cout<<"-------------------------------------------------------------t'en as?"<<std::endl; + Parameter* param = m_Application->GetParameterByKey(*it); + OutputImageParameter* outputParam = dynamic_cast<OutputImageParameter*>(param); + itk::OStringStream oss; + oss<< "Wrinting "<< param->GetName()<<std::endl; + + std::cout<<"----++++"<<std::endl; + std::cout<<"----++++: "<<outputParam->GetWriter()<<std::endl; + std::cout<<"----++++"<<std::endl; + //typedef otb::StreamingImageFileWriter<FloatVectorImageType> FloatWriterType; + //StandardWriterWatcher watch(static_cast<FloatWriterType::Pointer>(static_cast<FloatWriterType *>(outputParam->GetWriter())), "write that"); + //StandardWriterWatcher watch(outputParam->GetWriter(), "write that"); + //m_WriterWatcherList.push_back( watch ); + StandardFilterWatcher watch(outputParam->GetWriter(), oss.str()); + m_FilterWatcherList.push_back( watch ); + + } + } + std::cout<<"BRRRRRRRRRRRRRRR fin"<<std::endl; + */ +} + void CommandLineLauncher::DisplayHelp() { @@ -315,11 +394,11 @@ CommandLineLauncher::DisplayHelp() std::cerr<<"=== Mandatory parameters: "<<std::endl; - std::cerr<<"--"<<m_Parser->GetModulePathKey()<<" (Executables paths)"<<std::endl; + std::cerr<<m_Parser->GetModulePathKey()<<" (Executables paths)"<<std::endl; std::cerr<<"\t Description: Paths to the executable library."<<std::endl; - if( !m_Parser->IsAttributExists( "--modPath", m_Expression ) ) + if( !m_Parser->IsAttributExists( m_Parser->GetModulePathKey(), m_Expression ) ) std::cerr<<"\t Status: ENVIRONEMENT PATH"<<std::endl; - else if( m_Path == "") + else if( m_Path == "") std::cerr<< "\t Status: NO VALUE ASSOCIATED "<<m_Path<<std::endl; else std::cerr<< "\t Status: USER VALUE: "<<m_Path<<std::endl; @@ -335,20 +414,23 @@ CommandLineLauncher::DisplayHelp() } } - bool addOptionTag = true; // Optional parameters + std::cerr<<"=== Optional parameters: "<<std::endl; + std::cerr<<"--progress (Report progress)"<<std::endl; + std::cerr<<"\t Description: Do report progress."<<std::endl; + std::cerr<<"\t Default value: 1"<< std::endl; + if( !m_Parser->IsAttributExists( "--progress", m_Expression ) ) + std::cerr<<"\t Status: DEFAULT VALUE"<<std::endl; + else if( m_Parser->GetAttribut( "--progress", m_Expression ).size() == 0 ) + std::cerr<< "\t Status: none"<<m_Path<<std::endl; + else + std::cerr<< "\t Status: USER VALUE: "<<m_Parser->GetAttribut( "--progress", m_Expression )[0]<<std::endl; for( unsigned int i=0; i<nbOfParam; i++ ) { Parameter::Pointer param = paramGr->GetParameterByIndex(i); // Check if mandatory parameter are present and have value if( param->GetMandatory() != true ) { - if( addOptionTag == true ) - { - std::cerr<<"=== Optional parameters: "<<std::endl; - addOptionTag = false; - } - std::cerr << this->DisplayParameterHelp( param ); } @@ -434,7 +516,8 @@ CommandLineLauncher::CheckKeyValidity() std::vector<std::string> appKeyList = m_Application->GetParametersKeys( true ); appKeyList.push_back( std::string(m_Parser->GetModulePathKey()).substr(2, std::string(m_Parser->GetModulePathKey()).size()) ); appKeyList.push_back( std::string(m_Parser->GetModuleNameKey()).substr(2, std::string(m_Parser->GetModuleNameKey()).size()) ); - appKeyList.push_back( "--help" ); + appKeyList.push_back( "help" ); + appKeyList.push_back( "progress" ); // Check if each key in the expression exists in the application for( unsigned int i=0; i<expKeyList.size(); i++ ) @@ -456,6 +539,7 @@ CommandLineLauncher::CheckKeyValidity() } } + /* if(res == false) { for( unsigned int i=0; i<expKeyList.size(); i++ ) @@ -467,6 +551,8 @@ CommandLineLauncher::CheckKeyValidity() std::cout<< appKeyList[j]<<std::endl; } } + */ + return res; } diff --git a/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.h b/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.h index 397566b85244233d5e219ee310926aa8a57c90b2..aa588a9780da6e213bf665d92e1e662ffe44b366 100644 --- a/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.h +++ b/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.h @@ -18,18 +18,19 @@ #ifndef __otbWrapperCommandLineLauncher_h #define __otbWrapperCommandLineLauncher_h -//#include <string> #include "otbMacro.h" #include "itkObject.h" #include "itkObjectFactory.h" -//#include "otbWrapperTypes.h" -//#include "otbWrapperParameterGroup.h" #include "otbWrapperApplication.h" #include "otbWrapperParameter.h" #include "itksys/SystemTools.hxx" #include "otbWrapperCommandLineParser.h" +#include "otbStandardWriterWatcher.h" +#include "otbStandardFilterWatcher.h" + + namespace otb { namespace Wrapper @@ -37,7 +38,7 @@ namespace Wrapper /** \class CommandLineLauncher * \brief This class check the validity of a command line application. - * + * * To be valid, the expression must be as follow: * ModuleName --attribut1_Key attrubut1_Value --attribut2_Key attrubut2_Value * After the attribut key, if the user give several values (expression without \"--\" separated by space), it will automacally be interpreted as a list. @@ -58,12 +59,16 @@ public: itkNewMacro(Self); /** RTTI support */ - itkTypeMacro(CommandLineLauncher, itk::Object); + itkTypeMacro(CommandLineLauncher,itk::Object); /** Parse result enum */ typedef CommandLineParser::ParseResultType ParseResultType; typedef enum { OKPARAM, MISSINGMANDATORYPARAMETER, MISSINGPARAMETERVALUE, WRONGPARAMETERVALUE, INVALIDNUMBEROFVALUE, DEFAULT} ParamResultType; + /** Filter watcher list type */ + typedef std::vector<StandardFilterWatcher> FilterWatcherListType; + /** Writer watcher list type */ + typedef std::vector<StandardWriterWatcher> WriterWatcherListType; /** Load the application in several steps : * - Load the paths @@ -74,22 +79,22 @@ public: /** same as Load method but set the expression before. */ bool Load( const std::string & exp ); - /** Launch the process, using the Execute application method + /** Launch the process, using the Execute application method * The method will check if the user asked for help (looking at --help key) before loading parameter and launching process. **/ bool Execute(); - /** Launch the process, using the ExecuteAndWriteOutput application method + /** Launch the process, using the ExecuteAndWriteOutput application method * The method will check if the user asked for help (looking at --help key) before loading parameter and launching process. */ bool ExecuteAndWriteOutput(); - /** Gather the code process to do before Execute and ExecuteAndWriteOutput + /** Gather the code process to do before Execute and ExecuteAndWriteOutput * Returns false if a problem occurs, true otherwise. */ bool BeforeExecute(); - /** Create and display the help of the application */ + /** Create and display the help of the application */ void DisplayHelp(); protected: @@ -104,22 +109,25 @@ protected: /** Load the executable path. It looks for the key --modulePath, extract and interpret as path the following strings. */ bool LoadPath(); - /** Load the application calling the CreateApplication method of the ApplicationRegistry classes. + /** Load the application calling the CreateApplication method of the ApplicationRegistry classes. * Pay attention, the executable paths have to be loaded or set in the environment before calling the function. */ void LoadApplication(); /** Parse the user expression, extract the key and the associated string and set it as value of each corresonding application parameter. */ CommandLineLauncher::ParamResultType LoadParameters(); - /** Create and display the help of the application */ + /** Create and display the help of the application */ std::string DisplayParameterHelp( const Parameter::Pointer & param ); - /** Check if each key is unique in the expression. */ + /** Check if each key is unique in the expression. */ bool CheckUnicity(); - /** Check if each key is valid for the application. */ + /** Check if each key is valid for the application. */ bool CheckKeyValidity(); + /** Load the watchers for internal progress and writeing progress report. */ + void LinkWatchers(); + private: CommandLineLauncher(const CommandLineLauncher &); //purposely not implemented @@ -131,6 +139,9 @@ private: std::string m_Expression; CommandLineParser::Pointer m_Parser; + FilterWatcherListType m_FilterWatcherList; + WriterWatcherListType m_WriterWatcherList; + }; //end class } // end namespace Wrapper