diff --git a/Modules/Segmentation/Interactions/mitkWatershedTool.cpp b/Modules/Segmentation/Interactions/mitkWatershedTool.cpp index 63f2863a6d..33a3cbbedd 100644 --- a/Modules/Segmentation/Interactions/mitkWatershedTool.cpp +++ b/Modules/Segmentation/Interactions/mitkWatershedTool.cpp @@ -1,210 +1,203 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkWatershedTool.h" #include "mitkBinaryThresholdTool.xpm" #include "mitkToolManager.h" #include "mitkImageAccessByItk.h" #include "mitkImageCast.h" #include "mitkITKImageImport.h" #include "mitkRenderingManager.h" #include "mitkRenderingModeProperty.h" #include "mitkLookupTable.h" #include "mitkLookupTableProperty.h" #include "mitkIOUtil.h" #include "mitkLevelWindowManager.h" #include "mitkImageStatisticsHolder.h" #include "mitkToolCommand.h" #include "mitkProgressBar.h" #include #include #include #include #include #include #include #include namespace mitk { MITK_TOOL_MACRO(Segmentation_EXPORT, WatershedTool, "Watershed tool"); } mitk::WatershedTool::WatershedTool() : m_Level(0.), m_Threshold(0.) { } mitk::WatershedTool::~WatershedTool() { } void mitk::WatershedTool::Activated() { Superclass::Activated(); } void mitk::WatershedTool::Deactivated() { Superclass::Deactivated(); } us::ModuleResource mitk::WatershedTool::GetIconResource() const { us::Module* module = us::GetModuleContext()->GetModule(); us::ModuleResource resource = module->GetResource("Watershed_48x48.png"); return resource; } -us::ModuleResource mitk::WatershedTool::GetCursorIconResource() const -{ - us::Module* module = us::GetModuleContext()->GetModule(); - us::ModuleResource resource = module->GetResource("Watershed_Cursor_32x32.png"); - return resource; -} - const char** mitk::WatershedTool::GetXPM() const { return NULL; } const char* mitk::WatershedTool::GetName() const { return "Watershed"; } void mitk::WatershedTool::DoIt() { // get image from tool manager mitk::DataNode::Pointer referenceData = m_ToolManager->GetReferenceData(0); mitk::Image::Pointer input = dynamic_cast(referenceData->GetData()); mitk::Image::Pointer output; try { // create and run itk filter pipeline AccessFixedDimensionByItk_1(input.GetPointer(),ITKWatershed,3,output); // create a new datanode for output mitk::DataNode::Pointer dataNode = mitk::DataNode::New(); dataNode->SetData(output); // set properties of datanode dataNode->SetProperty("binary", mitk::BoolProperty::New(false)); dataNode->SetProperty("name", mitk::StringProperty::New("Watershed Result")); mitk::RenderingModeProperty::Pointer renderingMode = mitk::RenderingModeProperty::New(); renderingMode->SetValue( mitk::RenderingModeProperty::LOOKUPTABLE_LEVELWINDOW_COLOR ); dataNode->SetProperty("Image Rendering.Mode", renderingMode); // since we create a multi label image, define a vtk lookup table mitk::LookupTable::Pointer lut = mitk::LookupTable::New(); mitk::LookupTableProperty::Pointer prop = mitk::LookupTableProperty::New(lut); vtkLookupTable *lookupTable = vtkLookupTable::New(); lookupTable->SetHueRange(1.0, 0.0); lookupTable->SetSaturationRange(1.0, 1.0); lookupTable->SetValueRange(1.0, 1.0); lookupTable->SetTableRange(-1.0, 1.0); lookupTable->Build(); lookupTable->SetTableValue(1,0,0,0); lut->SetVtkLookupTable(lookupTable); prop->SetLookupTable(lut); dataNode->SetProperty("LookupTable",prop); // make the levelwindow fit to right values mitk::LevelWindowProperty::Pointer levWinProp = mitk::LevelWindowProperty::New(); mitk::LevelWindow levelwindow; levelwindow.SetRangeMinMax(0, output->GetStatistics()->GetScalarValueMax()); levWinProp->SetLevelWindow( levelwindow ); dataNode->SetProperty( "levelwindow", levWinProp ); dataNode->SetProperty( "opacity", mitk::FloatProperty::New(0.5)); // set name of data node std::string name = referenceData->GetName() + "_Watershed"; dataNode->SetName( name ); // look, if there is already a node with this name mitk::DataStorage::SetOfObjects::ConstPointer children = m_ToolManager->GetDataStorage()->GetDerivations(referenceData); mitk::DataStorage::SetOfObjects::ConstIterator currentNode = children->Begin(); mitk::DataNode::Pointer removeNode; while(currentNode != children->End()) { if(dataNode->GetName().compare(currentNode->Value()->GetName()) == 0) { removeNode = currentNode->Value(); } currentNode++; } // remove node with same name if(removeNode.IsNotNull()) m_ToolManager->GetDataStorage()->Remove(removeNode); // add output to the data storage m_ToolManager->GetDataStorage()->Add(dataNode,referenceData); } catch(itk::ExceptionObject& e) { MITK_ERROR<<"Watershed Filter Error: " << e.GetDescription(); } RenderingManager::GetInstance()->RequestUpdateAll(); } template void mitk::WatershedTool::ITKWatershed( itk::Image* originalImage, mitk::Image::Pointer& segmentation ) { typedef itk::WatershedImageFilter< itk::Image > WatershedFilter; typedef itk::GradientMagnitudeRecursiveGaussianImageFilter< itk::Image, itk::Image > MagnitudeFilter; // at first add a gradient magnitude filter typename MagnitudeFilter::Pointer magnitude = MagnitudeFilter::New(); magnitude->SetInput(originalImage); magnitude->SetSigma(1.0); // use the progress bar mitk::ToolCommand::Pointer command = mitk::ToolCommand::New(); - command->AddStepsToDo(10); + command->AddStepsToDo(60); // then add the watershed filter to the pipeline typename WatershedFilter::Pointer watershed = WatershedFilter::New(); watershed->SetInput(magnitude->GetOutput()); watershed->SetThreshold(m_Threshold); watershed->SetLevel(m_Level); watershed->AddObserver(itk::ProgressEvent(),command); watershed->Update(); // then make sure, that the output has the desired pixel type typedef itk::CastImageFilter > CastFilter; typename CastFilter::Pointer cast = CastFilter::New(); cast->SetInput(watershed->GetOutput()); // start the whole pipeline cast->Update(); // reset the progress bar by setting progress command->SetProgress(10); // since we obtain a new image from our pipeline, we have to make sure, that our mitk::Image::Pointer // is responsible for the memory management of the output image segmentation = mitk::GrabItkImageMemory(cast->GetOutput()); } diff --git a/Modules/Segmentation/Interactions/mitkWatershedTool.h b/Modules/Segmentation/Interactions/mitkWatershedTool.h index b8ed493439..65bd0839ec 100644 --- a/Modules/Segmentation/Interactions/mitkWatershedTool.h +++ b/Modules/Segmentation/Interactions/mitkWatershedTool.h @@ -1,94 +1,93 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef mitkWatershedTool_h_Included #define mitkWatershedTool_h_Included #include "mitkCommon.h" #include "SegmentationExports.h" #include "mitkAutoSegmentationTool.h" namespace us { class ModuleResource; } namespace mitk { class Image; /** \brief Simple watershed segmentation tool. \ingroup Interaction \ingroup ToolManagerEtAl Wraps ITK Watershed Filter into tool concept of MITK. For more information look into ITK documentation. \warning Only to be instantiated by mitk::ToolManager. $Darth Vader$ */ class Segmentation_EXPORT WatershedTool : public AutoSegmentationTool { public: mitkClassMacro(WatershedTool, AutoSegmentationTool); itkNewMacro(WatershedTool); void SetThreshold(double t) { m_Threshold = t; } void SetLevel(double l) { m_Level = l; } /** \brief Grabs the tool reference data and creates an ITK pipeline consisting of a GradientMagnitude * image filter followed by a Watershed image filter. The output of the filter pipeline is then added * to the data storage. */ void DoIt(); /** \brief Creates and runs an ITK filter pipeline consisting of the filters: GradientMagnitude-, Watershed- and CastImageFilter. * * \param originalImage The input image, which is delivered by the AccessByItk macro. * \param segmentation A pointer to the output image, which will point to the pipeline output after execution. */ template void ITKWatershed( itk::Image* originalImage, mitk::Image::Pointer& segmentation ); const char** GetXPM() const; const char* GetName() const; us::ModuleResource GetIconResource() const; - us::ModuleResource GetCursorIconResource() const; protected: WatershedTool(); // purposely hidden virtual ~WatershedTool(); virtual void Activated(); virtual void Deactivated(); /** \brief Threshold parameter of the ITK Watershed Image Filter. See ITK Documentation for more information. */ double m_Threshold; /** \brief Threshold parameter of the ITK Watershed Image Filter. See ITK Documentation for more information. */ double m_Level; }; } // namespace #endif diff --git a/Modules/SegmentationUI/Qmitk/QmitkWatershedToolGUI.cpp b/Modules/SegmentationUI/Qmitk/QmitkWatershedToolGUI.cpp index 10525fce0c..b060891efe 100644 --- a/Modules/SegmentationUI/Qmitk/QmitkWatershedToolGUI.cpp +++ b/Modules/SegmentationUI/Qmitk/QmitkWatershedToolGUI.cpp @@ -1,149 +1,156 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkWatershedToolGUI.h" #include "QmitkNewSegmentationDialog.h" +#include "mitkProgressBar.h" #include #include #include #include #include #include MITK_TOOL_GUI_MACRO(SegmentationUI_EXPORT, QmitkWatershedToolGUI, "") QmitkWatershedToolGUI::QmitkWatershedToolGUI() :QmitkToolGUI(), m_SliderThreshold(NULL), m_SliderLevel(NULL) { // create the visible widgets QGridLayout* layout = new QGridLayout( this ); this->setContentsMargins( 0, 0, 0, 0 ); QLabel* label = new QLabel( "Threshold ", this ); QFont f = label->font(); f.setBold(false); label->setFont( f ); layout->addWidget(label,0,0); QLabel* label2 = new QLabel( "Level ", this ); f = label2->font(); f.setBold(false); label2->setFont( f ); layout->addWidget(label2,2,0); - m_ThresholdLabel = new QLabel( " 0.5", this ); + m_ThresholdLabel = new QLabel( " 0.04", this ); f = m_ThresholdLabel->font(); f.setBold(false); m_ThresholdLabel->setFont( f ); layout->addWidget(m_ThresholdLabel,0,1); m_SliderThreshold = new QSlider( Qt::Horizontal, this ); m_SliderThreshold->setMinimum(0); m_SliderThreshold->setMaximum(100); m_SliderThreshold->setPageStep(1); - m_SliderThreshold->setValue(50); + m_SliderThreshold->setValue(4); connect( m_SliderThreshold, SIGNAL(valueChanged(int)), this, SLOT(OnSliderValueThresholdChanged(int))); layout->addWidget( m_SliderThreshold, 1, 0, 1, 2 ); - m_LevelLabel = new QLabel( " 0.5", this ); + m_LevelLabel = new QLabel( " 0.35", this ); f = m_LevelLabel->font(); f.setBold(false); m_LevelLabel->setFont( f ); layout->addWidget(m_LevelLabel,2,1); m_SliderLevel = new QSlider( Qt::Horizontal, this ); m_SliderLevel->setMinimum(0); m_SliderLevel->setMaximum(100); m_SliderLevel->setPageStep(1); - m_SliderLevel->setValue(50); + m_SliderLevel->setValue(35); connect( m_SliderLevel, SIGNAL(valueChanged(int)), this, SLOT(OnSliderValueLevelChanged(int))); layout->addWidget( m_SliderLevel, 3, 0, 1, 2 ); QPushButton* okButton = new QPushButton("Create Segmentation", this); connect( okButton, SIGNAL(clicked()), this, SLOT(OnCreateSegmentation())); okButton->setFont( f ); layout->addWidget( okButton, 4, 0, 1, 2 ); m_InformationLabel = new QLabel("", this); f = m_InformationLabel->font(); f.setBold(false); m_InformationLabel->setFont( f ); layout->addWidget( m_InformationLabel, 5,0,1,2); connect( this, SIGNAL(NewToolAssociated(mitk::Tool*)), this, SLOT(OnNewToolAssociated(mitk::Tool*)) ); } QmitkWatershedToolGUI::~QmitkWatershedToolGUI() { if (m_WatershedTool.IsNotNull()) { //m_WatershedTool->SizeChanged -= mitk::MessageDelegate1( this, &QmitkWatershedToolGUI::OnSizeChanged ); } } void QmitkWatershedToolGUI::OnNewToolAssociated(mitk::Tool* tool) { if (m_WatershedTool.IsNotNull()) { //m_WatershedTool->SizeChanged -= mitk::MessageDelegate1( this, &QmitkWatershedToolGUI::OnSizeChanged ); } m_WatershedTool = dynamic_cast( tool ); + OnSliderValueLevelChanged(35); + OnSliderValueThresholdChanged(4); if (m_WatershedTool.IsNotNull()) { // m_WatershedTool->SizeChanged += mitk::MessageDelegate1( this, &QmitkWatershedToolGUI::OnSizeChanged ); } } void QmitkWatershedToolGUI::OnSliderValueThresholdChanged(int value) { if (m_WatershedTool.IsNotNull()) { double realValue = value / 100.; m_WatershedTool->SetThreshold( realValue ); m_ThresholdLabel->setText(QString::number(realValue)); } } void QmitkWatershedToolGUI::OnSliderValueLevelChanged(int value) { if (m_WatershedTool.IsNotNull()) { double realValue = value / 100.; m_WatershedTool->SetLevel( realValue ); m_LevelLabel->setText(QString::number(realValue)); } } void QmitkWatershedToolGUI::OnCreateSegmentation() { - QCursor oldCursor = *QApplication::overrideCursor(); QApplication::setOverrideCursor(Qt::BusyCursor); m_InformationLabel->setText(QString("Please wait some time for computation...")); m_InformationLabel->repaint(); QApplication::processEvents(); m_WatershedTool->DoIt(); m_InformationLabel->setText(QString("")); - QApplication::setOverrideCursor(oldCursor); + QApplication::setOverrideCursor(Qt::ArrowCursor); + + for(int i=0; i<60; ++i) + { + mitk::ProgressBar::GetInstance()->Progress(); + } }