From 0410cde2a749710c2659d4c582d9fc0c332aced6 Mon Sep 17 00:00:00 2001 From: dsarrut Date: Fri, 5 Mar 2010 10:32:32 +0000 Subject: [PATCH] - update vv tool Binarize, now work with float pixel type + display lower contour --- filters/clitkBinarizeImageGenericFilter.txx | 6 +- vv/qt_ui/vvIntensityValueSlider.ui | 68 +++++++--- vv/vvImageContour.cxx | 15 ++- vv/vvImageContour.h | 9 +- vv/vvIntensityValueSlider.cxx | 133 ++++++++++++++++---- vv/vvIntensityValueSlider.h | 15 ++- vv/vvToolBinarize.cxx | 51 ++++++-- vv/vvToolBinarize.h | 5 +- 8 files changed, 232 insertions(+), 70 deletions(-) diff --git a/filters/clitkBinarizeImageGenericFilter.txx b/filters/clitkBinarizeImageGenericFilter.txx index fcdb693..747412a 100644 --- a/filters/clitkBinarizeImageGenericFilter.txx +++ b/filters/clitkBinarizeImageGenericFilter.txx @@ -22,9 +22,9 @@ namespace clitk template BinarizeImageGenericFilter::BinarizeImageGenericFilter(): ImageToImageGenericFilter("Binarize") { - // InitializeImageType<2>(); + InitializeImageType<2>(); InitializeImageType<3>(); - //InitializeImageType<4>(); + InitializeImageType<4>(); } //-------------------------------------------------------------------- @@ -33,7 +33,7 @@ namespace clitk template template void BinarizeImageGenericFilter::InitializeImageType() { - //ADD_IMAGE_TYPE(Dim, char); + ADD_IMAGE_TYPE(Dim, char); ADD_IMAGE_TYPE(Dim, short); ADD_IMAGE_TYPE(Dim, int); ADD_IMAGE_TYPE(Dim, float); diff --git a/vv/qt_ui/vvIntensityValueSlider.ui b/vv/qt_ui/vvIntensityValueSlider.ui index ae0c459..e0e1e1d 100644 --- a/vv/qt_ui/vvIntensityValueSlider.ui +++ b/vv/qt_ui/vvIntensityValueSlider.ui @@ -6,25 +6,19 @@ 0 0 - 222 - 39 + 324 + 29 Form - - 2 - - - 2 - - + 2 - + @@ -41,14 +35,8 @@ - - - 0 - 0 - - - 2 + 1 -9999.000000000000000 @@ -58,6 +46,52 @@ + + + + + + + 0 + 0 + + + + + 15 + 15 + + + + + 18 + + + + - + + + + + + + + 15 + 15 + + + + + 18 + + + + + + + + + + diff --git a/vv/vvImageContour.cxx b/vv/vvImageContour.cxx index 88924c1..7318640 100644 --- a/vv/vvImageContour.cxx +++ b/vv/vvImageContour.cxx @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvImageContour.cxx,v $ Language: C++ - Date: $Date: 2010/03/01 07:37:25 $ - Version: $Revision: 1.4 $ + Date: $Date: 2010/03/05 10:32:33 $ + Version: $Revision: 1.5 $ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) Copyright (C) 2010 @@ -83,6 +83,15 @@ void vvImageContour::setSlicer(vvSlicer * slicer) { //------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +void vvImageContour::setColor(double r, double g, double b) { + for(unsigned int i=0; iGetProperty()->SetColor(r,g,b); + } +} +//------------------------------------------------------------------------------ + + //------------------------------------------------------------------------------ void vvImageContour::hideActors() { if (!mSlicer) return; @@ -108,7 +117,7 @@ void vvImageContour::showActors() { //------------------------------------------------------------------------------ -void vvImageContour::update(int value) { +void vvImageContour::update(double value) { mValue= value; if (!mSlicer) return; diff --git a/vv/vvImageContour.h b/vv/vvImageContour.h index 3bf4a6e..4228b70 100644 --- a/vv/vvImageContour.h +++ b/vv/vvImageContour.h @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvImageContour.h,v $ Language: C++ - Date: $Date: 2010/03/01 07:37:25 $ - Version: $Revision: 1.4 $ + Date: $Date: 2010/03/05 10:32:33 $ + Version: $Revision: 1.5 $ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) Copyright (C) 2010 @@ -43,15 +43,16 @@ class vvImageContour ~vvImageContour(); void setSlicer(vvSlicer * slicer); - void update(int value); + void update(double value); void hideActors(); void showActors(); + void setColor(double r, double g, double b); protected: vvSlicer * mSlicer; int mSlice; int mTSlice; - int mValue; + double mValue; std::vector mClipperList; std::vector mSquaresList; diff --git a/vv/vvIntensityValueSlider.cxx b/vv/vvIntensityValueSlider.cxx index c1973af..ce2c6f8 100644 --- a/vv/vvIntensityValueSlider.cxx +++ b/vv/vvIntensityValueSlider.cxx @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvIntensityValueSlider.cxx,v $ Language: C++ - Date: $Date: 2010/03/01 07:37:25 $ - Version: $Revision: 1.4 $ + Date: $Date: 2010/03/05 10:32:33 $ + Version: $Revision: 1.5 $ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) Copyright (C) 2008 @@ -33,13 +33,15 @@ vvIntensityValueSlider::vvIntensityValueSlider(QWidget * parent, Qt::WindowFlags { // GUI Initialization setupUi(this); - mValue = 0; - SetMaximum(1000); - SetMinimum(-1000); + mIsInteger = true; + mButtonPlus->setHidden(true); + mButtonMinus->setHidden(true); // Connect signals & slots connect(mSpinBox, SIGNAL(valueChanged(double)), this, SLOT(valueChangedFromSpinBox(double))); connect(mSlider, SIGNAL(valueChanged(int)), this, SLOT(valueChangedFromSlider(int))); + connect(mButtonPlus, SIGNAL(clicked()), this, SLOT(SingleStepPlusClicked())); + connect(mButtonMinus, SIGNAL(clicked()), this, SLOT(SingleStepMinusClicked())); } //------------------------------------------------------------------------------ @@ -50,9 +52,40 @@ vvIntensityValueSlider::~vvIntensityValueSlider() { //------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +void vvIntensityValueSlider::SingleStepMinusClicked() { + mSpinBox->setSingleStep(mSpinBox->singleStep()*10); + mSpinBox->setDecimals(mSpinBox->decimals()-1); +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvIntensityValueSlider::SetSingleStep(double step) { + mSpinBox->setSingleStep(step); +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvIntensityValueSlider::SingleStepPlusClicked() { + mSpinBox->setSingleStep(mSpinBox->singleStep()/10); + mSpinBox->setDecimals(mSpinBox->decimals()+1); +} +//------------------------------------------------------------------------------ + + //------------------------------------------------------------------------------ void vvIntensityValueSlider::valueChangedFromSpinBox(double v) { - mSlider->setValue(v); + if (v == mValue) return; + mSpinBox->setValue(v); + v = mSpinBox->value(); // this is needed to 'round' value according to spinBox precision + double vv; + if (!mIsInteger) { + vv = ((v-mMin)/mWidth)/mSliderFactor; + } + else vv = v; + mSlider->setValue(vv); mValue = v; emit valueChanged(v); } @@ -60,8 +93,18 @@ void vvIntensityValueSlider::valueChangedFromSpinBox(double v) { //------------------------------------------------------------------------------ -void vvIntensityValueSlider::valueChangedFromSlider(int v) { - mSpinBox->setValue(v*mSliderFactor); +void vvIntensityValueSlider::valueChangedFromSlider(int vv) { + double v; + if (!mIsInteger) { + v = ((double)vv*mSliderFactor)*mWidth+mMin; + } + else v= vv; + + // arrondir ! ? + + if (mValue == v) return; + mSpinBox->setValue(v); + mValue = v; } //------------------------------------------------------------------------------ @@ -82,16 +125,27 @@ void vvIntensityValueSlider::SetImage(vvImage * im) { //------------------------------------------------------------------------------ -void vvIntensityValueSlider::SetValue(double d) { - mSpinBox->setValue(d); +void vvIntensityValueSlider::SetValue(double v) { + mValue = v; + mSpinBox->setValue(v); } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ void vvIntensityValueSlider::SetMaximum(double max) { - mSlider->setMaximum(max); + mMax = max; mSpinBox->setMaximum(max); + + // If integer values : update slider max + if (mIsInteger == 1) { + mSlider->setMaximum(max); + } + else { + double step = mWidth/1000.0; + mSpinBox->setSingleStep(step); + mWidth = mMax-mMin; + } if (mValue > max) { SetValue(max); } QString tip = QString("Min = %1 Max = %2").arg(mSpinBox->minimum()).arg(max); setToolTip(tip); @@ -101,8 +155,18 @@ void vvIntensityValueSlider::SetMaximum(double max) { //------------------------------------------------------------------------------ void vvIntensityValueSlider::SetMinimum(double min) { - mSlider->setMinimum(min); + mMin = min; mSpinBox->setMinimum(min); + + if (mIsInteger == 1) { + mSlider->setMinimum(min); + } + else { + double step = mWidth/1000.0; + mSpinBox->setSingleStep(step); + mWidth = mMax-mMin; + } + if (mValue < min) { SetValue(min); } QString tip = QString("Min = %1 Max = %2").arg(min).arg(mSpinBox->maximum()); setToolTip(tip); @@ -112,28 +176,43 @@ void vvIntensityValueSlider::SetMinimum(double min) { //------------------------------------------------------------------------------ void vvIntensityValueSlider::Update() { + double range[2]; + mImage->GetFirstVTKImageData()->GetScalarRange(range); + mMin = range[0]; + mMax = range[1]; + double step = (mMax-mMin)/1000.0; + if (mImage->IsScalarTypeInteger()) { - + mIsInteger = true; mSpinBox->setSingleStep(1.0); mSpinBox->setDecimals(0); - mSliderFactor = 1.0; - - double range[2]; - mImage->GetFirstVTKImageData()->GetScalarRange(range); - mMin = range[0]; - mMax = range[1]; mSlider->setMaximum(mMax); mSlider->setMinimum(mMin); - mSpinBox->setMaximum(mMax); - mSpinBox->setMinimum(mMin); - - QString tip = QString("Min = %1 Max = %2").arg(mMin).arg(mMax); - setToolTip(tip); + mSlider->setSingleStep(1); + mSliderFactor = 1.0; + mWidth = 1.0; } else { - std::cerr << "NO floating point image yet !!" << std::endl; - exit(0); + mIsInteger = false; + mButtonPlus->setHidden(false); + mButtonMinus->setHidden(false); + mSpinBox->sizePolicy().setHorizontalPolicy(QSizePolicy::Expanding); + mSpinBox->setSingleStep(step); + mSpinBox->setDecimals(4); + mSlider->setMaximum(1000); + mSlider->setMinimum(0); + mSlider->setSingleStep(1); + mSliderFactor = 1.0/1000.0; + mWidth = mMax-mMin; } + + mSpinBox->setMaximum(mMax); + mSpinBox->setMinimum(mMin); + mSpinBox->setValue((mMax-mMin)/2.0+mMin); + + QString tip = QString("Min = %1 Max = %2").arg(mMin).arg(mMax); + setToolTip(tip); } - //------------------------------------------------------------------------------ + + diff --git a/vv/vvIntensityValueSlider.h b/vv/vvIntensityValueSlider.h index 4050de4..be6e713 100644 --- a/vv/vvIntensityValueSlider.h +++ b/vv/vvIntensityValueSlider.h @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvIntensityValueSlider.h,v $ Language: C++ - Date: $Date: 2010/02/05 09:06:46 $ - Version: $Revision: 1.2 $ + Date: $Date: 2010/03/05 10:32:33 $ + Version: $Revision: 1.3 $ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) Copyright (C) 2008 @@ -50,13 +50,16 @@ class vvIntensityValueSlider: double GetValue() const { return mValue; } void SetValue(double d); void SetMaximum(double max); - void SetMinimum(double min); + void SetMinimum(double min); + void SetSingleStep(double step); void resetMinimum() { SetMinimum(mMin); } void resetMaximum() { SetMaximum(mMax); } public slots: void valueChangedFromSpinBox(double v); void valueChangedFromSlider(int v); + void SingleStepPlusClicked(); + void SingleStepMinusClicked(); signals: void valueChanged(double); @@ -64,10 +67,12 @@ class vvIntensityValueSlider: protected: Ui::vvIntensityValueSlider ui; vvImage * mImage; + double mMin; + double mMax; + double mWidth; double mSliderFactor; double mValue; - double mMax; - double mMin; + bool mIsInteger; }; // end class vvIntensityValueSlider //------------------------------------------------------------------------------ diff --git a/vv/vvToolBinarize.cxx b/vv/vvToolBinarize.cxx index 4f91d19..09016f0 100644 --- a/vv/vvToolBinarize.cxx +++ b/vv/vvToolBinarize.cxx @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvToolBinarize.cxx,v $ Language: C++ - Date: $Date: 2010/03/01 15:38:09 $ - Version: $Revision: 1.10 $ + Date: $Date: 2010/03/05 10:32:33 $ + Version: $Revision: 1.11 $ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) Copyright (C) 2008 @@ -64,8 +64,6 @@ vvToolBinarize::vvToolBinarize(vvMainWindowBase * parent, Qt::WindowFlags f) mInteractiveDisplayIsEnabled = mCheckBoxInteractiveDisplay->isChecked(); // Connect signals & slots - connect(mThresholdSlider1, SIGNAL(valueChanged(double)), this, SLOT(valueChangedT1(double))); - connect(mThresholdSlider2, SIGNAL(valueChanged(double)), this, SLOT(valueChangedT2(double))); connect(mRadioButtonLowerThan, SIGNAL(toggled(bool)), this, SLOT(enableLowerThan(bool))); connect(mCheckBoxUseFG, SIGNAL(toggled(bool)), this, SLOT(useFGBGtoggled(bool))); connect(mCheckBoxUseBG, SIGNAL(toggled(bool)), this, SLOT(useFGBGtoggled(bool))); @@ -96,8 +94,10 @@ void vvToolBinarize::InteractiveDisplayToggled(bool b) { RemoveVTKObjects(); } else { - for(unsigned int i=0; ishowActors(); + mImageContourLower[i]->showActors(); + } if (mCurrentSlicerManager) mCurrentSlicerManager->Render(); } @@ -107,8 +107,10 @@ void vvToolBinarize::InteractiveDisplayToggled(bool b) { //------------------------------------------------------------------------------ void vvToolBinarize::RemoveVTKObjects() { - for(unsigned int i=0; ihideActors(); + mImageContourLower[i]->hideActors(); + } if (mCurrentSlicerManager) mCurrentSlicerManager->Render(); } @@ -135,9 +137,18 @@ void vvToolBinarize::reject() { void vvToolBinarize::enableLowerThan(bool b) { if (!b) { mThresholdSlider1->resetMaximum(); + for(unsigned int i=0; ihideActors(); + } + mCurrentSlicerManager->Render(); } else { valueChangedT1(mThresholdSlider1->GetValue()); + valueChangedT2(mThresholdSlider2->GetValue()); + for(unsigned int i=0; ishowActors(); + } + mCurrentSlicerManager->Render(); } } //------------------------------------------------------------------------------ @@ -169,13 +180,23 @@ void vvToolBinarize::InputIsSelected(vvSlicerManager * m) { mBGSlider->SetMinimum(mCurrentImage->GetFirstVTKImageData()->GetScalarTypeMin()); mFGSlider->SetValue(1); mBGSlider->SetValue(0); + mFGSlider->SetSingleStep(1); + mBGSlider->SetSingleStep(1); // VTK objects for interactive display for(int i=0;iNumberOfSlicers(); i++) { mImageContour.push_back(new vvImageContour); mImageContour[i]->setSlicer(mCurrentSlicerManager->GetSlicer(i)); + mImageContour[i]->setColor(1.0, 0.0, 0.0); + mImageContourLower.push_back(new vvImageContour); + mImageContourLower[i]->setSlicer(mCurrentSlicerManager->GetSlicer(i)); + mImageContourLower[i]->setColor(0.0, 0.0, 1.0); } valueChangedT1(mThresholdSlider1->GetValue()); + + connect(mThresholdSlider1, SIGNAL(valueChanged(double)), this, SLOT(valueChangedT1(double))); + connect(mThresholdSlider2, SIGNAL(valueChanged(double)), this, SLOT(valueChangedT2(double))); + connect(mCurrentSlicerManager,SIGNAL(UpdateSlice(int,int)),this,SLOT(UpdateSlice(int, int))); connect(mCurrentSlicerManager,SIGNAL(UpdateTSlice(int,int)),this,SLOT(UpdateSlice(int, int))); @@ -189,6 +210,9 @@ void vvToolBinarize::UpdateSlice(int slicer,int slices) { if (!mCurrentSlicerManager) close(); for(int i=0;iNumberOfSlicers(); i++) { mImageContour[i]->update(mThresholdSlider1->GetValue()); + if (mRadioButtonLowerThan->isChecked()) + mImageContourLower[i]->update(mThresholdSlider2->GetValue()); + } mCurrentSlicerManager->Render(); } @@ -279,19 +303,28 @@ void vvToolBinarize::apply() { //------------------------------------------------------------------------------ void vvToolBinarize::valueChangedT2(double v) { - if (mRadioButtonLowerThan->isChecked()) mThresholdSlider1->SetMaximum(v); + // DD("valueChangedT2"); + if (mRadioButtonLowerThan->isChecked()) { + mThresholdSlider1->SetMaximum(v); + if (!mInteractiveDisplayIsEnabled) return; + for(int i=0;iNumberOfSlicers(); i++) { + mImageContourLower[i]->update(v); + } + mCurrentSlicerManager->Render(); + } } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ void vvToolBinarize::valueChangedT1(double v) { + // DD("valueChangedT1"); if (!mCurrentSlicerManager) close(); mThresholdSlider2->SetMinimum(v); - int m1 = (int)lrint(v); + // int m1 = (int)lrint(v); if (!mInteractiveDisplayIsEnabled) return; for(int i=0;iNumberOfSlicers(); i++) { - mImageContour[i]->update(m1); + mImageContour[i]->update(v); } mCurrentSlicerManager->Render(); } diff --git a/vv/vvToolBinarize.h b/vv/vvToolBinarize.h index 0453ad1..4b0721f 100644 --- a/vv/vvToolBinarize.h +++ b/vv/vvToolBinarize.h @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvToolBinarize.h,v $ Language: C++ - Date: $Date: 2010/03/01 07:37:25 $ - Version: $Revision: 1.7 $ + Date: $Date: 2010/03/05 10:32:33 $ + Version: $Revision: 1.8 $ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) Copyright (C) 2010 @@ -70,6 +70,7 @@ class vvToolBinarize: Ui::vvToolBinarize ui; args_info_clitkBinarizeImage mArgsInfo; std::vector mImageContour; + std::vector mImageContourLower; bool mInteractiveDisplayIsEnabled; }; // end class vvToolBinarize -- 2.47.1