]> Creatis software - clitk.git/blobdiff - vv/vvSlicer.cxx
Corrected LocalWindowing: now really in screen (view) coordinates
[clitk.git] / vv / vvSlicer.cxx
index 35897ddbfa151784b6843742c4830c73a8bd30ad..03ecaaaff126bcf49f27ddb5643c3b4b6d470e0a 100644 (file)
 #include <vtkExtractVOI.h>
 #include <vtkSphereSource.h>
 #include <vtkCutter.h>
-#include <vtkPlane.h>
 #include <vtkAssignAttribute.h>
+#include <vtkImageAccumulate.h>
 
 vtkCxxRevisionMacro(vvSlicer, "DummyRevision");
 vtkStandardNewMacro(vvSlicer);
 
+//------------------------------------------------------------------------------
 vvSlicer::vvSlicer()
 {
   mImage = NULL;
   mCurrentTSlice = 0;
+  mUseReducedExtent = false;
 
   mCurrent[0] = -VTK_DOUBLE_MAX;
   mCurrent[1] = -VTK_DOUBLE_MAX;
@@ -96,6 +98,7 @@ vvSlicer::vvSlicer()
   text += "F5 = horizontal flip; F6 = vertical flip\n\n";
   text += "0,1,2,3,4,5 : preset windowing\n";
   text += "6,7,8,9 : preset colormap\n";
+  text += "z : local windowing\n";
   text += "r : reset view\n";
   text += "l : reload image\n";
   text += "f : fly to mouse position\n";
@@ -144,27 +147,66 @@ vvSlicer::vvSlicer()
   this->WindowLevel = vvImageMapToWLColors::New();
   this->InstallPipeline();
 }
+//------------------------------------------------------------------------------
 
+
+//------------------------------------------------------------------------------
 vtkImageMapToWindowLevelColors* vvSlicer::GetOverlayMapper() {
   return mOverlayMapper.GetPointer();
 }
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
 vtkImageActor* vvSlicer::GetOverlayActor() {
   return mOverlayActor.GetPointer();
 }
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
 vtkImageMapToWindowLevelColors* vvSlicer::GetFusionMapper() {
   return mFusionMapper.GetPointer();
 }
+//------------------------------------------------------------------------------
+
     
+//------------------------------------------------------------------------------
 vtkImageActor* vvSlicer::GetFusionActor() {
   return mFusionActor.GetPointer();
 }
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
 vtkActor* vvSlicer::GetVFActor() {
   return mVFActor.GetPointer();
 }
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
 vtkCornerAnnotation* vvSlicer::GetAnnotation() {
   return ca.GetPointer();
 }
+//------------------------------------------------------------------------------
+
 
+//------------------------------------------------------------------------------
+void vvSlicer::EnableReducedExtent(bool b) {
+  mUseReducedExtent = b;
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvSlicer::SetReducedExtent(int * ext) {
+  mReducedExtent = ext;
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
 void vvSlicer::AddContour(vvMesh::Pointer contour,bool propagate)
 {
 
@@ -178,34 +220,54 @@ void vvSlicer::AddContour(vvMesh::Pointer contour,bool propagate)
 
   SetContourSlice();
 }
+//------------------------------------------------------------------------------
+
 
+//------------------------------------------------------------------------------
 void vvSlicer::ToggleContourSuperposition()
 {
   for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
        i!=mSurfaceCutActors.end();i++)
     (*i)->ToggleSuperposition();
 }
+//------------------------------------------------------------------------------
+
 
+//------------------------------------------------------------------------------
 void vvSlicer::SetCursorColor(int r,int g, int b)
 {
   pdmA->GetProperty()->SetColor(r,g,b);
 }
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
 void vvSlicer::SetCursorVisibility(bool s)
 {
   pdmA->SetVisibility(s);
 }
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
 bool vvSlicer::GetCursorVisibility()
 {
   return pdmA->GetVisibility();
 }
+//------------------------------------------------------------------------------
+
 
+//------------------------------------------------------------------------------
 vvSlicer::~vvSlicer()
 {
   for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
        i!=mSurfaceCutActors.end();i++)
     delete (*i);
 }
+//------------------------------------------------------------------------------
 
