]> Creatis software - clitk.git/blobdiff - vv/vvSlicer.cxx
add include
[clitk.git] / vv / vvSlicer.cxx
index 0c7852ad12e83b2c31518b4b3e75e8f82cbcacdc..dd585636c5a76227817ec14cc8ded56fd548f132 100644 (file)
@@ -155,6 +155,7 @@ vvSlicer::vvSlicer()
   mConcatenatedTransform = vtkSmartPointer<vtkTransform>::New();
   mConcatenatedFusionTransform = vtkSmartPointer<vtkTransform>::New();
   mConcatenatedOverlayTransform = vtkSmartPointer<vtkTransform>::New();
+  mFirstSetSliceOrientation = true;
 }
 //------------------------------------------------------------------------------
 
@@ -853,15 +854,17 @@ void vvSlicer::SetSliceOrientation(int orientation)
   // DDV(cursorPos, 3);
   // SetCurrentPosition(cursorPos[0],cursorPos[1],cursorPos[2],cursorPos[3]);
 
-  if (this->Renderer && this->GetInput()) {
+  if (mFirstSetSliceOrientation) {
+    int *range = this->GetSliceRange();
+    if (range)
+      this->Slice = static_cast<int>((range[0] + range[1]) * 0.5);
+    mFirstSetSliceOrientation = false;
+  }
+  else if (this->Renderer && this->GetInput()) {
     double s = mCursor[orientation];
     double sCursor = (s - this->GetInput()->GetOrigin()[orientation])/this->GetInput()->GetSpacing()[orientation];
     this->Slice = static_cast<int>(sCursor);
   }
-  
-//   int *range = this->GetSliceRange();
-//   if (range)
-//     this->Slice = static_cast<int>((range[0] + range[1]) * 0.5);
 
   this->UpdateOrientation();
   this->UpdateDisplayExtent();
@@ -901,11 +904,13 @@ void vvSlicer::AdjustResliceToSliceOrientation(vtkImageReslice *reslice)
   // Step 1: from world coordinates to image coordinates
   origin[this->SliceOrientation] -= mImageReslice->GetOutput()->GetOrigin()[this->SliceOrientation];
   origin[this->SliceOrientation] /= mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
+
   // Step 2: round to nearest grid positionInc. This has been validated as the only
   // way to have something consistent with the thickness of a 2D slice visible on the
   // other slices. The thickness is accounted for so if the 2D slice is to thin and
   // between two slices, one will never be able to see this 2D slice (bug #1883).
   origin[this->SliceOrientation] = itk::Math::Round<double>(origin[this->SliceOrientation]);
+
   // Step 3: back to world coordinates
   origin[this->SliceOrientation] *= mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
   origin[this->SliceOrientation] += mImageReslice->GetOutput()->GetOrigin()[this->SliceOrientation];
@@ -1165,7 +1170,6 @@ void vvSlicer::SetRenderWindow(int orientation, vtkRenderWindow * rw)
   this->SetupInteractor(rw->GetInteractor());
   ca->SetImageActor(this->GetImageActor());
   ca->SetWindowLevel(this->GetWindowLevel());
-  ca->SetText(2, "<slice>");
   ca->SetText(3, "<window>\n<level>");
 
   double bounds[6];
@@ -1302,14 +1306,16 @@ double vvSlicer::GetOverlayColorLevel()
 //----------------------------------------------------------------------------
 void vvSlicer::SetOverlayColorWindow(double window)
 {
-  mOverlayMapper->SetWindow(window);
+  if(mOverlayMapper)
+    mOverlayMapper->SetWindow(window);
 }
 //----------------------------------------------------------------------------
 
 //----------------------------------------------------------------------------
 void vvSlicer::SetOverlayColorLevel(double level)
 {
-  mOverlayMapper->SetLevel(level);
+  if(mOverlayMapper)
+    mOverlayMapper->SetLevel(level);
 }
 //----------------------------------------------------------------------------
 
@@ -1441,6 +1447,10 @@ void vvSlicer::Render()
                              << std::endl;
     }
     ca->SetText(1,worldPos.str().c_str());
+
+    std::stringstream slicePos;
+    slicePos << "Slice: " << this->GetSlice();
+    ca->SetText(2, slicePos.str().c_str());
   }
 
   if (pdmA->GetVisibility()) {