X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=vv%2FvvToolBinarize.cxx;h=fa22daad122e54bb2337d1feb1700f40bbd152e0;hb=488f24aa984ae24adc9458bf5fbf3b2351415742;hp=bccf02151d761b807c9240d93e4fb2a19f8873e4;hpb=0a85e47a06c7d046d06a4645b724c4e81b19998d;p=clitk.git
diff --git a/vv/vvToolBinarize.cxx b/vv/vvToolBinarize.cxx
index bccf021..fa22daa 100644
--- a/vv/vvToolBinarize.cxx
+++ b/vv/vvToolBinarize.cxx
@@ -1,40 +1,35 @@
/*=========================================================================
+ Program: vv http://www.creatis.insa-lyon.fr/rio/vv
- Program: vv
- Module: $RCSfile: vvToolBinarize.cxx,v $
- Language: C++
- Date: $Date: 2010/02/24 11:42:42 $
- Version: $Revision: 1.8 $
- Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr)
+ Authors belong to:
+ - University of LYON http://www.universite-lyon.fr/
+ - Léon Bérard cancer center http://www.centreleonberard.fr
+ - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
- Copyright (C) 2008
- Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
- CREATIS-LRMN http://www.creatis.insa-lyon.fr
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the copyright notices for more information.
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, version 3 of the License.
+ It is distributed under dual licence
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see .
-
- =========================================================================*/
+ - BSD See included LICENSE.txt file
+ - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+ ===========================================================================**/
+// vv
#include "vvToolBinarize.h"
#include "vvSlicerManager.h"
#include "vvSlicer.h"
#include "vvToolInputSelectorWidget.h"
+// clitk
#include "clitkBinarizeImageGenericFilter.h"
+// vtk
#include
#include
#include
+#include
//------------------------------------------------------------------------------
// Create the tool and automagically (I like this word) insert it in
@@ -44,10 +39,11 @@ ADD_TOOL(vvToolBinarize);
//------------------------------------------------------------------------------
-void vvToolBinarize::Initialize() {
+void vvToolBinarize::Initialize()
+{
SetToolName("Binarize");
SetToolMenuName("Binarize");
- SetToolIconFilename(":/new/prefix1/icons/binarize.png");
+ SetToolIconFilename(":/common/icons/binarize.png");
SetToolTip("Image interactive binarization with thresholds.");
}
//------------------------------------------------------------------------------
@@ -55,19 +51,19 @@ void vvToolBinarize::Initialize() {
//------------------------------------------------------------------------------
vvToolBinarize::vvToolBinarize(vvMainWindowBase * parent, Qt::WindowFlags f)
- :vvToolWidgetBase(parent,f),
- vvToolBase(parent),
- Ui::vvToolBinarize()
+ :vvToolWidgetBase(parent,f),
+ vvToolBase(parent),
+ Ui::vvToolBinarize()
{
// GUI Initialization
Ui_vvToolBinarize::setupUi(mToolWidget);
+ 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 signals & slots
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)));
+ connect(mCheckBoxInteractiveDisplay, SIGNAL(toggled(bool)), this, SLOT(InteractiveDisplayToggled(bool)));
// Initialize some widget
mThresholdSlider1->SetText("");
@@ -75,43 +71,119 @@ vvToolBinarize::vvToolBinarize(vvMainWindowBase * parent, Qt::WindowFlags f)
mFGSlider->SetText("Foreground value");
mBGSlider->SetText("Background value");
- // Main filter
- mFilter = new clitk::BinarizeImageGenericFilter; //DS PUT IN BASECLASS ?
+ // Main filter
+ mFilter = clitk::BinarizeImageGenericFilter::New();
+
+ // Set how many inputs are needed for this tool
+ AddInputSelector("Select one image", mFilter);
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+vvToolBinarize::~vvToolBinarize()
+{
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
-vvToolBinarize::~vvToolBinarize() {
+void vvToolBinarize::InteractiveDisplayToggled(bool b)
+{
+ mInteractiveDisplayIsEnabled = b;
+ if (!mInteractiveDisplayIsEnabled) {
+ RemoveVTKObjects();
+ } else {
+ for(unsigned int i=0; iShowActors();
+ if (mRadioButtonLowerThan->isChecked())
+ mImageContourLower[i]->ShowActors();
+ }
+ if (mCurrentSlicerManager)
+ mCurrentSlicerManager->Render();
+ }
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
-void vvToolBinarize::enableLowerThan(bool b) {
+void vvToolBinarize::RemoveVTKObjects()
+{
+ for(unsigned int i=0; iHideActors();
+ mImageContourLower[i]->HideActors();
+ }
+ if (mCurrentSlicerManager)
+ mCurrentSlicerManager->Render();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+bool vvToolBinarize::close()
+{
+ // RemoveVTKObjects();
+ return vvToolWidgetBase::close();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolBinarize::closeEvent(QCloseEvent *event) {
+ RemoveVTKObjects();
+ event->accept();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolBinarize::reject()
+{
+ // DD("vvToolBinarize::reject");
+ RemoveVTKObjects();
+ return vvToolWidgetBase::reject();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolBinarize::enableLowerThan(bool b)
+{
if (!b) {
mThresholdSlider1->resetMaximum();
- }
- else {
+ for(unsigned int i=0; iHideActors();
+ }
+ mCurrentSlicerManager->Render();
+ } else {
valueChangedT1(mThresholdSlider1->GetValue());
+ valueChangedT2(mThresholdSlider2->GetValue());
+ for(unsigned int i=0; iShowActors();
+ }
+ mCurrentSlicerManager->Render();
}
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
-void vvToolBinarize::useFGBGtoggled(bool) {
- if (!mCheckBoxUseBG->isChecked() && !mCheckBoxUseFG->isChecked())
+void vvToolBinarize::useFGBGtoggled(bool)
+{
+ if (!mCheckBoxUseBG->isChecked() && !mCheckBoxUseFG->isChecked())
mCheckBoxUseBG->toggle();
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
-void vvToolBinarize::InputIsSelected(vvSlicerManager * m) {
+// void vvToolBinarize::InputIsSelected(std::vector & m) {
+// DD("vvToolBinarize::InputIsSelected vector in binarize");
+// DD(m.size());
+// }
+void vvToolBinarize::InputIsSelected(vvSlicerManager * m)
+{
mCurrentSlicerManager = m;
- // Common
- mCurrentImage = mCurrentSlicerManager->GetImage();
// Specific for this gui
mThresholdSlider1->SetValue(0);
@@ -121,57 +193,103 @@ void vvToolBinarize::InputIsSelected(vvSlicerManager * m) {
mFGSlider->SetImage(mCurrentImage);
mBGSlider->SetImage(mCurrentImage);
// DD(mCurrentSlicerManager->GetFileName().c_str());
- mFGSlider->SetMaximum(mCurrentImage->GetFirstVTKImageData()->GetScalarTypeMax());
- mFGSlider->SetMinimum(mCurrentImage->GetFirstVTKImageData()->GetScalarTypeMin());
- mBGSlider->SetMaximum(mCurrentImage->GetFirstVTKImageData()->GetScalarTypeMax());
- mBGSlider->SetMinimum(mCurrentImage->GetFirstVTKImageData()->GetScalarTypeMin());
+ // mFGSlider->SetMaximum(mCurrentImage->GetFirstVTKImageData()->GetScalarTypeMax());
+ // mFGSlider->SetMinimum(mCurrentImage->GetFirstVTKImageData()->GetScalarTypeMin());
+ // mBGSlider->SetMaximum(mCurrentImage->GetFirstVTKImageData()->GetScalarTypeMax());
+ // mBGSlider->SetMinimum(mCurrentImage->GetFirstVTKImageData()->GetScalarTypeMin());
+
+ // Output is uchar ...
+ mFGSlider->SetMaximum(255);
+ mFGSlider->SetMinimum(0);
+ mBGSlider->SetMaximum(255);
+ mBGSlider->SetMinimum(0);
+
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));
+ for(int i=0; iGetNumberOfSlicers(); i++) {
+ mImageContour.push_back(vvImageContour::New());
+ mImageContour[i]->SetSlicer(mCurrentSlicerManager->GetSlicer(i));
+ mImageContour[i]->SetColor(1.0, 0.0, 0.0);
+ mImageContourLower.push_back(vvImageContour::New());
+ 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)));
+
+ connect(mCurrentSlicerManager,SIGNAL(UpdateOrientation(int,int)),this,SLOT(UpdateOrientation(int, int)));
+ // connect(mCurrentSlicerManager, SIGNAL(LeftButtonReleaseSignal(int)), SLOT(LeftButtonReleaseEvent(int)));
+
+ InteractiveDisplayToggled(mInteractiveDisplayIsEnabled);
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
-void vvToolBinarize::UpdateSlice(int slicer,int slices) {
+// void vvToolBinarize::LeftButtonReleaseEvent(int slicer) {
+// DD("LeftButtonReleaseEvent");
+// for(int i=0; iGetNumberOfSlicers(); i++) {
+// if (i == slicer);
+// mCurrentSlicerManager->GetSlicer(i)->GetRenderWindow()->Render();
+// }
+// }
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolBinarize::UpdateOrientation(int slicer,int orientation)
+{
+ Update(slicer);
+}
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+void vvToolBinarize::UpdateSlice(int slicer,int slices)
+{
+ Update(slicer);
+}
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+void vvToolBinarize::Update(int slicer)
+{
+ if (!mInteractiveDisplayIsEnabled) return;
if (!mCurrentSlicerManager) close();
- for(int i=0;iNumberOfSlicers(); i++) {
- mImageContour[i]->update(mThresholdSlider1->GetValue());
- }
- mCurrentSlicerManager->Render();
+ mImageContour[slicer]->Update(mThresholdSlider1->GetValue());
+ if (mRadioButtonLowerThan->isChecked())
+ mImageContourLower[slicer]->Update(mThresholdSlider2->GetValue());
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
-void vvToolBinarize::GetArgsInfoFromGUI() {
+void vvToolBinarize::GetArgsInfoFromGUI()
+{
/* //KEEP THIS FOR READING GGO FROM FILE
- int argc=1;
- std::string a = "toto";
- char * const* argv = new char*;
- //a.c_str();
- struct cmdline_parser_params p;
- p.check_required = 0;
- int good = cmdline_parser_ext(argc, argv, &args_info, &p);
- DD(good);
+ int argc=1;
+ std::string a = "toto";
+ char * const* argv = new char*;
+ //a.c_str();
+ struct cmdline_parser_params p;
+ p.check_required = 0;
+ int good = cmdline_parser_ext(argc, argv, &args_info, &p);
+ DD(good);
*/
-
- mArgsInfo.upper_given = 0;
- mArgsInfo.lower_given = 0;
+ cmdline_parser_clitkBinarizeImage_init(&mArgsInfo); // Initialisation to default
bool inverseBGandFG = false;
mArgsInfo.lower_given = 1;
mArgsInfo.lower_arg = mThresholdSlider1->GetValue();
- // DD(mArgsInfo.lower_arg);
if (mRadioButtonLowerThan->isChecked()) {
mArgsInfo.upper_given = 1;
mArgsInfo.upper_arg = mThresholdSlider2->GetValue();
@@ -184,7 +302,6 @@ void vvToolBinarize::GetArgsInfoFromGUI() {
mArgsInfo.fg_arg = mFGSlider->GetValue();
mArgsInfo.bg_arg = mBGSlider->GetValue();
- // DD(inverseBGandFG);
if (inverseBGandFG) {
mArgsInfo.fg_arg = mFGSlider->GetValue();
mArgsInfo.bg_arg = mBGSlider->GetValue();
@@ -195,60 +312,71 @@ void vvToolBinarize::GetArgsInfoFromGUI() {
if (mCheckBoxUseBG->isChecked()) {
if (mCheckBoxUseFG->isChecked()) mArgsInfo.mode_arg = (char*)"both";
else mArgsInfo.mode_arg = (char*)"BG";
- }
- else mArgsInfo.mode_arg = (char*)"FG";
+ } else mArgsInfo.mode_arg = (char*)"FG";
- mArgsInfo.verbose_flag = true;
+ mArgsInfo.verbose_flag = false;
- // Required (even if not used)
- mArgsInfo.input_given = 0;
- mArgsInfo.output_given = 0;
-
- mArgsInfo.input_arg = new char;
- mArgsInfo.output_arg = new char;
+ // // Required (even if not used)
+ // mArgsInfo.input_given = 0;
+ // mArgsInfo.output_given = 0;
+
+ // mArgsInfo.input_arg = new char;
+ // mArgsInfo.output_arg = new char;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
-void vvToolBinarize::apply() {
+void vvToolBinarize::apply()
+{
if (!mCurrentSlicerManager) close();
+ QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
GetArgsInfoFromGUI();
// Main filter
- clitk::BinarizeImageGenericFilter::Pointer filter =
- clitk::BinarizeImageGenericFilter::New();
- filter->SetArgsInfo(mArgsInfo);
+ clitk::BinarizeImageGenericFilter::Pointer filter =
+ clitk::BinarizeImageGenericFilter::New();
filter->SetInputVVImage(mCurrentImage);
+ filter->SetArgsInfo(mArgsInfo);
filter->Update();
- // Output ???
+ // Output
vvImage::Pointer output = filter->GetOutputVVImage();
std::ostringstream osstream;
- osstream << "Binarized_" << mCurrentSlicerManager->GetSlicer(0)->GetFileName();
- CREATOR(vvToolBinarize)->GetMainWindow()->AddImage(output,osstream.str());
+ osstream << "Binarized_" << mCurrentSlicerManager->GetSlicer(0)->GetFileName() << ".mhd";
+ AddImage(output,osstream.str());
+ QApplication::restoreOverrideCursor();
close();
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
-void vvToolBinarize::valueChangedT2(double v) {
- if (mRadioButtonLowerThan->isChecked()) mThresholdSlider1->SetMaximum(v);
+void vvToolBinarize::valueChangedT2(double v)
+{
+ // DD("valueChangedT2");
+ if (mRadioButtonLowerThan->isChecked()) {
+ mThresholdSlider1->SetMaximum(v);
+ if (!mInteractiveDisplayIsEnabled) return;
+ for(int i=0;iGetNumberOfSlicers(); i++) {
+ mImageContourLower[i]->Update(v);
+ }
+ mCurrentSlicerManager->Render();
+ }
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
-void vvToolBinarize::valueChangedT1(double v) {
- // DD(v);
+void vvToolBinarize::valueChangedT1(double v)
+{
+ // DD("valueChangedT1");
if (!mCurrentSlicerManager) close();
-// DD(mCurrentSlicerManager->GetSlicer(0));
mThresholdSlider2->SetMinimum(v);
- int m1 = (int)lrint(v);
-
- for(int i=0;iNumberOfSlicers(); i++) {
- mImageContour[i]->update(m1);
+ // int m1 = (int)lrint(v);
+ if (!mInteractiveDisplayIsEnabled) return;
+ for(int i=0;iGetNumberOfSlicers(); i++) {
+ mImageContour[i]->Update(v);
}
mCurrentSlicerManager->Render();
}