diff --git a/Applications/Util/otbExtractROI.cxx b/Applications/Util/otbExtractROI.cxx index c97ebe274dff5c16f706f150e07b515df81df294..c27e7464b97212eb521b769b2764a284ecc51e83 100644 --- a/Applications/Util/otbExtractROI.cxx +++ b/Applications/Util/otbExtractROI.cxx @@ -78,6 +78,7 @@ private: void DoUpdateParameters() { + std::cout<<"update????????????????????????????????????????????"<<std::endl; // Update the sizes only if the user does not defined a size if ( HasValue("in") ) { @@ -91,7 +92,7 @@ private: { std::ostringstream key, item; key<<"cl.channel"<<idx+1; - item<<"Channel "<<idx+1; + item<<"Channel"<<idx+1; AddChoice(key.str(), item.str()); } @@ -135,19 +136,23 @@ private: region.SetIndex(0, GetParameterInt("startx")); region.SetIndex(1, GetParameterInt("starty")); - if (region.Crop(GetParameterImage("in")->GetLargestPossibleRegion())) + if ( HasValue("in") ) { - SetParameterInt("sizex", region.GetSize(0)); - SetParameterInt("sizey", region.GetSize(1)); - SetParameterInt("startx", region.GetIndex(0)); - SetParameterInt("starty", region.GetIndex(1)); - return true; + if (region.Crop(GetParameterImage("in")->GetLargestPossibleRegion())) + { + SetParameterInt("sizex", region.GetSize(0)); + SetParameterInt("sizey", region.GetSize(1)); + SetParameterInt("startx", region.GetIndex(0)); + SetParameterInt("starty", region.GetIndex(1)); + return true; + } } return false; } void DoExecute() { + std::cout<<"goooooooooooooooooooooooooooooooooooooooooooooooooooooooo"<<std::endl; ExtractROIFilterType::InputImageType* inImage = GetParameterImage("in"); inImage->UpdateOutputInformation(); @@ -163,13 +168,13 @@ private: // std::cout <<"sizex"<<GetParameterInt("sizex") << std::endl; // std::cout <<"sizey"<<GetParameterInt("sizey") << std::endl; - //std::cout <<"Channels added : "; + std::cout <<"Channels added : "<<std::endl; for (unsigned int idx = 0; idx < GetSelectedItems("cl").size(); ++idx) { - //std::cout << GetSelectedItems("cl")[idx] + 1<< " "; + std::cout << GetSelectedItems("cl")[idx] + 1<< " "; m_ExtractROIFilter->SetChannel(GetSelectedItems("cl")[idx] + 1 ); } - //std::cout<<std::endl; + std::cout<<std::endl; SetParameterOutputImage("out", m_ExtractROIFilter->GetOutput()); } diff --git a/Code/ApplicationEngine/otbWrapperApplication.cxx b/Code/ApplicationEngine/otbWrapperApplication.cxx index 3563cd4ae5bd5b38788d9dcd619c9245cc46759d..f4f08676c28c30a48c774efe3f85afe5d7071277 100644 --- a/Code/ApplicationEngine/otbWrapperApplication.cxx +++ b/Code/ApplicationEngine/otbWrapperApplication.cxx @@ -276,6 +276,11 @@ std::vector<std::string> Application::GetChoiceKeys(std::string name) ChoiceParameter* paramChoice = dynamic_cast<ChoiceParameter*>(param); return paramChoice->GetChoiceKeys(); } + else if (dynamic_cast<ListViewParameter*>(param)) + { + ListViewParameter* paramList = dynamic_cast<ListViewParameter*>(param); + return paramList->GetChoiceKeys(); + } itkExceptionMacro(<< name << " is not a choice parameter"); } @@ -287,6 +292,11 @@ std::vector<std::string> Application::GetChoiceNames(std::string name) ChoiceParameter* paramChoice = dynamic_cast<ChoiceParameter*>(param); return paramChoice->GetChoiceNames(); } + else if (dynamic_cast<ListViewParameter*>(param)) + { + ListViewParameter* paramList = dynamic_cast<ListViewParameter*>(param); + return paramList->GetChoiceNames(); + } itkExceptionMacro(<< name << " is not a choice parameter"); } diff --git a/Code/ApplicationEngine/otbWrapperListViewParameter.cxx b/Code/ApplicationEngine/otbWrapperListViewParameter.cxx index 69fe80c6fc0bf70360a9bf2eec51f5d191d3da1d..5d72e0ab273b5d628148fd9009197c27fb532d80 100644 --- a/Code/ApplicationEngine/otbWrapperListViewParameter.cxx +++ b/Code/ApplicationEngine/otbWrapperListViewParameter.cxx @@ -123,29 +123,6 @@ ListViewParameter::GetValue() return m_CurrentChoice; } -// TODO : not implemented yet -std::vector<std::string> -ListViewParameter::GetParametersKeys() -{ - std::vector<std::string> parameters; - - ChoiceList::iterator cit = m_ChoiceList.begin(); - - // for (cit = m_ChoiceList.begin(); cit != m_ChoiceList.end(); ++cit) - // { - // if (cit->m_AssociatedParameter) - // { - // std::vector<std::string> subparams = cit->m_AssociatedParameter->GetParametersKeys(); - // for (std::vector<std::string>::const_iterator it = subparams.begin(); - // it != subparams.end(); ++it) - // { - // parameters.push_back( cit->m_Key + "." + *it ); - // } - // } - // } - return parameters; -} - /** Clear choices */ void @@ -154,6 +131,67 @@ ListViewParameter::ClearChoices() m_ChoiceList.clear(); } +void +ListViewParameter::SetSelectedItemsByNames() +{ + std::vector<int> selectedItems; + std::vector<std::string> names = this->GetChoiceNames(); + for(unsigned int i=0; i<m_SelectedNames.size(); i++) + { + const std::string selectedName = m_SelectedNames[i]; + unsigned int j(0); + for( ; j<names.size(); j++) + { + if( names[j] == selectedName ) + { + selectedItems.push_back(j); + break; + } + } + // If not found + if( j==names.size() ) + { + for( j=0; j<names.size(); j++) + { + std::cout<<names[j]<<std::endl; + } + itkExceptionMacro("Value "<<selectedName<<" not found in the ch888oices possibilities..."); + } + } + this->SetSelectedItems(selectedItems); +} + + + +void +ListViewParameter::SetSelectedItemsByKeys() +{ + std::vector<int> selectedItems; + std::vector<std::string> keys = this->GetChoiceKeys(); + for(unsigned int i=0; i<m_SelectedKeys.size(); i++) + { + const std::string selectedKey = m_SelectedKeys[i]; + unsigned int j(0); + for( ; j<keys.size(); j++) + { + if( keys[j] == selectedKey ) + { + selectedItems.push_back(j); + break; + } + } + // If not found + if( j==keys.size() ) + { + for( j=0; j<keys.size(); j++) + { + std::cout<<keys[j]<<std::endl; + } + itkExceptionMacro("Value "<<selectedKey<<" not found in the choices possibilities...") + } + } + this->SetSelectedItems(selectedItems); +} } } diff --git a/Code/ApplicationEngine/otbWrapperListViewParameter.h b/Code/ApplicationEngine/otbWrapperListViewParameter.h index 1b4b811ecbaf1354b44812be37b5f5022b9f517e..bfdb6a627c0feb7c8f37228401c8a23305cc9753 100644 --- a/Code/ApplicationEngine/otbWrapperListViewParameter.h +++ b/Code/ApplicationEngine/otbWrapperListViewParameter.h @@ -64,9 +64,6 @@ public: /** Get the list of the different choice keys */ std::vector<std::string> GetChoiceNames(); - /** Get all parameters that are child of this choice parameter */ - std::vector<std::string> GetParametersKeys(); - /** Get the number of available choice */ unsigned int GetNbChoices( void ); @@ -94,9 +91,59 @@ public: std::vector<int> GetSelectedItems() { + if( m_SelectedNames.size() != 0 ) + { + this->SetSelectedItemsByNames(); + } + else if( m_SelectedKeys.size() != 0 ) + { + this->SetSelectedItemsByKeys(); + } + return m_SelectedItems; } + void SetSelectedNames(std::vector<std::string> selectedNames) + { + m_SelectedNames = selectedNames; + m_SelectedItems.clear(); + m_SelectedKeys.clear(); + } + + std::vector<std::string> GetSelectedNames() + { + return m_SelectedNames; + } + + + void SetSelectedKeys(std::vector<std::string> selectedKeys) + { + m_SelectedKeys = selectedKeys; + m_SelectedItems.clear(); + m_SelectedNames.clear(); + } + + std::vector<std::string> GetSelectedKeys() + { + return m_SelectedKeys; + } + + /** Set selected items using a lit of selected keys. */ + void SetSelectedItemsByKeys(); + /** Set selected items using a lit of selected names. */ + void SetSelectedItemsByNames(); + void SetSelectedItems(std::vector<std::string> selectedItems) + { + std::vector<int> items; + for( unsigned int i=0; i<selectedItems.size(); i++ ) + { + items.push_back( atoi( selectedItems[i].c_str() ) ); + } + m_SelectedItems = items; + m_SelectedNames.clear(); + m_SelectedKeys.clear(); + } + void SetSelectedItems(std::vector<int> selectedItems) { m_SelectedItems = selectedItems; @@ -121,6 +168,8 @@ protected: ChoiceList m_ChoiceList; unsigned int m_CurrentChoice; std::vector<int> m_SelectedItems; + std::vector<std::string> m_SelectedKeys; + std::vector<std::string> m_SelectedNames; private: ListViewParameter(const ListViewParameter &); //purposely not implemented diff --git a/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx b/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx index e9f69a04c17f5367a9a00ea84b276e267782594f..b27a7c7caef9391a976ad07e52a9e4794c09e402 100644 --- a/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx +++ b/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx @@ -30,6 +30,9 @@ #include "otbWrapperOutputVectorDataParameter.h" #include "otbWrapperRadiusParameter.h" #include "otbWrapperStringParameter.h" +#include "otbWrapperListViewParameter.h" + + // List value parameter #include "otbWrapperInputImageListParameter.h" #include "otbWrapperStringListParameter.h" @@ -182,6 +185,8 @@ CommandLineLauncher::BeforeExecute() return false; } + m_Application->UpdateParameters(); + // Check for the progress report bool doProgressReport = true; if( m_Parser->IsAttributExists( "--progress", m_Expression ) == true ) @@ -374,6 +379,10 @@ CommandLineLauncher::LoadParameters() return INVALIDNUMBEROFVALUE; } } + else if( type == ParameterType_ListView ) + { + dynamic_cast<ListViewParameter *>(param.GetPointer())->SetSelectedNames( values ); + } else if( values.size() != 1) { std::cout<<"INVALIDNUMBEROFVALUE: "<<paramKey<<" "<<values.size()<<std::endl; @@ -498,19 +507,6 @@ 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; - std::cerr<<"\t Type: String (int8, uint8, int16, uint16, int32, uint32, float or double)"<<std::endl; - std::cerr<<"\t Default value: float"<< std::endl; - if( !m_Parser->IsAttributExists( "--progress", m_Expression ) ) - std::cerr<<"\t Status: DEFAULT VALUE"<<std::endl; - else if( m_Parser->GetAttribut( "--outPix", m_Expression ).size() == 0 ) - 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] ); @@ -542,7 +538,7 @@ 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 { @@ -611,6 +607,20 @@ CommandLineLauncher::DisplayParameterHelp( const Parameter::Pointer & param, con } oss<<std::endl; } + else if( type == ParameterType_ListView ) + { + oss<<"\t Type: List of int "; + std::vector<std::string> names = m_Application->GetChoiceNames(paramKey); + for( unsigned int j=0; j<names.size(); j++ ) + { + oss << names[j]; + if( j<= names.size()-1 ) + { + oss << ", "; + } + } + oss << std::endl; + } else { oss<<"\t Type: Type not handle yet"<<std::endl;