From 11b8c3a844d76b55cf5a6c7e06ce445bc3732120 Mon Sep 17 00:00:00 2001 From: dsarrut Date: Mon, 3 May 2010 06:55:30 +0000 Subject: [PATCH] - add opacity (seg fault) --- vv/vvBinaryImageOverlayActor.cxx | 32 ++++++++++++++++++++++---------- vv/vvBinaryImageOverlayActor.h | 3 ++- vv/vvROIActor.cxx | 15 ++++++++++++++- vv/vvROIActor.h | 1 + vv/vvToolStructureSetManager.cxx | 11 ++++++++--- 5 files changed, 47 insertions(+), 15 deletions(-) diff --git a/vv/vvBinaryImageOverlayActor.cxx b/vv/vvBinaryImageOverlayActor.cxx index d69879c..3a448ab 100644 --- a/vv/vvBinaryImageOverlayActor.cxx +++ b/vv/vvBinaryImageOverlayActor.cxx @@ -37,6 +37,7 @@ vvBinaryImageOverlayActor::vvBinaryImageOverlayActor() { mAlpha = 0.6; mImage = 0; mSlicer = 0; + mColorLUT = vtkLookupTable::New(); } //------------------------------------------------------------------------------ @@ -84,18 +85,15 @@ void vvBinaryImageOverlayActor::initialize() { DD(numImage); // how many intensity ? - - vtkImageMapToRGBA * mOverlayMapper = vtkImageMapToRGBA::New(); mOverlayMapper->SetInput(mImage->GetVTKImages()[0]); // DS TODO : to change if it is 4D !!! - vtkLookupTable * lut = vtkLookupTable::New(); - DD(lut->IsOpaque ()); - lut->SetRange(0,1); - lut->SetNumberOfTableValues(2); - lut->SetTableValue(mBackgroundValue, 0, 0, 0, 0.0); // BG - lut->SetTableValue(1, mColor[0], mColor[1], mColor[2], mAlpha); // FG + DD(mColorLUT->IsOpaque ()); + mColorLUT->SetRange(0,1); + mColorLUT->SetNumberOfTableValues(2); + mColorLUT->SetTableValue(mBackgroundValue, 0, 0, 0, 0.0); // BG + mColorLUT->SetTableValue(1, mColor[0], mColor[1], mColor[2], mAlpha); // FG DD(mColor[0]); - mOverlayMapper->SetLookupTable(lut); + mOverlayMapper->SetLookupTable(mColorLUT); vtkImageActor * mOverlayActor = vtkImageActor::New(); mOverlayActor->SetInput(mOverlayMapper->GetOutput()); @@ -114,7 +112,21 @@ void vvBinaryImageOverlayActor::initialize() { //------------------------------------------------------------------------------ void vvBinaryImageOverlayActor::SetOpacity(double d) { mAlpha = d; - // TODO !!lut->SetTableValue(1, mColor[0], mColor[1], mColor[2], mAlpha); // FG + mColorLUT->SetTableValue(1, mColor[0], mColor[1], mColor[2], mAlpha); // FG + for (unsigned int numImage = 0; numImage < mSlicer->GetImage()->GetVTKImages().size(); numImage++) { + DD(numImage); + + // how many intensity ? + vtkImageMapToRGBA * mOverlayMapper = mMapperList[numImage]; + mOverlayMapper->SetLookupTable(mColorLUT); + + vtkImageActor * mOverlayActor = mImageActorList[numImage]; + mOverlayActor->SetInput(mOverlayMapper->GetOutput()); + //mOverlayActor->SetPickable(0); + // mOverlayActor->SetVisibility(true); + //mOverlayActor->SetOpacity(1.0); + } + DD("end SetOpacity"); } //------------------------------------------------------------------------------ diff --git a/vv/vvBinaryImageOverlayActor.h b/vv/vvBinaryImageOverlayActor.h index ccf08ef..1d05760 100644 --- a/vv/vvBinaryImageOverlayActor.h +++ b/vv/vvBinaryImageOverlayActor.h @@ -55,7 +55,8 @@ class vvBinaryImageOverlayActor std::vector mColor; double mAlpha; double mBackgroundValue; - + vtkLookupTable * mColorLUT; + std::vector mMapperList; std::vector mImageActorList; diff --git a/vv/vvROIActor.cxx b/vv/vvROIActor.cxx index 13e906b..77dc56a 100644 --- a/vv/vvROIActor.cxx +++ b/vv/vvROIActor.cxx @@ -35,6 +35,7 @@ vvROIActor::vvROIActor() { mImageContour.clear(); mOverlayActors.clear(); mIsVisible = true; + mOpacity = 0.7; } //------------------------------------------------------------------------------ @@ -102,6 +103,7 @@ void vvROIActor::Initialize() { mOverlayActors[i]->setColor(mROI->GetDisplayColor()[0], mROI->GetDisplayColor()[1], mROI->GetDisplayColor()[2]); + mOverlayActors[i]->SetOpacity(mOpacity); mOverlayActors[i]->setSlicer(mSlicerManager->GetSlicer(i)); mOverlayActors[i]->initialize(); } @@ -148,10 +150,21 @@ void vvROIActor::UpdateSlice(int slicer, int slices) { //------------------------------------------------------------------------------ void vvROIActor::SetOpacity(double d) { + if (d == mOpacity) return; mOpacity = d; - for(unsigned int i=0; mOverlayActors.size(); i++) { + DD(mOpacity); + for(unsigned int i=0; iSetOpacity(d); } + DD("end vvROIActor::SetOpacity"); +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +double vvROIActor::GetOpacity() { + return mOpacity; } //------------------------------------------------------------------------------ diff --git a/vv/vvROIActor.h b/vv/vvROIActor.h index afe7636..c3a60b9 100644 --- a/vv/vvROIActor.h +++ b/vv/vvROIActor.h @@ -41,6 +41,7 @@ class vvROIActor: public QObject { void SetVisible(bool b); bool IsVisible(); void SetOpacity(double x); + double GetOpacity(); public slots: void UpdateSlice(int slicer, int slices); diff --git a/vv/vvToolStructureSetManager.cxx b/vv/vvToolStructureSetManager.cxx index 5fcd2af..fc20be9 100644 --- a/vv/vvToolStructureSetManager.cxx +++ b/vv/vvToolStructureSetManager.cxx @@ -95,8 +95,7 @@ void vvToolStructureSetManager::InputIsSelected(vvSlicerManager *m) { connect(mTree, SIGNAL(itemSelectionChanged()), this, SLOT(selectedItemChangedInTree())); connect(mCheckBoxShow, SIGNAL(toggled(bool)), this, SLOT(visibleROIToggled(bool))); - - // TODO connect(mOpacitySlider, SIGNAL(valueChanged(int), this, SLOT(opacityChanged(int)))); + connect(mOpacitySlider, SIGNAL(valueChanged(int)), this, SLOT(opacityChanged(int))); } //------------------------------------------------------------------------------ @@ -334,7 +333,7 @@ void vvToolStructureSetManager::selectedItemChangedInTree() { DD(actor); DD(actor->IsVisible()); mCheckBoxShow->setChecked(actor->IsVisible()); - + mOpacitySlider->setValue((int)lrint(actor->GetOpacity()*100)); //actor->SetSelected(true); // remove old selection DD("ici"); @@ -353,9 +352,15 @@ void vvToolStructureSetManager::visibleROIToggled(bool b) { //------------------------------------------------------------------------------ void vvToolStructureSetManager::opacityChanged(int v) { + // if (!mCurrentROIActor) return; DD(v); mCurrentROIActor->SetOpacity((double)v/100.0); + DD("ici"); mCurrentROIActor->Update(); + // Render ! + // for(int i=0; iNumberOfSlicers(); i++) { + mCurrentSlicerManager->Render(); + //} } //------------------------------------------------------------------------------ -- 2.47.1