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 #if CLITK_PRIVATE_FEATURES
104 #define EXTENSIONS "Images ( *.bmp *.png *.jpeg *.jpg *.tif *.mhd *.mha *.hdr *.vox *.his *.xdr *.SCAN *.nii *.nrrd *.nhdr *.usf)"
106 #define EXTENSIONS "Images ( *.bmp *.png *.jpeg *.jpg *.tif *.mhd *.mha *.hdr *.vox *.his *.xdr *.SCAN *.nii *.nrrd *.nhdr)"
110 0,Qt::UserRole full filename
111 1,Qt::CheckStateRole checkbutton UL View
112 1,Qt::UserRole overlay, fusion or vector
113 2,Qt::CheckStateRole checkbutton UR View
114 3,Qt::CheckStateRole checkbutton DL View
115 4,Qt::CheckStateRole checkbutton DR View
117 5,Qt::UserRole mSlicerManager id*/
119 //------------------------------------------------------------------------------
120 vvMainWindow::vvMainWindow():vvMainWindowBase()
122 setupUi(this); // this sets up the GUI
125 mMenuTools = menuTools;
126 // mMenuSegmentation = menuSegmentation;
127 mContextMenu = &contextMenu;
128 mMenuExperimentalTools = menuExperimental;
131 mCurrentSelectedImageId = "";
132 mCurrentPickedImageId = "";
133 mCurrentPickedImageIndex = 0;
135 //Init the contextMenu
136 this->setContextMenuPolicy(Qt::CustomContextMenu);
137 contextActions.resize(0);
138 QAction* actionOpen_new_image = contextMenu.addAction(QIcon(QString::fromUtf8(":/common/icons/fileopen.png")),
139 tr("O&pen new Image"));
140 actionOpen_new_image->setShortcut(QKeySequence(tr("Ctrl+O")));
141 connect(actionOpen_new_image,SIGNAL(triggered()),this,SLOT(OpenImages()));
142 contextActions.push_back(actionOpen_new_image);
143 contextMenu.addSeparator();
145 QAction* actionClose_Image = contextMenu.addAction(QIcon(QString::fromUtf8(":/common/icons/exit.png")),
146 tr("Close Current Image"));
147 connect(actionClose_Image,SIGNAL(triggered()),this,SLOT(CloseImage()));
148 contextActions.push_back(actionClose_Image);
150 QAction* actionReload_image = contextMenu.addAction(QIcon(QString::fromUtf8(":/common/icons/rotateright.png")),
151 tr("Reload Current Image"));
152 connect(actionReload_image,SIGNAL(triggered()),this,SLOT(ReloadImage()));
153 contextActions.push_back(actionReload_image);
155 QAction* actionSave_image = contextMenu.addAction(QIcon(QString::fromUtf8(":/common/icons/filesave.png")),
156 tr("Save Current Image"));
157 connect(actionSave_image,SIGNAL(triggered()),this,SLOT(SaveAs()));
158 contextActions.push_back(actionSave_image);
160 QAction* actionSave_state = contextMenu.addAction(QIcon(QString::fromUtf8(":/common/icons/filesave.png")),
161 tr("Save Current State"));
162 connect(actionSave_state,SIGNAL(triggered()),this,SLOT(SaveCurrentState()));
163 contextActions.push_back(actionSave_state);
165 QAction* actionRead_state = contextMenu.addAction(QIcon(QString::fromUtf8(":/common/icons/filesave.png")),
166 tr("Read Saved State"));
167 connect(actionRead_state,SIGNAL(triggered()),this,SLOT(ReadSavedState()));
168 contextActions.push_back(actionRead_state);
170 contextMenu.addSeparator();
172 contextMenu.addAction(actionAdd_VF_to_current_Image);
173 contextActions.push_back(actionAdd_VF_to_current_Image);
175 //QAction* actionAdd_Overlay_to_current_Image = menuOverlay->addAction(QIcon(QString::fromUtf8(":/common/icons/GPSup.png")),
176 // tr("Add overlay image to current image"));
177 contextMenu.addAction(actionAdd_overlay_image_to_current_image);
178 contextActions.push_back(actionAdd_overlay_image_to_current_image);
180 contextMenu.addAction(actionAdd_fusion_image);
181 contextActions.push_back(actionAdd_fusion_image);
183 contextMenu.addSeparator();
184 QAction* actionResetMatrix = contextMenu.addAction(QIcon(QString::fromUtf8(":/common/icons/identity.png")),
185 tr("Reset transformation to identity"));
186 connect(actionResetMatrix, SIGNAL(triggered()), this,SLOT(ResetTransformationToIdentity()));
190 QMenu * m = new QMenu(menubar);
192 // m->setObjectName(QString::fromUtf8("TOTOTO"));
193 contextMenu.addMenu(m);
194 QAction * a = m->addAction(QIcon(QString::fromUtf8(":/common/icons/GPSup.png")),
196 QAction * b = m->addAction(QIcon(QString::fromUtf8(":/common/icons/GPSup.png")),
200 connect(a,SIGNAL(triggered()),this,SLOT(AddFusionImage()));
204 mSlicerManagers.resize(0);
214 header.append("Name");
216 DataTree->setHeaderLabels(header);
217 DataTree->resizeColumnToContents(COLUMN_TREE);
218 DataTree->resizeColumnToContents(COLUMN_UL_VIEW);
219 DataTree->resizeColumnToContents(COLUMN_UR_VIEW);
220 DataTree->resizeColumnToContents(COLUMN_DL_VIEW);
221 DataTree->resizeColumnToContents(COLUMN_DR_VIEW);
222 DataTree->resizeColumnToContents(COLUMN_CLOSE_IMAGE);
223 DataTree->resizeColumnToContents(COLUMN_RELOAD_IMAGE);
224 DataTree->resizeColumnToContents(COLUMN_IMAGE_NAME);
227 documentation = new vvDocumentation();
228 help_dialog = new vvHelpDialog();
229 dicomSeriesSelector = new vvDicomSeriesSelector();
231 inverseButton->setEnabled(0);
232 actionAdd_overlay_image_to_current_image->setEnabled(0);
233 actionSave_As->setEnabled(0);
234 actionAdd_VF_to_current_Image->setEnabled(0);
235 actionAdd_fusion_image->setEnabled(0);
238 verticalSliders.push_back(NOVerticalSlider);
239 verticalSliders.push_back(NEVerticalSlider);
240 verticalSliders.push_back(SOVerticalSlider);
241 verticalSliders.push_back(SEVerticalSlider);
243 for (int i =0; i < 4; i++)
244 verticalSliders[i]->hide();
246 horizontalSliders.push_back(NOHorizontalSlider);
247 horizontalSliders.push_back(NEHorizontalSlider);
248 horizontalSliders.push_back(SOHorizontalSlider);
249 horizontalSliders.push_back(SEHorizontalSlider);
251 for (int i =0; i < 4; i++)
252 horizontalSliders[i]->hide();
255 connect(NOVerticalSlider,SIGNAL(valueChanged(int)),this,SLOT(NOVerticalSliderChanged()));
256 connect(NEVerticalSlider,SIGNAL(valueChanged(int)),this,SLOT(NEVerticalSliderChanged()));
257 connect(SOVerticalSlider,SIGNAL(valueChanged(int)),this,SLOT(SOVerticalSliderChanged()));
258 connect(SEVerticalSlider,SIGNAL(valueChanged(int)),this,SLOT(SEVerticalSliderChanged()));
260 connect(NOHorizontalSlider,SIGNAL(valueChanged(int)),this,SLOT(NOHorizontalSliderMoved()));
261 connect(NEHorizontalSlider,SIGNAL(valueChanged(int)),this,SLOT(NEHorizontalSliderMoved()));
262 connect(SOHorizontalSlider,SIGNAL(valueChanged(int)),this,SLOT(SOHorizontalSliderMoved()));
263 connect(SEHorizontalSlider,SIGNAL(valueChanged(int)),this,SLOT(SEHorizontalSliderMoved()));
266 connect(actionCompute_mid_position_image,SIGNAL(triggered()),this,SLOT(ComputeMidPosition()));
267 connect(actionDeformable_Registration,SIGNAL(triggered()),this,SLOT(ComputeDeformableRegistration()));
268 connect(actionWarp_image_with_vector_field,SIGNAL(triggered()),this,SLOT(WarpImage()));
269 connect(actionLoad_images,SIGNAL(triggered()),this,SLOT(OpenImages()));
270 connect(actionOpen_Dicom,SIGNAL(triggered()),this,SLOT(OpenDicom()));
271 connect(actionOpen_Dicom_Struct,SIGNAL(triggered()),this,SLOT(OpenDCStructContour()));
272 connect(actionOpen_VTK_contour,SIGNAL(triggered()),this,SLOT(OpenVTKContour()));
273 connect(actionOpen_Multiple_Images_As_One,SIGNAL(triggered()),this,SLOT(MergeImages()));
274 connect(actionSlice_Image_As_Multiple_Images,SIGNAL(triggered()),this,SLOT(SliceImages()));
275 connect(actionOpen_Image_With_Time,SIGNAL(triggered()),this,SLOT(OpenImageWithTime()));
276 connect(actionMerge_images_as_n_dim_t, SIGNAL(triggered()), this, SLOT(MergeImagesWithTime()));
277 connect(actionSave_As,SIGNAL(triggered()),this,SLOT(SaveAs()));
278 connect(actionSave_current_state,SIGNAL(triggered()),this,SLOT(SaveCurrentState()));
279 connect(actionRead_saved_state,SIGNAL(triggered()),this,SLOT(ReadSavedState()));
280 connect(actionExit,SIGNAL(triggered()),this,SLOT(close()));
281 connect(actionAdd_VF_to_current_Image,SIGNAL(triggered()),this,SLOT(OpenField()));
282 connect(actionAdd_fusion_image,SIGNAL(triggered()),this,SLOT(SelectFusionImage()));
283 connect(actionAdd_overlay_image_to_current_image,SIGNAL(triggered()), this,SLOT(SelectOverlayImage())); connect(actionNavigation_Help,SIGNAL(triggered()),this,SLOT(ShowHelpDialog()));
284 connect(actionDocumentation,SIGNAL(triggered()),this,SLOT(ShowDocumentation()));
285 connect(actionRegister_vv,SIGNAL(triggered()),this,SLOT(PopupRegisterForm()));
287 ///////////////////////////////////////////////
288 connect(actionSegmentation,SIGNAL(triggered()),this,SLOT(SegmentationOnCurrentImage()));
289 connect(actionSurface_Viewer,SIGNAL(triggered()),this,SLOT(SurfaceViewerLaunch()));
290 ///////////////////////////////////////////////
292 actionNorth_East_Window->setEnabled(0);
293 actionNorth_West_Window->setEnabled(0);
294 actionSouth_East_Window->setEnabled(0);
295 actionSouth_West_Window->setEnabled(0);
297 connect(actionNorth_East_Window,SIGNAL(triggered()),this,SLOT(SaveNEScreenshot()));
298 connect(actionNorth_West_Window,SIGNAL(triggered()),this,SLOT(SaveNOScreenshot()));
299 connect(actionSouth_East_Window,SIGNAL(triggered()),this,SLOT(SaveSEScreenshot()));
300 connect(actionSouth_West_Window,SIGNAL(triggered()),this,SLOT(SaveSOScreenshot()));
301 connect(actionSave_all_slices,SIGNAL(triggered()),this,SLOT(SaveScreenshotAllSlices()));
303 connect(DataTree,SIGNAL(itemSelectionChanged()),this,SLOT(ImageInfoChanged()));
304 connect(DataTree,SIGNAL(itemClicked(QTreeWidgetItem*, int)),this,
305 SLOT(DisplayChanged(QTreeWidgetItem*, int)));
307 connect(viewButton,SIGNAL(clicked()),this, SLOT(ChangeViewMode()) );
308 connect(windowSpinBox,SIGNAL(editingFinished()),this,SLOT(WindowLevelEdited()));
309 connect(levelSpinBox,SIGNAL(editingFinished()),this,SLOT(WindowLevelEdited()));
310 connect(colorMapComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(UpdateColorMap()));
311 connect(presetComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(UpdateWindowLevel()));
312 connect(slicingPresetComboBox, SIGNAL(currentIndexChanged(int)),this,SLOT(UpdateSlicingPreset()));
313 connect(inverseButton,SIGNAL(clicked()),this,SLOT(SwitchWindowLevel()));
314 connect(applyWindowLevelToAllButton,SIGNAL(clicked()),this,SLOT(ApplyWindowLevelToAllImages()));
316 connect(this,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(ShowContextMenu(QPoint)));
318 connect(linkPanel,SIGNAL(addLink(QString,QString)),this,SLOT(AddLink(QString,QString)));
319 connect(linkPanel,SIGNAL(removeLink(QString,QString)),this,SLOT(RemoveLink(QString,QString)));
320 connect(overlayPanel,SIGNAL(VFPropertyUpdated(int,int,int,int,double,double,double)),this,SLOT(SetVFProperty(int,int,int,int,double,double,double)));
321 connect(overlayPanel,SIGNAL(OverlayPropertyUpdated(int,int,double,double)),
322 this,SLOT(SetOverlayProperty(int,int,double,double)));
323 connect(overlayPanel,SIGNAL(FusionPropertyUpdated(int,int,int,double,double, bool)),
324 this,SLOT(SetFusionProperty(int,int,int,double,double, bool)));
325 connect(landmarksPanel,SIGNAL(UpdateRenderWindows()),this,SLOT(UpdateRenderWindows()));
329 playButton->setEnabled(0);
330 frameRateLabel->setEnabled(0);
331 frameRateSpinBox->setEnabled(0);
332 connect(playButton, SIGNAL(clicked()),this,SLOT(PlayPause()));
333 connect(frameRateSpinBox, SIGNAL(valueChanged(int)),this,SLOT(ChangeFrameRate(int)));
335 goToCursorPushButton->setEnabled(0);
336 connect(goToCursorPushButton, SIGNAL(clicked()),this,SLOT(GoToCursor()));
338 NOViewWidget->hide();
339 NEViewWidget->hide();
340 SOViewWidget->hide();
341 SEViewWidget->hide();
343 //Recently opened files
344 std::list<std::string> recent_files = GetRecentlyOpenedImages();
345 recentlyOpenedFilesMenu=NULL;
346 if ( !recent_files.empty() ) {
347 createRecentlyOpenedFilesMenu();
348 updateRecentlyOpenedFilesMenu(recent_files);
351 // Adding all new tools (insertion in the menu)
352 vvToolManager::GetInstance()->InsertToolsInMenu(this);
353 vvToolManager::GetInstance()->EnableToolsInMenu(this, false);
355 if (!CLITK_EXPERIMENTAL)
356 menuExperimental->menuAction()->setVisible(false);
359 QTimer * timerMemory = new QTimer(this);
360 //timerMemory->setInterval(5);
361 connect(timerMemory, SIGNAL(timeout()), this, SLOT(UpdateMemoryUsage()));
362 timerMemory->start(2000);
364 //------------------------------------------------------------------------------
365 void vvMainWindow::show()
367 vvMainWindowBase::show();
368 PopupRegisterForm(true);
370 //------------------------------------------------------------------------------
371 void vvMainWindow::UpdateMemoryUsage()
373 // clitk::PrintMemory(true);
374 if (clitk::GetMemoryUsageInMb() == 0) infoPanel->setMemoryInMb("NA");
375 else infoPanel->setMemoryInMb(QString::number(clitk::GetMemoryUsageInMb())+" MiB");
377 //------------------------------------------------------------------------------
380 //------------------------------------------------------------------------------
381 void vvMainWindow::createRecentlyOpenedFilesMenu()
383 recentlyOpenedFilesMenu = new QMenu("Recently opened files...");
384 recentlyOpenedFilesMenu->setIcon(QIcon(QString::fromUtf8(":/common/icons/open.png")));
385 menuFile->insertMenu(actionOpen_Image_With_Time,recentlyOpenedFilesMenu);
386 menuFile->insertSeparator(actionOpen_Image_With_Time);
388 //------------------------------------------------------------------------------
391 //------------------------------------------------------------------------------
393 void vvMainWindow::updateRecentlyOpenedFilesMenu(const std::list<std::string> &recent_files)
395 if(recentlyOpenedFilesMenu==NULL) {
396 createRecentlyOpenedFilesMenu();
398 recentlyOpenedFilesMenu->clear();
400 for (std::list<std::string>::const_iterator i = recent_files.begin(); i!=recent_files.end(); i++) {
401 QAction* current=new QAction(QIcon(QString::fromUtf8(":/common/icons/open.png")), i->c_str(),this);
402 recentlyOpenedFilesMenu->addAction(current);
403 connect(current,SIGNAL(triggered()),this,SLOT(OpenRecentImage()));
406 //------------------------------------------------------------------------------
409 //------------------------------------------------------------------------------
410 void vvMainWindow::ComputeMidPosition()
413 int index=GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
414 int ref = QInputDialog::getInteger(this,"Chose reference phase","Reference phase",0,0,\
415 mSlicerManagers[index]->GetImage()->GetVTKImages().size()-1,1,&ok);
418 midp.slicer_manager = mSlicerManagers[index];
419 midp.reference_image_index = ref;
420 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
423 QMessageBox::warning(this, "Error computing midposition image",midp.error_message.c_str());
425 QFileInfo info(midp.slicer_manager->GetFileName().c_str());
426 AddImage(midp.output,info.path().toStdString()+"/"+info.completeBaseName().toStdString()+"_midposition.mhd");
428 QApplication::restoreOverrideCursor();
431 //------------------------------------------------------------------------------
434 //------------------------------------------------------------------------------
435 void vvMainWindow::AddContour(int image_index, vvMesh::Pointer contour, bool propagation)
437 QTreeWidgetItem *item = new QTreeWidgetItem();
438 item->setData(0,Qt::UserRole,"filename.vtk");
439 item->setData(1,Qt::UserRole,tr("contour"));
441 brush.setColor(QColor(contour->r*255,contour->g*255,contour->b*255));
442 brush.setStyle(Qt::SolidPattern);
443 item->setData(COLUMN_IMAGE_NAME,Qt::BackgroundRole,brush);
444 item->setData(COLUMN_IMAGE_NAME,Qt::DisplayRole,contour->structure_name.c_str());
446 for (int j = 1; j <= 4; j++)
447 item->setData(j,Qt::CheckStateRole,DataTree->topLevelItem(image_index)->data(j,Qt::CheckStateRole));
449 QTreePushButton* cButton = new QTreePushButton;
450 cButton->setItem(item);
451 cButton->setColumn(COLUMN_CLOSE_IMAGE);
452 cButton->setToolTip(tr("close image"));
453 cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png")));
454 connect(cButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
455 this,SLOT(CloseImage(QTreeWidgetItem*, int)));
457 QTreePushButton* rButton = new QTreePushButton;
458 rButton->setItem(item);
459 rButton->setColumn(COLUMN_RELOAD_IMAGE);
460 rButton->setToolTip(tr("reload image"));
461 rButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/rotateright.png")));
462 rButton->setEnabled(false);
464 //connect(rButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
465 //this,SLOT(ReloadImage(QTreeWidgetItem*, int)));
467 DataTree->topLevelItem(image_index)->setExpanded(1);
468 DataTree->topLevelItem(image_index)->addChild(item);
469 DataTree->setItemWidget(item, COLUMN_CLOSE_IMAGE, cButton);
470 DataTree->setItemWidget(item, COLUMN_RELOAD_IMAGE, rButton);
471 QString id = DataTree->topLevelItem(image_index)->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString();
472 item->setData(COLUMN_IMAGE_NAME,Qt::UserRole,id.toStdString().c_str());
475 mSlicerManagers[image_index]->AddContour(contour,propagation);
476 mSlicerManagers[image_index]->Render();
478 //------------------------------------------------------------------------------
481 //------------------------------------------------------------------------------
482 void vvMainWindow::OpenVTKContour()
484 if (mSlicerManagers.size() > 0) {
485 QString Extensions = "Images ( *.vtk *.obj)";
486 Extensions += ";;All Files (*)";
487 QString file = QFileDialog::getOpenFileName(this,tr("Open vtkPolyData"),mInputPathName,Extensions);
490 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
491 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
493 reader.SetImage(mSlicerManagers[index]->GetImage());
494 reader.SetModeToVTK();
495 reader.SetFilename(file.toStdString());
497 AddContour(index,reader.GetOutput()[0],false);
498 QApplication::restoreOverrideCursor();
501 //------------------------------------------------------------------------------
504 //------------------------------------------------------------------------------
505 void vvMainWindow::AddDCStructContour(int index, QString file)
508 reader.SetFilename(file.toStdString());
509 vvStructSelector selector;
510 selector.SetStructures(reader.GetROINames());
511 if (!mSlicerManagers[index]->GetVF().IsNull())
512 selector.EnablePropagationCheckBox();
513 if (selector.exec()) {
514 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
515 reader.SetSelectedItems(selector.getSelectedItems());
516 reader.SetImage(mSlicerManagers[index]->GetImage());
517 if (selector.PropagationEnabled())
518 reader.SetPropagationVF(mSlicerManagers[index]->GetVF());
520 std::vector<vvMesh::Pointer> contours=reader.GetOutput();
521 for (std::vector<vvMesh::Pointer>::iterator i=contours.begin();
522 i!=contours.end(); i++)
523 AddContour(index,*i,selector.PropagationEnabled());
524 QApplication::restoreOverrideCursor();
528 //------------------------------------------------------------------------------
529 void vvMainWindow::OpenDCStructContour()
531 if (mSlicerManagers.size() > 0) {
532 QString Extensions = "Dicom Files ( *.dcm RS*)";
533 Extensions += ";;All Files (*)";
534 QString file = QFileDialog::getOpenFileName(this,tr("Merge Images"),mInputPathName,Extensions);
537 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
538 AddDCStructContour(index, file);
541 //------------------------------------------------------------------------------
544 //------------------------------------------------------------------------------
545 void vvMainWindow::ComputeDeformableRegistration()
547 if (mSlicerManagers.size() > 0) {
548 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
549 vvDeformationDialog dialog(index,mSlicerManagers);
551 std::string base_name=itksys::SystemTools::GetFilenameWithoutExtension(mSlicerManagers[dialog.GetInputFileIndex()]->GetFileName());
552 AddField(dialog.GetOutput(),dialog.getFieldFile(),dialog.GetInputFileIndex());
553 WarpImage(dialog.GetSelectedSlicer(),dialog.GetReferenceFrameIndex());
555 std::cout << "Error or user cancellation while computing deformation field..." << std::endl;
556 } else QMessageBox::information(this, "Need to open image","You must open an image first.");
558 //------------------------------------------------------------------------------
561 //------------------------------------------------------------------------------
562 void vvMainWindow::WarpImage()
564 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
565 if (!mSlicerManagers[index]->GetVF().IsNull()) {
567 int ref = QInputDialog::getInteger(this,"Chose reference phase","Reference phase",0,0,\
568 mSlicerManagers[index]->GetImage()->GetVTKImages().size()-1,1,&ok);
570 WarpImage(mSlicerManagers[index],ref);
573 QMessageBox::warning(this,tr("No vector field"),tr("Sorry, can't warp without a vector field"));
575 //------------------------------------------------------------------------------
578 //------------------------------------------------------------------------------
579 void vvMainWindow::WarpImage(vvSlicerManager* selected_slicer,int reference_phase)
581 if (!selected_slicer->GetVF().IsNull()) {
582 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
583 QFileInfo info(selected_slicer->GetFileName().c_str());
584 vvImageWarp warp(selected_slicer->GetImage(),selected_slicer->GetVF(),
585 reference_phase,this);
586 if (warp.ComputeWarpedImage()) {
587 AddImage(warp.GetWarpedImage(),info.path().toStdString()+"/"+info.completeBaseName().toStdString()+"_warped.mhd");
588 AddImage(warp.GetDiffImage() ,info.path().toStdString()+"/"+info.completeBaseName().toStdString()+"_diff.mhd");
589 AddImage(warp.GetJacobianImage() ,info.path().toStdString()+"/"+info.completeBaseName().toStdString()+"_jacobian.mhd");
590 QApplication::restoreOverrideCursor();
592 QApplication::restoreOverrideCursor();
593 QMessageBox::warning(this,tr("Different spacings"),tr("The vector field and image spacings must be the same in order to warp."));
596 QMessageBox::warning(this,tr("No vector field"),tr("Sorry, can't warp without a vector field."));
598 //------------------------------------------------------------------------------
601 //------------------------------------------------------------------------------
602 vvMainWindow::~vvMainWindow()
604 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
605 if (mSlicerManagers[i] != NULL)
606 delete mSlicerManagers[i];
609 //------------------------------------------------------------------------------
611 //------------------------------------------------------------------------------
612 QTabWidget * vvMainWindow::GetTab()
616 //------------------------------------------------------------------------------
619 //------------------------------------------------------------------------------
620 void vvMainWindow::MergeImages()
622 QString Extensions = EXTENSIONS;
623 Extensions += ";;All Files (*)";
624 QStringList files = QFileDialog::getOpenFileNames(this,tr("Merge Images"),mInputPathName,Extensions);
627 mInputPathName = itksys::SystemTools::GetFilenamePath(files[0].toStdString()).c_str();
628 std::vector<std::string> vector;
630 unsigned int currentDim = 0;
631 std::vector<double> currentSpacing;
632 std::vector<int> currentSize;
633 std::vector<double> currentOrigin;
635 for (int i = 0; i < files.size(); i++) {
636 itk::ImageIOBase::Pointer reader = itk::ImageIOFactory::CreateImageIO(
637 files[i].toStdString().c_str(), itk::ImageIOFactory::ReadMode);
638 reader->SetFileName(files[i].toStdString().c_str());
639 reader->ReadImageInformation();
641 //NOViewWidget->hide();
642 //NEViewWidget->hide();
643 //SOViewWidget->hide();
644 //SEViewWidget->hide();
646 currentDim = reader->GetNumberOfDimensions();
648 for (unsigned int j = 0; j < currentDim; j++) {
651 currentSpacing.resize(currentDim);
652 currentSize.resize(currentDim);
653 currentOrigin.resize(currentDim);
655 currentOrigin[j] = reader->GetOrigin(j);
656 currentSpacing[j] = reader->GetSpacing(j);
657 currentSize[j] = reader->GetDimensions(j);
658 } else if (currentDim != reader->GetNumberOfDimensions()
659 || currentSpacing[j] != reader->GetSpacing(j)
660 || currentSize[j] != (int)reader->GetDimensions(j)
661 || currentOrigin[j] != reader->GetOrigin(j)) {
662 QString error = "Cannot read file (too different from others ";
663 error += files[i].toStdString().c_str();
664 QMessageBox::information(this,tr("Reading problem"),error);
670 vector.push_back(files[i].toStdString());
673 if (vector.size() > 0)
674 LoadImages(vector, vvImageReader::MERGED);
676 //------------------------------------------------------------------------------
678 //------------------------------------------------------------------------------
679 void vvMainWindow::SliceImages()
681 QString Extensions = EXTENSIONS;
682 Extensions += ";;All Files (*)";
684 QStringList files = QFileDialog::getOpenFileNames(this,tr("Slice Images"),mInputPathName,Extensions);
687 mInputPathName = itksys::SystemTools::GetFilenamePath(files[0].toStdString()).c_str();
688 std::vector<std::string> vector;
689 for (int i = 0; i < files.size(); i++)
690 vector.push_back(files[i].toStdString());
691 LoadImages(vector, vvImageReader::SLICED);
693 //------------------------------------------------------------------------------
695 //------------------------------------------------------------------------------
696 void vvMainWindow::MergeImagesWithTime()
698 QString Extensions = EXTENSIONS;
699 Extensions += ";;All Files (*)";
700 QStringList files = QFileDialog::getOpenFileNames(this,tr("Merge Images With Time"),mInputPathName,Extensions);
703 mInputPathName = itksys::SystemTools::GetFilenamePath(files[0].toStdString()).c_str();
704 std::vector<std::string> vector;
706 unsigned int currentDim = 0;
707 std::vector<double> currentSpacing;
708 std::vector<int> currentSize;
709 std::vector<double> currentOrigin;
711 for (int i = 0; i < files.size(); i++) {
712 itk::ImageIOBase::Pointer reader = itk::ImageIOFactory::CreateImageIO(
713 files[i].toStdString().c_str(), itk::ImageIOFactory::ReadMode);
715 reader->SetFileName(files[i].toStdString().c_str());
716 reader->ReadImageInformation();
718 currentDim = reader->GetNumberOfDimensions();
720 for (unsigned int j = 0; j < currentDim; j++) {
723 currentSpacing.resize(currentDim);
724 currentSize.resize(currentDim);
725 currentOrigin.resize(currentDim);
727 currentOrigin[j] = reader->GetOrigin(j);
728 currentSpacing[j] = reader->GetSpacing(j);
729 currentSize[j] = reader->GetDimensions(j);
730 } else if (currentDim != reader->GetNumberOfDimensions()
731 || currentSpacing[j] != reader->GetSpacing(j)
732 || currentSize[j] != (int)reader->GetDimensions(j)
733 || currentOrigin[j] != reader->GetOrigin(j)) {
734 QString error = "Cannot read file (too different from others ";
735 error += files[i].toStdString().c_str();
736 QMessageBox::information(this,tr("Reading problem"),error);
742 vector.push_back(files[i].toStdString());
744 QString error = "Cannot read file info for ";
745 error += files[i].toStdString().c_str();
747 error += "Maybe you're trying to open an image in an unsupported format?\n";
748 QMessageBox::information(this,tr("Reading problem"),error);
751 sort(vector.begin(),vector.end());
752 if (vector.size() > 1)
753 LoadImages(vector, vvImageReader::MERGEDWITHTIME);
755 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.");
757 //------------------------------------------------------------------------------
760 //------------------------------------------------------------------------------
761 void vvMainWindow::OpenDicom()
763 std::vector<std::string> files;
765 std::cout << "dicomSeriesSelector " << std::endl;
766 if (dicomSeriesSelector->exec() == QDialog::Accepted) {
767 files = *(dicomSeriesSelector->GetFilenames());
768 LoadImages(files, vvImageReader::DICOM);
771 //------------------------------------------------------------------------------
773 //------------------------------------------------------------------------------
774 void vvMainWindow::OpenImages()
776 QString Extensions = EXTENSIONS;
777 Extensions += ";;All Files (*)";
779 QStringList files = QFileDialog::getOpenFileNames(this,tr("Load Images"),mInputPathName,Extensions);
782 mInputPathName = itksys::SystemTools::GetFilenamePath(files[0].toStdString()).c_str();
783 std::vector<std::string> vector;
784 for (int i = 0; i < files.size(); i++)
785 vector.push_back(files[i].toStdString());
786 LoadImages(vector, vvImageReader::IMAGE);
788 //------------------------------------------------------------------------------
789 void vvMainWindow::OpenRecentImage()
791 QAction * caller = qobject_cast<QAction*>(sender());
792 std::vector<std::string> images;
793 images.push_back(caller->text().toStdString());
794 mInputPathName = itksys::SystemTools::GetFilenamePath(images[0]).c_str();
795 LoadImages(images, vvImageReader::IMAGE);
797 //------------------------------------------------------------------------------
800 //------------------------------------------------------------------------------
801 void vvMainWindow::OpenImageWithTime()
803 QString Extensions = EXTENSIONS;
804 Extensions += ";;All Files (*)";
806 QStringList files = QFileDialog::getOpenFileNames(this,tr("Load Images With Time"),mInputPathName,Extensions);
809 mInputPathName = itksys::SystemTools::GetFilenamePath(files[0].toStdString()).c_str();
810 std::vector<std::string> vector;
811 for (int i = 0; i < files.size(); i++) {
812 vector.push_back(files[i].toStdString());
814 LoadImages(vector, vvImageReader::IMAGEWITHTIME);
816 //------------------------------------------------------------------------------
819 //------------------------------------------------------------------------------
820 void vvMainWindow::LoadImages(std::vector<std::string> files, vvImageReader::LoadedImageType filetype)
822 //Separate the way to open images and dicoms
824 if (filetype == vvImageReader::IMAGE || filetype == vvImageReader::IMAGEWITHTIME)
825 fileSize = files.size();
829 // For SLICED, we need the number of slices (ndim and #slices)
830 std::vector<unsigned int> nSlices;
831 nSlices.resize(files.size());
832 std::fill(nSlices.begin(), nSlices.end(), 1);
833 if (filetype == vvImageReader::SLICED) {
834 for (int i = 0; i < fileSize; i++) {
835 itk::ImageIOBase::Pointer header = clitk::readImageHeader(files[i]);
836 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
839 QString error = "Cannot open file \n";
840 error += files[i].c_str();
841 QMessageBox::information(this,tr("Reading problem"),error);
844 if (header->GetNumberOfDimensions() < 3) {
846 QString error = "Dimension problem. Cannot slice \n";
847 error += files[i].c_str();
848 QMessageBox::information(this,tr("Reading problem"),error);
851 nSlices[i] = header->GetDimensions( header->GetNumberOfDimensions()-1 );
855 //Only add to the list of recently opened files when a single file is opened,
856 //to avoid polluting the list of recently opened files
857 if (files.size() == 1) {
858 QFileInfo finfo=tr(files[0].c_str());
859 AddToRecentlyOpenedImages(finfo.absoluteFilePath().toStdString());
860 updateRecentlyOpenedFilesMenu(GetRecentlyOpenedImages());
862 //init the progress events
863 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
864 vvProgressDialog progress("Opening " + files[0],fileSize>1);
865 qApp->processEvents();
867 int numberofsuccesulreads=0;
868 //open images as 1 or multiples
869 for (int i = 0; i < fileSize; i++) {
871 progress.SetText("Opening " + files[i]);
872 progress.SetProgress(i,fileSize);
873 qApp->processEvents();
875 for (unsigned int j = 0; j < nSlices[i]; j++) {
876 //read the image and put it in mSlicerManagers
877 vvSlicerManager* imageManager = new vvSlicerManager(4);
878 qApp->processEvents();
880 bool SetImageSucceed=false;
882 // Change filename if an image with the same already exist
883 int number = GetImageDuplicateFilenameNumber(files[i] + std::string("_slice"));
885 if (filetype == vvImageReader::IMAGE || filetype == vvImageReader::IMAGEWITHTIME || filetype == vvImageReader::SLICED)
886 SetImageSucceed = imageManager->SetImage(files[i],filetype, number, j);
888 SetImageSucceed = imageManager->SetImages(files,filetype, number);
890 if (!SetImageSucceed) {
891 QApplication::restoreOverrideCursor();
892 QString error = "Cannot open file \n";
893 error += imageManager->GetLastError().c_str();
894 QMessageBox::information(this,tr("Reading problem"),error);
897 mSlicerManagers.push_back(imageManager);
899 //create an item in the tree with good settings
900 QTreeWidgetItem *item = new QTreeWidgetItem();
901 item->setData(0,Qt::UserRole,files[i].c_str());
902 QFileInfo fileinfo(imageManager->GetFileName().c_str()); //Do not show the path
903 item->setData(COLUMN_IMAGE_NAME,Qt::DisplayRole,fileinfo.fileName());
904 item->setData(1,Qt::UserRole,tr("image"));
905 item->setToolTip(COLUMN_IMAGE_NAME, imageManager->GetListOfAbsoluteFilePathInOneString("image").c_str());
906 qApp->processEvents();
908 //Create the buttons for reload and close
909 qApp->processEvents();
910 QTreePushButton* cButton = new QTreePushButton;
911 cButton->setItem(item);
912 cButton->setColumn(COLUMN_CLOSE_IMAGE);
913 cButton->setToolTip(tr("close image"));
914 cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png")));
915 connect(cButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
916 this,SLOT(CloseImage(QTreeWidgetItem*, int)));
918 QTreePushButton* rButton = new QTreePushButton;
919 rButton->setItem(item);
920 rButton->setColumn(COLUMN_RELOAD_IMAGE);
921 rButton->setToolTip(tr("reload image"));
922 rButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/rotateright.png")));
923 connect(rButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
924 this,SLOT(ReloadImage(QTreeWidgetItem*, int)));
926 DataTree->addTopLevelItem(item);
927 DataTree->setItemWidget(item, COLUMN_CLOSE_IMAGE, cButton);
928 DataTree->setItemWidget(item, COLUMN_RELOAD_IMAGE, rButton);
930 //set the id of the image
931 QString id = files[i].c_str() + QString::number(mSlicerManagers.size()-1);
932 item->setData(COLUMN_IMAGE_NAME,Qt::UserRole,id.toStdString().c_str());
933 mSlicerManagers.back()->SetId(id.toStdString());
935 linkPanel->addImage(imageManager->GetFileName(), id.toStdString());
937 connect(mSlicerManagers.back(), SIGNAL(currentImageChanged(std::string)),
938 this,SLOT(CurrentImageChanged(std::string)));
939 connect(mSlicerManagers.back(), SIGNAL(currentPickedImageChanged(std::string)),
940 this, SLOT(CurrentPickedImageChanged(std::string)));
941 connect(mSlicerManagers.back(), SIGNAL(UpdatePosition(int, double, double, double, double, double, double, double)),
942 this,SLOT(MousePositionChanged(int,double, double, double, double, double, double, double)));
943 connect(mSlicerManagers.back(), SIGNAL(UpdateVector(int, double, double, double, double)),
944 this, SLOT(VectorChanged(int,double,double,double, double)));
945 connect(mSlicerManagers.back(), SIGNAL(UpdateOverlay(int, double, double)),
946 this, SLOT(OverlayChanged(int,double,double)));
947 connect(mSlicerManagers.back(), SIGNAL(UpdateFusion(int, double)),
948 this, SLOT(FusionChanged(int,double)));
949 connect(mSlicerManagers.back(), SIGNAL(WindowLevelChanged()),
950 this,SLOT(WindowLevelChanged()));
951 connect(mSlicerManagers.back(), SIGNAL(UpdateSlice(int,int)),
952 this,SLOT(UpdateSlice(int,int)));
953 connect(mSlicerManagers.back(), SIGNAL(UpdateTSlice(int, int)),
954 this,SLOT(UpdateTSlice(int, int)));
955 connect(mSlicerManagers.back(), SIGNAL(UpdateSliceRange(int,int,int,int,int)),
956 this,SLOT(UpdateSliceRange(int,int,int,int,int)));
957 connect(mSlicerManagers.back(), SIGNAL(UpdateLinkManager(std::string,int,double,double,double,int)),
958 this,SLOT(UpdateLinkManager(std::string,int,double,double,double,int)));
959 connect(mSlicerManagers.back(), SIGNAL(UpdateLinkedNavigation(std::string,vvSlicerManager*,vvSlicer*)),
960 this,SLOT(UpdateLinkedNavigation(std::string,vvSlicerManager*,vvSlicer*)));
961 connect(mSlicerManagers.back(), SIGNAL(ChangeImageWithIndexOffset(vvSlicerManager*,int,int)),
962 this,SLOT(ChangeImageWithIndexOffset(vvSlicerManager*,int,int)));
963 connect(mSlicerManagers.back(),SIGNAL(LandmarkAdded()),landmarksPanel,SLOT(AddPoint()));
965 numberofsuccesulreads++;
969 if (numberofsuccesulreads) {
970 NOViewWidget->show();
971 NEViewWidget->show();
972 SOViewWidget->show();
973 SEViewWidget->show();
978 // Try to guess default WindowLevel
980 mSlicerManagers.back()->GetImage()->GetFirstVTKImageData()->GetScalarRange(range);
981 if ((range[0] == 0) && (range[1] == 1)) {
982 presetComboBox->setCurrentIndex(5);// binary
987 QApplication::restoreOverrideCursor();
989 //------------------------------------------------------------------------------
991 //------------------------------------------------------------------------------
992 void vvMainWindow::UpdateTree()
994 DataTree->resizeColumnToContents(COLUMN_TREE);
995 DataTree->resizeColumnToContents(COLUMN_UL_VIEW);
996 DataTree->resizeColumnToContents(COLUMN_UR_VIEW);
997 DataTree->resizeColumnToContents(COLUMN_DL_VIEW);
998 DataTree->resizeColumnToContents(COLUMN_DR_VIEW);
999 DataTree->resizeColumnToContents(COLUMN_IMAGE_NAME);
1000 DataTree->resizeColumnToContents(COLUMN_CLOSE_IMAGE);
1001 DataTree->resizeColumnToContents(COLUMN_RELOAD_IMAGE);
1003 //------------------------------------------------------------------------------
1005 //------------------------------------------------------------------------------
1006 void vvMainWindow::CurrentImageChanged(std::string id)
1008 if (id == mCurrentSelectedImageId) return; // Do nothing
1010 for (int i = 0; i < DataTree->topLevelItemCount(); i++) {
1011 if (DataTree->topLevelItem(i)->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString().toStdString() == id) {
1014 DataTree->topLevelItem(i)->setSelected(0);
1016 for (int child = 0; child < DataTree->topLevelItem(i)->childCount(); child++)
1017 DataTree->topLevelItem(i)->child(child)->setSelected(0);
1020 DataTree->topLevelItem(selected)->setSelected(1);
1021 mCurrentSelectedImageId = id;
1022 emit SelectedImageHasChanged(mSlicerManagers[selected]);
1024 //------------------------------------------------------------------------------
1026 //------------------------------------------------------------------------------
1027 void vvMainWindow::CurrentPickedImageChanged(std::string id)
1029 if (id == mCurrentPickedImageId) return; // Do nothing
1031 for (int i = 0; i < DataTree->topLevelItemCount(); i++) {
1032 if (DataTree->topLevelItem(i)->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString().toStdString() == id) {
1035 DataTree->topLevelItem(i)->setSelected(0);
1037 for (int child = 0; child < DataTree->topLevelItem(i)->childCount(); child++)
1038 DataTree->topLevelItem(i)->child(child)->setSelected(0);
1041 DataTree->topLevelItem(selected)->setSelected(1);
1042 mCurrentPickedImageId = id;
1043 mCurrentPickedImageIndex = selected;
1045 //------------------------------------------------------------------------------
1047 //------------------------------------------------------------------------------
1048 void vvMainWindow::ImageInfoChanged()
1050 contextActions[6]->setEnabled(1);
1051 contextActions[5]->setEnabled(1);
1052 actionSave_As->setEnabled(1);
1053 actionAdd_VF_to_current_Image->setEnabled(1);
1054 actionAdd_fusion_image->setEnabled(1);
1055 actionAdd_overlay_image_to_current_image->setEnabled(1);
1056 actionNorth_East_Window->setEnabled(1);
1057 actionNorth_West_Window->setEnabled(1);
1058 actionSouth_East_Window->setEnabled(1);
1059 actionSouth_West_Window->setEnabled(1);
1060 vvToolManager::GetInstance()->EnableToolsInMenu(this, true);
1061 inverseButton->setEnabled(1);
1063 goToCursorPushButton->setEnabled(1);
1065 if (DataTree->selectedItems().size()) {
1066 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
1068 colorMapComboBox->setEnabled(1);
1069 for (int i = 0; i < DataTree->topLevelItem(index)->childCount(); i++) {
1070 if (DataTree->topLevelItem(index)->child(i)->data(1,Qt::UserRole).toString() == "overlay" ||
1071 DataTree->topLevelItem(index)->child(i)->data(1,Qt::UserRole).toString() == "fusion") {
1072 colorMapComboBox->setEnabled(0);
1077 std::vector<double> origin;
1078 std::vector<double> inputSpacing;
1079 std::vector<int> inputSize;
1080 std::vector<double> sizeMM;
1081 vtkSmartPointer<vtkMatrix4x4> transformation;
1084 QString inputSizeInBytes;
1085 QString image = DataTree->selectedItems()[0]->data(COLUMN_IMAGE_NAME,Qt::DisplayRole).toString();
1087 if (mSlicerManagers[index]->GetSlicer(0)->GetImage()->GetVTKImages().size() > 1 || playMode == 1) {
1088 playButton->setEnabled(1);
1089 frameRateLabel->setEnabled(1);
1090 frameRateSpinBox->setEnabled(1);
1092 playButton->setEnabled(0);
1093 frameRateLabel->setEnabled(0);
1094 frameRateSpinBox->setEnabled(0);
1100 vvImage::Pointer imageSelected;
1101 if (DataTree->topLevelItem(index) == DataTree->selectedItems()[0]) {
1102 imageSelected = mSlicerManagers[index]->GetSlicer(0)->GetImage();
1103 } else if (DataTree->selectedItems()[0]->data(1,Qt::UserRole).toString() == "vector") {
1104 imageSelected = mSlicerManagers[index]->GetSlicer(0)->GetVF();
1105 } else if (DataTree->selectedItems()[0]->data(1,Qt::UserRole).toString() == "overlay") {
1106 imageSelected = mSlicerManagers[index]->GetSlicer(0)->GetOverlay();
1107 } else if (DataTree->selectedItems()[0]->data(1,Qt::UserRole).toString() == "fusion") {
1108 imageSelected = mSlicerManagers[index]->GetSlicer(0)->GetFusion();
1110 else if (DataTree->selectedItems()[0]->data(1,Qt::UserRole).toString() == "contour") {
1111 imageSelected = mSlicerManagers[index]->GetSlicer(0)->GetImage();
1114 imageSelected = mSlicerManagers[index]->GetSlicer(0)->GetImage();
1117 dimension = imageSelected->GetNumberOfDimensions();
1118 origin.resize(dimension);
1119 inputSpacing.resize(dimension);
1120 inputSize.resize(dimension);
1121 sizeMM.resize(dimension);
1122 pixelType = mSlicerManagers[index]->GetImage()->GetScalarTypeAsITKString().c_str();
1123 for (int i = 0; i < dimension; i++) {
1124 origin[i] = imageSelected->GetOrigin()[i];
1125 inputSpacing[i] = imageSelected->GetSpacing()[i];
1126 inputSize[i] = imageSelected->GetSize()[i];
1127 sizeMM[i] = inputSize[i]*inputSpacing[i];
1128 NPixel *= inputSize[i];
1130 inputSizeInBytes = GetSizeInBytes(imageSelected->GetActualMemorySize()*1000);
1132 QString dim = QString::number(dimension) + " (";
1133 dim += pixelType + ")";
1135 infoPanel->setFileName(image);
1136 infoPanel->setDimension(dim);
1137 infoPanel->setSizePixel(GetVectorIntAsString(inputSize));
1138 infoPanel->setSizeMM(GetVectorDoubleAsString(sizeMM));
1139 infoPanel->setOrigin(GetVectorDoubleAsString(origin));
1140 infoPanel->setSpacing(GetVectorDoubleAsString(inputSpacing));
1141 infoPanel->setNPixel(QString::number(NPixel)+" ("+inputSizeInBytes+")");
1142 transformation = imageSelected->GetTransform()->GetMatrix();
1143 infoPanel->setTransformation(Get4x4MatrixDoubleAsString(transformation));
1145 landmarksPanel->SetCurrentLandmarks(mSlicerManagers[index]->GetLandmarks(),
1146 mSlicerManagers[index]->GetSlicer(0)->GetImage()->GetVTKImages().size());
1147 landmarksPanel->SetCurrentPath(mInputPathName.toStdString());
1148 landmarksPanel->SetCurrentImage(mSlicerManagers[index]->GetFileName().c_str());
1150 overlayPanel->getCurrentImageName(mSlicerManagers[index]->GetFileName().c_str());
1151 for (int i = 0; i < 4; i++) {
1152 if (DataTree->selectedItems()[0]->data(i+1,Qt::CheckStateRole).toInt() > 0 || i == 3) {
1153 mSlicerManagers[index]->UpdateInfoOnCursorPosition(i);
1158 infoPanel->setFileName(image);
1159 infoPanel->setDimension(dim);
1160 infoPanel->setSizePixel(GetVectorIntAsString(inputSize));
1161 infoPanel->setSizeMM(GetVectorDoubleAsString(sizeMM));
1162 infoPanel->setOrigin(GetVectorDoubleAsString(origin));
1163 infoPanel->setSpacing(GetVectorDoubleAsString(inputSpacing));
1164 infoPanel->setNPixel(QString::number(NPixel)+" ("+inputSizeInBytes+")");
1166 landmarksPanel->SetCurrentLandmarks(mSlicerManagers[index]->GetLandmarks(),
1167 mSlicerManagers[index]->GetSlicer(0)->GetImage()->GetVTKImages().size());
1168 landmarksPanel->SetCurrentPath(mInputPathName.toStdString());
1169 landmarksPanel->SetCurrentImage(mSlicerManagers[index]->GetFileName().c_str());
1171 overlayPanel->getCurrentImageName(mSlicerManagers[index]->GetFileName().c_str());
1172 for (int i = 0; i < 4; i++) {
1173 if (DataTree->selectedItems()[0]->data(i+1,Qt::CheckStateRole).toInt() > 0 || i == 3) {
1174 mSlicerManagers[index]->UpdateInfoOnCursorPosition(i);
1178 WindowLevelChanged();
1179 slicingPresetComboBox->setCurrentIndex(mSlicerManagers[index]->GetSlicingPreset());
1181 if (mSlicerManagers[index]->GetSlicer(0)->GetVF()) {
1182 overlayPanel->getVFName(mSlicerManagers[index]->GetVFName().c_str());
1183 overlayPanel->getVFProperty(mSlicerManagers[index]->GetSlicer(0)->GetVFSubSampling(),
1184 mSlicerManagers[index]->GetSlicer(0)->GetVFScale(),
1185 mSlicerManagers[index]->GetSlicer(0)->GetVFLog());
1187 overlayPanel->getVFName(mSlicerManagers[index]->GetVFName().c_str());
1188 overlayPanel->getVFProperty(-1,-1,-1);
1190 if (mSlicerManagers[index]->GetSlicer(0)->GetOverlay()) {
1191 overlayPanel->getOverlayName(mSlicerManagers[index]->GetOverlayName().c_str());
1193 overlayPanel->getOverlayName(mSlicerManagers[index]->GetOverlayName().c_str());
1196 if (mSlicerManagers[index]->GetSlicer(0)->GetFusion()) {
1197 overlayPanel->getFusionName(mSlicerManagers[index]->GetFusionName().c_str());
1199 overlayPanel->getFusionName(mSlicerManagers[index]->GetFusionName().c_str());
1203 //------------------------------------------------------------------------------
1205 //------------------------------------------------------------------------------
1206 void vvMainWindow::ShowDocumentation()
1208 documentation->show();
1210 //------------------------------------------------------------------------------
1212 //------------------------------------------------------------------------------
1213 void vvMainWindow::PopupRegisterForm(bool checkCanPush)
1215 vvRegisterForm* registerForm = new vvRegisterForm(QUrl("http://www.creatis.insa-lyon.fr/~dsarrut/vvregister/write.php"), getVVSettingsPath(), getSettingsOptionFormat());
1217 registerForm->show();
1219 if(registerForm->canPush()) {
1220 registerForm->show();
1221 registerForm->acquitPushed();//too bad if there is not internet connection anymore.
1225 //------------------------------------------------------------------------------
1227 //------------------------------------------------------------------------------
1228 void vvMainWindow::ShowHelpDialog()
1230 help_dialog->show();
1232 //------------------------------------------------------------------------------
1234 //------------------------------------------------------------------------------
1235 void vvMainWindow::ChangeViewMode()
1238 if (viewMode == 1) {
1242 splitter_3->setSizes(size);
1243 OSplitter->setSizes(size);
1244 DataTree->setColumnHidden(2,1);
1245 DataTree->setColumnHidden(3,1);
1246 DataTree->setColumnHidden(4,1);
1251 splitter_3->setSizes(size);
1252 OSplitter->setSizes(size);
1253 DataTree->setColumnHidden(2,0);
1254 DataTree->setColumnHidden(3,0);
1255 DataTree->setColumnHidden(4,0);
1257 UpdateRenderWindows();
1259 ** I don't know why but for both resized QVTKWidget we also need to render
1260 ** the associated Slicer to redraw crosses.
1262 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
1263 if (DataTree->topLevelItem(i)->data(COLUMN_UL_VIEW,Qt::CheckStateRole).toInt() > 1)
1264 mSlicerManagers[i]->GetSlicer(0)->Render();
1265 if (DataTree->topLevelItem(i)->data(COLUMN_DL_VIEW,Qt::CheckStateRole).toInt() > 1)
1266 mSlicerManagers[i]->GetSlicer(2)->Render();
1269 //------------------------------------------------------------------------------
1271 //------------------------------------------------------------------------------
1272 QString vvMainWindow::GetSizeInBytes(unsigned long size)
1274 QString result = "";// QString::number(size);
1275 //result += " bytes (";
1276 if (size > 1000000000) {
1278 result += QString::number(size);
1279 result += "Gb";//)";
1280 } else if (size > 1000000) {
1282 result += QString::number(size);
1283 result += "Mb";//)";
1284 } else if (size > 1000) {
1286 result += QString::number(size);
1287 result += "kb";//)";
1291 //------------------------------------------------------------------------------
1293 //------------------------------------------------------------------------------
1294 QString vvMainWindow::Get4x4MatrixDoubleAsString(vtkSmartPointer<vtkMatrix4x4> matrix, const int precision)
1296 std::ostringstream strmatrix;
1298 // Figure out the number of digits of the integer part of the largest absolute value
1301 for (unsigned int j = 0; j < 4; j++){
1303 for (unsigned int i = 0; i < 4; i++)
1304 absmax = std::max(absmax, vnl_math_abs(matrix->GetElement(i, j)));
1305 unsigned ndigits = (unsigned)std::max(0.,std::log10(absmax))+1;
1306 width[j] = precision+ndigits+3;
1309 // Output with correct width, aligned to the right
1310 for (unsigned int i = 0; i < 4; i++) {
1311 for (unsigned int j = 0; j < 4; j++) {
1312 strmatrix.setf(ios::fixed,ios::floatfield);
1313 strmatrix.precision(precision);
1314 strmatrix.fill(' ');
1315 strmatrix.width(width[j]);
1316 strmatrix << std::right << matrix->GetElement(i, j);
1318 strmatrix << std::endl;
1320 QString result = strmatrix.str().c_str();
1323 //------------------------------------------------------------------------------
1325 //------------------------------------------------------------------------------
1326 QString vvMainWindow::GetVectorDoubleAsString(std::vector<double> vectorDouble)
1329 for (unsigned int i= 0; i < vectorDouble.size(); i++) {
1332 result += QString::number(vectorDouble[i]);
1336 //------------------------------------------------------------------------------
1338 //------------------------------------------------------------------------------
1339 QString vvMainWindow::GetVectorIntAsString(std::vector<int> vectorInt)
1342 for (unsigned int i= 0; i < vectorInt.size(); i++) {
1345 result += QString::number(vectorInt[i]);
1349 //------------------------------------------------------------------------------
1351 //------------------------------------------------------------------------------
1352 int vvMainWindow::GetSlicerIndexFromItem(QTreeWidgetItem* item)
1354 QString id = item->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString();
1355 for (int i = 0; i < DataTree->topLevelItemCount(); i++) {
1356 if (DataTree->topLevelItem(i)->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString() == id)
1361 //------------------------------------------------------------------------------
1363 //------------------------------------------------------------------------------
1364 QTreeWidgetItem* vvMainWindow::GetItemFromSlicerManager(vvSlicerManager* sm)
1366 QString id = sm->GetId().c_str();
1367 for (int i = 0; i < DataTree->topLevelItemCount(); i++) {
1368 if (DataTree->topLevelItem(i)->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString() == id)
1369 return DataTree->topLevelItem(i);
1373 //------------------------------------------------------------------------------
1375 //------------------------------------------------------------------------------
1376 void vvMainWindow::DisplayChanged(QTreeWidgetItem *clickedItem, int column)
1378 if ( column >= COLUMN_CLOSE_IMAGE || column <= 0)
1381 // Get parent information (might be the same item)
1382 int slicerManagerIndex = GetSlicerIndexFromItem(clickedItem);
1383 QTreeWidgetItem* clickedParentItem = DataTree->topLevelItem(slicerManagerIndex);
1384 vvSlicer* clickedSlicer = mSlicerManagers[slicerManagerIndex]->GetSlicer(column-1);
1386 // Go over the complete item tree (only 2 levels, parents and children)
1387 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
1388 // Trick to avoid redoing twice the job for a key (sr)
1389 mSlicerManagers[i]->GetSlicer(column-1)->GetRenderWindow()->GetInteractor()->SetKeySym("Crap");
1391 QTreeWidgetItem* currentParentItem = DataTree->topLevelItem(i);
1392 if(currentParentItem != clickedParentItem) {
1393 // Not the branch of the clicked item, uncheck all
1396 currentParentItem->setData(column,Qt::CheckStateRole, 0);
1397 mSlicerManagers[i]->UpdateSlicer(column-1, false);
1400 for (int iChild = 0; iChild < currentParentItem->childCount(); iChild++) {
1401 currentParentItem->child(iChild)->setData(column,Qt::CheckStateRole, 0);
1405 // Branch of the clicked one: get check status from actor visibility in slicer
1406 // and toggle the clicked one
1409 bool vis = clickedSlicer->GetActorVisibility("image", 0);
1410 bool draw = clickedSlicer->GetRenderer()->GetDraw();
1412 // Update slicer (after getting visibility)
1413 mSlicerManagers[slicerManagerIndex]->UpdateSlicer(column-1, true);
1414 mSlicerManagers[slicerManagerIndex]->UpdateInfoOnCursorPosition(column-1);
1415 DisplaySliders(slicerManagerIndex, column-1);
1416 if(clickedParentItem == clickedItem) {
1418 vis = !draw || !vis;
1420 clickedSlicer->SetActorVisibility("image", 0, vis);
1421 clickedParentItem->setData(column, Qt::CheckStateRole, vis?2:0);
1424 std::map<std::string, int> actorTypeCounts;
1425 for (int iChild = 0; iChild < clickedParentItem->childCount(); iChild++) {
1426 QTreeWidgetItem* currentChildItem = clickedParentItem->child(iChild);
1427 std::string actorType = currentChildItem->data(1,Qt::UserRole).toString().toStdString();
1428 vis = clickedSlicer->GetActorVisibility(actorType, actorTypeCounts[actorType]);
1429 if(currentChildItem == clickedItem) {
1430 // Toggle or force visibility if it was not on this branch so far
1431 vis = !draw || !vis;
1432 clickedSlicer->SetActorVisibility(actorType, actorTypeCounts[actorType], vis);
1434 currentChildItem->setData(column, Qt::CheckStateRole, vis?2:0);
1435 actorTypeCounts[actorType]++;
1440 clickedSlicer->Render();
1442 //------------------------------------------------------------------------------
1444 void vvMainWindow::InitSlicers()
1446 if (mSlicerManagers.size()) {
1447 mSlicerManagers.back()->GenerateDefaultLookupTable();
1449 mSlicerManagers.back()->SetSlicerWindow(0,NOViewWidget->GetRenderWindow());
1450 mSlicerManagers.back()->SetSlicerWindow(1,NEViewWidget->GetRenderWindow());
1451 mSlicerManagers.back()->SetSlicerWindow(2,SOViewWidget->GetRenderWindow());
1452 mSlicerManagers.back()->SetSlicerWindow(3,SEViewWidget->GetRenderWindow());
1456 //------------------------------------------------------------------------------
1457 void vvMainWindow::InitDisplay()
1459 if (mSlicerManagers.size()) {
1460 //BE CAREFUL : this is absolutely necessary to set the interactor style
1461 //in order to have the same style instanciation for all SlicerManagers in
1463 for (int j = 0; j < 4; j++) {
1464 vvInteractorStyleNavigator* style = vvInteractorStyleNavigator::New();
1465 style->SetAutoAdjustCameraClippingRange(1);
1466 bool AlreadySelected = false;
1467 for (int i = 0; i < DataTree->topLevelItemCount(); i++) {
1468 mSlicerManagers[i]->SetInteractorStyleNavigator(j,style);
1470 //select the image only if previous are not selected
1471 if (DataTree->topLevelItem(i)->data(j+1,Qt::CheckStateRole).toInt() > 1) {
1472 mSlicerManagers[i]->UpdateSlicer(j,1);
1473 AlreadySelected = true;
1474 } else if (i == DataTree->topLevelItemCount()-1 && !AlreadySelected) {
1475 if (DataTree->selectedItems().size() == 0)
1476 DataTree->topLevelItem(i)->setSelected(1);
1477 DataTree->topLevelItem(i)->setData(j+1,Qt::CheckStateRole,2);
1478 mSlicerManagers[i]->UpdateSlicer(j,1);
1479 DisplaySliders(i,j);
1481 DataTree->topLevelItem(i)->setData(j+1,Qt::CheckStateRole,0);
1482 mSlicerManagers[i]->UpdateSlicer(j,0);
1489 //------------------------------------------------------------------------------
1491 //------------------------------------------------------------------------------
1492 void vvMainWindow::DisplaySliders(int slicer, int window)
1495 mSlicerManagers[slicer]->GetSlicer(window)->GetSliceRange(range);
1496 int position = mSlicerManagers[slicer]->GetSlicer(window)->GetSlice();
1500 tRange[1] = mSlicerManagers[slicer]->GetSlicer(window)->GetTMax();
1501 int tPosition = mSlicerManagers[slicer]->GetSlicer(window)->GetTSlice();
1502 bool showHorizontal = false;
1503 bool showVertical = false;
1504 if (mSlicerManagers[slicer]->GetSlicer(window)->GetImage()->GetNumberOfDimensions() > 3
1505 || (mSlicerManagers[slicer]->GetSlicer(window)->GetImage()->GetNumberOfDimensions() > 2
1506 && mSlicerManagers[slicer]->GetType() != vvImageReader::IMAGEWITHTIME
1507 && mSlicerManagers[slicer]->GetType() != vvImageReader::MERGEDWITHTIME))
1508 showVertical = true;
1509 if (mSlicerManagers[slicer]->GetSlicer(window)->GetImage()->GetNumberOfDimensions() > 3
1510 || mSlicerManagers[slicer]->GetType() == vvImageReader::IMAGEWITHTIME
1511 || mSlicerManagers[slicer]->GetType() == vvImageReader::MERGEDWITHTIME)
1512 showHorizontal = true;
1515 verticalSliders[window]->show();
1517 verticalSliders[window]->hide();
1518 verticalSliders[window]->setRange(range[0],range[1]);
1519 verticalSliders[window]->setValue(position);
1522 horizontalSliders[window]->show();
1524 horizontalSliders[window]->hide();
1525 horizontalSliders[window]->setRange(tRange[0],tRange[1]);
1526 horizontalSliders[window]->setValue(tPosition);
1528 //------------------------------------------------------------------------------
1530 //------------------------------------------------------------------------------
1531 void vvMainWindow::CloseImage(QTreeWidgetItem* item, int column)
1533 int index = GetSlicerIndexFromItem(item);
1535 if (DataTree->topLevelItem(index) != item) {
1536 QString warning = "Do you really want to close the overlay : ";
1537 warning += item->data(COLUMN_IMAGE_NAME,Qt::DisplayRole).toString();
1538 QMessageBox msgBox(QMessageBox::Warning, tr("Close Overlay"),
1540 msgBox.addButton(tr("Close"), QMessageBox::AcceptRole);
1541 msgBox.addButton(tr("Cancel"), QMessageBox::RejectRole);
1542 if (msgBox.exec() == QMessageBox::AcceptRole) {
1543 std::string overlay_type=item->data(1,Qt::UserRole).toString().toStdString();
1544 int overlay_index=0;
1545 for (int child = 0; child < DataTree->topLevelItem(index)->childCount(); child++) {
1546 if (DataTree->topLevelItem(index)->\
1547 child(child)->data(1,Qt::UserRole).toString().toStdString() == overlay_type)
1549 if (DataTree->topLevelItem(index)->child(child) == item) break;
1551 mSlicerManagers[index]->RemoveActor(overlay_type, overlay_index-1);
1552 mSlicerManagers[index]->SetColorMap(0);
1553 DataTree->topLevelItem(index)->takeChild(DataTree->topLevelItem(index)->indexOfChild(item));
1554 mSlicerManagers[index]->Render();
1556 } else if (DataTree->topLevelItemCount() <= 1) {
1557 QString warning = "Do you really want to close the image : ";
1558 warning += item->data(COLUMN_IMAGE_NAME,Qt::DisplayRole).toString();
1559 warning += "\nThis is the last image, you're about to close vv !!!";
1560 QMessageBox msgBox(QMessageBox::Warning, tr("Close Image"),
1562 msgBox.addButton(tr("Close vv"), QMessageBox::AcceptRole);
1563 msgBox.addButton(tr("Cancel"), QMessageBox::RejectRole);
1564 if (msgBox.exec() == QMessageBox::AcceptRole) {
1568 QString warning = "Do you really want to close the image : ";
1569 warning += item->data(COLUMN_IMAGE_NAME,Qt::DisplayRole).toString();
1570 QMessageBox msgBox(QMessageBox::Warning, tr("Close Image"),
1572 msgBox.addButton(tr("Close"), QMessageBox::AcceptRole);
1573 msgBox.addButton(tr("Cancel"), QMessageBox::RejectRole);
1574 if (msgBox.exec() == QMessageBox::AcceptRole) {
1576 // Tell tools that we close an image
1577 emit AnImageIsBeingClosed(mSlicerManagers[index]);
1579 std::vector<vvSlicerManager*>::iterator Manageriter = mSlicerManagers.begin();
1580 DataTree->takeTopLevelItem(index);
1581 for (int i = 0; i < index; i++) {
1584 linkPanel->removeImage(index);
1585 mSlicerManagers[index]->RemoveActors();
1586 delete mSlicerManagers[index];
1587 mSlicerManagers.erase(Manageriter);
1595 //------------------------------------------------------------------------------
1597 //------------------------------------------------------------------------------
1598 void vvMainWindow::ReloadImage(QTreeWidgetItem* item, int column)
1600 // int index = GetSlicerIndexFromItem(item);
1601 // QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
1602 // if (item->data(1,Qt::UserRole).toString() == "vector")
1603 // mSlicerManagers[index]->ReloadVF();
1605 // mSlicerManagers[index]->Reload();
1607 // QApplication::restoreOverrideCursor();
1608 int index = GetSlicerIndexFromItem(item);
1609 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
1610 QString role=item->data(1,Qt::UserRole).toString();
1611 if ( role == "vector"){
1612 mSlicerManagers[index]->ReloadVF();
1614 else if (role == "overlay"){
1615 mSlicerManagers[index]->ReloadOverlay();
1617 else if (role == "fusion"){
1618 mSlicerManagers[index]->ReloadFusion();
1621 mSlicerManagers[index]->Reload();
1623 // Update view and info
1625 mSlicerManagers[index]->Render();
1626 QApplication::restoreOverrideCursor();
1628 //------------------------------------------------------------------------------
1630 //------------------------------------------------------------------------------
1631 void vvMainWindow::MousePositionChanged(int visibility,double x, double y, double z, double X, double Y, double Z , double value)
1633 infoPanel->setCurrentInfo(visibility,x,y,z,X,Y,Z,value);
1635 //------------------------------------------------------------------------------
1637 //------------------------------------------------------------------------------
1638 void vvMainWindow::VectorChanged(int visibility,double x, double y, double z, double value)
1640 overlayPanel->getCurrentVectorInfo(visibility,x,y,z,value);
1642 //------------------------------------------------------------------------------
1644 //------------------------------------------------------------------------------
1645 void vvMainWindow::OverlayChanged(int visibility, double valueOver, double valueRef)
1647 overlayPanel->getCurrentOverlayInfo(visibility,valueOver, valueRef);
1649 //------------------------------------------------------------------------------
1651 //------------------------------------------------------------------------------
1652 void vvMainWindow::FusionChanged(int visibility, double value)
1654 overlayPanel->getCurrentFusionInfo(visibility,value);
1656 //------------------------------------------------------------------------------
1658 //------------------------------------------------------------------------------
1659 void vvMainWindow::WindowLevelChanged()
1662 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
1663 if(index==-1) return;
1664 windowSpinBox->setValue(mSlicerManagers[index]->GetColorWindow());
1665 levelSpinBox->setValue(mSlicerManagers[index]->GetColorLevel());
1666 colorMapComboBox->setCurrentIndex(mSlicerManagers[index]->GetColorMap());
1667 presetComboBox->setCurrentIndex(mSlicerManagers[index]->GetPreset());
1670 if (mSlicerManagers[index]->GetSlicer(0)->GetOverlay())
1671 overlayPanel->getOverlayProperty(mSlicerManagers[index]->GetOverlayColor(),
1672 mSlicerManagers[index]->GetLinkOverlayWindowLevel(),
1673 mSlicerManagers[index]->GetOverlayColorWindow(),
1674 mSlicerManagers[index]->GetOverlayColorLevel());
1676 overlayPanel->getOverlayProperty(-1,0,0.,0.);
1679 if (mSlicerManagers[index]->GetSlicer(0)->GetFusion())
1680 overlayPanel->getFusionProperty(mSlicerManagers[index]->GetFusionOpacity(),
1681 mSlicerManagers[index]->GetFusionThresholdOpacity(),
1682 mSlicerManagers[index]->GetFusionColorMap(),
1683 mSlicerManagers[index]->GetFusionWindow(),
1684 mSlicerManagers[index]->GetFusionLevel());
1686 overlayPanel->getFusionProperty(-1, -1, -1, -1, -1);
1688 //------------------------------------------------------------------------------
1690 //------------------------------------------------------------------------------
1691 void vvMainWindow::WindowLevelEdited()
1693 presetComboBox->setCurrentIndex(6);
1694 UpdateWindowLevel();
1696 //------------------------------------------------------------------------------
1698 //------------------------------------------------------------------------------
1699 void vvMainWindow::SetWindowLevel(double w, double l)
1701 windowSpinBox->setValue(w);
1702 levelSpinBox->setValue(l);
1703 presetComboBox->setCurrentIndex(6);
1704 colorMapComboBox->setCurrentIndex(0);
1705 UpdateWindowLevel();
1707 //------------------------------------------------------------------------------
1709 //------------------------------------------------------------------------------
1710 void vvMainWindow::UpdateWindowLevel()
1712 if (DataTree->selectedItems().size()) {
1713 if (presetComboBox->currentIndex() == 7) //For ventilation
1714 colorMapComboBox->setCurrentIndex(5);
1715 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
1716 mSlicerManagers[index]->SetColorWindow(windowSpinBox->value());
1717 mSlicerManagers[index]->SetColorLevel(levelSpinBox->value());
1718 mSlicerManagers[index]->SetPreset(presetComboBox->currentIndex());
1719 mSlicerManagers[index]->Render();
1720 WindowLevelChanged();
1723 //------------------------------------------------------------------------------
1725 //------------------------------------------------------------------------------
1726 void vvMainWindow::UpdateSlicingPreset()
1728 if (DataTree->selectedItems().size()) {
1729 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
1730 mSlicerManagers[index]->SetSlicingPreset(slicingPresetComboBox->currentIndex());
1733 //------------------------------------------------------------------------------
1735 //------------------------------------------------------------------------------
1736 void vvMainWindow::UpdateColorMap()
1738 if (DataTree->selectedItems().size()) {
1739 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
1740 mSlicerManagers[index]->SetColorMap(colorMapComboBox->currentIndex());
1741 mSlicerManagers[index]->Render();
1744 //------------------------------------------------------------------------------
1745 void vvMainWindow::SwitchWindowLevel()
1747 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
1748 int window = mSlicerManagers[index]->GetColorWindow();
1749 presetComboBox->setCurrentIndex(6);
1750 windowSpinBox->setValue(-window);
1751 UpdateWindowLevel();
1753 //------------------------------------------------------------------------------
1755 //------------------------------------------------------------------------------
1756 void vvMainWindow::ApplyWindowLevelToAllImages()
1758 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
1759 if(index==-1) return;
1760 double window = mSlicerManagers[index]->GetColorWindow();
1761 double level = mSlicerManagers[index]->GetColorLevel();
1763 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
1764 if (mSlicerManagers[i] == NULL)
1766 mSlicerManagers[i]->SetColorWindow(window);
1767 mSlicerManagers[i]->SetColorLevel(level);
1768 mSlicerManagers[i]->SetPreset(6);
1769 mSlicerManagers[i]->Render();
1772 //------------------------------------------------------------------------------
1774 //------------------------------------------------------------------------------
1775 void vvMainWindow::UpdateLinkManager(std::string id, int slicer, double x, double y, double z, int temps)
1777 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
1778 if (mSlicerManagers[i]->GetId() == id) {
1779 //mSlicerManagers[i]->SetTSlice(temps);
1780 mSlicerManagers[i]->GetSlicer(slicer)->SetCurrentPosition(x,y,z,temps);
1781 mSlicerManagers[i]->UpdateViews(0,slicer);
1786 //------------------------------------------------------------------------------
1788 //------------------------------------------------------------------------------
1789 void vvMainWindow::UpdateLinkedNavigation(std::string id, vvSlicerManager * sm, vvSlicer* refSlicer)
1791 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
1792 if (id == mSlicerManagers[i]->GetId()) {
1793 mSlicerManagers[i]->UpdateLinkedNavigation(refSlicer);
1797 //------------------------------------------------------------------------------
1799 //------------------------------------------------------------------------------
1800 void vvMainWindow::ShowContextMenu(QPoint point)
1802 if (!DataTree->selectedItems().size()) {
1803 contextActions[1]->setEnabled(0);
1804 contextActions[2]->setEnabled(0);
1805 contextActions[3]->setEnabled(0);
1806 contextActions[4]->setEnabled(0);
1807 contextActions[5]->setEnabled(0);
1808 contextActions[6]->setEnabled(0);
1810 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
1811 contextActions[1]->setEnabled(1);
1812 contextActions[2]->setEnabled(
1813 DataTree->itemWidget(DataTree->selectedItems()[0],
1814 COLUMN_RELOAD_IMAGE)->isEnabled());
1815 contextActions[3]->setEnabled(1);
1816 contextActions[5]->setEnabled(1);
1817 contextActions[6]->setEnabled(1);
1819 if (mSlicerManagers[index]->GetDimension() < 3)
1820 contextActions[4]->setEnabled(0);
1822 contextActions[4]->setEnabled(1);
1824 contextMenu.exec(QCursor::pos());
1826 //------------------------------------------------------------------------------
1828 //------------------------------------------------------------------------------
1829 void vvMainWindow::CloseImage()
1831 CloseImage(DataTree->selectedItems()[0],0);
1833 //------------------------------------------------------------------------------
1835 //------------------------------------------------------------------------------
1836 void vvMainWindow::ReloadImage()
1838 ReloadImage(DataTree->selectedItems()[0],0);
1840 //------------------------------------------------------------------------------
1842 //------------------------------------------------------------------------------
1843 void vvMainWindow::SelectOverlayImage()
1845 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
1847 //check if one overlay image is added
1848 for (int child = 0; child < DataTree->topLevelItem(index)->childCount(); child++)
1849 if (DataTree->topLevelItem(index)->child(child)->data(1,Qt::UserRole).toString() == "overlay") {
1850 QString error = "Cannot add more than one compared image\n";
1851 error += "Please remove first ";
1852 error += DataTree->topLevelItem(index)->child(child)->data(COLUMN_IMAGE_NAME,Qt::DisplayRole).toString();
1853 QMessageBox::information(this,tr("Problem adding compared image !"),error);
1857 QString Extensions = EXTENSIONS;
1858 Extensions += ";;All Files (*)";
1859 QString file = QFileDialog::getOpenFileName(this,tr("Load Overlay image"),mInputPathName,Extensions);
1860 if (!file.isEmpty())
1861 AddOverlayImage(index,file);
1863 //------------------------------------------------------------------------------
1865 //------------------------------------------------------------------------------
1866 void vvMainWindow::AddOverlayImage(int index, QString file)
1868 if (QFile::exists(file))
1870 mInputPathName = itksys::SystemTools::GetFilenamePath(file.toStdString()).c_str();
1871 itk::ImageIOBase::Pointer reader = itk::ImageIOFactory::CreateImageIO(
1872 file.toStdString().c_str(), itk::ImageIOFactory::ReadMode);
1873 reader->SetFileName(file.toStdString().c_str());
1874 reader->ReadImageInformation();
1875 std::string component = reader->GetComponentTypeAsString(reader->GetComponentType());
1876 int dimension = reader->GetNumberOfDimensions();
1877 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
1878 vvProgressDialog progress("Opening " + file.toStdString());
1879 qApp->processEvents();
1881 std::string filename = itksys::SystemTools::GetFilenameWithoutExtension(file.toStdString()).c_str();
1882 if (mSlicerManagers[index]->SetOverlay(file.toStdString(),dimension, component)) {
1883 //create an item in the tree with good settings
1884 QTreeWidgetItem *item = new QTreeWidgetItem();
1885 item->setData(0,Qt::UserRole,file.toStdString().c_str());
1886 item->setData(1,Qt::UserRole,tr("overlay"));
1887 QFileInfo fileinfo(file); //Do not show the path
1888 item->setData(COLUMN_IMAGE_NAME,Qt::DisplayRole,fileinfo.fileName());
1889 item->setToolTip(COLUMN_IMAGE_NAME, mSlicerManagers[index]->GetListOfAbsoluteFilePathInOneString("overlay").c_str());
1890 qApp->processEvents();
1892 for (int j = 1; j <= 4; j++) {
1893 item->setData(j,Qt::CheckStateRole,DataTree->topLevelItem(index)->data(j,Qt::CheckStateRole));
1896 //Create the buttons for reload and close
1897 qApp->processEvents();
1898 QTreePushButton* cButton = new QTreePushButton;
1899 cButton->setItem(item);
1900 cButton->setColumn(COLUMN_CLOSE_IMAGE);
1901 cButton->setToolTip(tr("close image"));
1902 cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png")));
1903 connect(cButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
1904 this,SLOT(CloseImage(QTreeWidgetItem*, int)));
1906 QTreePushButton* rButton = new QTreePushButton;
1907 rButton->setItem(item);
1908 rButton->setColumn(COLUMN_RELOAD_IMAGE);
1909 rButton->setToolTip(tr("reload image"));
1910 rButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/rotateright.png")));
1911 connect(rButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
1912 this,SLOT(ReloadImage(QTreeWidgetItem*, int)));
1914 DataTree->topLevelItem(index)->setExpanded(1);
1915 DataTree->topLevelItem(index)->addChild(item);
1916 DataTree->setItemWidget(item, COLUMN_CLOSE_IMAGE, cButton);
1917 DataTree->setItemWidget(item, COLUMN_RELOAD_IMAGE, rButton);
1919 //set the id of the image
1920 QString id = DataTree->topLevelItem(index)->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString();
1921 item->setData(COLUMN_IMAGE_NAME,Qt::UserRole,id.toStdString().c_str());
1923 qApp->processEvents();
1925 QApplication::restoreOverrideCursor();
1927 QApplication::restoreOverrideCursor();
1928 QString error = "Cannot import the new image.\n";
1929 error += mSlicerManagers[index]->GetLastError().c_str();
1930 QMessageBox::information(this,tr("Problem reading image !"),error);
1932 WindowLevelChanged();
1935 QMessageBox::information(this,tr("Problem reading Overlay !"),"File doesn't exist!");
1937 //------------------------------------------------------------------------------
1940 //------------------------------------------------------------------------------
1941 void vvMainWindow::AddROI(int index, QString file)
1944 // Get slice manager
1948 vvImageReader * mReader = new vvImageReader;
1949 mReader->SetInputFilename(filename.toStdString());
1950 mReader->Update(IMAGE);
1951 if (mReader->GetLastError().size() != 0) {
1952 std::cerr << "Error while reading " << filename.toStdString() << std::endl;
1953 QString error = "Cannot open file \n";
1954 error += mReader->GetLastError().c_str();
1955 QMessageBox::information(this,tr("Reading problem"),error);
1959 vvImage::Pointer roi = mReader->GetOutput();
1961 // Create roi in new tool
1962 vvToolStructureSetManager::AddImage(mCurrentSlicerManager, roi);
1965 //------------------------------------------------------------------------------
1967 //------------------------------------------------------------------------------
1968 void vvMainWindow::SelectFusionImage()
1970 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
1972 //check if one fusion image is added
1973 for (int child = 0; child < DataTree->topLevelItem(index)->childCount(); child++)
1974 if (DataTree->topLevelItem(index)->child(child)->data(1,Qt::UserRole).toString() == "fusion") {
1975 QString error = "Cannot add more than one fusion image\n";
1976 error += "Please remove first ";
1977 error += DataTree->topLevelItem(index)->child(child)->data(COLUMN_IMAGE_NAME,Qt::DisplayRole).toString();
1978 QMessageBox::information(this,tr("Problem adding fusion image !"),error);
1982 QString Extensions = EXTENSIONS;
1983 Extensions += ";;All Files (*)";
1984 QString file = QFileDialog::getOpenFileName(this,tr("Load Fusion image"),mInputPathName,Extensions);
1985 if (!file.isEmpty())
1986 AddFusionImage(index,file);
1988 //------------------------------------------------------------------------------
1990 //------------------------------------------------------------------------------
1991 void vvMainWindow::ResetTransformationToIdentity()
1993 std::string actorType = DataTree->selectedItems()[0]->data(1,Qt::UserRole).toString().toStdString();
1994 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
1995 mSlicerManagers[index]->ResetTransformationToIdentity(actorType);
1998 //------------------------------------------------------------------------------
2000 //------------------------------------------------------------------------------
2001 void vvMainWindow::AddFusionImage(int index, QString file)
2003 if (QFile::exists(file))
2005 mInputPathName = itksys::SystemTools::GetFilenamePath(file.toStdString()).c_str();
2006 itk::ImageIOBase::Pointer reader = itk::ImageIOFactory::CreateImageIO(
2007 file.toStdString().c_str(), itk::ImageIOFactory::ReadMode);
2008 reader->SetFileName(file.toStdString().c_str());
2009 reader->ReadImageInformation();
2010 std::string component = reader->GetComponentTypeAsString(reader->GetComponentType());
2012 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
2013 vvProgressDialog progress("Opening fusion");
2014 qApp->processEvents();
2016 std::string filename = itksys::SystemTools::GetFilenameWithoutExtension(file.toStdString()).c_str();
2017 if (mSlicerManagers[index]->SetFusion(file.toStdString(),
2018 reader->GetNumberOfDimensions(), component)) {
2019 //create an item in the tree with good settings
2020 QTreeWidgetItem *item = new QTreeWidgetItem();
2021 item->setData(0,Qt::UserRole,file.toStdString().c_str());
2022 item->setData(1,Qt::UserRole,tr("fusion"));
2023 QFileInfo fileinfo(filename.c_str()); //Do not show the path
2024 item->setData(COLUMN_IMAGE_NAME,Qt::DisplayRole,fileinfo.fileName());
2025 item->setToolTip(COLUMN_IMAGE_NAME, mSlicerManagers[index]->GetListOfAbsoluteFilePathInOneString("fusion").c_str());
2026 qApp->processEvents();
2028 for (int j = 1; j <= 4; j++) {
2029 item->setData(j,Qt::CheckStateRole,DataTree->topLevelItem(index)->data(j,Qt::CheckStateRole));
2032 //Create the buttons for reload and close
2033 qApp->processEvents();
2034 QTreePushButton* cButton = new QTreePushButton;
2035 cButton->setItem(item);
2036 cButton->setColumn(COLUMN_CLOSE_IMAGE);
2037 cButton->setToolTip(tr("close image"));
2038 cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png")));
2039 connect(cButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
2040 this,SLOT(CloseImage(QTreeWidgetItem*, int)));
2042 QTreePushButton* rButton = new QTreePushButton;
2043 rButton->setItem(item);
2044 rButton->setColumn(COLUMN_RELOAD_IMAGE);
2045 rButton->setToolTip(tr("reload image"));
2046 rButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/rotateright.png")));
2047 connect(rButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
2048 this,SLOT(ReloadImage(QTreeWidgetItem*, int)));
2050 DataTree->topLevelItem(index)->setExpanded(1);
2051 DataTree->topLevelItem(index)->addChild(item);
2052 DataTree->setItemWidget(item, COLUMN_CLOSE_IMAGE, cButton);
2053 DataTree->setItemWidget(item, COLUMN_RELOAD_IMAGE, rButton);
2055 //set the id of the image
2056 QString id = DataTree->topLevelItem(index)->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString();
2057 item->setData(COLUMN_IMAGE_NAME,Qt::UserRole,id.toStdString().c_str());
2059 qApp->processEvents();
2061 QApplication::restoreOverrideCursor();
2063 QApplication::restoreOverrideCursor();
2064 QString error = "Cannot import the new image.\n";
2065 error += mSlicerManagers[index]->GetLastError().c_str();
2066 QMessageBox::information(this,tr("Problem reading image !"),error);
2069 QString error = "Cannot import the new image.\n";
2070 QMessageBox::information(this,tr("Problem reading image !"),error);
2074 QMessageBox::information(this,tr("Problem reading Fusion !"),"File doesn't exist!");
2076 //------------------------------------------------------------------------------
2079 //------------------------------------------------------------------------------
2080 void vvMainWindow::OpenField()
2082 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
2083 //check if a vector field has already been added
2084 for (int child = 0; child < DataTree->topLevelItem(index)->childCount(); child++)
2085 if (DataTree->topLevelItem(index)->child(child)->data(1,Qt::UserRole).toString() == "vector") {
2086 QString error = "Cannot add more than one vector field\n";
2087 error += "Please remove first ";
2088 error += DataTree->topLevelItem(index)->child(child)->data(COLUMN_IMAGE_NAME,Qt::DisplayRole).toString();
2089 QMessageBox::information(this,tr("Problem adding vector field!"),error);
2093 QString Extensions = "Images ( *.mhd)";
2094 Extensions += ";;Images ( *.mha)";
2095 Extensions += ";;Images ( *.vf)";
2096 QString file = QFileDialog::getOpenFileName(this,tr("Load deformation field"),mInputPathName,Extensions);
2097 if (!file.isEmpty())
2098 AddField(file,index);
2100 //------------------------------------------------------------------------------
2103 //------------------------------------------------------------------------------
2104 void vvMainWindow::AddFieldEntry(QString filename,int index,bool from_disk)
2106 //create an item in the tree with good settings
2107 QTreeWidgetItem *item = new QTreeWidgetItem();
2108 item->setData(0,Qt::UserRole,filename.toStdString().c_str());
2109 item->setData(1,Qt::UserRole,tr("vector"));
2110 QFileInfo fileinfo(filename); //Do not show the path
2111 item->setData(COLUMN_IMAGE_NAME,Qt::DisplayRole,fileinfo.fileName());
2112 item->setToolTip(COLUMN_IMAGE_NAME, mSlicerManagers[index]->GetListOfAbsoluteFilePathInOneString("vector").c_str());
2113 qApp->processEvents();
2115 for (int j = 1; j <= 4; j++) {
2116 item->setData(j,Qt::CheckStateRole,DataTree->topLevelItem(index)->data(j,Qt::CheckStateRole));
2119 //Create the buttons for reload and close
2120 qApp->processEvents();
2121 QTreePushButton* cButton = new QTreePushButton;
2122 cButton->setItem(item);
2123 cButton->setColumn(COLUMN_CLOSE_IMAGE);
2124 cButton->setToolTip(tr("close vector field"));
2125 cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png")));
2126 connect(cButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
2127 this,SLOT(CloseImage(QTreeWidgetItem*, int)));
2129 QTreePushButton* rButton = new QTreePushButton;
2130 rButton->setItem(item);
2131 rButton->setColumn(COLUMN_RELOAD_IMAGE);
2132 rButton->setToolTip(tr("reload vector field"));
2133 rButton->setEnabled(from_disk);
2134 rButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/rotateright.png")));
2135 connect(rButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
2136 this,SLOT(ReloadImage(QTreeWidgetItem*, int)));
2138 DataTree->topLevelItem(index)->setExpanded(1);
2139 DataTree->topLevelItem(index)->addChild(item);
2140 DataTree->setItemWidget(item, COLUMN_RELOAD_IMAGE, rButton);
2141 DataTree->setItemWidget(item, COLUMN_CLOSE_IMAGE, cButton);
2143 //set the id of the image
2144 QString id = DataTree->topLevelItem(index)->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString();
2145 item->setData(COLUMN_IMAGE_NAME,Qt::UserRole,id.toStdString().c_str());
2147 qApp->processEvents();
2149 QApplication::restoreOverrideCursor();
2151 //------------------------------------------------------------------------------
2154 //------------------------------------------------------------------------------
2155 void vvMainWindow::AddField(vvImage::Pointer vf,QString file,int index)
2157 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
2158 vvSlicerManager* imageManager = mSlicerManagers[index];
2159 if (imageManager->SetVF(vf,file.toStdString())) {
2160 AddFieldEntry(file,index,false);
2162 QString error = "Cannot import the vector field for this image.\n";
2163 error += imageManager->GetLastError().c_str();
2164 QMessageBox::information(this,tr("Problem reading VF !"),error);
2166 QApplication::restoreOverrideCursor();
2168 //------------------------------------------------------------------------------
2171 //------------------------------------------------------------------------------
2172 void vvMainWindow::AddField(QString file,int index)
2174 if (QFile::exists(file)) {
2175 mInputPathName = itksys::SystemTools::GetFilenamePath(file.toStdString()).c_str();
2177 //init the progress events
2178 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
2179 vvProgressDialog progress("Opening " + file.toStdString());
2180 qApp->processEvents();
2182 //read the vector and put it in the current mSlicerManager
2183 vvSlicerManager* imageManager = mSlicerManagers[index];
2184 qApp->processEvents();
2186 std::string filename = itksys::SystemTools::GetFilenameWithoutExtension(file.toStdString()).c_str();
2187 if (imageManager->SetVF(file.toStdString())) {
2188 imageManager->Render();
2189 AddFieldEntry(file,index,true);
2191 QApplication::restoreOverrideCursor();
2192 QString error = "Cannot import the vector field for this image.\n";
2193 error += imageManager->GetLastError().c_str();
2194 QMessageBox::information(this,tr("Problem reading VF !"),error);
2197 QMessageBox::information(this,tr("Problem reading VF !"),"File doesn't exist!");
2200 //------------------------------------------------------------------------------
2203 //------------------------------------------------------------------------------
2204 void vvMainWindow::SetVFProperty(int subsampling, int scale, int log, int width, double r, double g, double b)
2206 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
2207 if (mSlicerManagers[index]->GetSlicer(0)->GetVF()) {
2208 for (int i = 0; i < 4; i++) {
2209 mSlicerManagers[index]->GetSlicer(i)->SetVFSubSampling(subsampling);
2210 mSlicerManagers[index]->GetSlicer(i)->SetVFScale(scale);
2211 mSlicerManagers[index]->GetSlicer(i)->SetVFWidth(width);
2212 mSlicerManagers[index]->GetSlicer(i)->SetVFColor(r,g,b);
2214 mSlicerManagers[index]->GetSlicer(i)->SetVFLog(1);
2216 mSlicerManagers[index]->GetSlicer(i)->SetVFLog(0);
2220 //------------------------------------------------------------------------------
2223 //------------------------------------------------------------------------------
2224 void vvMainWindow::SetOverlayProperty(int color, int linked, double window, double level)
2226 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
2227 if (mSlicerManagers[index]->GetSlicer(0)->GetOverlay()) {
2228 mSlicerManagers[index]->SetOverlayColor(color);
2229 mSlicerManagers[index]->SetColorMap(0);
2230 mSlicerManagers[index]->SetLinkOverlayWindowLevel(linked);
2231 mSlicerManagers[index]->SetOverlayColorWindow(window);
2232 mSlicerManagers[index]->SetOverlayColorLevel(level);
2233 mSlicerManagers[index]->Render();
2236 //------------------------------------------------------------------------------
2238 //------------------------------------------------------------------------------
2239 void vvMainWindow::SetFusionProperty(int opacity, int thresOpacity, int colormap,double window, double level, bool showLegend)
2241 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
2242 if (mSlicerManagers[index]->GetSlicer(0)->GetFusion()) {
2243 mSlicerManagers[index]->SetFusionColorMap(colormap);
2244 mSlicerManagers[index]->SetFusionOpacity(opacity);
2245 mSlicerManagers[index]->SetFusionThresholdOpacity(thresOpacity);
2246 mSlicerManagers[index]->SetFusionWindow(window);
2247 mSlicerManagers[index]->SetFusionLevel(level);
2248 mSlicerManagers[index]->SetFusionShowLegend(showLegend);
2249 mSlicerManagers[index]->SetColorMap(0);
2250 mSlicerManagers[index]->Render();
2253 //------------------------------------------------------------------------------
2255 //------------------------------------------------------------------------------
2256 void vvMainWindow::SaveAs()
2258 if (DataTree->selectedItems()[0]->data(1,Qt::UserRole).toString() == "vector") {
2259 QMessageBox::warning(this,tr("Unsupported type"),tr("Sorry, saving a vector field is unsupported for the moment"));
2263 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
2264 int dimension = mSlicerManagers[index]->GetDimension();
2265 QStringList OutputListeFormat;
2266 OutputListeFormat.clear();
2267 if (dimension == 1) {
2268 OutputListeFormat.push_back(".mhd");
2269 OutputListeFormat.push_back(".mha");
2271 if (dimension == 2) {
2272 OutputListeFormat.push_back(".bmp");
2273 OutputListeFormat.push_back(".png");
2274 OutputListeFormat.push_back(".jpeg");
2275 OutputListeFormat.push_back(".tif");
2276 OutputListeFormat.push_back(".mhd");
2277 OutputListeFormat.push_back(".mha");
2278 OutputListeFormat.push_back(".hdr");
2279 OutputListeFormat.push_back(".vox");
2280 } else if (dimension == 3) {
2281 OutputListeFormat.push_back(".mhd");
2282 OutputListeFormat.push_back(".mha");
2283 OutputListeFormat.push_back(".nii");
2284 OutputListeFormat.push_back(".nrrd");
2285 OutputListeFormat.push_back(".nhdr");
2286 OutputListeFormat.push_back(".hdr");
2287 OutputListeFormat.push_back(".vox");
2288 } else if (dimension == 4) {
2289 OutputListeFormat.push_back(".mhd");
2290 OutputListeFormat.push_back(".mha");
2291 OutputListeFormat.push_back(".nii");
2292 OutputListeFormat.push_back(".nrrd");
2293 OutputListeFormat.push_back(".nhdr");
2295 QString Extensions = "AllFiles(*.*)";
2296 for (int i = 0; i < OutputListeFormat.count(); i++) {
2297 Extensions += ";;Images ( *";
2298 Extensions += OutputListeFormat[i];
2301 QString fileName = QFileDialog::getSaveFileName(this,
2303 mSlicerManagers[index]->GetFileName().c_str(),
2305 if (!fileName.isEmpty()) {
2306 std::string fileformat = itksys::SystemTools::GetFilenameLastExtension(fileName.toStdString());
2307 if (OutputListeFormat.contains(
2308 fileformat.c_str())) {
2309 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
2310 std::string action = "Saving";
2311 vvProgressDialog progress("Saving "+fileName.toStdString());
2312 qApp->processEvents();
2313 vvImageWriter::Pointer writer = vvImageWriter::New();
2314 writer->SetOutputFileName(fileName.toStdString());
2315 writer->SetInput(mSlicerManagers[index]->GetImage());
2317 // Check on transform and prompt user
2318 writer->SetSaveTransform(false);
2320 for(int i=0; i<4; i++)
2321 for(int j=0; j<4; j++) {
2322 double elt = mSlicerManagers[index]->GetImage()->GetTransform()->GetMatrix()->GetElement(i,j);
2329 QString warning = "The image has an associated linear transform. Do you want to save it along?";
2330 QMessageBox msgBox(QMessageBox::Warning, tr("Save transform"), warning, 0, this);
2331 msgBox.addButton(tr("Yes"), QMessageBox::AcceptRole);
2332 msgBox.addButton(tr("No"), QMessageBox::RejectRole);
2333 if (msgBox.exec() == QMessageBox::AcceptRole)
2334 writer->SetSaveTransform(true);
2338 QApplication::restoreOverrideCursor();
2339 if (writer->GetLastError().size()) {
2340 QString error = "Saving did not succeed\n";
2341 error += writer->GetLastError().c_str();
2342 QMessageBox::information(this,tr("Saving Problem"),error);
2346 QString error = fileformat.c_str();
2347 if (error.isEmpty())
2348 error += "no file format specified !";
2350 error += " format unknown !!!\n";
2351 QMessageBox::information(this,tr("Saving Problem"),error);
2356 //------------------------------------------------------------------------------
2358 //------------------------------------------------------------------------------
2359 void vvMainWindow::SaveCurrentState()
2361 QString Extensions = "XML Files(*.xml)";
2362 QString fileName = QFileDialog::getSaveFileName(this,
2363 tr("Save Current Window State"),
2367 SaveCurrentStateAs(fileName.toStdString());
2369 //------------------------------------------------------------------------------
2371 //------------------------------------------------------------------------------
2372 void vvMainWindow::SaveCurrentStateAs(const std::string& stateFile)
2374 vvSaveState save_state;
2375 save_state.Run(this, stateFile);
2378 //------------------------------------------------------------------------------
2379 void vvMainWindow::ReadSavedState()
2381 QString Extensions = "XML Files(*.xml)";
2382 QString fileName = QFileDialog::getOpenFileName(this,
2383 tr("Load Window State"),
2387 ReadSavedStateFile(fileName.toStdString());
2389 //------------------------------------------------------------------------------
2391 //------------------------------------------------------------------------------
2392 void vvMainWindow::ReadSavedStateFile(const std::string& stateFile)
2394 vvReadState read_state;
2395 read_state.Run(this, stateFile);
2397 //------------------------------------------------------------------------------
2399 //------------------------------------------------------------------------------
2400 void vvMainWindow::LinkAllImages()
2402 linkPanel->linkAll();
2405 //------------------------------------------------------------------------------
2406 void vvMainWindow::AddLink(QString image1,QString image2)
2408 unsigned int sm1 = 0;
2409 unsigned int sm2 = 0;
2411 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
2412 if (image1.toStdString() == mSlicerManagers[i]->GetId()) {
2413 mSlicerManagers[i]->AddLink(image2.toStdString());
2416 if (image2.toStdString() == mSlicerManagers[i]->GetId()) {
2417 mSlicerManagers[i]->AddLink(image1.toStdString());
2422 if (linkPanel->isLinkAll()) {
2423 emit UpdateLinkedNavigation(mSlicerManagers[sm1]->GetId(), mSlicerManagers[mCurrentPickedImageIndex], mSlicerManagers[mCurrentPickedImageIndex]->GetSlicer(0));
2424 emit UpdateLinkedNavigation(mSlicerManagers[sm2]->GetId(), mSlicerManagers[mCurrentPickedImageIndex], mSlicerManagers[mCurrentPickedImageIndex]->GetSlicer(0));
2426 emit UpdateLinkedNavigation(mSlicerManagers[sm2]->GetId(), mSlicerManagers[sm1], mSlicerManagers[sm1]->GetSlicer(0));
2430 //------------------------------------------------------------------------------
2433 //------------------------------------------------------------------------------
2434 void vvMainWindow::RemoveLink(QString image1,QString image2)
2436 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
2437 if (image1.toStdString() == mSlicerManagers[i]->GetId()) {
2438 mSlicerManagers[i]->RemoveLink(image2.toStdString());
2440 if (image2.toStdString() == mSlicerManagers[i]->GetId()) {
2441 mSlicerManagers[i]->RemoveLink(image1.toStdString());
2445 //------------------------------------------------------------------------------
2447 //------------------------------------------------------------------------------
2448 void vvMainWindow::ChangeImageWithIndexOffset(vvSlicerManager *sm, int slicer, int offset)
2450 if(mSlicerManagers.size()==1)
2454 while(sm != mSlicerManagers[index])
2456 index = (index+offset+mSlicerManagers.size()) % mSlicerManagers.size();
2458 QTreeWidgetItem* item = GetItemFromSlicerManager(mSlicerManagers[index]);
2459 item->setData(slicer+1,Qt::CheckStateRole,2); //change checkbox
2460 CurrentImageChanged(mSlicerManagers[index]->GetId()); //select new image
2461 DisplayChanged(item,slicer+1);
2463 //------------------------------------------------------------------------------
2465 void vvMainWindow::HorizontalSliderMoved(int value,int column, int slicer_index)
2467 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
2468 if (DataTree->topLevelItem(i)->data(column,Qt::CheckStateRole).toInt() > 1) {
2469 for (int j = 0; j < 4; j++) {
2470 mSlicerManagers[i]->SetTSliceInSlicer(value,j);
2471 //if (mSlicerManagers[i]->GetSlicer(j)->GetImageActor()->GetVisibility())
2472 //UpdateTSlice(j,value);
2474 mSlicerManagers[i]->GetSlicer(slicer_index)->Render();
2479 //------------------------------------------------------------------------------
2482 //------------------------------------------------------------------------------
2483 void vvMainWindow::NOHorizontalSliderMoved()
2485 // if (mCurrentTime == NOHorizontalSlider->value()) return;
2486 HorizontalSliderMoved(NOHorizontalSlider->value(),COLUMN_UL_VIEW,0);
2487 // mCurrentTime = NOHorizontalSlider->value();
2489 //------------------------------------------------------------------------------
2492 //------------------------------------------------------------------------------
2493 void vvMainWindow::NEHorizontalSliderMoved()
2495 // if (mCurrentTime == NEHorizontalSlider->value()) return;
2496 HorizontalSliderMoved(NEHorizontalSlider->value(),COLUMN_UR_VIEW,1);
2497 // mCurrentTime = NEHorizontalSlider->value();
2499 //------------------------------------------------------------------------------
2502 //------------------------------------------------------------------------------
2503 void vvMainWindow::SOHorizontalSliderMoved()
2505 // if (mCurrentTime == SOHorizontalSlider->value()) return;
2506 HorizontalSliderMoved(SOHorizontalSlider->value(),COLUMN_DL_VIEW,2);
2507 // mCurrentTime = SOHorizontalSlider->value();
2509 //------------------------------------------------------------------------------
2512 //------------------------------------------------------------------------------
2513 void vvMainWindow::SEHorizontalSliderMoved()
2515 // if (mCurrentTime == SEHorizontalSlider->value()) return;
2516 HorizontalSliderMoved(SEHorizontalSlider->value(),COLUMN_DR_VIEW,3);
2517 // mCurrentTime = SEHorizontalSlider->value();
2519 //------------------------------------------------------------------------------
2521 //------------------------------------------------------------------------------
2522 void vvMainWindow::NOVerticalSliderChanged()
2524 static int value=-1;
2525 if (value == NOVerticalSlider->value()) return;
2526 else value = NOVerticalSlider->value();
2527 // int value = NOVerticalSlider->value();
2528 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
2529 if (DataTree->topLevelItem(i)->data(COLUMN_UL_VIEW,Qt::CheckStateRole).toInt() > 1) {
2530 if (mSlicerManagers[i]->GetSlicer(0)->GetSlice() != value) {
2531 mSlicerManagers[i]->GetSlicer(0)->SetSlice(value);
2532 mSlicerManagers[i]->VerticalSliderHasChanged(0, value);
2534 // If nor Update/Render -> slider not work
2535 // only render = ok navigation, but for contour Update needed but slower ?
2537 mSlicerManagers[i]->UpdateSlice(0); // <-- DS add this. Not too much update ? YES. but needed for ImageContour ...
2538 //mSlicerManagers[i]->GetSlicer(0)->Render(); // <-- DS add this, needed for contour, seems ok ? not too slow ?
2544 //------------------------------------------------------------------------------
2547 //------------------------------------------------------------------------------
2548 void vvMainWindow::NEVerticalSliderChanged()
2550 static int value=-1;
2551 if (value == NEVerticalSlider->value()) return;
2552 else value = NEVerticalSlider->value();
2553 // int value = NEVerticalSlider->value();
2554 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
2555 if (DataTree->topLevelItem(i)->data(COLUMN_UR_VIEW,Qt::CheckStateRole).toInt() > 1) {
2556 if (mSlicerManagers[i]->GetSlicer(1)->GetSlice() != value) {
2557 mSlicerManagers[i]->GetSlicer(1)->SetSlice(value);
2558 mSlicerManagers[i]->VerticalSliderHasChanged(1, value);
2559 mSlicerManagers[i]->UpdateSlice(1);
2560 //mSlicerManagers[i]->GetSlicer(1)->Render(); // <-- DS add this, needed for contour, seems ok ? not too slow ?
2566 //------------------------------------------------------------------------------
2569 //------------------------------------------------------------------------------
2570 void vvMainWindow::SOVerticalSliderChanged()
2572 static int value=-1;
2573 if (value == SOVerticalSlider->value()) return;
2574 else value = SOVerticalSlider->value();
2575 //int value = SOVerticalSlider->value();
2576 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
2577 if (DataTree->topLevelItem(i)->data(COLUMN_DL_VIEW,Qt::CheckStateRole).toInt() > 1) {
2578 if (mSlicerManagers[i]->GetSlicer(2)->GetSlice() != value) {
2579 mSlicerManagers[i]->GetSlicer(2)->SetSlice(value);
2580 mSlicerManagers[i]->VerticalSliderHasChanged(2, value);
2581 mSlicerManagers[i]->UpdateSlice(2);
2582 //mSlicerManagers[i]->GetSlicer(2)->Render(); // <-- DS add this, needed for contour, seems ok ? not too slow ?
2584 // else { DD("avoid SOVerticalSlider slicer update"); }
2589 //------------------------------------------------------------------------------
2592 //------------------------------------------------------------------------------
2593 void vvMainWindow::SEVerticalSliderChanged()
2595 static int value=-1;
2596 if (value == SEVerticalSlider->value()) return;
2597 else value = SEVerticalSlider->value();
2598 // int value = SEVerticalSlider->value();
2599 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
2600 if (DataTree->topLevelItem(i)->data(COLUMN_DR_VIEW,Qt::CheckStateRole).toInt() > 1) {
2601 if (mSlicerManagers[i]->GetSlicer(3)->GetSlice() != value) {
2602 mSlicerManagers[i]->GetSlicer(3)->SetSlice(value);
2603 mSlicerManagers[i]->VerticalSliderHasChanged(3, value);
2604 mSlicerManagers[i]->UpdateSlice(3);
2605 //mSlicerManagers[i]->GetSlicer(3)->Render(); // <-- DS add this, needed for contour, seems ok ? not too slow ?
2611 //------------------------------------------------------------------------------
2614 //------------------------------------------------------------------------------
2615 void vvMainWindow::UpdateSlice(int slicer, int slice)
2617 // DD("vvMainWindow::UpdateSlice");
2621 // if (slice != NOVerticalSlider->value())
2622 NOVerticalSlider->setValue(slice);
2625 NEVerticalSlider->setValue(slice);
2628 SOVerticalSlider->setValue(slice);
2631 SEVerticalSlider->setValue(slice);
2635 // DD("vvMainWindow:UpdateSlice END");
2637 //------------------------------------------------------------------------------
2640 //------------------------------------------------------------------------------
2641 void vvMainWindow::UpdateTSlice(int slicer, int slice)
2645 NOHorizontalSlider->setValue(slice);
2648 NEHorizontalSlider->setValue(slice);
2651 SOHorizontalSlider->setValue(slice);
2654 SEHorizontalSlider->setValue(slice);
2658 //------------------------------------------------------------------------------
2661 //------------------------------------------------------------------------------
2662 void vvMainWindow::UpdateSliceRange(int slicer, int min, int max, int tmin, int tmax)
2664 int position = int((min+max)/2);
2666 NOVerticalSlider->setValue(position);
2667 NOVerticalSlider->setRange(min,max);
2668 NOHorizontalSlider->setRange(tmin,tmax);
2669 } else if (slicer == 1) {
2670 NEVerticalSlider->setValue(position);
2671 NEVerticalSlider->setRange(min,max);
2672 NEHorizontalSlider->setRange(tmin,tmax);
2673 } else if (slicer == 2) {
2674 SOVerticalSlider->setValue(position);
2675 SOVerticalSlider->setRange(min,max);
2676 SOHorizontalSlider->setRange(tmin,tmax);
2677 } else if (slicer == 3) {
2678 SEVerticalSlider->setValue(position);
2679 SEVerticalSlider->setRange(min,max);
2680 SEHorizontalSlider->setRange(tmin,tmax);
2683 //------------------------------------------------------------------------------
2686 //------------------------------------------------------------------------------
2687 void vvMainWindow::SaveNOScreenshot()
2689 SaveScreenshot(NOViewWidget);
2691 //------------------------------------------------------------------------------
2694 //------------------------------------------------------------------------------
2695 void vvMainWindow::SaveNEScreenshot()
2697 SaveScreenshot(NEViewWidget);
2699 //------------------------------------------------------------------------------
2702 //------------------------------------------------------------------------------
2703 void vvMainWindow::SaveSOScreenshot()
2705 SaveScreenshot(SOViewWidget);
2707 //------------------------------------------------------------------------------
2710 //------------------------------------------------------------------------------
2711 void vvMainWindow::SaveSEScreenshot()
2713 SaveScreenshot(SEViewWidget);
2715 //------------------------------------------------------------------------------
2718 //------------------------------------------------------------------------------
2719 void vvMainWindow::SaveScreenshotAllSlices()
2721 QVTKWidget *widget = NOViewWidget;
2723 int index = 0;// GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
2724 vvSlicerManager * SM = mSlicerManagers[index];
2725 vvImage * image = SM->GetImage();
2726 vvSlicer * slicer = SM->GetSlicer(0);
2727 int orientation = slicer->GetOrientation();
2728 int nbSlices = image->GetSize()[orientation];
2729 vtkSmartPointer<vtkRenderWindow> renderWindow = widget->GetRenderWindow();
2731 // Select filename base
2732 QString filename = QFileDialog::getSaveFileName(this,
2733 tr("Save As (filename will be completed by slice number)"),
2734 itksys::SystemTools::GetFilenamePath(mSlicerManagers[index]->GetFileName()).c_str(),
2735 "Images( *.png);;Images( *.jpg)");
2738 for(int i=0; i<nbSlices; i++) {
2740 slicer->SetSlice(i); // -> change the slice of the current slicer
2741 SM->UpdateSlice(0); // --> this one emit UpdateSlice
2742 QCoreApplication::flush(); // -> needed to force display of contours
2745 vtkSmartPointer<vtkWindowToImageFilter> windowToImageFilter = vtkSmartPointer<vtkWindowToImageFilter>::New();
2746 windowToImageFilter->SetInput(renderWindow);
2747 windowToImageFilter->SetMagnification(1);
2748 windowToImageFilter->SetInputBufferTypeToRGBA(); //also record the alpha (transparency) channel
2749 windowToImageFilter->Update();
2751 vtkSmartPointer<vtkPNGWriter> writer = vtkSmartPointer<vtkPNGWriter>::New();
2752 std::string fn = itksys::SystemTools::GetFilenameWithoutLastExtension(filename.toStdString());
2753 std::string num = clitk::toString(i);
2754 if (i<10) num = "0"+num;
2755 if (i<100) num = "0"+num;
2756 if (i<1000) num = "0"+num;
2758 fn = itksys::SystemTools::GetFilenamePath(filename.toStdString()) + "/"+ fn
2759 + "_" + num + itksys::SystemTools::GetFilenameLastExtension(filename.toStdString());
2760 writer->SetFileName(fn.c_str());
2761 writer->SetInput(windowToImageFilter->GetOutput());
2765 //------------------------------------------------------------------------------
2768 //------------------------------------------------------------------------------
2769 void vvMainWindow::SaveScreenshot(QVTKWidget *widget)
2771 QString Extensions = "Images( *.png);;";
2772 Extensions += "Images( *.jpg);;";
2773 Extensions += "Images( *.bmp);;";
2774 Extensions += "Images( *.tif);;";
2775 Extensions += "Images( *.ppm)";
2776 #if defined(VTK_USE_FFMPEG_ENCODER) || defined(VTK_USE_VIDEO_FOR_WINDOWS)
2777 Extensions += ";;Video( *.avi)";
2779 #ifdef VTK_USE_MPEG2_ENCODER
2780 Extensions += ";;Video( *.mpg)";
2782 #ifdef CLITK_EXPERIMENTAL
2783 Extensions += ";;Video( *.gif)";
2786 int smIndex=GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
2787 QString fileName = QFileDialog::getSaveFileName(this,
2789 itksys::SystemTools::GetFilenamePath(mSlicerManagers[smIndex]->GetFileName()).c_str(),
2792 if (!fileName.isEmpty()) {
2793 vtkSmartPointer<vtkWindowToImageFilter> w2i = vtkSmartPointer<vtkWindowToImageFilter>::New();
2794 w2i->SetInput(widget->GetRenderWindow());
2796 vtkImageData *image = w2i->GetOutput();
2798 std::string ext(itksys::SystemTools::GetFilenameLastExtension(fileName.toStdString()));
2801 vtkImageWriter *imgwriter = NULL;
2803 imgwriter = vtkBMPWriter::New();
2804 else if (ext==".tif")
2805 imgwriter = vtkTIFFWriter::New();
2806 else if (ext==".ppm")
2807 imgwriter = vtkPNMWriter::New();
2808 else if (ext==".png")
2809 imgwriter = vtkPNGWriter::New();
2810 else if (ext==".jpg")
2811 imgwriter = vtkJPEGWriter::New();
2813 // Snapshot image if not null
2814 if(imgwriter!=NULL) {
2815 imgwriter->SetInput(image);
2816 imgwriter->SetFileName(fileName.toStdString().c_str());
2822 vtkGenericMovieWriter *vidwriter = NULL;
2823 #if CLITK_EXPERIMENTAL == 1
2825 vvAnimatedGIFWriter *gif = vvAnimatedGIFWriter::New();
2830 int fps = QInputDialog::getInteger(this, tr("Number of frames per second"),
2831 tr("FPS:"), 5, 0, 1000, 1, &ok);
2836 int loops = QInputDialog::getInteger(this, tr("Loops"),
2837 tr("Number of loops (0 means infinite):"), 0, 0, 1000000000, 1, &ok);
2839 gif->SetLoops(loops);
2842 QString msg = "Would you like to activate dithering?";
2843 QMessageBox msgBox(QMessageBox::Question, tr("Dithering"),msg, 0, this);
2844 msgBox.addButton(tr("Yes"), QMessageBox::AcceptRole);
2845 msgBox.addButton(tr("No"), QMessageBox::RejectRole);
2846 gif->SetDither(msgBox.exec() == QMessageBox::AcceptRole);
2849 #ifdef VTK_USE_VIDEO_FOR_WINDOWS
2851 vtkAVIWriter *mpg = vtkAVIWriter::New();
2855 int fps = QInputDialog::getInteger(this, tr("Number of frames per second"),
2856 tr("FPS:"), 5, 0, 1024, 1, &ok);
2862 #ifdef VTK_USE_FFMPEG_ENCODER
2864 vtkFFMPEGWriter *mpg = vtkFFMPEGWriter::New();
2868 int fps = QInputDialog::getInteger(this, tr("Number of frames per second"),
2869 tr("FPS:"), 5, 0, 1024, 1, &ok);
2873 mpg->SetBitRateTolerance(int(ceil(12.0*1024*1024/fps)));
2876 #ifdef VTK_USE_MPEG2_ENCODER
2878 vtkMPEG2Writer *mpg = vtkMPEG2Writer::New();
2883 // Take video if not null
2884 if(vidwriter!=NULL){
2885 vidwriter->SetInput(image);
2886 vidwriter->SetFileName(fileName.toStdString().c_str());
2888 vvImage * vvImg = mSlicerManagers[smIndex]->GetImage();
2889 int nSlice = vvImg->GetVTKImages().size();
2890 for(int i=0; i<nSlice; i++) {
2891 mSlicerManagers[smIndex]->SetNextTSlice(0);
2892 vtkSmartPointer<vtkWindowToImageFilter> w2i = vtkSmartPointer<vtkWindowToImageFilter>::New();
2893 w2i->SetInput(widget->GetRenderWindow());
2895 vidwriter->SetInput(w2i->GetOutput());
2899 vidwriter->Delete();
2903 QMessageBox::information(this,tr("Problem saving screenshot !"),tr("Cannot save image.\nPlease set a file extension !!!"));
2906 //------------------------------------------------------------------------------
2909 //------------------------------------------------------------------------------
2910 void vvMainWindow::GoToCursor()
2912 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
2913 for (int column = 1; column < 5; column++) {
2914 if (DataTree->selectedItems()[0]->data(column,Qt::CheckStateRole).toInt() > 1) {
2915 double* cursorPos = mSlicerManagers[index]->GetSlicer(column-1)->GetCursorPosition();
2916 mSlicerManagers[index]->GetSlicer(column-1)->SetCurrentPosition(
2917 cursorPos[0],cursorPos[1],cursorPos[2],cursorPos[3]);
2918 mSlicerManagers[index]->UpdateViews(1,column-1);
2919 mSlicerManagers[index]->UpdateLinked(column-1);
2924 //------------------------------------------------------------------------------
2926 //------------------------------------------------------------------------------
2927 void vvMainWindow::PlayPause()
2931 playButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/player_play.png")));
2935 int image_number=DataTree->topLevelItemCount();
2937 for (int i=0; i<image_number; i++)
2938 if (mSlicerManagers[i]->GetImage()->GetVTKImages().size() > 1) {
2944 playButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/player_pause.png")));
2945 QTimer::singleShot(1000/mFrameRate, this, SLOT(PlayNext()));
2949 //------------------------------------------------------------------------------
2951 //------------------------------------------------------------------------------
2952 void vvMainWindow::PlayNext()
2954 if (playMode && !this->isHidden()) {
2955 int image_number=DataTree->topLevelItemCount();
2956 ///Only play one slicer per SM, and only if the SM is being displayed
2957 for (int i=0; i<image_number; i++)
2958 for (int j=0; j<4; j++)
2959 if (mSlicerManagers[i]->GetImage()->GetVTKImages().size() > 1 &&
2960 DataTree->topLevelItem(i)->data(j+1,Qt::CheckStateRole).toInt() > 0) {
2961 mSlicerManagers[i]->SetNextTSlice(j);
2964 QTimer::singleShot(1000/mFrameRate, this, SLOT(PlayNext()));
2967 //------------------------------------------------------------------------------
2969 void vvMainWindow::ShowLastImage()
2971 if (mSlicerManagers.size() > 1) {
2972 QTreeWidgetItem * item=DataTree->topLevelItem(DataTree->topLevelItemCount()-1);
2973 CurrentImageChanged(mSlicerManagers.back()->GetId()); //select new image
2974 item->setData(1,Qt::CheckStateRole,2); //show the new image in the first panel
2975 DisplayChanged(item,1);
2979 //------------------------------------------------------------------------------
2980 void vvMainWindow::UpdateRenderWindows()
2982 if (NOViewWidget->GetRenderWindow()) NOViewWidget->GetRenderWindow()->Render();
2983 if (NEViewWidget->GetRenderWindow()) NEViewWidget->GetRenderWindow()->Render();
2984 if (SOViewWidget->GetRenderWindow()) SOViewWidget->GetRenderWindow()->Render();
2985 if (SEViewWidget->GetRenderWindow()) SEViewWidget->GetRenderWindow()->Render();
2987 //------------------------------------------------------------------------------
2989 //------------------------------------------------------------------------------
2990 void vvMainWindow::SegmentationOnCurrentImage()
2992 int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
2994 vvSegmentationDialog segmentation;
2995 segmentation.SetImage(mSlicerManagers[index]->GetSlicer(0)->GetImage());
2996 segmentation.exec();
2998 //------------------------------------------------------------------------------
3000 void vvMainWindow::SurfaceViewerLaunch()
3002 vvSurfaceViewerDialog surfaceViewer;
3003 surfaceViewer.exec();
3005 //------------------------------------------------------------------------------
3008 //------------------------------------------------------------------------------
3009 int vvMainWindow::GetImageDuplicateFilenameNumber(std::string filename)
3012 for(unsigned int l=0; l<mSlicerManagers.size(); l++) {
3013 vvSlicerManager * v = mSlicerManagers[l];
3014 if (v->GetBaseFileName() ==
3015 vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(filename))) {
3016 number = std::max(number, v->GetBaseFileNameNumber()+1);
3021 //------------------------------------------------------------------------------
3024 //------------------------------------------------------------------------------
3025 vvSlicerManager* vvMainWindow::AddImage(vvImage::Pointer image,std::string filename)
3027 // Change filename if another image exist with the same name
3028 int number = GetImageDuplicateFilenameNumber(filename);
3030 // Create new SliceManager
3031 vvSlicerManager* slicer_manager = new vvSlicerManager(4);
3032 slicer_manager->SetImage(image);//, IMAGE, number);
3033 // filename = filename+"_"+clitk::toString(number);
3034 slicer_manager->SetFilename(filename, number);
3035 mSlicerManagers.push_back(slicer_manager);
3037 //create an item in the tree with good settings
3038 QTreeWidgetItem *item = new QTreeWidgetItem();
3039 item->setData(0,Qt::UserRole,slicer_manager->GetFileName().c_str());//files[i].c_str());
3040 item->setData(1,Qt::UserRole,tr("image"));
3041 item->setData(COLUMN_IMAGE_NAME,Qt::DisplayRole,slicer_manager->GetFileName().c_str());//filename.c_str());
3042 qApp->processEvents();
3044 for (int j = 1; j <= 4; j++) item->setData(j,Qt::CheckStateRole,1);
3046 //Create the buttons for reload and close
3047 qApp->processEvents();
3048 QTreePushButton* cButton = new QTreePushButton;
3049 cButton->setItem(item);
3050 cButton->setColumn(COLUMN_CLOSE_IMAGE);
3051 cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png")));
3052 connect(cButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
3053 this,SLOT(CloseImage(QTreeWidgetItem*, int)));
3055 QTreePushButton* rButton = new QTreePushButton;
3056 rButton->setItem(item);
3057 rButton->setColumn(COLUMN_RELOAD_IMAGE);
3058 rButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/rotateright.png")));
3059 rButton->setEnabled(0);
3060 connect(rButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
3061 this,SLOT(ReloadImage(QTreeWidgetItem*, int)));
3063 DataTree->addTopLevelItem(item);
3064 DataTree->setItemWidget(item, COLUMN_CLOSE_IMAGE, cButton);
3065 DataTree->setItemWidget(item, COLUMN_RELOAD_IMAGE, rButton);
3067 //set the id of the image
3068 QString id = slicer_manager->GetFileName().c_str() + QString::number(mSlicerManagers.size()-1);
3069 item->setData(COLUMN_IMAGE_NAME,Qt::UserRole,id.toStdString().c_str());
3070 mSlicerManagers.back()->SetId(id.toStdString());
3072 linkPanel->addImage(slicer_manager->GetFileName().c_str()// filename
3073 , id.toStdString());
3075 connect(mSlicerManagers.back(), SIGNAL(currentImageChanged(std::string)),
3076 this, SLOT(CurrentImageChanged(std::string)));
3077 connect(mSlicerManagers.back(), SIGNAL(currentPickedImageChanged(std::string)),
3078 this, SLOT(CurrentPickedImageChanged(std::string)));
3079 connect(mSlicerManagers.back(), SIGNAL(UpdatePosition(int, double, double, double, double, double, double, double)),
3080 this, SLOT(MousePositionChanged(int,double, double, double, double, double, double, double)));
3081 connect(mSlicerManagers.back(), SIGNAL(UpdateVector(int, double, double, double, double)),
3082 this, SLOT(VectorChanged(int,double,double,double, double)));
3083 connect(mSlicerManagers.back(), SIGNAL(UpdateOverlay(int, double, double)),
3084 this, SLOT(OverlayChanged(int,double,double)));
3085 connect(mSlicerManagers.back(), SIGNAL(UpdateFusion(int, double)),
3086 this, SLOT(FusionChanged(int,double)));
3087 connect(mSlicerManagers.back(), SIGNAL(WindowLevelChanged()),
3088 this,SLOT(WindowLevelChanged()));
3089 connect(mSlicerManagers.back(), SIGNAL(UpdateSlice(int,int)),
3090 this,SLOT(UpdateSlice(int,int)));
3091 connect(mSlicerManagers.back(), SIGNAL(UpdateTSlice(int, int)),
3092 this,SLOT(UpdateTSlice(int, int)));
3093 connect(mSlicerManagers.back(), SIGNAL(UpdateSliceRange(int,int,int,int,int)),
3094 this,SLOT(UpdateSliceRange(int,int,int,int,int)));
3095 connect(mSlicerManagers.back(), SIGNAL(UpdateLinkManager(std::string,int,double,double,double,int)),
3096 this,SLOT(UpdateLinkManager(std::string,int,double,double,double,int)));
3097 connect(mSlicerManagers.back(), SIGNAL(UpdateLinkedNavigation(std::string,vvSlicerManager*,vvSlicer*)),
3098 this,SLOT(UpdateLinkedNavigation(std::string,vvSlicerManager*,vvSlicer*)));
3099 connect(mSlicerManagers.back(), SIGNAL(ChangeImageWithIndexOffset(vvSlicerManager*,int,int)),
3100 this,SLOT(ChangeImageWithIndexOffset(vvSlicerManager*,int,int)));
3101 connect(mSlicerManagers.back(), SIGNAL(LandmarkAdded()),landmarksPanel,SLOT(AddPoint()));
3103 qApp->processEvents();
3107 qApp->processEvents();
3111 return slicer_manager;
3113 //------------------------------------------------------------------------------
3116 //------------------------------------------------------------------------------
3117 void vvMainWindow::UpdateCurrentSlicer()
3120 if (DataTree->selectedItems().size() > 0) {
3121 index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
3123 mSlicerManagerCurrentIndex = index;
3125 //------------------------------------------------------------------------------