]> Creatis software - clitk.git/blobdiff - vv/vvSlicerManager.cxx
corrected bug in fusion opacity with double values
[clitk.git] / vv / vvSlicerManager.cxx
index fbbc7946febc1a75bbbe2905f8e20f14d2f636a0..813ba2258bc1f2b247b342f9176e5b2be8f91a4b 100644 (file)
@@ -57,7 +57,8 @@ vvSlicerManager::vvSlicerManager(int numberOfSlicers)
   mPreset = 0;
   mOverlayColor = 130;
 
-  mFusionOpacity = 70;
+  mFusionOpacity = 30;
+  mFusionThresOpacity = 1;
   mFusionColorMap = 3;
   mFusionWindow = 1000;
   mFusionLevel = 1000;
@@ -292,6 +293,7 @@ bool vvSlicerManager::SetFusion(std::string filename,int dim, std::string compon
   double *fusRange = mFusionReader->GetOutput()->GetVTKImages()[0]->GetScalarRange();
   mFusionLevel = (fusRange[0]+fusRange[1])/2;
   mFusionWindow = fusRange[1]-fusRange[0];
+
   return true;
 }
 //----------------------------------------------------------------------------
@@ -303,7 +305,11 @@ bool vvSlicerManager::SetVF(std::string filename)
   if (mVectorReader.IsNull())
     mVectorReader = vvImageReader::New();
   mVectorReader->SetInputFilename(filename);
-  mVectorReader->Update(vvImageReader::VECTORFIELD);
+  
+  if (mType == vvImageReader::IMAGEWITHTIME)
+    mVectorReader->Update(vvImageReader::VECTORFIELDWITHTIME);
+  else
+    mVectorReader->Update(vvImageReader::VECTORFIELD);
   if (mVectorReader->GetLastError().size() != 0) {
     mLastError = mVectorReader->GetLastError();
     return false;
@@ -506,7 +512,6 @@ void vvSlicerManager::SetColorWindow(double s)
 }
 //----------------------------------------------------------------------------
 
-
 //----------------------------------------------------------------------------
 void vvSlicerManager::SetColorLevel(double s)
 {
@@ -516,6 +521,33 @@ void vvSlicerManager::SetColorLevel(double s)
 }
 //----------------------------------------------------------------------------
 
+//----------------------------------------------------------------------------
+void vvSlicerManager::SetOverlayColorWindow(double s)
+{
+  for ( unsigned int i = 0; i < mSlicers.size(); i++) {
+    mSlicers[i]->SetOverlayColorWindow(s);
+  }
+}
+//----------------------------------------------------------------------------
+
+//----------------------------------------------------------------------------
+void vvSlicerManager::SetOverlayColorLevel(double s)
+{
+  for ( unsigned int i = 0; i < mSlicers.size(); i++) {
+    mSlicers[i]->SetOverlayColorLevel(s);
+  }
+}
+//----------------------------------------------------------------------------
+
+//----------------------------------------------------------------------------
+void vvSlicerManager::SetLinkOverlayWindowLevel(bool b)
+{
+  for ( unsigned int i = 0; i < mSlicers.size(); i++) {
+    mSlicers[i]->SetLinkOverlayWindowLevel(b);
+  }
+}
+//----------------------------------------------------------------------------
+
 //----------------------------------------------------------------------------
 void vvSlicerManager::SetCursorAndCornerAnnotationVisibility(int s)
 {
@@ -730,6 +762,54 @@ double vvSlicerManager::GetColorLevel()
 }
 //----------------------------------------------------------------------------
 
