From c2aaedddfc2ad8a9cefcbfcb6b67556198121984 Mon Sep 17 00:00:00 2001 From: David Sarrut Date: Fri, 18 Nov 2011 16:52:48 +0100 Subject: [PATCH] Add Depth option for contours and overlays --- vv/vvBinaryImageOverlayActor.cxx | 59 +++++++++++++++----------------- vv/vvBinaryImageOverlayActor.h | 4 ++- vv/vvImageContour.cxx | 21 ++++++------ vv/vvImageContour.h | 2 ++ vv/vvMeshActor.cxx | 2 ++ vv/vvROIActor.cxx | 31 +++++++++++++---- vv/vvROIActor.h | 9 +++-- 7 files changed, 75 insertions(+), 53 deletions(-) diff --git a/vv/vvBinaryImageOverlayActor.cxx b/vv/vvBinaryImageOverlayActor.cxx index d4b9617..612d9c0 100644 --- a/vv/vvBinaryImageOverlayActor.cxx +++ b/vv/vvBinaryImageOverlayActor.cxx @@ -42,6 +42,7 @@ vvBinaryImageOverlayActor::vvBinaryImageOverlayActor() mForegroundValue = 1; mBackgroundValue = 0; m_modeBG = true; + mDepth = 1.0; } //------------------------------------------------------------------------------ @@ -233,14 +234,15 @@ void vvBinaryImageOverlayActor::UpdateColor() //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ -void vvBinaryImageOverlayActor::UpdateSlice(int slicer, int slice) +void vvBinaryImageOverlayActor::UpdateSlice(int slicer, int slice, bool force) { if (!mSlicer) return; - if (mPreviousSlice == mSlicer->GetSlice()) { - if (mPreviousTSlice == mSlicer->GetTSlice()) { - //DD("=========== NOTHING"); - return; // Nothing to do + if (!force) { + if (mPreviousSlice == mSlicer->GetSlice()) { + if (mPreviousTSlice == mSlicer->GetTSlice()) { + return; // Nothing to do + } } } @@ -253,14 +255,9 @@ void vvBinaryImageOverlayActor::UpdateSlice(int slicer, int slice) int orientation = mSlicer->GetOrientation(); int maskExtent[6]; ComputeExtent(orientation, mSlice, imageExtent, maskExtent); - //ComputeExtent(imageExtent, maskExtent, mSlicer->GetImage()->GetFirstVTKImageData(), mImage->GetFirstVTKImageData()); ComputeExtent(maskExtent, maskExtent, mSlicer->GetImage()->GetFirstVTKImageData(), mImage->GetFirstVTKImageData()); - // std::cout << "maskExtent = " << maskExtent[0] << " " << maskExtent[1] << " " << maskExtent[2] << " " - // << maskExtent[3] << " " << maskExtent[4] << " " << maskExtent[5] << std::endl; mSlicer->ClipDisplayedExtent(maskExtent, mMapperList[mTSlice]->GetInput()->GetWholeExtent()); - // std::cout << "maskExtent = " << maskExtent[0] << " " << maskExtent[1] << " " << maskExtent[2] << " " - // << maskExtent[3] << " " << maskExtent[4] << " " << maskExtent[5] << std::endl; - SetDisplayExtentAndCameraPosition(orientation, mSlice, maskExtent, mImageActorList[mTSlice], 0.0); + SetDisplayExtentAndCameraPosition(orientation, mSlice, maskExtent, mImageActorList[mTSlice], mDepth); // set previous slice mPreviousTSlice = mSlicer->GetTSlice(); @@ -297,18 +294,12 @@ void vvBinaryImageOverlayActor::ComputeExtent(int orientation, //---------------------------------------------------------------------------- void vvBinaryImageOverlayActor::ComputeExtent(int * inExtent, int * outExtent, vtkImageData * image, vtkImageData * overlay) { - outExtent[0] = (( image->GetOrigin()[0] + inExtent[0]*image->GetSpacing()[0] ) - overlay->GetOrigin()[0]) / - overlay->GetSpacing()[0]; - outExtent[1] = (( image->GetOrigin()[0] + inExtent[1]*image->GetSpacing()[0] ) - overlay->GetOrigin()[0]) / - overlay->GetSpacing()[0]; - outExtent[2] = (( image->GetOrigin()[1] + inExtent[2]*image->GetSpacing()[1] ) - overlay->GetOrigin()[1]) / - overlay->GetSpacing()[1]; - outExtent[3] = (( image->GetOrigin()[1] + inExtent[3]*image->GetSpacing()[1] ) - overlay->GetOrigin()[1]) / - overlay->GetSpacing()[1]; - outExtent[4] = (( image->GetOrigin()[2] + inExtent[4]*image->GetSpacing()[2] ) - overlay->GetOrigin()[2]) / - overlay->GetSpacing()[2]; - outExtent[5] = (( image->GetOrigin()[2] + inExtent[5]*image->GetSpacing()[2] ) - overlay->GetOrigin()[2]) / - overlay->GetSpacing()[2]; + outExtent[0] = (int)lrint(((image->GetOrigin()[0] + inExtent[0]*image->GetSpacing()[0]) - overlay->GetOrigin()[0]) / overlay->GetSpacing()[0]); + outExtent[1] = (int)lrint(((image->GetOrigin()[0] + inExtent[1]*image->GetSpacing()[0]) - overlay->GetOrigin()[0]) / overlay->GetSpacing()[0]); + outExtent[2] = (int)lrint(((image->GetOrigin()[1] + inExtent[2]*image->GetSpacing()[1]) - overlay->GetOrigin()[1]) / overlay->GetSpacing()[1]); + outExtent[3] = (int)lrint(((image->GetOrigin()[1] + inExtent[3]*image->GetSpacing()[1]) - overlay->GetOrigin()[1]) / overlay->GetSpacing()[1]); + outExtent[4] = (int)lrint(((image->GetOrigin()[2] + inExtent[4]*image->GetSpacing()[2]) - overlay->GetOrigin()[2]) / overlay->GetSpacing()[2]); + outExtent[5] = (int)lrint(((image->GetOrigin()[2] + inExtent[5]*image->GetSpacing()[2]) - overlay->GetOrigin()[2]) / overlay->GetSpacing()[2]); } //---------------------------------------------------------------------------- @@ -320,23 +311,27 @@ void vvBinaryImageOverlayActor::SetDisplayExtentAndCameraPosition(int orientatio vtkImageActor * actor, double position) { + /* FIXME + Error according to camera orientation + */ + // Set position if (orientation == vtkImageViewer2::SLICE_ORIENTATION_XY) { - if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2] > slice) - actor->SetPosition(0,0, position); - else + //if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2] > slice) actor->SetPosition(0,0, -position); + //else + //actor->SetPosition(0,0, position); } if (orientation == vtkImageViewer2::SLICE_ORIENTATION_XZ) { - if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[1] > slice) - actor->SetPosition(0,position,0); - else + //if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[1] > slice) + // actor->SetPosition(0,position,0); + //else actor->SetPosition(0,-position,0); } if (orientation == vtkImageViewer2::SLICE_ORIENTATION_YZ) { - if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[0] > slice) - actor->SetPosition(position,0, 0); - else + //if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[0] > slice) + // actor->SetPosition(position,0, 0); + //else actor->SetPosition(-position,0, 0); } actor->SetDisplayExtent(extent); diff --git a/vv/vvBinaryImageOverlayActor.h b/vv/vvBinaryImageOverlayActor.h index dfa3109..0b02c62 100644 --- a/vv/vvBinaryImageOverlayActor.h +++ b/vv/vvBinaryImageOverlayActor.h @@ -41,9 +41,10 @@ class vvBinaryImageOverlayActor : public itk::LightObject void SetColor(double r, double g, double b); void SetOpacity(double d); void SetImage(vvImage * image, double bg, bool modeBG=true); + void SetDepth(double d) { mDepth = d; } void Initialize(bool IsVisible=true); void UpdateColor(); - void UpdateSlice(int slicer, int slice); + void UpdateSlice(int slicer, int slice, bool force=false); void HideActors(); void ShowActors(); @@ -60,6 +61,7 @@ class vvBinaryImageOverlayActor : public itk::LightObject double mForegroundValue; bool m_modeBG; vtkSmartPointer mColorLUT; + double mDepth; std::vector > mMapperList; std::vector > mImageActorList; diff --git a/vv/vvImageContour.cxx b/vv/vvImageContour.cxx index 9412903..173bde0 100644 --- a/vv/vvImageContour.cxx +++ b/vv/vvImageContour.cxx @@ -36,6 +36,7 @@ vvImageContour::vvImageContour() mDisplayModeIsPreserveMemory = true; SetPreserveMemoryModeEnabled(true); mPreviousOrientation = -1; + mDepth = 1.0; } //------------------------------------------------------------------------------ @@ -291,8 +292,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 +312,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; } @@ -338,7 +339,7 @@ void vvImageContour::UpdateActor(vtkActor * actor, // Move the actor to be visible double position[3] = {0, 0, 0}; - position[orientation] = -1; + position[orientation] = -mDepth; actor->SetPosition(position); mapper->Update(); diff --git a/vv/vvImageContour.h b/vv/vvImageContour.h index d2be512..2c92abb 100644 --- a/vv/vvImageContour.h +++ b/vv/vvImageContour.h @@ -43,6 +43,7 @@ public: void SetLineWidth(double w); void SetImage(vvImage * image); void SetPreserveMemoryModeEnabled(bool b); + void SetDepth(double d) { mDepth = d; } protected: vvSlicer * mSlicer; @@ -54,6 +55,7 @@ protected: bool mHiddenImageIsUsed; vvImage * mHiddenImage; bool mDisplayModeIsPreserveMemory; + double mDepth; // For preserveMemory mode std::vector > mSquaresActorList; diff --git a/vv/vvMeshActor.cxx b/vv/vvMeshActor.cxx index 3c50b84..bfc5343 100644 --- a/vv/vvMeshActor.cxx +++ b/vv/vvMeshActor.cxx @@ -67,6 +67,8 @@ void vvMeshActor::Init(vvMesh::Pointer mesh,int time_slice,vvImage::Pointer vf) void vvMeshActor::SetCutSlice(double slice) { + DD("SetCutSlice"); + DD(slice); mCutSlice=slice; vtkImageData* mask; if (static_cast(mTimeSlice)GetNumberOfMasks()) diff --git a/vv/vvROIActor.cxx b/vv/vvROIActor.cxx index f4abf28..b46ae0a 100644 --- a/vv/vvROIActor.cxx +++ b/vv/vvROIActor.cxx @@ -40,6 +40,7 @@ vvROIActor::vvROIActor() mContourWidth = 1; mContourColor.resize(3); m_modeBG = true; + mDepth = 1.0; } //------------------------------------------------------------------------------ @@ -78,7 +79,7 @@ void vvROIActor::UpdateImage() { mOverlayActors.clear(); mImageContour.clear(); - Initialize(mIsVisible); + Initialize(mDepth, mIsVisible); Update(); // No Render } //------------------------------------------------------------------------------ @@ -133,10 +134,11 @@ bool vvROIActor::IsContourVisible() { //------------------------------------------------------------------------------ -void vvROIActor::Initialize(bool IsVisible) { +void vvROIActor::Initialize(double depth, bool IsVisible) { if (mROI->GetImage()) { mImageContour.clear(); mOverlayActors.clear(); + mDepth = depth; for(int i=0; iGetNumberOfSlicers(); i++) { mImageContour.push_back(vvImageContour::New()); @@ -148,6 +150,7 @@ void vvROIActor::Initialize(bool IsVisible) { mImageContour[i]->SetColor(mContourColor[0], mContourColor[1], mContourColor[2]); mImageContour[i]->SetLineWidth(mContourWidth); mImageContour[i]->SetPreserveMemoryModeEnabled(true); + mImageContour[i]->SetDepth(mDepth); //mImageContour[i]->SetPreserveMemoryModeEnabled(false); // SEG FAULT !!! mImageContour[i]->SetSlicer(mSlicerManager->GetSlicer(i)); mImageContour[i]->HideActors(); @@ -168,7 +171,8 @@ void vvROIActor::Initialize(bool IsVisible) { mROI->GetDisplayColor()[2]); mOverlayActors[i]->SetOpacity(mOpacity); mOverlayActors[i]->SetSlicer(mSlicerManager->GetSlicer(i)); - mOverlayActors[i]->Initialize(IsVisible); + mOverlayActors[i]->Initialize(IsVisible); + mOverlayActors[i]->SetDepth(mDepth); } connect(mSlicerManager,SIGNAL(UpdateSlice(int,int)),this,SLOT(UpdateSlice(int, int))); @@ -180,17 +184,30 @@ void vvROIActor::Initialize(bool IsVisible) { //------------------------------------------------------------------------------ -void vvROIActor::Update() +void vvROIActor::SetDepth(double d) +{ + mDepth = d; + for(int i=0; iGetNumberOfSlicers(); i++) { + mOverlayActors[i]->SetDepth(d); + mImageContour[i]->SetDepth(d); + } + Update(true); +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvROIActor::Update(bool force) { for(int i=0; iGetNumberOfSlicers(); i++) { - UpdateSlice(i, mSlicerManager->GetSlicer(i)->GetSlice()); + UpdateSlice(i, mSlicerManager->GetSlicer(i)->GetSlice(), force); } } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ -void vvROIActor::UpdateSlice(int slicer, int slices) +void vvROIActor::UpdateSlice(int slicer, int slices, bool force) { if (!mROI->GetImage()) return; if ((!mIsVisible) && (!mIsContourVisible)) return; @@ -204,7 +221,7 @@ void vvROIActor::UpdateSlice(int slicer, int slices) } // Refresh overlays - mOverlayActors[slicer]->UpdateSlice(slicer, slices); + mOverlayActors[slicer]->UpdateSlice(slicer, slices, force); } //------------------------------------------------------------------------------ diff --git a/vv/vvROIActor.h b/vv/vvROIActor.h index fb85658..42182cb 100644 --- a/vv/vvROIActor.h +++ b/vv/vvROIActor.h @@ -37,8 +37,8 @@ class vvROIActor: public QObject { void SetROI(clitk::DicomRT_ROI * r); clitk::DicomRT_ROI * GetROI() { return mROI; } void SetSlicerManager(vvSlicerManager * s); - void Update(); - void Initialize(bool IsVisible=true); + void Update(bool force=false); + void Initialize(double d=1.0, bool IsVisible=true); void SetVisible(bool b); void SetContourVisible(bool b); bool IsVisible(); @@ -51,9 +51,11 @@ class vvROIActor: public QObject { void SetContourColor(double r, double v, double b); std::vector & GetContourColor(); void SetBGMode(bool b) { m_modeBG = b; } + void SetDepth(double d); + double GetDepth() { return mDepth; } public slots: - void UpdateSlice(int slicer, int slices); + void UpdateSlice(int slicer, int slices, bool force=false); void UpdateColor(); void UpdateImage(); @@ -70,6 +72,7 @@ public slots: int mContourWidth; std::vector mContourColor; bool m_modeBG; + double mDepth; }; // end class vvROIActor //------------------------------------------------------------------------------ -- 2.47.1