]> Creatis software - clitk.git/blobdiff - vv/vvSlicer.cxx
Merge branch 'master' of git.creatis.insa-lyon.fr:clitk
[clitk.git] / vv / vvSlicer.cxx
index d3a8dec85839cc1902a004fd3a75a851b6c29887..efaf80fde672006a3926428eb8b271163bd30eb5 100644 (file)
@@ -16,6 +16,9 @@
   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
   ===========================================================================**/
 
+#include <QMessageBox>
+#include <QString>
+
 #include "vvSlicer.h"
 #include "vvImage.h"
 #include "vvSlicerManagerCommand.h"
@@ -40,6 +43,7 @@
 #include <vtkDataArray.h>
 #include <vtkFloatArray.h>
 #include <vtkClipPolyData.h>
+#include <vtkActor2DCollection.h>
 #include <vtkGlyph3D.h>
 #include <vtkMath.h>
 #include <vtkCursor3D.h>
@@ -77,6 +81,7 @@ static void copyExtent(int* in, int* to){
 //------------------------------------------------------------------------------
 vvSlicer::vvSlicer()
 {
+       mFusionSequenceCode = -1;
   this->UnInstallPipeline();
   mImage = NULL;
   mReducedExtent = new int[6];
@@ -307,7 +312,7 @@ void vvSlicer::SetCurrentPosition(double x, double y, double z, int t)
   mCurrentBeforeSlicingTransform[1]=y;
   mCurrentBeforeSlicingTransform[2]=z;
   mSlicingTransform->GetInverse()->TransformPoint(mCurrentBeforeSlicingTransform,mCurrent);
-  SetTSlice(t);
+  if (t>=0) SetTSlice(t);
 }
 //------------------------------------------------------------------------------
 
@@ -410,8 +415,9 @@ void vvSlicer::SetOverlay(vvImage::Pointer overlay)
 
 
 //------------------------------------------------------------------------------
-void vvSlicer::SetFusion(vvImage::Pointer fusion)
+void vvSlicer::SetFusion(vvImage::Pointer fusion, int fusionSequenceCode)
 {
+       mFusionSequenceCode = fusionSequenceCode;
   if (fusion->GetVTKImages().size()) {
     mFusion = fusion;
 
@@ -474,7 +480,7 @@ bool vvSlicer::GetActorVisibility(const std::string& actor_type, int overlay_ind
   else if (actor_type == "overlay") {
     vis = this->mOverlayActor->GetVisibility();
   }
-  else if (actor_type == "fusion") {
+  else if ( (actor_type == "fusion") || (actor_type == "fusionSequence") ){
     vis = this->mFusionActor->GetVisibility();
   }
   else if (actor_type == "contour")
@@ -496,7 +502,7 @@ void vvSlicer::SetActorVisibility(const std::string& actor_type, int overlay_ind
   else if (actor_type == "overlay") {
     this->mOverlayActor->SetVisibility(vis);
   }
-  else if (actor_type == "fusion") {
+  else if ( (actor_type == "fusion") || (actor_type == "fusionSequence") ){
     this->mFusionActor->SetVisibility(vis);
   }
   else if (actor_type == "contour")
@@ -576,36 +582,40 @@ void vvSlicer::SetLandmarks(vvLandmarks* landmarks)
 
     if (!mCross)
       mCross = vtkSmartPointer<vtkCursor3D>::New();
+       if (!mClipBox)
+      mClipBox = vtkSmartPointer<vtkBox>::New();
+    if (!mLandClipper)
+      mLandClipper = vtkSmartPointer<vvClipPolyData>::New();
+    if (!mLandGlyph)
+      mLandGlyph = vtkSmartPointer<vtkGlyph3D>::New();
+    if (!mLandMapper)
+      mLandMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
+    if (!mLandActor)
+      mLandActor = vtkSmartPointer<vtkActor>::New();
+
     mCross->SetFocalPoint(0.0,0.0,0.0);
     mCross->SetModelBounds(-10,10,-10,10,-10,10);
     mCross->AllOff();
     mCross->AxesOn();
 
-    if (!mLandGlyph)
-      mLandGlyph = vtkSmartPointer<vtkGlyph3D>::New();
+    mLandClipper->SetClipFunction(mClipBox);
+    mLandClipper->InsideOutOn();
+    mLandClipper->SetInput(mLandmarks->GetOutput());
+
     mLandGlyph->SetSource(mCross->GetOutput());
-    mLandGlyph->SetInput(landmarks->GetOutput());
+    mLandGlyph->SetInput(mLandClipper->GetOutput());
     //mLandGlyph->SetIndexModeToScalar();
-    mLandGlyph->SetRange(0,1);
-    mLandGlyph->ScalingOff();
+    //mLandGlyph->SetRange(0,1);
+    //mLandGlyph->ScalingOff();
 
-    mLandGlyph->SetColorModeToColorByScalar();
-
-    if (!mClipBox)
-      mClipBox = vtkSmartPointer<vtkBox>::New();
-    if (!mLandClipper)
-      mLandClipper = vtkSmartPointer<vtkClipPolyData>::New();
-    mLandClipper->InsideOutOn();
-    mLandClipper->SetInput(mLandGlyph->GetOutput());
-    mLandClipper->SetClipFunction(mClipBox);
+    //mLandGlyph->SetColorModeToColorByScalar();
+    
+    mLandGlyph->SetScaleModeToDataScalingOff();
+    mLandGlyph->SetIndexModeToOff();
 
-    if (!mLandMapper)
-      mLandMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
-    mLandMapper->SetInputConnection(mLandClipper->GetOutputPort());
+    mLandMapper->SetInputConnection(mLandGlyph->GetOutputPort());
     //mLandMapper->ScalarVisibilityOff();
 
-    if (!mLandActor)
-      mLandActor = vtkSmartPointer<vtkActor>::New();
     mLandActor->SetMapper(mLandMapper);
     mLandActor->GetProperty()->SetColor(255,10,212);
     mLandActor->SetPickable(0);
@@ -636,7 +646,7 @@ void vvSlicer::RemoveActor(const std::string& actor_type, int overlay_index)
     mOverlayActor = NULL;
     mOverlayMapper = NULL;
   }
-  if (actor_type == "fusion") {
+  if ( (actor_type == "fusion") || (actor_type == "fusionSequence") ) {
     Renderer->RemoveActor(mFusionActor);
     mFusion = NULL;
     mFusionActor = NULL;
@@ -701,8 +711,19 @@ void vvSlicer::SetVFLog(int log)
 
 
 //------------------------------------------------------------------------------
-void vvSlicer::SetTSlice(int t)
+void vvSlicer::SetTSlice(int t, bool updateLinkedImages)
 {
+       if (!updateLinkedImages) {
+               mCurrentTSlice = t;
+               mImageReslice->SetInput( mImage->GetVTKImages()[mCurrentTSlice] );
+               // Update transform
+               mConcatenatedTransform->Identity();
+               mConcatenatedTransform->Concatenate(mImage->GetTransform()[mCurrentTSlice]);
+               mConcatenatedTransform->Concatenate(mSlicingTransform);
+               UpdateDisplayExtent();
+               return;
+       }
+
   if (t < 0)
     mCurrentTSlice = 0;
   else if ((unsigned int)t >= mImage->GetVTKImages().size())
@@ -721,6 +742,7 @@ void vvSlicer::SetTSlice(int t)
     if (mVF->GetVTKImages().size() > (unsigned int)mCurrentTSlice)
       mVOIFilter->SetInput(mVF->GetVTKImages()[mCurrentTSlice]);
   }
+  //update the overlay
   if (mOverlay && mOverlayActor->GetVisibility()) {
     if (mOverlay->GetVTKImages().size() > (unsigned int)t) {
       mCurrentOverlayTSlice = t;
@@ -732,7 +754,8 @@ void vvSlicer::SetTSlice(int t)
       mConcatenatedOverlayTransform->Concatenate(mSlicingTransform);
     }
   }
-  if (mFusion && mFusionActor->GetVisibility()) {
+  //update the fusion ; except in case this is a fusionSequence, in which case both 'times' should be independent.
+  if (mFusion && mFusionActor->GetVisibility() && (mFusionSequenceCode<0)) {
     if (mFusion->GetVTKImages().size() > (unsigned int)t) {
       mCurrentFusionTSlice = t;
       mFusionReslice->SetInput( mFusion->GetVTKImages()[mCurrentFusionTSlice]);
@@ -752,6 +775,25 @@ void vvSlicer::SetTSlice(int t)
 //------------------------------------------------------------------------------
 
 
+//------------------------------------------------------------------------------
+void vvSlicer::SetFusionSequenceTSlice(int t)
+{
+  if (mFusion && mFusionActor->GetVisibility() && (mFusionSequenceCode>=0)) {
+    if (mFusion->GetVTKImages().size() > (unsigned int)t) {
+      mCurrentFusionTSlice = t;
+      mFusionReslice->SetInput( mFusion->GetVTKImages()[mCurrentFusionTSlice] );
+      // Update fusion transform
+      mConcatenatedFusionTransform->Identity();
+      mConcatenatedFusionTransform->Concatenate(mFusion->GetTransform()[mCurrentFusionTSlice]); //not really useful...
+      mConcatenatedFusionTransform->Concatenate(mSlicingTransform);
+    }
+  }
+
+  UpdateDisplayExtent();
+}
+//------------------------------------------------------------------------------
+
+
 //------------------------------------------------------------------------------
 int vvSlicer::GetTSlice()
 {
@@ -765,7 +807,7 @@ int vvSlicer::GetMaxCurrentTSlice()
   int t = mCurrentTSlice;
   if(mOverlay)
     t = std::max(t, mCurrentOverlayTSlice);
-  if(mFusion)
+  if(mFusion&& (mFusionSequenceCode<0)) //ignore fusionSequence data: for these, the times are not to be related (this way)
     t = std::max(t, mCurrentFusionTSlice);
   return t;
 }
@@ -1003,7 +1045,6 @@ void vvSlicer::UpdateDisplayExtent()
       }
     }
   }
-  
 }
 //----------------------------------------------------------------------------
 
@@ -1142,9 +1183,8 @@ void vvSlicer::ResetCamera()
 //----------------------------------------------------------------------------
 void vvSlicer::SetDisplayMode(bool i)
 {
-  this->GetRenderer()->SetDraw(i);
-  if (i)
-    UpdateDisplayExtent();
+       this->GetRenderer()->SetDraw(i);
+       if (i) UpdateDisplayExtent();
 }
 //----------------------------------------------------------------------------
 
@@ -1319,6 +1359,7 @@ double vvSlicer::GetScalarComponentAsDouble(vtkImageData *image, double X, doubl
   ix = lrint(X);
   iy = lrint(Y);
   iz = lrint(Z);
+
   if (ix < image->GetWholeExtent()[0] ||
       ix > image->GetWholeExtent()[1] ||
       iy < image->GetWholeExtent()[2] ||
@@ -1391,12 +1432,12 @@ void vvSlicer::Render()
     double yCursor = (y - this->GetInput()->GetOrigin()[1])/this->GetInput()->GetSpacing()[1];
     double zCursor = (z - this->GetInput()->GetOrigin()[2])/this->GetInput()->GetSpacing()[2];
 
-    if (xCursor >= this->GetImageActor()->GetDisplayExtent()[0] &&
-        xCursor < this->GetImageActor()->GetDisplayExtent()[1]+1 &&
-        yCursor >= this->GetImageActor()->GetDisplayExtent()[2] &&
-        yCursor < this->GetImageActor()->GetDisplayExtent()[3]+1 &&
-        zCursor >= this->GetImageActor()->GetDisplayExtent()[4] &&
-        zCursor < this->GetImageActor()->GetDisplayExtent()[5]+1 ) {
+    if (xCursor >= this->GetImageActor()->GetDisplayExtent()[0]-0.5 &&
+        xCursor < this->GetImageActor()->GetDisplayExtent()[1]+0.5 &&
+        yCursor >= this->GetImageActor()->GetDisplayExtent()[2]-0.5 &&
+        yCursor < this->GetImageActor()->GetDisplayExtent()[3]+0.5 &&
+        zCursor >= this->GetImageActor()->GetDisplayExtent()[4]-0.5 &&
+        zCursor < this->GetImageActor()->GetDisplayExtent()[5]+0.5 ) {
       vtkRenderer * renderer = this->Renderer;
 
       renderer->WorldToView(x,y,z);
@@ -1444,13 +1485,38 @@ void vvSlicer::UpdateLandmarks()
 {
   vtkPolyData *pd = static_cast<vtkPolyData*>(mLandClipper->GetInput());
   if (pd->GetPoints()) {
-    mLandGlyph->SetRange(0,1);
-    mLandGlyph->Modified();
-    mLandGlyph->Update();
+    //mLandGlyph->SetRange(0,1);
+    //mLandGlyph->Modified();
+    //mLandGlyph->Update();
 
     mClipBox->Modified();
     mLandClipper->Update();
     mLandMapper->Update();
+    //Let's add the captions
+    //First remove all captions:
+    for(unsigned int i=0;i<mLandLabelActors.size();i++) {
+       this->Renderer->RemoveActor2D(mLandLabelActors[i]);
+       //allActors2D->Remove (mLandLabelActors[i]);
+    }
+    mLandLabelActors.clear();
+    //Next add the captions to the displayed points
+    for (vtkIdType id=0; id<mLandClipper->GetOutput()->GetNumberOfPoints(); id++) {
+         double *position = mLandClipper->GetOutput()->GetPoint(id);
+      vtkStdString label = static_cast<vtkStringArray*>(mLandClipper->GetOutput()->GetPointData()->GetAbstractArray("labels"))->GetValue(id);
+      vtkSmartPointer<vtkCaptionActor2D> label_actor = vtkSmartPointer<vtkCaptionActor2D>::New();
+      label_actor->SetCaption(label);
+      label_actor->SetAttachmentPoint(position);
+      label_actor->GetCaptionTextProperty()->SetColor(1,0,0);
+      label_actor->GetCaptionTextProperty()->SetOrientation(33.333333);
+      label_actor->GetCaptionTextProperty()->SetFontFamilyToTimes();
+      label_actor->GetCaptionTextProperty()->SetBold(0);
+      label_actor->GetCaptionTextProperty()->SetFontSize(6);
+      label_actor->BorderOff();
+      label_actor->LeaderOff();
+      label_actor->ThreeDimensionalLeaderOff();
+      mLandLabelActors.push_back(label_actor);
+      this->Renderer->AddActor2D(mLandLabelActors[id]);
+     }
   }
 
 }