+//----------------------------------------------------------------------------
+double vvSlicerManager::GetOverlayColorWindow() const
+{
+  if (mSlicers.size())
+    return mSlicers[0]->GetOverlayColorWindow();
+  return -1;
+}
+//----------------------------------------------------------------------------
+
+//----------------------------------------------------------------------------
+double vvSlicerManager::GetOverlayColorLevel() const
+{
+  if (mSlicers.size())
+    return mSlicers[0]->GetOverlayColorLevel();
+  return -1;
+}
+//----------------------------------------------------------------------------
+
+//----------------------------------------------------------------------------
+bool vvSlicerManager::GetLinkOverlayWindowLevel() const
+{
+  if (mSlicers.size())
+    return mSlicers[0]->GetLinkOverlayWindowLevel();
+  return -1;
+}
+//----------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+void vvSlicerManager::ResetTransformationToIdentity(const std::string actorType)
+{
+  if(actorType == "image")
+    this->GetImage()->GetTransform()->Identity();
+  else if(actorType == "overlay")
+    this->GetSlicer(0)->GetOverlay()->GetTransform()->Identity();
+  else if(actorType == "fusion")
+    this->GetSlicer(0)->GetFusion()->GetTransform()->Identity();
+  else if(actorType == "vf")
+    this->GetVF()->GetTransform()->Identity();
+  else
+    return;
+
+  for(int i=0; i< this->GetNumberOfSlicers(); i++){
+    this->GetSlicer(i)->ForceUpdateDisplayExtent();
+    this->GetSlicer(i)->ResetCamera();
+    this->GetSlicer(i)->Render();
+  }
+}
+//------------------------------------------------------------------------------
 
 //----------------------------------------------------------------------------
 void vvSlicerManager::Render()
@@ -923,10 +1003,11 @@ void vvSlicerManager::Picked()
 }
 //----------------------------------------------------------------------------
 
+
 //----------------------------------------------------------------------------
 void vvSlicerManager::UpdateWindowLevel()
 {
-  emit WindowLevelChanged(mSlicers[0]->GetColorWindow(),mSlicers[0]->GetColorLevel(),mPreset,mColorMap);
+  emit WindowLevelChanged();
 }
 //----------------------------------------------------------------------------
 
@@ -1030,14 +1111,34 @@ void vvSlicerManager::SetPreset(int preset)
 
 
 //----------------------------------------------------------------------------
-void vvSlicerManager::SetLocalColorWindowing(const int slicer)
+void vvSlicerManager::SetLocalColorWindowing(const int slicer, const bool bCtrlKey)
 {
   double min, max;
-  this->mSlicers[slicer]->GetExtremasAroundMousePointer(min, max);
-  this->SetColorWindow(max-min);
-  this->SetColorLevel(0.5*(min+max));
-  this->UpdateWindowLevel();
+  int t = this->mSlicers[slicer]->GetTSlice();
+  if(bCtrlKey && this->mSlicers[slicer]->GetFusion()) {
+    this->mSlicers[slicer]->GetExtremasAroundMousePointer(min, max, this->mSlicers[slicer]->GetFusion()->GetVTKImages()[t]);
+    this->SetFusionWindow(max-min);
+    this->SetFusionLevel(0.5*(min+max));
+    this->SetColorMap(mColorMap);
+  }
+  else if(bCtrlKey && this->mSlicers[slicer]->GetOverlay()) {
+    this->mSlicers[slicer]->GetExtremasAroundMousePointer(min, max, this->mSlicers[slicer]->GetOverlay()->GetVTKImages()[t]);
+    if(this->mSlicers[slicer]->GetLinkOverlayWindowLevel()){
+      this->SetColorWindow(max-min);
+      this->SetColorLevel(0.5*(min+max));
+    } else {
+      this->SetOverlayColorWindow(max-min);
+      this->SetOverlayColorLevel(0.5*(min+max));
+    }
+  }
+  else {
+    this->mSlicers[slicer]->GetExtremasAroundMousePointer(min, max, this->mSlicers[slicer]->GetInput());
+    this->SetColorWindow(max-min);
+    this->SetColorLevel(0.5*(min+max));
+    this->SetPreset(6);
+  }
   this->Render();
+  this->UpdateWindowLevel();
 }
 //----------------------------------------------------------------------------
 
@@ -1074,6 +1175,13 @@ void vvSlicerManager::SetColorMap(int colormap)
     LUT->SetHueRange(0.4,0.80);
     break;
   case 3:
