]> Creatis software - clitk.git/blobdiff - vv/vvImageContour.cxx
added functionalities such as Reset a Transform, Save and view transformations etc.
[clitk.git] / vv / vvImageContour.cxx
index 0ffff620e4496e69fab31e66e9e396e17dc0a7ec..0e4e428110c4a2958e2441fee248149406ca5fb7 100644 (file)
@@ -1,7 +1,7 @@
 /*=========================================================================
   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
 
-  Authors belong to: 
+  Authors belong to:
   - University of LYON              http://www.universite-lyon.fr/
   - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
@@ -28,7 +28,8 @@
 #include <vtkProperty.h>
 
 //------------------------------------------------------------------------------
-vvImageContour::vvImageContour() {
+vvImageContour::vvImageContour()
+{
   mTSlice = -1;
   mSlice = 0;
   mHiddenImageIsUsed = false;
@@ -38,7 +39,8 @@ vvImageContour::vvImageContour() {
 
 
 //------------------------------------------------------------------------------
-vvImageContour::~vvImageContour() {
+vvImageContour::~vvImageContour()
+{
   for (unsigned int i = 0; i < mSlicer->GetImage()->GetVTKImages().size(); i++) {
     mSlicer->GetRenderer()->RemoveActor(mSquaresActorList[i]);
   }
@@ -50,14 +52,14 @@ vvImageContour::~vvImageContour() {
 
 
 //------------------------------------------------------------------------------
-void vvImageContour::setSlicer(vvSlicer * 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);
@@ -67,7 +69,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]);
   }
@@ -78,26 +80,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();
+    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);
   }
@@ -106,7 +108,8 @@ void vvImageContour::setColor(double r, double g, double b) {
 
 
 //------------------------------------------------------------------------------
-void vvImageContour::SetLineWidth(double w) {
+void vvImageContour::SetLineWidth(double w)
+{
   for(unsigned int i=0; i<mSquaresActorList.size(); i++) {
     mSquaresActorList[i]->GetProperty()->SetLineWidth(w);
   }
@@ -115,7 +118,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++) {
@@ -124,28 +127,28 @@ 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) {
+void vvImageContour::Update(double value) {
   //  DD(value);
   if (!mSlicer) return;
   if (mPreviousValue == value) {
     if (mPreviousSlice == mSlicer->GetSlice()) {
       if (mPreviousTSlice == mSlicer->GetTSlice()) {
-       // DD("vvImageContour::update nothing");
+        // DD("vvImageContour::update nothing");
         return; // Nothing to do
       }
     }
@@ -158,10 +161,10 @@ void vvImageContour::update(double value) {
   mSlice = mSlicer->GetSlice();
   //  DD(mDisplayModeIsPreserveMemory);
   if (mDisplayModeIsPreserveMemory) {
-    updateWithPreserveMemoryMode();
+    UpdateWithPreserveMemoryMode();
   }
   else {
-    updateWithFastCacheMode();
+    UpdateWithFastCacheMode();
   }
 
 
@@ -176,7 +179,7 @@ void vvImageContour::update(double value) {
 
 
 //------------------------------------------------------------------------------
-void vvImageContour::updateWithPreserveMemoryMode() {
+void vvImageContour::UpdateWithPreserveMemoryMode() {
   // Only change actor visibility if tslice change
   //DD(mTSlice);
   //DD(mSlice);
@@ -192,12 +195,12 @@ void vvImageContour::updateWithPreserveMemoryMode() {
   vtkMarchingSquares * mSquares = mSquaresList[mTSlice];
   vtkImageClip * mClipper = mClipperList[mTSlice];
   vtkActor * mSquaresActor = mSquaresActorList[mTSlice];
-  int orientation = computeCurrentOrientation();
+  int orientation = ComputeCurrentOrientation();
   //  DD(orientation);
   //DD(mValue);
   //DD(mSlice);
   //DD(mPreviousTslice);
-  updateActor(mSquaresActor, mSquares, mClipper, mValue, orientation, mSlice);
+  UpdateActor(mSquaresActor, mSquares, mClipper, mValue, orientation, mSlice);
   mSquaresActorList[mTSlice]->VisibilityOn();
   if (mPreviousTslice != mTSlice) {
     if (mPreviousTslice != -1) mSquaresActorList[mPreviousTslice]->VisibilityOff();
@@ -207,7 +210,7 @@ void vvImageContour::updateWithPreserveMemoryMode() {
 
 
 //------------------------------------------------------------------------------
-void vvImageContour::initializeCacheMode() {
+void vvImageContour::InitializeCacheMode() {
   mPreviousSlice = mPreviousOrientation = 0;
   int dim = mSlicer->GetImage()->GetNumberOfDimensions();
 
@@ -225,13 +228,13 @@ void vvImageContour::initializeCacheMode() {
 
 
 //------------------------------------------------------------------------------
-int vvImageContour::computeCurrentOrientation() {
+int vvImageContour::ComputeCurrentOrientation() {
   // Get extent of image in the slicer
   int* extent = mSlicer->GetImageActor()->GetDisplayExtent();
-  
+
   // Compute orientation
   int orientation;
-  for (orientation = 0; orientation < 6;orientation = orientation+2) {
+  for (orientation = 0; orientation < 6; orientation = orientation+2) {
     if (extent[orientation] == extent[orientation+1]) {
       break;
     }
@@ -243,22 +246,21 @@ int vvImageContour::computeCurrentOrientation() {
 
 
 //------------------------------------------------------------------------------
-void vvImageContour::updateWithFastCacheMode() {
+void vvImageContour::UpdateWithFastCacheMode() {
   // Compute orientation
-  int orientation = computeCurrentOrientation();
+  int orientation = ComputeCurrentOrientation();
 
   if ((mPreviousSlice == mSlice) && (mPreviousOrientation == orientation)) return;
 
   vtkActor * actor = mListOfCachedContourActors[orientation][mSlice];
   if (actor != NULL) {
     mListOfCachedContourActors[orientation][mSlice]->VisibilityOn();
-  }
-  else {
+  } else {
     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();
   }
@@ -272,18 +274,18 @@ void vvImageContour::updateWithFastCacheMode() {
 
 
 //------------------------------------------------------------------------------
-void vvImageContour::createNewActor(vtkActor ** actor, 
-                                   vtkMarchingSquares ** squares, 
-                                   vtkImageClip ** clipper, 
+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());
   vtkPolyDataMapper * mSquaresMapper = vtkPolyDataMapper::New();
-  
-  if (mHiddenImageIsUsed) 
+
+  if (mHiddenImageIsUsed)
     mClipper->SetInput(mHiddenImage->GetVTKImages()[0]);
-  else 
+  else
     mClipper->SetInput(mSlicer->GetImage()->GetVTKImages()[numImage]);
   mSquares->SetInput(mClipper->GetOutput());
   mSquaresMapper->SetInput(mSquares->GetOutput());
@@ -292,17 +294,16 @@ void vvImageContour::createNewActor(vtkActor ** actor,
   mSquaresActor->GetProperty()->SetColor(1.0,0,0);
   mSquaresActor->SetPickable(0);
   mSquaresActor->VisibilityOff();
-  mSlicer->GetRenderer()->AddActor(mSquaresActor);  
+  mSlicer->GetRenderer()->AddActor(mSquaresActor);
 }
 //------------------------------------------------------------------------------
 
 
 //------------------------------------------------------------------------------
-void vvImageContour::updateActor(vtkActor * actor, 
-                                vtkMarchingSquares * squares, 
-                                vtkImageClip * clipper, 
-                                double threshold, int orientation, int slice) {
-  
+void vvImageContour::UpdateActor(vtkActor * actor, 
+                                 vtkMarchingSquares * squares, 
+                                 vtkImageClip * clipper, 
+                                 double threshold, int orientation, int slice) {
   // Set parameter for the MarchigSquare
   squares->SetValue(0, threshold);
 
@@ -316,21 +317,19 @@ void vvImageContour::updateActor(vtkActor * actor,
     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
     s = s+mSlicer->GetImage()->GetOrigin()[orientation]; // from origin
     s = s-mHiddenImage->GetFirstVTKImageData()->GetOrigin()[orientation]; // from corner second image
     s = s/mHiddenImage->GetFirstVTKImageData()->GetSpacing()[orientation]; // in voxel
-    
-    if (s == floor(s)) { 
+
+    if (s == floor(s)) {
       extent2[orientation*2] = extent2[orientation*2+1] = (int)floor(s);
-    }
-    else {
+    } else {
       extent2[orientation*2] = (int)floor(s);
       extent2[orientation*2+1] = extent2[orientation*2];
     }
-  }
-  else {
+  } else {
     extent2 = extent;
   }
   clipper->SetOutputWholeExtent(extent2[0],extent2[1],extent2[2],
@@ -340,37 +339,34 @@ void vvImageContour::updateActor(vtkActor * actor,
 
   // Move the actor to be visible
   // DD(orientation);
-//   DD(slice);
+  //   DD(slice);
 
   //TO SIMPLiFY :!!!!!!!!! == ???????
   // actor->SetPosition(-1,-1,-1);
+
   switch (orientation)  {
-  case 0: 
+  case 0:
     // DD(mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[0]);
     if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[0] > slice) {
       actor->SetPosition(1,0,0);
-    }
-    else {
+    } else {
       actor->SetPosition(-1,0,0);
     }
     break;
-  case 1: 
+  case 1:
     // DD(mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[1]);
     if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[1] > slice) {
       actor->SetPosition(0,1,0);
-    }
-    else {
+    } else {
       actor->SetPosition(0,-1,0);
     }
     break;
-  case 2: 
+  case 2:
     // DD(mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2]);
     if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2] > slice) {
       // DD("1");
       actor->SetPosition(0,0,1);
-    }
-    else {
+    } else {
       // DD("-1");
       actor->SetPosition(0,0,-1);
     }