]> Creatis software - clitk.git/commitdiff
Add wipe file tests
authortbaudier <thomas.baudier@creatis.insa-lyon.fr>
Mon, 22 Aug 2016 07:42:15 +0000 (09:42 +0200)
committertbaudier <thomas.baudier@creatis.insa-lyon.fr>
Mon, 22 Aug 2016 07:42:15 +0000 (09:42 +0200)
vv/extensions.h [new file with mode: 0644]
vv/vvMainWindow.cxx
vv/vvMainWindow.h
vv/vvWipeImage.cxx
vv/vvWipeImage.h

diff --git a/vv/extensions.h b/vv/extensions.h
new file mode 100644 (file)
index 0000000..c09ad87
--- /dev/null
@@ -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
index 0075d46aa76718d59321c792adbd0045465602b2..e756ddf6b1288c04d20b5fb286f0f953de4acef3 100644 (file)
@@ -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 <extensions.h>
 
 
 /*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<std::string> vecFileNames;
   for (int i = 0; i < files.size(); i++) {
     vecFileNames.push_back(files[i].toStdString());
-  }
+  }*/
 
   //AddWipeImage(index,vecFileNames,vvImageReader::IMAGE);
 }
index 1e0ad6fdfc61cfc10607cd3d16f1284d2db1defa..1ddf45d307bea1adb5756fae9b6290b2f1a860f7 100644 (file)
@@ -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;
index 7c7cc00c0888b73a16b4ad572bbba435663aa220..c2d5a7e303378483d01924a61b7e6aca7c6c4f9b 100644 (file)
@@ -31,6 +31,7 @@
 #include <QApplication>
 #include <QMessageBox>
 #include <QSignalMapper>
+#include <QFileDialog>
 
 // vtk
 #include <vtkVersion.h>
 #include <vtkImageData.h>
 #include <vtkSmartPointer.h>
 
-//------------------------------------------------------------------------------
-// Create the tool and automagically (I like this word) insert it in
-// the main window menu.
-ADD_TOOL(vvWipeImage);
-//------------------------------------------------------------------------------
+
+#include <extensions.h>
+
+#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<vvWipeImage>(parent),
+vvWipeImage::vvWipeImage():
   Ui::vvWipeImage()
 {
     vtkSmartPointer<vtkImageRectilinearWipe> mWipe = vtkSmartPointer<vtkImageRectilinearWipe>::New();
@@ -64,45 +69,23 @@ vvWipeImage::~vvWipeImage()
 }
 //------------------------------------------------------------------------------
 
-//------------------------------------------------------------------------------
-void vvWipeImage::setInput(int number, vvImage::Pointer image)
+void vvWipeImage::Initialize(QString inputPathName, std::vector<vvSlicerManager*> 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; i<mCurrentSlicerManager->GetNumberOfSlicers(); 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; i<mCurrentSlicerManager->GetNumberOfSlicers(); 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<vtkMatrix4x4>::New();
-  mConcatenedTransform->DeepCopy(slicer->GetSlicer(0)->GetConcatenatedTransform()->GetMatrix());
-  vtkSmartPointer<vtkMatrix4x4> matrix = vtkSmartPointer<vtkMatrix4x4>::New();
-  matrix->Identity();
-  mCurrentSlicerManager->GetImage()->GetTransform()[0]->SetMatrix(matrix);
-  for (int i=0; i<mCurrentSlicerManager->GetNumberOfSlicers(); 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<std::string> 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<std::string> 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!");
 }
 //------------------------------------------------------------------------------
 
+
+
index 9b3970883865813f97748fc4a7856b5231f80e76..138866d0283246fcee54bdb93462bdc21d370aac 100644 (file)
 #include <QtDesigner/QDesignerExportWidget>
 #include <QDialog>
 #include <QSlider>
+#include <QMessageBox>
+#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 <vtkTransform.h>
 #include <vtkImageRectilinearWipe.h>
+//itk
+#include <itkLightObject.h>
 
 //------------------------------------------------------------------------------
 class vvWipeImage:
-  public vvToolWidgetBase,
-  public vvToolBase<vvWipeImage>, 
-  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<Self> 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<vvSlicerManager*> slicerManagers);
+  void selectWipeImage(int index);
+  void setInputImage(int number, vvImage::Pointer image);
+  void AddWipeImage(int index, std::vector<std::string> 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<vtkImageRectilinearWipe> mWipe;
   void UpdateWipe();
-  virtual void closeEvent(QCloseEvent *event);
   vtkSmartPointer<vtkMatrix4x4> mConcatenedTransform;
   vvImage::Pointer mImage;
+  QString mInputPathName;
+  std::vector<vvSlicerManager*> mSlicerManagers;
 
 }; // end class vvWipeImage
 //------------------------------------------------------------------------------