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

ENH: improve inputimagelist

parent 71ef597d
No related branches found
No related tags found
No related merge requests found
......@@ -88,12 +88,25 @@ private:
// Get the input image list
FloatVectorImageListType::Pointer inList = this->GetParameterImageList("il");
if( inList->Size() == 0 )
{
itkExceptionMacro("No input Image set...");
}
inList->GetNthElement(0)->UpdateOutputInformation();
FloatVectorImageType::SizeType size = inList->GetNthElement(0)->GetLargestPossibleRegion().GetSize();
// Split each input vector image into image
// and generate an mono channel image list
for( unsigned int i=0; i<inList->Size(); i++ )
{
FloatVectorImageType::Pointer vectIm = inList->GetNthElement(i);
vectIm->UpdateOutputInformation();
if( size != vectIm->GetLargestPossibleRegion().GetSize() )
{
itkExceptionMacro("Input Image size mismatch...");
}
for( unsigned int j=0; j<vectIm->GetNumberOfComponentsPerPixel(); j++)
{
ExtractROIFilterType::Pointer extractor = ExtractROIFilterType::New();
......@@ -105,6 +118,8 @@ private:
}
}
m_Concatener->SetInput( m_ImageList );
SetParameterOutputImage("out", m_Concatener->GetOutput());
......
......@@ -623,7 +623,7 @@ FloatVectorImageListType* Application::GetParameterImageList(std::string paramet
Parameter* param = GetParameterByKey(parameter);
if (dynamic_cast<InputImageListParameter*>(param))
{
{
InputImageListParameter* paramDown = dynamic_cast<InputImageListParameter*>(param);
ret = paramDown->GetImageList();
}
......
......@@ -38,33 +38,79 @@ InputImageListParameter::~InputImageListParameter()
void
InputImageListParameter::SetListFromFileName(const std::vector<std::string> & filenames)
{
// First clear previous file choosen
this->ClearValue();
bool isOk = false;
for(unsigned int i=0; i<filenames.size(); i++)
{
ImageFileReaderType::Pointer reader = ImageFileReaderType::New();
reader->SetFileName(filenames[i]);
reader->UpdateOutputInformation();
// everything went fine, store the object references
m_ReaderList->PushBack(reader);
m_ImageList->PushBack(reader->GetOutput());
const std::string filename = filenames[i];
// TODO : when the logger will be available, redirect the exception
// in the logger (like what is done in MsgReporter)
if (!filename.empty()
&& itksys::SystemTools::FileExists(filename.c_str()))
{
ImageFileReaderType::Pointer reader = ImageFileReaderType::New();
reader->SetFileName(filename);
try
{
reader->UpdateOutputInformation();
}
catch(itk::ExceptionObject & err)
{
this->ClearValue();
isOk = false;
break;
}
// everything went fine, store the object references
m_ReaderList->PushBack(reader);
m_ImageList->PushBack(reader->GetOutput());
}
}
SetActive(true);
this->Modified();
if( isOk == true )
{
SetActive(true);
this->Modified();
}
}
void
InputImageListParameter::AddNullElement()
{
m_ReaderList->PushBack(NULL);
m_ImageList->PushBack(NULL);
SetActive(false);
this->Modified();
}
void
InputImageListParameter::AddFromFileName(const std::string & filename)
{
ImageFileReaderType::Pointer reader = ImageFileReaderType::New();
reader->SetFileName(filename);
reader->UpdateOutputInformation();
// TODO : when the logger will be available, redirect the exception
// in the logger (like what is done in MsgReporter)
if (!filename.empty()
&& itksys::SystemTools::FileExists(filename.c_str()))
{
ImageFileReaderType::Pointer reader = ImageFileReaderType::New();
reader->SetFileName(filename);
try
{
reader->UpdateOutputInformation();
}
catch(itk::ExceptionObject & err)
{
this->ClearValue();
}
// everything went fine, store the object references
m_ReaderList->PushBack(reader);
m_ImageList->PushBack(reader->GetOutput());
SetActive(true);
this->Modified();
// everything went fine, store the object references
m_ReaderList->PushBack(reader);
m_ImageList->PushBack(reader->GetOutput());
SetActive(true);
this->Modified();
}
}
void
......@@ -74,12 +120,27 @@ InputImageListParameter::SetNthFileName( const unsigned int id, const std::strin
{
itkExceptionMacro(<< "No image "<<id<<". Only "<<m_ReaderList->Size()<<" images available.");
}
ImageFileReaderType::Pointer reader = ImageFileReaderType::New();
reader->SetFileName(filename);
reader->UpdateOutputInformation();
m_ReaderList->SetNthElement(id, reader);
m_ImageList->SetNthElement(id, reader->GetOutput());
// TODO : when the logger will be available, redirect the exception
// in the logger (like what is done in MsgReporter)
if (!filename.empty()
&& itksys::SystemTools::FileExists(filename.c_str()))
{
ImageFileReaderType::Pointer reader = ImageFileReaderType::New();
reader->SetFileName(filename);
try
{
reader->UpdateOutputInformation();
}
catch(itk::ExceptionObject & err)
{
this->ClearValue();
}
m_ReaderList->SetNthElement(id, reader);
m_ImageList->SetNthElement(id, reader->GetOutput());
this->Modified();
}
}
......@@ -136,21 +197,51 @@ InputImageListParameter::GetNthImage(unsigned int i) const
void
InputImageListParameter::SetImageList(FloatVectorImageListType* imList)
{
// Check input availability
// TODO : when the logger will be available, redirect the exception
// in the logger (like what is done in MsgReporter)
try
{
for(unsigned int i=0; i<imList->Size(); i++)
{
imList->GetNthElement( i )->UpdateOutputInformation();
}
}
catch(itk::ExceptionObject & err)
{
return;
}
m_ImageList = imList;
m_ReaderList = ImageFileReaderListType::Pointer();
for(unsigned int i=0; i<m_ImageList->Size(); i++)
{
m_ReaderList->PushBack( ImageFileReaderType::Pointer() );
}
SetActive(true);
this->Modified();
}
void
InputImageListParameter::AddImage(FloatVectorImageType* image)
{
// Check input availability
// TODO : when the logger will be available, redirect the exception
// in the logger (like what is done in MsgReporter)
try
{
image->UpdateOutputInformation();
}
catch(itk::ExceptionObject & err)
{
return;
}
m_ImageList->PushBack( image );
m_ReaderList->PushBack( ImageFileReaderType::Pointer() );
this->Modified();
}
bool
......@@ -161,7 +252,16 @@ InputImageListParameter::HasValue() const
return false;
}
return m_ImageList->GetNthElement(0).IsNotNull();
bool res(true);
unsigned int i(0);
while(i<m_ImageList->Size() && res==true)
{
res = m_ImageList->GetNthElement(i).IsNotNull();
i++;
}
return res;
}
......@@ -175,13 +275,18 @@ InputImageListParameter::Erase( unsigned int id )
m_ImageList->Erase( id );
m_ReaderList->Erase( id );
this->Modified();
}
void
InputImageListParameter::Clear()
InputImageListParameter::ClearValue()
{
m_ImageList->Clear();
m_ReaderList->Clear();
SetActive(false);
this->Modified();
}
......
......@@ -52,11 +52,13 @@ public:
/** Set image form a list of filename */
void SetListFromFileName(const std::vector<std::string> & filenames);
/** Add null element to lists. */
void AddNullElement();
/** Add an image from a filename */
void AddFromFileName(const std::string & filename);
/** Set one specific stored image filename. */
/** Set one specific stored image filename. */
void SetNthFileName( const unsigned int id, const std::string & filename );
......@@ -85,7 +87,7 @@ public:
void Erase( unsigned int id );
/** Clear all the list. */
void Clear();
virtual void ClearValue();
protected:
......
......@@ -23,16 +23,8 @@ namespace Wrapper
{
QtFileSelectionWidget::QtFileSelectionWidget()
: QWidget() /*, m_Index(0), m_AsValue(false)*/
: QWidget()
{
//m_InputList = InputImageListParameter::New();
this->DoCreateWidget();
}
QtFileSelectionWidget::QtFileSelectionWidget( InputImageListParameter * il )
: QWidget()/*, m_Index(0), m_AsValue(false)*/
{
//m_InputList = il;
this->DoCreateWidget();
}
......@@ -66,7 +58,6 @@ void QtFileSelectionWidget::DoCreateWidget()
m_Button->setToolTip("Select file...");
m_Button->setFixedWidth(30);
//m_Button->setMaximumWidth(m_Button->width());
connect( m_Button, SIGNAL(clicked()), this, SLOT(SelectFile()) );
m_HLayout->addWidget(m_Button);
......@@ -82,21 +73,8 @@ void QtFileSelectionWidget::SelectFile()
if (fileDialog.exec())
{
//this->SetFileName(fileDialog.selectedFiles().at(0));
QString filemane(fileDialog.selectedFiles().at(0));
m_Input->setText(filemane);
/*
if( m_AsValue == false )
{
m_InputList->AddFromFileName(filemane.toStdString());
m_Index = m_InputList->GetImageList()->Size()-1;
m_AsValue = true;
}
else
{
m_InputList->SetNthFileName( m_Index, filemane.toStdString());
}
*/
}
}
......
......@@ -36,33 +36,8 @@ class QtFileSelectionWidget : public QWidget
Q_OBJECT
public:
QtFileSelectionWidget();
QtFileSelectionWidget( InputImageListParameter * il );
virtual ~QtFileSelectionWidget();
/*
InputImageListParameter * GetInputList()
{
return m_InputList;
}
void SetInputList(InputImageListParameter * il)
{
m_InputList = il;
}
*/
/*
unsigned int GetIndex()
{
return m_Index;
}
unsigned int SetIndex( unsigned int id )
{
m_Index = id;
}
*/
bool IsChecked()
{
return m_Checkbox->isChecked();
......@@ -78,9 +53,12 @@ public:
return m_Input->text().toStdString();
}
QLineEdit* GetInput()
{
return m_Input;
}
protected slots:
//void SetFileName( const QString& value );
void SelectFile();
private:
......@@ -96,9 +74,6 @@ private:
QLineEdit* m_Input;
QPushButton * m_Button;
QCheckBox * m_Checkbox;
//InputImageListParameter::Pointer m_InputList;
//unsigned int m_Index;
//bool m_AsValue;
};
......
......@@ -26,6 +26,7 @@ QtWidgetInputImageListParameter::QtWidgetInputImageListParameter(InputImageListP
: QtWidgetParameterBase(param, m),
m_InputImageListParam(param)
{
connect( this, SIGNAL(Change()), GetModel(), SLOT(NotifyUpdate()) );
}
QtWidgetInputImageListParameter::~QtWidgetInputImageListParameter()
......@@ -66,7 +67,6 @@ void QtWidgetInputImageListParameter::DoCreateWidget()
addButton->setText("+");
addButton->setFixedWidth(buttonSize);
addButton->setToolTip("Add a file selector...");
//addButton->setMaximumWidth(addButton->width());
connect( addButton, SIGNAL(clicked()), this, SLOT(AddFile()) );
addSupLayout->addWidget(addButton);
......@@ -107,9 +107,12 @@ void QtWidgetInputImageListParameter::DoCreateWidget()
QVBoxLayout * fileLayout = new QVBoxLayout();
fileLayout->setSpacing(0);
QtFileSelectionWidget * fileSelection = new QtFileSelectionWidget(m_InputImageListParam);
fileSelection->setFixedHeight(40);
QtFileSelectionWidget * fileSelection = new QtFileSelectionWidget();
fileSelection->setFixedHeight(30);
fileLayout->addWidget( fileSelection );
m_InputImageListParam->AddNullElement();
connect( fileSelection->GetInput(), SIGNAL(textChanged(const QString&)), this, SLOT(UpdateImageList()) );
m_FileSelectionList.push_back(fileSelection);
QGroupBox *mainGroup = new QGroupBox();
......@@ -131,6 +134,18 @@ void QtWidgetInputImageListParameter::DoCreateWidget()
}
void
QtWidgetInputImageListParameter::UpdateImageList()
{
// save value
for(unsigned int j=0; j<m_InputImageListParam->GetImageList()->Size(); j++ )
{
m_InputImageListParam->SetNthFileName(j, m_FileSelectionList[j]->GetFilename());
}
emit Change();
}
void
QtWidgetInputImageListParameter::UpFile()
......@@ -244,6 +259,10 @@ QtWidgetInputImageListParameter::UpdateFileList( std::map<unsigned int, unsigned
m_Scroll->setWidget(mainGroup);
this->update();
// notify of value change
QString key( QString::fromStdString(m_InputImageListParam->GetKey()) );
emit ParameterChanged(key);
}
......@@ -262,13 +281,15 @@ QtWidgetInputImageListParameter::AddFile()
fileSelection->setFixedHeight( 30 );
m_FileLayout->addWidget( fileSelection );
m_FileSelectionList.push_back(fileSelection);
m_InputImageListParam->AddNullElement();
connect( fileSelection->GetInput(), SIGNAL(textChanged(const QString&)), this, SLOT(UpdateImageList()) );
QGroupBox *mainGroup = new QGroupBox();
mainGroup->setLayout(m_FileLayout);
m_Scroll->setWidget(mainGroup);
this->update();
this->RecreateImageList();
}
void
......@@ -305,9 +326,11 @@ QtWidgetInputImageListParameter::EraseFile()
m_FileLayout = new QVBoxLayout();
QtFileSelectionWidget * fileSelection = new QtFileSelectionWidget();
fileSelection->setFixedHeight( 40 );
fileSelection->setFixedHeight( 30 );
m_FileLayout->addWidget( fileSelection );
m_FileSelectionList.push_back(fileSelection);
m_InputImageListParam->AddNullElement();
connect( fileSelection->GetInput(), SIGNAL(textChanged(const QString&)), this, SLOT(UpdateImageList()) );
QGroupBox *mainGroup = new QGroupBox();
mainGroup->setLayout(m_FileLayout);
......@@ -321,13 +344,14 @@ QtWidgetInputImageListParameter::EraseFile()
void QtWidgetInputImageListParameter::RecreateImageList()
{
// save value
m_InputImageListParam->Clear();
m_InputImageListParam->ClearValue();
for(unsigned int j=0; j<m_FileSelectionList.size(); j++ )
{
if( m_FileSelectionList[j]->GetFilename() != "" )
m_InputImageListParam->AddFromFileName(m_FileSelectionList[j]->GetFilename());
m_InputImageListParam->AddFromFileName(m_FileSelectionList[j]->GetFilename());
connect( m_FileSelectionList[j]->GetInput(), SIGNAL(textChanged(const QString&)), this, SLOT(UpdateImageList()) );
}
emit Change();
// notify of value change
QString key( QString::fromStdString(m_InputImageListParam->GetKey()) );
emit ParameterChanged(key);
......
......@@ -38,6 +38,10 @@ public:
QtWidgetInputImageListParameter(InputImageListParameter*, QtWidgetModel*);
virtual ~QtWidgetInputImageListParameter();
signals:
void Change();
protected slots:
//void SetFileName( const QString& value );
//virtual void SelectFile();
......@@ -46,7 +50,7 @@ protected slots:
virtual void AddFile();
virtual void SupressFile();
virtual void EraseFile();
virtual void UpdateImageList();
private:
QtWidgetInputImageListParameter(const QtWidgetInputImageListParameter&); //purposely not implemented
......@@ -63,14 +67,6 @@ private:
QHBoxLayout * m_HLayout;
QVBoxLayout * m_FileLayout;
//QVBoxLayout * m_ButtonLayout;
//QHBoxLayout * m_AddSupLayout;
//QHBoxLayout * m_UpDownLayout;
//QPushButton * m_SupButton;
//QPushButton * m_AddButton;
//QPushButton * m_EraseButton;
//QPushButton * m_UpButton;
//QPushButton * m_DownButton;
QScrollArea * m_Scroll;
std::vector<QtFileSelectionWidget *> m_FileSelectionList;
};
......
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