Skip to content
Snippets Groups Projects
Commit e0649e4b authored by Cyrille Valladeau's avatar Cyrille Valladeau
Browse files

ENH: list view in progress in commandline

parent d6d8ce62
No related branches found
No related tags found
No related merge requests found
......@@ -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());
}
......
......@@ -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");
}
......
......@@ -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);
}
}
}
......@@ -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
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment