]> Creatis software - clitk.git/blobdiff - vv/vvSlicerManager.cxx
1/ some minor changes for compilation under windows / VC++ 2010 Express
[clitk.git] / vv / vvSlicerManager.cxx
index eb8977dd0548b890388f5cda415785e644d69ac1..b3cd57e91a380d2e5e5ab0d14a83682e6fec84a2 100644 (file)
@@ -23,7 +23,6 @@
 #include "vvInteractorStyleNavigator.h"
 #include "vvLandmarks.h"
 #include "vvMesh.h"
-#include "vvImageMapToWLColors.h"
 #include "vvBlendImageActor.h"
 
 #include <vtkImageActor.h>
@@ -41,7 +40,6 @@
 #include <vtkCamera.h>
 
 #include <qfileinfo.h>
-
 //----------------------------------------------------------------------------
 vvSlicerManager::vvSlicerManager(int numberOfSlicers)
 {
@@ -64,15 +62,22 @@ vvSlicerManager::vvSlicerManager(int numberOfSlicers)
   mFusionLevel = 1000;
   mFusionShowLegend = true;
   
+  mFusionSequenceFrameIndex = -1;
+  mFusionSequenceSpatialSyncFlag = false;
+  mFusionSequenceNbFrames = 0;
+
   mLandmarks = NULL;
   mLinkedId.resize(0);
 
   for ( int i = 0; i < numberOfSlicers; i++)
     mSlicers.push_back(vtkSmartPointer<vvSlicer>::New());
-
+  mSelectedSlicer = -1;
+  
   mPreviousSlice.resize(numberOfSlicers);
   mPreviousTSlice.resize(numberOfSlicers);
   mSlicingPreset = WORLD_SLICING;
+
+  
 }
 //----------------------------------------------------------------------------
 
@@ -139,6 +144,8 @@ std::string vvSlicerManager::GetListOfAbsoluteFilePathInOneString(const std::str
     reader = mFusionReader;
   else if(actorType=="vector")
     reader = mVectorReader;
+  else if(actorType=="fusionSequence")
+       reader = mFusionSequenceReader;
 
   if(!reader)
     return "";
@@ -298,6 +305,54 @@ bool vvSlicerManager::SetFusion(std::string filename,int dim, std::string compon
 }
 //----------------------------------------------------------------------------
 
+//----------------------------------------------------------------------------
+bool vvSlicerManager::SetFusionSequence(std::vector<std::string> filenames,int dim, std::string component, vvImageReader::LoadedImageType type)
+{
+  mFusionName = filenames[0];
+  mFusionComponent = component;
+
+  if (dim > mImage->GetNumberOfDimensions()) {
+    mLastError = " Fusion Sequence dimension cannot be greater than reference image!";
+    return false;
+  }
+
+  if (mFusionSequenceReader.IsNull())
+    mFusionSequenceReader = vvImageReader::New();
+
+  mFusionSequenceReader->SetInputFilenames(filenames);
+  mFusionSequenceReader->Update(type);
+
+  //store the initial transform matrices of each frame, and reset them to identity
+  mFusionSequenceListInitialTransformMatrices.clear();
+  for (unsigned i=0 ; i<mFusionSequenceReader->GetOutput()->GetTransform().size() ; i++) {
+         AddFusionSequenceInitialTransformMatrices( mFusionSequenceReader->GetOutput()->GetTransform()[i]->GetMatrix() );
+         mFusionSequenceReader->GetOutput()->GetTransform()[i]->Identity();
+         mFusionSequenceReader->GetOutput()->GetTransform()[i]->Update();
+  }
+
+  //adjust the time slider in the overlay panel
+  mFusionSequenceNbFrames = mFusionSequenceReader->GetOutput()->GetTransform().size()-1; //actually, this is the maximum index...
+  if (mFusionSequenceFrameIndex>=mFusionSequenceNbFrames) {
+         mFusionSequenceFrameIndex=0;
+  }
+
+
+  if (mFusionSequenceReader->GetLastError().size() == 0) {
+    for ( unsigned int i = 0; i < mSlicers.size(); i++) {
+      mSlicers[i]->SetFusion(mFusionSequenceReader->GetOutput());
+    }
+  } else {
+    mLastError = mFusionSequenceReader->GetLastError();
+    return false;
+  }
+  double *fusRange = mFusionSequenceReader->GetOutput()->GetVTKImages()[0]->GetScalarRange();
+  mFusionLevel = (fusRange[0]+fusRange[1])/2;
+  mFusionWindow = fusRange[1]-fusRange[0];
+
+  return true;
+}
+//----------------------------------------------------------------------------
+
 
 //----------------------------------------------------------------------------
 bool vvSlicerManager::SetVF(std::string filename)
@@ -417,6 +472,23 @@ void vvSlicerManager::LeftButtonReleaseEvent(int slicer)
 }
 //----------------------------------------------------------------------------
 
