]> Creatis software - clitk.git/blobdiff - vv/vvSlicerManager.cxx
corrected bug in fusion opacity with double values
[clitk.git] / vv / vvSlicerManager.cxx
index fd8f09fccc30b4667a6e271076ca5000f2839512..813ba2258bc1f2b247b342f9176e5b2be8f91a4b 100644 (file)
@@ -57,7 +57,7 @@ vvSlicerManager::vvSlicerManager(int numberOfSlicers)
   mPreset = 0;
   mOverlayColor = 130;
 
-  mFusionOpacity = 70;
+  mFusionOpacity = 30;
   mFusionThresOpacity = 1;
   mFusionColorMap = 3;
   mFusionWindow = 1000;
@@ -512,7 +512,6 @@ void vvSlicerManager::SetColorWindow(double s)
 }
 //----------------------------------------------------------------------------
 
-
 //----------------------------------------------------------------------------
 void vvSlicerManager::SetColorLevel(double s)
 {
@@ -522,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)
 {
@@ -736,6 +762,33 @@ 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)
 {
@@ -950,10 +1003,11 @@ void vvSlicerManager::Picked()
 }
 //----------------------------------------------------------------------------
 
+
 //----------------------------------------------------------------------------
 void vvSlicerManager::UpdateWindowLevel()
 {
-  emit WindowLevelChanged(mSlicers[0]->GetColorWindow(),mSlicers[0]->GetColorLevel(),mPreset,mColorMap);
+  emit WindowLevelChanged();
 }
 //----------------------------------------------------------------------------
 
@@ -1057,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();
 }
 //----------------------------------------------------------------------------
 
@@ -1124,7 +1198,7 @@ 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();
   }
   vtkWindowLevelLookupTable* fusLUT = NULL;
@@ -1158,15 +1232,18 @@ void vvSlicerManager::SetColorMap(int colormap)
     }
     
     fusLUT->ForceBuild();
+    double v[4];
     
     // set color table transparency
-    double alpha_range_end = frange[0] + (double)mFusionThresOpacity*(frange[1] - frange[0])/100;
-    for (double i = frange[0]; i < alpha_range_end; i++) {
-      double v[4];
-      vtkIdType index = fusLUT->GetIndex(i);
-      fusLUT->GetTableValue(index, v);
+    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(index, v);
+      fusLUT->SetTableValue(i, v);
+      curr_value += (frange[1] - frange[0])/nvalues;
     }
   }
   for ( unsigned int i = 0; i < mSlicers.size(); i++) {