+    if (LUT == NULL)
+      LUT = vtkLookupTable::New();
+    LUT->SetValueRange(0.5,1);
+    LUT->SetSaturationRange(1,1);
+    LUT->SetHueRange(0.666,0);
+    break;
+  case 4:
     if (LUT == NULL)
       LUT = vtkLookupTable::New();
     LUT->SetValueRange(0,1);
@@ -1090,29 +1198,56 @@ void vvSlicerManager::SetColorMap(int colormap)
     break;
   }
   if (LUT) {
-    LUT->SetTableRange(level-fabs(window)/4,level+fabs(window)/4);
+    LUT->SetTableRange(level-fabs(window)/2,level+fabs(window)/2);
     LUT->Build();
   }
-  vtkLookupTable* fusLUT = NULL;
-  if (mSlicers[0]->GetFusion()) {
-    fusLUT = vtkLookupTable::New();
+  vtkWindowLevelLookupTable* fusLUT = NULL;
+  if (mSlicers[0]->GetFusion()) { // && mFusionColorMap >= 0) {
+    fusLUT = vtkWindowLevelLookupTable::New();
     double fusRange [2];
     fusRange[0] = mFusionLevel - mFusionWindow/2;
     fusRange[1] = mFusionLevel + mFusionWindow/2;
-    fusLUT->SetTableRange(fusRange[0],fusRange[1]);
+    double* frange = mFusionReader->GetOutput()->GetVTKImages()[0]->GetScalarRange();
+    fusLUT->SetTableRange(frange);
     fusLUT->SetValueRange(1,1);
     fusLUT->SetSaturationRange(1,1);
+    fusLUT->SetAlphaRange(1, 1);
+    fusLUT->SetWindow(mFusionWindow);
+    fusLUT->SetLevel(mFusionLevel);
     if (mFusionColorMap == 1)
       fusLUT->SetHueRange(0,0.18);
     else if (mFusionColorMap == 2)
       fusLUT->SetHueRange(0.4,0.80);
     else if (mFusionColorMap == 3)
+    {
+      fusLUT->SetHueRange(0.666, 0);
+      fusLUT->SetValueRange(0.5, 1);
+    }
+    else if (mFusionColorMap == 4)
       fusLUT->SetHueRange(0,1);
-    fusLUT->Build();
-    if (mFusionColorMap == 0)
-      fusLUT = NULL;
+    else if (mFusionColorMap <= 0)
+    {
+      fusLUT->SetValueRange(0,1);
+      fusLUT->SetSaturationRange(0,0);
+    }
+    
+    fusLUT->ForceBuild();
+    double v[4];
+    
+    // set color table transparency
+    double range_end = frange[0] + (double)mFusionThresOpacity*(frange[1] - frange[0])/100;
+    double curr_value = frange[0];
+    int nvalues = fusLUT->GetNumberOfTableValues();
+    //for (double i = frange[0]; i <= alpha_range_end; i++) {
+    for (double i = 0; curr_value < range_end; i++) {  
+      fusLUT->GetTableValue(i, v);
+      v[3] = 0;
+      fusLUT->SetTableValue(i, v);
+      curr_value += (frange[1] - frange[0])/nvalues;
+    }
   }
   for ( unsigned int i = 0; i < mSlicers.size(); i++) {
+    
     if (mSlicers[i]->GetOverlay()) {
       vtkLookupTable* supLUT = vtkLookupTable::New();
       supLUT->SetTableRange(range[0],range[1]);
@@ -1139,11 +1274,10 @@ void vvSlicerManager::SetColorMap(int colormap)
     } else {
       mSlicers[i]->GetWindowLevel()->SetLookupTable(LUT);
     }
+    
     if (mSlicers[i]->GetFusion()) {
-      mSlicers[i]->GetFusionActor()->SetOpacity(double(mFusionOpacity)/100);
       mSlicers[i]->GetFusionMapper()->SetLookupTable(fusLUT);
-      mSlicers[i]->GetFusionMapper()->SetWindow(mFusionWindow);
-      mSlicers[i]->GetFusionMapper()->SetLevel(mFusionLevel);
+      mSlicers[i]->GetFusionActor()->SetOpacity(double(mFusionOpacity)/100);
     }
   }
   if (fusLUT)