diff --git a/Modules/QmitkExt/QmitkFunctionalityComponents/CMakeLists.txt b/Modules/QmitkExt/QmitkFunctionalityComponents/CMakeLists.txt new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/Modules/QmitkExt/QmitkFunctionalityComponents/CMakeLists.txt @@ -0,0 +1 @@ + diff --git a/Modules/QmitkExt/QmitkFunctionalityComponents/QmitkThresholdComponent.cpp b/Modules/QmitkExt/QmitkFunctionalityComponents/QmitkThresholdComponent.cpp new file mode 100644 index 0000000000..e6bd194f93 --- /dev/null +++ b/Modules/QmitkExt/QmitkFunctionalityComponents/QmitkThresholdComponent.cpp @@ -0,0 +1,553 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date$ +Version: $Revision$ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "QmitkThresholdComponent.h" +#include "ui_QmitkThresholdComponentControls.h" + + +#include +#include + +#include "mitkRenderingManager.h" +#include "mitkProperties.h" +#include "mitkDataTreeFilterFunctions.h" +#include "mitkDataTreeNodeFactory.h" +#include "mitkLevelWindowProperty.h" + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + + +/*************** CONSTRUCTOR ***************/ +QmitkThresholdComponent::QmitkThresholdComponent(QObject * parent, const char * parentName, bool updateSelector, bool showSelector, QmitkStdMultiWidget * /*mitkStdMultiWidget*/, mitk::DataTreeIteratorBase* it) +: QmitkFunctionalityComponentContainer(parent, parentName, updateSelector, showSelector), +m_ThresholdImageNode(NULL), +m_ThresholdComponentGUI(NULL), +m_ThresholdNodeExisting(false) +{ + SetAvailability(true); + + SetComponentName("ThresholdFinder"); + m_Node = this->GetDefaultDataStorage()->GetNode(); +} + +/*************** DESTRUCTOR ***************/ +QmitkThresholdComponent::~QmitkThresholdComponent() +{ + +} + + +/************** SET SELECTOR VISIBILITY ***************/ +void QmitkThresholdComponent::SetSelectorVisibility(bool visibility) +{ + if(m_ThresholdComponentGUI) + { + m_ThresholdComponentGUI->m_ThresholdSelectDataGroupBox->setShown(visibility); + } +} + +/*************** GET IMAGE CONTENT ***************/ +QGroupBox* QmitkThresholdComponent::GetImageContent() +{ + return (QGroupBox*) m_ThresholdComponentGUI->m_ImageContent; +} + + +/*************** GET TREE NODE SELECTOR ***************/ +QmitkDataStorageComboBox* QmitkThresholdComponent::GetTreeNodeSelector() +{ + return m_ThresholdComponentGUI->m_TreeNodeSelector; +} + +/*************** CONNECTIONS ***************/ +void QmitkThresholdComponent::CreateConnections() +{ + if ( m_ThresholdComponentGUI ) + { + connect( (QObject*)(m_ThresholdComponentGUI->m_TreeNodeSelector), SIGNAL(activated(const mitk::DataTreeFilter::Item *)), (QObject*) this, SLOT(ImageSelected(const mitk::DataTreeFilter::Item *))); + connect( (QObject*)(m_ThresholdComponentGUI->m_ThresholdFinder), SIGNAL(toggled(bool)), (QObject*) this, SLOT(ShowThresholdFinderContent(bool))); + connect( (QObject*)(m_ThresholdComponentGUI->m_ThresholdSelectDataGroupBox), SIGNAL(toggled(bool)), (QObject*) this, SLOT(ShowImageContent(bool))); + + connect( (QObject*)(m_ThresholdComponentGUI->m_ThresholdInputSlider), SIGNAL(sliderMoved(int)), (QObject*) this, SLOT(ThresholdSliderChanged(int))); + connect( (QObject*)(m_ThresholdComponentGUI->m_ThresholdInputNumber), SIGNAL(returnPressed()), (QObject*) this, SLOT(ThresholdValueChanged())); + //connect( (QObject*)(m_ThresholdComponentGUI->m_ShowThresholdGroupBox), SIGNAL(toggled(bool)), (QObject*) this, SLOT(ShowThreshold(bool))); + + //to connect the toplevel checkable GroupBox with the method SetContentContainerVisibility to inform all containing komponent to shrink or to expand + connect( (QObject*)(m_ThresholdComponentGUI->m_ThresholdFinder), SIGNAL(toggled(bool)), (QObject*) this, SLOT(SetContentContainerVisibility(bool))); + connect( (QObject*)(m_ThresholdComponentGUI->m_CreateSegmentationButton), SIGNAL(pressed()), (QObject*) this, SLOT(CreateThresholdSegmentation())); + } +} + + +/*************** IMAGE SELECTED ***************/ +void QmitkThresholdComponent::ImageSelected(mitk::DataTreeNode::Pointer item) +{ + if(m_ThresholdComponentGUI != NULL) + { + for(unsigned int i = 0; i < m_AddedChildList.size(); i++) + { + QmitkBaseFunctionalityComponent* functionalityComponent = dynamic_cast(m_AddedChildList[i]); + if (functionalityComponent != NULL) + functionalityComponent->ImageSelected(item); + } + } + m_Node = item; + DataObjectSelected(); + SetSliderRange(); + ShowThreshold(); +} + +/*************** DATA OBJECT SELECTED **************/ +void QmitkThresholdComponent::DataObjectSelected() +{ + if(m_Active) + { + if(m_ThresholdNodeExisting) + { + m_ThresholdImageNode->SetData(m_Node->GetData()); + } + else + { + CreateThresholdImageNode(); + m_ThresholdImageNode->SetData(m_Node->GetData()); + } + ShowThreshold(); + } +} + +/** \brief Method to set the DataStorage*/ +void QmitkThresholdComponent::SetDataStorage(mitk::DataStorage::Pointer dataStorage) +{ + m_DataStorage = dataStorage; +} + +/** \brief Method to get the DataStorage*/ +mitk::DataStorage::Pointer QmitkThresholdComponent::GetDataStorage() +{ + return m_DataStorage; +} + +/*************** CREATE CONTAINER WIDGET **************/ +void QmitkThresholdComponent::CreateQtPartControl(QWidget *parent, mitk::DataStorage::Pointer dataStorage) +{ + m_GUI = new QWidget; + m_ThresholdComponentGUI = new Ui::QmitkThresholdComponentControls; + m_ThresholdComponentGUI->setupUi(m_GUI); + this->CreateConnections(); + + SetDataStorage(dataStorage); + + m_ThresholdComponentGUI->m_TreeNodeSelector->SetDataStorage(dataStorage); + m_ThresholdComponentGUI->m_TreeNodeSelector->SetPredicate(mitk::NodePredicateDataType::New("Image")); +// m_GUI = m_ThresholdComponentGUI; + + // m_ThresholdComponentGUI->m_TreeNodeSelector->SetDataTree(GetDataTreeIterator()); + + if(m_ShowSelector) + { + m_ThresholdComponentGUI->m_ImageContent->setShown(m_ThresholdComponentGUI->m_ThresholdSelectDataGroupBox->isChecked()); + } + else + { + m_ThresholdComponentGUI->m_ThresholdSelectDataGroupBox->setShown(m_ShowSelector); + } + + //m_ThresholdComponentGUI->m_TreeNodeSelector->GetFilter()->SetFilter(mitk::IsBaseDataTypeWithoutProperty("isComponentThresholdImage")); + +} + +/*************** GET CONTENT CONTAINER ***************/ +QGroupBox * QmitkThresholdComponent::GetContentContainer() +{ + return m_ThresholdComponentGUI->m_ContainerContent; +} + +/************ GET MAIN CHECK BOX CONTAINER ************/ +QGroupBox * QmitkThresholdComponent::GetMainCheckBoxContainer() +{ + return m_ThresholdComponentGUI->m_ThresholdFinder; +} + +///*********** SET CONTENT CONTAINER VISIBLE ************/ +//void QmitkThresholdComponent::SetContentContainerVisibility() +//{ +// for(unsigned int i = 0; i < m_AddedChildList.size(); i++) +// { +// if(m_AddedChildList[i]->GetContentContainer() != NULL) +// { +// m_AddedChildList[i]->GetContentContainer()->setShown(GetMainCheckBoxContainer()->isChecked()); +// } +// } +//} + +/*************** ACTIVATED ***************/ +void QmitkThresholdComponent::Activated() +{ + QmitkBaseFunctionalityComponent::Activated(); + m_Active = true; + for(unsigned int i = 0; i < m_AddedChildList.size(); i++) + { + m_AddedChildList[i]->Activated(); + } + CreateThresholdImageNode(); + ShowThreshold(); + SetSliderRange(); +} + +/*************** DEACTIVATED ***************/ +void QmitkThresholdComponent::Deactivated() +{ + QmitkBaseFunctionalityComponent::Deactivated(); + m_Active = false; + for(unsigned int i = 0; i < m_AddedChildList.size(); i++) + { + m_AddedChildList[i]->Deactivated(); + } + ShowThreshold(); + if(m_ThresholdComponentGUI->m_DeleateImageIfDeactivatedCheckBox->isChecked()) + { + DeleteThresholdNode(); + } +} + +///************ SHOW THRESHOLD FINDER CONTENT ***********/ +void QmitkThresholdComponent::ShowThresholdFinderContent(bool) +{ + //m_ThresholdComponentGUI->m_ShowThresholdGroupBox->setShown(m_ThresholdComponentGUI->m_ThresholdFinder->isChecked()); + m_ThresholdComponentGUI->m_ContainerContent->setShown(m_ThresholdComponentGUI->m_ThresholdFinder->isChecked()); + + + if(m_ShowSelector) + { + m_ThresholdComponentGUI->m_ThresholdSelectDataGroupBox->setShown(m_ThresholdComponentGUI->m_ThresholdFinder->isChecked()); + } + + //ShowThreshold(); +} + +///*************** SHOW IMAGE CONTENT **************/ +void QmitkThresholdComponent::ShowImageContent(bool) +{ + m_ThresholdComponentGUI->m_ImageContent->setShown(m_ThresholdComponentGUI->m_ThresholdSelectDataGroupBox->isChecked()); + + if(m_ShowSelector) + { + m_ThresholdComponentGUI->m_ImageContent->setShown(m_ThresholdComponentGUI->m_ThresholdSelectDataGroupBox->isChecked()); + } + else + { + m_ThresholdComponentGUI->m_ThresholdSelectDataGroupBox->setShown(m_ShowSelector); + } +} + +///*************** SHOW THRESHOLD **************/ +void QmitkThresholdComponent::ShowThreshold(bool) +{ + if(m_ThresholdImageNode) + { + if(m_Active == true) + { + m_ThresholdImageNode->SetProperty("visible", mitk::BoolProperty::New((m_ThresholdComponentGUI->m_ThresholdFinder->isChecked())) ); + } + else + { + if(m_ThresholdComponentGUI->m_DeleateImageIfDeactivatedCheckBox->isChecked()) + { + m_ThresholdImageNode->SetProperty("visible", mitk::BoolProperty::New((false)) ); + } + } + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + } +} + +///*************** THRESHOLD VALUE CHANGED **************/ +//By Slider +void QmitkThresholdComponent::ThresholdSliderChanged(int) +{ + int value = m_ThresholdComponentGUI->m_ThresholdInputSlider->value(); + if (m_ThresholdImageNode) + { + m_ThresholdImageNode->SetLevelWindow(mitk::LevelWindow(value,1)); + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + } + m_ThresholdComponentGUI->m_ThresholdInputNumber->setText(QString::number(value)); +} + +///*************** THRESHOLD VALUE CHANGED **************/ +//By LineEdit +void QmitkThresholdComponent::ThresholdValueChanged( ) +{ + int value = atoi(m_ThresholdComponentGUI->m_ThresholdInputNumber->text()); + if (m_ThresholdImageNode) + { + m_ThresholdImageNode->SetLevelWindow(mitk::LevelWindow(value,1)); + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + } + m_ThresholdComponentGUI->m_ThresholdInputSlider->setValue(value); +} + + +///*************** SET SLIDER RANGE **************/ +void QmitkThresholdComponent::SetSliderRange() +{ + if(m_Active) + { + if(m_ThresholdComponentGUI->m_ThresholdFinder->isChecked()==true) + { + mitk::Image* currentImage = dynamic_cast(m_ThresholdImageNode->GetData()); + if(currentImage) + { + int min = (int) currentImage->GetScalarValueMin(); + int max = (int) currentImage->GetScalarValueMaxNoRecompute(); + //int realMax = currentImage->GetScalarValueMax(); + if(min < -32000) + { + min = (int) currentImage->GetScalarValue2ndMin(); + max = (int) currentImage->GetScalarValue2ndMaxNoRecompute(); + } + m_ThresholdComponentGUI->m_ThresholdInputSlider->setMinValue(min); + m_ThresholdComponentGUI->m_ThresholdInputSlider->setMaxValue(max); + /*m_ThresholdComponentGUI->m_ThresholdInputSlider->setMinValue((int)currentImage->GetScalarValueMin()); + m_ThresholdComponentGUI->m_ThresholdInputSlider->setMaxValue((int)currentImage->GetScalarValueMaxNoRecompute());*/ + } + } + } +} + +///*************** DELETE THRESHOLD NODE **************/ +void QmitkThresholdComponent::DeleteThresholdNode() +{ + if(m_ThresholdImageNode) + { + + mitk::DataTreeNode::Pointer foundNode = GetDefaultDataStorage()->GetNamedNode("Thresholdview image"); + foundNode->Delete(); + + + m_ThresholdNodeExisting = false; + return; + } +} + ///*************CREATE THRESHOLD IMAGE NODE************/ + void QmitkThresholdComponent::CreateThresholdImageNode() + { + if(m_Active) + { + if(!m_ThresholdNodeExisting) + { + if (m_Node) + { + m_ThresholdImageNode = mitk::DataTreeNode::New(); + mitk::StringProperty::Pointer nameProp = mitk::StringProperty::New("Thresholdview image" ); + m_ThresholdImageNode->SetProperty( "name", nameProp ); + mitk::BoolProperty::Pointer componentThresholdImageProp = mitk::BoolProperty::New(true); + m_ThresholdImageNode->SetProperty( "isComponentThresholdImage", componentThresholdImageProp ); + + m_ThresholdImageNode->SetData(m_Node->GetData()); + m_ThresholdImageNode->SetColor(0.0,1.0,0.0); + m_ThresholdImageNode->SetOpacity(.25); + int layer = 0; + m_Node->GetIntProperty("layer", layer); + m_ThresholdImageNode->SetIntProperty("layer", layer+1); + m_ThresholdImageNode->SetLevelWindow(mitk::LevelWindow(atoi(m_ThresholdComponentGUI->m_ThresholdInputNumber->text()),1)); + + GetDefaultDataStorage()->Add(m_ThresholdImageNode); + m_ThresholdNodeExisting = true; + + } + } + } + } + + /*************CREAET THRESHOLD SEGMENTATION************/ + void QmitkThresholdComponent::CreateThresholdSegmentation() + { + + //mitk::DataTreeNode::Pointer segmentationNode = m_Controls->m_ToolDataSelectionBox->GetToolManager()->GetReferenceData(0); + mitk::DataTreeNode::Pointer segmentationNode = mitk::DataTreeNode::New(); + segmentationNode->SetData(m_Node->GetData()); + m_MitkImage = dynamic_cast(m_Node->GetData()); + if + (segmentationNode.IsNotNull()) + { + mitk::StringProperty::Pointer nameProp = mitk::StringProperty::New("TH segmentation" ); + segmentationNode->SetProperty( "name", nameProp ); + segmentationNode->GetPropertyList()->SetProperty("binary", mitk::BoolProperty::New(true)); + mitk::BoolProperty::Pointer thresholdBasedSegmentationProp = mitk::BoolProperty::New(true); + segmentationNode->SetProperty( "segmentation", thresholdBasedSegmentationProp ); + segmentationNode->GetPropertyList()->SetProperty("layer",mitk::IntProperty::New(1)); + segmentationNode->SetColor(1.0,0.0,0.0); + segmentationNode->SetOpacity(.25); + + mitk::Image::Pointer image = dynamic_cast( segmentationNode->GetData() ); + if (image.IsNotNull()) + { + + + // ask the user about an organ type and name, add this information to the image's (!) propertylist + + // create a new image of the same dimensions and smallest possible pixel type + AccessFixedDimensionByItk_2(m_MitkImage, /*the actual selected image */ + ThresholdSegmentation, /*called template-method */ + 3, /*dimension */ + image, /*passed segmentation */ + this /* the QmitkSurfaceCreator-object */); + + + //mitk::DataTreeNode::Pointer segmentation = CreateEmptySegmentationNode(image); + if (!m_ThresholdSegmentationImage) return; // could be aborted by user + + + segmentationNode->SetData(m_ThresholdSegmentationImage); + + mitk::DataTreeNode::Pointer origNode = m_ThresholdComponentGUI->m_TreeNodeSelector->GetSelectedNode(); + GetDefaultDataStorage()->Add(segmentationNode, origNode); + + //mitk::DataTreeIteratorClone iteratorClone = m_DataTreeIterator; + //iteratorClone->GoToBegin(); + //while ( !iteratorClone->IsAtEnd() ) + //{ + // mitk::DataTreeNode::Pointer node = iteratorClone->Get(); + // if ( node == m_Node ) + // { + // iteratorClone->Add(segmentationNode); + // } + // ++iteratorClone; + + //} + } + } + + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + } + + mitk::DataTreeNode::Pointer QmitkThresholdComponent::CreateEmptySegmentationNode( mitk::Image* image) + { + //if (!image) return NULL; + //// actually create a new empty segmentation + //mitk::PixelType pixelType( typeid(short int) ); + //mitk::Image::Pointer segmentation = mitk::Image::New(); + //segmentation->Initialize( pixelType, image->GetDimension(), image->GetDimensions() ); + //memset( segmentation->GetData(), 0, sizeof(short int) * segmentation->GetDimension(0) * segmentation->GetDimension(1) * segmentation->GetDimension(2) ); + + //if (image->GetGeometry() ) + //{ + // mitk::AffineGeometryFrame3D::Pointer originalGeometryAGF = image->GetGeometry()->Clone(); + // mitk::Geometry3D::Pointer originalGeometry = dynamic_cast( originalGeometryAGF.GetPointer() ); + // segmentation->SetGeometry( originalGeometry ); + //} + + return CreateSegmentationNode(image); + } + + mitk::DataTreeNode::Pointer QmitkThresholdComponent::CreateSegmentationNode( + mitk::Image* image) + { + if (!image) return NULL; + + // decorate the datatreenode with some properties + mitk::DataTreeNode::Pointer segmentationNode = mitk::DataTreeNode::New(); + segmentationNode->SetData( image ); + + // visualization properties + + segmentationNode->SetProperty( "binary", mitk::BoolProperty::New(true) ); + segmentationNode->SetProperty( "layer", mitk::IntProperty::New(10) ); + segmentationNode->SetProperty( "segmentation", mitk::BoolProperty::New(true) ); + segmentationNode->SetProperty( "opacity", mitk::FloatProperty::New(0.3) ); + + segmentationNode->SetProperty( "levelwindow", mitk::LevelWindowProperty::New( mitk::LevelWindow(0, 1) ) ); + segmentationNode->SetProperty( "color", mitk::ColorProperty::New(0.0, 1.0, 0.0) ); + + return segmentationNode; + } + + //*************************************TEMPLATE FOR THRESHOLDSEGMENTATION****************************** + // + // to create a new segmentation that contains those areas above the threshold + // called from NewThresholdSegmentation + + template < typename TPixel, unsigned int VImageDimension > + void QmitkThresholdComponent::ThresholdSegmentation(itk::Image< TPixel, VImageDimension >* itkImage, mitk::Image* segmentation, QmitkThresholdComponent * /*thresholdComponent*/) + { + // iterator on m_MitkImage + typedef itk::Image< TPixel, VImageDimension > ItkImageType; + itk::ImageRegionConstIterator itMitkImage(itkImage, itkImage->GetLargestPossibleRegion() ); + + // pointer on segmentation + typedef itk::Image< unsigned char, VImageDimension > ItkSegmentationImageType; + typename ItkSegmentationImageType::Pointer itkSegmentation; + + // cast segmentation from mitk-image to itk-image + if(segmentation != NULL) + { + mitk::CastToItkImage(segmentation, itkSegmentation); + } + + // new pointer on segmentation: itkThresholdSegmentedImage + typename ItkSegmentationImageType::Pointer itkThresholdSegmentedImage = ItkSegmentationImageType::New(); + + // properties for itkThresholdSegmentedImage: + itkThresholdSegmentedImage->SetRegions(itkImage->GetLargestPossibleRegion()); + itkThresholdSegmentedImage->Allocate(); + + // iterator on itkThresholdSegmentedImage: itSegmented + itk::ImageRegionIterator itSegmented(itkThresholdSegmentedImage, itkThresholdSegmentedImage->GetLargestPossibleRegion() ); + + + int thresholdValue(0);//Threshold above that the segmentation shall be created + + // threshold-input from GUI: + thresholdValue = atoi(m_ThresholdComponentGUI->m_ThresholdInputNumber->text()); + + while(!(itMitkImage.IsAtEnd())) + { + if((signed)itMitkImage.Get() >= thresholdValue) + //if the pixel-value of the m_Mitk-Image is higher or equals the threshold + { + itSegmented.Set(1); + // set the pixel-value at the segmentation to "1" + } + else + { + itSegmented.Set(0); + // else set the pixel-value at the segmentation to "0" + } + ++itMitkImage; + ++itSegmented; + //TODO: die Segmentierung aus der Methode returnen + }//end of while (!(itMitkImage.IsAtEnd())) + + // create new mitk-Image: m_ThresholdSegmentationImage + m_ThresholdSegmentationImage = mitk::Image::New(); + + // fill m_ThresholdSegmentationImage with itkThresholdSegmentedImage: + mitk::CastToMitkImage(itkThresholdSegmentedImage, m_ThresholdSegmentationImage); + + } + + + diff --git a/Modules/QmitkExt/QmitkFunctionalityComponents/QmitkThresholdComponent.h b/Modules/QmitkExt/QmitkFunctionalityComponents/QmitkThresholdComponent.h new file mode 100644 index 0000000000..838dca5d2c --- /dev/null +++ b/Modules/QmitkExt/QmitkFunctionalityComponents/QmitkThresholdComponent.h @@ -0,0 +1,188 @@ + + +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date$ +Version: $Revision$ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef MITK_THRESHOLDCOMPONENT_H +#define MITK_THRESHOLDCOMPONENT_H + +#include "QmitkFunctionalityComponentContainer.h" +#include +#include "ui_QmitkThresholdComponentControls.h" +class QmitkStdMultiWidget; + +/** +* \brief ComponentClass to find an adequate threshold for a selected image +* \ingroup QmitkFunctionalityComponent +* +* This class inherits from +* - \ref QmitkFunctionalityComponentContainer + +* +* \section QmitkThresholdComponent Overview +* +* The ThresholdComponent is a class to easy find an adequate threshold. On two ways the user can insert +* a possible threshold: as a number in a textfield or by moving a scrollbar. The selected threshold will +* be shown on the image as an new binary layer that contains those areas above the theshold. +* Like all other componentes the QmitkThresholdComponent inherits from QmitkFunctionalityComponentContainer. +* +*/ + + +class QMITKEXT_EXPORT QmitkThresholdComponent : public QmitkFunctionalityComponentContainer +{ + + Q_OBJECT + +public: + /*************** CONSTRUCTOR ***************/ + /** \brief Constructor. */ + QmitkThresholdComponent(QObject *parent=0, const char *parentName=0, bool updateSelector = true, bool showSelector = true, QmitkStdMultiWidget *mitkStdMultiWidget = NULL, mitk::DataTreeIteratorBase* dataIt = NULL); + + /*************** DESTRUCTOR ***************/ + /** \brief Destructor. */ + virtual ~QmitkThresholdComponent(); + + /*************** CREATE ***************/ + + /** \brief Method to create the GUI for the component from the .ui-File. This Method is obligatory */ + void CreateQtPartControl(QWidget *parent, mitk::DataStorage::Pointer dataStorage); + + /** \brief Method to create the connections for the component. This Method is obligatory even if no connections is needed*/ + virtual void CreateConnections(); + + + /*************** SET AND GET ***************/ + + /** \brief Method to set the Image Selector visible or invisible */ + virtual void SetSelectorVisibility(bool visibility); + + /** \brief Method to return the TreeNodeSelector-QmitkDataStorageComboBox */ + virtual QmitkDataStorageComboBox* GetTreeNodeSelector(); + + /** \brief Method to set the DataStorage*/ + virtual void SetDataStorage(mitk::DataStorage::Pointer dataStorage); + + /** \brief Method to get the DataStorage*/ + virtual mitk::DataStorage::Pointer GetDataStorage(); + + /** \brief Method to return the ComboBox that includes all GUI-elements instead of the outermost checkable CheckBox and that can be set visible or not*/ + virtual QGroupBox * GetContentContainer(); + + /** \brief Method to return the outermost checkable ComboBox that is to decide whether the content shall be shown or not */ + virtual QGroupBox * GetMainCheckBoxContainer(); + +/** \brief Method to return the group-box that contains the tree-node-selector */ +virtual QGroupBox* GetImageContent(); + + /*************** (DE)ACTIVATED ***************/ + + ///** \brief Method to set m_Activated to true */ + virtual void Activated(); + + ///** \brief Method to set m_Activated to false */ + virtual void Deactivated(); + +public slots: + /*************** OHTER METHODS ***************/ + + /** \brief Slot method that will be called if TreeNodeSelector widget was activated to select the current image. */ + void ImageSelected(const mitk::DataTreeNode::Pointer item); + + /** \brief Slot method that will be called if the CheckBox at the Threshold-Group-Box was toggled to show the threshold image or not. */ + void ShowThreshold(bool show = true); + + /** \brief Slot method that will be called if the CheckBox at the Threshold-Group-Box was toggled to show the threshold image or not. */ + void ShowThresholdFinderContent(bool show = true); + + /** \brief Slot method that will be called if the CheckBox at the TreeNodeSelector-Group-Box was toggled to show the TreeNodeSelector or not. */ + void ShowImageContent(bool show = true); + + /** \brief Slot method that will be called if the Thresholdslider was moved to update the shown image and the ThresholdLineEdit. */ + void ThresholdSliderChanged(int moved = 0); + + /** \brief Slot method that will be called if the ThresholdLineEdit was changed to update the shown image and the ThresholdSlider. */ + void ThresholdValueChanged( ); + + /** \brief Slot method that will be called if the "Create Segmentation"-Button was pressed to create a new segmentation image. Everything over the threshold will have the value 1, all other 0. */ + void CreateThresholdSegmentation(); + + +protected: + + /*! + Method to create a new Segmentation + */ + mitk::DataTreeNode::Pointer CreateEmptySegmentationNode( mitk::Image* image); + + /*! + Method to create the node for the thresholdbased segmentation + */ + mitk::DataTreeNode::Pointer CreateSegmentationNode( mitk::Image* image); + + /** \brief Method that controls everything what happend after an image was selected */ + void DataObjectSelected(); + + /*************** ATTRIBUTES ***************/ + + /** \brief Item on the actual selected Image in the TreeNodeSelector */ + mitk::DataStorage::Pointer m_DataStorage; + + /*! + a reference to the current ImageNode + */ + mitk::DataTreeNode::Pointer m_Node; + + /*! + a reference to the node with the thresholdImage and adjusted preferences to show the threshold + */ + mitk::DataTreeNode::Pointer m_ThresholdImageNode; + + +private: + + /** \brief Method to create an Node that will hold the ThresholdImage and to set that preferences*/ + void CreateThresholdImageNode(); + + /** \brief Method to set the Range of the ThresholdSlider*/ + void SetSliderRange(); + + /** \brief Method to to delete ThresholdNode if Component is deactivated*/ + void DeleteThresholdNode(); + + /*! + \brief template to create thresholdSegmentation + */ + template < typename TPixel, unsigned int VImageDimension > + void ThresholdSegmentation(itk::Image< TPixel, VImageDimension >* itkImage, mitk::Image* segmentation, QmitkThresholdComponent * /*thresholdComponent*/); + + /*************** ATTRIBUTES ***************/ + + /** \brief The created GUI from the .ui-File. This Attribute is obligatory*/ + Ui::QmitkThresholdComponentControls * m_ThresholdComponentGUI; + + /** \brief This Attribute holds the information if a thresholdnode is already existing or not*/ + bool m_ThresholdNodeExisting; + + /*! + * Segmentation made with thresholdSegmentation + */ + mitk::Image::Pointer m_ThresholdSegmentationImage; + +}; + +#endif + diff --git a/Modules/QmitkExt/QmitkFunctionalityComponents/QmitkThresholdComponentGUI.ui.h b/Modules/QmitkExt/QmitkFunctionalityComponents/QmitkThresholdComponentGUI.ui.h new file mode 100644 index 0000000000..faf0631b48 --- /dev/null +++ b/Modules/QmitkExt/QmitkFunctionalityComponents/QmitkThresholdComponentGUI.ui.h @@ -0,0 +1,113 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date$ +Version: $Revision$ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +/**************************************************************************** +** ui.h extension file, included from the uic-generated form implementation. +** +** If you want to add, delete, or rename functions or slots, use +** Qt Designer to update this file, preserving your code. +** +** You should not define a constructor or destructor in this file. +** Instead, write your code in functions called init() and destroy(). +** These will automatically be called by the form's constructor and +** destructor. +*****************************************************************************/ + +#include "QmitkTreeNodeSelector.h" + + + +void QmitkThresholdComponentGUI::SetDataTreeIterator( mitk::DataTreeIteratorBase * it ) +{ + m_DataTreeIterator = it; +//TODO m_TreeNodeSelector->SetDataTreeNodeIterator(it); + //m_VolumetryWidget->SetDataTreeNodeIterator(it); +} + + + + +QmitkDataTreeComboBox * QmitkThresholdComponentGUI::GetTreeNodeSelector() +{ + return m_TreeNodeSelector; +} + +int QmitkThresholdComponentGUI::GetSliderValue() +{ + int value = m_ThresholdInputSlider->value(); + return value; +} + +int QmitkThresholdComponentGUI::GetNumberValue() +{ + int value = atoi(m_ThresholdInputNumber->text()); + return value; +} + +QSlider* QmitkThresholdComponentGUI::GetThresholdInputSlider() +{ +return m_ThresholdInputSlider; +} + +QLineEdit* QmitkThresholdComponentGUI::GetThresholdInputNumber() +{ +return m_ThresholdInputNumber; +} + + +QGroupBox* QmitkThresholdComponentGUI::GetShowThresholdGroupBox() +{ + return m_ShowThresholdGroupBox; +} + +QGroupBox* QmitkThresholdComponentGUI::GetThresholdFinderGroupBox() +{ + return m_ThresholdFinder; +} + +QGroupBox* QmitkThresholdComponentGUI::GetSelectDataGroupBox() +{ + return m_ThresholdSelectDataGroupBox; +} + +QGroupBox* QmitkThresholdComponentGUI::GetThresholdValueContent() +{ + return m_ThresholdValueContent; +} + +QGroupBox* QmitkThresholdComponentGUI::GetImageContent() +{ + return m_ImageContent; +} + + +QCheckBox* QmitkThresholdComponentGUI::GetDeleteImageIfDeactivatedCheckBox() +{ + return m_DeleateImageIfDeactivatedCheckBox; +} + + +QGroupBox* QmitkThresholdComponentGUI::GetContainerContent() +{ + return m_ContainerContent; +} + + +QPushButton* QmitkThresholdComponentGUI::GetCreateSegmentationButton() +{ + return m_CreateSegmentationButton; +}