X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=vv%2FvvImageContour.cxx;h=68dc72059a32d5cf02ac3424720149e6ffd9fc7f;hb=a7894a5ffd6848731eba30e4cdf9590cf0c0dce6;hp=f0c11b6c710a4afa6e88dd176f163615b78c2070;hpb=fad7d69a7df544d05deaa19b81bd770aa4c7dd47;p=clitk.git diff --git a/vv/vvImageContour.cxx b/vv/vvImageContour.cxx index f0c11b6..68dc720 100644 --- a/vv/vvImageContour.cxx +++ b/vv/vvImageContour.cxx @@ -3,7 +3,7 @@ Authors belong to: - University of LYON http://www.universite-lyon.fr/ - - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - Léon Bérard cancer center http://www.centreleonberard.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr This software is distributed WITHOUT ANY WARRANTY; without even @@ -14,10 +14,11 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html - ======================================================================-====*/ + ===========================================================================**/ #include "vvImageContour.h" #include "vvImage.h" +#include #include #include #include @@ -26,31 +27,53 @@ #include #include #include +#include //------------------------------------------------------------------------------ vvImageContour::vvImageContour() -{ +{ mTSlice = -1; mSlice = 0; mHiddenImageIsUsed = false; mDisplayModeIsPreserveMemory = true; SetPreserveMemoryModeEnabled(true); + mPreviousOrientation = -1; + mPreviousValue=0; + mDepth = 1.0; + mSlice = 0; } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ vvImageContour::~vvImageContour() -{ - for (unsigned int i = 0; i < mSlicer->GetImage()->GetVTKImages().size(); i++) { - mSlicer->GetRenderer()->RemoveActor(mSquaresActorList[i]); +{ + mSquaresActorList.clear(); +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvImageContour::RemoveActors() +{ + for (unsigned int i = 0; i < mSquaresActorList.size(); i++) { + if (mSlicer != 0) { + if (mSlicer!= NULL) { + if (mSlicer->GetRenderer() != NULL) { + if (mSquaresActorList[i] != NULL) { + mSlicer->GetRenderer()->RemoveActor(mSquaresActorList[i]); + } + } + } + } } } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ -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++) { @@ -61,9 +84,14 @@ void vvImageContour::SetSlicer(vvSlicer * slicer) { //------------------------------------------------------------------------------ -void vvImageContour::SetImage(vvImage * image) { +void vvImageContour::SetImage(vvImage::Pointer image) +{ for (unsigned int numImage = 0; numImage < image->GetVTKImages().size(); numImage++) { +#if VTK_MAJOR_VERSION <= 5 mClipperList[numImage]->SetInput(image->GetVTKImages()[numImage]); +#else + mClipperList[numImage]->SetInputData(image->GetVTKImages()[numImage]); +#endif } mHiddenImageIsUsed = true; mHiddenImage = image; @@ -72,7 +100,8 @@ void vvImageContour::SetImage(vvImage * 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; @@ -92,9 +121,11 @@ void vvImageContour::SetPreserveMemoryModeEnabled(bool b) { //------------------------------------------------------------------------------ -void vvImageContour::SetColor(double r, double g, double b) { +void vvImageContour::SetColor(double r, double g, double b) +{ for(unsigned int i=0; iGetProperty()->SetColor(r,g,b); + mSquaresActorList[i]->GetProperty()->SetOpacity(0.995); //in order to get VTK to turn on the alpha-blending in OpenGL } } //------------------------------------------------------------------------------ @@ -102,7 +133,7 @@ void vvImageContour::SetColor(double r, double g, double b) { //------------------------------------------------------------------------------ void vvImageContour::SetLineWidth(double w) -{ +{ for(unsigned int i=0; iGetProperty()->SetLineWidth(w); } @@ -111,7 +142,8 @@ void vvImageContour::SetLineWidth(double w) //------------------------------------------------------------------------------ -void vvImageContour::HideActors() { +void vvImageContour::HideActors() +{ if (!mSlicer) return; mSlice = mSlicer->GetSlice(); for(unsigned int i=0; iGetSlice(); mTSlice = mSlicer->GetTSlice(); @@ -133,12 +166,29 @@ void vvImageContour::ShowActors() { //------------------------------------------------------------------------------ -void vvImageContour::Update(double value) { +void vvImageContour::SetDepth(double d) +{ + mDepth = d; + // Move the actor to be visible + double position[3] = {0, 0, 0}; + int orientation = ComputeCurrentOrientation(); + position[orientation] = -mDepth; + + for(unsigned int i=0; iSetPosition(position); +} +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +void vvImageContour::Update(double value) +{ if (!mSlicer) return; if (mPreviousValue == value) { if (mPreviousSlice == mSlicer->GetSlice()) { if (mPreviousTSlice == mSlicer->GetTSlice()) { - return; // Nothing to do + if (mPreviousOrientation == ComputeCurrentOrientation()) { + return; // Nothing to do + } } } } @@ -156,38 +206,43 @@ void vvImageContour::Update(double value) { UpdateWithFastCacheMode(); } - // mSlicer->Render(); //DS ---> REMOVE ?? + //mSlicer->Render(); //DS ---> REMOVE ?? mPreviousTSlice = mSlicer->GetTSlice(); mPreviousSlice = mSlicer->GetSlice(); mPreviousValue = value; + mPreviousOrientation = ComputeCurrentOrientation(); } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ -void vvImageContour::UpdateWithPreserveMemoryMode() { +void vvImageContour::UpdateWithPreserveMemoryMode() +{ // Only change actor visibility if tslice change - int mPreviousTslice = mTSlice; + mPreviousTslice = mTSlice; 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); - //mSquaresActorList[mTSlice]->VisibilityOn(); + UpdateActor(mSquaresActor, mapper, mSquares, mClipper, mValue, orientation, mSlice); if (mPreviousTslice != mTSlice) { if (mPreviousTslice != -1) mSquaresActorList[mPreviousTslice]->VisibilityOff(); } + + //mSlicer->Render(); } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ -void vvImageContour::InitializeCacheMode() { +void vvImageContour::InitializeCacheMode() +{ clitkExceptionMacro("TODO : not implemented yet"); mPreviousSlice = mPreviousOrientation = 0; int dim = mSlicer->GetImage()->GetNumberOfDimensions(); @@ -205,7 +260,8 @@ clitkExceptionMacro("TODO : not implemented yet"); //------------------------------------------------------------------------------ -int vvImageContour::ComputeCurrentOrientation() { +int vvImageContour::ComputeCurrentOrientation() +{ // Get extent of image in the slicer int* extent = mSlicer->GetImageActor()->GetDisplayExtent(); @@ -223,7 +279,8 @@ int vvImageContour::ComputeCurrentOrientation() { //------------------------------------------------------------------------------ -void vvImageContour::UpdateWithFastCacheMode() { +void vvImageContour::UpdateWithFastCacheMode() +{ clitkExceptionMacro("TODO : not implemented yet"); // Compute orientation @@ -251,21 +308,37 @@ clitkExceptionMacro("TODO : not implemented yet"); //------------------------------------------------------------------------------ -void vvImageContour::CreateNewActor(int numImage) { +void vvImageContour::CreateNewActor(int numImage) +{ vtkSmartPointer squaresActor = vtkSmartPointer::New(); vtkSmartPointer clipper = vtkSmartPointer::New(); vtkSmartPointer squares = vtkSmartPointer::New(); vtkSmartPointer squaresMapper = vtkSmartPointer::New(); - if (mHiddenImageIsUsed) + if (mHiddenImageIsUsed) { +#if VTK_MAJOR_VERSION <= 5 clipper->SetInput(mHiddenImage->GetVTKImages()[0]); - else +#else + clipper->SetInputData(mHiddenImage->GetVTKImages()[0]); +#endif + } else { +#if VTK_MAJOR_VERSION <= 5 clipper->SetInput(mSlicer->GetImage()->GetVTKImages()[numImage]); +#else + clipper->SetInputData(mSlicer->GetImage()->GetVTKImages()[numImage]); +#endif + } +#if VTK_MAJOR_VERSION <= 5 squares->SetInput(clipper->GetOutput()); squaresMapper->SetInput(squares->GetOutput()); +#else + squares->SetInputConnection(clipper->GetOutputPort(0)); + squaresMapper->SetInputConnection(squares->GetOutputPort(0)); +#endif 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); @@ -280,12 +353,14 @@ void vvImageContour::CreateNewActor(int numImage) { //------------------------------------------------------------------------------ void vvImageContour::UpdateActor(vtkActor * actor, + vtkPolyDataMapper * mapper, vtkMarchingSquares * squares, vtkImageClip * clipper, - double threshold, int orientation, int slice) { - // Set parameter for the MarchigSquare + double threshold, int orientation, int slice) +{ + // Set parameter for the MarchigSquare squares->SetValue(0, threshold); - + squares->Update(); // Get image extent int* extent = mSlicer->GetImageActor()->GetDisplayExtent(); @@ -303,15 +378,16 @@ void vvImageContour::UpdateActor(vtkActor * actor, s = s-mHiddenImage->GetFirstVTKImageData()->GetOrigin()[orientation]; // from corner second image s = s/mHiddenImage->GetFirstVTKImageData()->GetSpacing()[orientation]; // in voxel - if (s == floor(s)) { - extent2[orientation*2] = extent2[orientation*2+1] = (int)floor(s); - } else { - extent2[orientation*2] = (int)floor(s); - extent2[orientation*2+1] = extent2[orientation*2]; - } + // Rint to the closest slice + extent2[orientation*2+1] = extent2[orientation*2] = (int)lrint(s); // Do not display a contour if there is no contour on this slice - if (extent2[orientation*2+1] > extent3[orientation*2+1]) { + // DD(extent2[orientation*2+1]); + // DD(extent3[orientation*2+1]); + // DD(extent2[orientation*2]); + // DD(extent3[orientation*2]); + if ((extent2[orientation*2+1] > extent3[orientation*2+1]) || + (extent2[orientation*2] < extent3[orientation*2])) { actor->VisibilityOff(); return; } @@ -319,52 +395,21 @@ void vvImageContour::UpdateActor(vtkActor * actor, } else { extent2 = extent; + actor->VisibilityOn(); } - + clipper->SetOutputWholeExtent(extent2[0],extent2[1],extent2[2], extent2[3],extent2[4],extent2[5]); - + 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(); + SetDepth(mDepth); + // double position[3] = {0, 0, 0}; + // DD(mDepth); + // position[orientation] = -mDepth; + // actor->SetPosition(position); + mapper->Update(); } //------------------------------------------------------------------------------