+
+//----------------------------------------------------------------------------
+void vvSlicerManager::EmitMousePositionUpdated(int slicer)
+{
+  emit MousePositionUpdatedSignal(slicer);
+}
+//----------------------------------------------------------------------------
+
+
+//----------------------------------------------------------------------------
+void vvSlicerManager::EmitKeyPressed(std::string KeyPress)
+{
+  emit KeyPressedSignal(KeyPress);
+}
+//----------------------------------------------------------------------------
+
+
 //----------------------------------------------------------------------------
 void vvSlicerManager::SetSliceOrientation(int slicer, int orientation)
 {
@@ -451,6 +523,17 @@ void vvSlicerManager::SetTSlice(int slice)
 //----------------------------------------------------------------------------
 
 
+//----------------------------------------------------------------------------
+void vvSlicerManager::SetFusionSequenceTSlice(int slice)
+{
+       for ( unsigned int i = 0; i < mSlicers.size(); i++) {
+               mSlicers[i]->SetFusionSequenceTSlice(slice);
+               UpdateTSlice(i);
+       }
+}
+//----------------------------------------------------------------------------
+
+
 //----------------------------------------------------------------------------
 void vvSlicerManager::SetNextTSlice(int originating_slicer)
 {
@@ -605,6 +688,7 @@ void vvSlicerManager::UpdateViews(int current,int slicer)
       z <= mSlicers[slicer]->GetInput()->GetWholeExtent()[5]+0.5) {
     mSlicers[slicer]->UpdateCursorPosition();
     mSlicers[slicer]->SetCursorColor(10,212,255);
+    mSelectedSlicer = slicer;
 
     switch (mSlicers[slicer]->GetSliceOrientation()) {
     case vtkImageViewer2::SLICE_ORIENTATION_XY:
@@ -640,18 +724,18 @@ void vvSlicerManager::UpdateViews(int current,int slicer)
         }
         switch (mSlicers[i]->GetSliceOrientation()) {
         case vtkImageViewer2::SLICE_ORIENTATION_XY:
-          if (mSlicers[i]->GetSlice() != (int)floor(z))
-            mSlicers[i]->SetSlice((int)floor(z));
+          if (mSlicers[i]->GetSlice() != (int)lrint(z))
+            mSlicers[i]->SetSlice((int)lrint(z));
           break;
 
         case vtkImageViewer2::SLICE_ORIENTATION_XZ:
-          if (mSlicers[i]->GetSlice() != (int)floor(y))
-            mSlicers[i]->SetSlice((int)floor(y));
+          if (mSlicers[i]->GetSlice() != (int)lrint(y))
+            mSlicers[i]->SetSlice((int)lrint(y));
           break;
 
         case vtkImageViewer2::SLICE_ORIENTATION_YZ:
-          if (mSlicers[i]->GetSlice() != (int)floor(x))
-            mSlicers[i]->SetSlice((int)floor(x));
+          if (mSlicers[i]->GetSlice() != (int)lrint(x))
+            mSlicers[i]->SetSlice((int)lrint(x));
           break;
         }
         
@@ -735,7 +819,7 @@ void vvSlicerManager::UpdateLinkedNavigation(vvSlicer *refSlicer, bool bPropagat
 //----------------------------------------------------------------------------
 
 //----------------------------------------------------------------------------
-double vvSlicerManager::GetColorWindow()
+double vvSlicerManager::GetColorWindow() const
 {
   if (mSlicers.size())
     return mSlicers[0]->GetColorWindow();
@@ -745,7 +829,7 @@ double vvSlicerManager::GetColorWindow()
 
 
 //----------------------------------------------------------------------------
-double vvSlicerManager::GetColorLevel()
+double vvSlicerManager::GetColorLevel() const
 {
   if (mSlicers.size())
     return mSlicers[0]->GetColorLevel();
@@ -792,6 +876,9 @@ void vvSlicerManager::ResetTransformationToIdentity(const std::string actorType)
   else if(actorType == "fusion")
     for(unsigned int i=0; i<this->GetImage()->GetTransform().size(); i++)
       this->GetSlicer(0)->GetFusion()->GetTransform()[i]->Identity();
+  else if(actorType == "fusionSequence") //TODO: Check what should really be done here
+    for(unsigned int i=0; i<this->GetImage()->GetTransform().size(); i++)
+      this->GetSlicer(0)->GetFusion()->GetTransform()[i]->Identity();
   else if(actorType == "vf")
     for(unsigned int i=0; i<this->GetImage()->GetTransform().size(); i++)
       this->GetVF()->GetTransform()[i]->Identity();
@@ -833,6 +920,7 @@ void vvSlicerManager::Reload()
   for ( unsigned int i = 0; i < mSlicers.size(); i++) {
     mSlicers[i]->SetImage(mImage);
   }
+  //TODO: check if this image is involved in a fusion sequence, then the main transform matrix should be updated.
 }
 //----------------------------------------------------------------------------
 
@@ -849,6 +937,33 @@ void vvSlicerManager::ReloadFusion()
 }
 //----------------------------------------------------------------------------
 
+//----------------------------------------------------------------------------
+void vvSlicerManager::ReloadFusionSequence()
+{
+  mFusionSequenceReader->Update(mImage->GetNumberOfDimensions(),mFusionComponent.c_str(),vvImageReader::MERGEDWITHTIME);
+
+  for ( unsigned int i = 0; i < mSlicers.size(); i++) {
+    mSlicers[i]->SetFusion(mFusionSequenceReader->GetOutput());
+    mSlicers[i]->Render();
+  }
+
+  //Update the slider
+  mFusionSequenceNbFrames = mFusionSequenceReader->GetOutput()->GetTransform().size();
+  if (mFusionSequenceFrameIndex>=mFusionSequenceNbFrames) {
+         mFusionSequenceFrameIndex=0;
+  }
+
+  //Update the list of initial transforms
+  //Warning, the main transform will not be updated on reload.........
+  mFusionSequenceListInitialTransformMatrices.clear();
+  for (unsigned i=0 ; i<mFusionSequenceNbFrames ; i++) {
+         this->AddFusionSequenceInitialTransformMatrices( mFusionSequenceReader->GetOutput()->GetTransform()[i]->GetMatrix() );
+  }
+
+  //emit UpdateFusionSequence(mFusionSequenceFrameIndex, mFusionSequenceSpatialSyncFlag, mFusionSequenceNbFrames);
+}
+//----------------------------------------------------------------------------
+
 
 //----------------------------------------------------------------------------
 void vvSlicerManager::ReloadOverlay()
@@ -884,6 +999,10 @@ void vvSlicerManager::RemoveActor(const std::string& actor_type, int overlay_ind
   if (actor_type =="fusion")
     mFusionReader = NULL;
 
+  if (actor_type =="fusionSequence") {
+    mFusionSequenceReader = NULL;
+  }
+
   for (unsigned int i = 0; i < mSlicers.size(); i++)
     mSlicers[i]->RemoveActor(actor_type,overlay_index);
 
@@ -966,14 +1085,17 @@ void vvSlicerManager::UpdateInfoOnCursorPosition(int slicer)
       double Zover = (z - overlay->GetOrigin()[2]) / overlay->GetSpacing()[2];
       valueOver = this->GetScalarComponentAsDouble(overlay, Xover, Yover, Zover);
     }
-    if (mSlicers[slicer]->GetFusionActor() ) {
-      displayFus = 1;
-      vtkImageData *fusion = dynamic_cast<vtkImageData*>(mSlicers[slicer]->GetFusionMapper()->GetInput());
-      double Xover = (x - fusion->GetOrigin()[0]) / fusion->GetSpacing()[0];
-      double Yover = (y - fusion->GetOrigin()[1]) / fusion->GetSpacing()[1];
-      double Zover = (z - fusion->GetOrigin()[2]) / fusion->GetSpacing()[2];
-      valueFus = this->GetScalarComponentAsDouble(fusion, Xover, Yover, Zover);
-    }
+\r
+       if (mSlicers[slicer]->GetFusionActor() ) {\r
+               displayFus = 1;\r
+               vtkImageData *fusion = dynamic_cast<vtkImageData*>(mSlicers[slicer]->GetFusionMapper()->GetInput());\r
+               double Xover = (x - fusion->GetOrigin()[0]) / fusion->GetSpacing()[0];\r
+               double Yover = (y - fusion->GetOrigin()[1]) / fusion->GetSpacing()[1];\r
+               double Zover = (z - fusion->GetOrigin()[2]) / fusion->GetSpacing()[2];\r
+               valueFus = this->GetScalarComponentAsDouble(fusion, Xover, Yover, Zover);\r
+       }\r
+
+
     emit UpdatePosition(mSlicers[slicer]->GetCursorVisibility(),
                         x,y,z,X,Y,Z,value);
     emit UpdateVector(displayVec,xVec, yVec, zVec, valueVec);
@@ -1186,6 +1308,7 @@ void vvSlicerManager::SetLocalColorWindowing(const int slicer, const bool bCtrlK
 void vvSlicerManager::SetColorMap(int colormap)
 {
   double range[2];
+
   range[0] = mSlicers[0]->GetInput()->GetScalarRange()[0];
   range[1] = mSlicers[0]->GetInput()->GetScalarRange()[1];
 
@@ -1243,12 +1366,17 @@ void vvSlicerManager::SetColorMap(int colormap)
   }
   vtkWindowLevelLookupTable* fusLUT = NULL;
   if (mSlicers[0]->GetFusion()) { // && mFusionColorMap >= 0) {
-    fusLUT = vtkWindowLevelLookupTable::New();
+       fusLUT = vtkWindowLevelLookupTable::New();
     double fusRange [2];
     fusRange[0] = mFusionLevel - mFusionWindow/2;
     fusRange[1] = mFusionLevel + mFusionWindow/2;
-    double* frange = mFusionReader->GetOutput()->GetVTKImages()[0]->GetScalarRange();
-    fusLUT->SetTableRange(frange);
+
+       //check whether it is actually a fusionSequence or a fusion, before invoking mFusionReader...
+       double* frange;
+       if (mFusionReader.IsNull()) frange = mFusionSequenceReader->GetOutput()->GetVTKImages()[0]->GetScalarRange();
+    else                        frange = mFusionReader->GetOutput()->GetVTKImages()[0]->GetScalarRange();
+
+       fusLUT->SetTableRange(frange);
     fusLUT->SetValueRange(1,1);
     fusLUT->SetSaturationRange(1,1);
     fusLUT->SetAlphaRange(1, 1);
@@ -1303,15 +1431,11 @@ void vvSlicerManager::SetColorMap(int colormap)
       invLUT->SetSaturationRange(1,1);
       invLUT->SetHueRange(double((mOverlayColor+180)%360)/360,double((mOverlayColor+180)%360)/360);
       invLUT->Build();
-      dynamic_cast<vvImageMapToWLColors*>(mSlicers[i]->GetWindowLevel())
-        ->SetWindowLevelMode(true);
       mSlicers[i]->GetWindowLevel()->SetLookupTable(supLUT);
       mSlicers[i]->GetOverlayMapper()->SetLookupTable(invLUT);
       invLUT->Delete();
       supLUT->Delete();
     } else if (mSlicers[i]->GetOverlay()) {
-      //dynamic_cast<vvImageMapToWLColors*>(mSlicers[i]->GetWindowLevel())
-      //->SetWindowLevelMode(false);
       mSlicers[i]->GetWindowLevel()->SetLookupTable(LUT);
     } else {
       mSlicers[i]->GetWindowLevel()->SetLookupTable(LUT);