+
+//------------------------------------------------------------------------------
 void vvSlicer::SetCurrentPosition(double x, double y, double z, int t)
 {
   mCurrent[0] = x;
@@ -213,7 +275,10 @@ void vvSlicer::SetCurrentPosition(double x, double y, double z, int t)
   mCurrent[2] = z;
   mCurrentTSlice = t;
 }
+//------------------------------------------------------------------------------
+
 
+//------------------------------------------------------------------------------
 void vvSlicer::SetImage(vvImage::Pointer image)
 {
   if (image->GetVTKImages().size())
@@ -225,7 +290,10 @@ void vvSlicer::SetImage(vvImage::Pointer image)
       ca->SetText(0,mFileName.c_str());
     }
 }
+//------------------------------------------------------------------------------
 
+
+//------------------------------------------------------------------------------
 void vvSlicer::SetOverlay(vvImage::Pointer overlay)
 {
   if (overlay->GetVTKImages().size())
@@ -260,7 +328,10 @@ void vvSlicer::SetOverlay(vvImage::Pointer overlay)
       SetTSlice(mCurrentTSlice);
     }
 }
+//------------------------------------------------------------------------------
+
 
+//------------------------------------------------------------------------------
 void vvSlicer::SetFusion(vvImage::Pointer fusion)
 {
   if (fusion->GetVTKImages().size())
@@ -286,7 +357,10 @@ void vvSlicer::SetFusion(vvImage::Pointer fusion)
       SetTSlice(mCurrentTSlice);
     }
 }
+//------------------------------------------------------------------------------
+
 
+//------------------------------------------------------------------------------
 void vvSlicer::SetActorVisibility(const std::string& actor_type, int overlay_index ,bool vis)
 {
   if (actor_type == "vector")
@@ -305,7 +379,10 @@ void vvSlicer::SetActorVisibility(const std::string& actor_type, int overlay_ind
     this->mSurfaceCutActors[overlay_index]->GetActor()->SetVisibility(vis);
   UpdateDisplayExtent();
 }
+//------------------------------------------------------------------------------
 
+
+//------------------------------------------------------------------------------
 void vvSlicer::SetVF(vvImage::Pointer vf)
 {
   if (vf->GetVTKImages().size())
@@ -357,7 +434,10 @@ void vvSlicer::SetVF(vvImage::Pointer vf)
       SetTSlice(mCurrentTSlice);
     }
 }
+//------------------------------------------------------------------------------
+
 
+//------------------------------------------------------------------------------
 void vvSlicer::SetLandmarks(vvLandmarks* landmarks)
 {
   mLandmarks = landmarks;
@@ -404,7 +484,9 @@ void vvSlicer::SetLandmarks(vvLandmarks* landmarks)
       this->GetRenderer()->AddActor(mLandActor);
     }
 }
+//------------------------------------------------------------------------------
 
+//------------------------------------------------------------------------------
 //FIXME: this function leaks memory, we should fix it someday :)
 void vvSlicer::RemoveActor(const std::string& actor_type, int overlay_index)
 {
@@ -439,7 +521,10 @@ void vvSlicer::RemoveActor(const std::string& actor_type, int overlay_index)
       mSurfaceCutActors.erase(mSurfaceCutActors.begin()+overlay_index);
     }
 }
+//------------------------------------------------------------------------------
 
+
+//------------------------------------------------------------------------------
 void vvSlicer::SetVFSubSampling(int sub)
 {
   if (mVOIFilter)
@@ -450,7 +535,10 @@ void vvSlicer::SetVFSubSampling(int sub)
   UpdateDisplayExtent();
   Render();
 }
+//------------------------------------------------------------------------------
+
 
+//------------------------------------------------------------------------------
 void vvSlicer::SetVFScale(int scale)
 {
   mScale = scale;
@@ -459,7 +547,10 @@ void vvSlicer::SetVFScale(int scale)
   UpdateDisplayExtent();
   Render();
 }
+//------------------------------------------------------------------------------
+
 
+//------------------------------------------------------------------------------
 void vvSlicer::SetVFLog(int log)
 {
   mVFLog = log;
@@ -471,7 +562,10 @@ void vvSlicer::SetVFLog(int log)
   UpdateDisplayExtent();
   Render();
 }
+//------------------------------------------------------------------------------
 
+
+//------------------------------------------------------------------------------
 void vvSlicer::SetTSlice(int t)
 {
   if (t < 0)
@@ -501,12 +595,18 @@ void vvSlicer::SetTSlice(int t)
       (*i)->SetTimeSlice(mCurrentTSlice);
   UpdateDisplayExtent();
 }
