X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=vv%2FvvImageContour.cxx;h=8fb22ae4d000428bd0fb50317b2843fa22372c80;hb=3a823a03d4a2217e41e4dd3b05a8ea825bb762a5;hp=94129031759648c7808a40f6216b12b95ef74d1d;hpb=842bd9736b8c4a9e249dd4f026794d473ba095f7;p=clitk.git diff --git a/vv/vvImageContour.cxx b/vv/vvImageContour.cxx index 9412903..8fb22ae 100644 --- a/vv/vvImageContour.cxx +++ b/vv/vvImageContour.cxx @@ -18,6 +18,7 @@ #include "vvImageContour.h" #include "vvImage.h" +#include #include #include #include @@ -36,6 +37,8 @@ vvImageContour::vvImageContour() mDisplayModeIsPreserveMemory = true; SetPreserveMemoryModeEnabled(true); mPreviousOrientation = -1; + mDepth = 1.0; + mSlice = 0; } //------------------------------------------------------------------------------ @@ -43,8 +46,24 @@ vvImageContour::vvImageContour() //------------------------------------------------------------------------------ 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]); + } + } + } + } } } //------------------------------------------------------------------------------ @@ -62,9 +81,13 @@ 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; @@ -133,6 +156,20 @@ void vvImageContour::ShowActors() { //------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +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; @@ -263,13 +300,27 @@ void vvImageContour::CreateNewActor(int numImage) { 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->SetInputData(clipper->GetOutput()); + squaresMapper->SetInputData(squares->GetOutput()); +#endif squaresMapper->ScalarVisibilityOff(); squaresActor->SetMapper(squaresMapper); squaresActor->GetProperty()->SetColor(1.0,0,0); @@ -291,8 +342,7 @@ void vvImageContour::UpdateActor(vtkActor * actor, vtkMarchingSquares * squares, vtkImageClip * clipper, double threshold, int orientation, int slice) { - - // Set parameter for the MarchigSquare + // Set parameter for the MarchigSquare squares->SetValue(0, threshold); // Get image extent @@ -312,15 +362,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; } @@ -337,9 +388,11 @@ void vvImageContour::UpdateActor(vtkActor * actor, if (mHiddenImageIsUsed) delete extent2; // Move the actor to be visible - double position[3] = {0, 0, 0}; - position[orientation] = -1; - actor->SetPosition(position); + SetDepth(mDepth); + // double position[3] = {0, 0, 0}; + // DD(mDepth); + // position[orientation] = -mDepth; + // actor->SetPosition(position); mapper->Update(); }