]> Creatis software - clitk.git/commitdiff
Add an option to the screenshots menu to save all slices (with ROI and transparency)
authorDavid Sarrut <david.sarrut@creatis.insa-lyon.fr>
Wed, 5 Oct 2011 09:05:59 +0000 (11:05 +0200)
committerDavid Sarrut <david.sarrut@creatis.insa-lyon.fr>
Wed, 5 Oct 2011 09:05:59 +0000 (11:05 +0200)
vv/qt_ui/vvMainWindow.ui
vv/vvMainWindow.cxx
vv/vvMainWindow.h

index a6801c2ca363b92615db55f7665894b1f14ef309..e03cb231421f775fc2fc93c03ea5e447cce40b32 100644 (file)
            <number>2</number>
           </property>
           <item row="0" column="0">
-           <widget class="QVTKWidget" name="NOViewWidget">
+           <widget class="QVTKWidget" name="NOViewWidget" native="true">
             <property name="mouseTracking">
              <bool>true</bool>
             </property>
            <number>2</number>
           </property>
           <item row="0" column="0">
-           <widget class="QVTKWidget" name="SOViewWidget">
+           <widget class="QVTKWidget" name="SOViewWidget" native="true">
             <property name="mouseTracking">
              <bool>true</bool>
             </property>
            <number>2</number>
           </property>
           <item row="0" column="0">
-           <widget class="QVTKWidget" name="NEViewWidget">
+           <widget class="QVTKWidget" name="NEViewWidget" native="true">
             <property name="mouseTracking">
              <bool>true</bool>
             </property>
            <number>2</number>
           </property>
           <item row="0" column="0">
-           <widget class="QVTKWidget" name="SEViewWidget">
+           <widget class="QVTKWidget" name="SEViewWidget" native="true">
             <property name="sizePolicy">
              <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
               <horstretch>0</horstretch>
     <addaction name="actionNorth_East_Window"/>
     <addaction name="actionSouth_West_Window"/>
     <addaction name="actionSouth_East_Window"/>
+    <addaction name="separator"/>
+    <addaction name="actionSave_all_slices"/>
    </widget>
    <widget class="QMenu" name="menuExperimental">
     <property name="title">
     <string>Register vv</string>
    </property>
   </action>
+  <action name="actionSave_all_slices">
+   <property name="text">
+    <string>Save all slices (Top-Left view)</string>
+   </property>
+  </action>
  </widget>
  <customwidgets>
   <customwidget>
index 596e6af969f9859f0520de3e3f70ab8eb61af613..ca0d09f9c33ff62c9e660ca9375bf34ca59574d8 100644 (file)
@@ -275,6 +275,7 @@ vvMainWindow::vvMainWindow():vvMainWindowBase()
   connect(actionNorth_West_Window,SIGNAL(triggered()),this,SLOT(SaveNOScreenshot()));
   connect(actionSouth_East_Window,SIGNAL(triggered()),this,SLOT(SaveSEScreenshot()));
   connect(actionSouth_West_Window,SIGNAL(triggered()),this,SLOT(SaveSOScreenshot()));
+  connect(actionSave_all_slices,SIGNAL(triggered()),this,SLOT(SaveScreenshotAllSlices()));
 
   connect(DataTree,SIGNAL(itemSelectionChanged()),this,SLOT(ImageInfoChanged()));
   connect(DataTree,SIGNAL(itemClicked(QTreeWidgetItem*, int)),this,
@@ -2573,6 +2574,48 @@ void vvMainWindow::SaveSEScreenshot()
 //------------------------------------------------------------------------------
 
 
+//------------------------------------------------------------------------------
+void vvMainWindow::SaveScreenshotAllSlices()
+{
+  QVTKWidget *widget = NOViewWidget;
+  vtkSmartPointer<vtkRenderWindow>  renderWindow = widget->GetRenderWindow();
+
+  int index = 0;// GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
+  vvSlicerManager * SM = mSlicerManagers[index];
+  vvImage * image = SM->GetImage();
+  vvSlicer * slicer = SM->GetSlicer(0);
+  int orientation = slicer->GetOrientation();
+  int nbSlices = image->GetSize()[orientation];
+
+  // Select filename base
+  QString filename = QFileDialog::getSaveFileName(this,
+                                                  tr("Save As (filename will be completed by slice number)"),
+                                                  itksys::SystemTools::GetFilenamePath(mSlicerManagers[index]->GetFileName()).c_str(),
+                                                  "Images( *.png);;");
+
+  // Loop on slices
+  for(uint i=0; i<nbSlices; i++) {
+    // Change the slice
+    slicer->SetSlice(i);
+    
+    // Screenshot  
+    vtkSmartPointer<vtkWindowToImageFilter> windowToImageFilter = vtkSmartPointer<vtkWindowToImageFilter>::New();
+    windowToImageFilter->SetInput(renderWindow);
+    windowToImageFilter->SetMagnification(1);
+    windowToImageFilter->SetInputBufferTypeToRGBA(); //also record the alpha (transparency) channel
+    windowToImageFilter->Update();
+    
+    vtkSmartPointer<vtkPNGWriter> writer = vtkSmartPointer<vtkPNGWriter>::New();
+    std::string fn = itksys::SystemTools::GetFilenameWithoutLastExtension(filename.toStdString());
+    fn = fn + "_" + clitk::toString(i) + itksys::SystemTools::GetFilenameLastExtension(filename.toStdString());
+    writer->SetFileName(fn.c_str());
+    writer->SetInput(windowToImageFilter->GetOutput());
+    writer->Write();
+  }
+}
+//------------------------------------------------------------------------------
+
+
 //------------------------------------------------------------------------------
 void vvMainWindow::SaveScreenshot(QVTKWidget *widget)
 {
index 8ee5ab26178adf4d421514e1c9a8a147c79765b9..8a2f0365ae6361f9a8d31e36edc6d22277292a3c 100644 (file)
@@ -133,6 +133,7 @@ public slots:
   void SaveNOScreenshot();
   void SaveSEScreenshot();
   void SaveSOScreenshot();
+  void SaveScreenshotAllSlices();
 
   void ShowContextMenu(QPoint point);
   void CloseImage();