From a1fb28aafccf64d6438575dd0dd684701d0ef132 Mon Sep 17 00:00:00 2001 From: David Sarrut Date: Wed, 5 Oct 2011 11:05:59 +0200 Subject: [PATCH] Add an option to the screenshots menu to save all slices (with ROI and transparency) --- vv/qt_ui/vvMainWindow.ui | 15 ++++++++++---- vv/vvMainWindow.cxx | 43 ++++++++++++++++++++++++++++++++++++++++ vv/vvMainWindow.h | 1 + 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/vv/qt_ui/vvMainWindow.ui b/vv/qt_ui/vvMainWindow.ui index a6801c2..e03cb23 100644 --- a/vv/qt_ui/vvMainWindow.ui +++ b/vv/qt_ui/vvMainWindow.ui @@ -626,7 +626,7 @@ 2 - + true @@ -666,7 +666,7 @@ 2 - + true @@ -708,7 +708,7 @@ 2 - + true @@ -745,7 +745,7 @@ 2 - + 0 @@ -833,6 +833,8 @@ + + @@ -1112,6 +1114,11 @@ Register vv + + + Save all slices (Top-Left view) + + diff --git a/vv/vvMainWindow.cxx b/vv/vvMainWindow.cxx index 596e6af..ca0d09f 100644 --- a/vv/vvMainWindow.cxx +++ b/vv/vvMainWindow.cxx @@ -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 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; iSetSlice(i); + + // Screenshot + vtkSmartPointer windowToImageFilter = vtkSmartPointer::New(); + windowToImageFilter->SetInput(renderWindow); + windowToImageFilter->SetMagnification(1); + windowToImageFilter->SetInputBufferTypeToRGBA(); //also record the alpha (transparency) channel + windowToImageFilter->Update(); + + vtkSmartPointer writer = vtkSmartPointer::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) { diff --git a/vv/vvMainWindow.h b/vv/vvMainWindow.h index 8ee5ab2..8a2f036 100644 --- a/vv/vvMainWindow.h +++ b/vv/vvMainWindow.h @@ -133,6 +133,7 @@ public slots: void SaveNOScreenshot(); void SaveSEScreenshot(); void SaveSOScreenshot(); + void SaveScreenshotAllSlices(); void ShowContextMenu(QPoint point); void CloseImage(); -- 2.45.1