]> Creatis software - clitk.git/blobdiff - vv/vvMainWindow.cxx
Open files by dropping them inside the window
[clitk.git] / vv / vvMainWindow.cxx
index ba3f3136d721d1d5240d498d19fea343d57e13dc..153b461380e4566fb22418e90bd388141d84e887 100644 (file)
@@ -18,6 +18,7 @@ It is distributed under dual licence
 
 #include <algorithm>
 #include <QMessageBox>
+#include <QMimeData>
 #include <QInputDialog>
 #include <QTimer>
 #include "QTreePushButton.h"
@@ -48,7 +49,7 @@ It is distributed under dual licence
 #include "vvMeshReader.h"
 #include "vvSaveState.h"
 #include "vvReadState.h"
-#ifdef CLITK_USE_PACS_CONNECTION
+#if CLITK_USE_PACS_CONNECTION
 #include "vvQPacsConnection.h"
 #endif
 #include "clitkConfiguration.h"
@@ -82,9 +83,7 @@ It is distributed under dual licence
 #include <vtkPNGWriter.h>
 #include <vtkJPEGWriter.h>
 #include <vtkGenericMovieWriter.h>
-#ifdef CLITK_EXPERIMENTAL
-#  include <vvAnimatedGIFWriter.h>
-#endif
+#include <vvAnimatedGIFWriter.h>
 #ifdef VTK_USE_VIDEO_FOR_WINDOWS
 #  include <vtkAVIWriter.h>
 #endif
@@ -134,6 +133,8 @@ vvMainWindow::vvMainWindow():vvMainWindowBase()
 { 
   setupUi(this); // this sets up the GUI
 
+  setAcceptDrops(true); // enable to drop into the window
+
   setDicomClient();
 
   //Qt::WindowFlags flags = windowFlags();
@@ -235,7 +236,7 @@ vvMainWindow::vvMainWindow():vvMainWindowBase()
   documentation = new vvDocumentation();
   help_dialog = new vvHelpDialog();
   dicomSeriesSelector = new vvDicomSeriesSelector();
-#ifdef CLITK_USE_PACS_CONNECTION
+#if CLITK_USE_PACS_CONNECTION
      PacsConnection = new vvQPacsConnection();
 #endif
 
@@ -280,8 +281,8 @@ vvMainWindow::vvMainWindow():vvMainWindowBase()
   connect(actionWarp_image_with_vector_field,SIGNAL(triggered()),this,SLOT(WarpImage()));
   connect(actionLoad_images,SIGNAL(triggered()),this,SLOT(OpenImages()));
   connect(actionOpen_Dicom,SIGNAL(triggered()),this,SLOT(OpenDicom()));
-  #ifdef CLITK_USE_PACS_CONNECTION
-connect(actionConnect_Pacs,SIGNAL(triggered()),this,SLOT(ConnectPacs()));
+#if CLITK_USE_PACS_CONNECTION
+  connect(actionConnect_Pacs,SIGNAL(triggered()),this,SLOT(ConnectPacs()));
 #endif
   //  connect(actionOpen_Dicom_Struct,SIGNAL(triggered()),this,SLOT(OpenDCStructContour()));
   connect(actionOpen_VTK_contour,SIGNAL(triggered()),this,SLOT(OpenVTKContour()));
@@ -397,6 +398,10 @@ connect(actionConnect_Pacs,SIGNAL(triggered()),this,SLOT(ConnectPacs()));
     menuExperimental->menuAction()->setVisible(false);
 #endif
 
+#if !CLITK_USE_PACS_CONNECTION
+    actionConnect_Pacs->setVisible(false);
+#endif
+
   QTimer * timerMemory = new QTimer(this);
   //timerMemory->setInterval(5);
   connect(timerMemory, SIGNAL(timeout()), this, SLOT(UpdateMemoryUsage()));
@@ -414,7 +419,7 @@ void vvMainWindow::UpdateMemoryUsage()
 { 
   //  clitk::PrintMemory(true);
   if (clitk::GetMemoryUsageInMb() == 0) infoPanel->setMemoryInMb("NA");
-  else infoPanel->setMemoryInMb(QString::number(clitk::GetMemoryUsageInMb())+" MiB");
+  else infoPanel->setMemoryInMb(QString::number(clitk::GetMemoryUsageInMb())+" MB");
 }
 //------------------------------------------------------------------------------
 
@@ -770,7 +775,7 @@ void vvMainWindow::OpenDicom()
     LoadImages(files, vvImageReader::DICOM);
   }
 }  