+//------------------------------------------------------------------------------
+
 
+//------------------------------------------------------------------------------
 int vvSlicer::GetTSlice()
 {
   return mCurrentTSlice;
 }
+//------------------------------------------------------------------------------
 
+
+//------------------------------------------------------------------------------
 void vvSlicer::SetSliceOrientation(int orientation)
 {
   //if 2D image, force to watch in Axial View
@@ -551,7 +651,12 @@ void vvSlicer::UpdateDisplayExtent()
       return;
     }
   input->UpdateInformation();
-  int *w_ext = input->GetWholeExtent();
+  int *w_ext;// = input->GetWholeExtent();
+
+  if (mUseReducedExtent) {
+    w_ext = mReducedExtent;
+  }
+  else w_ext = input->GetWholeExtent();
 
   switch (this->SliceOrientation)
     {
@@ -755,7 +860,10 @@ void vvSlicer::UpdateDisplayExtent()
         }
     }
 }
+//----------------------------------------------------------------------------
 
+
+//----------------------------------------------------------------------------
 void vvSlicer::ComputeVFDisplayedExtent(int x1,int x2,int y1,int y2,int z1,int z2,int vfExtent[6])
 {
   vtkImageData* image=this->GetInput();
@@ -774,7 +882,10 @@ void vvSlicer::ComputeVFDisplayedExtent(int x1,int x2,int y1,int y2,int z1,int z
 
   ClipDisplayedExtent(vfExtent,mVOIFilter->GetInput()->GetWholeExtent());
 }
+//----------------------------------------------------------------------------
+
 
+//----------------------------------------------------------------------------
 void vvSlicer::ComputeOverlayDisplayedExtent(int x1,int x2,int y1,int y2,int z1,int z2,int overExtent[6])
 {
   vtkImageData* image=this->GetInput();
@@ -792,7 +903,10 @@ void vvSlicer::ComputeOverlayDisplayedExtent(int x1,int x2,int y1,int y2,int z1,
     mOverlay->GetSpacing()[2];
   ClipDisplayedExtent(overExtent, mOverlayMapper->GetInput()->GetWholeExtent());
 }
+//----------------------------------------------------------------------------
+
 
+//----------------------------------------------------------------------------
 void vvSlicer::ComputeFusionDisplayedExtent(int x1,int x2,int y1,int y2,int z1,int z2,int fusExtent[6])
 {
   vtkImageData* image=this->GetInput();
@@ -810,7 +924,10 @@ void vvSlicer::ComputeFusionDisplayedExtent(int x1,int x2,int y1,int y2,int z1,i
     mFusion->GetSpacing()[2];
   ClipDisplayedExtent(fusExtent, mFusionMapper->GetInput()->GetWholeExtent());
 }
+//----------------------------------------------------------------------------
+
 
+//----------------------------------------------------------------------------
 void vvSlicer::ClipDisplayedExtent(int extent[6], int refExtent[6])
 {
   bool out = false;
@@ -845,7 +962,10 @@ void vvSlicer::ClipDisplayedExtent(int extent[6], int refExtent[6])
         extent[i+1] = refExtent[i];
       }
 }
+//----------------------------------------------------------------------------
+
 
+//----------------------------------------------------------------------------
 void vvSlicer::UpdateOrientation()
 {
   // Set the camera position
@@ -874,12 +994,18 @@ void vvSlicer::UpdateOrientation()
         }
     }
 }
+//----------------------------------------------------------------------------
+
 
+//----------------------------------------------------------------------------
 void vvSlicer::SetOpacity(double s)
 {
   this->GetImageActor()->SetOpacity(s);
 }
+//----------------------------------------------------------------------------
 
+
+//----------------------------------------------------------------------------
 void vvSlicer::SetRenderWindow(int orientation, vtkRenderWindow * rw)
 {
   this->Superclass::SetRenderWindow(rw);
@@ -909,7 +1035,10 @@ void vvSlicer::SetRenderWindow(int orientation, vtkRenderWindow * rw)
   SetSliceOrientation(2-(orientation%3));
   ResetCamera();
 }
+//----------------------------------------------------------------------------
 
