From 12be037aac07fd0f9cb046e78e983ed95f89d877 Mon Sep 17 00:00:00 2001
From: Romulo Pinho <pinho@lyon.fnclcc.fr>
Date: Thu, 26 May 2011 18:43:29 +0200
Subject: [PATCH] solved bug 457

- but there's another bug
	+ change of orientation does not work
---
 vv/vvImageContour.cxx  | 95 ++++++++++++++++++++++++------------------
 vv/vvImageContour.h    |  2 +-
 vv/vvSlicer.cxx        |  9 +++-
 vv/vvSlicerManager.cxx |  1 +
 vv/vvToolBinarize.cxx  |  1 +
 5 files changed, 65 insertions(+), 43 deletions(-)

diff --git a/vv/vvImageContour.cxx b/vv/vvImageContour.cxx
index 99bc6e4..ab6d820 100644
--- a/vv/vvImageContour.cxx
+++ b/vv/vvImageContour.cxx
@@ -35,6 +35,7 @@ vvImageContour::vvImageContour()
   mHiddenImageIsUsed = false;
   mDisplayModeIsPreserveMemory = true;
   SetPreserveMemoryModeEnabled(true);
+  mPreviousOrientation = -1;
 }
 //------------------------------------------------------------------------------
 
@@ -134,11 +135,15 @@ void vvImageContour::ShowActors() {
 
 //------------------------------------------------------------------------------
 void vvImageContour::Update(double value) {
+  std::cout << "vvImageContour::Update " << value << std::endl;
   if (!mSlicer) return;
   if (mPreviousValue == value) {
     if (mPreviousSlice == mSlicer->GetSlice()) {
       if (mPreviousTSlice == mSlicer->GetTSlice()) {
-        return; // Nothing to do
+        if (mPreviousOrientation == ComputeCurrentOrientation()) {
+          std::cout << "Nothing to do" << std::endl;
+          return; // Nothing to do
+        }
       }
     }
   }
@@ -161,6 +166,7 @@ void vvImageContour::Update(double value) {
   mPreviousTSlice = mSlicer->GetTSlice();
   mPreviousSlice  = mSlicer->GetSlice();
   mPreviousValue  = value;
+  mPreviousOrientation = ComputeCurrentOrientation();
 }
 //------------------------------------------------------------------------------
 
@@ -172,11 +178,12 @@ void vvImageContour::UpdateWithPreserveMemoryMode() {
   mTSlice = mSlicer->GetTSlice();
 
   vtkMarchingSquares * mSquares = mSquaresList[mTSlice];
+  vtkPolyDataMapper* mapper = mSquaresMapperList[mTSlice];
   vtkImageClip * mClipper = mClipperList[mTSlice];
   vtkActor * mSquaresActor = mSquaresActorList[mTSlice];
   int orientation = ComputeCurrentOrientation();
 
-  UpdateActor(mSquaresActor, mSquares, mClipper, mValue, orientation, mSlice);
+  UpdateActor(mSquaresActor, mapper, mSquares, mClipper, mValue, orientation, mSlice);
   //mSquaresActorList[mTSlice]->VisibilityOn();
 
   if (mPreviousTslice != mTSlice) {
@@ -280,9 +287,12 @@ void vvImageContour::CreateNewActor(int numImage) {
 
 //------------------------------------------------------------------------------
 void vvImageContour::UpdateActor(vtkActor * actor, 
+                                 vtkPolyDataMapper * mapper, 
                                  vtkMarchingSquares * squares, 
                                  vtkImageClip * clipper, 
                                  double threshold, int orientation, int slice) {
+  std::cout << "vvImageContour::UpdateActor" << std::endl;
+  
    // Set parameter for the MarchigSquare
   squares->SetValue(0, threshold);
 
@@ -327,44 +337,49 @@ void vvImageContour::UpdateActor(vtkActor * actor,
   if (mHiddenImageIsUsed) delete extent2;
 
   // Move the actor to be visible
-  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);
-    } 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:
-    actor->SetPosition(0,0,-1);
-    /*
-    DD(mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2]);
-    if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2] > slice) {
-      DD("1");
-      actor->SetPosition(0,0,1);
-    } else {
-     DD("-1");
-      actor->SetPosition(0,0,-1);
-    }
-    */
-    break;
-  }
-
-  squares->Update();
+  double position[3] = {0, 0, 0};
+  position[orientation] = -1;
+  actor->SetPosition(position);
+  
+//   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);
+//     } 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:
+//     actor->SetPosition(0,0,-1);
+//     /*
+//     DD(mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2]);
+//     if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2] > slice) {
+//       DD("1");
+//       actor->SetPosition(0,0,1);
+//     } else {
+//      DD("-1");
+//       actor->SetPosition(0,0,-1);
+//     }
+//     */
+//     break;
+//   }
+
+  mapper->Update();
+  actor->VisibilityOn();
 }
 //------------------------------------------------------------------------------
 
diff --git a/vv/vvImageContour.h b/vv/vvImageContour.h
index 1cf2e56..d35ce4b 100644
--- a/vv/vvImageContour.h
+++ b/vv/vvImageContour.h
@@ -71,7 +71,7 @@ protected:
   void UpdateWithPreserveMemoryMode();
   void UpdateWithFastCacheMode();
   void CreateNewActor(int numImage);
-  void UpdateActor(vtkActor * actor, vtkMarchingSquares * squares, vtkImageClip * clipper,
+  void UpdateActor(vtkActor * actor, vtkPolyDataMapper * mapper, vtkMarchingSquares * squares, vtkImageClip * clipper,
                    double threshold, int orientation, int slice);
   void CreateActor(int orientation, int slice);
   int ComputeCurrentOrientation();
diff --git a/vv/vvSlicer.cxx b/vv/vvSlicer.cxx
index 30e8ccb..c9d9be2 100644
--- a/vv/vvSlicer.cxx
+++ b/vv/vvSlicer.cxx
@@ -1045,7 +1045,11 @@ void vvSlicer::FlipHorizontalView()
   vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
   if (cam) {
     double *position = cam->GetPosition();
-    switch (this->SliceOrientation) {
+    double factor[3] = {1, 1, 1};
+    factor[this->SliceOrientation] = -1;
+    cam->SetPosition(factor[0]*position[0],factor[1]*position[1],factor[2]*position[2]);
+    
+/*    switch (this->SliceOrientation) {
     case vtkImageViewer2::SLICE_ORIENTATION_XY:
       cam->SetPosition(position[0],position[1],-position[2]);
       break;
@@ -1057,7 +1061,8 @@ void vvSlicer::FlipHorizontalView()
     case vtkImageViewer2::SLICE_ORIENTATION_YZ:
       cam->SetPosition(-position[0],position[1],position[2]);
       break;
-    }
+    }*/
+
     this->Renderer->ResetCameraClippingRange();
     this->UpdateDisplayExtent();
   }
diff --git a/vv/vvSlicerManager.cxx b/vv/vvSlicerManager.cxx
index c3f5c0c..5941056 100644
--- a/vv/vvSlicerManager.cxx
+++ b/vv/vvSlicerManager.cxx
@@ -916,6 +916,7 @@ void vvSlicerManager::UpdateSlice(int slicer)
 //----------------------------------------------------------------------------
 void vvSlicerManager::UpdateTSlice(int slicer)
 {
+  std::cout << "vvSlicerManager::UpdateTSlice" << std::endl;
   if (mPreviousSlice[slicer] == mSlicers[slicer]->GetSlice()) {
     if (mPreviousTSlice[slicer] == mSlicers[slicer]->GetTSlice()) {
       //      DD("************** NOTHING ***********");
diff --git a/vv/vvToolBinarize.cxx b/vv/vvToolBinarize.cxx
index 5cde323..338e2ea 100644
--- a/vv/vvToolBinarize.cxx
+++ b/vv/vvToolBinarize.cxx
@@ -247,6 +247,7 @@ void vvToolBinarize::InputIsSelected(vvSlicerManager * m)
 //------------------------------------------------------------------------------
 void vvToolBinarize::UpdateSlice(int slicer,int slices)
 {
+  std::cout << "vvToolBinarize::UpdateSlice" << std::endl;
   if (!mInteractiveDisplayIsEnabled) return;
   if (!mCurrentSlicerManager) close();
   mImageContour[slicer]->Update(mThresholdSlider1->GetValue());
-- 
2.49.0