]> Creatis software - clitk.git/blobdiff - vv/vvImageContour.cxx
correct bug when reload
[clitk.git] / vv / vvImageContour.cxx
index 56024c8e7942028efdfb2a3de254c5aa83f1949f..1ee32cf906be201abaebf4c950d9ecb001d72a46 100644 (file)
@@ -33,7 +33,8 @@ vvImageContour::vvImageContour()
   mTSlice = -1;
   mSlice = 0;
   mHiddenImageIsUsed = false;
-  mDisplayModeIsPreserveMemory = true;
+  mDisplayModeIsPreserveMemory = false;
+  SetPreserveMemoryModeEnabled(false);
 }
 //------------------------------------------------------------------------------
 
@@ -52,15 +53,14 @@ vvImageContour::~vvImageContour()
 
 
 //------------------------------------------------------------------------------
-void vvImageContour::setSlicer(vvSlicer * slicer)
-{
-  mSlicer = slicer;
+void vvImageContour::SetSlicer(vvSlicer * slicer) {
+  mSlicer = slicer;  
   // Create an actor for each time slice
   for (unsigned int numImage = 0; numImage < mSlicer->GetImage()->GetVTKImages().size(); numImage++) {
     vtkImageClip * mClipper = vtkImageClip::New();
     vtkMarchingSquares * mSquares = vtkMarchingSquares::New();
     vtkActor * mSquaresActor = vtkActor::New();
-    createNewActor(&mSquaresActor, &mSquares, &mClipper, numImage);
+    CreateNewActor(&mSquaresActor, &mSquares, &mClipper, numImage);
     mSquaresActorList.push_back(mSquaresActor);
     mSquaresList.push_back(mSquares);
     mClipperList.push_back(mClipper);
@@ -70,8 +70,7 @@ void vvImageContour::setSlicer(vvSlicer * slicer)
 
 
 //------------------------------------------------------------------------------
-void vvImageContour::setImage(vvImage::Pointer image)
-{
+void vvImageContour::SetImage(vvImage::Pointer image) {
   for (unsigned int numImage = 0; numImage < image->GetVTKImages().size(); numImage++) {
     mClipperList[numImage]->SetInput(image->GetVTKImages()[numImage]);
   }
@@ -82,27 +81,26 @@ void vvImageContour::setImage(vvImage::Pointer image)
 
 
 //------------------------------------------------------------------------------
-void vvImageContour::setPreserveMemoryModeEnabled(bool b)
-{
+void vvImageContour::SetPreserveMemoryModeEnabled(bool b) {
   // FastCache mode work only if threshold is always the same
   if (mDisplayModeIsPreserveMemory == b) return;
   mDisplayModeIsPreserveMemory = b;
   if (!b) {
-    hideActors();
-    initializeCacheMode();
-  } else {
+    HideActors();
+    InitializeCacheMode();
+  }
+  else {
     for(unsigned int d=0; d<mListOfCachedContourActors.size(); d++)
       mListOfCachedContourActors[d].clear();
     mListOfCachedContourActors.clear();
-    showActors();
+    ShowActors();
   }
 }
 //------------------------------------------------------------------------------
 
 
 //------------------------------------------------------------------------------
-void vvImageContour::setColor(double r, double g, double b)
-{
+void vvImageContour::SetColor(double r, double g, double b) {
   for(unsigned int i=0; i<mSquaresActorList.size(); i++) {
     mSquaresActorList[i]->GetProperty()->SetColor(r,g,b);
   }
@@ -121,8 +119,7 @@ void vvImageContour::SetLineWidth(double w)
 
 
 //------------------------------------------------------------------------------
-void vvImageContour::hideActors()
-{
+void vvImageContour::HideActors() {
   if (!mSlicer) return;
   mSlice = mSlicer->GetSlice();
   for(unsigned int i=0; i<mSquaresActorList.size(); i++) {
@@ -133,28 +130,22 @@ void vvImageContour::hideActors()
 
 
 //------------------------------------------------------------------------------
-void vvImageContour::showActors()
-{
+void vvImageContour::ShowActors() {
   if (!mSlicer) return;
   mSlice = mSlicer->GetSlice();
   mTSlice = mSlicer->GetTSlice();
-  //  for(unsigned int i=0; i<mSquaresActorList.size(); i++) {
   mSquaresActorList[mTSlice]->VisibilityOn();
-  update(mValue);
-  //}
+  Update(mValue);
 }
 //------------------------------------------------------------------------------
 
 
 //------------------------------------------------------------------------------
-void vvImageContour::update(double value)
-{
-  //  DD(value);
+void vvImageContour::Update(double value) {
   if (!mSlicer) return;
   if (mPreviousValue == value) {
     if (mPreviousSlice == mSlicer->GetSlice()) {
       if (mPreviousTSlice == mSlicer->GetTSlice()) {
-        // DD("vvImageContour::update nothing");
         return; // Nothing to do
       }
     }
@@ -165,16 +156,15 @@ void vvImageContour::update(double value)
 
   // Get current slice
   mSlice = mSlicer->GetSlice();
-  //  DD(mDisplayModeIsPreserveMemory);
+
   if (mDisplayModeIsPreserveMemory) {
-    updateWithPreserveMemoryMode();
-  } else {
-    updateWithFastCacheMode();
+    UpdateWithPreserveMemoryMode();
+  }
+  else {
+    UpdateWithFastCacheMode();
   }
 
-
-  mSlicer->Render(); //DS ---> REMOVE ??
-
+  //  mSlicer->Render(); //DS ---> REMOVE ??
 
   mPreviousTSlice = mSlicer->GetTSlice();
   mPreviousSlice  = mSlicer->GetSlice();
@@ -184,30 +174,19 @@ void vvImageContour::update(double value)
 
 
 //------------------------------------------------------------------------------
-void vvImageContour::updateWithPreserveMemoryMode()
-{
+void vvImageContour::UpdateWithPreserveMemoryMode() {
   // Only change actor visibility if tslice change
-  //DD(mTSlice);
-  //DD(mSlice);
   int mPreviousTslice = mTSlice;
-  //    ;
-  //   if (mTSlice != mSlicer->GetTSlice()) {
-  //     if (mTSlice != -1) mTsliceToSetOff = mTSlice;
-  //       mSquaresActorList[mTSlice]->VisibilityOff();
   mTSlice = mSlicer->GetTSlice();
-  //   }
-  //  else return;
-  //  DD(mTSlice);
+
   vtkMarchingSquares * mSquares = mSquaresList[mTSlice];
   vtkImageClip * mClipper = mClipperList[mTSlice];
   vtkActor * mSquaresActor = mSquaresActorList[mTSlice];
-  int orientation = computeCurrentOrientation();
-  //  DD(orientation);
-  //DD(mValue);
-  //DD(mSlice);
-  //DD(mPreviousTslice);
-  updateActor(mSquaresActor, mSquares, mClipper, mValue, orientation, mSlice);
+  int orientation = ComputeCurrentOrientation();
+
+  UpdateActor(mSquaresActor, mSquares, mClipper, mValue, orientation, mSlice);
   mSquaresActorList[mTSlice]->VisibilityOn();
+
   if (mPreviousTslice != mTSlice) {
     if (mPreviousTslice != -1) mSquaresActorList[mPreviousTslice]->VisibilityOff();
   }
@@ -216,15 +195,13 @@ void vvImageContour::updateWithPreserveMemoryMode()
 
 
 //------------------------------------------------------------------------------
-void vvImageContour::initializeCacheMode()
-{
+void vvImageContour::InitializeCacheMode() {
   mPreviousSlice = mPreviousOrientation = 0;
   int dim = mSlicer->GetImage()->GetNumberOfDimensions();
 
   mListOfCachedContourActors.resize(dim);
   for(int d=0; d<dim; d++) {
     int size = mSlicer->GetImage()->GetSize()[d];
-    //DD(size);
     mListOfCachedContourActors[d].resize(size);
     for(int j=0; j<size; j++) {
       mListOfCachedContourActors[d][j] = NULL;
@@ -235,8 +212,7 @@ void vvImageContour::initializeCacheMode()
 
 
 //------------------------------------------------------------------------------
-int vvImageContour::computeCurrentOrientation()
-{
+int vvImageContour::ComputeCurrentOrientation() {
   // Get extent of image in the slicer
   int* extent = mSlicer->GetImageActor()->GetDisplayExtent();
 
@@ -254,10 +230,9 @@ int vvImageContour::computeCurrentOrientation()
 
 
 //------------------------------------------------------------------------------
-void vvImageContour::updateWithFastCacheMode()
-{
+void vvImageContour::UpdateWithFastCacheMode() {
   // Compute orientation
-  int orientation = computeCurrentOrientation();
+  int orientation = ComputeCurrentOrientation();
 
   if ((mPreviousSlice == mSlice) && (mPreviousOrientation == orientation)) return;
 
@@ -268,8 +243,8 @@ void vvImageContour::updateWithFastCacheMode()
     vtkImageClip * mClipper;
     vtkMarchingSquares * mSquares;
     vtkActor * mSquaresActor;
-    createNewActor(&mSquaresActor, &mSquares, &mClipper, 0);
-    updateActor(mSquaresActor, mSquares, mClipper, mValue, orientation, mSlice);
+    CreateNewActor(&mSquaresActor, &mSquares, &mClipper, 0);
+    UpdateActor(mSquaresActor, mSquares, mClipper, mValue, orientation, mSlice);
     mListOfCachedContourActors[orientation][mSlice] = mSquaresActor;
     mSquaresActor->VisibilityOn();
   }
@@ -283,11 +258,10 @@ void vvImageContour::updateWithFastCacheMode()
 
 
 //------------------------------------------------------------------------------
-void vvImageContour::createNewActor(vtkActor ** actor,
-                                    vtkMarchingSquares ** squares,
-                                    vtkImageClip ** clipper,
-                                    int numImage)
-{
+void vvImageContour::CreateNewActor(vtkActor ** actor, 
+                                    vtkMarchingSquares ** squares, 
+                                    vtkImageClip ** clipper, 
+                                    int numImage) {
   vtkActor * mSquaresActor = (*actor = vtkActor::New());
   vtkImageClip * mClipper = (*clipper = vtkImageClip::New());
   vtkMarchingSquares * mSquares = (*squares = vtkMarchingSquares::New());
@@ -310,13 +284,11 @@ void vvImageContour::createNewActor(vtkActor ** actor,
 
 
 //------------------------------------------------------------------------------
-void vvImageContour::updateActor(vtkActor * actor,
-                                 vtkMarchingSquares * squares,
-                                 vtkImageClip * clipper,
-                                 double threshold, int orientation, int slice)
-{
-
-  // Set parameter for the MarchigSquare
+void vvImageContour::UpdateActor(vtkActor * actor, 
+                                 vtkMarchingSquares * squares, 
+                                 vtkImageClip * clipper, 
+                                 double threshold, int orientation, int slice) {
+   // Set parameter for the MarchigSquare
   squares->SetValue(0, threshold);
 
   // Get image extent
@@ -328,6 +300,7 @@ void vvImageContour::updateActor(vtkActor * actor,
     extent2 = new int[6];
     int * extent3;
     extent3 = mHiddenImage->GetFirstVTKImageData()->GetExtent();
+
     for(int i=0; i<6; i++) extent2[i] = extent3[i];
 
     double s = (double)extent[orientation*2]*(double)mSlicer->GetImage()->GetSpacing()[orientation]; // in mm
@@ -341,47 +314,58 @@ void vvImageContour::updateActor(vtkActor * actor,
       extent2[orientation*2] = (int)floor(s);
       extent2[orientation*2+1] = extent2[orientation*2];
     }
+
+    // Do not display a contour if there is no contour on this slice
+    if (extent2[orientation*2+1] > extent3[orientation*2+1]) {
+      actor->VisibilityOff();
+      return;
+    }
+    else actor->VisibilityOn();
+
   } else {
     extent2 = extent;
   }
   clipper->SetOutputWholeExtent(extent2[0],extent2[1],extent2[2],
                                 extent2[3],extent2[4],extent2[5]);
 
   if (mHiddenImage) delete extent2;
 
   // Move the actor to be visible
-  // DD(orientation);
-//   DD(slice);
-
-  //TO SIMPLiFY :!!!!!!!!! == ???????
-  // actor->SetPosition(-1,-1,-1);
-
   switch (orientation)  {
   case 0:
+    actor->SetPosition(-1,0,0);
+    /*
     // DD(mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[0]);
     if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[0] > slice) {
-      actor->SetPosition(1,0,0);
+    actor->SetPosition(1,0,0);
     } else {
       actor->SetPosition(-1,0,0);
-    }
+      }*/
     break;
   case 1:
+    actor->SetPosition(0,-1,0);
+    /*
     // DD(mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[1]);
     if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[1] > slice) {
       actor->SetPosition(0,1,0);
     } else {
       actor->SetPosition(0,-1,0);
     }
+    */
     break;
   case 2:
-    // DD(mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2]);
+    actor->SetPosition(0,0,-1);
+    /*
+    DD(mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2]);
     if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2] > slice) {
-      // DD("1");
+      DD("1");
       actor->SetPosition(0,0,1);
     } else {
-      // DD("-1");
+     DD("-1");
       actor->SetPosition(0,0,-1);
     }
+    */
     break;
   }