1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://www.centreleonberard.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
20 #include <QMessageBox>
21 #include <QInputDialog>
23 #include "QTreePushButton.h"
28 #include "vvMainWindow.h"
29 #include "vvHelpDialog.h"
30 #include "vvRegisterForm.h"
31 #include "vvDocumentation.h"
32 #include "vvProgressDialog.h"
33 #include "vvQDicomSeriesSelector.h"
34 #include "vvSlicerManager.h"
35 #include "clitkImageCommon.h"
37 #include "vvInteractorStyleNavigator.h"
38 #include "vvImageWriter.h"
39 #include "vvSegmentationDialog.h"
40 #include "vvSurfaceViewerDialog.h"
41 #include "vvDeformationDialog.h"
42 #include "vvImageWarp.h"
44 #include "vvMidPosition.h"
46 #include "vvStructSelector.h"
47 #include "vvMeshReader.h"
48 #include "vvSaveState.h"
49 #include "vvReadState.h"
50 #include "clitkConfiguration.h"
54 #include <itkImageFileReader.h>
55 #include <itkByteSwapper.h>
56 #include <itkCommand.h>
57 #include <itkNumericSeriesFileNames.h>
60 #include <vtkImageData.h>
61 #include <vtkImageActor.h>
62 #include <vtkCornerAnnotation.h>
63 #include <vtkRenderWindow.h>
64 #include <vtkRenderWindowInteractor.h>
65 #include <vtkRenderer.h>
66 #include <vtkRendererCollection.h>
67 #include <vtkWindowToImageFilter.h>
68 #include <vtkBMPWriter.h>
69 #include <vtkTIFFWriter.h>
70 #include <vtkPNMWriter.h>
71 #include <vtkPNGWriter.h>
72 #include <vtkJPEGWriter.h>
73 #include <vtkGenericMovieWriter.h>
74 #ifdef CLITK_EXPERIMENTAL
75 # include <vvAnimatedGIFWriter.h>
77 #ifdef VTK_USE_VIDEO_FOR_WINDOWS
78 # include <vtkAVIWriter.h>
80 #ifdef VTK_USE_FFMPEG_ENCODER
81 # include <vtkFFMPEGWriter.h>
83 #ifdef VTK_USE_MPEG2_ENCODER
84 # include <vtkMPEG2Writer.h>
86 #include <vtkMatrix4x4.h>
87 #include <vtkTransform.h>
95 #define COLUMN_UL_VIEW 1
96 #define COLUMN_UR_VIEW 2
97 #define COLUMN_DL_VIEW 3
98 #define COLUMN_DR_VIEW 4
99 #define COLUMN_CLOSE_IMAGE 5
100 #define COLUMN_RELOAD_IMAGE 6
101 #define COLUMN_IMAGE_NAME 7
103 #define EXTENSIONS "Images ( *.bmp *.png *.jpeg *.jpg *.tif *.mhd *.mha *.hdr *.vox *.his *.xdr *.SCAN *.nii *.nrrd *.nhdr)"
106 0,Qt::UserRole full filename
107 1,Qt::CheckStateRole checkbutton UL View
108 1,Qt::UserRole overlay, fusion or vector
109 2,Qt::CheckStateRole checkbutton UR View
110 3,Qt::CheckStateRole checkbutton DL View
111 4,Qt::CheckStateRole checkbutton DR View
113 5,Qt::UserRole mSlicerManager id*/
115 //------------------------------------------------------------------------------
116 vvMainWindow::vvMainWindow():vvMainWindowBase()
118 setupUi(this); // this sets up the GUI
121 mMenuTools = menuTools;
122 // mMenuSegmentation = menuSegmentation;
123 mContextMenu = &contextMenu;
124 mMenuExperimentalTools = menuExperimental;
127 mCurrentSelectedImageId = "";
128 mCurrentPickedImageId = "";
129 mCurrentPickedImageIndex = 0;
131 //Init the contextMenu
132 this->setContextMenuPolicy(Qt::CustomContextMenu);
133 contextActions.resize(0);
134 QAction* actionOpen_new_image = contextMenu.addAction(QIcon(QString::fromUtf8(":/common/icons/fileopen.png")),
135 tr("O&pen new Image"));
136 actionOpen_new_image->setShortcut(QKeySequence(tr("Ctrl+O")));
137 connect(actionOpen_new_image,SIGNAL(triggered()),this,SLOT(OpenImages()));
138 contextActions.push_back(actionOpen_new_image);
139 contextMenu.addSeparator();
141 QAction* actionClose_Image = contextMenu.addAction(QIcon(QString::fromUtf8(":/common/icons/exit.png")),
142 tr("Close Current Image"));
143 connect(actionClose_Image,SIGNAL(triggered()),this,SLOT(CloseImage()));
144 contextActions.push_back(actionClose_Image);
146 QAction* actionReload_image = contextMenu.addAction(QIcon(QString::fromUtf8(":/common/icons/rotateright.png")),
147 tr("Reload Current Image"));
148 connect(actionReload_image,SIGNAL(triggered()),this,SLOT(ReloadImage()));
149 contextActions.push_back(actionReload_image);
151 QAction* actionSave_image = contextMenu.addAction(QIcon(QString::fromUtf8(":/common/icons/filesave.png")),
152 tr("Save Current Image"));
153 connect(actionSave_image,SIGNAL(triggered()),this,SLOT(SaveAs()));
154 contextActions.push_back(actionSave_image);
156 QAction* actionSave_state = contextMenu.addAction(QIcon(QString::fromUtf8(":/common/icons/filesave.png")),
157 tr("Save Current State"));
158 connect(actionSave_state,SIGNAL(triggered()),this,SLOT(SaveCurrentState()));
159 contextActions.push_back(actionSave_state);
161 QAction* actionRead_state = contextMenu.addAction(QIcon(QString::fromUtf8(":/common/icons/filesave.png")),
162 tr("Read Saved State"));
163 connect(actionRead_state,SIGNAL(triggered()),this,SLOT(ReadSavedState()));
164 contextActions.push_back(actionRead_state);
166 contextMenu.addSeparator();
168 contextMenu.addAction(actionAdd_VF_to_current_Image);
169 contextActions.push_back(actionAdd_VF_to_current_Image);
171 //QAction* actionAdd_Overlay_to_current_Image = menuOverlay->addAction(QIcon(QString::fromUtf8(":/common/icons/GPSup.png")),
172 // tr("Add overlay image to current image"));
173 contextMenu.addAction(actionAdd_overlay_image_to_current_image);
174 contextActions.push_back(actionAdd_overlay_image_to_current_image);
176 contextMenu.addAction(actionAdd_fusion_image);
177 contextActions.push_back(actionAdd_fusion_image);
179 contextMenu.addSeparator();
180 QAction* actionResetMatrix = contextMenu.addAction(QIcon(QString::fromUtf8(":/common/icons/identity.png")),
181 tr("Reset transformation to identity"));
182 connect(actionResetMatrix, SIGNAL(triggered()), this,SLOT(ResetTransformationToIdentity()));
186 QMenu * m = new QMenu(menubar);
188 // m->setObjectName(QString::fromUtf8("TOTOTO"));
189 contextMenu.addMenu(m);
190 QAction * a = m->addAction(QIcon(QString::fromUtf8(":/common/icons/GPSup.png")),
192 QAction * b = m->addAction(QIcon(QString::fromUtf8(":/common/icons/GPSup.png")),
196 connect(a,SIGNAL(triggered()),this,SLOT(AddFusionImage()));
200 mSlicerManagers.resize(0);
210 header.append("Name");
212 DataTree->setHeaderLabels(header);
213 DataTree->resizeColumnToContents(COLUMN_TREE);
214 DataTree->resizeColumnToContents(COLUMN_UL_VIEW);
215 DataTree->resizeColumnToContents(COLUMN_UR_VIEW);
216 DataTree->resizeColumnToContents(COLUMN_DL_VIEW);
217 DataTree->resizeColumnToContents(COLUMN_DR_VIEW);
218 DataTree->resizeColumnToContents(COLUMN_CLOSE_IMAGE);
219 DataTree->resizeColumnToContents(COLUMN_RELOAD_IMAGE);
220 DataTree->resizeColumnToContents(COLUMN_IMAGE_NAME);
223 documentation = new vvDocumentation();
224 help_dialog = new vvHelpDialog();
225 dicomSeriesSelector = new vvDicomSeriesSelector();
227 inverseButton->setEnabled(0);
228 actionAdd_overlay_image_to_current_image->setEnabled(0);
229 actionSave_As->setEnabled(0);
230 actionAdd_VF_to_current_Image->setEnabled(0);
231 actionAdd_fusion_image->setEnabled(0);
234 verticalSliders.push_back(NOVerticalSlider);
235 verticalSliders.push_back(NEVerticalSlider);
236 verticalSliders.push_back(SOVerticalSlider);
237 verticalSliders.push_back(SEVerticalSlider);
239 for (int i =0; i < 4; i++)
240 verticalSliders[i]->hide();
242 horizontalSliders.push_back(NOHorizontalSlider);
243 horizontalSliders.push_back(NEHorizontalSlider);
244 horizontalSliders.push_back(SOHorizontalSlider);
245 horizontalSliders.push_back(SEHorizontalSlider);
247 for (int i =0; i < 4; i++)
248 horizontalSliders[i]->hide();
251 connect(NOVerticalSlider,SIGNAL(valueChanged(int)),this,SLOT(NOVerticalSliderChanged()));
252 connect(NEVerticalSlider,SIGNAL(valueChanged(int)),this,SLOT(NEVerticalSliderChanged()));
253 connect(SOVerticalSlider,SIGNAL(valueChanged(int)),this,SLOT(SOVerticalSliderChanged()));
254 connect(SEVerticalSlider,SIGNAL(valueChanged(int)),this,SLOT(SEVerticalSliderChanged()));
256 connect(NOHorizontalSlider,SIGNAL(valueChanged(int)),this,SLOT(NOHorizontalSliderMoved()));
257 connect(NEHorizontalSlider,SIGNAL(valueChanged(int)),this,SLOT(NEHorizontalSliderMoved()));
258 connect(SOHorizontalSlider,SIGNAL(valueChanged(int)),this,SLOT(SOHorizontalSliderMoved()));
259 connect(SEHorizontalSlider,SIGNAL(valueChanged(int)),this,SLOT(SEHorizontalSliderMoved()));
262 connect(actionCompute_mid_position_image,SIGNAL(triggered()),this,SLOT(ComputeMidPosition()));
263 connect(actionDeformable_Registration,SIGNAL(triggered()),this,SLOT(ComputeDeformableRegistration()));
264 connect(actionWarp_image_with_vector_field,SIGNAL(triggered()),this,SLOT(WarpImage()));
265 connect(actionLoad_images,SIGNAL(triggered()),this,SLOT(OpenImages()));
266 connect(actionOpen_Dicom,SIGNAL(triggered()),this,SLOT(OpenDicom()));
267 connect(actionOpen_Dicom_Struct,SIGNAL(triggered()),this,SLOT(OpenDCStructContour()));
268 connect(actionOpen_VTK_contour,SIGNAL(triggered()),this,SLOT(OpenVTKContour()));
269 connect(actionOpen_Multiple_Images_As_One,SIGNAL(triggered()),this,SLOT(MergeImages()));
270 connect(actionSlice_Image_As_Multiple_Images,SIGNAL(triggered()),this,SLOT(SliceImages()));
271 connect(actionOpen_Image_With_Time,SIGNAL(triggered()),this,SLOT(OpenImageWithTime()));
272 connect(actionMerge_images_as_n_dim_t, SIGNAL(triggered()), this, SLOT(MergeImagesWithTime()));
273 connect(actionSave_As,SIGNAL(triggered()),this,SLOT(SaveAs()));
274 connect(actionSave_current_state,SIGNAL(triggered()),this,SLOT(SaveCurrentState()));
275 connect(actionRead_saved_state,SIGNAL(triggered()),this,SLOT(ReadSavedState()));
276 connect(actionExit,SIGNAL(triggered()),this,SLOT(close()));
277 connect(actionAdd_VF_to_current_Image,SIGNAL(triggered()),this,SLOT(OpenField()));
278 connect(actionAdd_fusion_image,SIGNAL(triggered()),this,SLOT(SelectFusionImage()));
279 connect(actionAdd_overlay_image_to_current_image,SIGNAL(triggered()), this,SLOT(SelectOverlayImage())); connect(actionNavigation_Help,SIGNAL(triggered()),this,SLOT(ShowHelpDialog()));
280 connect(actionDocumentation,SIGNAL(triggered()),this,SLOT(ShowDocumentation()));
281 connect(actionRegister_vv,SIGNAL(triggered()),this,SLOT(PopupRegisterForm()));
283 ///////////////////////////////////////////////
284 connect(actionSegmentation,SIGNAL(triggered()),this,SLOT(SegmentationOnCurrentImage()));
285 connect(actionSurface_Viewer,SIGNAL(triggered()),this,SLOT(SurfaceViewerLaunch()));
286 ///////////////////////////////////////////////
288 actionNorth_East_Window->setEnabled(0);
289 actionNorth_West_Window->setEnabled(0);
290 actionSouth_East_Window->setEnabled(0);
291 actionSouth_West_Window->setEnabled(0);
293 connect(actionNorth_East_Window,SIGNAL(triggered()),this,SLOT(SaveNEScreenshot()));
294 connect(actionNorth_West_Window,SIGNAL(triggered()),this,SLOT(SaveNOScreenshot()));
295 connect(actionSouth_East_Window,SIGNAL(triggered()),this,SLOT(SaveSEScreenshot()));
296 connect(actionSouth_West_Window,SIGNAL(triggered()),this,SLOT(SaveSOScreenshot()));
297 connect(actionSave_all_slices,SIGNAL(triggered()),this,SLOT(SaveScreenshotAllSlices()));
299 connect(DataTree,SIGNAL(itemSelectionChanged()),this,SLOT(ImageInfoChanged()));
300 connect(DataTree,SIGNAL(itemClicked(QTreeWidgetItem*, int)),this,
301 SLOT(DisplayChanged(QTreeWidgetItem*, int)));
303 connect(viewButton,SIGNAL(clicked()),this, SLOT(ChangeViewMode()) );
304 connect(windowSpinBox,SIGNAL(editingFinished()),this,SLOT(WindowLevelEdited()));
305 connect(levelSpinBox,SIGNAL(editingFinished()),this,SLOT(WindowLevelEdited()));
306 connect(colorMapComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(UpdateColorMap()));
307 connect(presetComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(UpdateWindowLevel()));
308 connect(inverseButton,SIGNAL(clicked()),this,SLOT(SwitchWindowLevel()));
309 connect(applyWindowLevelToAllButton,SIGNAL(clicked()),this,SLOT(ApplyWindowLevelToAllImages()));
312 connect(this,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(ShowContextMenu(QPoint)));
314 connect(linkPanel,SIGNAL(addLink(QString,QString)),this,SLOT(AddLink(QString,QString)));
315 connect(linkPanel,SIGNAL(removeLink(QString,QString)),this,SLOT(RemoveLink(QString,QString)));
316 connect(overlayPanel,SIGNAL(VFPropertyUpdated(int,int,int,int,double,double,double)),this,SLOT(SetVFProperty(int,int,int,int,double,double,double)));
317 connect(overlayPanel,SIGNAL(OverlayPropertyUpdated(int,int,double,double)),
318 this,SLOT(SetOverlayProperty(int,int,double,double)));
319 connect(overlayPanel,SIGNAL(FusionPropertyUpdated(int,int,int,double,double, bool)),
320 this,SLOT(SetFusionProperty(int,int,int,double,double, bool)));
321 connect(landmarksPanel,SIGNAL(UpdateRenderWindows()),this,SLOT(UpdateRenderWindows()));
325 playButton->setEnabled(0);
326 frameRateLabel->setEnabled(0);
327 frameRateSpinBox->setEnabled(0);
328 connect(playButton, SIGNAL(clicked()),this,SLOT(PlayPause()));
329 connect(frameRateSpinBox, SIGNAL(valueChanged(int)),this,SLOT(ChangeFrameRate(int)));
331 goToCursorPushButton->setEnabled(0);
332 connect(goToCursorPushButton, SIGNAL(clicked()),this,SLOT(GoToCursor()));
334 NOViewWidget->hide();
335 NEViewWidget->hide();
336 SOViewWidget->hide();
337 SEViewWidget->hide();
339 //Recently opened files
340 std::list<std::string> recent_files = GetRecentlyOpenedImages();
341 recentlyOpenedFilesMenu=NULL;
342 if ( !recent_files.empty() ) {
343 createRecentlyOpenedFilesMenu();
344 updateRecentlyOpenedFilesMenu(recent_files);
347 // Adding all new tools (insertion in the menu)
348 vvToolManager::GetInstance()->InsertToolsInMenu(this);
349 vvToolManager::GetInstance()->EnableToolsInMenu(this, false);
351 if (!CLITK_EXPERIMENTAL)
352 menuExperimental->menuAction()->setVisible(false);
355 QTimer * timerMemory = new QTimer(this);
356 //timerMemory->setInterval(5);
357 connect(timerMemory, SIGNAL(timeout()), this, SLOT(UpdateMemoryUsage()));
358 timerMemory->start(2000);
360 //------------------------------------------------------------------------------
361 void vvMainWindow::show()
363 vvMainWindowBase::show();
364 PopupRegisterForm(true);
366 //------------------------------------------------------------------------------
367 void vvMainWindow::UpdateMemoryUsage()
369 // clitk::PrintMemory(true);
370 if (clitk::GetMemoryUsageInMb() == 0) infoPanel->setMemoryInMb("NA");
371 else infoPanel->setMemoryInMb(QString::number(clitk::GetMemoryUsageInMb())+" MiB");
373 //------------------------------------------------------------------------------
376 //------------------------------------------------------------------------------
377 void vvMainWindow::createRecentlyOpenedFilesMenu()
379 recentlyOpenedFilesMenu = new QMenu("Recently opened files...");
380 recentlyOpenedFilesMenu->setIcon(QIcon(QString::fromUtf8(":/common/icons/open.png")));
381 menuFile->insertMenu(actionOpen_Image_With_Time,recentlyOpenedFilesMenu);
382 menuFile->insertSeparator(actionOpen_Image_With_Time);
384 //------------------------------------------------------------------------------
387 //------------------------------------------------------------------------------
389 void vvMainWindow::updateRecentlyOpenedFilesMenu(const std::list<std::string> &recent_files)
391 if(recentlyOpenedFilesMenu==NULL) {
392 createRecentlyOpenedFilesMenu();
394 recentlyOpenedFilesMenu->clear();
396 for (std::list<std::string>::const_iterator i = recent_files.begin(); i!=recent_files.end(); i++) {
397 QAction* current=new QAction(QIcon(QString::fromUtf8(":/common/icons/open.png")), i->c_str(),this);
398 recentlyOpenedFilesMenu->addAction(current);
399 connect(current,SIGNAL(triggered()),this,SLOT(OpenRecentImage()));
402 //------------------------------------------------------------------------------
405 //------------------------------------------------------------------------------
406 void vvMainWindow::ComputeMidPosition()
409 int index=GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
410 int ref = QInputDialog::getInteger(this,"Chose reference phase","Reference phase",0,0,\
411 mSlicerManagers[index]->GetImage()->GetVTKImages().size()-1,1,&ok);
414 midp.slicer_manager = mSlicerManagers[index];
415 midp.reference_image_index = ref;
416 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
419 QMessageBox::warning(this, "Error computing midposition image",midp.error_message.c_str());
421 QFileInfo info(midp.slicer_manager->GetFileName().c_str());
422 AddImage(midp.output,info.path().toStdString()+"/"+info.completeBaseName().toStdString()+"_midposition.mhd");
424 QApplication::restoreOverrideCursor();
427 //------------------------------------------------------------------------------
430 //------------------------------------------------------------------------------
431 void vvMainWindow::AddContour(int image_index, vvMesh::Pointer contour, bool propagation)
433 QTreeWidgetItem *item = new QTreeWidgetItem();
434 item->setData(0,Qt::UserRole,"filename.vtk");
435 item->setData(1,Qt::UserRole,tr("contour"));
437 brush.setColor(QColor(contour->r*255,contour->g*255,contour->b*255));
438 brush.setStyle(Qt::SolidPattern);
439 item->setData(COLUMN_IMAGE_NAME,Qt::BackgroundRole,brush);
440 item->setData(COLUMN_IMAGE_NAME,Qt::DisplayRole,contour->structure_name.c_str());
442 for (int j = 1; j <= 4; j++)
443 item->setData(j,Qt::CheckStateRole,DataTree->topLevelItem(image_index)->data(j,Qt::CheckStateRole));
445 QTreePushButton* cButton = new QTreePushButton;
446 cButton->setItem(item);
447 cButton->setColumn(COLUMN_CLOSE_IMAGE);
448 cButton->setToolTip(tr("close image"));
449 cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png")));
450 connect(cButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
451 this,SLOT(CloseImage(QTreeWidgetItem*, int)));
453 QTreePushButton* rButton = new QTreePushButton;
454 rButton->setItem(item);
455 rButton->setColumn(COLUMN_RELOAD_IMAGE);
456 rButton->setToolTip(tr("reload image"));
457 rButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/rotateright.png")));
458 rButton->setEnabled(false);
460 //connect(rButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
461 //this,SLOT(ReloadImage(QTreeWidgetItem*, int)));
463 DataTree->topLevelItem(image_index)->setExpanded(1);
464 DataTree->topLevelItem(image_index)->addChild(item);
465 DataTree->setItemWidget(item, COLUMN_CLOSE_IMAGE, cButton);
466 DataTree->setItemWidget(item, COLUMN_RELOAD_IMAGE, rButton);
467 QString id = DataTree->topLevelItem(image_index)->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString();
468 item->setData(COLUMN_IMAGE_NAME,Qt::UserRole,id.toStdString().c_str());
471 mSlicerManagers[image_index]->AddContour(contour,propagation);
472 mSlicerManagers[image_index]->Render();
474 //------------------------------------------------------------------------------
477 //------------------------------------------------------------------------------
478 void vvMainWindow::OpenVTKContour()
480 if (mSlicerManagers.size() > 0) {
481 QString Extensions = "Images ( *.vtk *.obj)";
482 Extensions += ";;All Files (*)";
483 QString file = QFileDialog::getOpenFileName(this,tr("Open vtkPolyData"),mInputPathName,Extensions);
486 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
487 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
489 reader.SetImage(mSlicerManagers[index]->GetImage());
490 reader.SetModeToVTK();
491 reader.SetFilename(file.toStdString());
493 AddContour(index,reader.GetOutput()[0],false);
494 QApplication::restoreOverrideCursor();
497 //------------------------------------------------------------------------------
500 //------------------------------------------------------------------------------
501 void vvMainWindow::AddDCStructContour(int index, QString file)
504 reader.SetFilename(file.toStdString());
505 vvStructSelector selector;
506 selector.SetStructures(reader.GetROINames());
507 if (!mSlicerManagers[index]->GetVF().IsNull())
508 selector.EnablePropagationCheckBox();
509 if (selector.exec()) {
510 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
511 reader.SetSelectedItems(selector.getSelectedItems());
512 reader.SetImage(mSlicerManagers[index]->GetImage());
513 if (selector.PropagationEnabled())
514 reader.SetPropagationVF(mSlicerManagers[index]->GetVF());
516 std::vector<vvMesh::Pointer> contours=reader.GetOutput();
517 for (std::vector<vvMesh::Pointer>::iterator i=contours.begin();
518 i!=contours.end(); i++)
519 AddContour(index,*i,selector.PropagationEnabled());
520 QApplication::restoreOverrideCursor();
524 //------------------------------------------------------------------------------
525 void vvMainWindow::OpenDCStructContour()
527 if (mSlicerManagers.size() > 0) {
528 QString Extensions = "Dicom Files ( *.dcm RS*)";
529 Extensions += ";;All Files (*)";
530 QString file = QFileDialog::getOpenFileName(this,tr("Merge Images"),mInputPathName,Extensions);
533 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
534 AddDCStructContour(index, file);
537 //------------------------------------------------------------------------------
540 //------------------------------------------------------------------------------
541 void vvMainWindow::ComputeDeformableRegistration()
543 if (mSlicerManagers.size() > 0) {
544 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
545 vvDeformationDialog dialog(index,mSlicerManagers);
547 std::string base_name=itksys::SystemTools::GetFilenameWithoutExtension(mSlicerManagers[dialog.GetInputFileIndex()]->GetFileName());
548 AddField(dialog.GetOutput(),dialog.getFieldFile(),dialog.GetInputFileIndex());
549 WarpImage(dialog.GetSelectedSlicer(),dialog.GetReferenceFrameIndex());
551 std::cout << "Error or user cancellation while computing deformation field..." << std::endl;
552 } else QMessageBox::information(this, "Need to open image","You must open an image first.");
554 //------------------------------------------------------------------------------
557 //------------------------------------------------------------------------------
558 void vvMainWindow::WarpImage()
560 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
561 if (!mSlicerManagers[index]->GetVF().IsNull()) {
563 int ref = QInputDialog::getInteger(this,"Chose reference phase","Reference phase",0,0,\
564 mSlicerManagers[index]->GetImage()->GetVTKImages().size()-1,1,&ok);
566 WarpImage(mSlicerManagers[index],ref);
569 QMessageBox::warning(this,tr("No vector field"),tr("Sorry, can't warp without a vector field"));
571 //------------------------------------------------------------------------------
574 //------------------------------------------------------------------------------
575 void vvMainWindow::WarpImage(vvSlicerManager* selected_slicer,int reference_phase)
577 if (!selected_slicer->GetVF().IsNull()) {
578 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
579 QFileInfo info(selected_slicer->GetFileName().c_str());
580 vvImageWarp warp(selected_slicer->GetImage(),selected_slicer->GetVF(),
581 reference_phase,this);
582 if (warp.ComputeWarpedImage()) {
583 AddImage(warp.GetWarpedImage(),info.path().toStdString()+"/"+info.completeBaseName().toStdString()+"_warped.mhd");
584 AddImage(warp.GetDiffImage() ,info.path().toStdString()+"/"+info.completeBaseName().toStdString()+"_diff.mhd");
585 AddImage(warp.GetJacobianImage() ,info.path().toStdString()+"/"+info.completeBaseName().toStdString()+"_jacobian.mhd");
586 QApplication::restoreOverrideCursor();
588 QApplication::restoreOverrideCursor();
589 QMessageBox::warning(this,tr("Different spacings"),tr("The vector field and image spacings must be the same in order to warp."));
592 QMessageBox::warning(this,tr("No vector field"),tr("Sorry, can't warp without a vector field."));
594 //------------------------------------------------------------------------------
597 //------------------------------------------------------------------------------
598 vvMainWindow::~vvMainWindow()
600 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
601 if (mSlicerManagers[i] != NULL)
602 delete mSlicerManagers[i];
605 //------------------------------------------------------------------------------
607 //------------------------------------------------------------------------------
608 QTabWidget * vvMainWindow::GetTab()
612 //------------------------------------------------------------------------------
615 //------------------------------------------------------------------------------
616 void vvMainWindow::MergeImages()
618 QString Extensions = EXTENSIONS;
619 Extensions += ";;All Files (*)";
620 QStringList files = QFileDialog::getOpenFileNames(this,tr("Merge Images"),mInputPathName,Extensions);
623 mInputPathName = itksys::SystemTools::GetFilenamePath(files[0].toStdString()).c_str();
624 std::vector<std::string> vector;
626 unsigned int currentDim = 0;
627 std::vector<double> currentSpacing;
628 std::vector<int> currentSize;
629 std::vector<double> currentOrigin;
631 for (int i = 0; i < files.size(); i++) {
632 itk::ImageIOBase::Pointer reader = itk::ImageIOFactory::CreateImageIO(
633 files[i].toStdString().c_str(), itk::ImageIOFactory::ReadMode);
634 reader->SetFileName(files[i].toStdString().c_str());
635 reader->ReadImageInformation();
637 //NOViewWidget->hide();
638 //NEViewWidget->hide();
639 //SOViewWidget->hide();
640 //SEViewWidget->hide();
642 currentDim = reader->GetNumberOfDimensions();
644 for (unsigned int j = 0; j < currentDim; j++) {
647 currentSpacing.resize(currentDim);
648 currentSize.resize(currentDim);
649 currentOrigin.resize(currentDim);
651 currentOrigin[j] = reader->GetOrigin(j);
652 currentSpacing[j] = reader->GetSpacing(j);
653 currentSize[j] = reader->GetDimensions(j);
654 } else if (currentDim != reader->GetNumberOfDimensions()
655 || currentSpacing[j] != reader->GetSpacing(j)
656 || currentSize[j] != (int)reader->GetDimensions(j)
657 || currentOrigin[j] != reader->GetOrigin(j)) {
658 QString error = "Cannot read file (too different from others ";
659 error += files[i].toStdString().c_str();
660 QMessageBox::information(this,tr("Reading problem"),error);
666 vector.push_back(files[i].toStdString());
669 if (vector.size() > 0)
670 LoadImages(vector, vvImageReader::MERGED);
672 //------------------------------------------------------------------------------
674 //------------------------------------------------------------------------------
675 void vvMainWindow::SliceImages()
677 QString Extensions = EXTENSIONS;
678 Extensions += ";;All Files (*)";
680 QStringList files = QFileDialog::getOpenFileNames(this,tr("Slice Images"),mInputPathName,Extensions);
683 mInputPathName = itksys::SystemTools::GetFilenamePath(files[0].toStdString()).c_str();
684 std::vector<std::string> vector;
685 for (int i = 0; i < files.size(); i++)
686 vector.push_back(files[i].toStdString());
687 LoadImages(vector, vvImageReader::SLICED);
689 //------------------------------------------------------------------------------
691 //------------------------------------------------------------------------------
692 void vvMainWindow::MergeImagesWithTime()
694 QString Extensions = EXTENSIONS;
695 Extensions += ";;All Files (*)";
696 QStringList files = QFileDialog::getOpenFileNames(this,tr("Merge Images With Time"),mInputPathName,Extensions);
699 mInputPathName = itksys::SystemTools::GetFilenamePath(files[0].toStdString()).c_str();
700 std::vector<std::string> vector;
702 unsigned int currentDim = 0;
703 std::vector<double> currentSpacing;
704 std::vector<int> currentSize;
705 std::vector<double> currentOrigin;
707 for (int i = 0; i < files.size(); i++) {
708 itk::ImageIOBase::Pointer reader = itk::ImageIOFactory::CreateImageIO(
709 files[i].toStdString().c_str(), itk::ImageIOFactory::ReadMode);
711 reader->SetFileName(files[i].toStdString().c_str());
712 reader->ReadImageInformation();
714 currentDim = reader->GetNumberOfDimensions();
716 for (unsigned int j = 0; j < currentDim; j++) {
719 currentSpacing.resize(currentDim);
720 currentSize.resize(currentDim);
721 currentOrigin.resize(currentDim);
723 currentOrigin[j] = reader->GetOrigin(j);
724 currentSpacing[j] = reader->GetSpacing(j);
725 currentSize[j] = reader->GetDimensions(j);
726 } else if (currentDim != reader->GetNumberOfDimensions()
727 || currentSpacing[j] != reader->GetSpacing(j)
728 || currentSize[j] != (int)reader->GetDimensions(j)
729 || currentOrigin[j] != reader->GetOrigin(j)) {
730 QString error = "Cannot read file (too different from others ";
731 error += files[i].toStdString().c_str();
732 QMessageBox::information(this,tr("Reading problem"),error);
738 vector.push_back(files[i].toStdString());
740 QString error = "Cannot read file info for ";
741 error += files[i].toStdString().c_str();
743 error += "Maybe you're trying to open an image in an unsupported format?\n";
744 QMessageBox::information(this,tr("Reading problem"),error);
747 sort(vector.begin(),vector.end());
748 if (vector.size() > 1)
749 LoadImages(vector, vvImageReader::MERGEDWITHTIME);
751 QMessageBox::warning(this,tr("Reading problem"),"You need to select at least two images to merge images with time.\nIf you only want to open one image, please use the \"Open Image\" function.");
753 //------------------------------------------------------------------------------
756 //------------------------------------------------------------------------------
757 void vvMainWindow::OpenDicom()
759 std::vector<std::string> files;
761 std::cout << "dicomSeriesSelector " << std::endl;
762 if (dicomSeriesSelector->exec() == QDialog::Accepted) {
763 files = *(dicomSeriesSelector->GetFilenames());
764 LoadImages(files, vvImageReader::DICOM);
767 //------------------------------------------------------------------------------
769 //------------------------------------------------------------------------------
770 void vvMainWindow::OpenImages()
772 QString Extensions = EXTENSIONS;
773 Extensions += ";;All Files (*)";
775 QStringList files = QFileDialog::getOpenFileNames(this,tr("Load Images"),mInputPathName,Extensions);
778 mInputPathName = itksys::SystemTools::GetFilenamePath(files[0].toStdString()).c_str();
779 std::vector<std::string> vector;
780 for (int i = 0; i < files.size(); i++)
781 vector.push_back(files[i].toStdString());
782 LoadImages(vector, vvImageReader::IMAGE);
784 //------------------------------------------------------------------------------
785 void vvMainWindow::OpenRecentImage()
787 QAction * caller = qobject_cast<QAction*>(sender());
788 std::vector<std::string> images;
789 images.push_back(caller->text().toStdString());
790 mInputPathName = itksys::SystemTools::GetFilenamePath(images[0]).c_str();
791 LoadImages(images, vvImageReader::IMAGE);
793 //------------------------------------------------------------------------------
796 //------------------------------------------------------------------------------
797 void vvMainWindow::OpenImageWithTime()
799 QString Extensions = EXTENSIONS;
800 Extensions += ";;All Files (*)";
802 QStringList files = QFileDialog::getOpenFileNames(this,tr("Load Images With Time"),mInputPathName,Extensions);
805 mInputPathName = itksys::SystemTools::GetFilenamePath(files[0].toStdString()).c_str();
806 std::vector<std::string> vector;
807 for (int i = 0; i < files.size(); i++) {
808 vector.push_back(files[i].toStdString());
810 LoadImages(vector, vvImageReader::IMAGEWITHTIME);
812 //------------------------------------------------------------------------------
815 //------------------------------------------------------------------------------
816 void vvMainWindow::LoadImages(std::vector<std::string> files, vvImageReader::LoadedImageType filetype)
818 //Separate the way to open images and dicoms
820 if (filetype == vvImageReader::IMAGE || filetype == vvImageReader::IMAGEWITHTIME)
821 fileSize = files.size();
825 // For SLICED, we need the number of slices (ndim and #slices)
826 std::vector<unsigned int> nSlices;
827 nSlices.resize(files.size());
828 std::fill(nSlices.begin(), nSlices.end(), 1);
829 if (filetype == vvImageReader::SLICED) {
830 for (int i = 0; i < fileSize; i++) {
831 itk::ImageIOBase::Pointer header = clitk::readImageHeader(files[i]);
832 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
835 QString error = "Cannot open file \n";
836 error += files[i].c_str();
837 QMessageBox::information(this,tr("Reading problem"),error);
840 if (header->GetNumberOfDimensions() < 3) {
842 QString error = "Dimension problem. Cannot slice \n";
843 error += files[i].c_str();
844 QMessageBox::information(this,tr("Reading problem"),error);
847 nSlices[i] = header->GetDimensions( header->GetNumberOfDimensions()-1 );
851 //Only add to the list of recently opened files when a single file is opened,
852 //to avoid polluting the list of recently opened files
853 if (files.size() == 1) {
854 QFileInfo finfo=tr(files[0].c_str());
855 AddToRecentlyOpenedImages(finfo.absoluteFilePath().toStdString());
856 updateRecentlyOpenedFilesMenu(GetRecentlyOpenedImages());
858 //init the progress events
859 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
860 vvProgressDialog progress("Opening " + files[0],fileSize>1);
861 qApp->processEvents();
863 int numberofsuccesulreads=0;
864 //open images as 1 or multiples
865 for (int i = 0; i < fileSize; i++) {
867 progress.SetText("Opening " + files[i]);
868 progress.SetProgress(i,fileSize);
869 qApp->processEvents();
871 for (unsigned int j = 0; j < nSlices[i]; j++) {
872 //read the image and put it in mSlicerManagers
873 vvSlicerManager* imageManager = new vvSlicerManager(4);
874 qApp->processEvents();
876 bool SetImageSucceed=false;
878 // Change filename if an image with the same already exist
879 int number = GetImageDuplicateFilenameNumber(files[i] + std::string("_slice"));
881 if (filetype == vvImageReader::IMAGE || filetype == vvImageReader::IMAGEWITHTIME || filetype == vvImageReader::SLICED)
882 SetImageSucceed = imageManager->SetImage(files[i],filetype, number, j);
884 SetImageSucceed = imageManager->SetImages(files,filetype, number);
886 if (!SetImageSucceed) {
887 QApplication::restoreOverrideCursor();
888 QString error = "Cannot open file \n";
889 error += imageManager->GetLastError().c_str();
890 QMessageBox::information(this,tr("Reading problem"),error);
893 mSlicerManagers.push_back(imageManager);
895 //create an item in the tree with good settings
896 QTreeWidgetItem *item = new QTreeWidgetItem();
897 item->setData(0,Qt::UserRole,files[i].c_str());
898 QFileInfo fileinfo(imageManager->GetFileName().c_str()); //Do not show the path
899 item->setData(COLUMN_IMAGE_NAME,Qt::DisplayRole,fileinfo.fileName());
900 item->setData(1,Qt::UserRole,tr("image"));
901 item->setToolTip(COLUMN_IMAGE_NAME, imageManager->GetListOfAbsoluteFilePathInOneString("image").c_str());
902 qApp->processEvents();
904 //Create the buttons for reload and close
905 qApp->processEvents();
906 QTreePushButton* cButton = new QTreePushButton;
907 cButton->setItem(item);
908 cButton->setColumn(COLUMN_CLOSE_IMAGE);
909 cButton->setToolTip(tr("close image"));
910 cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png")));
911 connect(cButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
912 this,SLOT(CloseImage(QTreeWidgetItem*, int)));
914 QTreePushButton* rButton = new QTreePushButton;
915 rButton->setItem(item);
916 rButton->setColumn(COLUMN_RELOAD_IMAGE);
917 rButton->setToolTip(tr("reload image"));
918 rButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/rotateright.png")));
919 connect(rButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
920 this,SLOT(ReloadImage(QTreeWidgetItem*, int)));
922 DataTree->addTopLevelItem(item);
923 DataTree->setItemWidget(item, COLUMN_CLOSE_IMAGE, cButton);
924 DataTree->setItemWidget(item, COLUMN_RELOAD_IMAGE, rButton);
926 //set the id of the image
927 QString id = files[i].c_str() + QString::number(mSlicerManagers.size()-1);
928 item->setData(COLUMN_IMAGE_NAME,Qt::UserRole,id.toStdString().c_str());
929 mSlicerManagers.back()->SetId(id.toStdString());
931 linkPanel->addImage(imageManager->GetFileName(), id.toStdString());
933 connect(mSlicerManagers.back(), SIGNAL(currentImageChanged(std::string)),
934 this,SLOT(CurrentImageChanged(std::string)));
935 connect(mSlicerManagers.back(), SIGNAL(currentPickedImageChanged(std::string)),
936 this, SLOT(CurrentPickedImageChanged(std::string)));
937 connect(mSlicerManagers.back(), SIGNAL(UpdatePosition(int, double, double, double, double, double, double, double)),
938 this,SLOT(MousePositionChanged(int,double, double, double, double, double, double, double)));
939 connect(mSlicerManagers.back(), SIGNAL(UpdateVector(int, double, double, double, double)),
940 this, SLOT(VectorChanged(int,double,double,double, double)));
941 connect(mSlicerManagers.back(), SIGNAL(UpdateOverlay(int, double, double)),
942 this, SLOT(OverlayChanged(int,double,double)));
943 connect(mSlicerManagers.back(), SIGNAL(UpdateFusion(int, double)),
944 this, SLOT(FusionChanged(int,double)));
945 connect(mSlicerManagers.back(), SIGNAL(WindowLevelChanged()),
946 this,SLOT(WindowLevelChanged()));
947 connect(mSlicerManagers.back(), SIGNAL(UpdateSlice(int,int)),
948 this,SLOT(UpdateSlice(int,int)));
949 connect(mSlicerManagers.back(), SIGNAL(UpdateTSlice(int, int)),
950 this,SLOT(UpdateTSlice(int, int)));
951 connect(mSlicerManagers.back(), SIGNAL(UpdateSliceRange(int,int,int,int,int)),
952 this,SLOT(UpdateSliceRange(int,int,int,int,int)));
953 connect(mSlicerManagers.back(), SIGNAL(UpdateLinkManager(std::string,int,double,double,double,int)),
954 this,SLOT(UpdateLinkManager(std::string,int,double,double,double,int)));
955 connect(mSlicerManagers.back(), SIGNAL(UpdateLinkedNavigation(std::string,vvSlicerManager*,vvSlicer*)),
956 this,SLOT(UpdateLinkedNavigation(std::string,vvSlicerManager*,vvSlicer*)));
957 connect(mSlicerManagers.back(), SIGNAL(ChangeImageWithIndexOffset(vvSlicerManager*,int,int)),
958 this,SLOT(ChangeImageWithIndexOffset(vvSlicerManager*,int,int)));
959 connect(mSlicerManagers.back(),SIGNAL(LandmarkAdded()),landmarksPanel,SLOT(AddPoint()));
961 numberofsuccesulreads++;
965 if (numberofsuccesulreads) {
966 NOViewWidget->show();
967 NEViewWidget->show();
968 SOViewWidget->show();
969 SEViewWidget->show();
974 // Try to guess default WindowLevel
976 mSlicerManagers.back()->GetImage()->GetFirstVTKImageData()->GetScalarRange(range);
977 if ((range[0] == 0) && (range[1] == 1)) {
978 presetComboBox->setCurrentIndex(5);// binary
983 QApplication::restoreOverrideCursor();
985 //------------------------------------------------------------------------------
987 //------------------------------------------------------------------------------
988 void vvMainWindow::UpdateTree()
990 DataTree->resizeColumnToContents(COLUMN_TREE);
991 DataTree->resizeColumnToContents(COLUMN_UL_VIEW);
992 DataTree->resizeColumnToContents(COLUMN_UR_VIEW);
993 DataTree->resizeColumnToContents(COLUMN_DL_VIEW);
994 DataTree->resizeColumnToContents(COLUMN_DR_VIEW);
995 DataTree->resizeColumnToContents(COLUMN_IMAGE_NAME);
996 DataTree->resizeColumnToContents(COLUMN_CLOSE_IMAGE);
997 DataTree->resizeColumnToContents(COLUMN_RELOAD_IMAGE);
999 //------------------------------------------------------------------------------
1001 //------------------------------------------------------------------------------
1002 void vvMainWindow::CurrentImageChanged(std::string id)
1004 if (id == mCurrentSelectedImageId) return; // Do nothing
1006 for (int i = 0; i < DataTree->topLevelItemCount(); i++) {
1007 if (DataTree->topLevelItem(i)->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString().toStdString() == id) {
1010 DataTree->topLevelItem(i)->setSelected(0);
1012 for (int child = 0; child < DataTree->topLevelItem(i)->childCount(); child++)
1013 DataTree->topLevelItem(i)->child(child)->setSelected(0);
1016 DataTree->topLevelItem(selected)->setSelected(1);
1017 mCurrentSelectedImageId = id;
1018 emit SelectedImageHasChanged(mSlicerManagers[selected]);
1020 //------------------------------------------------------------------------------
1022 //------------------------------------------------------------------------------
1023 void vvMainWindow::CurrentPickedImageChanged(std::string id)
1025 if (id == mCurrentPickedImageId) return; // Do nothing
1027 for (int i = 0; i < DataTree->topLevelItemCount(); i++) {
1028 if (DataTree->topLevelItem(i)->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString().toStdString() == id) {
1031 DataTree->topLevelItem(i)->setSelected(0);
1033 for (int child = 0; child < DataTree->topLevelItem(i)->childCount(); child++)
1034 DataTree->topLevelItem(i)->child(child)->setSelected(0);
1037 DataTree->topLevelItem(selected)->setSelected(1);
1038 mCurrentPickedImageId = id;
1039 mCurrentPickedImageIndex = selected;
1041 //------------------------------------------------------------------------------
1043 //------------------------------------------------------------------------------
1044 void vvMainWindow::ImageInfoChanged()
1046 contextActions[6]->setEnabled(1);
1047 contextActions[5]->setEnabled(1);
1048 actionSave_As->setEnabled(1);
1049 actionAdd_VF_to_current_Image->setEnabled(1);
1050 actionAdd_fusion_image->setEnabled(1);
1051 actionAdd_overlay_image_to_current_image->setEnabled(1);
1052 actionNorth_East_Window->setEnabled(1);
1053 actionNorth_West_Window->setEnabled(1);
1054 actionSouth_East_Window->setEnabled(1);
1055 actionSouth_West_Window->setEnabled(1);
1056 vvToolManager::GetInstance()->EnableToolsInMenu(this, true);
1057 inverseButton->setEnabled(1);
1059 goToCursorPushButton->setEnabled(1);
1061 if (DataTree->selectedItems().size()) {
1062 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
1064 colorMapComboBox->setEnabled(1);
1065 for (int i = 0; i < DataTree->topLevelItem(index)->childCount(); i++) {
1066 if (DataTree->topLevelItem(index)->child(i)->data(1,Qt::UserRole).toString() == "overlay" ||
1067 DataTree->topLevelItem(index)->child(i)->data(1,Qt::UserRole).toString() == "fusion") {
1068 colorMapComboBox->setEnabled(0);
1073 std::vector<double> origin;
1074 std::vector<double> inputSpacing;
1075 std::vector<int> inputSize;
1076 std::vector<double> sizeMM;
1077 vtkSmartPointer<vtkMatrix4x4> transformation;
1080 QString inputSizeInBytes;
1081 QString image = DataTree->selectedItems()[0]->data(COLUMN_IMAGE_NAME,Qt::DisplayRole).toString();
1083 if (mSlicerManagers[index]->GetSlicer(0)->GetImage()->GetVTKImages().size() > 1 || playMode == 1) {
1084 playButton->setEnabled(1);
1085 frameRateLabel->setEnabled(1);
1086 frameRateSpinBox->setEnabled(1);
1088 playButton->setEnabled(0);
1089 frameRateLabel->setEnabled(0);
1090 frameRateSpinBox->setEnabled(0);
1096 vvImage::Pointer imageSelected;
1097 if (DataTree->topLevelItem(index) == DataTree->selectedItems()[0]) {
1098 imageSelected = mSlicerManagers[index]->GetSlicer(0)->GetImage();
1099 } else if (DataTree->selectedItems()[0]->data(1,Qt::UserRole).toString() == "vector") {
1100 imageSelected = mSlicerManagers[index]->GetSlicer(0)->GetVF();
1101 } else if (DataTree->selectedItems()[0]->data(1,Qt::UserRole).toString() == "overlay") {
1102 imageSelected = mSlicerManagers[index]->GetSlicer(0)->GetOverlay();
1103 } else if (DataTree->selectedItems()[0]->data(1,Qt::UserRole).toString() == "fusion") {
1104 imageSelected = mSlicerManagers[index]->GetSlicer(0)->GetFusion();
1106 else if (DataTree->selectedItems()[0]->data(1,Qt::UserRole).toString() == "contour") {
1107 imageSelected = mSlicerManagers[index]->GetSlicer(0)->GetImage();
1110 imageSelected = mSlicerManagers[index]->GetSlicer(0)->GetImage();
1113 dimension = imageSelected->GetNumberOfDimensions();
1114 origin.resize(dimension);
1115 inputSpacing.resize(dimension);
1116 inputSize.resize(dimension);
1117 sizeMM.resize(dimension);
1118 pixelType = mSlicerManagers[index]->GetImage()->GetScalarTypeAsITKString().c_str();
1119 for (int i = 0; i < dimension; i++) {
1120 origin[i] = imageSelected->GetOrigin()[i];
1121 inputSpacing[i] = imageSelected->GetSpacing()[i];
1122 inputSize[i] = imageSelected->GetSize()[i];
1123 sizeMM[i] = inputSize[i]*inputSpacing[i];
1124 NPixel *= inputSize[i];
1126 inputSizeInBytes = GetSizeInBytes(imageSelected->GetActualMemorySize()*1000);
1128 QString dim = QString::number(dimension) + " (";
1129 dim += pixelType + ")";
1131 infoPanel->setFileName(image);
1132 infoPanel->setDimension(dim);
1133 infoPanel->setSizePixel(GetVectorIntAsString(inputSize));
1134 infoPanel->setSizeMM(GetVectorDoubleAsString(sizeMM));
1135 infoPanel->setOrigin(GetVectorDoubleAsString(origin));
1136 infoPanel->setSpacing(GetVectorDoubleAsString(inputSpacing));
1137 infoPanel->setNPixel(QString::number(NPixel)+" ("+inputSizeInBytes+")");
1138 transformation = imageSelected->GetTransform()->GetMatrix();
1139 infoPanel->setTransformation(Get4x4MatrixDoubleAsString(transformation));
1141 landmarksPanel->SetCurrentLandmarks(mSlicerManagers[index]->GetLandmarks(),
1142 mSlicerManagers[index]->GetSlicer(0)->GetImage()->GetVTKImages().size());
1143 landmarksPanel->SetCurrentPath(mInputPathName.toStdString());
1144 landmarksPanel->SetCurrentImage(mSlicerManagers[index]->GetFileName().c_str());
1146 overlayPanel->getCurrentImageName(mSlicerManagers[index]->GetFileName().c_str());
1147 for (int i = 0; i < 4; i++) {
1148 if (DataTree->selectedItems()[0]->data(i+1,Qt::CheckStateRole).toInt() > 0 || i == 3) {
1149 mSlicerManagers[index]->UpdateInfoOnCursorPosition(i);
1154 infoPanel->setFileName(image);
1155 infoPanel->setDimension(dim);
1156 infoPanel->setSizePixel(GetVectorIntAsString(inputSize));
1157 infoPanel->setSizeMM(GetVectorDoubleAsString(sizeMM));
1158 infoPanel->setOrigin(GetVectorDoubleAsString(origin));
1159 infoPanel->setSpacing(GetVectorDoubleAsString(inputSpacing));
1160 infoPanel->setNPixel(QString::number(NPixel)+" ("+inputSizeInBytes+")");
1162 landmarksPanel->SetCurrentLandmarks(mSlicerManagers[index]->GetLandmarks(),
1163 mSlicerManagers[index]->GetSlicer(0)->GetImage()->GetVTKImages().size());
1164 landmarksPanel->SetCurrentPath(mInputPathName.toStdString());
1165 landmarksPanel->SetCurrentImage(mSlicerManagers[index]->GetFileName().c_str());
1167 overlayPanel->getCurrentImageName(mSlicerManagers[index]->GetFileName().c_str());
1168 for (int i = 0; i < 4; i++) {
1169 if (DataTree->selectedItems()[0]->data(i+1,Qt::CheckStateRole).toInt() > 0 || i == 3) {
1170 mSlicerManagers[index]->UpdateInfoOnCursorPosition(i);
1174 WindowLevelChanged();
1176 if (mSlicerManagers[index]->GetSlicer(0)->GetVF()) {
1177 overlayPanel->getVFName(mSlicerManagers[index]->GetVFName().c_str());
1178 overlayPanel->getVFProperty(mSlicerManagers[index]->GetSlicer(0)->GetVFSubSampling(),
1179 mSlicerManagers[index]->GetSlicer(0)->GetVFScale(),
1180 mSlicerManagers[index]->GetSlicer(0)->GetVFLog());
1182 overlayPanel->getVFName(mSlicerManagers[index]->GetVFName().c_str());
1183 overlayPanel->getVFProperty(-1,-1,-1);
1185 if (mSlicerManagers[index]->GetSlicer(0)->GetOverlay()) {
1186 overlayPanel->getOverlayName(mSlicerManagers[index]->GetOverlayName().c_str());
1188 overlayPanel->getOverlayName(mSlicerManagers[index]->GetOverlayName().c_str());
1191 if (mSlicerManagers[index]->GetSlicer(0)->GetFusion()) {
1192 overlayPanel->getFusionName(mSlicerManagers[index]->GetFusionName().c_str());
1194 overlayPanel->getFusionName(mSlicerManagers[index]->GetFusionName().c_str());
1198 //------------------------------------------------------------------------------
1200 //------------------------------------------------------------------------------
1201 void vvMainWindow::ShowDocumentation()
1203 documentation->show();
1205 //------------------------------------------------------------------------------
1207 //------------------------------------------------------------------------------
1208 void vvMainWindow::PopupRegisterForm(bool checkCanPush)
1210 vvRegisterForm* registerForm = new vvRegisterForm(QUrl("http://www.creatis.insa-lyon.fr/~dsarrut/vvregister/write.php"), getVVSettingsPath(), getSettingsOptionFormat());
1212 registerForm->show();
1214 if(registerForm->canPush()) {
1215 registerForm->show();
1216 registerForm->acquitPushed();//too bad if there is not internet connection anymore.
1220 //------------------------------------------------------------------------------
1222 //------------------------------------------------------------------------------
1223 void vvMainWindow::ShowHelpDialog()
1225 help_dialog->show();
1227 //------------------------------------------------------------------------------
1229 //------------------------------------------------------------------------------
1230 void vvMainWindow::ChangeViewMode()
1233 if (viewMode == 1) {
1237 splitter_3->setSizes(size);
1238 OSplitter->setSizes(size);
1239 DataTree->setColumnHidden(2,1);
1240 DataTree->setColumnHidden(3,1);
1241 DataTree->setColumnHidden(4,1);
1246 splitter_3->setSizes(size);
1247 OSplitter->setSizes(size);
1248 DataTree->setColumnHidden(2,0);
1249 DataTree->setColumnHidden(3,0);
1250 DataTree->setColumnHidden(4,0);
1252 UpdateRenderWindows();
1254 ** I don't know why but for both resized QVTKWidget we also need to render
1255 ** the associated Slicer to redraw crosses.
1257 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
1258 if (DataTree->topLevelItem(i)->data(COLUMN_UL_VIEW,Qt::CheckStateRole).toInt() > 1)
1259 mSlicerManagers[i]->GetSlicer(0)->Render();
1260 if (DataTree->topLevelItem(i)->data(COLUMN_DL_VIEW,Qt::CheckStateRole).toInt() > 1)
1261 mSlicerManagers[i]->GetSlicer(2)->Render();
1264 //------------------------------------------------------------------------------
1266 //------------------------------------------------------------------------------
1267 QString vvMainWindow::GetSizeInBytes(unsigned long size)
1269 QString result = "";// QString::number(size);
1270 //result += " bytes (";
1271 if (size > 1000000000) {
1273 result += QString::number(size);
1274 result += "Gb";//)";
1275 } else if (size > 1000000) {
1277 result += QString::number(size);
1278 result += "Mb";//)";
1279 } else if (size > 1000) {
1281 result += QString::number(size);
1282 result += "kb";//)";
1286 //------------------------------------------------------------------------------
1288 //------------------------------------------------------------------------------
1289 QString vvMainWindow::Get4x4MatrixDoubleAsString(vtkSmartPointer<vtkMatrix4x4> matrix, const int precision)
1291 std::ostringstream strmatrix;
1293 // Figure out the number of digits of the integer part of the largest absolute value
1296 for (unsigned int j = 0; j < 4; j++){
1298 for (unsigned int i = 0; i < 4; i++)
1299 absmax = std::max(absmax, vnl_math_abs(matrix->GetElement(i, j)));
1300 unsigned ndigits = (unsigned)std::max(0.,std::log10(absmax))+1;
1301 width[j] = precision+ndigits+3;
1304 // Output with correct width, aligned to the right
1305 for (unsigned int i = 0; i < 4; i++) {
1306 for (unsigned int j = 0; j < 4; j++) {
1307 strmatrix.setf(ios::fixed,ios::floatfield);
1308 strmatrix.precision(precision);
1309 strmatrix.fill(' ');
1310 strmatrix.width(width[j]);
1311 strmatrix << std::right << matrix->GetElement(i, j);
1313 strmatrix << std::endl;
1315 QString result = strmatrix.str().c_str();
1318 //------------------------------------------------------------------------------
1320 //------------------------------------------------------------------------------
1321 QString vvMainWindow::GetVectorDoubleAsString(std::vector<double> vectorDouble)
1324 for (unsigned int i= 0; i < vectorDouble.size(); i++) {
1327 result += QString::number(vectorDouble[i]);
1331 //------------------------------------------------------------------------------
1333 //------------------------------------------------------------------------------
1334 QString vvMainWindow::GetVectorIntAsString(std::vector<int> vectorInt)
1337 for (unsigned int i= 0; i < vectorInt.size(); i++) {
1340 result += QString::number(vectorInt[i]);
1344 //------------------------------------------------------------------------------
1346 //------------------------------------------------------------------------------
1347 int vvMainWindow::GetSlicerIndexFromItem(QTreeWidgetItem* item)
1349 QString id = item->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString();
1350 for (int i = 0; i < DataTree->topLevelItemCount(); i++) {
1351 if (DataTree->topLevelItem(i)->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString() == id)
1356 //------------------------------------------------------------------------------
1358 //------------------------------------------------------------------------------
1359 QTreeWidgetItem* vvMainWindow::GetItemFromSlicerManager(vvSlicerManager* sm)
1361 QString id = sm->GetId().c_str();
1362 for (int i = 0; i < DataTree->topLevelItemCount(); i++) {
1363 if (DataTree->topLevelItem(i)->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString() == id)
1364 return DataTree->topLevelItem(i);
1368 //------------------------------------------------------------------------------
1370 //------------------------------------------------------------------------------
1371 void vvMainWindow::DisplayChanged(QTreeWidgetItem *clickedItem, int column)
1373 if ( column >= COLUMN_CLOSE_IMAGE || column <= 0)
1376 // Get parent information (might be the same item)
1377 int slicerManagerIndex = GetSlicerIndexFromItem(clickedItem);
1378 QTreeWidgetItem* clickedParentItem = DataTree->topLevelItem(slicerManagerIndex);
1379 vvSlicer* clickedSlicer = mSlicerManagers[slicerManagerIndex]->GetSlicer(column-1);
1381 // Go over the complete item tree (only 2 levels, parents and children)
1382 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
1383 // Trick to avoid redoing twice the job for a key (sr)
1384 mSlicerManagers[i]->GetSlicer(column-1)->GetRenderWindow()->GetInteractor()->SetKeySym("Crap");
1386 QTreeWidgetItem* currentParentItem = DataTree->topLevelItem(i);
1387 if(currentParentItem != clickedParentItem) {
1388 // Not the branch of the clicked item, uncheck all
1391 currentParentItem->setData(column,Qt::CheckStateRole, 0);
1392 mSlicerManagers[i]->UpdateSlicer(column-1, false);
1395 for (int iChild = 0; iChild < currentParentItem->childCount(); iChild++) {
1396 currentParentItem->child(iChild)->setData(column,Qt::CheckStateRole, 0);
1400 // Branch of the clicked one: get check status from actor visibility in slicer
1401 // and toggle the clicked one
1404 bool vis = clickedSlicer->GetActorVisibility("image", 0);
1405 bool draw = clickedSlicer->GetRenderer()->GetDraw();
1407 // Update slicer (after getting visibility)
1408 mSlicerManagers[slicerManagerIndex]->UpdateSlicer(column-1, true);
1409 mSlicerManagers[slicerManagerIndex]->UpdateInfoOnCursorPosition(column-1);
1410 DisplaySliders(slicerManagerIndex, column-1);
1411 if(clickedParentItem == clickedItem) {
1413 vis = !draw || !vis;
1415 clickedSlicer->SetActorVisibility("image", 0, vis);
1416 clickedParentItem->setData(column, Qt::CheckStateRole, vis?2:0);
1419 std::map<std::string, int> actorTypeCounts;
1420 for (int iChild = 0; iChild < clickedParentItem->childCount(); iChild++) {
1421 QTreeWidgetItem* currentChildItem = clickedParentItem->child(iChild);
1422 std::string actorType = currentChildItem->data(1,Qt::UserRole).toString().toStdString();
1423 vis = clickedSlicer->GetActorVisibility(actorType, actorTypeCounts[actorType]);
1424 if(currentChildItem == clickedItem) {
1425 // Toggle or force visibility if it was not on this branch so far
1426 vis = !draw || !vis;
1427 clickedSlicer->SetActorVisibility(actorType, actorTypeCounts[actorType], vis);
1429 currentChildItem->setData(column, Qt::CheckStateRole, vis?2:0);
1430 actorTypeCounts[actorType]++;
1435 clickedSlicer->Render();
1437 //------------------------------------------------------------------------------
1439 void vvMainWindow::InitSlicers()
1441 if (mSlicerManagers.size()) {
1442 mSlicerManagers.back()->GenerateDefaultLookupTable();
1444 mSlicerManagers.back()->SetSlicerWindow(0,NOViewWidget->GetRenderWindow());
1445 mSlicerManagers.back()->SetSlicerWindow(1,NEViewWidget->GetRenderWindow());
1446 mSlicerManagers.back()->SetSlicerWindow(2,SOViewWidget->GetRenderWindow());
1447 mSlicerManagers.back()->SetSlicerWindow(3,SEViewWidget->GetRenderWindow());
1451 //------------------------------------------------------------------------------
1452 void vvMainWindow::InitDisplay()
1454 if (mSlicerManagers.size()) {
1455 //BE CAREFUL : this is absolutely necessary to set the interactor style
1456 //in order to have the same style instanciation for all SlicerManagers in
1458 for (int j = 0; j < 4; j++) {
1459 vvInteractorStyleNavigator* style = vvInteractorStyleNavigator::New();
1460 style->SetAutoAdjustCameraClippingRange(1);
1461 bool AlreadySelected = false;
1462 for (int i = 0; i < DataTree->topLevelItemCount(); i++) {
1463 mSlicerManagers[i]->SetInteractorStyleNavigator(j,style);
1465 //select the image only if previous are not selected
1466 if (DataTree->topLevelItem(i)->data(j+1,Qt::CheckStateRole).toInt() > 1) {
1467 mSlicerManagers[i]->UpdateSlicer(j,1);
1468 AlreadySelected = true;
1469 } else if (i == DataTree->topLevelItemCount()-1 && !AlreadySelected) {
1470 if (DataTree->selectedItems().size() == 0)
1471 DataTree->topLevelItem(i)->setSelected(1);
1472 DataTree->topLevelItem(i)->setData(j+1,Qt::CheckStateRole,2);
1473 mSlicerManagers[i]->UpdateSlicer(j,1);
1474 DisplaySliders(i,j);
1476 DataTree->topLevelItem(i)->setData(j+1,Qt::CheckStateRole,0);
1477 mSlicerManagers[i]->UpdateSlicer(j,0);
1484 //------------------------------------------------------------------------------
1486 //------------------------------------------------------------------------------
1487 void vvMainWindow::DisplaySliders(int slicer, int window)
1490 mSlicerManagers[slicer]->GetSlicer(window)->GetSliceRange(range);
1491 int position = mSlicerManagers[slicer]->GetSlicer(window)->GetSlice();
1495 tRange[1] = mSlicerManagers[slicer]->GetSlicer(window)->GetTMax();
1496 int tPosition = mSlicerManagers[slicer]->GetSlicer(window)->GetTSlice();
1497 bool showHorizontal = false;
1498 bool showVertical = false;
1499 if (mSlicerManagers[slicer]->GetSlicer(window)->GetImage()->GetNumberOfDimensions() > 3
1500 || (mSlicerManagers[slicer]->GetSlicer(window)->GetImage()->GetNumberOfDimensions() > 2
1501 && mSlicerManagers[slicer]->GetType() != vvImageReader::IMAGEWITHTIME
1502 && mSlicerManagers[slicer]->GetType() != vvImageReader::MERGEDWITHTIME))
1503 showVertical = true;
1504 if (mSlicerManagers[slicer]->GetSlicer(window)->GetImage()->GetNumberOfDimensions() > 3
1505 || mSlicerManagers[slicer]->GetType() == vvImageReader::IMAGEWITHTIME
1506 || mSlicerManagers[slicer]->GetType() == vvImageReader::MERGEDWITHTIME)
1507 showHorizontal = true;
1510 verticalSliders[window]->show();
1512 verticalSliders[window]->hide();
1513 verticalSliders[window]->setRange(range[0],range[1]);
1514 verticalSliders[window]->setValue(position);
1517 horizontalSliders[window]->show();
1519 horizontalSliders[window]->hide();
1520 horizontalSliders[window]->setRange(tRange[0],tRange[1]);
1521 horizontalSliders[window]->setValue(tPosition);
1523 //------------------------------------------------------------------------------
1525 //------------------------------------------------------------------------------
1526 void vvMainWindow::CloseImage(QTreeWidgetItem* item, int column)
1528 int index = GetSlicerIndexFromItem(item);
1530 if (DataTree->topLevelItem(index) != item) {
1531 QString warning = "Do you really want to close the overlay : ";
1532 warning += item->data(COLUMN_IMAGE_NAME,Qt::DisplayRole).toString();
1533 QMessageBox msgBox(QMessageBox::Warning, tr("Close Overlay"),
1535 msgBox.addButton(tr("Close"), QMessageBox::AcceptRole);
1536 msgBox.addButton(tr("Cancel"), QMessageBox::RejectRole);
1537 if (msgBox.exec() == QMessageBox::AcceptRole) {
1538 std::string overlay_type=item->data(1,Qt::UserRole).toString().toStdString();
1539 int overlay_index=0;
1540 for (int child = 0; child < DataTree->topLevelItem(index)->childCount(); child++) {
1541 if (DataTree->topLevelItem(index)->\
1542 child(child)->data(1,Qt::UserRole).toString().toStdString() == overlay_type)
1544 if (DataTree->topLevelItem(index)->child(child) == item) break;
1546 mSlicerManagers[index]->RemoveActor(overlay_type, overlay_index-1);
1547 mSlicerManagers[index]->SetColorMap(0);
1548 DataTree->topLevelItem(index)->takeChild(DataTree->topLevelItem(index)->indexOfChild(item));
1549 mSlicerManagers[index]->Render();
1551 } else if (DataTree->topLevelItemCount() <= 1) {
1552 QString warning = "Do you really want to close the image : ";
1553 warning += item->data(COLUMN_IMAGE_NAME,Qt::DisplayRole).toString();
1554 warning += "\nThis is the last image, you're about to close vv !!!";
1555 QMessageBox msgBox(QMessageBox::Warning, tr("Close Image"),
1557 msgBox.addButton(tr("Close vv"), QMessageBox::AcceptRole);
1558 msgBox.addButton(tr("Cancel"), QMessageBox::RejectRole);
1559 if (msgBox.exec() == QMessageBox::AcceptRole) {
1563 QString warning = "Do you really want to close the image : ";
1564 warning += item->data(COLUMN_IMAGE_NAME,Qt::DisplayRole).toString();
1565 QMessageBox msgBox(QMessageBox::Warning, tr("Close Image"),
1567 msgBox.addButton(tr("Close"), QMessageBox::AcceptRole);
1568 msgBox.addButton(tr("Cancel"), QMessageBox::RejectRole);
1569 if (msgBox.exec() == QMessageBox::AcceptRole) {
1571 // Tell tools that we close an image
1572 emit AnImageIsBeingClosed(mSlicerManagers[index]);
1574 std::vector<vvSlicerManager*>::iterator Manageriter = mSlicerManagers.begin();
1575 DataTree->takeTopLevelItem(index);
1576 for (int i = 0; i < index; i++) {
1579 linkPanel->removeImage(index);
1580 mSlicerManagers[index]->RemoveActors();
1581 delete mSlicerManagers[index];
1582 mSlicerManagers.erase(Manageriter);
1590 //------------------------------------------------------------------------------
1592 //------------------------------------------------------------------------------
1593 void vvMainWindow::ReloadImage(QTreeWidgetItem* item, int column)
1595 // int index = GetSlicerIndexFromItem(item);
1596 // QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
1597 // if (item->data(1,Qt::UserRole).toString() == "vector")
1598 // mSlicerManagers[index]->ReloadVF();
1600 // mSlicerManagers[index]->Reload();
1602 // QApplication::restoreOverrideCursor();
1603 int index = GetSlicerIndexFromItem(item);
1604 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
1605 QString role=item->data(1,Qt::UserRole).toString();
1606 if ( role == "vector"){
1607 mSlicerManagers[index]->ReloadVF();
1609 else if (role == "overlay"){
1610 mSlicerManagers[index]->ReloadOverlay();
1612 else if (role == "fusion"){
1613 mSlicerManagers[index]->ReloadFusion();
1616 mSlicerManagers[index]->Reload();
1618 // Update view and info
1620 mSlicerManagers[index]->Render();
1621 QApplication::restoreOverrideCursor();
1623 //------------------------------------------------------------------------------
1625 //------------------------------------------------------------------------------
1626 void vvMainWindow::MousePositionChanged(int visibility,double x, double y, double z, double X, double Y, double Z , double value)
1628 infoPanel->setCurrentInfo(visibility,x,y,z,X,Y,Z,value);
1630 //------------------------------------------------------------------------------
1632 //------------------------------------------------------------------------------
1633 void vvMainWindow::VectorChanged(int visibility,double x, double y, double z, double value)
1635 overlayPanel->getCurrentVectorInfo(visibility,x,y,z,value);
1637 //------------------------------------------------------------------------------
1639 //------------------------------------------------------------------------------
1640 void vvMainWindow::OverlayChanged(int visibility, double valueOver, double valueRef)
1642 overlayPanel->getCurrentOverlayInfo(visibility,valueOver, valueRef);
1644 //------------------------------------------------------------------------------
1646 //------------------------------------------------------------------------------
1647 void vvMainWindow::FusionChanged(int visibility, double value)
1649 overlayPanel->getCurrentFusionInfo(visibility,value);
1651 //------------------------------------------------------------------------------
1653 //------------------------------------------------------------------------------
1654 void vvMainWindow::WindowLevelChanged()
1657 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
1658 if(index==-1) return;
1659 windowSpinBox->setValue(mSlicerManagers[index]->GetColorWindow());
1660 levelSpinBox->setValue(mSlicerManagers[index]->GetColorLevel());
1661 colorMapComboBox->setCurrentIndex(mSlicerManagers[index]->GetColorMap());
1662 presetComboBox->setCurrentIndex(mSlicerManagers[index]->GetPreset());
1665 if (mSlicerManagers[index]->GetSlicer(0)->GetOverlay())
1666 overlayPanel->getOverlayProperty(mSlicerManagers[index]->GetOverlayColor(),
1667 mSlicerManagers[index]->GetLinkOverlayWindowLevel(),
1668 mSlicerManagers[index]->GetOverlayColorWindow(),
1669 mSlicerManagers[index]->GetOverlayColorLevel());
1671 overlayPanel->getOverlayProperty(-1,0,0.,0.);
1674 if (mSlicerManagers[index]->GetSlicer(0)->GetFusion())
1675 overlayPanel->getFusionProperty(mSlicerManagers[index]->GetFusionOpacity(),
1676 mSlicerManagers[index]->GetFusionThresholdOpacity(),
1677 mSlicerManagers[index]->GetFusionColorMap(),
1678 mSlicerManagers[index]->GetFusionWindow(),
1679 mSlicerManagers[index]->GetFusionLevel());
1681 overlayPanel->getFusionProperty(-1, -1, -1, -1, -1);
1683 //------------------------------------------------------------------------------
1685 //------------------------------------------------------------------------------
1686 void vvMainWindow::WindowLevelEdited()
1688 presetComboBox->setCurrentIndex(6);
1689 UpdateWindowLevel();
1691 //------------------------------------------------------------------------------
1693 //------------------------------------------------------------------------------
1694 void vvMainWindow::SetWindowLevel(double w, double l)
1696 windowSpinBox->setValue(w);
1697 levelSpinBox->setValue(l);
1698 presetComboBox->setCurrentIndex(6);
1699 colorMapComboBox->setCurrentIndex(0);
1700 UpdateWindowLevel();
1702 //------------------------------------------------------------------------------
1704 //------------------------------------------------------------------------------
1705 void vvMainWindow::UpdateWindowLevel()
1707 if (DataTree->selectedItems().size()) {
1708 if (presetComboBox->currentIndex() == 7) //For ventilation
1709 colorMapComboBox->setCurrentIndex(5);
1710 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
1711 mSlicerManagers[index]->SetColorWindow(windowSpinBox->value());
1712 mSlicerManagers[index]->SetColorLevel(levelSpinBox->value());
1713 mSlicerManagers[index]->SetPreset(presetComboBox->currentIndex());
1714 mSlicerManagers[index]->Render();
1715 WindowLevelChanged();
1718 //------------------------------------------------------------------------------
1720 //------------------------------------------------------------------------------
1721 void vvMainWindow::UpdateColorMap()
1723 if (DataTree->selectedItems().size()) {
1724 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
1725 mSlicerManagers[index]->SetColorMap(colorMapComboBox->currentIndex());
1726 mSlicerManagers[index]->Render();
1729 //------------------------------------------------------------------------------
1730 void vvMainWindow::SwitchWindowLevel()
1732 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
1733 int window = mSlicerManagers[index]->GetColorWindow();
1734 presetComboBox->setCurrentIndex(6);
1735 windowSpinBox->setValue(-window);
1736 UpdateWindowLevel();
1738 //------------------------------------------------------------------------------
1740 //------------------------------------------------------------------------------
1741 void vvMainWindow::ApplyWindowLevelToAllImages()
1743 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
1744 if(index==-1) return;
1745 double window = mSlicerManagers[index]->GetColorWindow();
1746 double level = mSlicerManagers[index]->GetColorLevel();
1748 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
1749 if (mSlicerManagers[i] == NULL)
1751 mSlicerManagers[i]->SetColorWindow(window);
1752 mSlicerManagers[i]->SetColorLevel(level);
1753 mSlicerManagers[i]->SetPreset(6);
1754 mSlicerManagers[i]->Render();
1757 //------------------------------------------------------------------------------
1759 //------------------------------------------------------------------------------
1760 void vvMainWindow::UpdateLinkManager(std::string id, int slicer, double x, double y, double z, int temps)
1762 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
1763 if (mSlicerManagers[i]->GetId() == id) {
1764 //mSlicerManagers[i]->SetTSlice(temps);
1765 mSlicerManagers[i]->GetSlicer(slicer)->SetCurrentPosition(x,y,z,temps);
1766 mSlicerManagers[i]->UpdateViews(0,slicer);
1771 //------------------------------------------------------------------------------
1773 //------------------------------------------------------------------------------
1774 void vvMainWindow::UpdateLinkedNavigation(std::string id, vvSlicerManager * sm, vvSlicer* refSlicer)
1776 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
1777 if (id == mSlicerManagers[i]->GetId()) {
1778 mSlicerManagers[i]->UpdateLinkedNavigation(refSlicer);
1782 //------------------------------------------------------------------------------
1784 //------------------------------------------------------------------------------
1785 void vvMainWindow::ShowContextMenu(QPoint point)
1787 if (!DataTree->selectedItems().size()) {
1788 contextActions[1]->setEnabled(0);
1789 contextActions[2]->setEnabled(0);
1790 contextActions[3]->setEnabled(0);
1791 contextActions[4]->setEnabled(0);
1792 contextActions[5]->setEnabled(0);
1793 contextActions[6]->setEnabled(0);
1795 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
1796 contextActions[1]->setEnabled(1);
1797 contextActions[2]->setEnabled(
1798 DataTree->itemWidget(DataTree->selectedItems()[0],
1799 COLUMN_RELOAD_IMAGE)->isEnabled());
1800 contextActions[3]->setEnabled(1);
1801 contextActions[5]->setEnabled(1);
1802 contextActions[6]->setEnabled(1);
1804 if (mSlicerManagers[index]->GetDimension() < 3)
1805 contextActions[4]->setEnabled(0);
1807 contextActions[4]->setEnabled(1);
1809 contextMenu.exec(QCursor::pos());
1811 //------------------------------------------------------------------------------
1813 //------------------------------------------------------------------------------
1814 void vvMainWindow::CloseImage()
1816 CloseImage(DataTree->selectedItems()[0],0);
1818 //------------------------------------------------------------------------------
1820 //------------------------------------------------------------------------------
1821 void vvMainWindow::ReloadImage()
1823 ReloadImage(DataTree->selectedItems()[0],0);
1825 //------------------------------------------------------------------------------
1827 //------------------------------------------------------------------------------
1828 void vvMainWindow::SelectOverlayImage()
1830 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
1832 //check if one overlay image is added
1833 for (int child = 0; child < DataTree->topLevelItem(index)->childCount(); child++)
1834 if (DataTree->topLevelItem(index)->child(child)->data(1,Qt::UserRole).toString() == "overlay") {
1835 QString error = "Cannot add more than one compared image\n";
1836 error += "Please remove first ";
1837 error += DataTree->topLevelItem(index)->child(child)->data(COLUMN_IMAGE_NAME,Qt::DisplayRole).toString();
1838 QMessageBox::information(this,tr("Problem adding compared image !"),error);
1842 QString Extensions = EXTENSIONS;
1843 Extensions += ";;All Files (*)";
1844 QString file = QFileDialog::getOpenFileName(this,tr("Load Overlay image"),mInputPathName,Extensions);
1845 if (!file.isEmpty())
1846 AddOverlayImage(index,file);
1848 //------------------------------------------------------------------------------
1850 //------------------------------------------------------------------------------
1851 void vvMainWindow::AddOverlayImage(int index, QString file)
1853 if (QFile::exists(file))
1855 mInputPathName = itksys::SystemTools::GetFilenamePath(file.toStdString()).c_str();
1856 itk::ImageIOBase::Pointer reader = itk::ImageIOFactory::CreateImageIO(
1857 file.toStdString().c_str(), itk::ImageIOFactory::ReadMode);
1858 reader->SetFileName(file.toStdString().c_str());
1859 reader->ReadImageInformation();
1860 std::string component = reader->GetComponentTypeAsString(reader->GetComponentType());
1861 int dimension = reader->GetNumberOfDimensions();
1862 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
1863 vvProgressDialog progress("Opening " + file.toStdString());
1864 qApp->processEvents();
1866 std::string filename = itksys::SystemTools::GetFilenameWithoutExtension(file.toStdString()).c_str();
1867 if (mSlicerManagers[index]->SetOverlay(file.toStdString(),dimension, component)) {
1868 //create an item in the tree with good settings
1869 QTreeWidgetItem *item = new QTreeWidgetItem();
1870 item->setData(0,Qt::UserRole,file.toStdString().c_str());
1871 item->setData(1,Qt::UserRole,tr("overlay"));
1872 QFileInfo fileinfo(file); //Do not show the path
1873 item->setData(COLUMN_IMAGE_NAME,Qt::DisplayRole,fileinfo.fileName());
1874 item->setToolTip(COLUMN_IMAGE_NAME, mSlicerManagers[index]->GetListOfAbsoluteFilePathInOneString("overlay").c_str());
1875 qApp->processEvents();
1877 for (int j = 1; j <= 4; j++) {
1878 item->setData(j,Qt::CheckStateRole,DataTree->topLevelItem(index)->data(j,Qt::CheckStateRole));
1881 //Create the buttons for reload and close
1882 qApp->processEvents();
1883 QTreePushButton* cButton = new QTreePushButton;
1884 cButton->setItem(item);
1885 cButton->setColumn(COLUMN_CLOSE_IMAGE);
1886 cButton->setToolTip(tr("close image"));
1887 cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png")));
1888 connect(cButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
1889 this,SLOT(CloseImage(QTreeWidgetItem*, int)));
1891 QTreePushButton* rButton = new QTreePushButton;
1892 rButton->setItem(item);
1893 rButton->setColumn(COLUMN_RELOAD_IMAGE);
1894 rButton->setToolTip(tr("reload image"));
1895 rButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/rotateright.png")));
1896 connect(rButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
1897 this,SLOT(ReloadImage(QTreeWidgetItem*, int)));
1899 DataTree->topLevelItem(index)->setExpanded(1);
1900 DataTree->topLevelItem(index)->addChild(item);
1901 DataTree->setItemWidget(item, COLUMN_CLOSE_IMAGE, cButton);
1902 DataTree->setItemWidget(item, COLUMN_RELOAD_IMAGE, rButton);
1904 //set the id of the image
1905 QString id = DataTree->topLevelItem(index)->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString();
1906 item->setData(COLUMN_IMAGE_NAME,Qt::UserRole,id.toStdString().c_str());
1908 qApp->processEvents();
1910 QApplication::restoreOverrideCursor();
1912 QApplication::restoreOverrideCursor();
1913 QString error = "Cannot import the new image.\n";
1914 error += mSlicerManagers[index]->GetLastError().c_str();
1915 QMessageBox::information(this,tr("Problem reading image !"),error);
1917 WindowLevelChanged();
1920 QMessageBox::information(this,tr("Problem reading Overlay !"),"File doesn't exist!");
1922 //------------------------------------------------------------------------------
1925 //------------------------------------------------------------------------------
1926 void vvMainWindow::AddROI(int index, QString file)
1929 // Get slice manager
1933 vvImageReader * mReader = new vvImageReader;
1934 mReader->SetInputFilename(filename.toStdString());
1935 mReader->Update(IMAGE);
1936 if (mReader->GetLastError().size() != 0) {
1937 std::cerr << "Error while reading " << filename.toStdString() << std::endl;
1938 QString error = "Cannot open file \n";
1939 error += mReader->GetLastError().c_str();
1940 QMessageBox::information(this,tr("Reading problem"),error);
1944 vvImage::Pointer roi = mReader->GetOutput();
1946 // Create roi in new tool
1947 vvToolStructureSetManager::AddImage(mCurrentSlicerManager, roi);
1950 //------------------------------------------------------------------------------
1952 //------------------------------------------------------------------------------
1953 void vvMainWindow::SelectFusionImage()
1955 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
1957 //check if one fusion image is added
1958 for (int child = 0; child < DataTree->topLevelItem(index)->childCount(); child++)
1959 if (DataTree->topLevelItem(index)->child(child)->data(1,Qt::UserRole).toString() == "fusion") {
1960 QString error = "Cannot add more than one fusion image\n";
1961 error += "Please remove first ";
1962 error += DataTree->topLevelItem(index)->child(child)->data(COLUMN_IMAGE_NAME,Qt::DisplayRole).toString();
1963 QMessageBox::information(this,tr("Problem adding fusion image !"),error);
1967 QString Extensions = EXTENSIONS;
1968 Extensions += ";;All Files (*)";
1969 QString file = QFileDialog::getOpenFileName(this,tr("Load Fusion image"),mInputPathName,Extensions);
1970 if (!file.isEmpty())
1971 AddFusionImage(index,file);
1973 //------------------------------------------------------------------------------
1975 //------------------------------------------------------------------------------
1976 void vvMainWindow::ResetTransformationToIdentity()
1978 std::string actorType = DataTree->selectedItems()[0]->data(1,Qt::UserRole).toString().toStdString();
1979 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
1980 mSlicerManagers[index]->ResetTransformationToIdentity(actorType);
1983 //------------------------------------------------------------------------------
1985 //------------------------------------------------------------------------------
1986 void vvMainWindow::AddFusionImage(int index, QString file)
1988 if (QFile::exists(file))
1990 mInputPathName = itksys::SystemTools::GetFilenamePath(file.toStdString()).c_str();
1991 itk::ImageIOBase::Pointer reader = itk::ImageIOFactory::CreateImageIO(
1992 file.toStdString().c_str(), itk::ImageIOFactory::ReadMode);
1993 reader->SetFileName(file.toStdString().c_str());
1994 reader->ReadImageInformation();
1995 std::string component = reader->GetComponentTypeAsString(reader->GetComponentType());
1997 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
1998 vvProgressDialog progress("Opening fusion");
1999 qApp->processEvents();
2001 std::string filename = itksys::SystemTools::GetFilenameWithoutExtension(file.toStdString()).c_str();
2002 if (mSlicerManagers[index]->SetFusion(file.toStdString(),
2003 reader->GetNumberOfDimensions(), component)) {
2004 //create an item in the tree with good settings
2005 QTreeWidgetItem *item = new QTreeWidgetItem();
2006 item->setData(0,Qt::UserRole,file.toStdString().c_str());
2007 item->setData(1,Qt::UserRole,tr("fusion"));
2008 QFileInfo fileinfo(filename.c_str()); //Do not show the path
2009 item->setData(COLUMN_IMAGE_NAME,Qt::DisplayRole,fileinfo.fileName());
2010 item->setToolTip(COLUMN_IMAGE_NAME, mSlicerManagers[index]->GetListOfAbsoluteFilePathInOneString("fusion").c_str());
2011 qApp->processEvents();
2013 for (int j = 1; j <= 4; j++) {
2014 item->setData(j,Qt::CheckStateRole,DataTree->topLevelItem(index)->data(j,Qt::CheckStateRole));
2017 //Create the buttons for reload and close
2018 qApp->processEvents();
2019 QTreePushButton* cButton = new QTreePushButton;
2020 cButton->setItem(item);
2021 cButton->setColumn(COLUMN_CLOSE_IMAGE);
2022 cButton->setToolTip(tr("close image"));
2023 cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png")));
2024 connect(cButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
2025 this,SLOT(CloseImage(QTreeWidgetItem*, int)));
2027 QTreePushButton* rButton = new QTreePushButton;
2028 rButton->setItem(item);
2029 rButton->setColumn(COLUMN_RELOAD_IMAGE);
2030 rButton->setToolTip(tr("reload image"));
2031 rButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/rotateright.png")));
2032 connect(rButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
2033 this,SLOT(ReloadImage(QTreeWidgetItem*, int)));
2035 DataTree->topLevelItem(index)->setExpanded(1);
2036 DataTree->topLevelItem(index)->addChild(item);
2037 DataTree->setItemWidget(item, COLUMN_CLOSE_IMAGE, cButton);
2038 DataTree->setItemWidget(item, COLUMN_RELOAD_IMAGE, rButton);
2040 //set the id of the image
2041 QString id = DataTree->topLevelItem(index)->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString();
2042 item->setData(COLUMN_IMAGE_NAME,Qt::UserRole,id.toStdString().c_str());
2044 qApp->processEvents();
2046 QApplication::restoreOverrideCursor();
2048 QApplication::restoreOverrideCursor();
2049 QString error = "Cannot import the new image.\n";
2050 error += mSlicerManagers[index]->GetLastError().c_str();
2051 QMessageBox::information(this,tr("Problem reading image !"),error);
2054 QString error = "Cannot import the new image.\n";
2055 QMessageBox::information(this,tr("Problem reading image !"),error);
2059 QMessageBox::information(this,tr("Problem reading Fusion !"),"File doesn't exist!");
2061 //------------------------------------------------------------------------------
2064 //------------------------------------------------------------------------------
2065 void vvMainWindow::OpenField()
2067 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
2068 //check if a vector field has already been added
2069 for (int child = 0; child < DataTree->topLevelItem(index)->childCount(); child++)
2070 if (DataTree->topLevelItem(index)->child(child)->data(1,Qt::UserRole).toString() == "vector") {
2071 QString error = "Cannot add more than one vector field\n";
2072 error += "Please remove first ";
2073 error += DataTree->topLevelItem(index)->child(child)->data(COLUMN_IMAGE_NAME,Qt::DisplayRole).toString();
2074 QMessageBox::information(this,tr("Problem adding vector field!"),error);
2078 QString Extensions = "Images ( *.mhd)";
2079 Extensions += ";;Images ( *.mha)";
2080 Extensions += ";;Images ( *.vf)";
2081 QString file = QFileDialog::getOpenFileName(this,tr("Load deformation field"),mInputPathName,Extensions);
2082 if (!file.isEmpty())
2083 AddField(file,index);
2085 //------------------------------------------------------------------------------
2088 //------------------------------------------------------------------------------
2089 void vvMainWindow::AddFieldEntry(QString filename,int index,bool from_disk)
2091 //create an item in the tree with good settings
2092 QTreeWidgetItem *item = new QTreeWidgetItem();
2093 item->setData(0,Qt::UserRole,filename.toStdString().c_str());
2094 item->setData(1,Qt::UserRole,tr("vector"));
2095 QFileInfo fileinfo(filename); //Do not show the path
2096 item->setData(COLUMN_IMAGE_NAME,Qt::DisplayRole,fileinfo.fileName());
2097 item->setToolTip(COLUMN_IMAGE_NAME, mSlicerManagers[index]->GetListOfAbsoluteFilePathInOneString("vector").c_str());
2098 qApp->processEvents();
2100 for (int j = 1; j <= 4; j++) {
2101 item->setData(j,Qt::CheckStateRole,DataTree->topLevelItem(index)->data(j,Qt::CheckStateRole));
2104 //Create the buttons for reload and close
2105 qApp->processEvents();
2106 QTreePushButton* cButton = new QTreePushButton;
2107 cButton->setItem(item);
2108 cButton->setColumn(COLUMN_CLOSE_IMAGE);
2109 cButton->setToolTip(tr("close vector field"));
2110 cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png")));
2111 connect(cButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
2112 this,SLOT(CloseImage(QTreeWidgetItem*, int)));
2114 QTreePushButton* rButton = new QTreePushButton;
2115 rButton->setItem(item);
2116 rButton->setColumn(COLUMN_RELOAD_IMAGE);
2117 rButton->setToolTip(tr("reload vector field"));
2118 rButton->setEnabled(from_disk);
2119 rButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/rotateright.png")));
2120 connect(rButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
2121 this,SLOT(ReloadImage(QTreeWidgetItem*, int)));
2123 DataTree->topLevelItem(index)->setExpanded(1);
2124 DataTree->topLevelItem(index)->addChild(item);
2125 DataTree->setItemWidget(item, COLUMN_RELOAD_IMAGE, rButton);
2126 DataTree->setItemWidget(item, COLUMN_CLOSE_IMAGE, cButton);
2128 //set the id of the image
2129 QString id = DataTree->topLevelItem(index)->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString();
2130 item->setData(COLUMN_IMAGE_NAME,Qt::UserRole,id.toStdString().c_str());
2132 qApp->processEvents();
2134 QApplication::restoreOverrideCursor();
2136 //------------------------------------------------------------------------------
2139 //------------------------------------------------------------------------------
2140 void vvMainWindow::AddField(vvImage::Pointer vf,QString file,int index)
2142 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
2143 vvSlicerManager* imageManager = mSlicerManagers[index];
2144 if (imageManager->SetVF(vf,file.toStdString())) {
2145 AddFieldEntry(file,index,false);
2147 QString error = "Cannot import the vector field for this image.\n";
2148 error += imageManager->GetLastError().c_str();
2149 QMessageBox::information(this,tr("Problem reading VF !"),error);
2151 QApplication::restoreOverrideCursor();
2153 //------------------------------------------------------------------------------
2156 //------------------------------------------------------------------------------
2157 void vvMainWindow::AddField(QString file,int index)
2159 if (QFile::exists(file)) {
2160 mInputPathName = itksys::SystemTools::GetFilenamePath(file.toStdString()).c_str();
2162 //init the progress events
2163 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
2164 vvProgressDialog progress("Opening " + file.toStdString());
2165 qApp->processEvents();
2167 //read the vector and put it in the current mSlicerManager
2168 vvSlicerManager* imageManager = mSlicerManagers[index];
2169 qApp->processEvents();
2171 std::string filename = itksys::SystemTools::GetFilenameWithoutExtension(file.toStdString()).c_str();
2172 if (imageManager->SetVF(file.toStdString())) {
2173 imageManager->Render();
2174 AddFieldEntry(file,index,true);
2176 QApplication::restoreOverrideCursor();
2177 QString error = "Cannot import the vector field for this image.\n";
2178 error += imageManager->GetLastError().c_str();
2179 QMessageBox::information(this,tr("Problem reading VF !"),error);
2182 QMessageBox::information(this,tr("Problem reading VF !"),"File doesn't exist!");
2185 //------------------------------------------------------------------------------
2188 //------------------------------------------------------------------------------
2189 void vvMainWindow::SetVFProperty(int subsampling, int scale, int log, int width, double r, double g, double b)
2191 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
2192 if (mSlicerManagers[index]->GetSlicer(0)->GetVF()) {
2193 for (int i = 0; i < 4; i++) {
2194 mSlicerManagers[index]->GetSlicer(i)->SetVFSubSampling(subsampling);
2195 mSlicerManagers[index]->GetSlicer(i)->SetVFScale(scale);
2196 mSlicerManagers[index]->GetSlicer(i)->SetVFWidth(width);
2197 mSlicerManagers[index]->GetSlicer(i)->SetVFColor(r,g,b);
2199 mSlicerManagers[index]->GetSlicer(i)->SetVFLog(1);
2201 mSlicerManagers[index]->GetSlicer(i)->SetVFLog(0);
2205 //------------------------------------------------------------------------------
2208 //------------------------------------------------------------------------------
2209 void vvMainWindow::SetOverlayProperty(int color, int linked, double window, double level)
2211 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
2212 if (mSlicerManagers[index]->GetSlicer(0)->GetOverlay()) {
2213 mSlicerManagers[index]->SetOverlayColor(color);
2214 mSlicerManagers[index]->SetColorMap(0);
2215 mSlicerManagers[index]->SetLinkOverlayWindowLevel(linked);
2216 mSlicerManagers[index]->SetOverlayColorWindow(window);
2217 mSlicerManagers[index]->SetOverlayColorLevel(level);
2218 mSlicerManagers[index]->Render();
2221 //------------------------------------------------------------------------------
2223 //------------------------------------------------------------------------------
2224 void vvMainWindow::SetFusionProperty(int opacity, int thresOpacity, int colormap,double window, double level, bool showLegend)
2226 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
2227 if (mSlicerManagers[index]->GetSlicer(0)->GetFusion()) {
2228 mSlicerManagers[index]->SetFusionColorMap(colormap);
2229 mSlicerManagers[index]->SetFusionOpacity(opacity);
2230 mSlicerManagers[index]->SetFusionThresholdOpacity(thresOpacity);
2231 mSlicerManagers[index]->SetFusionWindow(window);
2232 mSlicerManagers[index]->SetFusionLevel(level);
2233 mSlicerManagers[index]->SetFusionShowLegend(showLegend);
2234 mSlicerManagers[index]->SetColorMap(0);
2235 mSlicerManagers[index]->Render();
2238 //------------------------------------------------------------------------------
2240 //------------------------------------------------------------------------------
2241 void vvMainWindow::SaveAs()
2243 if (DataTree->selectedItems()[0]->data(1,Qt::UserRole).toString() == "vector") {
2244 QMessageBox::warning(this,tr("Unsupported type"),tr("Sorry, saving a vector field is unsupported for the moment"));
2248 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
2249 int dimension = mSlicerManagers[index]->GetDimension();
2250 QStringList OutputListeFormat;
2251 OutputListeFormat.clear();
2252 if (dimension == 1) {
2253 OutputListeFormat.push_back(".mhd");
2254 OutputListeFormat.push_back(".mha");
2256 if (dimension == 2) {
2257 OutputListeFormat.push_back(".bmp");
2258 OutputListeFormat.push_back(".png");
2259 OutputListeFormat.push_back(".jpeg");
2260 OutputListeFormat.push_back(".tif");
2261 OutputListeFormat.push_back(".mhd");
2262 OutputListeFormat.push_back(".mha");
2263 OutputListeFormat.push_back(".hdr");
2264 OutputListeFormat.push_back(".vox");
2265 } else if (dimension == 3) {
2266 OutputListeFormat.push_back(".mhd");
2267 OutputListeFormat.push_back(".mha");
2268 OutputListeFormat.push_back(".nii");
2269 OutputListeFormat.push_back(".nrrd");
2270 OutputListeFormat.push_back(".nhdr");
2271 OutputListeFormat.push_back(".hdr");
2272 OutputListeFormat.push_back(".vox");
2273 } else if (dimension == 4) {
2274 OutputListeFormat.push_back(".mhd");
2275 OutputListeFormat.push_back(".mha");
2276 OutputListeFormat.push_back(".nii");
2277 OutputListeFormat.push_back(".nrrd");
2278 OutputListeFormat.push_back(".nhdr");
2280 QString Extensions = "AllFiles(*.*)";
2281 for (int i = 0; i < OutputListeFormat.count(); i++) {
2282 Extensions += ";;Images ( *";
2283 Extensions += OutputListeFormat[i];
2286 QString fileName = QFileDialog::getSaveFileName(this,
2288 mSlicerManagers[index]->GetFileName().c_str(),
2290 if (!fileName.isEmpty()) {
2291 std::string fileformat = itksys::SystemTools::GetFilenameLastExtension(fileName.toStdString());
2292 if (OutputListeFormat.contains(
2293 fileformat.c_str())) {
2294 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
2295 std::string action = "Saving";
2296 vvProgressDialog progress("Saving "+fileName.toStdString());
2297 qApp->processEvents();
2298 vvImageWriter::Pointer writer = vvImageWriter::New();
2299 writer->SetOutputFileName(fileName.toStdString());
2300 writer->SetInput(mSlicerManagers[index]->GetImage());
2302 // Check on transform and prompt user
2303 writer->SetSaveTransform(false);
2305 for(int i=0; i<4; i++)
2306 for(int j=0; j<4; j++) {
2307 double elt = mSlicerManagers[index]->GetImage()->GetTransform()->GetMatrix()->GetElement(i,j);
2314 QString warning = "The image has an associated linear transform. Do you want to save it along?";
2315 QMessageBox msgBox(QMessageBox::Warning, tr("Save transform"), warning, 0, this);
2316 msgBox.addButton(tr("Yes"), QMessageBox::AcceptRole);
2317 msgBox.addButton(tr("No"), QMessageBox::RejectRole);
2318 if (msgBox.exec() == QMessageBox::AcceptRole)
2319 writer->SetSaveTransform(true);
2323 QApplication::restoreOverrideCursor();
2324 if (writer->GetLastError().size()) {
2325 QString error = "Saving did not succeed\n";
2326 error += writer->GetLastError().c_str();
2327 QMessageBox::information(this,tr("Saving Problem"),error);
2331 QString error = fileformat.c_str();
2332 if (error.isEmpty())
2333 error += "no file format specified !";
2335 error += " format unknown !!!\n";
2336 QMessageBox::information(this,tr("Saving Problem"),error);
2341 //------------------------------------------------------------------------------
2343 //------------------------------------------------------------------------------
2344 void vvMainWindow::SaveCurrentState()
2346 QString Extensions = "XML Files(*.xml)";
2347 QString fileName = QFileDialog::getSaveFileName(this,
2348 tr("Save Current Window State"),
2352 SaveCurrentStateAs(fileName.toStdString());
2354 //------------------------------------------------------------------------------
2356 //------------------------------------------------------------------------------
2357 void vvMainWindow::SaveCurrentStateAs(const std::string& stateFile)
2359 vvSaveState save_state;
2360 save_state.Run(this, stateFile);
2363 //------------------------------------------------------------------------------
2364 void vvMainWindow::ReadSavedState()
2366 QString Extensions = "XML Files(*.xml)";
2367 QString fileName = QFileDialog::getOpenFileName(this,
2368 tr("Load Window State"),
2372 ReadSavedStateFile(fileName.toStdString());
2374 //------------------------------------------------------------------------------
2376 //------------------------------------------------------------------------------
2377 void vvMainWindow::ReadSavedStateFile(const std::string& stateFile)
2379 vvReadState read_state;
2380 read_state.Run(this, stateFile);
2382 //------------------------------------------------------------------------------
2384 //------------------------------------------------------------------------------
2385 void vvMainWindow::LinkAllImages()
2387 linkPanel->linkAll();
2390 //------------------------------------------------------------------------------
2391 void vvMainWindow::AddLink(QString image1,QString image2)
2393 unsigned int sm1 = 0;
2394 unsigned int sm2 = 0;
2396 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
2397 if (image1.toStdString() == mSlicerManagers[i]->GetId()) {
2398 mSlicerManagers[i]->AddLink(image2.toStdString());
2401 if (image2.toStdString() == mSlicerManagers[i]->GetId()) {
2402 mSlicerManagers[i]->AddLink(image1.toStdString());
2407 if (linkPanel->isLinkAll()) {
2408 emit UpdateLinkedNavigation(mSlicerManagers[sm1]->GetId(), mSlicerManagers[mCurrentPickedImageIndex], mSlicerManagers[mCurrentPickedImageIndex]->GetSlicer(0));
2409 emit UpdateLinkedNavigation(mSlicerManagers[sm2]->GetId(), mSlicerManagers[mCurrentPickedImageIndex], mSlicerManagers[mCurrentPickedImageIndex]->GetSlicer(0));
2411 emit UpdateLinkedNavigation(mSlicerManagers[sm2]->GetId(), mSlicerManagers[sm1], mSlicerManagers[sm1]->GetSlicer(0));
2415 //------------------------------------------------------------------------------
2418 //------------------------------------------------------------------------------
2419 void vvMainWindow::RemoveLink(QString image1,QString image2)
2421 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
2422 if (image1.toStdString() == mSlicerManagers[i]->GetId()) {
2423 mSlicerManagers[i]->RemoveLink(image2.toStdString());
2425 if (image2.toStdString() == mSlicerManagers[i]->GetId()) {
2426 mSlicerManagers[i]->RemoveLink(image1.toStdString());
2430 //------------------------------------------------------------------------------
2432 //------------------------------------------------------------------------------
2433 void vvMainWindow::ChangeImageWithIndexOffset(vvSlicerManager *sm, int slicer, int offset)
2435 if(mSlicerManagers.size()==1)
2439 while(sm != mSlicerManagers[index])
2441 index = (index+offset+mSlicerManagers.size()) % mSlicerManagers.size();
2443 QTreeWidgetItem* item = GetItemFromSlicerManager(mSlicerManagers[index]);
2444 item->setData(slicer+1,Qt::CheckStateRole,2); //change checkbox
2445 CurrentImageChanged(mSlicerManagers[index]->GetId()); //select new image
2446 DisplayChanged(item,slicer+1);
2448 //------------------------------------------------------------------------------
2450 void vvMainWindow::HorizontalSliderMoved(int value,int column, int slicer_index)
2452 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
2453 if (DataTree->topLevelItem(i)->data(column,Qt::CheckStateRole).toInt() > 1) {
2454 for (int j = 0; j < 4; j++) {
2455 mSlicerManagers[i]->SetTSliceInSlicer(value,j);
2456 //if (mSlicerManagers[i]->GetSlicer(j)->GetImageActor()->GetVisibility())
2457 //UpdateTSlice(j,value);
2459 mSlicerManagers[i]->GetSlicer(slicer_index)->Render();
2464 //------------------------------------------------------------------------------
2467 //------------------------------------------------------------------------------
2468 void vvMainWindow::NOHorizontalSliderMoved()
2470 // if (mCurrentTime == NOHorizontalSlider->value()) return;
2471 HorizontalSliderMoved(NOHorizontalSlider->value(),COLUMN_UL_VIEW,0);
2472 // mCurrentTime = NOHorizontalSlider->value();
2474 //------------------------------------------------------------------------------
2477 //------------------------------------------------------------------------------
2478 void vvMainWindow::NEHorizontalSliderMoved()
2480 // if (mCurrentTime == NEHorizontalSlider->value()) return;
2481 HorizontalSliderMoved(NEHorizontalSlider->value(),COLUMN_UR_VIEW,1);
2482 // mCurrentTime = NEHorizontalSlider->value();
2484 //------------------------------------------------------------------------------
2487 //------------------------------------------------------------------------------
2488 void vvMainWindow::SOHorizontalSliderMoved()
2490 // if (mCurrentTime == SOHorizontalSlider->value()) return;
2491 HorizontalSliderMoved(SOHorizontalSlider->value(),COLUMN_DL_VIEW,2);
2492 // mCurrentTime = SOHorizontalSlider->value();
2494 //------------------------------------------------------------------------------
2497 //------------------------------------------------------------------------------
2498 void vvMainWindow::SEHorizontalSliderMoved()
2500 // if (mCurrentTime == SEHorizontalSlider->value()) return;
2501 HorizontalSliderMoved(SEHorizontalSlider->value(),COLUMN_DR_VIEW,3);
2502 // mCurrentTime = SEHorizontalSlider->value();
2504 //------------------------------------------------------------------------------
2506 //------------------------------------------------------------------------------
2507 void vvMainWindow::NOVerticalSliderChanged()
2509 static int value=-1;
2510 if (value == NOVerticalSlider->value()) return;
2511 else value = NOVerticalSlider->value();
2512 // int value = NOVerticalSlider->value();
2513 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
2514 if (DataTree->topLevelItem(i)->data(COLUMN_UL_VIEW,Qt::CheckStateRole).toInt() > 1) {
2515 if (mSlicerManagers[i]->GetSlicer(0)->GetSlice() != value) {
2516 mSlicerManagers[i]->GetSlicer(0)->SetSlice(value);
2517 mSlicerManagers[i]->VerticalSliderHasChanged(0, value);
2519 // If nor Update/Render -> slider not work
2520 // only render = ok navigation, but for contour Update needed but slower ?
2522 mSlicerManagers[i]->UpdateSlice(0); // <-- DS add this. Not too much update ? YES. but needed for ImageContour ...
2523 //mSlicerManagers[i]->GetSlicer(0)->Render(); // <-- DS add this, needed for contour, seems ok ? not too slow ?
2529 //------------------------------------------------------------------------------
2532 //------------------------------------------------------------------------------
2533 void vvMainWindow::NEVerticalSliderChanged()
2535 static int value=-1;
2536 if (value == NEVerticalSlider->value()) return;
2537 else value = NEVerticalSlider->value();
2538 // int value = NEVerticalSlider->value();
2539 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
2540 if (DataTree->topLevelItem(i)->data(COLUMN_UR_VIEW,Qt::CheckStateRole).toInt() > 1) {
2541 if (mSlicerManagers[i]->GetSlicer(1)->GetSlice() != value) {
2542 mSlicerManagers[i]->GetSlicer(1)->SetSlice(value);
2543 mSlicerManagers[i]->VerticalSliderHasChanged(1, value);
2544 mSlicerManagers[i]->UpdateSlice(1);
2545 //mSlicerManagers[i]->GetSlicer(1)->Render(); // <-- DS add this, needed for contour, seems ok ? not too slow ?
2551 //------------------------------------------------------------------------------
2554 //------------------------------------------------------------------------------
2555 void vvMainWindow::SOVerticalSliderChanged()
2557 static int value=-1;
2558 if (value == SOVerticalSlider->value()) return;
2559 else value = SOVerticalSlider->value();
2560 //int value = SOVerticalSlider->value();
2561 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
2562 if (DataTree->topLevelItem(i)->data(COLUMN_DL_VIEW,Qt::CheckStateRole).toInt() > 1) {
2563 if (mSlicerManagers[i]->GetSlicer(2)->GetSlice() != value) {
2564 mSlicerManagers[i]->GetSlicer(2)->SetSlice(value);
2565 mSlicerManagers[i]->VerticalSliderHasChanged(2, value);
2566 mSlicerManagers[i]->UpdateSlice(2);
2567 //mSlicerManagers[i]->GetSlicer(2)->Render(); // <-- DS add this, needed for contour, seems ok ? not too slow ?
2569 // else { DD("avoid SOVerticalSlider slicer update"); }
2574 //------------------------------------------------------------------------------
2577 //------------------------------------------------------------------------------
2578 void vvMainWindow::SEVerticalSliderChanged()
2580 static int value=-1;
2581 if (value == SEVerticalSlider->value()) return;
2582 else value = SEVerticalSlider->value();
2583 // int value = SEVerticalSlider->value();
2584 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
2585 if (DataTree->topLevelItem(i)->data(COLUMN_DR_VIEW,Qt::CheckStateRole).toInt() > 1) {
2586 if (mSlicerManagers[i]->GetSlicer(3)->GetSlice() != value) {
2587 mSlicerManagers[i]->GetSlicer(3)->SetSlice(value);
2588 mSlicerManagers[i]->VerticalSliderHasChanged(3, value);
2589 mSlicerManagers[i]->UpdateSlice(3);
2590 //mSlicerManagers[i]->GetSlicer(3)->Render(); // <-- DS add this, needed for contour, seems ok ? not too slow ?
2596 //------------------------------------------------------------------------------
2599 //------------------------------------------------------------------------------
2600 void vvMainWindow::UpdateSlice(int slicer, int slice)
2602 // DD("vvMainWindow::UpdateSlice");
2606 // if (slice != NOVerticalSlider->value())
2607 NOVerticalSlider->setValue(slice);
2610 NEVerticalSlider->setValue(slice);
2613 SOVerticalSlider->setValue(slice);
2616 SEVerticalSlider->setValue(slice);
2620 // DD("vvMainWindow:UpdateSlice END");
2622 //------------------------------------------------------------------------------
2625 //------------------------------------------------------------------------------
2626 void vvMainWindow::UpdateTSlice(int slicer, int slice)
2630 NOHorizontalSlider->setValue(slice);
2633 NEHorizontalSlider->setValue(slice);
2636 SOHorizontalSlider->setValue(slice);
2639 SEHorizontalSlider->setValue(slice);
2643 //------------------------------------------------------------------------------
2646 //------------------------------------------------------------------------------
2647 void vvMainWindow::UpdateSliceRange(int slicer, int min, int max, int tmin, int tmax)
2649 int position = int((min+max)/2);
2651 NOVerticalSlider->setValue(position);
2652 NOVerticalSlider->setRange(min,max);
2653 NOHorizontalSlider->setRange(tmin,tmax);
2654 } else if (slicer == 1) {
2655 NEVerticalSlider->setValue(position);
2656 NEVerticalSlider->setRange(min,max);
2657 NEHorizontalSlider->setRange(tmin,tmax);
2658 } else if (slicer == 2) {
2659 SOVerticalSlider->setValue(position);
2660 SOVerticalSlider->setRange(min,max);
2661 SOHorizontalSlider->setRange(tmin,tmax);
2662 } else if (slicer == 3) {
2663 SEVerticalSlider->setValue(position);
2664 SEVerticalSlider->setRange(min,max);
2665 SEHorizontalSlider->setRange(tmin,tmax);
2668 //------------------------------------------------------------------------------
2671 //------------------------------------------------------------------------------
2672 void vvMainWindow::SaveNOScreenshot()
2674 SaveScreenshot(NOViewWidget);
2676 //------------------------------------------------------------------------------
2679 //------------------------------------------------------------------------------
2680 void vvMainWindow::SaveNEScreenshot()
2682 SaveScreenshot(NEViewWidget);
2684 //------------------------------------------------------------------------------
2687 //------------------------------------------------------------------------------
2688 void vvMainWindow::SaveSOScreenshot()
2690 SaveScreenshot(SOViewWidget);
2692 //------------------------------------------------------------------------------
2695 //------------------------------------------------------------------------------
2696 void vvMainWindow::SaveSEScreenshot()
2698 SaveScreenshot(SEViewWidget);
2700 //------------------------------------------------------------------------------
2703 //------------------------------------------------------------------------------
2704 void vvMainWindow::SaveScreenshotAllSlices()
2706 QVTKWidget *widget = NOViewWidget;
2708 int index = 0;// GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
2709 vvSlicerManager * SM = mSlicerManagers[index];
2710 vvImage * image = SM->GetImage();
2711 vvSlicer * slicer = SM->GetSlicer(0);
2712 int orientation = slicer->GetOrientation();
2713 int nbSlices = image->GetSize()[orientation];
2714 vtkSmartPointer<vtkRenderWindow> renderWindow = widget->GetRenderWindow();
2716 // Select filename base
2717 QString filename = QFileDialog::getSaveFileName(this,
2718 tr("Save As (filename will be completed by slice number)"),
2719 itksys::SystemTools::GetFilenamePath(mSlicerManagers[index]->GetFileName()).c_str(),
2720 "Images( *.png);;Images( *.jpg)");
2723 for(int i=0; i<nbSlices; i++) {
2725 slicer->SetSlice(i); // -> change the slice of the current slicer
2726 SM->UpdateSlice(0); // --> this one emit UpdateSlice
2727 QCoreApplication::flush(); // -> needed to force display of contours
2730 vtkSmartPointer<vtkWindowToImageFilter> windowToImageFilter = vtkSmartPointer<vtkWindowToImageFilter>::New();
2731 windowToImageFilter->SetInput(renderWindow);
2732 windowToImageFilter->SetMagnification(1);
2733 windowToImageFilter->SetInputBufferTypeToRGBA(); //also record the alpha (transparency) channel
2734 windowToImageFilter->Update();
2736 vtkSmartPointer<vtkPNGWriter> writer = vtkSmartPointer<vtkPNGWriter>::New();
2737 std::string fn = itksys::SystemTools::GetFilenameWithoutLastExtension(filename.toStdString());
2738 std::string num = clitk::toString(i);
2739 if (i<10) num = "0"+num;
2740 if (i<100) num = "0"+num;
2741 if (i<1000) num = "0"+num;
2743 fn = itksys::SystemTools::GetFilenamePath(filename.toStdString()) + "/"+ fn
2744 + "_" + num + itksys::SystemTools::GetFilenameLastExtension(filename.toStdString());
2745 writer->SetFileName(fn.c_str());
2746 writer->SetInput(windowToImageFilter->GetOutput());
2750 //------------------------------------------------------------------------------
2753 //------------------------------------------------------------------------------
2754 void vvMainWindow::SaveScreenshot(QVTKWidget *widget)
2756 QString Extensions = "Images( *.png);;";
2757 Extensions += "Images( *.jpg);;";
2758 Extensions += "Images( *.bmp);;";
2759 Extensions += "Images( *.tif);;";
2760 Extensions += "Images( *.ppm)";
2761 #if defined(VTK_USE_FFMPEG_ENCODER) || defined(VTK_USE_VIDEO_FOR_WINDOWS)
2762 Extensions += ";;Video( *.avi)";
2764 #ifdef VTK_USE_MPEG2_ENCODER
2765 Extensions += ";;Video( *.mpg)";
2767 #ifdef CLITK_EXPERIMENTAL
2768 Extensions += ";;Video( *.gif)";
2771 int smIndex=GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
2772 QString fileName = QFileDialog::getSaveFileName(this,
2774 itksys::SystemTools::GetFilenamePath(mSlicerManagers[smIndex]->GetFileName()).c_str(),
2777 if (!fileName.isEmpty()) {
2778 vtkSmartPointer<vtkWindowToImageFilter> w2i = vtkSmartPointer<vtkWindowToImageFilter>::New();
2779 w2i->SetInput(widget->GetRenderWindow());
2781 vtkImageData *image = w2i->GetOutput();
2783 std::string ext(itksys::SystemTools::GetFilenameLastExtension(fileName.toStdString()));
2786 vtkImageWriter *imgwriter = NULL;
2788 imgwriter = vtkBMPWriter::New();
2789 else if (ext==".tif")
2790 imgwriter = vtkTIFFWriter::New();
2791 else if (ext==".ppm")
2792 imgwriter = vtkPNMWriter::New();
2793 else if (ext==".png")
2794 imgwriter = vtkPNGWriter::New();
2795 else if (ext==".jpg")
2796 imgwriter = vtkJPEGWriter::New();
2798 // Snapshot image if not null
2799 if(imgwriter!=NULL) {
2800 imgwriter->SetInput(image);
2801 imgwriter->SetFileName(fileName.toStdString().c_str());
2807 vtkGenericMovieWriter *vidwriter = NULL;
2808 #if CLITK_EXPERIMENTAL == 1
2810 vvAnimatedGIFWriter *gif = vvAnimatedGIFWriter::New();
2815 int fps = QInputDialog::getInteger(this, tr("Number of frames per second"),
2816 tr("FPS:"), 5, 0, 1000, 1, &ok);
2821 int loops = QInputDialog::getInteger(this, tr("Loops"),
2822 tr("Number of loops (0 means infinite):"), 0, 0, 1000000000, 1, &ok);
2824 gif->SetLoops(loops);
2827 QString msg = "Would you like to activate dithering?";
2828 QMessageBox msgBox(QMessageBox::Question, tr("Dithering"),msg, 0, this);
2829 msgBox.addButton(tr("Yes"), QMessageBox::AcceptRole);
2830 msgBox.addButton(tr("No"), QMessageBox::RejectRole);
2831 gif->SetDither(msgBox.exec() == QMessageBox::AcceptRole);
2834 #ifdef VTK_USE_VIDEO_FOR_WINDOWS
2836 vtkAVIWriter *mpg = vtkAVIWriter::New();
2840 int fps = QInputDialog::getInteger(this, tr("Number of frames per second"),
2841 tr("FPS:"), 5, 0, 1024, 1, &ok);
2847 #ifdef VTK_USE_FFMPEG_ENCODER
2849 vtkFFMPEGWriter *mpg = vtkFFMPEGWriter::New();
2853 int fps = QInputDialog::getInteger(this, tr("Number of frames per second"),
2854 tr("FPS:"), 5, 0, 1024, 1, &ok);
2858 mpg->SetBitRateTolerance(int(ceil(12.0*1024*1024/fps)));
2861 #ifdef VTK_USE_MPEG2_ENCODER
2863 vtkMPEG2Writer *mpg = vtkMPEG2Writer::New();
2868 // Take video if not null
2869 if(vidwriter!=NULL){
2870 vidwriter->SetInput(image);
2871 vidwriter->SetFileName(fileName.toStdString().c_str());
2873 vvImage * vvImg = mSlicerManagers[smIndex]->GetImage();
2874 int nSlice = vvImg->GetVTKImages().size();
2875 for(int i=0; i<nSlice; i++) {
2876 mSlicerManagers[smIndex]->SetNextTSlice(0);
2877 vtkSmartPointer<vtkWindowToImageFilter> w2i = vtkSmartPointer<vtkWindowToImageFilter>::New();
2878 w2i->SetInput(widget->GetRenderWindow());
2880 vidwriter->SetInput(w2i->GetOutput());
2884 vidwriter->Delete();
2888 QMessageBox::information(this,tr("Problem saving screenshot !"),tr("Cannot save image.\nPlease set a file extension !!!"));
2891 //------------------------------------------------------------------------------
2894 //------------------------------------------------------------------------------
2895 void vvMainWindow::GoToCursor()
2897 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
2898 for (int column = 1; column < 5; column++) {
2899 if (DataTree->selectedItems()[0]->data(column,Qt::CheckStateRole).toInt() > 1) {
2900 double* cursorPos = mSlicerManagers[index]->GetSlicer(column-1)->GetCursorPosition();
2901 mSlicerManagers[index]->GetSlicer(column-1)->SetCurrentPosition(
2902 cursorPos[0],cursorPos[1],cursorPos[2],cursorPos[3]);
2903 mSlicerManagers[index]->UpdateViews(1,column-1);
2904 mSlicerManagers[index]->UpdateLinked(column-1);
2909 //------------------------------------------------------------------------------
2911 //------------------------------------------------------------------------------
2912 void vvMainWindow::PlayPause()
2916 playButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/player_play.png")));
2920 int image_number=DataTree->topLevelItemCount();
2922 for (int i=0; i<image_number; i++)
2923 if (mSlicerManagers[i]->GetImage()->GetVTKImages().size() > 1) {
2929 playButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/player_pause.png")));
2930 QTimer::singleShot(1000/mFrameRate, this, SLOT(PlayNext()));
2934 //------------------------------------------------------------------------------
2936 //------------------------------------------------------------------------------
2937 void vvMainWindow::PlayNext()
2939 if (playMode && !this->isHidden()) {
2940 int image_number=DataTree->topLevelItemCount();
2941 ///Only play one slicer per SM, and only if the SM is being displayed
2942 for (int i=0; i<image_number; i++)
2943 for (int j=0; j<4; j++)
2944 if (mSlicerManagers[i]->GetImage()->GetVTKImages().size() > 1 &&
2945 DataTree->topLevelItem(i)->data(j+1,Qt::CheckStateRole).toInt() > 0) {
2946 mSlicerManagers[i]->SetNextTSlice(j);
2949 QTimer::singleShot(1000/mFrameRate, this, SLOT(PlayNext()));
2952 //------------------------------------------------------------------------------
2954 void vvMainWindow::ShowLastImage()
2956 if (mSlicerManagers.size() > 1) {
2957 QTreeWidgetItem * item=DataTree->topLevelItem(DataTree->topLevelItemCount()-1);
2958 CurrentImageChanged(mSlicerManagers.back()->GetId()); //select new image
2959 item->setData(1,Qt::CheckStateRole,2); //show the new image in the first panel
2960 DisplayChanged(item,1);
2964 //------------------------------------------------------------------------------
2965 void vvMainWindow::UpdateRenderWindows()
2967 if (NOViewWidget->GetRenderWindow()) NOViewWidget->GetRenderWindow()->Render();
2968 if (NEViewWidget->GetRenderWindow()) NEViewWidget->GetRenderWindow()->Render();
2969 if (SOViewWidget->GetRenderWindow()) SOViewWidget->GetRenderWindow()->Render();
2970 if (SEViewWidget->GetRenderWindow()) SEViewWidget->GetRenderWindow()->Render();
2972 //------------------------------------------------------------------------------
2974 //------------------------------------------------------------------------------
2975 void vvMainWindow::SegmentationOnCurrentImage()
2977 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
2979 vvSegmentationDialog segmentation;
2980 segmentation.SetImage(mSlicerManagers[index]->GetSlicer(0)->GetImage());
2981 segmentation.exec();
2983 //------------------------------------------------------------------------------
2985 void vvMainWindow::SurfaceViewerLaunch()
2987 vvSurfaceViewerDialog surfaceViewer;
2988 surfaceViewer.exec();
2990 //------------------------------------------------------------------------------
2993 //------------------------------------------------------------------------------
2994 int vvMainWindow::GetImageDuplicateFilenameNumber(std::string filename)
2997 for(unsigned int l=0; l<mSlicerManagers.size(); l++) {
2998 vvSlicerManager * v = mSlicerManagers[l];
2999 if (v->GetBaseFileName() ==
3000 vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(filename))) {
3001 number = std::max(number, v->GetBaseFileNameNumber()+1);
3006 //------------------------------------------------------------------------------
3009 //------------------------------------------------------------------------------
3010 vvSlicerManager* vvMainWindow::AddImage(vvImage::Pointer image,std::string filename)
3012 // Change filename if another image exist with the same name
3013 int number = GetImageDuplicateFilenameNumber(filename);
3015 // Create new SliceManager
3016 vvSlicerManager* slicer_manager = new vvSlicerManager(4);
3017 slicer_manager->SetImage(image);//, IMAGE, number);
3018 // filename = filename+"_"+clitk::toString(number);
3019 slicer_manager->SetFilename(filename, number);
3020 mSlicerManagers.push_back(slicer_manager);
3022 //create an item in the tree with good settings
3023 QTreeWidgetItem *item = new QTreeWidgetItem();
3024 item->setData(0,Qt::UserRole,slicer_manager->GetFileName().c_str());//files[i].c_str());
3025 item->setData(1,Qt::UserRole,tr("image"));
3026 item->setData(COLUMN_IMAGE_NAME,Qt::DisplayRole,slicer_manager->GetFileName().c_str());//filename.c_str());
3027 qApp->processEvents();
3029 for (int j = 1; j <= 4; j++) item->setData(j,Qt::CheckStateRole,1);
3031 //Create the buttons for reload and close
3032 qApp->processEvents();
3033 QTreePushButton* cButton = new QTreePushButton;
3034 cButton->setItem(item);
3035 cButton->setColumn(COLUMN_CLOSE_IMAGE);
3036 cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png")));
3037 connect(cButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
3038 this,SLOT(CloseImage(QTreeWidgetItem*, int)));
3040 QTreePushButton* rButton = new QTreePushButton;
3041 rButton->setItem(item);
3042 rButton->setColumn(COLUMN_RELOAD_IMAGE);
3043 rButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/rotateright.png")));
3044 rButton->setEnabled(0);
3045 connect(rButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
3046 this,SLOT(ReloadImage(QTreeWidgetItem*, int)));
3048 DataTree->addTopLevelItem(item);
3049 DataTree->setItemWidget(item, COLUMN_CLOSE_IMAGE, cButton);
3050 DataTree->setItemWidget(item, COLUMN_RELOAD_IMAGE, rButton);
3052 //set the id of the image
3053 QString id = slicer_manager->GetFileName().c_str() + QString::number(mSlicerManagers.size()-1);
3054 item->setData(COLUMN_IMAGE_NAME,Qt::UserRole,id.toStdString().c_str());
3055 mSlicerManagers.back()->SetId(id.toStdString());
3057 linkPanel->addImage(slicer_manager->GetFileName().c_str()// filename
3058 , id.toStdString());
3060 connect(mSlicerManagers.back(), SIGNAL(currentImageChanged(std::string)),
3061 this, SLOT(CurrentImageChanged(std::string)));
3062 connect(mSlicerManagers.back(), SIGNAL(currentPickedImageChanged(std::string)),
3063 this, SLOT(CurrentPickedImageChanged(std::string)));
3064 connect(mSlicerManagers.back(), SIGNAL(UpdatePosition(int, double, double, double, double, double, double, double)),
3065 this, SLOT(MousePositionChanged(int,double, double, double, double, double, double, double)));
3066 connect(mSlicerManagers.back(), SIGNAL(UpdateVector(int, double, double, double, double)),
3067 this, SLOT(VectorChanged(int,double,double,double, double)));
3068 connect(mSlicerManagers.back(), SIGNAL(UpdateOverlay(int, double, double)),
3069 this, SLOT(OverlayChanged(int,double,double)));
3070 connect(mSlicerManagers.back(), SIGNAL(UpdateFusion(int, double)),
3071 this, SLOT(FusionChanged(int,double)));
3072 connect(mSlicerManagers.back(), SIGNAL(WindowLevelChanged()),
3073 this,SLOT(WindowLevelChanged()));
3074 connect(mSlicerManagers.back(), SIGNAL(UpdateSlice(int,int)),
3075 this,SLOT(UpdateSlice(int,int)));
3076 connect(mSlicerManagers.back(), SIGNAL(UpdateTSlice(int, int)),
3077 this,SLOT(UpdateTSlice(int, int)));
3078 connect(mSlicerManagers.back(), SIGNAL(UpdateSliceRange(int,int,int,int,int)),
3079 this,SLOT(UpdateSliceRange(int,int,int,int,int)));
3080 connect(mSlicerManagers.back(), SIGNAL(UpdateLinkManager(std::string,int,double,double,double,int)),
3081 this,SLOT(UpdateLinkManager(std::string,int,double,double,double,int)));
3082 connect(mSlicerManagers.back(), SIGNAL(UpdateLinkedNavigation(std::string,vvSlicerManager*,vvSlicer*)),
3083 this,SLOT(UpdateLinkedNavigation(std::string,vvSlicerManager*,vvSlicer*)));
3084 connect(mSlicerManagers.back(), SIGNAL(ChangeImageWithIndexOffset(vvSlicerManager*,int,int)),
3085 this,SLOT(ChangeImageWithIndexOffset(vvSlicerManager*,int,int)));
3086 connect(mSlicerManagers.back(), SIGNAL(LandmarkAdded()),landmarksPanel,SLOT(AddPoint()));
3088 qApp->processEvents();
3092 qApp->processEvents();
3096 return slicer_manager;
3098 //------------------------------------------------------------------------------
3101 //------------------------------------------------------------------------------
3102 void vvMainWindow::UpdateCurrentSlicer()
3105 if (DataTree->selectedItems().size() > 0) {
3106 index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
3108 mSlicerManagerCurrentIndex = index;
3110 //------------------------------------------------------------------------------