From 5a80d16b4dc2ad2d825c443f39ae6276786e72e4 Mon Sep 17 00:00:00 2001 From: dsarrut Date: Tue, 11 May 2010 09:07:54 +0000 Subject: [PATCH] - small correction about Render (a bit less unuseful Render) --- vv/vvBinaryImageOverlayActor.cxx | 83 ++-- vv/vvBinaryImageOverlayActor.h | 15 +- vv/vvImageContour.cxx | 23 +- vv/vvImageContour.h | 1 + vv/vvMainWindow.cxx | 5 +- vv/vvROIActor.cxx | 84 +++- vv/vvROIActor.h | 8 +- vv/vvSlicer.cxx | 2 +- vv/vvStructureSetActor.cxx | 7 +- vv/vvToolBinarize.cxx | 13 + vv/vvToolBinarize.h | 1 + vv/vvToolCropImage.cxx | 4 + vv/vvToolResample.cxx | 744 ++++++++++++++++--------------- vv/vvToolResample.h | 126 +++--- vv/vvToolStructureSetManager.cxx | 83 +++- vv/vvToolStructureSetManager.h | 1 + 16 files changed, 692 insertions(+), 508 deletions(-) diff --git a/vv/vvBinaryImageOverlayActor.cxx b/vv/vvBinaryImageOverlayActor.cxx index 3a448ab..7d6d26c 100644 --- a/vv/vvBinaryImageOverlayActor.cxx +++ b/vv/vvBinaryImageOverlayActor.cxx @@ -54,7 +54,7 @@ vvBinaryImageOverlayActor::~vvBinaryImageOverlayActor() { //------------------------------------------------------------------------------ -void vvBinaryImageOverlayActor::setColor(double r, double g, double b) { +void vvBinaryImageOverlayActor::SetColor(double r, double g, double b) { mColor[0] = r; mColor[1] = g; mColor[2] = b; @@ -63,14 +63,14 @@ void vvBinaryImageOverlayActor::setColor(double r, double g, double b) { //------------------------------------------------------------------------------ -void vvBinaryImageOverlayActor::setSlicer(vvSlicer * slicer) { +void vvBinaryImageOverlayActor::SetSlicer(vvSlicer * slicer) { mSlicer = slicer; } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ -void vvBinaryImageOverlayActor::initialize() { +void vvBinaryImageOverlayActor::Initialize() { if (!mSlicer) { std::cerr << "ERROR. Please use setSlicer before setSlicer in vvBinaryImageOverlayActor." << std::endl; exit(0); @@ -82,17 +82,13 @@ void vvBinaryImageOverlayActor::initialize() { } // Create an actor for each time slice for (unsigned int numImage = 0; numImage < mSlicer->GetImage()->GetVTKImages().size(); numImage++) { - DD(numImage); - // how many intensity ? vtkImageMapToRGBA * mOverlayMapper = vtkImageMapToRGBA::New(); mOverlayMapper->SetInput(mImage->GetVTKImages()[0]); // DS TODO : to change if it is 4D !!! - 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(mColorLUT); vtkImageActor * mOverlayActor = vtkImageActor::New(); @@ -112,27 +108,46 @@ void vvBinaryImageOverlayActor::initialize() { //------------------------------------------------------------------------------ void vvBinaryImageOverlayActor::SetOpacity(double d) { mAlpha = d; - 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); + +//------------------------------------------------------------------------------ +// void vvBinaryImageOverlayActor::UpdateOpacity(double d) { +// mAlpha = d; +// mColorLUT->SetTableValue(1, mColor[0], mColor[1], mColor[2], mAlpha); // FG +// for (unsigned int numImage = 0; numImage < mSlicer->GetImage()->GetVTKImages().size(); 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"); -} +// vtkImageActor * mOverlayActor = mImageActorList[numImage]; +// mOverlayActor->SetInput(mOverlayMapper->GetOutput()); +// } +// } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ -void vvBinaryImageOverlayActor::setImage(vvImage::Pointer image, double bg) { +// void vvBinaryImageOverlayActor::SetColor(double r, double v, double b) { +// mColor[0] = r; +// mColor[1] = v; +// mColor[2] = b; +// // mColorLUT->SetTableValue(1, mColor[0], mColor[1], mColor[2], mAlpha); // FG +// // for (unsigned int numImage = 0; numImage < mSlicer->GetImage()->GetVTKImages().size(); numImage++) { +// // // how many intensity ? +// // vtkImageMapToRGBA * mOverlayMapper = mMapperList[numImage]; +// // mOverlayMapper->SetLookupTable(mColorLUT); + +// // vtkImageActor * mOverlayActor = mImageActorList[numImage]; +// // mOverlayActor->SetInput(mOverlayMapper->GetOutput()); +// // } +// } +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvBinaryImageOverlayActor::SetImage(vvImage::Pointer image, double bg) { mImage = image; mBackgroundValue = bg; } @@ -140,31 +155,47 @@ void vvBinaryImageOverlayActor::setImage(vvImage::Pointer image, double bg) { //------------------------------------------------------------------------------ -void vvBinaryImageOverlayActor::hideActors() { +void vvBinaryImageOverlayActor::HideActors() { if (!mSlicer) return; mSlice = mSlicer->GetSlice(); for(unsigned int i=0; iVisibilityOff(); } + mSlicer->Render(); } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ -void vvBinaryImageOverlayActor::showActors() { +void vvBinaryImageOverlayActor::ShowActors() { if (!mSlicer) return; mSlice = mSlicer->GetSlice(); mTSlice = mSlicer->GetTSlice(); // for(unsigned int i=0; iVisibilityOn(); - update(0, mSlice); + UpdateSlice(0, mSlice); //} + mSlicer->Render(); } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ -void vvBinaryImageOverlayActor::update(int slicer, int slice) { +void vvBinaryImageOverlayActor::UpdateColor() { + mColorLUT->SetTableValue(1, mColor[0], mColor[1], mColor[2], mAlpha); // FG + for (unsigned int numImage = 0; numImage < mSlicer->GetImage()->GetVTKImages().size(); numImage++) { + // how many intensity ? + vtkImageMapToRGBA * mOverlayMapper = mMapperList[numImage]; + mOverlayMapper->SetLookupTable(mColorLUT); + + vtkImageActor * mOverlayActor = mImageActorList[numImage]; + mOverlayActor->SetInput(mOverlayMapper->GetOutput()); + } +} +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +void vvBinaryImageOverlayActor::UpdateSlice(int slicer, int slice) { if (!mSlicer) return; if (mPreviousSlice == mSlicer->GetSlice()) { diff --git a/vv/vvBinaryImageOverlayActor.h b/vv/vvBinaryImageOverlayActor.h index 1d05760..58512ed 100644 --- a/vv/vvBinaryImageOverlayActor.h +++ b/vv/vvBinaryImageOverlayActor.h @@ -36,14 +36,15 @@ class vvBinaryImageOverlayActor vvBinaryImageOverlayActor(); ~vvBinaryImageOverlayActor(); - void setSlicer(vvSlicer * slicer); - void update(int slicer, int slice); - void hideActors(); - void showActors(); - void setColor(double r, double g, double b); - void setImage(vvImage::Pointer image, double bg); - void initialize(); + void SetSlicer(vvSlicer * slicer); + void SetColor(double r, double g, double b); void SetOpacity(double d); + void SetImage(vvImage::Pointer image, double bg); + void Initialize(); + void UpdateColor(); + void UpdateSlice(int slicer, int slice); + void HideActors(); + void ShowActors(); protected: vvSlicer * mSlicer; diff --git a/vv/vvImageContour.cxx b/vv/vvImageContour.cxx index 1c5354e..0ffff62 100644 --- a/vv/vvImageContour.cxx +++ b/vv/vvImageContour.cxx @@ -105,6 +105,15 @@ void vvImageContour::setColor(double r, double g, double b) { //------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +void vvImageContour::SetLineWidth(double w) { + for(unsigned int i=0; iGetProperty()->SetLineWidth(w); + } +} +//------------------------------------------------------------------------------ + + //------------------------------------------------------------------------------ void vvImageContour::hideActors() { if (!mSlicer) return; @@ -131,10 +140,12 @@ void vvImageContour::showActors() { //------------------------------------------------------------------------------ void vvImageContour::update(double value) { + // DD(value); if (!mSlicer) return; if (mPreviousValue == value) { if (mPreviousSlice == mSlicer->GetSlice()) { if (mPreviousTSlice == mSlicer->GetTSlice()) { + // DD("vvImageContour::update nothing"); return; // Nothing to do } } @@ -145,14 +156,18 @@ void vvImageContour::update(double value) { // Get current slice mSlice = mSlicer->GetSlice(); - + // DD(mDisplayModeIsPreserveMemory); if (mDisplayModeIsPreserveMemory) { updateWithPreserveMemoryMode(); } else { updateWithFastCacheMode(); } - mSlicer->Render(); + + + mSlicer->Render(); //DS ---> REMOVE ?? + + mPreviousTSlice = mSlicer->GetTSlice(); mPreviousSlice = mSlicer->GetSlice(); mPreviousValue = value; @@ -178,6 +193,10 @@ void vvImageContour::updateWithPreserveMemoryMode() { vtkImageClip * mClipper = mClipperList[mTSlice]; vtkActor * mSquaresActor = mSquaresActorList[mTSlice]; int orientation = computeCurrentOrientation(); + // DD(orientation); + //DD(mValue); + //DD(mSlice); + //DD(mPreviousTslice); updateActor(mSquaresActor, mSquares, mClipper, mValue, orientation, mSlice); mSquaresActorList[mTSlice]->VisibilityOn(); if (mPreviousTslice != mTSlice) { diff --git a/vv/vvImageContour.h b/vv/vvImageContour.h index d7cf62c..747ecd8 100644 --- a/vv/vvImageContour.h +++ b/vv/vvImageContour.h @@ -39,6 +39,7 @@ class vvImageContour void hideActors(); void showActors(); void setColor(double r, double g, double b); + void SetLineWidth(double w); void setImage(vvImage::Pointer image); void setPreserveMemoryModeEnabled(bool b); diff --git a/vv/vvMainWindow.cxx b/vv/vvMainWindow.cxx index ef064fa..6b5a677 100644 --- a/vv/vvMainWindow.cxx +++ b/vv/vvMainWindow.cxx @@ -2451,7 +2451,7 @@ void vvMainWindow::NOVerticalSliderChanged() { { mSlicerManagers[i]->GetSlicer(0)->SetSlice(value); mSlicerManagers[i]->VerticalSliderHasChanged(0, value); - // mSlicerManagers[i]->UpdateSlice(0); // <-- DS add this. Not too much update ? YES. + mSlicerManagers[i]->UpdateSlice(0); // <-- DS add this. Not too much update ? YES. but needed for ImageContour ... mSlicerManagers[i]->GetSlicer(0)->Render(); // <-- DS add this, needed for contour, seems ok ? not too slow ? break; } @@ -2469,6 +2469,7 @@ void vvMainWindow::NEVerticalSliderChanged() { { mSlicerManagers[i]->GetSlicer(1)->SetSlice(value); mSlicerManagers[i]->VerticalSliderHasChanged(1, value); + mSlicerManagers[i]->UpdateSlice(1); mSlicerManagers[i]->GetSlicer(1)->Render(); // <-- DS add this, needed for contour, seems ok ? not too slow ? break; } @@ -2486,6 +2487,7 @@ void vvMainWindow::SOVerticalSliderChanged() { { mSlicerManagers[i]->GetSlicer(2)->SetSlice(value); mSlicerManagers[i]->VerticalSliderHasChanged(2, value); + mSlicerManagers[i]->UpdateSlice(2); mSlicerManagers[i]->GetSlicer(2)->Render(); // <-- DS add this, needed for contour, seems ok ? not too slow ? break; } @@ -2503,6 +2505,7 @@ void vvMainWindow::SEVerticalSliderChanged() { { mSlicerManagers[i]->GetSlicer(3)->SetSlice(value); mSlicerManagers[i]->VerticalSliderHasChanged(3, value); + mSlicerManagers[i]->UpdateSlice(3); mSlicerManagers[i]->GetSlicer(3)->Render(); // <-- DS add this, needed for contour, seems ok ? not too slow ? break; } diff --git a/vv/vvROIActor.cxx b/vv/vvROIActor.cxx index 77dc56a..1b3585d 100644 --- a/vv/vvROIActor.cxx +++ b/vv/vvROIActor.cxx @@ -36,6 +36,7 @@ vvROIActor::vvROIActor() { mOverlayActors.clear(); mIsVisible = true; mOpacity = 0.7; + mIsSelected = false; } //------------------------------------------------------------------------------ @@ -47,7 +48,7 @@ vvROIActor::~vvROIActor() { //------------------------------------------------------------------------------ -void vvROIActor::SetROI(const clitk::DicomRT_ROI * s) { +void vvROIActor::SetROI(clitk::DicomRT_ROI * s) { mROI = s; } //------------------------------------------------------------------------------ @@ -65,11 +66,11 @@ void vvROIActor::SetVisible(bool b) { mIsVisible = b; if (!b) { // remove actor for(unsigned int i= 0; ihideActors(); + mOverlayActors[i]->HideActors(); } else { for(unsigned int i= 0; ishowActors(); + mOverlayActors[i]->ShowActors(); } Update(); } @@ -92,20 +93,21 @@ void vvROIActor::Initialize() { mImageContour.push_back(new vvImageContour); mImageContour[i]->setSlicer(mSlicerManager->GetSlicer(i)); mImageContour[i]->setImage(mROI->GetImage()); - // mImageContour[i]->setColor(1.0, 0.0, 0.0); - mImageContour[i]->setColor(mROI->GetDisplayColor()[0], - mROI->GetDisplayColor()[1], - mROI->GetDisplayColor()[2]); - mImageContour[i]->setPreserveMemoryModeEnabled(false); + //mImageContour[i]->setColor(1.0, 0.0, 0.0); + mImageContour[i]->setColor(1.0-mROI->GetDisplayColor()[0], + 1.0-mROI->GetDisplayColor()[1], + 1.0-mROI->GetDisplayColor()[2]); + mImageContour[i]->setPreserveMemoryModeEnabled(true); + mImageContour[i]->setSlicer(mSlicerManager->GetSlicer(i)); mOverlayActors.push_back(new vvBinaryImageOverlayActor); - mOverlayActors[i]->setImage(mROI->GetImage(), mROI->GetBackgroundValueLabelImage()); - mOverlayActors[i]->setColor(mROI->GetDisplayColor()[0], + mOverlayActors[i]->SetImage(mROI->GetImage(), mROI->GetBackgroundValueLabelImage()); + 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(); + mOverlayActors[i]->SetSlicer(mSlicerManager->GetSlicer(i)); + mOverlayActors[i]->Initialize(); } connect(mSlicerManager,SIGNAL(UpdateSlice(int,int)),this,SLOT(UpdateSlice(int, int))); @@ -137,10 +139,17 @@ void vvROIActor::UpdateSlice(int slicer, int slices) { } // CONTOUR HERE - // mImageContour[slicer]->update(1.0); + DD("vvROIActor::UpdateSlice"); + DD(mROI->GetName()); + DD(mIsSelected); + DD(mROI->GetBackgroundValueLabelImage()); + if (mIsSelected) { + mImageContour[slicer]->update(1.0);//mROI->GetBackgroundValueLabelImage()); + // mImageContour[slicer]->showActors(); + } // Refresh overlays - mOverlayActors[slicer]->update(slicer, slices); + mOverlayActors[slicer]->UpdateSlice(slicer, slices); // Do not used the following line : TOO SLOW. // mSlicerManager->GetSlicer(slicer)->GetRenderWindow()->Render(); @@ -148,16 +157,35 @@ void vvROIActor::UpdateSlice(int slicer, int slices) { //------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +// void vvROIActor::UpdateOpacity(double d) { +// if (d == mOpacity) return; +// mOpacity = d; +// for(unsigned int i=0; iSetOpacity(d); +// mOverlayActors[i]->UpdateColor(); +// } +// mSlicerManager->Render(); +// } +//------------------------------------------------------------------------------ + + //------------------------------------------------------------------------------ void vvROIActor::SetOpacity(double d) { - if (d == mOpacity) return; mOpacity = d; - DD(mOpacity); +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvROIActor::UpdateColor() { for(unsigned int i=0; iSetOpacity(d); + mOverlayActors[i]->SetOpacity(mOpacity); + mOverlayActors[i]->SetColor(mROI->GetDisplayColor()[0], + mROI->GetDisplayColor()[1], + mROI->GetDisplayColor()[2]); + mOverlayActors[i]->UpdateColor(); } - DD("end vvROIActor::SetOpacity"); } //------------------------------------------------------------------------------ @@ -168,3 +196,21 @@ double vvROIActor::GetOpacity() { } //------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +void vvROIActor::SetSelected(bool b) { + mIsSelected = b; + if (b) { + for(int i=0; iNumberOfSlicers(); i++) { + mImageContour[i]->SetLineWidth(3.0); + mImageContour[i]->showActors(); + } + } + else { + for(int i=0; iNumberOfSlicers(); i++) { + mImageContour[i]->hideActors(); + } + } +} +//------------------------------------------------------------------------------ + diff --git a/vv/vvROIActor.h b/vv/vvROIActor.h index c3a60b9..bb5c16b 100644 --- a/vv/vvROIActor.h +++ b/vv/vvROIActor.h @@ -34,7 +34,8 @@ class vvROIActor: public QObject { vvROIActor(); ~vvROIActor(); - void SetROI(const clitk::DicomRT_ROI * r); + void SetROI(clitk::DicomRT_ROI * r); + clitk::DicomRT_ROI * GetROI() { return mROI; } void SetSlicerManager(vvSlicerManager * s); void Update(); void Initialize(); @@ -42,18 +43,21 @@ class vvROIActor: public QObject { bool IsVisible(); void SetOpacity(double x); double GetOpacity(); + void SetSelected(bool b); public slots: void UpdateSlice(int slicer, int slices); + void UpdateColor(); protected: - const clitk::DicomRT_ROI * mROI; + clitk::DicomRT_ROI * mROI; vvSlicerManager * mSlicerManager; std::vector mImageContour; std::vector mOverlayActors; bool mIsVisible; double mOpacity; + bool mIsSelected; }; // end class vvROIActor //------------------------------------------------------------------------------ diff --git a/vv/vvSlicer.cxx b/vv/vvSlicer.cxx index 331c236..3b585b2 100644 --- a/vv/vvSlicer.cxx +++ b/vv/vvSlicer.cxx @@ -1255,7 +1255,7 @@ void vvSlicer::GetExtremasAroundMousePointer(double & min, double & max) //---------------------------------------------------------------------------- void vvSlicer::Render() { - // DD("Render"); + // DD("vvSlicer::Render"); //DD(SliceOrientation); if (this->GetWindowLevel()->GetLookupTable() && !this->mOverlay && !this->mFusion) { diff --git a/vv/vvStructureSetActor.cxx b/vv/vvStructureSetActor.cxx index 16df512..7ea1ef9 100644 --- a/vv/vvStructureSetActor.cxx +++ b/vv/vvStructureSetActor.cxx @@ -48,12 +48,10 @@ void vvStructureSetActor::SetSlicerManager(vvSlicerManager * s) { //------------------------------------------------------------------------------ vvROIActor * vvStructureSetActor::GetROIActor(int n) { - DD(n); if (mMapROIIndex.find(n) == mMapROIIndex.end()) { std::cerr << "No ROI number " << n << std::endl; return NULL; } - DD(mMapROIIndex[n]); return mROIActors[mMapROIIndex[n]]; } //------------------------------------------------------------------------------ @@ -61,11 +59,8 @@ vvROIActor * vvStructureSetActor::GetROIActor(int n) { //------------------------------------------------------------------------------ void vvStructureSetActor::CreateNewROIActor(int n) { - DD("AddROIActor"); - DD(n); - // Check - const clitk::DicomRT_ROI * roi = mStructureSet->GetROI(n); + clitk::DicomRT_ROI * roi = mStructureSet->GetROI(n); if (roi == NULL) { std::cerr << "Error. No ROI number " << n << std::endl; exit(0); diff --git a/vv/vvToolBinarize.cxx b/vv/vvToolBinarize.cxx index 2834285..ae06718 100644 --- a/vv/vvToolBinarize.cxx +++ b/vv/vvToolBinarize.cxx @@ -26,6 +26,7 @@ #include #include #include +#include //------------------------------------------------------------------------------ // Create the tool and automagically (I like this word) insert it in @@ -200,10 +201,22 @@ void vvToolBinarize::InputIsSelected(vvSlicerManager * m) { connect(mCurrentSlicerManager,SIGNAL(UpdateSlice(int,int)),this,SLOT(UpdateSlice(int, int))); connect(mCurrentSlicerManager,SIGNAL(UpdateTSlice(int,int)),this,SLOT(UpdateSlice(int, int))); + // connect(mCurrentSlicerManager, SIGNAL(LeftButtonReleaseSignal(int)), SLOT(LeftButtonReleaseEvent(int))); } //------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +// void vvToolBinarize::LeftButtonReleaseEvent(int slicer) { +// DD("LeftButtonReleaseEvent"); +// for(int i=0; iNumberOfSlicers(); i++) { +// if (i == slicer); +// mCurrentSlicerManager->GetSlicer(i)->GetRenderWindow()->Render(); +// } +// } +//------------------------------------------------------------------------------ + + //------------------------------------------------------------------------------ void vvToolBinarize::UpdateSlice(int slicer,int slices) { if (!mInteractiveDisplayIsEnabled) return; diff --git a/vv/vvToolBinarize.h b/vv/vvToolBinarize.h index 2332bd4..fc042d9 100644 --- a/vv/vvToolBinarize.h +++ b/vv/vvToolBinarize.h @@ -52,6 +52,7 @@ class vvToolBinarize: void enableLowerThan(bool b); void useFGBGtoggled(bool); void InteractiveDisplayToggled(bool b); + // void LeftButtonReleaseEvent(int slicer); protected: void RemoveVTKObjects(); diff --git a/vv/vvToolCropImage.cxx b/vv/vvToolCropImage.cxx index 74c1e4c..6192350 100644 --- a/vv/vvToolCropImage.cxx +++ b/vv/vvToolCropImage.cxx @@ -15,6 +15,7 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html ======================================================================-====*/ + #include "vvToolCropImage.h" #include #include @@ -245,6 +246,9 @@ void vvToolCropImage::InputIsSelected(vvSlicerManager * slicer) { // connect(tminSlider, SIGNAL(valueChanged(int)), this, SLOT(sliderTMinValueChanged(int))); // connect(tmaxSlider, SIGNAL(valueChanged(int)), this, SLOT(sliderTMaxValueChanged(int))); + // connect(mCurrentSlicerManager,SIGNAL(UpdateSlice(int,int)),this,SLOT(UpdateExtent())); + //connect(mCurrentSlicerManager,SIGNAL(UpdateTSlice(int,int)),this,SLOT(UpdateExtent())); + // connect(mIntensitySlider, SIGNAL(valueChanged(double)), this, SLOT(autoCropValueChanged(double))); UpdateExtent(); } diff --git a/vv/vvToolResample.cxx b/vv/vvToolResample.cxx index 3ac1701..531a03b 100644 --- a/vv/vvToolResample.cxx +++ b/vv/vvToolResample.cxx @@ -14,7 +14,7 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html -======================================================================-====*/ + ======================================================================-====*/ #include "vvToolResample.h" #include "vvSlicer.h" @@ -27,437 +27,457 @@ ADD_TOOL(vvToolResample); -//==================================================================== +//------------------------------------------------------------------------------ vvToolResample::vvToolResample(vvMainWindowBase * parent, Qt::WindowFlags f): - vvToolWidgetBase(parent,f), - vvToolBase(parent), - Ui::vvToolResample() -{ - Ui_vvToolResample::setupUi(mToolWidget); - - mFilter = clitk::ImageResampleGenericFilter::New(); - mLastError =""; - - mInputFileFormat = ""; - ComponentType = ""; - mPixelType = ""; - mCurrentSlicerManager=NULL; - - mInputSize.resize(0); - mInputSpacing.resize(0); - mInputOrigin.resize(0); - mOutputSize.resize(0); - mOutputSpacing.resize(0); - - xSizeLineEdit->setText(""); - ySizeLineEdit->setText(""); - zSizeLineEdit->setText(""); - xSpacingLineEdit->setText(""); - ySpacingLineEdit->setText(""); - zSpacingLineEdit->setText(""); - scaleSizeLineEdit->setText(""); - scaleSpacingLineEdit->setText(""); - - sizeRadioButton->setChecked(0); - scaleSizeRadioButton->setChecked(0); - isoSizeRadioButton->setChecked(0); - spacingRadioButton->setChecked(0); - scaleSpacingRadioButton->setChecked(0); - isoSpacingRadioButton->setChecked(0); - - gaussianFilterCheckBox->setCheckState(Qt::Unchecked); - - xGaussianLineEdit->hide(); - yGaussianLineEdit->hide(); - zGaussianLineEdit->hide(); - gaussianFilterLabel->hide(); - - bSplineLabel->hide(); - bSplineOrderSpinBox->hide(); - bLUTFactorLabel->hide(); - bLUTSpinBox->hide(); - mDimension = -1; - - QPalette qPalette; - qPalette.setColor(QPalette::Foreground, QColor(Qt::blue)); - mInputFormatLabel->setPalette(qPalette); - mInputDimLabel->setPalette(qPalette); - mInputPixelTypeLabel->setPalette(qPalette); - mInputSizeLabel->setPalette(qPalette); - mInputSpacingLabel->setPalette(qPalette); - - // Set how many inputs are needed for this tool - AddInputSelector("Select an image to resample", mFilter); - - // Connect signals & slots - - connect(sizeRadioButton, SIGNAL(clicked()), this, SLOT(UpdateControlSizeAndSpacing())); - connect(scaleSizeRadioButton, SIGNAL(clicked()), this, SLOT(UpdateControlSizeAndSpacing())); - connect(isoSizeRadioButton, SIGNAL(clicked()), this, SLOT(UpdateControlSizeAndSpacing())); - connect(spacingRadioButton, SIGNAL(clicked()), this, SLOT(UpdateControlSizeAndSpacing())); - connect(scaleSpacingRadioButton, SIGNAL(clicked()), this, SLOT(UpdateControlSizeAndSpacing())); - connect(isoSpacingRadioButton, SIGNAL(clicked()), this, SLOT(UpdateControlSizeAndSpacing())); - - connect(xSizeLineEdit, SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSpacingFromSize())); - connect(ySizeLineEdit, SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSpacingFromSize())); - connect(zSizeLineEdit, SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSpacingFromSize())); - connect(xSpacingLineEdit, SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSizeFromSpacing())); - connect(ySpacingLineEdit, SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSizeFromSpacing())); - connect(zSpacingLineEdit, SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSizeFromSpacing())); - connect(scaleSizeLineEdit,SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSizeFromScale())); - connect(scaleSpacingLineEdit,SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSpacingFromScale())); - connect(isoSizeLineEdit,SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSizeFromIso())); - connect(isoSpacingLineEdit,SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSpacingFromIso())); - - connect(gaussianFilterCheckBox,SIGNAL(stateChanged(int)),this,SLOT(UpdateGaussianFilter())); - connect(interpolationComboBox,SIGNAL(currentIndexChanged(QString)),this,SLOT(UpdateInterpolation())); + vvToolWidgetBase(parent,f), + vvToolBase(parent), + Ui::vvToolResample() { + Ui_vvToolResample::setupUi(mToolWidget); + + mFilter = clitk::ImageResampleGenericFilter::New(); + mLastError =""; + + mInputFileFormat = ""; + ComponentType = ""; + mPixelType = ""; + mCurrentSlicerManager=NULL; + + mInputSize.resize(0); + mInputSpacing.resize(0); + mInputOrigin.resize(0); + mOutputSize.resize(0); + mOutputSpacing.resize(0); + + xSizeLineEdit->setText(""); + ySizeLineEdit->setText(""); + zSizeLineEdit->setText(""); + xSpacingLineEdit->setText(""); + ySpacingLineEdit->setText(""); + zSpacingLineEdit->setText(""); + scaleSizeLineEdit->setText(""); + scaleSpacingLineEdit->setText(""); + + sizeRadioButton->setChecked(0); + scaleSizeRadioButton->setChecked(0); + isoSizeRadioButton->setChecked(0); + spacingRadioButton->setChecked(0); + scaleSpacingRadioButton->setChecked(0); + isoSpacingRadioButton->setChecked(0); + + gaussianFilterCheckBox->setCheckState(Qt::Unchecked); + + xGaussianLineEdit->hide(); + yGaussianLineEdit->hide(); + zGaussianLineEdit->hide(); + gaussianFilterLabel->hide(); + + bSplineLabel->hide(); + bSplineOrderSpinBox->hide(); + bLUTFactorLabel->hide(); + bLUTSpinBox->hide(); + mDimension = -1; + + QPalette qPalette; + qPalette.setColor(QPalette::Foreground, QColor(Qt::blue)); + mInputFormatLabel->setPalette(qPalette); + mInputDimLabel->setPalette(qPalette); + mInputPixelTypeLabel->setPalette(qPalette); + mInputSizeLabel->setPalette(qPalette); + mInputSpacingLabel->setPalette(qPalette); + + // Set how many inputs are needed for this tool + AddInputSelector("Select an image to resample", mFilter); + + // Connect signals & slots + + connect(sizeRadioButton, SIGNAL(clicked()), this, SLOT(UpdateControlSizeAndSpacing())); + connect(scaleSizeRadioButton, SIGNAL(clicked()), this, SLOT(UpdateControlSizeAndSpacing())); + connect(isoSizeRadioButton, SIGNAL(clicked()), this, SLOT(UpdateControlSizeAndSpacing())); + connect(spacingRadioButton, SIGNAL(clicked()), this, SLOT(UpdateControlSizeAndSpacing())); + connect(scaleSpacingRadioButton, SIGNAL(clicked()), this, SLOT(UpdateControlSizeAndSpacing())); + connect(isoSpacingRadioButton, SIGNAL(clicked()), this, SLOT(UpdateControlSizeAndSpacing())); + + connect(xSizeLineEdit, SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSpacingFromSize())); + connect(ySizeLineEdit, SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSpacingFromSize())); + connect(zSizeLineEdit, SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSpacingFromSize())); + connect(xSpacingLineEdit, SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSizeFromSpacing())); + connect(ySpacingLineEdit, SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSizeFromSpacing())); + connect(zSpacingLineEdit, SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSizeFromSpacing())); + connect(scaleSizeLineEdit,SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSizeFromScale())); + connect(scaleSpacingLineEdit,SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSpacingFromScale())); + connect(isoSizeLineEdit,SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSizeFromIso())); + connect(isoSpacingLineEdit,SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSpacingFromIso())); + + connect(gaussianFilterCheckBox,SIGNAL(stateChanged(int)),this,SLOT(UpdateGaussianFilter())); + connect(interpolationComboBox,SIGNAL(currentIndexChanged(QString)),this,SLOT(UpdateInterpolation())); } -//==================================================================== +//------------------------------------------------------------------------------ + -//==================================================================== +//------------------------------------------------------------------------------ void vvToolResample::Initialize() { SetToolName("Resample Image"); SetToolMenuName("Resample"); SetToolIconFilename(":/common/icons/resample.png"); SetToolTip("Resample image with various interpolation methods."); } -//==================================================================== +//------------------------------------------------------------------------------ -//==================================================================== -void vvToolResample::InputIsSelected(vvSlicerManager* m) { - mCurrentSlicerManager = m; - mCurrentImage = mCurrentSlicerManager->GetSlicer(0)->GetImage(); - if (mCurrentImage.IsNull()) return; - mInputFileName = mCurrentSlicerManager->GetFileName().c_str(); - - // Set current information - mPixelType = mCurrentImage->GetScalarTypeAsString().c_str(); - //ds ComponentType = mCurrentImageGetNumberOfScalarComponents(); - mDimension = mCurrentImage->GetNumberOfDimensions(); - - // Copy size, spacing ... - mInputOrigin.resize(mDimension); - mInputSpacing.resize(mDimension); - mInputSize.resize(mDimension); - for (int i = 0; i < mDimension;i++) { - mInputOrigin[i] = mCurrentImage->GetOrigin()[i]; - mInputSpacing[i] = mCurrentImage->GetSpacing()[i]; - mInputSize[i] = mCurrentImage->GetSize()[i]; - } +//------------------------------------------------------------------------------ +void vvToolResample::InputIsSelected(vvSlicerManager* m) { - // Get file format - mInputFileFormat = itksys::SystemTools::GetFilenameLastExtension(mInputFileName.toStdString()).c_str(); - - // Display infos - mInputFormatLabel->setText(mInputFileFormat); - mInputSizeLabel->setText(GetVectorIntAsString(mInputSize)); - mInputDimLabel->setText(QString::number(mDimension)+"D"); - mInputSpacingLabel->setText(GetVectorDoubleAsString(mInputSpacing)); - mInputPixelTypeLabel->setText(mPixelType); - mInputMemoryLabel->setText(GetSizeInBytes(mInputSize)); - - // Set current size - scaleSizeRadioButton->setChecked(true); - UpdateControlSizeAndSpacing(); - scaleSizeLineEdit->setText("100"); - ComputeNewSizeFromScale(); - - // Update output - UpdateOutputInfo(); + mCurrentSlicerManager = m; + mCurrentImage = mCurrentSlicerManager->GetSlicer(0)->GetImage(); + if (mCurrentImage.IsNull()) return; + mInputFileName = mCurrentSlicerManager->GetFileName().c_str(); + + // Set current information + mPixelType = mCurrentImage->GetScalarTypeAsString().c_str(); + //ds ComponentType = mCurrentImageGetNumberOfScalarComponents(); + mDimension = mCurrentImage->GetNumberOfDimensions(); + + // Copy size, spacing ... + mInputOrigin.resize(mDimension); + mInputSpacing.resize(mDimension); + mInputSize.resize(mDimension); + for (int i = 0; i < mDimension;i++) { + mInputOrigin[i] = mCurrentImage->GetOrigin()[i]; + mInputSpacing[i] = mCurrentImage->GetSpacing()[i]; + mInputSize[i] = mCurrentImage->GetSize()[i]; + } + + // Get file format + mInputFileFormat = itksys::SystemTools::GetFilenameLastExtension(mInputFileName.toStdString()).c_str(); + + // Display infos + mInputFormatLabel->setText(mInputFileFormat); + mInputSizeLabel->setText(GetVectorIntAsString(mInputSize)); + mInputDimLabel->setText(QString::number(mDimension)+"D"); + mInputSpacingLabel->setText(GetVectorDoubleAsString(mInputSpacing)); + mInputPixelTypeLabel->setText(mPixelType); + mInputMemoryLabel->setText(GetSizeInBytes(mInputSize)); + + // Set current size + scaleSizeRadioButton->setChecked(true); + UpdateControlSizeAndSpacing(); + scaleSizeLineEdit->setText("100"); + ComputeNewSizeFromScale(); + + // Update output + UpdateOutputInfo(); } -//==================================================================== +//------------------------------------------------------------------------------ + -//==================================================================== +//------------------------------------------------------------------------------ void vvToolResample::UpdateOutputInfo() { - mOutputSizeLabel->setText(GetVectorIntAsString(mOutputSize)); - mOutputSpacingLabel->setText(GetVectorDoubleAsString(mOutputSpacing)); - mOutputMemoryLabel->setText(GetSizeInBytes(mOutputSize)); + mOutputSizeLabel->setText(GetVectorIntAsString(mOutputSize)); + mOutputSpacingLabel->setText(GetVectorDoubleAsString(mOutputSpacing)); + mOutputMemoryLabel->setText(GetSizeInBytes(mOutputSize)); } -//==================================================================== +//------------------------------------------------------------------------------ -//==================================================================== + +//------------------------------------------------------------------------------ QString vvToolResample::GetSizeInBytes(std::vector & size) { - int t = 1; - for (unsigned int i=0; iGetScalarSize()*mCurrentImage->GetNumberOfScalarComponents(); - QString result = QString::number(t); - result += " bytes ("; - if (t > 1000000000) { - t /= 1000000000; - result += QString::number(t); - result += " GB)"; - } - else if (t > 1000000) { - t /= 1000000; - result += QString::number(t); - result += " MB)"; - } - else if (t > 1000) { - t /= 1000; - result += QString::number(t); - result += " KB)"; - } - else result += ")"; - return result; + int t = 1; + for (unsigned int i=0; iGetScalarSize()*mCurrentImage->GetNumberOfScalarComponents(); + QString result = QString::number(t); + result += " bytes ("; + if (t > 1000000000) { + t /= 1000000000; + result += QString::number(t); + result += " GB)"; + } + else if (t > 1000000) { + t /= 1000000; + result += QString::number(t); + result += " MB)"; + } + else if (t > 1000) { + t /= 1000; + result += QString::number(t); + result += " KB)"; + } + else result += ")"; + return result; } -//==================================================================== +//------------------------------------------------------------------------------ -//==================================================================== + +//------------------------------------------------------------------------------ QString vvToolResample::GetVectorDoubleAsString(std::vector vectorDouble) { - QString result; - for (unsigned int i= 0; i vectorInt) { - QString result; - for (unsigned int i= 0; i size) { - xSizeLineEdit->setText(QString::number(size[0])); - ySizeLineEdit->setText(QString::number(size[1])); - if (size.size() > 2) - zSizeLineEdit->setText(QString::number(size[2])); + xSizeLineEdit->setText(QString::number(size[0])); + ySizeLineEdit->setText(QString::number(size[1])); + if (size.size() > 2) + zSizeLineEdit->setText(QString::number(size[2])); } -//==================================================================== +//------------------------------------------------------------------------------ + -//==================================================================== +//------------------------------------------------------------------------------ void vvToolResample::FillSpacingEdit(std::vector spacing) { - xSpacingLineEdit->setText(QString::number(spacing[0])); - ySpacingLineEdit->setText(QString::number(spacing[1])); - if (spacing.size() > 2) - zSpacingLineEdit->setText(QString::number(spacing[2])); + xSpacingLineEdit->setText(QString::number(spacing[0])); + ySpacingLineEdit->setText(QString::number(spacing[1])); + if (spacing.size() > 2) + zSpacingLineEdit->setText(QString::number(spacing[2])); } -//==================================================================== +//------------------------------------------------------------------------------ -//==================================================================== -void vvToolResample::UpdateOutputSizeAndSpacing() { - mOutputSize.resize(mDimension); - mOutputSize = mInputSize; - mOutputSpacing.resize(mDimension); - mOutputSpacing = mInputSpacing; - mOutputSize[0] = (int)xSizeLineEdit->text().toDouble(); - mOutputSize[1] = (int)ySizeLineEdit->text().toDouble(); - if (mDimension > 2) - mOutputSize[2] = (int)zSizeLineEdit->text().toDouble(); - - mOutputSpacing[0] = xSpacingLineEdit->text().toDouble(); - mOutputSpacing[1] = ySpacingLineEdit->text().toDouble(); - if (mDimension > 2) - mOutputSpacing[2] = zSpacingLineEdit->text().toDouble(); - UpdateOutputInfo(); +//------------------------------------------------------------------------------ +void vvToolResample::UpdateOutputSizeAndSpacing() { + mOutputSize.resize(mDimension); + mOutputSize = mInputSize; + mOutputSpacing.resize(mDimension); + mOutputSpacing = mInputSpacing; + mOutputSize[0] = (int)xSizeLineEdit->text().toDouble(); + mOutputSize[1] = (int)ySizeLineEdit->text().toDouble(); + if (mDimension > 2) + mOutputSize[2] = (int)zSizeLineEdit->text().toDouble(); + + mOutputSpacing[0] = xSpacingLineEdit->text().toDouble(); + mOutputSpacing[1] = ySpacingLineEdit->text().toDouble(); + if (mDimension > 2) + mOutputSpacing[2] = zSpacingLineEdit->text().toDouble(); + + UpdateOutputInfo(); } -//==================================================================== +//------------------------------------------------------------------------------ + -//==================================================================== +//------------------------------------------------------------------------------ void vvToolResample::UpdateControlSizeAndSpacing() { - scaleSizeLineEdit->setText(""); - scaleSpacingLineEdit->setText(""); - isoSizeLineEdit->setText(""); - isoSpacingLineEdit->setText(""); - - xSizeLineEdit->setReadOnly(1); - ySizeLineEdit->setReadOnly(1); - zSizeLineEdit->setReadOnly(1); - scaleSizeLineEdit->setReadOnly(1); - isoSizeLineEdit->setReadOnly(1); - - xSpacingLineEdit->setReadOnly(1); - ySpacingLineEdit->setReadOnly(1); - zSpacingLineEdit->setReadOnly(1); - scaleSpacingLineEdit->setReadOnly(1); - isoSpacingLineEdit->setReadOnly(1); - - if (sizeRadioButton->isChecked()) { - xSizeLineEdit->setReadOnly(0); - ySizeLineEdit->setReadOnly(0); - if (mDimension > 2) - zSizeLineEdit->setReadOnly(0); - } - else { - if (spacingRadioButton->isChecked()) { - xSpacingLineEdit->setReadOnly(0); - ySpacingLineEdit->setReadOnly(0); - if (mDimension > 2) - zSpacingLineEdit->setReadOnly(0); - } - else if (scaleSizeRadioButton->isChecked()) - scaleSizeLineEdit->setReadOnly(0); - else if (scaleSpacingRadioButton->isChecked()) - scaleSpacingLineEdit->setReadOnly(0); - else if (isoSizeRadioButton->isChecked()) - isoSizeLineEdit->setReadOnly(0); - else if (isoSpacingRadioButton->isChecked()) - isoSpacingLineEdit->setReadOnly(0); + scaleSizeLineEdit->setText(""); + scaleSpacingLineEdit->setText(""); + isoSizeLineEdit->setText(""); + isoSpacingLineEdit->setText(""); + + xSizeLineEdit->setReadOnly(1); + ySizeLineEdit->setReadOnly(1); + zSizeLineEdit->setReadOnly(1); + scaleSizeLineEdit->setReadOnly(1); + isoSizeLineEdit->setReadOnly(1); + + xSpacingLineEdit->setReadOnly(1); + ySpacingLineEdit->setReadOnly(1); + zSpacingLineEdit->setReadOnly(1); + scaleSpacingLineEdit->setReadOnly(1); + isoSpacingLineEdit->setReadOnly(1); + + if (sizeRadioButton->isChecked()) { + xSizeLineEdit->setReadOnly(0); + ySizeLineEdit->setReadOnly(0); + if (mDimension > 2) + zSizeLineEdit->setReadOnly(0); + } + else { + if (spacingRadioButton->isChecked()) { + xSpacingLineEdit->setReadOnly(0); + ySpacingLineEdit->setReadOnly(0); + if (mDimension > 2) + zSpacingLineEdit->setReadOnly(0); } + else if (scaleSizeRadioButton->isChecked()) + scaleSizeLineEdit->setReadOnly(0); + else if (scaleSpacingRadioButton->isChecked()) + scaleSpacingLineEdit->setReadOnly(0); + else if (isoSizeRadioButton->isChecked()) + isoSizeLineEdit->setReadOnly(0); + else if (isoSpacingRadioButton->isChecked()) + isoSpacingLineEdit->setReadOnly(0); + } } -//==================================================================== +//------------------------------------------------------------------------------ -//==================================================================== + +//------------------------------------------------------------------------------ void vvToolResample::ComputeNewSpacingFromSize() { - double newSpacing = mInputSpacing[0]*mInputSize[0]; - xSpacingLineEdit->setText(QString::number(newSpacing/xSizeLineEdit->text().toDouble())); - newSpacing = mInputSpacing[1]*mInputSize[1]; - ySpacingLineEdit->setText(QString::number(newSpacing/ySizeLineEdit->text().toDouble())); - if (mDimension > 2) + double newSpacing = mInputSpacing[0]*mInputSize[0]; + xSpacingLineEdit->setText(QString::number(newSpacing/xSizeLineEdit->text().toDouble())); + newSpacing = mInputSpacing[1]*mInputSize[1]; + ySpacingLineEdit->setText(QString::number(newSpacing/ySizeLineEdit->text().toDouble())); + if (mDimension > 2) { - newSpacing = mInputSpacing[2]*mInputSize[2]; - zSpacingLineEdit->setText(QString::number(newSpacing/zSizeLineEdit->text().toDouble())); + newSpacing = mInputSpacing[2]*mInputSize[2]; + zSpacingLineEdit->setText(QString::number(newSpacing/zSizeLineEdit->text().toDouble())); } - UpdateOutputSizeAndSpacing(); + UpdateOutputSizeAndSpacing(); } -//==================================================================== +//------------------------------------------------------------------------------ + -//==================================================================== +//------------------------------------------------------------------------------ void vvToolResample::ComputeNewSizeFromSpacing() { - double newSize = mInputSpacing[0]*mInputSize[0]; - xSizeLineEdit->setText(QString::number(newSize/xSpacingLineEdit->text().toDouble())); - newSize = mInputSpacing[1]*mInputSize[1]; - ySizeLineEdit->setText(QString::number(newSize/ySpacingLineEdit->text().toDouble())); - if (mDimension > 2) + double newSize = mInputSpacing[0]*mInputSize[0]; + xSizeLineEdit->setText(QString::number(newSize/xSpacingLineEdit->text().toDouble())); + newSize = mInputSpacing[1]*mInputSize[1]; + ySizeLineEdit->setText(QString::number(newSize/ySpacingLineEdit->text().toDouble())); + if (mDimension > 2) { - newSize = mInputSpacing[2]*mInputSize[2]; - zSizeLineEdit->setText(QString::number(newSize/zSpacingLineEdit->text().toDouble())); + newSize = mInputSpacing[2]*mInputSize[2]; + zSizeLineEdit->setText(QString::number(newSize/zSpacingLineEdit->text().toDouble())); } - UpdateOutputSizeAndSpacing(); + UpdateOutputSizeAndSpacing(); } -//==================================================================== +//------------------------------------------------------------------------------ + -//==================================================================== +//------------------------------------------------------------------------------ void vvToolResample::ComputeNewSpacingFromScale() { - xSpacingLineEdit->setText(QString::number(mInputSpacing[0]*scaleSpacingLineEdit->text().toDouble()/100)); - ySpacingLineEdit->setText(QString::number(mInputSpacing[1]*scaleSpacingLineEdit->text().toDouble()/100)); - if (mDimension > 2) - zSpacingLineEdit->setText(QString::number(mInputSpacing[2]*scaleSpacingLineEdit->text().toDouble()/100)); - ComputeNewSizeFromSpacing(); + xSpacingLineEdit->setText(QString::number(mInputSpacing[0]*scaleSpacingLineEdit->text().toDouble()/100)); + ySpacingLineEdit->setText(QString::number(mInputSpacing[1]*scaleSpacingLineEdit->text().toDouble()/100)); + if (mDimension > 2) + zSpacingLineEdit->setText(QString::number(mInputSpacing[2]*scaleSpacingLineEdit->text().toDouble()/100)); + ComputeNewSizeFromSpacing(); } -//==================================================================== +//------------------------------------------------------------------------------ + -//==================================================================== +//------------------------------------------------------------------------------ void vvToolResample::ComputeNewSizeFromScale() { - xSizeLineEdit->setText(QString::number(mInputSize[0]*scaleSizeLineEdit->text().toDouble()/100)); - ySizeLineEdit->setText(QString::number(mInputSize[1]*scaleSizeLineEdit->text().toDouble()/100)); - if (mDimension > 2) - zSizeLineEdit->setText(QString::number(mInputSize[2]*scaleSizeLineEdit->text().toDouble()/100)); - ComputeNewSpacingFromSize(); + xSizeLineEdit->setText(QString::number(mInputSize[0]*scaleSizeLineEdit->text().toDouble()/100)); + ySizeLineEdit->setText(QString::number(mInputSize[1]*scaleSizeLineEdit->text().toDouble()/100)); + if (mDimension > 2) + zSizeLineEdit->setText(QString::number(mInputSize[2]*scaleSizeLineEdit->text().toDouble()/100)); + ComputeNewSpacingFromSize(); } -//==================================================================== +//------------------------------------------------------------------------------ + -//==================================================================== +//------------------------------------------------------------------------------ void vvToolResample::ComputeNewSpacingFromIso() { - xSpacingLineEdit->setText(QString::number(isoSpacingLineEdit->text().toDouble())); - ySpacingLineEdit->setText(QString::number(isoSpacingLineEdit->text().toDouble())); - if (mDimension > 2) - zSpacingLineEdit->setText(QString::number(isoSpacingLineEdit->text().toDouble())); - ComputeNewSizeFromSpacing(); + xSpacingLineEdit->setText(QString::number(isoSpacingLineEdit->text().toDouble())); + ySpacingLineEdit->setText(QString::number(isoSpacingLineEdit->text().toDouble())); + if (mDimension > 2) + zSpacingLineEdit->setText(QString::number(isoSpacingLineEdit->text().toDouble())); + ComputeNewSizeFromSpacing(); } -//==================================================================== +//------------------------------------------------------------------------------ + -//==================================================================== +//------------------------------------------------------------------------------ void vvToolResample::ComputeNewSizeFromIso() { - xSizeLineEdit->setText(QString::number(isoSizeLineEdit->text().toDouble())); - ySizeLineEdit->setText(QString::number(isoSizeLineEdit->text().toDouble())); - if (mDimension > 2) - zSizeLineEdit->setText(QString::number(isoSizeLineEdit->text().toDouble())); - ComputeNewSpacingFromSize(); + xSizeLineEdit->setText(QString::number(isoSizeLineEdit->text().toDouble())); + ySizeLineEdit->setText(QString::number(isoSizeLineEdit->text().toDouble())); + if (mDimension > 2) + zSizeLineEdit->setText(QString::number(isoSizeLineEdit->text().toDouble())); + ComputeNewSpacingFromSize(); } -//==================================================================== +//------------------------------------------------------------------------------ + -//==================================================================== +//------------------------------------------------------------------------------ void vvToolResample::UpdateInterpolation() { - if (interpolationComboBox->currentText() == "BSpline") { - bSplineLabel->show(); - bSplineOrderSpinBox->show(); - bLUTFactorLabel->hide(); - bLUTSpinBox->hide(); - } - else if (interpolationComboBox->currentText() == "Blut (faster BSpline)") { - bSplineLabel->show(); - bSplineOrderSpinBox->show(); - bLUTFactorLabel->show(); - bLUTSpinBox->show(); - } - else { - bSplineLabel->hide(); - bSplineOrderSpinBox->hide(); - bLUTFactorLabel->hide(); - bLUTSpinBox->hide(); - } + if (interpolationComboBox->currentText() == "BSpline") { + bSplineLabel->show(); + bSplineOrderSpinBox->show(); + bLUTFactorLabel->hide(); + bLUTSpinBox->hide(); + } + else if (interpolationComboBox->currentText() == "B-LUT (faster BSpline)") { + bSplineLabel->show(); + bSplineOrderSpinBox->show(); + bLUTFactorLabel->show(); + bLUTSpinBox->show(); + } + else { + bSplineLabel->hide(); + bSplineOrderSpinBox->hide(); + bLUTFactorLabel->hide(); + bLUTSpinBox->hide(); + } } -//==================================================================== +//------------------------------------------------------------------------------ + -//==================================================================== +//------------------------------------------------------------------------------ void vvToolResample::UpdateGaussianFilter() { - if (gaussianFilterCheckBox->isChecked()) { - gaussianFilterLabel->show(); - xGaussianLineEdit->show(); - yGaussianLineEdit->show(); - if (mDimension > 2) - zGaussianLineEdit->show(); - } - else { - gaussianFilterLabel->hide(); - xGaussianLineEdit->hide(); - yGaussianLineEdit->hide(); - zGaussianLineEdit->hide(); - } + if (gaussianFilterCheckBox->isChecked()) { + gaussianFilterLabel->show(); + xGaussianLineEdit->show(); + yGaussianLineEdit->show(); + if (mDimension > 2) + zGaussianLineEdit->show(); + } + else { + gaussianFilterLabel->hide(); + xGaussianLineEdit->hide(); + yGaussianLineEdit->hide(); + zGaussianLineEdit->hide(); + } } -//==================================================================== +//------------------------------------------------------------------------------ -//==================================================================== +//------------------------------------------------------------------------------ void vvToolResample::apply() { - // Get resampler options - std::vector sigma; - sigma.push_back(xGaussianLineEdit->text().toDouble()); - sigma.push_back(yGaussianLineEdit->text().toDouble()); - if (mDimension > 2) sigma.push_back(zGaussianLineEdit->text().toDouble()); - if (mDimension == 4) sigma.push_back(0.01); //FIXME Don't filter along the temporal direction - - mFilter->SetOutputSize(mOutputSize); - mFilter->SetOutputSpacing(mOutputSpacing); - mFilter->SetInterpolationName(interpolationComboBox->currentText().toLower().toStdString()); - - if (interpolationComboBox->currentText() == "BSpline") - mFilter->SetBSplineOrder(bSplineOrderSpinBox->value()); - else if (interpolationComboBox->currentText() == "Blut (faster BSpline)") { - mFilter->SetInterpolationName("blut"); - mFilter->SetBSplineOrder(bSplineOrderSpinBox->value()); - mFilter->SetBLUTSampling(bLUTSpinBox->value()); - } - if (gaussianFilterCheckBox->isChecked()) - mFilter->SetGaussianSigma(sigma); - // mFilter->SetOutputFileName(OutputFileName.toStdString()); - mFilter->SetDefaultPixelValue(defaultPixelValueLineEdit->text().toDouble()); - mFilter->SetInputVVImage(mCurrentImage); - - // Go ! - mFilter->Update(); - mOutput = mFilter->GetOutputVVImage(); - AddImage(mOutput,GetOutputFileName()); - close(); + // Get resampler options + std::vector sigma; + sigma.push_back(xGaussianLineEdit->text().toDouble()); + sigma.push_back(yGaussianLineEdit->text().toDouble()); + if (mDimension > 2) sigma.push_back(zGaussianLineEdit->text().toDouble()); + if (mDimension == 4) sigma.push_back(0.01); //FIXME Don't filter along the temporal direction + + mFilter->SetOutputSize(mOutputSize); + mFilter->SetOutputSpacing(mOutputSpacing); + mFilter->SetInterpolationName(interpolationComboBox->currentText().toLower().toStdString()); + + if (interpolationComboBox->currentText() == "BSpline") + mFilter->SetBSplineOrder(bSplineOrderSpinBox->value()); + else if (interpolationComboBox->currentText() == "B-LUT (faster BSpline)") { + mFilter->SetInterpolationName("blut"); + mFilter->SetBSplineOrder(bSplineOrderSpinBox->value()); + mFilter->SetBLUTSampling(bLUTSpinBox->value()); + } + if (gaussianFilterCheckBox->isChecked()) + mFilter->SetGaussianSigma(sigma); + // mFilter->SetOutputFileName(OutputFileName.toStdString()); + mFilter->SetDefaultPixelValue(defaultPixelValueLineEdit->text().toDouble()); + mFilter->SetInputVVImage(mCurrentImage); + + // Go ! + mFilter->Update(); + mOutput = mFilter->GetOutputVVImage(); + AddImage(mOutput,GetOutputFileName()); + close(); } -//==================================================================== -std::string vvToolResample::GetOutputFileName() -{ - QFileInfo info(QString(mCurrentSlicerManager->GetFileName().c_str())); - return (info.path().toStdString() + "/resampled_" + info.fileName().toStdString()); +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +std::string vvToolResample::GetOutputFileName() { + QFileInfo info(QString(mCurrentSlicerManager->GetFileName().c_str())); + return (info.path().toStdString() + "/resampled_" + info.fileName().toStdString()); } +//------------------------------------------------------------------------------ diff --git a/vv/vvToolResample.h b/vv/vvToolResample.h index 56801be..b12e940 100644 --- a/vv/vvToolResample.h +++ b/vv/vvToolResample.h @@ -14,93 +14,95 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html -======================================================================-====*/ -#ifndef _vvToolResample_h -#define _vvToolResample_h + ======================================================================-====*/ + +#ifndef _VVTOOLRESAMPLE_H +#define _VVTOOLRESAMPLE_H + #include "ui_vvToolResample.h" #include "clitkCommon.h" +#include "clitkImageResampleGenericFilter.h" #include "vvImage.h" #include "vvSlicerManager.h" #include "vvToolWidgetBase.h" #include "vvToolBase.h" -#include "clitkImageResampleGenericFilter.h" #include #include -//==================================================================== +//------------------------------------------------------------------------------ class vvToolResample : - public vvToolWidgetBase, - public vvToolBase, - private Ui::vvToolResample -{ - - Q_OBJECT - -public: - // constructor - destructor - vvToolResample(vvMainWindowBase * parent=0, Qt::WindowFlags f=0); - - // Get output result - vvImage::Pointer GetOutput() { - return mOutput; - } - std::string GetOutputFileName(); - static void Initialize(); - void apply(); + public vvToolWidgetBase, + public vvToolBase, + private Ui::vvToolResample { + + Q_OBJECT + + public: + // constructor - destructor + vvToolResample(vvMainWindowBase * parent=0, Qt::WindowFlags f=0); + + // Get output result + vvImage::Pointer GetOutput() { + return mOutput; + } + std::string GetOutputFileName(); + static void Initialize(); + void apply(); public slots: -// void SetImagesList(QTreeWidget * tree); - void UpdateControlSizeAndSpacing(); - void ComputeNewSizeFromSpacing(); - void ComputeNewSizeFromScale(); - void ComputeNewSizeFromIso(); - void ComputeNewSpacingFromSize(); - void ComputeNewSpacingFromScale(); - void ComputeNewSpacingFromIso(); - void UpdateInterpolation(); - void UpdateGaussianFilter(); - void InputIsSelected(vvSlicerManager* m); + // void SetImagesList(QTreeWidget * tree); + void UpdateControlSizeAndSpacing(); + void ComputeNewSizeFromSpacing(); + void ComputeNewSizeFromScale(); + void ComputeNewSizeFromIso(); + void ComputeNewSpacingFromSize(); + void ComputeNewSpacingFromScale(); + void ComputeNewSpacingFromIso(); + void UpdateInterpolation(); + void UpdateGaussianFilter(); + void InputIsSelected(vvSlicerManager* m); protected: - Ui::vvToolResample ui; - vvImage::Pointer mOutput; - clitk::ImageResampleGenericFilter::Pointer mFilter; + Ui::vvToolResample ui; + vvImage::Pointer mOutput; + clitk::ImageResampleGenericFilter::Pointer mFilter; - vvSlicerManager* mCurrentSlicerManager; - vvImage::Pointer mCurrentImage; - int mCurrentIndex; + vvSlicerManager* mCurrentSlicerManager; + vvImage::Pointer mCurrentImage; + int mCurrentIndex; - std::vector mInputOrigin; - std::vector mInputSize; - std::vector mInputSpacing; - std::vector mOutputSize; - std::vector mOutputSpacing; - int mDimension; + std::vector mInputOrigin; + std::vector mInputSize; + std::vector mInputSpacing; + std::vector mOutputSize; + std::vector mOutputSpacing; + int mDimension; - QString mLastError; + QString mLastError; - QString mInputFileName; + QString mInputFileName; - QString mInputFileFormat; - QString mPixelType; - QString ComponentType; + QString mInputFileFormat; + QString mPixelType; + QString ComponentType; - QStringList OutputListFormat; + QStringList OutputListFormat; - void UpdateInputInfo(); - void UpdateOutputInfo(); - void UpdateOutputFormat(); - void FillSizeEdit(std::vector size); - void FillSpacingEdit(std::vector spacing); - void UpdateOutputSizeAndSpacing(); + void UpdateInputInfo(); + void UpdateOutputInfo(); + void UpdateOutputFormat(); + void FillSizeEdit(std::vector size); + void FillSpacingEdit(std::vector spacing); + void UpdateOutputSizeAndSpacing(); - QString GetSizeInBytes(std::vector & size); - QString GetVectorDoubleAsString(std::vector vectorDouble); - QString GetVectorIntAsString(std::vector vectorInt); + QString GetSizeInBytes(std::vector & size); + QString GetVectorDoubleAsString(std::vector vectorDouble); + QString GetVectorIntAsString(std::vector vectorInt); }; // end class vvToolResample -//==================================================================== +//------------------------------------------------------------------------------ + #endif diff --git a/vv/vvToolStructureSetManager.cxx b/vv/vvToolStructureSetManager.cxx index fc20be9..ea24ca6 100644 --- a/vv/vvToolStructureSetManager.cxx +++ b/vv/vvToolStructureSetManager.cxx @@ -21,8 +21,11 @@ #include "vvStructureSetActor.h" #include "vvSlicer.h" #include "vvROIActor.h" + #include #include +#include + #include #include @@ -41,6 +44,9 @@ vvToolStructureSetManager::vvToolStructureSetManager(vvMainWindowBase * parent, Ui_vvToolStructureSetManager::setupUi(mToolWidget); mTree->clear(); mCurrentStructureSet = NULL; + mCurrentStructureSetIndex = -1; + mGroupBoxROI->setEnabled(false); + mCurrentROIActor = NULL; mDefaultLUTColor = vtkLookupTable::New(); for(unsigned int i=0; iGetNumberOfTableValues(); i++) { @@ -96,6 +102,7 @@ void vvToolStructureSetManager::InputIsSelected(vvSlicerManager *m) { connect(mTree, SIGNAL(itemSelectionChanged()), this, SLOT(selectedItemChangedInTree())); connect(mCheckBoxShow, SIGNAL(toggled(bool)), this, SLOT(visibleROIToggled(bool))); connect(mOpacitySlider, SIGNAL(valueChanged(int)), this, SLOT(opacityChanged(int))); + connect(mChangeColorButton, SIGNAL(clicked()), this, SLOT(changeColor())); } //------------------------------------------------------------------------------ @@ -315,56 +322,92 @@ void vvToolStructureSetManager::apply() { //------------------------------------------------------------------------------ void vvToolStructureSetManager::selectedItemChangedInTree() { DD("selectedItemChangedInTree"); + + // Search which roi is selected QList l = mTree->selectedItems(); DD(l.size()); QTreeWidgetItem * w = l[0]; - if (mMapTreeWidgetToROI.find(w) == mMapTreeWidgetToROI.end()) return; // Search for SS (first) + if (mMapTreeWidgetToROI.find(w) == mMapTreeWidgetToROI.end()) { + mCurrentROIActor = NULL; + mCurrentROI = NULL; + mGroupBoxROI->setEnabled(false); + return; // Search for SS (first) + } clitk::DicomRT_ROI * roi = mMapTreeWidgetToROI[w]; - DD(roi->GetName()); - //setCurrentSelectedROI(roi); + // DD(roi->GetName()); + + // Get selected roi actor + if (mCurrentROIActor != NULL) { + mCurrentROIActor->SetSelected(false); + mCurrentROIActor->Update(); + } - mROInameLabel->setText(roi->GetName().c_str()); - DD(roi->GetROINumber()); - DD(mCurrentStructureSetIndex); vvROIActor * actor = mStructureSetActorsList[mCurrentStructureSetIndex]->GetROIActor(roi->GetROINumber()); mCurrentROI = roi; mCurrentROIActor = actor; - DD(actor); - DD(actor->IsVisible()); + // Update GUI + mGroupBoxROI->setEnabled(true); + mROInameLabel->setText(roi->GetName().c_str()); mCheckBoxShow->setChecked(actor->IsVisible()); + + // Warning -> avoir unuseful Render here by disconnect slider + // + disconnect(mOpacitySlider, SIGNAL(valueChanged(int)), + this, SLOT(opacityChanged(int))); mOpacitySlider->setValue((int)lrint(actor->GetOpacity()*100)); - //actor->SetSelected(true); // remove old selection + mOpacitySpinBox->setValue((int)lrint(actor->GetOpacity()*100)); + connect(mOpacitySlider, SIGNAL(valueChanged(int)), + this, SLOT(opacityChanged(int))); - DD("ici"); + actor->SetSelected(true); // remove old selection + // The following must not render !! + DD("before update"); + actor->Update(); // To change in UpdateSelecte + DD("after update"); + + mCurrentSlicerManager->Render(); } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ void vvToolStructureSetManager::visibleROIToggled(bool b) { - DD(b); mCurrentROIActor->SetVisible(b); - //mCurrentROIActor->Update(); } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ 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(); - //} + mCurrentROIActor->UpdateColor(); + mCurrentSlicerManager->Render(); } //------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +void vvToolStructureSetManager::changeColor() { + QColor color; + color.setRgbF(mCurrentROIActor->GetROI()->GetDisplayColor()[0], + mCurrentROIActor->GetROI()->GetDisplayColor()[1], + mCurrentROIActor->GetROI()->GetDisplayColor()[2]); + QColor c = QColorDialog::getColor(color, this, "Choose the ROI color"); + mCurrentROIActor->GetROI()->SetDisplayColor(c.redF(), c.greenF(), c.blueF()); + mCurrentROIActor->UpdateColor(); + + QTreeWidgetItem * w = mMapROIToTreeWidget[mCurrentROI]; + QBrush brush(QColor(mCurrentROI->GetDisplayColor()[0]*255, + mCurrentROI->GetDisplayColor()[1]*255, + mCurrentROI->GetDisplayColor()[2]*255)); + brush.setStyle(Qt::SolidPattern); + for(int i=0; icolumnCount (); i++) { + w->setBackground(i, brush); + } +} +//------------------------------------------------------------------------------ + //------------------------------------------------------------------------------ diff --git a/vv/vvToolStructureSetManager.h b/vv/vvToolStructureSetManager.h index 8421473..008caa1 100644 --- a/vv/vvToolStructureSetManager.h +++ b/vv/vvToolStructureSetManager.h @@ -54,6 +54,7 @@ public slots: void selectedItemChangedInTree(); void visibleROIToggled(bool b); void opacityChanged(int v); + void changeColor(); protected: Ui::vvToolStructureSetManager ui; -- 2.47.1