From d9c91416397b25702d1946944730c0569a207164 Mon Sep 17 00:00:00 2001 From: tbaudier Date: Mon, 22 Aug 2016 09:42:15 +0200 Subject: [PATCH] Add wipe file tests --- vv/extensions.h | 5 + vv/vvMainWindow.cxx | 15 +-- vv/vvMainWindow.h | 5 + vv/vvWipeImage.cxx | 224 ++++++++++++++++++++++---------------------- vv/vvWipeImage.h | 45 ++++----- 5 files changed, 154 insertions(+), 140 deletions(-) create mode 100644 vv/extensions.h diff --git a/vv/extensions.h b/vv/extensions.h new file mode 100644 index 0000000..c09ad87 --- /dev/null +++ b/vv/extensions.h @@ -0,0 +1,5 @@ +#ifdef CLITK_PRIVATE_FEATURES +#define EXTENSIONS "Images ( *.bmp *.dcm *.png *.jpeg *.jpg *.tif *.mhd *.mha *.hdr *.vox *.his *.xdr *.SCAN *.nii *.nrrd *.nhdr *.refscan *.nii.gz *.usf *.svl)" +#else +#define EXTENSIONS "Images ( *.bmp *.dcm *.png *.jpeg *.jpg *.tif *.mhd *.mha *.hdr *.vox *.his *.xdr *.SCAN *.nii *.nrrd *.nhdr *.refscan *.nii.gz)" +#endif diff --git a/vv/vvMainWindow.cxx b/vv/vvMainWindow.cxx index 0075d46..e756ddf 100644 --- a/vv/vvMainWindow.cxx +++ b/vv/vvMainWindow.cxx @@ -109,11 +109,7 @@ It is distributed under dual licence #define COLUMN_RELOAD_IMAGE 6 #define COLUMN_IMAGE_NAME 7 -#ifdef CLITK_PRIVATE_FEATURES -#define EXTENSIONS "Images ( *.bmp *.dcm *.png *.jpeg *.jpg *.tif *.mhd *.mha *.hdr *.vox *.his *.xdr *.SCAN *.nii *.nrrd *.nhdr *.refscan *.nii.gz *.usf *.svl)" -#else -#define EXTENSIONS "Images ( *.bmp *.dcm *.png *.jpeg *.jpg *.tif *.mhd *.mha *.hdr *.vox *.his *.xdr *.SCAN *.nii *.nrrd *.nhdr *.refscan *.nii.gz)" -#endif +#include /*Data Tree values @@ -2148,11 +2144,16 @@ void vvMainWindow::AddROI(int index, QString file) void vvMainWindow::SelectWipeImage() { int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]); + if (!(CheckAddedImage(index, "wipe"))) return; - QString Extensions = EXTENSIONS; + vvWipeImage::Pointer wipeImage = vvWipeImage::New(); + wipeImage->Initialize(mInputPathName, mSlicerManagers); + wipeImage->selectWipeImage(index); + + /*QString Extensions = EXTENSIONS; Extensions += ";;All Files (*)"; QStringList files = QFileDialog::getOpenFileNames(this,tr("Load Wipe image"),mInputPathName,Extensions); if (files.isEmpty()) @@ -2161,7 +2162,7 @@ void vvMainWindow::SelectWipeImage() std::vector vecFileNames; for (int i = 0; i < files.size(); i++) { vecFileNames.push_back(files[i].toStdString()); - } + }*/ //AddWipeImage(index,vecFileNames,vvImageReader::IMAGE); } diff --git a/vv/vvMainWindow.h b/vv/vvMainWindow.h index 1e0ad6f..1ddf45d 100644 --- a/vv/vvMainWindow.h +++ b/vv/vvMainWindow.h @@ -26,6 +26,7 @@ #include "vvToolManager.h" #include "vvImageReader.h" #include "vvMesh.h" +#include "vvWipeImage.h" #include "clitkMemoryUsage.h" #include "vtkSmartPointer.h" @@ -48,6 +49,8 @@ class vvMainWindow: public vvMainWindowBase, { Q_OBJECT + friend class vvWipeImage; + public: vvMainWindow(); ~vvMainWindow(); @@ -194,6 +197,8 @@ private: vvHelpDialog *help_dialog; vvDocumentation *documentation; vvDicomSeriesSelector *dicomSeriesSelector; + + vvWipeImage::Pointer mWipeImage; bool viewMode; bool playMode; diff --git a/vv/vvWipeImage.cxx b/vv/vvWipeImage.cxx index 7c7cc00..c2d5a7e 100644 --- a/vv/vvWipeImage.cxx +++ b/vv/vvWipeImage.cxx @@ -31,6 +31,7 @@ #include #include #include +#include // vtk #include @@ -39,16 +40,20 @@ #include #include -//------------------------------------------------------------------------------ -// Create the tool and automagically (I like this word) insert it in -// the main window menu. -ADD_TOOL(vvWipeImage); -//------------------------------------------------------------------------------ + +#include + +#define COLUMN_TREE 0 +#define COLUMN_UL_VIEW 1 +#define COLUMN_UR_VIEW 2 +#define COLUMN_DL_VIEW 3 +#define COLUMN_DR_VIEW 4 +#define COLUMN_CLOSE_IMAGE 5 +#define COLUMN_RELOAD_IMAGE 6 +#define COLUMN_IMAGE_NAME 7 //------------------------------------------------------------------------------ -vvWipeImage::vvWipeImage(vvMainWindowBase * parent, Qt::WindowFlags f): - vvToolWidgetBase(parent, f), - vvToolBase(parent), +vvWipeImage::vvWipeImage(): Ui::vvWipeImage() { vtkSmartPointer mWipe = vtkSmartPointer::New(); @@ -64,45 +69,23 @@ vvWipeImage::~vvWipeImage() } //------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ -void vvWipeImage::setInput(int number, vvImage::Pointer image) +void vvWipeImage::Initialize(QString inputPathName, std::vector slicerManagers) { - if (image->GetVTKImages().size()) { - mImage = image; - mWipe->SetInputData(number, mImage->GetVTKImages()[0]); //[0] pour du 4D ? - } + mInputPathName = inputPathName; + mSlicerManagers = slicerManagers; } -//------------------------------------------------------------------------------ //------------------------------------------------------------------------------ -void vvWipeImage::closeEvent(QCloseEvent *event) +void vvWipeImage::setInputImage(int number, vvImage::Pointer image) { - mCurrentSlicerManager->GetImage()->GetTransform()[0]->SetMatrix(mConcatenedTransform); - for (int i=0; iGetNumberOfSlicers(); i++) { - mCurrentSlicerManager->GetSlicer(i)->ResetCamera(); - mCurrentSlicerManager->GetSlicer(i)->Render(); - mCurrentSlicerManager->UpdateLinkedNavigation( mCurrentSlicerManager->GetSlicer(i) ); + if (image->GetVTKImages().size()) { + mImage = image; + mWipe->SetInputData(number, mImage->GetVTKImages()[0]); //[0] pour du 4D ? } - vvToolWidgetBase::closeEvent(event); -} -//------------------------------------------------------------------------------ - - -//------------------------------------------------------------------------------ -bool vvWipeImage::close() -{ - return vvToolWidgetBase::close(); } //------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ -void vvWipeImage::reject() -{ - return vvToolWidgetBase::reject(); -} -//------------------------------------------------------------------------------ - //------------------------------------------------------------------------------ void vvWipeImage::crossPointerChanged() @@ -116,94 +99,111 @@ void vvWipeImage::crossPointerChanged() //------------------------------------------------------------------------------ void vvWipeImage::UpdateWipe() { - for(int i=0; iGetNumberOfSlicers(); i++) { - //mCurrentSlicerManager->GetSlicer(i)->SetReducedExtent(mReducedExtent); - mCurrentSlicerManager->GetSlicer(i)->ForceUpdateDisplayExtent(); - mCurrentSlicerManager->GetSlicer(i)->Render(); - } + } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ -void vvWipeImage::InputIsSelected(vvSlicerManager * slicer) -{ - //Save the current transformation - mConcatenedTransform = vtkSmartPointer::New(); - mConcatenedTransform->DeepCopy(slicer->GetSlicer(0)->GetConcatenatedTransform()->GetMatrix()); - vtkSmartPointer matrix = vtkSmartPointer::New(); - matrix->Identity(); - mCurrentSlicerManager->GetImage()->GetTransform()[0]->SetMatrix(matrix); - for (int i=0; iGetNumberOfSlicers(); i++) { - mCurrentSlicerManager->GetSlicer(i)->ResetCamera(); - mCurrentSlicerManager->GetSlicer(i)->Render(); - mCurrentSlicerManager->UpdateLinkedNavigation( mCurrentSlicerManager->GetSlicer(i) ); - } +void vvWipeImage::selectWipeImage(int index) +{ - // Change interface according to number of dimension -#if VTK_MAJOR_VERSION <= 5 - int *a = mCurrentImage->GetFirstVTKImageData()->GetWholeExtent(); -#else - int *a = mCurrentImage->GetFirstVTKImageData()->GetInformation()->Get(vtkDataObject::DATA_EXTENT()); -#endif + QString Extensions = EXTENSIONS; + Extensions += ";;All Files (*)"; + QStringList files = QFileDialog::getOpenFileNames(NULL,tr("Load Wipe image"),mInputPathName,Extensions); + if (files.isEmpty()) + return; -// Set initial sliders values - int w_ext[6], imsize[3]; - mCurrentSlicerManager->GetSlicer(0)->GetRegisterExtent(w_ext); + std::vector vecFileNames; + for (int i = 0; i < files.size(); i++) { + vecFileNames.push_back(files[i].toStdString()); + } - QSignalMapper* signalMapper = new QSignalMapper(this); - connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(sliderValueChanged(int))); + AddWipeImage(index,vecFileNames,vvImageReader::IMAGE); } //------------------------------------------------------------------------------ +void vvWipeImage::AddWipeImage(int index, std::vector fileNames, vvImageReader::LoadedImageType type) +{ + QString file(fileNames[0].c_str()); + if (QFile::exists(file)) + { + mInputPathName = itksys::SystemTools::GetFilenamePath(file.toStdString()).c_str(); + itk::ImageIOBase::Pointer reader = itk::ImageIOFactory::CreateImageIO( + file.toStdString().c_str(), itk::ImageIOFactory::ReadMode); + reader->SetFileName(fileNames[0].c_str()); + reader->ReadImageInformation(); + std::string component = reader->GetComponentTypeAsString(reader->GetComponentType()); + int dimension = reader->GetNumberOfDimensions(); + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + vvProgressDialog progress("Opening " + file.toStdString()); + qApp->processEvents(); + + std::string filename = itksys::SystemTools::GetFilenameWithoutExtension(file.toStdString()).c_str(); +// if (mSlicerManagers[index]->SetOverlay(fileNames,dimension, component,type)) { + //create an item in the tree with good settings + QTreeWidgetItem *item = new QTreeWidgetItem(); + item->setData(0,Qt::UserRole,file.toStdString().c_str()); + item->setData(1,Qt::UserRole,tr("overlay")); + QFileInfo fileinfo(file); //Do not show the path + item->setData(COLUMN_IMAGE_NAME,Qt::DisplayRole,fileinfo.fileName()); + item->setToolTip(COLUMN_IMAGE_NAME, mSlicerManagers[index]->GetListOfAbsoluteFilePathInOneString("overlay").c_str()); + qApp->processEvents(); +#if VTK_MAJOR_VERSION > 5 + for ( unsigned int i = 0; i < mSlicerManagers[index]->GetNumberOfSlicers(); i++) + mSlicerManagers[index]->GetSlicer(i)->ForceUpdateDisplayExtent(); +#endif -//------------------------------------------------------------------------------ -void vvWipeImage::apply() -{ - if (!mCurrentSlicerManager) close(); - QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); - - // Typedef - typedef args_info_clitkCropImage ArgsInfoType; - typedef clitk::CropImageGenericFilter CropFilterType; - - // Get options - ArgsInfoType mArgsInfo; - cmdline_parser_clitkCropImage_init(&mArgsInfo); // Initialisation to default - int n = mCurrentSlicerManager->GetDimension()*2; // 2D and 3D only - mArgsInfo.boundingBox_given = n; - mArgsInfo.boundingBox_arg = new int[n]; - - // We MUST reset initial extend to input image before using the - // filter to retrieve the correct image size ; - // Main filter - CropFilterType::Pointer filter = CropFilterType::New(); - filter->SetInputVVImage(mCurrentImage); - filter->SetArgsInfo(mArgsInfo); - - // Go ! (not threaded) - try{ - filter->Update(); - } - catch(clitk::ExceptionObject & e) { - DD(e.what()); - QApplication::restoreOverrideCursor(); - delete [] mArgsInfo.boundingBox_arg; - close(); + for (int j = 1; j <= 4; j++) { + item->setData(j,Qt::CheckStateRole,GetTree()->topLevelItem(index)->data(j,Qt::CheckStateRole)); + } + + //Create the buttons for reload and close + qApp->processEvents(); + QTreePushButton* cButton = new QTreePushButton; + cButton->setItem(item); + cButton->setColumn(COLUMN_CLOSE_IMAGE); + cButton->setToolTip(tr("close image")); + cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png"))); + /*connect(cButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)), + this,SLOT(CloseImage(QTreeWidgetItem*, int))); + + QTreePushButton* rButton = new QTreePushButton; + rButton->setItem(item); + rButton->setColumn(COLUMN_RELOAD_IMAGE); + rButton->setToolTip(tr("reload image")); + rButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/rotateright.png"))); + connect(rButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)), + this,SLOT(ReloadImage(QTreeWidgetItem*, int))); + + DataTree->topLevelItem(index)->setExpanded(1); + DataTree->topLevelItem(index)->addChild(item); + DataTree->setItemWidget(item, COLUMN_CLOSE_IMAGE, cButton); + DataTree->setItemWidget(item, COLUMN_RELOAD_IMAGE, rButton); + + //set the id of the image + QString id = DataTree->topLevelItem(index)->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString(); + item->setData(COLUMN_IMAGE_NAME,Qt::UserRole,id.toStdString().c_str()); + UpdateTree(); + qApp->processEvents(); + ImageInfoChanged(); + QApplication::restoreOverrideCursor(); + + // Update the display to update, e.g., the sliders + for(int i=0; i<4; i++) + DisplaySliders(index, i); + } else { + QApplication::restoreOverrideCursor(); + QString error = "Cannot import the new image.\n"; + error += mSlicerManagers[index]->GetLastError().c_str(); + QMessageBox::information(this,tr("Problem reading image !"),error); + } + WindowLevelChanged(); */ } - std::ostringstream croppedImageName; - croppedImageName << "Cropped_" << mCurrentSlicerManager->GetSlicer(0)->GetFileName() << ".mhd"; - // Retrieve result and display it - vvImage::Pointer output = filter->GetOutputVVImage(); - - output->GetTransform()[0]->SetMatrix(mConcatenedTransform); - - AddImage(output,croppedImageName.str()); - - // End - QApplication::restoreOverrideCursor(); - delete [] mArgsInfo.boundingBox_arg; - close(); + else + QMessageBox::information(NULL,tr("Problem reading wipe Image !"),"File doesn't exist!"); } //------------------------------------------------------------------------------ + + diff --git a/vv/vvWipeImage.h b/vv/vvWipeImage.h index 9b39708..138866d 100644 --- a/vv/vvWipeImage.h +++ b/vv/vvWipeImage.h @@ -23,50 +23,53 @@ #include #include #include +#include +#include "QTreePushButton.h" // vv -#include "vvToolBase.h" -#include "vvToolWidgetBase.h" #include "vvMainWindowBase.h" +#include "vvImage.h" +#include "vvImageReader.h" +#include "vvProgressDialog.h" +#include "vvSlicerManager.h" #include "ui_vvWipeImage.h" //vtk #include #include +//itk +#include //------------------------------------------------------------------------------ class vvWipeImage: - public vvToolWidgetBase, - public vvToolBase, - private Ui::vvWipeImage + public QObject, + public itk::LightObject, + private Ui::vvWipeImage { Q_OBJECT public: - vvWipeImage(vvMainWindowBase * parent=0, Qt::WindowFlags f=0); + + typedef vvWipeImage Self; + typedef itk::SmartPointer Pointer; + typedef itk::ProcessObject::Pointer ConverterPointer; + + itkNewMacro(Self); + vvWipeImage(); ~vvWipeImage(); - virtual void InputIsSelected(vvSlicerManager *m); - void setInput(int number, vvImage::Pointer image); + void Initialize(QString inputPathName, std::vector slicerManagers); + void selectWipeImage(int index); + void setInputImage(int number, vvImage::Pointer image); + void AddWipeImage(int index, std::vector fileNames, vvImageReader::LoadedImageType type); public slots: - virtual void apply(); - virtual bool close(); - virtual void reject(); void crossPointerChanged(); - - //----------------------------------------------------- - static void Initialize() { - SetToolName("Wipe"); - SetToolMenuName("Wipe"); - SetToolIconFilename(":/common/icons/crop.png"); - SetToolTip("Wipe 2 images."); - } - protected: vtkSmartPointer mWipe; void UpdateWipe(); - virtual void closeEvent(QCloseEvent *event); vtkSmartPointer mConcatenedTransform; vvImage::Pointer mImage; + QString mInputPathName; + std::vector mSlicerManagers; }; // end class vvWipeImage //------------------------------------------------------------------------------ -- 2.47.1