-#ifdef CLITK_USE_PACS_CONNECTION
+#if CLITK_USE_PACS_CONNECTION
 void vvMainWindow::ConnectPacs()
 {
   std::vector<std::string> files;
@@ -814,6 +819,25 @@ void vvMainWindow::OpenRecentImage()
   LoadImages(images, vvImageReader::IMAGE);
 }
 //------------------------------------------------------------------------------
+void vvMainWindow::dragEnterEvent(QDragEnterEvent *event)
+{
+  if (event->mimeData()->hasUrls()) {
+    event->acceptProposedAction();
+  }
+}
+//------------------------------------------------------------------------------
+void vvMainWindow::dropEvent(QDropEvent *event)
+{
+  const QMimeData * mimeData = event->mimeData();
+  if (!mimeData->hasUrls())
+    return;
+  std::vector<std::string> images;
+  for (auto const & url : mimeData->urls()) {
+    images.push_back(url.toLocalFile().toStdString());
+  }
+  LoadImages(images, vvImageReader::IMAGE);
+}
+//------------------------------------------------------------------------------
 
 
 //------------------------------------------------------------------------------
@@ -900,11 +924,13 @@ void vvMainWindow::LoadImages(std::vector<std::string> files, vvImageReader::Loa
       // Change filename if an image with the same already exist
       int number = GetImageDuplicateFilenameNumber(files[i] + std::string("_slice"));
 
-      if (filetype == vvImageReader::IMAGE || filetype == vvImageReader::IMAGEWITHTIME || filetype == vvImageReader::SLICED) {
+      if (filetype == vvImageReader::IMAGE || filetype == vvImageReader::IMAGEWITHTIME || filetype == vvImageReader::SLICED)
         SetImageSucceed = imageManager->SetImage(files[i],filetype, number, j);
-      } else {
+      else if (filetype == vvImageReader::DICOM)
+        SetImageSucceed = imageManager->SetImages(files,filetype, number, dicomSeriesSelector->IsPatientCoordianteSystemChecked());
+      else
         SetImageSucceed = imageManager->SetImages(files,filetype, number);
-      }
+
       if (!SetImageSucceed) {
         QApplication::restoreOverrideCursor();
         QString error = "Cannot open file \n";
@@ -982,6 +1008,7 @@ void vvMainWindow::LoadImages(std::vector<std::string> files, vvImageReader::Loa
         connect(mSlicerManagers.back(), SIGNAL(ChangeImageWithIndexOffset(vvSlicerManager*,int,int)),
           this,SLOT(ChangeImageWithIndexOffset(vvSlicerManager*,int,int)));
         connect(mSlicerManagers.back(),SIGNAL(LandmarkAdded()),landmarksPanel,SLOT(AddPoint()));
+        connect(landmarksPanel,SIGNAL(UpdateLandmarkTransform()), mSlicerManagers.back(), SLOT(UpdateLandmark()));
         InitSlicers();
         numberofsuccesulreads++;
       }
@@ -1170,7 +1197,7 @@ void vvMainWindow::ImageInfoChanged()
       sizeMM[i] = inputSize[i]*inputSpacing[i];
       NPixel *= inputSize[i];
     }
-    inputSizeInBytes = GetSizeInBytes(imageSelected->GetActualMemorySize()*1000);
+    inputSizeInBytes = GetSizeInBytes(imageSelected->GetActualMemorySize());
 
     QString dim = QString::number(dimension) + " (";
     dim += pixelType + ")";
@@ -1371,15 +1398,15 @@ QString vvMainWindow::GetSizeInBytes(unsigned long size)
   if (size > 1000000000) {
     size /= 1000000000;
     result += QString::number(size);
-    result += "Gb";//)";
+    result += "GB";//)";
   } else if (size > 1000000) {
     size /= 1000000;
     result += QString::number(size);
-    result += "Mb";//)";
+    result += "MB";//)";
   } else if (size > 1000) {
     size /= 1000;
     result += QString::number(size);
-    result += "kb";//)";
+    result += "kB";//)";
   }
   return result;
 }
