]> Creatis software - clitk.git/blobdiff - vv/vvImageContour.cxx
Debug RTStruct conversion with empty struc
[clitk.git] / vv / vvImageContour.cxx
index e4ecfdf364f5db6354f3fc86c250707f03699d17..68dc72059a32d5cf02ac3424720149e6ffd9fc7f 100644 (file)
 #include <vtkImageData.h>
 #include <vtkPolyDataMapper.h>
 #include <vtkProperty.h>
+#include <vtkInformation.h>
 
 //------------------------------------------------------------------------------
 vvImageContour::vvImageContour()
-{ //out << __func__ << endl;
+{ 
   mTSlice = -1;
   mSlice = 0;
   mHiddenImageIsUsed = false;
   mDisplayModeIsPreserveMemory = true;
   SetPreserveMemoryModeEnabled(true);
   mPreviousOrientation = -1;
+  mPreviousValue=0;
   mDepth = 1.0;
   mSlice = 0;
 }
@@ -45,7 +47,7 @@ vvImageContour::vvImageContour()
 
 //------------------------------------------------------------------------------
 vvImageContour::~vvImageContour()
-{ //out << __func__ << endl;
+{ 
   mSquaresActorList.clear();
 }
 //------------------------------------------------------------------------------
@@ -53,7 +55,7 @@ vvImageContour::~vvImageContour()
 
 //------------------------------------------------------------------------------
 void vvImageContour::RemoveActors()
-{ //out << __func__ << endl;
+{ 
   for (unsigned int i = 0; i < mSquaresActorList.size(); i++) {
     if (mSlicer != 0) {
       if (mSlicer!= NULL) {
@@ -71,7 +73,7 @@ void vvImageContour::RemoveActors()
 
 //------------------------------------------------------------------------------
 void vvImageContour::SetSlicer(vvSlicer * slicer) 
-{ //out << __func__ << endl;
+{ 
   mSlicer = slicer;  
   // Create an actor for each time slice
   for (unsigned int numImage = 0; numImage < mSlicer->GetImage()->GetVTKImages().size(); numImage++) {
@@ -83,7 +85,7 @@ void vvImageContour::SetSlicer(vvSlicer * slicer)
 
 //------------------------------------------------------------------------------
 void vvImageContour::SetImage(vvImage::Pointer image) 
-{ //out << __func__ << endl;
+{ 
   for (unsigned int numImage = 0; numImage < image->GetVTKImages().size(); numImage++) {
 #if VTK_MAJOR_VERSION <= 5
     mClipperList[numImage]->SetInput(image->GetVTKImages()[numImage]);
@@ -99,7 +101,7 @@ void vvImageContour::SetImage(vvImage::Pointer image)
 
 //------------------------------------------------------------------------------
 void vvImageContour::SetPreserveMemoryModeEnabled(bool b) 
-{ //out << __func__ << endl;
+{ 
   // FastCache mode work only if threshold is always the same
   if (mDisplayModeIsPreserveMemory == b) return;
   mDisplayModeIsPreserveMemory = b;
@@ -120,9 +122,10 @@ void vvImageContour::SetPreserveMemoryModeEnabled(bool b)
 
 //------------------------------------------------------------------------------
 void vvImageContour::SetColor(double r, double g, double b) 
-{ //out << __func__ << endl;
+{ 
   for(unsigned int i=0; i<mSquaresActorList.size(); i++) {
     mSquaresActorList[i]->GetProperty()->SetColor(r,g,b);
+    mSquaresActorList[i]->GetProperty()->SetOpacity(0.995); //in order to get VTK to turn on the alpha-blending in OpenGL
   }
 }
 //------------------------------------------------------------------------------
@@ -130,7 +133,7 @@ void vvImageContour::SetColor(double r, double g, double b)
 
 //------------------------------------------------------------------------------
 void vvImageContour::SetLineWidth(double w)
-{ //out << __func__ << endl;
+{ 
   for(unsigned int i=0; i<mSquaresActorList.size(); i++) {
     mSquaresActorList[i]->GetProperty()->SetLineWidth(w);
   }
@@ -140,7 +143,7 @@ void vvImageContour::SetLineWidth(double w)
 
 //------------------------------------------------------------------------------
 void vvImageContour::HideActors() 
-{ //out << __func__ << endl;
+{ 
   if (!mSlicer) return;
   mSlice = mSlicer->GetSlice();
   for(unsigned int i=0; i<mSquaresActorList.size(); i++) {
@@ -152,7 +155,7 @@ void vvImageContour::HideActors()
 
 //------------------------------------------------------------------------------
 void vvImageContour::ShowActors() 
-{ //out << __func__ << endl;
+{ 
   if (!mSlicer) return;
   mSlice = mSlicer->GetSlice();
   mTSlice = mSlicer->GetTSlice();
@@ -164,7 +167,7 @@ void vvImageContour::ShowActors()
 
 //------------------------------------------------------------------------------
 void vvImageContour::SetDepth(double d) 
-{ //out << __func__ << endl;
+{ 
   mDepth = d;
   // Move the actor to be visible
   double position[3] = {0, 0, 0};
@@ -178,7 +181,7 @@ void vvImageContour::SetDepth(double d)
 
 //------------------------------------------------------------------------------
 void vvImageContour::Update(double value) 
-{ //out << __func__ << endl;
+{ 
   if (!mSlicer) return;
   if (mPreviousValue == value) {
     if (mPreviousSlice == mSlicer->GetSlice()) {
@@ -215,7 +218,7 @@ void vvImageContour::Update(double value)
 
 //------------------------------------------------------------------------------
 void vvImageContour::UpdateWithPreserveMemoryMode() 
-{ //out << __func__ << endl;
+{ 
   // Only change actor visibility if tslice change
   mPreviousTslice = mTSlice;
   mTSlice = mSlicer->GetTSlice();
@@ -226,20 +229,20 @@ void vvImageContour::UpdateWithPreserveMemoryMode()
   vtkActor * mSquaresActor = mSquaresActorList[mTSlice];
   int orientation = ComputeCurrentOrientation();
 
-  //UpdateActor(mSquaresActor, mapper, mSquares, mClipper, mValue, orientation, mSlice);
+  UpdateActor(mSquaresActor, mapper, mSquares, mClipper, mValue, orientation, mSlice);
 
   if (mPreviousTslice != mTSlice) {
     if (mPreviousTslice != -1) mSquaresActorList[mPreviousTslice]->VisibilityOff();
   }
-  
-  mSlicer->Render();
+
+  //mSlicer->Render();
 }
 //------------------------------------------------------------------------------
 
 
 //------------------------------------------------------------------------------
 void vvImageContour::InitializeCacheMode() 
-{ //out << __func__ << endl;
+{ 
 clitkExceptionMacro("TODO : not implemented yet");
   mPreviousSlice = mPreviousOrientation = 0;
   int dim = mSlicer->GetImage()->GetNumberOfDimensions();
@@ -258,7 +261,7 @@ clitkExceptionMacro("TODO : not implemented yet");
 
 //------------------------------------------------------------------------------
 int vvImageContour::ComputeCurrentOrientation() 
-{ //out << __func__ << endl;
+{ 
   // Get extent of image in the slicer
   int* extent = mSlicer->GetImageActor()->GetDisplayExtent();
 
@@ -277,7 +280,7 @@ int vvImageContour::ComputeCurrentOrientation()
 
 //------------------------------------------------------------------------------
 void vvImageContour::UpdateWithFastCacheMode() 
-{ //out << __func__ << endl;
+{ 
 clitkExceptionMacro("TODO : not implemented yet");
 
   // Compute orientation
@@ -306,7 +309,7 @@ clitkExceptionMacro("TODO : not implemented yet");
 
 //------------------------------------------------------------------------------
 void vvImageContour::CreateNewActor(int numImage) 
-{ //out << __func__ << endl;
+{ 
   vtkSmartPointer<vtkActor> squaresActor = vtkSmartPointer<vtkActor>::New();
   vtkSmartPointer<vtkImageClip> clipper = vtkSmartPointer<vtkImageClip>::New();
   vtkSmartPointer<vtkMarchingSquares> squares = vtkSmartPointer<vtkMarchingSquares>::New();
@@ -325,19 +328,17 @@ void vvImageContour::CreateNewActor(int numImage)
     clipper->SetInputData(mSlicer->GetImage()->GetVTKImages()[numImage]);
 #endif
   }
-clipper->Update();
 #if VTK_MAJOR_VERSION <= 5
   squares->SetInput(clipper->GetOutput());
   squaresMapper->SetInput(squares->GetOutput());
 #else
-  squares->SetInputData(clipper->GetOutput());
-  squaresMapper->SetInputData(squares->GetOutput());
+  squares->SetInputConnection(clipper->GetOutputPort(0));
+  squaresMapper->SetInputConnection(squares->GetOutputPort(0));
 #endif
-squares->Update();
-squaresMapper->Update();
   squaresMapper->ScalarVisibilityOff();
   squaresActor->SetMapper(squaresMapper);
   squaresActor->GetProperty()->SetColor(1.0,0,0);
+  squaresActor->GetProperty()->SetOpacity(0.995); //in order to get VTK to turn on the alpha-blending in OpenGL
   squaresActor->SetPickable(0);
   squaresActor->VisibilityOff();
   mSlicer->GetRenderer()->AddActor(squaresActor);
@@ -356,10 +357,10 @@ void vvImageContour::UpdateActor(vtkActor * actor,
                                  vtkMarchingSquares * squares, 
                                  vtkImageClip * clipper, 
                                  double threshold, int orientation, int slice) 
-{ //out << __func__ << endl;
+{ 
   // Set parameter for the MarchigSquare
   squares->SetValue(0, threshold);
-  
+  squares->Update();
   // Get image extent
   int* extent = mSlicer->GetImageActor()->GetDisplayExtent();
 
@@ -399,9 +400,7 @@ void vvImageContour::UpdateActor(vtkActor * actor,
   
   clipper->SetOutputWholeExtent(extent2[0],extent2[1],extent2[2],
                                 extent2[3],extent2[4],extent2[5]);
-                                clipper->Update();
-                                clipper->Print(cout);
-
+                                
   if (mHiddenImageIsUsed) delete extent2;
 
   // Move the actor to be visible
@@ -410,7 +409,6 @@ void vvImageContour::UpdateActor(vtkActor * actor,
   // DD(mDepth);
   // position[orientation] = -mDepth;
   // actor->SetPosition(position);
-  
   mapper->Update();
 }
 //------------------------------------------------------------------------------