]> Creatis software - clitk.git/blobdiff - vv/vvMainWindow.cxx
Debug RTStruct conversion with empty struc
[clitk.git] / vv / vvMainWindow.cxx
index 1bf54692df4a6de78ae15e312f2d3786f9098249..d148c3f14cc8ecf9ed748483372cbe5751ebaa6c 100644 (file)
@@ -25,6 +25,7 @@ It is distributed under dual licence
 #include <QUrl>
 #include <QSettings>
 #include <QShortcut>
+#include <QFileSystemWatcher>
 
 // VV include
 #include "vvMainWindow.h"
@@ -386,6 +387,9 @@ vvMainWindow::vvMainWindow():vvMainWindowBase()
     updateRecentlyOpenedFilesMenu(recent_files);
   }
 
+  //Update and get vv parameters
+  setVVSettings();
+
   // Adding all new tools (insertion in the menu)
   vvToolManager::GetInstance()->InsertToolsInMenu(this);
   vvToolManager::GetInstance()->EnableToolsInMenu(this, false);
@@ -979,6 +983,12 @@ void vvMainWindow::LoadImages(std::vector<std::string> files, vvImageReader::Loa
 
         linkPanel->addImage(imageManager->GetFileName(), id.toStdString());
 
+        //Create a watcher to see if the image file is modified. In such a case, reload it automatically
+        QFileSystemWatcher* watcher = new QFileSystemWatcher;
+        watcher->addPath(files[i].c_str());
+        connect(watcher, SIGNAL(fileChanged(const QString&)), this, SLOT(SlotFileChanged(const QString&)));
+
+
         connect(mSlicerManagers.back(), SIGNAL(currentImageChanged(std::string)),
           this,SLOT(CurrentImageChanged(std::string)));
         connect(mSlicerManagers.back(), SIGNAL(currentPickedImageChanged(std::string)),
@@ -1438,6 +1448,29 @@ QString vvMainWindow::GetVectorIntAsString(std::vector<int> vectorInt)
 }
 //------------------------------------------------------------------------------
 
+//------------------------------------------------------------------------------
+void vvMainWindow::SlotFileChanged(const QString& pathname)
+{
+  std::vector<QTreeWidgetItem*> items = GetItemFromPathname(pathname);
+  for (unsigned int i=0; i< items.size(); ++i)
+    ReloadImage(items[i], 0);
+}
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+std::vector<QTreeWidgetItem*> vvMainWindow::GetItemFromPathname(const QString& pathname)
+{
+  std::vector<QTreeWidgetItem*> items;
+  for (int i = 0; i < DataTree->topLevelItemCount(); ++i) {
+    QString tempItemPathname(DataTree->topLevelItem(i)->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString());
+    tempItemPathname = tempItemPathname.left(tempItemPathname.length() - 1);
+    if (tempItemPathname == pathname)
+      items.push_back(DataTree->topLevelItem(i));
+  }
+  return items;
+}
+//------------------------------------------------------------------------------
+
 //------------------------------------------------------------------------------
 //this actually returns the SlicerManager index!
 int vvMainWindow::GetSlicerIndexFromItem(QTreeWidgetItem* item)
@@ -3300,7 +3333,7 @@ void vvMainWindow::SaveSEScreenshot()
 //------------------------------------------------------------------------------
 void vvMainWindow::SaveScreenshotAllSlices()
 { 
-#if (VTK_MAJOR_VERSION == 8 && VTK_MINOR_VERSION >= 1) || VTK_MAJOR_VERSION >= 9
+#if (VTK_MAJOR_VERSION == 8 && VTK_MINOR_VERSION >= 2) || VTK_MAJOR_VERSION >= 9
   QVTKOpenGLNativeWidget *widget = NOViewWidget;
 #else
   QVTKWidget *widget = NOViewWidget;
@@ -3330,7 +3363,7 @@ 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
+#if (VTK_MAJOR_VERSION >= 8 && VTK_MINOR_VERSION >= 2) || VTK_MAJOR_VERSION >= 9
     windowToImageFilter->SetScale(1);
 #else
     windowToImageFilter->SetMagnification(1);
@@ -3360,24 +3393,24 @@ void vvMainWindow::SaveScreenshotAllSlices()
 
 
 //------------------------------------------------------------------------------
-#if (VTK_MAJOR_VERSION == 8 && VTK_MINOR_VERSION >= 1) || VTK_MAJOR_VERSION >= 9
+#if (VTK_MAJOR_VERSION == 8 && VTK_MINOR_VERSION >= 2) || VTK_MAJOR_VERSION >= 9
 void vvMainWindow::SaveScreenshot(QVTKOpenGLNativeWidget *widget)
 #else
 void vvMainWindow::SaveScreenshot(QVTKWidget *widget)
 #endif
 { 
-  QString Extensions = "Images( *.png);;";
-  Extensions += "Images( *.jpg);;";
-  Extensions += "Images( *.bmp);;";
-  Extensions += "Images( *.tif);;";
-  Extensions += "Images( *.ppm)";
+  QString Extensions = "*.png;;";
+  Extensions += "*.jpg;;";
+  Extensions += "*.bmp;;";
+  Extensions += "*.tif;;";
+  Extensions += "*.ppm";
 #if defined(VTK_USE_FFMPEG_ENCODER) || defined(VTK_USE_VIDEO_FOR_WINDOWS)
-  Extensions += ";;Video( *.avi)";
+  Extensions += ";;*.avi Video";
 #endif
 #ifdef VTK_USE_MPEG2_ENCODER
-  Extensions += ";;Video( *.mpg)";
+  Extensions += ";;*.mpg Video";
 #endif
-  Extensions += ";;Video( *.gif)";
+  Extensions += ";;*.gif Video";
 
   int smIndex=GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
   QString fileName = QFileDialog::getSaveFileName(this,
@@ -3388,12 +3421,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
+#if (VTK_MAJOR_VERSION >= 8 && VTK_MINOR_VERSION >= 2) || VTK_MAJOR_VERSION >= 9
     w2i->SetScale(1);
 #else
     w2i->SetMagnification(1);
 #endif
-    w2i->SetInputBufferTypeToRGBA(); //also record the alpha (transparency) channel
+    //w2i->SetInputBufferTypeToRGBA(); //also record the alpha (transparency) channel
     w2i->Update();
     vtkImageData *image = w2i->GetOutput();