]> Creatis software - clitk.git/blobdiff - vv/vvMainWindow.cxx
Added Manual Registration Tool with updated Median Filter tool
[clitk.git] / vv / vvMainWindow.cxx
index d50278dee1a5be5a274cfe0f5a75d51fba34667d..a35922f342a414613cf16e48a9c8abae17c422cc 100644 (file)
@@ -1,3 +1,21 @@
+/*=========================================================================
+  Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
+
+  Authors belong to: 
+  - University of LYON              http://www.universite-lyon.fr/
+  - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
+  - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
+
+  This software is distributed WITHOUT ANY WARRANTY; without even
+  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+  PURPOSE.  See the copyright notices for more information.
+
+  It is distributed under dual licence
+
+  - BSD        See included LICENSE.txt file
+  - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+======================================================================-====*/
+
 #include <algorithm>
 #include <QMessageBox>
 #include <QInputDialog>
@@ -15,7 +33,6 @@
 #include "vvSlicer.h"
 #include "vvInteractorStyleNavigator.h"
 #include "vvImageWriter.h"
-#include "vvResamplerDialog.h"
 #include "vvSegmentationDialog.h"
 #include "vvSurfaceViewerDialog.h"
 #include "vvDeformationDialog.h"
@@ -84,42 +101,44 @@ vvMainWindow::vvMainWindow():vvMainWindowBase() {
 
   mInputPathName = "";
   mMenuTools = menuTools;
+  mContextMenu = &contextMenu;
   mMenuExperimentalTools = menuExperimental;
   mMainWidget = this;
+  mCurrentTime = -1;
 
   //Init the contextMenu
   this->setContextMenuPolicy(Qt::CustomContextMenu);
   contextActions.resize(0);
-  QAction* actionOpen_new_image = contextMenu.addAction(QIcon(QString::fromUtf8(":/new/prefix1/icons/fileopen.png")),
+  QAction* actionOpen_new_image = contextMenu.addAction(QIcon(QString::fromUtf8(":/common/icons/fileopen.png")),
                                                         tr("O&pen new Image"));
   actionOpen_new_image->setShortcut(QKeySequence(tr("Ctrl+O")));
   connect(actionOpen_new_image,SIGNAL(triggered()),this,SLOT(OpenImages()));
   contextActions.push_back(actionOpen_new_image);
   contextMenu.addSeparator();
 
-  QAction* actionClose_Image = contextMenu.addAction(QIcon(QString::fromUtf8(":/new/prefix1/icons/exit.png")),
+  QAction* actionClose_Image = contextMenu.addAction(QIcon(QString::fromUtf8(":/common/icons/exit.png")),
                                                      tr("Close Current Image"));
   connect(actionClose_Image,SIGNAL(triggered()),this,SLOT(CloseImage()));
   contextActions.push_back(actionClose_Image);
 
-  QAction* actionReload_image = contextMenu.addAction(QIcon(QString::fromUtf8(":/new/prefix1/icons/rotateright.png")),
+  QAction* actionReload_image = contextMenu.addAction(QIcon(QString::fromUtf8(":/common/icons/rotateright.png")),
                                                       tr("Reload Current Image"));
   connect(actionReload_image,SIGNAL(triggered()),this,SLOT(ReloadImage()));
   contextActions.push_back(actionReload_image);
 
-  QAction* actionSave_image = contextMenu.addAction(QIcon(QString::fromUtf8(":/new/prefix1/icons/filesave.png")),
+  QAction* actionSave_image = contextMenu.addAction(QIcon(QString::fromUtf8(":/common/icons/filesave.png")),
                                                     tr("Save Current Image"));
   connect(actionSave_image,SIGNAL(triggered()),this,SLOT(SaveAs()));
   contextActions.push_back(actionSave_image);
 
   contextMenu.addSeparator();
 
-  // QAction* actionCrop_image = contextMenu.addAction(QIcon(QString::fromUtf8(":/new/prefix1/icons/crop.png")),
+  // QAction* actionCrop_image = contextMenu.addAction(QIcon(QString::fromUtf8(":/common/icons/crop.png")),
   //                                                   tr("Crop Current Image"));
   // connect(actionCrop_image,SIGNAL(triggered()),this,SLOT(CropImage()));
   // contextActions.push_back(actionCrop_image);
 
-  QAction* actionSplit_image = contextMenu.addAction(QIcon(QString::fromUtf8(":/new/prefix1/icons/cut.png")),
+  QAction* actionSplit_image = contextMenu.addAction(QIcon(QString::fromUtf8(":/common/icons/cut.png")),
                                                      tr("Split Current Image"));
   connect(actionSplit_image,SIGNAL(triggered()),this,SLOT(SplitImage()));
   contextActions.push_back(actionSplit_image);
@@ -129,7 +148,7 @@ vvMainWindow::vvMainWindow():vvMainWindowBase() {
   contextMenu.addAction(actionAdd_VF_to_current_Image);
   contextActions.push_back(actionAdd_VF_to_current_Image);
 
-  QAction* actionAdd_Overlay_to_current_Image = menuOverlay->addAction(QIcon(QString::fromUtf8(":/new/prefix1/icons/GPSup.png")),
+  QAction* actionAdd_Overlay_to_current_Image = menuOverlay->addAction(QIcon(QString::fromUtf8(":/common/icons/GPSup.png")),
                                                                        tr("Add overlay image to current image"));
   contextMenu.addAction(actionAdd_Overlay_to_current_Image);
   contextActions.push_back(actionAdd_Overlay_to_current_Image);
@@ -140,6 +159,21 @@ vvMainWindow::vvMainWindow():vvMainWindowBase() {
   connect(actionAdd_fusion_image,SIGNAL(triggered()),this,SLOT(AddFusionImage()));
   contextActions.push_back(actionAdd_fusion_image);
 
+  // TRIAL DS
+  /*
+  QMenu * m = new QMenu(menubar);
+  m->setTitle("TOTO");
+  //  m->setObjectName(QString::fromUtf8("TOTOTO"));
+  contextMenu.addMenu(m);
+  QAction * a = m->addAction(QIcon(QString::fromUtf8(":/common/icons/GPSup.png")),
+                    tr("BIDON"));
+  QAction * b = m->addAction(QIcon(QString::fromUtf8(":/common/icons/GPSup.png")),
+                    tr("BIDON2"));
+  m->addAction(a);
+  m->addAction(b);
+  connect(a,SIGNAL(triggered()),this,SLOT(AddFusionImage()));
+  */
+
   //init the DataTree
   mSlicerManagers.resize(0);
 
@@ -221,8 +255,6 @@ vvMainWindow::vvMainWindow():vvMainWindowBase() {
   connect(actionDocumentation,SIGNAL(triggered()),this,SLOT(ShowDocumentation()));
 
   ///////////////////////////////////////////////
-  contextMenu.addAction(actionResampler);
-  connect(actionResampler,SIGNAL(triggered()),this,SLOT(ResampleCurrentImage()));
   connect(actionSegmentation,SIGNAL(triggered()),this,SLOT(SegmentationOnCurrentImage()));
   connect(actionSurface_Viewer,SIGNAL(triggered()),this,SLOT(SurfaceViewerLaunch()));
   ///////////////////////////////////////////////
@@ -280,11 +312,11 @@ vvMainWindow::vvMainWindow():vvMainWindowBase() {
   if ( !recent_files.empty() )
     {
       QMenu * rmenu = new QMenu("Recently opened files...");
-      rmenu->setIcon(QIcon(QString::fromUtf8(":/new/prefix1/icons/open.png")));
+      rmenu->setIcon(QIcon(QString::fromUtf8(":/common/icons/open.png")));
       menuFile->insertMenu(actionOpen_Image_With_Time,rmenu);
       for (std::list<std::string>::iterator i = recent_files.begin();i!=recent_files.end();i++)
         {
-          QAction* current=new QAction(QIcon(QString::fromUtf8(":/new/prefix1/icons/open.png")),
+          QAction* current=new QAction(QIcon(QString::fromUtf8(":/common/icons/open.png")),
                                        (*i).c_str(),this);
           rmenu->addAction(current);
           connect(current,SIGNAL(triggered()),this,SLOT(OpenRecentImage()));
@@ -307,7 +339,8 @@ void vvMainWindow::ComputeMIP()
   vvSlicerManager* selected_slicer = mSlicerManagers[GetSlicerIndexFromItem(DataTree->selectedItems()[0])];
   QFileInfo info(selected_slicer->GetFileName().c_str());
   mip.Compute(selected_slicer);
-  AddImage(mip.GetOutput(),info.path().toStdString()+"/"+info.completeBaseName().toStdString()+"_mip.mhd");
+  if (!mip.error)
+      AddImage(mip.GetOutput(),info.path().toStdString()+"/"+info.completeBaseName().toStdString()+"_mip.mhd");
 }
 //------------------------------------------------------------------------------
 
@@ -358,7 +391,7 @@ void vvMainWindow::AddContour(int image_index, vvMesh::Pointer contour, bool pro
   cButton->setItem(item);
   cButton->setColumn(COLUMN_CLOSE_IMAGE);
   cButton->setToolTip(tr("close image"));
-  cButton->setIcon(QIcon(QString::fromUtf8(":/new/prefix1/icons/exit.png")));
+  cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png")));
   connect(cButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
           this,SLOT(CloseImage(QTreeWidgetItem*, int)));
 
@@ -366,7 +399,7 @@ void vvMainWindow::AddContour(int image_index, vvMesh::Pointer contour, bool pro
   rButton->setItem(item);
   rButton->setColumn(COLUMN_RELOAD_IMAGE);
   rButton->setToolTip(tr("reload image"));
-  rButton->setIcon(QIcon(QString::fromUtf8(":/new/prefix1/icons/rotateright.png")));
+  rButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/rotateright.png")));
   rButton->setEnabled(false);
   //Not implemented
   //connect(rButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
@@ -721,6 +754,8 @@ void vvMainWindow::OpenRecentImage()
   mInputPathName = itksys::SystemTools::GetFilenamePath(images[0]).c_str();
   LoadImages(images,IMAGE);
 }
+//------------------------------------------------------------------------------
+
 
 //------------------------------------------------------------------------------
 void vvMainWindow::OpenImageWithTime() {
@@ -740,6 +775,7 @@ void vvMainWindow::OpenImageWithTime() {
 }
 //------------------------------------------------------------------------------
 
+
 //------------------------------------------------------------------------------
 void vvMainWindow::LoadImages(std::vector<std::string> files, LoadedImageType filetype) {
   //Separate the way to open images and dicoms
@@ -775,11 +811,25 @@ void vvMainWindow::LoadImages(std::vector<std::string> files, LoadedImageType fi
 
     bool SetImageSucceed=false;
 
+    // Change filename if an image with the same already exist
+    //    DD(files[i]);
+    int number=0;
+    for(unsigned int l=0; l<mSlicerManagers.size(); l++) {
+      vvSlicerManager * v = mSlicerManagers[l];
+      //      DD(v->GetBaseFileName());
+      // DD(v->GetFileName());
+      if (v->GetBaseFileName() == 
+          vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(files[i]))) {
+        number = std::max(number, v->GetBaseFileNameNumber()+1);
+      }
+    }
+
+
     if (filetype == IMAGE || filetype == IMAGEWITHTIME)
-      SetImageSucceed = imageManager->SetImage(files[i],filetype);
+      SetImageSucceed = imageManager->SetImage(files[i],filetype, number);
     else
       {
-        SetImageSucceed = imageManager->SetImages(files,filetype);
+        SetImageSucceed = imageManager->SetImages(files,filetype, number);
       }
     if (SetImageSucceed == false)
       {
@@ -806,7 +856,7 @@ void vvMainWindow::LoadImages(std::vector<std::string> files, LoadedImageType fi
         cButton->setItem(item);
         cButton->setColumn(COLUMN_CLOSE_IMAGE);
         cButton->setToolTip(tr("close image"));
-        cButton->setIcon(QIcon(QString::fromUtf8(":/new/prefix1/icons/exit.png")));
+        cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png")));
         connect(cButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
                 this,SLOT(CloseImage(QTreeWidgetItem*, int)));
 
@@ -814,7 +864,7 @@ void vvMainWindow::LoadImages(std::vector<std::string> files, LoadedImageType fi
         rButton->setItem(item);
         rButton->setColumn(COLUMN_RELOAD_IMAGE);
         rButton->setToolTip(tr("reload image"));
-        rButton->setIcon(QIcon(QString::fromUtf8(":/new/prefix1/icons/rotateright.png")));
+        rButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/rotateright.png")));
         connect(rButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
                 this,SLOT(ReloadImage(QTreeWidgetItem*, int)));
 
@@ -829,29 +879,30 @@ void vvMainWindow::LoadImages(std::vector<std::string> files, LoadedImageType fi
 
         linkPanel->addImage(imageManager->GetFileName(), id.toStdString());
 
-        connect(mSlicerManagers.back(),SIGNAL(currentImageChanged(std::string)),
+        connect(mSlicerManagers.back(), SIGNAL(currentImageChanged(std::string)),
                 this,SLOT(CurrentImageChanged(std::string)));
-        connect(mSlicerManagers.back(),SIGNAL(
-                                              UpdatePosition(int, double, double, double, double, double, double, double)),this,
-                SLOT(MousePositionChanged(int,double, double, double, double, double, double, double)));
-        connect(mSlicerManagers.back(),SIGNAL(UpdateVector(int, double, double, double, double)),
+        connect(mSlicerManagers.back(), SIGNAL(UpdatePosition(int, double, double, double, double, double, double, double)),
+             this,SLOT(MousePositionChanged(int,double, double, double, double, double, double, double)));
+        connect(mSlicerManagers.back(), SIGNAL(UpdateVector(int, double, double, double, double)),
                 this, SLOT(VectorChanged(int,double,double,double, double)));
-        connect(mSlicerManagers.back(),SIGNAL(UpdateOverlay(int, double, double)),
+        connect(mSlicerManagers.back(), SIGNAL(UpdateOverlay(int, double, double)),
                 this, SLOT(OverlayChanged(int,double,double)));
-        connect(mSlicerManagers.back(),SIGNAL(UpdateFusion(int, double)),
+        connect(mSlicerManagers.back(), SIGNAL(UpdateFusion(int, double)),
                 this, SLOT(FusionChanged(int,double)));
-        connect(mSlicerManagers.back(),SIGNAL(UpdateWindows(int, int, int)),
+        connect(mSlicerManagers.back(), SIGNAL(UpdateWindows(int, int, int)),
                 this,SLOT(WindowsChanged(int, int, int)));
-        connect(mSlicerManagers.back(),SIGNAL(WindowLevelChanged(double, double,int, int)),
+        connect(mSlicerManagers.back(), SIGNAL(WindowLevelChanged(double, double,int, int)),
                 this,SLOT(WindowLevelChanged(double, double, int, int)));
-        connect(mSlicerManagers.back(),SIGNAL(UpdateSlice(int,int)),
+        connect(mSlicerManagers.back(), SIGNAL(UpdateSlice(int,int)),
                 this,SLOT(UpdateSlice(int,int)));
-        connect(mSlicerManagers.back(),SIGNAL(UpdateTSlice(int, int)),
+        connect(mSlicerManagers.back(), SIGNAL(UpdateTSlice(int, int)),
                 this,SLOT(UpdateTSlice(int, int)));
-        connect(mSlicerManagers.back(),SIGNAL(UpdateSliceRange(int,int,int,int,int)),
+        connect(mSlicerManagers.back(), SIGNAL(UpdateSliceRange(int,int,int,int,int)),
                 this,SLOT(UpdateSliceRange(int,int,int,int,int)));
-        connect(mSlicerManagers.back(),SIGNAL(UpdateLinkManager(std::string,int,double,double,double,int)),
+        connect(mSlicerManagers.back(), SIGNAL(UpdateLinkManager(std::string,int,double,double,double,int)),
                 this,SLOT(UpdateLinkManager(std::string,int,double,double,double,int)));
+        connect(mSlicerManagers.back(), SIGNAL(ChangeImageWithIndexOffset(vvSlicerManager*,int,int)),
+                this,SLOT(ChangeImageWithIndexOffset(vvSlicerManager*,int,int)));
         connect(mSlicerManagers.back(),SIGNAL(LandmarkAdded()),landmarksPanel,SLOT(AddPoint()));
         InitSlicers();
         numberofsuccesulreads++;
@@ -869,6 +920,17 @@ void vvMainWindow::LoadImages(std::vector<std::string> files, LoadedImageType fi
     }
   QApplication::restoreOverrideCursor();
 
+  // Try to guess default WindowLevel
+  double range[2];
+  mSlicerManagers.back()->GetImage()->GetFirstVTKImageData()->GetScalarRange(range);
+  // DD(range[0]);
+  //   DD(range[1]);
+  if ((range[0] == 0) && (range[1] == 1)) {
+    presetComboBox->setCurrentIndex(5);// binary
+  }
+  else {
+    // TODO
+  }
 }
 //------------------------------------------------------------------------------
 
@@ -1254,6 +1316,18 @@ int vvMainWindow::GetSlicerIndexFromItem(QTreeWidgetItem* item) {
 }
 //------------------------------------------------------------------------------
 
+//------------------------------------------------------------------------------
+QTreeWidgetItem* vvMainWindow::GetItemFromSlicerManager(vvSlicerManager* sm) {
+    QString id = sm->GetId().c_str();
+    for (int i = 0; i < DataTree->topLevelItemCount(); i++)
+    {
+        if (DataTree->topLevelItem(i)->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString() == id)
+            return DataTree->topLevelItem(i);
+    }
+    return NULL;
+}
+//------------------------------------------------------------------------------
+
 //------------------------------------------------------------------------------
 void vvMainWindow::DisplayChanged(QTreeWidgetItem *clicked_item, int column) {
   int index = GetSlicerIndexFromItem(clicked_item);
@@ -1261,6 +1335,9 @@ void vvMainWindow::DisplayChanged(QTreeWidgetItem *clicked_item, int column) {
     return;
   for (unsigned int i = 0; i < mSlicerManagers.size(); i++)
     {
+     //Trick to avoid redoing twice the job for a key (sr)
+      mSlicerManagers[i]->GetSlicer(column-1)->GetRenderWindow()-> GetInteractor()->SetKeySym("Crap");
+      
       QTreeWidgetItem* current_row=DataTree->topLevelItem(i);
       if (DataTree->topLevelItem(index) == current_row)
         {
@@ -1468,7 +1545,7 @@ void vvMainWindow::CloseImage(QTreeWidgetItem* item, int column) {
       msgBox.addButton(tr("Cancel"), QMessageBox::RejectRole);
       if (msgBox.exec() == QMessageBox::AcceptRole)
         {
-          this->close();
+         this->close();
         }
     }
   else
@@ -1598,7 +1675,7 @@ void vvMainWindow::SplitImage() {
               cButton->setItem(item);
               cButton->setColumn(COLUMN_CLOSE_IMAGE);
               cButton->setToolTip(tr("close image"));
-              cButton->setIcon(QIcon(QString::fromUtf8(":/new/prefix1/icons/exit.png")));
+              cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png")));
               connect(cButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
                       this,SLOT(CloseImage(QTreeWidgetItem*, int)));
 
@@ -1606,7 +1683,7 @@ void vvMainWindow::SplitImage() {
               rButton->setItem(item);
               rButton->setColumn(COLUMN_RELOAD_IMAGE);
               rButton->setToolTip(tr("reload image"));
-              rButton->setIcon(QIcon(QString::fromUtf8(":/new/prefix1/icons/rotateright.png")));
+              rButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/rotateright.png")));
               rButton->setEnabled(false);
               connect(rButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
                       this,SLOT(ReloadImage(QTreeWidgetItem*, int)));
@@ -1827,6 +1904,7 @@ void vvMainWindow::SelectOverlayImage() {
 
 //------------------------------------------------------------------------------
 void vvMainWindow::AddOverlayImage(int index, QString file) {
+
   mInputPathName = itksys::SystemTools::GetFilenamePath(file.toStdString()).c_str();
   itk::ImageIOBase::Pointer reader = itk::ImageIOFactory::CreateImageIO(
                                                                         file.toStdString().c_str(), itk::ImageIOFactory::ReadMode);
@@ -1837,7 +1915,7 @@ void vvMainWindow::AddOverlayImage(int index, QString file) {
   QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
   vvProgressDialog progress("Opening " + file.toStdString());
   qApp->processEvents();
-
+  
   std::string filename = itksys::SystemTools::GetFilenameWithoutExtension(file.toStdString()).c_str();
   if (mSlicerManagers[index]->SetOverlay(file.toStdString(),dimension, component))
     {
@@ -1852,7 +1930,7 @@ void vvMainWindow::AddOverlayImage(int index, QString file) {
         {
           item->setData(j,Qt::CheckStateRole,DataTree->topLevelItem(index)->data(j,Qt::CheckStateRole));
           mSlicerManagers[index]->GetSlicer(j-1)->SetActorVisibility("overlay",0,
-                                                                     DataTree->topLevelItem(index)->data(j,Qt::CheckStateRole).toInt());
+                                                                    DataTree->topLevelItem(index)->data(j,Qt::CheckStateRole).toInt());
         }
 
       //Create the buttons for reload and close
@@ -1861,7 +1939,7 @@ void vvMainWindow::AddOverlayImage(int index, QString file) {
       cButton->setItem(item);
       cButton->setColumn(COLUMN_CLOSE_IMAGE);
       cButton->setToolTip(tr("close image"));
-      cButton->setIcon(QIcon(QString::fromUtf8(":/new/prefix1/icons/exit.png")));
+      cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png")));
       connect(cButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
               this,SLOT(CloseImage(QTreeWidgetItem*, int)));
 
@@ -1869,7 +1947,7 @@ void vvMainWindow::AddOverlayImage(int index, QString file) {
       rButton->setItem(item);
       rButton->setColumn(COLUMN_RELOAD_IMAGE);
       rButton->setToolTip(tr("reload image"));
-      rButton->setIcon(QIcon(QString::fromUtf8(":/new/prefix1/icons/rotateright.png")));
+      rButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/rotateright.png")));
       connect(rButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
               this,SLOT(ReloadImage(QTreeWidgetItem*, int)));
 
@@ -1951,7 +2029,7 @@ void vvMainWindow::AddFusionImage()
               cButton->setItem(item);
               cButton->setColumn(COLUMN_CLOSE_IMAGE);
               cButton->setToolTip(tr("close image"));
-              cButton->setIcon(QIcon(QString::fromUtf8(":/new/prefix1/icons/exit.png")));
+              cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png")));
               connect(cButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
                       this,SLOT(CloseImage(QTreeWidgetItem*, int)));
 
@@ -1959,7 +2037,7 @@ void vvMainWindow::AddFusionImage()
               rButton->setItem(item);
               rButton->setColumn(COLUMN_RELOAD_IMAGE);
               rButton->setToolTip(tr("reload image"));
-              rButton->setIcon(QIcon(QString::fromUtf8(":/new/prefix1/icons/rotateright.png")));
+              rButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/rotateright.png")));
               connect(rButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
                       this,SLOT(ReloadImage(QTreeWidgetItem*, int)));
 
@@ -1991,8 +2069,10 @@ void vvMainWindow::AddFusionImage()
         }
     }
 }
+//------------------------------------------------------------------------------
 
 
+//------------------------------------------------------------------------------
 void vvMainWindow::OpenField()
 {
   int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
@@ -2013,7 +2093,10 @@ void vvMainWindow::OpenField()
   if (!file.isEmpty())
     AddField(file,index);
 }
+//------------------------------------------------------------------------------
 
+
+//------------------------------------------------------------------------------
 void vvMainWindow::AddFieldEntry(QString filename,int index,bool from_disk)
 {
   //create an item in the tree with good settings
@@ -2036,7 +2119,7 @@ void vvMainWindow::AddFieldEntry(QString filename,int index,bool from_disk)
   cButton->setItem(item);
   cButton->setColumn(COLUMN_CLOSE_IMAGE);
   cButton->setToolTip(tr("close vector field"));
-  cButton->setIcon(QIcon(QString::fromUtf8(":/new/prefix1/icons/exit.png")));
+  cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png")));
   connect(cButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
           this,SLOT(CloseImage(QTreeWidgetItem*, int)));
 
@@ -2045,7 +2128,7 @@ void vvMainWindow::AddFieldEntry(QString filename,int index,bool from_disk)
   rButton->setColumn(COLUMN_RELOAD_IMAGE);
   rButton->setToolTip(tr("reload vector field"));
   rButton->setEnabled(from_disk);
-  rButton->setIcon(QIcon(QString::fromUtf8(":/new/prefix1/icons/rotateright.png")));
+  rButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/rotateright.png")));
   connect(rButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
           this,SLOT(ReloadImage(QTreeWidgetItem*, int)));
 
@@ -2062,7 +2145,10 @@ void vvMainWindow::AddFieldEntry(QString filename,int index,bool from_disk)
   ImageInfoChanged();
   QApplication::restoreOverrideCursor();
 }
+//------------------------------------------------------------------------------
+
 
+//------------------------------------------------------------------------------
 void vvMainWindow::AddField(vvImage::Pointer vf,QString file,int index)
 {
   QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
@@ -2079,7 +2165,10 @@ void vvMainWindow::AddField(vvImage::Pointer vf,QString file,int index)
     }
   QApplication::restoreOverrideCursor();
 }
+//------------------------------------------------------------------------------
 
+
+//------------------------------------------------------------------------------
 void vvMainWindow::AddField(QString file,int index)
 {
   if (QFile::exists(file))
@@ -2115,6 +2204,7 @@ void vvMainWindow::AddField(QString file,int index)
 }
 //------------------------------------------------------------------------------
 
+
 //------------------------------------------------------------------------------
 void vvMainWindow::SetVFProperty(int subsampling, int scale, int log) {
   int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
@@ -2133,6 +2223,7 @@ void vvMainWindow::SetVFProperty(int subsampling, int scale, int log) {
 }
 //------------------------------------------------------------------------------
 
+
 //------------------------------------------------------------------------------
 void vvMainWindow::SetOverlayProperty(int color) {
   int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
@@ -2276,6 +2367,21 @@ void vvMainWindow::RemoveLink(QString image1,QString image2) {
 }
 //------------------------------------------------------------------------------
 
+//------------------------------------------------------------------------------
+void vvMainWindow::ChangeImageWithIndexOffset(vvSlicerManager *sm, int slicer, int offset)
+{
+    int index = 0;
+    while(sm != mSlicerManagers[index])
+        index++;
+    index = (index+offset) % mSlicerManagers.size();
+
+    QTreeWidgetItem* item = GetItemFromSlicerManager(mSlicerManagers[index]);
+    //CurrentImageChanged(mSlicerManagers[index]->GetId()); //select new image
+    item->setData(slicer+1,Qt::CheckStateRole,2);         //change checkbox
+    DisplayChanged(item,slicer+1);
+}
+//------------------------------------------------------------------------------
+
 void vvMainWindow::HorizontalSliderMoved(int value,int column, int slicer_index)
 {
   for (unsigned int i = 0; i < mSlicerManagers.size(); i++)
@@ -2293,28 +2399,41 @@ void vvMainWindow::HorizontalSliderMoved(int value,int column, int slicer_index)
         }
     }
 }
+//------------------------------------------------------------------------------
+
 
 //------------------------------------------------------------------------------
 void vvMainWindow::NOHorizontalSliderMoved() {
+  // if (mCurrentTime == NOHorizontalSlider->value()) return;
   HorizontalSliderMoved(NOHorizontalSlider->value(),COLUMN_UL_VIEW,0);
+ //  mCurrentTime = NOHorizontalSlider->value();
 }
 //------------------------------------------------------------------------------
 
+
 //------------------------------------------------------------------------------
 void vvMainWindow::NEHorizontalSliderMoved() {
+  // if (mCurrentTime == NEHorizontalSlider->value()) return;
   HorizontalSliderMoved(NEHorizontalSlider->value(),COLUMN_UR_VIEW,1);
+ //  mCurrentTime = NEHorizontalSlider->value();
 }
 //------------------------------------------------------------------------------
 
+
 //------------------------------------------------------------------------------
 void vvMainWindow::SOHorizontalSliderMoved() {
+  // if (mCurrentTime == SOHorizontalSlider->value()) return;
   HorizontalSliderMoved(SOHorizontalSlider->value(),COLUMN_DL_VIEW,2);
+  // mCurrentTime = SOHorizontalSlider->value();
 }
 //------------------------------------------------------------------------------
 
+
 //------------------------------------------------------------------------------
 void vvMainWindow::SEHorizontalSliderMoved() {
+  // if (mCurrentTime == SEHorizontalSlider->value()) return;
   HorizontalSliderMoved(SEHorizontalSlider->value(),COLUMN_DR_VIEW,3);
+  // mCurrentTime = SEHorizontalSlider->value();
 }
 //------------------------------------------------------------------------------
 
@@ -2326,13 +2445,16 @@ void vvMainWindow::NOVerticalSliderChanged() {
       if (DataTree->topLevelItem(i)->data(COLUMN_UL_VIEW,Qt::CheckStateRole).toInt() > 1)
         {
           mSlicerManagers[i]->GetSlicer(0)->SetSlice(value);
-          mSlicerManagers[i]->UpdateSlice(0); // <-- DS add this. Not too much update ? 
+          mSlicerManagers[i]->VerticalSliderHasChanged(0, value);
+          // mSlicerManagers[i]->UpdateSlice(0);  // <-- DS add this. Not too much update ? YES.
+         mSlicerManagers[i]->GetSlicer(0)->Render(); // <-- DS add this, needed for contour, seems ok ? not too slow ? 
           break;
         }
     }
 }
 //------------------------------------------------------------------------------
 
+
 //------------------------------------------------------------------------------
 void vvMainWindow::NEVerticalSliderChanged() {
   int value = NEVerticalSlider->value();
@@ -2341,12 +2463,15 @@ void vvMainWindow::NEVerticalSliderChanged() {
       if (DataTree->topLevelItem(i)->data(COLUMN_UR_VIEW,Qt::CheckStateRole).toInt() > 1)
         {
           mSlicerManagers[i]->GetSlicer(1)->SetSlice(value);
+          mSlicerManagers[i]->VerticalSliderHasChanged(1, value);
+         mSlicerManagers[i]->GetSlicer(1)->Render(); // <-- DS add this, needed for contour, seems ok ? not too slow ? 
           break;
         }
     }
 }
 //------------------------------------------------------------------------------
 
+
 //------------------------------------------------------------------------------
 void vvMainWindow::SOVerticalSliderChanged() {
   int value = SOVerticalSlider->value();
@@ -2355,12 +2480,15 @@ void vvMainWindow::SOVerticalSliderChanged() {
       if (DataTree->topLevelItem(i)->data(COLUMN_DL_VIEW,Qt::CheckStateRole).toInt() > 1)
         {
           mSlicerManagers[i]->GetSlicer(2)->SetSlice(value);
+          mSlicerManagers[i]->VerticalSliderHasChanged(2, value);
+         mSlicerManagers[i]->GetSlicer(2)->Render(); // <-- DS add this, needed for contour, seems ok ? not too slow ? 
           break;
         }
     }
 }
 //------------------------------------------------------------------------------
 
+
 //------------------------------------------------------------------------------
 void vvMainWindow::SEVerticalSliderChanged() {
   int value = SEVerticalSlider->value();
@@ -2369,12 +2497,15 @@ void vvMainWindow::SEVerticalSliderChanged() {
       if (DataTree->topLevelItem(i)->data(COLUMN_DR_VIEW,Qt::CheckStateRole).toInt() > 1)
         {
           mSlicerManagers[i]->GetSlicer(3)->SetSlice(value);
+          mSlicerManagers[i]->VerticalSliderHasChanged(3, value);
+         mSlicerManagers[i]->GetSlicer(3)->Render(); // <-- DS add this, needed for contour, seems ok ? not too slow ? 
           break;
         }
     }
 }
 //------------------------------------------------------------------------------
 
+
 //------------------------------------------------------------------------------
 void vvMainWindow::UpdateSlice(int slicer, int slice) {
   if (slicer == 0) {
@@ -2390,6 +2521,7 @@ void vvMainWindow::UpdateSlice(int slicer, int slice) {
 }
 //------------------------------------------------------------------------------
 
+
 //------------------------------------------------------------------------------
 void vvMainWindow::UpdateTSlice(int slicer, int slice) {
   switch (slicer)
@@ -2410,6 +2542,7 @@ void vvMainWindow::UpdateTSlice(int slicer, int slice) {
 }
 //------------------------------------------------------------------------------
 
+
 //------------------------------------------------------------------------------
 void vvMainWindow::UpdateSliceRange(int slicer, int min, int max, int tmin, int tmax) {
   int position = int((min+max)/2);
@@ -2445,6 +2578,7 @@ void vvMainWindow::UpdateSliceRange(int slicer, int min, int max, int tmin, int
 }
 //------------------------------------------------------------------------------
 
+
 //------------------------------------------------------------------------------
 void vvMainWindow::SaveNOScreenshot() {
   vtkWindowToImageFilter *w2i = vtkWindowToImageFilter::New();
@@ -2455,6 +2589,7 @@ void vvMainWindow::SaveNOScreenshot() {
 }
 //------------------------------------------------------------------------------
 
+
 //------------------------------------------------------------------------------
 void vvMainWindow::SaveNEScreenshot() {
   vtkWindowToImageFilter *w2i = vtkWindowToImageFilter::New();
@@ -2465,6 +2600,7 @@ void vvMainWindow::SaveNEScreenshot() {
 }
 //------------------------------------------------------------------------------
 
+
 //------------------------------------------------------------------------------
 void vvMainWindow::SaveSOScreenshot() {
   vtkWindowToImageFilter *w2i = vtkWindowToImageFilter::New();
@@ -2475,6 +2611,7 @@ void vvMainWindow::SaveSOScreenshot() {
 }
 //------------------------------------------------------------------------------
 
+
 //------------------------------------------------------------------------------
 void vvMainWindow::SaveSEScreenshot() {
   vtkWindowToImageFilter *w2i = vtkWindowToImageFilter::New();
@@ -2485,6 +2622,7 @@ void vvMainWindow::SaveSEScreenshot() {
 }
 //------------------------------------------------------------------------------
 
+
 //------------------------------------------------------------------------------
 void vvMainWindow::SaveScreenshot(vtkImageData* image) {
   QString Extensions = "Images( *.png);;";
@@ -2549,6 +2687,7 @@ void vvMainWindow::SaveScreenshot(vtkImageData* image) {
 }
 //------------------------------------------------------------------------------
 
+
 //------------------------------------------------------------------------------
 void vvMainWindow::GoToCursor() {
   int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
@@ -2572,7 +2711,7 @@ void vvMainWindow::PlayPause() {
   if (playMode)
     {
       playMode = 0;
-      playButton->setIcon(QIcon(QString::fromUtf8(":/new/prefix1/icons/player_play.png")));
+      playButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/player_play.png")));
       ImageInfoChanged();
       return;
     }
@@ -2589,7 +2728,7 @@ void vvMainWindow::PlayPause() {
       if (has_temporal)
         {
           playMode = 1;
-          playButton->setIcon(QIcon(QString::fromUtf8(":/new/prefix1/icons/player_pause.png")));
+          playButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/player_pause.png")));
           QTimer::singleShot(1000/mFrameRate, this, SLOT(PlayNext()));
         }
     }
@@ -2635,16 +2774,6 @@ void vvMainWindow::UpdateRenderWindows() {
 }
 //------------------------------------------------------------------------------
 
-//------------------------------------------------------------------------------
-void vvMainWindow::ResampleCurrentImage() {
-  vvResamplerDialog resampler;
-  int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
-  resampler.SetSlicerManagers(mSlicerManagers,index);
-  if (resampler.exec()) 
-    AddImage(resampler.GetOutput(),resampler.GetOutputFileName());
-}
-//------------------------------------------------------------------------------
-
 //------------------------------------------------------------------------------
 void vvMainWindow::SegmentationOnCurrentImage() {
   int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
@@ -2664,18 +2793,11 @@ void vvMainWindow::SurfaceViewerLaunch()
 //------------------------------------------------------------------------------
 void vvMainWindow::AddImage(vvImage::Pointer image,std::string filename)
 {
-  vvSlicerManager* m = new vvSlicerManager(4);
-  m->SetImage(image);
-  m->SetFilename(filename);
-  AddImage(m);
-}
-
-//------------------------------------------------------------------------------
-void vvMainWindow::AddImage(vvSlicerManager * slicer_manager) {
+  vvSlicerManager* slicer_manager = new vvSlicerManager(4);
+  slicer_manager->SetImage(image);
+  slicer_manager->SetFilename(filename);
   mSlicerManagers.push_back(slicer_manager);
 
-  std::string filename = slicer_manager->GetFileName();
-
   //create an item in the tree with good settings
   QTreeWidgetItem *item = new QTreeWidgetItem();
   item->setData(0,Qt::UserRole,slicer_manager->GetFileName().c_str());//files[i].c_str());
@@ -2689,14 +2811,14 @@ void vvMainWindow::AddImage(vvSlicerManager * slicer_manager) {
   QTreePushButton* cButton = new QTreePushButton;
   cButton->setItem(item);
   cButton->setColumn(COLUMN_CLOSE_IMAGE);
-  cButton->setIcon(QIcon(QString::fromUtf8(":/new/prefix1/icons/exit.png")));
+  cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png")));
   connect(cButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
           this,SLOT(CloseImage(QTreeWidgetItem*, int)));
 
   QTreePushButton* rButton = new QTreePushButton;
   rButton->setItem(item);
   rButton->setColumn(COLUMN_RELOAD_IMAGE);
-  rButton->setIcon(QIcon(QString::fromUtf8(":/new/prefix1/icons/rotateright.png")));
+  rButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/rotateright.png")));
   rButton->setEnabled(0);
   connect(rButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
           this,SLOT(ReloadImage(QTreeWidgetItem*, int)));
@@ -2712,30 +2834,31 @@ void vvMainWindow::AddImage(vvSlicerManager * slicer_manager) {
 
   linkPanel->addImage(filename, id.toStdString());
 
-  connect(mSlicerManagers.back(),SIGNAL(currentImageChanged(std::string)),
-          this,SLOT(CurrentImageChanged(std::string)));
-  connect(mSlicerManagers.back(),SIGNAL(
-                                        UpdatePosition(int, double, double, double, double, double, double, double)),this,
-          SLOT(MousePositionChanged(int,double, double, double, double, double, double, double)));
-  connect(mSlicerManagers.back(),SIGNAL(UpdateVector(int, double, double, double, double)),
+  connect(mSlicerManagers.back(), SIGNAL(currentImageChanged(std::string)),
+          this, SLOT(CurrentImageChanged(std::string)));
+  connect(mSlicerManagers.back(), SIGNAL(UpdatePosition(int, double, double, double, double, double, double, double)),
+          this, SLOT(MousePositionChanged(int,double, double, double, double, double, double, double)));
+  connect(mSlicerManagers.back(), SIGNAL(UpdateVector(int, double, double, double, double)),
           this, SLOT(VectorChanged(int,double,double,double, double)));
-  connect(mSlicerManagers.back(),SIGNAL(UpdateOverlay(int, double, double)),
+  connect(mSlicerManagers.back(), SIGNAL(UpdateOverlay(int, double, double)),
           this, SLOT(OverlayChanged(int,double,double)));
-  connect(mSlicerManagers.back(),SIGNAL(UpdateFusion(int, double)),
+  connect(mSlicerManagers.back(), SIGNAL(UpdateFusion(int, double)),
           this, SLOT(FusionChanged(int,double)));
-  connect(mSlicerManagers.back(),SIGNAL(UpdateWindows(int, int, int)),
+  connect(mSlicerManagers.back(), SIGNAL(UpdateWindows(int, int, int)),
           this,SLOT(WindowsChanged(int, int, int)));
-  connect(mSlicerManagers.back(),SIGNAL(WindowLevelChanged(double, double,int, int)),
+  connect(mSlicerManagers.back(), SIGNAL(WindowLevelChanged(double, double,int, int)),
           this,SLOT(WindowLevelChanged(double, double, int, int)));
-  connect(mSlicerManagers.back(),SIGNAL(UpdateSlice(int,int)),
+  connect(mSlicerManagers.back(), SIGNAL(UpdateSlice(int,int)),
           this,SLOT(UpdateSlice(int,int)));
-  connect(mSlicerManagers.back(),SIGNAL(UpdateTSlice(int, int)),
+  connect(mSlicerManagers.back(), SIGNAL(UpdateTSlice(int, int)),
           this,SLOT(UpdateTSlice(int, int)));
-  connect(mSlicerManagers.back(),SIGNAL(UpdateSliceRange(int,int,int,int,int)),
+  connect(mSlicerManagers.back(), SIGNAL(UpdateSliceRange(int,int,int,int,int)),
           this,SLOT(UpdateSliceRange(int,int,int,int,int)));
-  connect(mSlicerManagers.back(),SIGNAL(UpdateLinkManager(std::string,int,double,double,double,int)),
+  connect(mSlicerManagers.back(), SIGNAL(UpdateLinkManager(std::string,int,double,double,double,int)),
           this,SLOT(UpdateLinkManager(std::string,int,double,double,double,int)));
-  connect(mSlicerManagers.back(),SIGNAL(LandmarkAdded()),landmarksPanel,SLOT(AddPoint()));
+  connect(mSlicerManagers.back(), SIGNAL(ChangeImageWithIndexOffset(vvSlicerManager*,int,int)),
+          this,SLOT(ChangeImageWithIndexOffset(vvSlicerManager*,int,int)));
+  connect(mSlicerManagers.back(), SIGNAL(LandmarkAdded()),landmarksPanel,SLOT(AddPoint()));
   UpdateTree();
   qApp->processEvents();
   InitSlicers();