+
+//----------------------------------------------------------------------------
 void vvSlicer::ResetCamera()
 {
   if (this->GetInput())
@@ -922,7 +1051,10 @@ void vvSlicer::ResetCamera()
       this->GetRenderer()->GetActiveCamera()->SetParallelScale(bmax/2);
     }
 }
+//----------------------------------------------------------------------------
+
 
+//----------------------------------------------------------------------------
 void vvSlicer::SetDisplayMode(bool i)
 {
   this->GetImageActor()->SetVisibility(i);
@@ -1009,6 +1141,56 @@ void vvSlicer::SetColorLevel(double level)
 }
 //----------------------------------------------------------------------------
 
+//----------------------------------------------------------------------------
+// Returns the min an the max value in a 41x41 region around the mouse pointer
+void vvSlicer::GetExtremasAroundMousePointer(double & min, double & max)
+{
+    //Get mouse pointer position in view coordinates
+    double fLocalExtents[6];
+    for(int i=0; i<3; i++)
+    {
+        fLocalExtents[i*2  ] = mCurrent[i];
+        fLocalExtents[i*2+1] = mCurrent[i];
+    }
+    this->Renderer->WorldToView(fLocalExtents[0], fLocalExtents[2], fLocalExtents[4]);
+    this->Renderer->WorldToView(fLocalExtents[1], fLocalExtents[3], fLocalExtents[5]);
+    for(int i=0; i<3; i++)
+    {
+        if (i!=SliceOrientation) //SR: assumes that SliceOrientation is valid in ViewCoordinates (???)
+        {
+            fLocalExtents[i*2  ] -= 0.2;
+            fLocalExtents[i*2+1] += 0.2;
+        }
+    }
+    this->Renderer->ViewToWorld(fLocalExtents[0], fLocalExtents[2], fLocalExtents[4]);
+    this->Renderer->ViewToWorld(fLocalExtents[1], fLocalExtents[3], fLocalExtents[5]);
+
+    //Convert to image pixel coordinates (rounded)
+    int iLocalExtents[6];
+    for(int i=0; i<3; i++)
+    {
+        fLocalExtents[i*2  ] = (fLocalExtents[i*2  ] - this->GetInput()->GetOrigin()[i])/this->GetInput()->GetSpacing()[i];
+        fLocalExtents[i*2+1] = (fLocalExtents[i*2+1] - this->GetInput()->GetOrigin()[i])/this->GetInput()->GetSpacing()[i];
+    
+        iLocalExtents[i*2  ] = lrint(fLocalExtents[i*2  ]);
+        iLocalExtents[i*2+1] = lrint(fLocalExtents[i*2+1]);
+
+        if(iLocalExtents[i*2  ]>iLocalExtents[i*2+1])
+            std::swap(iLocalExtents[i*2], iLocalExtents[i*2+1]);
+    }
+    
+    vtkSmartPointer<vtkExtractVOI> voiFilter = vtkExtractVOI::New();
+    voiFilter->SetInput(this->GetInput());
+    voiFilter->SetVOI(iLocalExtents);
+
+    vtkSmartPointer<vtkImageAccumulate> accFilter = vtkImageAccumulate::New();
+    accFilter->SetInput(voiFilter->GetOutput());
+    accFilter->Update();
+   
+    min = *(accFilter->GetMin());
+    max = *(accFilter->GetMax());
+}
+//----------------------------------------------------------------------------
 
 //----------------------------------------------------------------------------
 void vvSlicer::Render()
@@ -1085,8 +1267,10 @@ void vvSlicer::Render()
           std::stringstream val;
           val << value;
           worldPos += "data value : " + val.str();
-          worldPos += "\n mm : " + world1.str() + " " + world2.str() + " " + world3.str() + " " + temps.str();
-          worldPos += "\n pixel : " + pixel1.str() + " " + pixel2.str() + " " + pixel3.str() + " " + temps.str();
+          worldPos += "\n mm : " + world1.str() + " " + world2.str() + " " + 
+            world3.str() + " " + temps.str();
+          worldPos += "\n pixel : " + pixel1.str() + " " + pixel2.str() + " " + 
+            pixel3.str() + " " + temps.str();
         }
       ca->SetText(1,worldPos.c_str());
     }
@@ -1118,6 +1302,7 @@ void vvSlicer::UpdateCursorPosition()
 }
 //----------------------------------------------------------------------------
 
+
 //----------------------------------------------------------------------------
 void vvSlicer::UpdateLandmarks()
 {