From 8589fcebf4301ec9edefdf53af222189c9946a44 Mon Sep 17 00:00:00 2001 From: Cyrille Valladeau <cyrille.valladeau@c-s.fr> Date: Tue, 20 Sep 2011 09:29:40 +0200 Subject: [PATCH] ENH: add output image pixel type as option of outputimage key --- .../otbWrapperCommandLineLauncher.cxx | 91 +++++++++++-------- 1 file changed, 55 insertions(+), 36 deletions(-) diff --git a/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx b/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx index 0b94c3c4f1..a0acd99166 100644 --- a/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx +++ b/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx @@ -339,6 +339,36 @@ CommandLineLauncher::LoadParameters() { dynamic_cast<StringListParameter *>(param.GetPointer())->SetValue( values ); } + else if( type == ParameterType_OutputImage ) + { + m_Application->SetParameterString( paramKey, values[0] ); + // Check if pixel type is given + if( values.size() == 2 ) + { + ImagePixelType outPixType = ImagePixelType_float; + if( values[1] == "int8" ) + outPixType = ImagePixelType_int8; + else if( values[1] == "uint8" ) + outPixType = ImagePixelType_uint8; + else if( values[1] == "int16" ) + outPixType = ImagePixelType_int16; + else if( values[1] == "uint16" ) + outPixType = ImagePixelType_uint16; + else if( values[1] == "int32" ) + outPixType = ImagePixelType_int32; + else if( values[1] == "uint32" ) + outPixType = ImagePixelType_uint32; + else if( values[1] == "float" ) + outPixType = ImagePixelType_float; + else if( values[1] == "double" ) + outPixType = ImagePixelType_double; + else + { + return WRONGPARAMETERVALUE; + } + dynamic_cast<OutputImageParameter *>(param.GetPointer())->SetPixelType( outPixType ); + } + } else if( values.size() != 1) { std::cout<<"INVALIDNUMBEROFVALUE: "<<paramKey<<" "<<values.size()<<std::endl; @@ -348,7 +378,7 @@ 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 - || type == ParameterType_InputImage || type == ParameterType_InputVectorData || type == ParameterType_OutputImage || type == ParameterType_OutputVectorData ) + || type == ParameterType_InputImage || type == ParameterType_InputVectorData || type == ParameterType_OutputVectorData ) { m_Application->SetParameterString( paramKey, values[0] ); } @@ -370,33 +400,7 @@ CommandLineLauncher::LoadParameters() } } } - - // case of output pixel type... - if ( m_Parser->IsAttributExists( std::string("--outPix"), m_Expression ) ) - { - std::vector<std::string> values = m_Parser->GetAttribut( "--outPix", m_Expression ); - if( values.size() == 0 ) - return MISSINGPARAMETERVALUE; - else if( values.size() > 1 ) - return INVALIDNUMBEROFVALUE; - - ImagePixelType outPixType = ImagePixelType_float; - if( values[0] == "int8" ) - outPixType = ImagePixelType_int8; - else if( values[0] == "uint8" ) - outPixType = ImagePixelType_uint8; - else if( values[0] == "int16" ) - outPixType = ImagePixelType_int16; - else if( values[0] == "uint16" ) - outPixType = ImagePixelType_uint16; - else if( values[0] == "int32" ) - outPixType = ImagePixelType_int32; - else if( values[0] == "uint32" ) - outPixType = ImagePixelType_uint32; - else if( values[0] == "float" ) - outPixType = ImagePixelType_float; - else if( values[0] == "double" ) - outPixType = ImagePixelType_double; + else { return WRONGPARAMETERVALUE; @@ -480,7 +484,7 @@ CommandLineLauncher::DisplayHelp() //// Module path parameter std::cerr<<m_Parser->GetModulePathKey()<<" (Executables paths)"<<std::endl; std::cerr<<"\t Description: Paths to the executable library."<<std::endl; - std::cerr<<"\t Type: List of path (ie. String)"<<std::endl; + std::cerr<<"\t Type: List of string (list of path)"<<std::endl; if( !m_Parser->IsAttributExists( m_Parser->GetModulePathKey(), m_Expression ) ) { const std::string envVal = itksys::SystemTools::GetEnv("ITK_AUTOLOAD_PATH"); @@ -508,6 +512,7 @@ CommandLineLauncher::DisplayHelp() else std::cerr<< "\t Status: USER VALUE: "<<m_Parser->GetAttribut( "--progress", m_Expression )[0]<<std::endl; + /* //// Output pixel type std::cerr<<"--outPix (Output pixel type)"<<std::endl; std::cerr<<"\t Description: Defines the output images pixel type."<<std::endl; @@ -519,7 +524,7 @@ CommandLineLauncher::DisplayHelp() std::cerr<< "\t Status: none"<<m_Path<<std::endl; else std::cerr<< "\t Status: USER VALUE: "<<m_Parser->GetAttribut( "--outPix", m_Expression )[0]<<std::endl; - + */ for( unsigned int i=0; i<nbOfParam; i++ ) { Parameter::Pointer param = m_Application->GetParameterByKey( appKeyList[i] ); @@ -551,11 +556,11 @@ CommandLineLauncher::DisplayParameterHelp( const Parameter::Pointer & param, con // Display parameter description if( std::string(param->GetDescription()).size() != 0 ) { - oss<<"\t Description: "<<param->GetDescription()<< std::endl; ; + oss<<"\t Description: "<<param->GetDescription()<< std::endl;; } else { - oss<<"\t Description: none"<< std::endl; ; + oss<<"\t Description: none"<< std::endl; } // Display the type the parameter @@ -593,7 +598,8 @@ CommandLineLauncher::DisplayParameterHelp( const Parameter::Pointer & param, con } else if( type == ParameterType_OutputImage ) { - oss<<"\t Type: String (output image file name)"<<std::endl; + oss<<"\t Type: String (output image file name and optionally its pixel type)"<<std::endl; + oss<<"\t Possible pixel type: int8, uint8, int16, uint16, int32, uint32, float or double"<<std::endl; } else if( type == ParameterType_OutputVectorData ) { @@ -632,14 +638,27 @@ CommandLineLauncher::DisplayParameterHelp( const Parameter::Pointer & param, con { oss << "\t Default value: "<< m_Application->GetChoiceKeys(paramKey)[m_Application->GetParameterInt( paramKey )]<< std::endl; } + else if( type == ParameterType_OutputImage ) + { + oss << "\t Default value: filename: "<< m_Application->GetParameterAsString( paramKey )<< std::endl; + oss << "\t pixel type: float"<< std::endl; + } else { oss << "\t Default value: "<<m_Application->GetParameterAsString( paramKey )<< std::endl; } } else - oss << "\t Default value: none"<<std::endl; - + { + if( type == ParameterType_OutputImage ) + { + oss << "\t Default value: filename: none"<< std::endl; + oss << "\t pixel type: float"<< std::endl; + } + else + oss << "\t Default value: none"<<std::endl; + } + if( !m_Parser->IsAttributExists( std::string("--").append(paramKey), m_Expression) ) { if ( !m_Application->HasValue( paramKey ) ) @@ -703,7 +722,7 @@ CommandLineLauncher::CheckKeyValidity() appKeyList.push_back( std::string(m_Parser->GetModuleNameKey()).substr(2, std::string(m_Parser->GetModuleNameKey()).size()) ); appKeyList.push_back( "help" ); appKeyList.push_back( "progress" ); - appKeyList.push_back( "outPix" ); + // Check if each key in the expression exists in the application for( unsigned int i=0; i<expKeyList.size(); i++ ) { -- GitLab