@@ -3299,7 +3326,11 @@ void vvMainWindow::SaveScreenshotAllSlices()
     // Screenshot
     vtkSmartPointer<vtkWindowToImageFilter> windowToImageFilter = vtkSmartPointer<vtkWindowToImageFilter>::New();
     windowToImageFilter->SetInput(renderWindow);
+#if (VTK_MAJOR_VERSION >= 8 && VTK_MINOR_VERSION >= 1) || VTK_MAJOR_VERSION >= 9
+    windowToImageFilter->SetScale(1);
+#else
     windowToImageFilter->SetMagnification(1);
+#endif
     windowToImageFilter->SetInputBufferTypeToRGBA(); //also record the alpha (transparency) channel
     windowToImageFilter->Update();
 
@@ -3338,9 +3369,7 @@ void vvMainWindow::SaveScreenshot(QVTKWidget *widget)
 #ifdef VTK_USE_MPEG2_ENCODER
   Extensions += ";;Video( *.mpg)";
 #endif
-#ifdef CLITK_EXPERIMENTAL
   Extensions += ";;Video( *.gif)";
-#endif
 
   int smIndex=GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
   QString fileName = QFileDialog::getSaveFileName(this,
@@ -3351,6 +3380,12 @@ void vvMainWindow::SaveScreenshot(QVTKWidget *widget)
   if (!fileName.isEmpty()) {
     vtkSmartPointer<vtkWindowToImageFilter> w2i = vtkSmartPointer<vtkWindowToImageFilter>::New();
     w2i->SetInput(widget->GetRenderWindow());
+#if (VTK_MAJOR_VERSION >= 8 && VTK_MINOR_VERSION >= 1) || VTK_MAJOR_VERSION >= 9
+    w2i->SetScale(1);
+#else
+    w2i->SetMagnification(1);
+#endif
+    w2i->SetInputBufferTypeToRGBA(); //also record the alpha (transparency) channel
     w2i->Update();
     vtkImageData *image = w2i->GetOutput();
 
@@ -3383,7 +3418,6 @@ void vvMainWindow::SaveScreenshot(QVTKWidget *widget)
 
     // Video
     vtkGenericMovieWriter *vidwriter = NULL;
-#if CLITK_EXPERIMENTAL == 1
     if (ext==".gif") {
       vvAnimatedGIFWriter *gif = vvAnimatedGIFWriter::New();
       vidwriter = gif;
@@ -3408,7 +3442,6 @@ void vvMainWindow::SaveScreenshot(QVTKWidget *widget)
       msgBox.addButton(tr("No"), QMessageBox::RejectRole);
       gif->SetDither(msgBox.exec() == QMessageBox::AcceptRole);
     }
-#endif
 #ifdef VTK_USE_VIDEO_FOR_WINDOWS
     if (ext==".avi") {
       vtkAVIWriter *mpg = vtkAVIWriter::New();
@@ -3697,6 +3730,7 @@ vvSlicerManager* vvMainWindow::AddImage(vvImage::Pointer image,std::string filen
   connect(mSlicerManagers.back(), SIGNAL(ChangeImageWithIndexOffset(vvSlicerManager*,int,int)),
     this,SLOT(ChangeImageWithIndexOffset(vvSlicerManager*,int,int)));
   connect(mSlicerManagers.back(), SIGNAL(LandmarkAdded()),landmarksPanel,SLOT(AddPoint()));
+  connect(landmarksPanel,SIGNAL(UpdateLandmarkTransform()), mSlicerManagers.back(), SLOT(UpdateLandmark()));