]> Creatis software - clitk.git/commitdiff
Allow for overlay images with differing temporal length
authorSimon Rit <simon.rit@creatis.insa-lyon.fr>
Thu, 6 Sep 2012 07:53:08 +0000 (09:53 +0200)
committerSimon Rit <simon.rit@creatis.insa-lyon.fr>
Thu, 6 Sep 2012 07:53:08 +0000 (09:53 +0200)
vv/vvMainWindow.cxx
vv/vvSlicer.cxx
vv/vvSlicer.h
vv/vvSlicerManager.cxx
vv/vvSlicerManagerCommand.cxx

index e82590e4f02435ce0058cbeb90d2c671b6af3e59..8f94ff664c8bdb033e3228d57f54f4126d81b4ba 100644 (file)
@@ -1086,7 +1086,8 @@ void vvMainWindow::ImageInfoChanged()
     QString inputSizeInBytes;
     QString image = DataTree->selectedItems()[0]->data(COLUMN_IMAGE_NAME,Qt::DisplayRole).toString();
 
-    if (mSlicerManagers[index]->GetSlicer(0)->GetImage()->GetVTKImages().size() > 1 || playMode == 1) {
+    int nframes = mSlicerManagers[index]->GetSlicer(0)->GetTMax();
+    if (nframes > 1 || playMode == 1) {
       playButton->setEnabled(1);
       frameRateLabel->setEnabled(1);
       frameRateSpinBox->setEnabled(1);
@@ -1500,17 +1501,12 @@ void vvMainWindow::DisplaySliders(int slicer, int window)
   int tRange[2];
   tRange[0] = 0;
   tRange[1] = mSlicerManagers[slicer]->GetSlicer(window)->GetTMax();
-  int tPosition = mSlicerManagers[slicer]->GetSlicer(window)->GetTSlice();
+  int tPosition = mSlicerManagers[slicer]->GetSlicer(window)->GetMaxCurrentTSlice();
   bool showHorizontal = false;
   bool showVertical = false;
-  if (mSlicerManagers[slicer]->GetSlicer(window)->GetImage()->GetNumberOfDimensions() > 3
-      || (mSlicerManagers[slicer]->GetSlicer(window)->GetImage()->GetNumberOfDimensions() > 2
-          && mSlicerManagers[slicer]->GetType() != vvImageReader::IMAGEWITHTIME
-          && mSlicerManagers[slicer]->GetType() != vvImageReader::MERGEDWITHTIME))
+  if (range[1]>0)
     showVertical = true;
-  if (mSlicerManagers[slicer]->GetSlicer(window)->GetImage()->GetNumberOfDimensions() > 3
-      || mSlicerManagers[slicer]->GetType() == vvImageReader::IMAGEWITHTIME
-      || mSlicerManagers[slicer]->GetType() == vvImageReader::MERGEDWITHTIME)
+  if (tRange[1]>0)
     showHorizontal = true;
 
   if (showVertical)
@@ -1932,6 +1928,10 @@ void vvMainWindow::AddOverlayImage(int index, std::vector<std::string> fileNames
       qApp->processEvents();
       ImageInfoChanged();
       QApplication::restoreOverrideCursor();
+
+      // Update the display to update, e.g., the sliders
+      for(int i=0; i<4; i++)
+        DisplaySliders(index, i);
     } else {
       QApplication::restoreOverrideCursor();
       QString error = "Cannot import the new image.\n";
@@ -2895,9 +2895,8 @@ void vvMainWindow::SaveScreenshot(QVTKWidget *widget)
       vidwriter->SetInput(image);
       vidwriter->SetFileName(fileName.toStdString().c_str());
       vidwriter->Start();
-      vvImage * vvImg = mSlicerManagers[smIndex]->GetImage();
-      int nSlice = vvImg->GetVTKImages().size();
-      for(int i=0; i<nSlice; i++) {
+      int nSlice = mSlicerManagers[smIndex]->GetSlicer(0)->GetTMax();
+      for(int i=0; i<=nSlice; i++) {
         mSlicerManagers[smIndex]->SetNextTSlice(0);
         vtkSmartPointer<vtkWindowToImageFilter> w2i = vtkSmartPointer<vtkWindowToImageFilter>::New();
         w2i->SetInput(widget->GetRenderWindow());
@@ -2945,7 +2944,7 @@ void vvMainWindow::PlayPause()
     int image_number=DataTree->topLevelItemCount();
     bool has_temporal;
     for (int i=0; i<image_number; i++)
-      if (mSlicerManagers[i]->GetImage()->GetVTKImages().size() > 1) {
+      if (mSlicerManagers[i]->GetSlicer(0)->GetTMax() > 0) {
         has_temporal=true;
         break;
       }
@@ -2966,7 +2965,7 @@ void vvMainWindow::PlayNext()
     ///Only play one slicer per SM, and only if the SM is being displayed
     for (int i=0; i<image_number; i++)
       for (int j=0; j<4; j++)
-        if (mSlicerManagers[i]->GetImage()->GetVTKImages().size() > 1 &&
+        if (mSlicerManagers[i]->GetSlicer(0)->GetTMax() > 0 &&
             DataTree->topLevelItem(i)->data(j+1,Qt::CheckStateRole).toInt() > 0) {
           mSlicerManagers[i]->SetNextTSlice(j);
           break;
index cc5662bb23c176288fbde36af6d41064995f4bc8..17aa41b81a9619b928a3268fea886d6d4c858fad 100644 (file)
@@ -708,17 +708,18 @@ void vvSlicer::SetVFLog(int log)
 void vvSlicer::SetTSlice(int t)
 {
   if (t < 0)
-    t = 0;
+    mCurrentTSlice = 0;
   else if ((unsigned int)t >= mImage->GetVTKImages().size())
-    t = mImage->GetVTKImages().size() -1;
+    mCurrentTSlice = mImage->GetVTKImages().size() -1;
+  else
+    mCurrentTSlice = t;
 
   // Update transform
   mConcatenatedTransform->Identity();
-  mConcatenatedTransform->Concatenate(mImage->GetTransform()[t]);
+  mConcatenatedTransform->Concatenate(mImage->GetTransform()[mCurrentTSlice]);
   mConcatenatedTransform->Concatenate(mSlicingTransform);
 
   // Update image data
-  mCurrentTSlice = t;
   mImageReslice->SetInput( mImage->GetVTKImages()[mCurrentTSlice] );
   if (mVF && mVFActor->GetVisibility()) {
     if (mVF->GetVTKImages().size() > (unsigned int)mCurrentTSlice)
@@ -762,6 +763,18 @@ int vvSlicer::GetTSlice()
 }
 //------------------------------------------------------------------------------
 
+//------------------------------------------------------------------------------
+int vvSlicer::GetMaxCurrentTSlice()
+{
+  int t = mCurrentTSlice;
+  if(mOverlay)
+    t = std::max(t, mCurrentOverlayTSlice);
+  if(mFusion)
+    t = std::max(t, mCurrentFusionTSlice);
+  return t;
+}
+//------------------------------------------------------------------------------
+
 //------------------------------------------------------------------------------
 int vvSlicer::GetFusionTSlice()
 {
@@ -1467,6 +1480,14 @@ void vvSlicer::SetSlice(int slice)
 }
 //----------------------------------------------------------------------------
 
+//----------------------------------------------------------------------------
+int vvSlicer::GetTMax() {
+  int tmax = (int)mImage->GetVTKImages().size() - 1;
+  if(mOverlay)
+    tmax = std::max(tmax, (int)mOverlay->GetVTKImages().size()-1);
+  return tmax;
+}
+//----------------------------------------------------------------------------
 
 //----------------------------------------------------------------------------
 void vvSlicer::SetContourSlice()
index 71f7ece7e4ecbe22e75fab3406a143d11d8ad5b6..9a750e14d69a6db41596d143e4d3ff30c33b9fae 100644 (file)
@@ -101,11 +101,10 @@ public:
   int GetTSlice();
   int GetFusionTSlice();
   int GetOverlayTSlice();
+  int GetMaxCurrentTSlice();
   ///Reimplemented from vtkImageViewer2 to add polydata support
   void SetSlice(int s);
-  int GetTMax() {
-    return (unsigned int)mImage->GetVTKImages().size() - 1;
-  }
+  int GetTMax();
 
   void SetOpacity(double s);
   void SetRenderWindow(int orientation, vtkRenderWindow * rw);
index bc03ebd7f715f4f56bc9f8069b1e8207c5abc89d..c0e652de2317cafdfa07eb976a46f893b228c6a4 100644 (file)
@@ -442,7 +442,7 @@ void vvSlicerManager::SetTSlice(int slice)
   if (mLandmarks)
     mLandmarks->SetTime(slice);
   for ( unsigned int i = 0; i < mSlicers.size(); i++) {
-    if (slice != mSlicers[i]->GetTSlice()) {
+    if (slice != mSlicers[i]->GetMaxCurrentTSlice()) {
       mSlicers[i]->SetTSlice(slice);
       UpdateTSlice(i);
     }
@@ -454,7 +454,7 @@ void vvSlicerManager::SetTSlice(int slice)
 //----------------------------------------------------------------------------
 void vvSlicerManager::SetNextTSlice(int originating_slicer)
 {
-  int t = mSlicers[0]->GetTSlice();
+  int t = mSlicers[0]->GetMaxCurrentTSlice();
   t++;
   if (t > mSlicers[0]->GetTMax())
     t = 0;
@@ -467,7 +467,7 @@ void vvSlicerManager::SetNextTSlice(int originating_slicer)
 //----------------------------------------------------------------------------
 void vvSlicerManager::SetPreviousTSlice(int originating_slicer)
 {
-  int t = mSlicers[0]->GetTSlice();
+  int t = mSlicers[0]->GetMaxCurrentTSlice();
   t--;
   if (t < 0)
     t = mSlicers[0]->GetTMax();
@@ -502,16 +502,17 @@ void vvSlicerManager::SetTSliceInSlicer(int tslice, int slicer)
   if (mLandmarks)
     mLandmarks->SetTime(tslice);
 
-  if (mSlicers[slicer]->GetTSlice() == tslice) return;
+  if (mSlicers[slicer]->GetMaxCurrentTSlice() == tslice) return;
+
+  mSlicers[slicer]->SetTSlice(tslice);
 
   if(mSlicingPreset==VOXELS_SLICING) {
     vtkMatrix4x4 *imageTransformInverse = vtkMatrix4x4::New();
-    mImage->GetTransform()[tslice]->GetInverse(imageTransformInverse);
+    mImage->GetTransform()[mSlicers[slicer]->GetTSlice()]->GetInverse(imageTransformInverse);
     this->GetSlicer(slicer)->GetSlicingTransform()->SetMatrix(imageTransformInverse);
     imageTransformInverse->Delete();
   }
 
-  mSlicers[slicer]->SetTSlice(tslice);
   UpdateTSlice(slicer);
 }
 //----------------------------------------------------------------------------
@@ -628,11 +629,11 @@ void vvSlicerManager::UpdateViews(int current,int slicer)
           && mSlicers[i]->GetRenderer()->GetDraw()
           && mSlicers[i]->GetRenderWindow()->GetSize()[0] > 2
           && mSlicers[i]->GetRenderWindow()->GetSize()[1] > 2) {
-        mSlicers[i]->SetCurrentPosition(p[0], p[1], p[2], mSlicers[slicer]->GetTSlice());
+        mSlicers[i]->SetCurrentPosition(p[0], p[1], p[2], mSlicers[slicer]->GetMaxCurrentTSlice());
         mSlicers[i]->UpdateCursorPosition();
         if (current) { //do not display corner annotation if image is the one picked
           mSlicers[i]->SetCurrentPosition(-VTK_DOUBLE_MAX,-VTK_DOUBLE_MAX,
-                                          -VTK_DOUBLE_MAX, mSlicers[slicer]->GetTSlice());
+                                          -VTK_DOUBLE_MAX, mSlicers[slicer]->GetMaxCurrentTSlice());
           mSlicers[i]->SetCursorColor(255,10,212);
         } else {
           mSlicers[i]->SetCursorColor(150,10,282);
@@ -684,7 +685,7 @@ void vvSlicerManager::UpdateLinked(int slicer)
       z >= mSlicers[slicer]->GetInput()->GetWholeExtent()[4]-0.5 &&
       z <= mSlicers[slicer]->GetInput()->GetWholeExtent()[5]+0.5) {
     for (std::list<std::string>::const_iterator i = mLinkedId.begin(); i != mLinkedId.end(); i++) {
-      emit UpdateLinkManager(*i, slicer, p[0], p[1], p[2], mSlicers[slicer]->GetTSlice());
+      emit UpdateLinkManager(*i, slicer, p[0], p[1], p[2], mSlicers[slicer]->GetMaxCurrentTSlice());
     }
   }
 }
@@ -939,7 +940,7 @@ void vvSlicerManager::UpdateInfoOnCursorPosition(int slicer)
 
     if (mSlicers[slicer]->GetVFActor() ) {
       displayVec = 1;
-      unsigned int currentTime = mSlicers[slicer]->GetTSlice();
+      unsigned int currentTime = mSlicers[slicer]->GetMaxCurrentTSlice();
       vtkImageData *vf = NULL;
 
       if (mSlicers[slicer]->GetVF()->GetVTKImages().size() > currentTime)
@@ -1026,7 +1027,7 @@ void vvSlicerManager::UpdateSlice(int slicer)
 void vvSlicerManager::UpdateTSlice(int slicer)
 {
   int slice = mSlicers[slicer]->GetSlice();
-  int tslice = mSlicers[slicer]->GetTSlice();
+  int tslice = mSlicers[slicer]->GetMaxCurrentTSlice();
   if (mPreviousSlice[slicer] == slice) {
     if (mPreviousTSlice[slicer] == tslice) {
       //      DD("************** NOTHING ***********");
index 9929e9d4f5c0b4e005dcf5ea7723ba21422d0c1f..73a0ab5efda3e79ba42b604908662a2149806b4b 100644 (file)
@@ -271,7 +271,7 @@ void vvSlicerManagerCommand::Execute(vtkObject *caller,
       //All type of mouse events
       if (event == vtkCommand::LeaveEvent) {
         this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition(-VTK_DOUBLE_MAX,-VTK_DOUBLE_MAX,
-            -VTK_DOUBLE_MAX,this->SM->GetSlicer(VisibleInWindow)->GetTSlice());
+            -VTK_DOUBLE_MAX,this->SM->GetSlicer(VisibleInWindow)->GetMaxCurrentTSlice());
         this->SM->GetSlicer(VisibleInWindow)->Render();
         return;
       }
@@ -368,7 +368,7 @@ void vvSlicerManagerCommand::Execute(vtkObject *caller,
       this->SM->GetSlicer(VisibleInWindow)->GetSlicingTransform()->TransformPoint(p, pt);
 
       this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition(pt[0],pt[1],pt[2],
-          this->SM->GetSlicer(VisibleInWindow)->GetTSlice());
+          this->SM->GetSlicer(VisibleInWindow)->GetMaxCurrentTSlice());
       if (newLandmark) {
         this->SM->AddLandmark(xWorld,yWorld,zWorld,
                               this->SM->GetSlicer(VisibleInWindow)->GetTSlice());