diff --git a/Modules/ImageStatisticsUI/Qmitk/QmitkImageStatisticsWidget.h b/Modules/ImageStatisticsUI/Qmitk/QmitkImageStatisticsWidget.h index a68d225fe0..e7b43fba27 100644 --- a/Modules/ImageStatisticsUI/Qmitk/QmitkImageStatisticsWidget.h +++ b/Modules/ImageStatisticsUI/Qmitk/QmitkImageStatisticsWidget.h @@ -1,51 +1,51 @@ /*=================================================================== 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 QmitkImageStatisticsWidget_H__INCLUDED #define QmitkImageStatisticsWidget_H__INCLUDED #include <mitkImageStatisticsContainer.h> #include <MitkImageStatisticsUIExports.h> #include <ui_QmitkImageStatisticsWidget.h> #include <QmitkImageStatisticsTableModel.h> //Qt #include <QWidget> class MITKIMAGESTATISTICSUI_EXPORT QmitkImageStatisticsWidget : public QWidget { Q_OBJECT public: QmitkImageStatisticsWidget(QWidget* parent = nullptr); void SetStatistics(const std::vector<mitk::StatisticsContainer::ConstPointer>& sc); + void EnableAllComponents(); + private: void CreateConnections(); - void EnableAllComponents(); - /** \brief Saves the image statistics to the clipboard */ void OnClipboardButtonClicked(); /** \brief Toogle GUI elements if histogram default bin size checkbox value changed. */ private: Ui::QmitkImageStatisticsControls m_Controls; QmitkImageStatisticsTableModel* m_imageStatisticsModel; }; #endif // QmitkImageStatisticsWidget_H__INCLUDED diff --git a/Modules/ImageStatisticsUI/Qmitk/QmitkImageStatisticsWidget.ui b/Modules/ImageStatisticsUI/Qmitk/QmitkImageStatisticsWidget.ui index 4cad6e6890..dda135aa4d 100644 --- a/Modules/ImageStatisticsUI/Qmitk/QmitkImageStatisticsWidget.ui +++ b/Modules/ImageStatisticsUI/Qmitk/QmitkImageStatisticsWidget.ui @@ -1,130 +1,133 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>QmitkImageStatisticsControls</class> <widget class="QWidget" name="QmitkImageStatisticsControls"> <property name="geometry"> <rect> <x>0</x> <y>0</y> - <width>540</width> - <height>460</height> + <width>496</width> + <height>468</height> </rect> </property> <property name="sizePolicy"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="minimumSize"> <size> <width>0</width> <height>0</height> </size> </property> <property name="windowTitle"> <string>Form</string> </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> <widget class="QGroupBox" name="groupBoxHistogram"> <property name="enabled"> - <bool>false</bool> + <bool>true</bool> </property> <property name="minimumSize"> <size> <width>400</width> <height>450</height> </size> </property> <property name="title"> <string/> </property> <property name="checkable"> <bool>false</bool> </property> <layout class="QVBoxLayout" name="verticalLayout_4"> <item> <widget class="QTableView" name="tableViewStatistics"/> </item> <item> <widget class="QWidget" name="widgetClipboard" native="true"> <layout class="QHBoxLayout" name="horizontalLayout_3"> <property name="spacing"> <number>0</number> </property> <property name="leftMargin"> <number>0</number> </property> <property name="topMargin"> <number>0</number> </property> <property name="rightMargin"> <number>0</number> </property> <property name="bottomMargin"> <number>0</number> </property> <item> <widget class="QPushButton" name="buttonCopyImageStatisticsToClipboard"> + <property name="enabled"> + <bool>false</bool> + </property> <property name="sizePolicy"> <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="text"> <string>Copy to Clipboard</string> </property> </widget> </item> <item> <spacer name="horizontalSpacer_3"> <property name="orientation"> <enum>Qt::Horizontal</enum> </property> <property name="sizeType"> <enum>QSizePolicy::Fixed</enum> </property> <property name="sizeHint" stdset="0"> <size> <width>20</width> <height>20</height> </size> </property> </spacer> </item> <item> <widget class="QCheckBox" name="checkBox4dCompleteTable"> <property name="enabled"> <bool>false</bool> </property> <property name="text"> <string>copy complete table</string> </property> </widget> </item> <item> <spacer name="horizontalSpacer_2"> <property name="orientation"> <enum>Qt::Horizontal</enum> </property> <property name="sizeHint" stdset="0"> <size> <width>40</width> <height>20</height> </size> </property> </spacer> </item> </layout> </widget> </item> </layout> </widget> </item> </layout> </widget> <resources/> <connections/> </ui> diff --git a/Plugins/org.mitk.gui.qt.measurementtoolbox/src/internal/QmitkImageStatisticsReloadedView.cpp b/Plugins/org.mitk.gui.qt.measurementtoolbox/src/internal/QmitkImageStatisticsReloadedView.cpp index e3da6e2070..6bca70ecf1 100644 --- a/Plugins/org.mitk.gui.qt.measurementtoolbox/src/internal/QmitkImageStatisticsReloadedView.cpp +++ b/Plugins/org.mitk.gui.qt.measurementtoolbox/src/internal/QmitkImageStatisticsReloadedView.cpp @@ -1,92 +1,173 @@ /*=================================================================== 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 "QmitkImageStatisticsReloadedView.h" // berry includes #include <berryIWorkbenchPage.h> #include <berryWorkbenchPlugin.h> #include <berryQtPreferences.h> #include <mitkNodePredicateAnd.h> #include <mitkNodePredicateDataType.h> #include <mitkNodePredicateProperty.h> +#include <mitkNodePredicateNot.h> +#include <mitkStatusBar.h> const std::string QmitkImageStatisticsReloadedView::VIEW_ID = "org.mitk.views.imagestatisticsReloaded"; +void QmitkImageStatisticsReloadedView::FillStatisticsWidget(const std::vector<mitk::StatisticsContainer::ConstPointer>& statistics) +{ + m_Controls.widget_statistics->SetStatistics(statistics); + m_Controls.widget_statistics->EnableAllComponents(); + m_Controls.groupBox_statistics->setEnabled(true); + m_Controls.widget_statistics->setEnabled(true); +} + +void QmitkImageStatisticsReloadedView::FillHistogramWidget(const std::vector<HistogramType::ConstPointer>& histogram) +{ + //m_Controls.widget_histogram->SetHistogram(histogram); + //m_Controls.widget_histogram->EnableAllComponents(); +} + QmitkImageStatisticsReloadedView::QmitkImageStatisticsReloadedView(QObject* /*parent*/, const char* /*name*/) { + this->m_CalculationThread = new QmitkImageStatisticsCalculationThread; } QmitkImageStatisticsReloadedView::~QmitkImageStatisticsReloadedView() { } void QmitkImageStatisticsReloadedView::CreateQtPartControl(QWidget *parent) { m_Controls.setupUi(parent); - CreateConnections(); + PrepareDataStorageComboBoxes(); + CreateConnections(); } void QmitkImageStatisticsReloadedView::CreateConnections() { + connect(m_Controls.imageSelector, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](int index) { OnImageOrMaskSelectorChanged(); }); + connect(this->m_CalculationThread, &QmitkImageStatisticsCalculationThread::finished, this, &QmitkImageStatisticsReloadedView::OnStatisticsCalculationEnds, Qt::QueuedConnection); } void QmitkImageStatisticsReloadedView::PartClosed(const berry::IWorkbenchPartReference::Pointer& ) { } +void QmitkImageStatisticsReloadedView::OnImageOrMaskSelectorChanged() +{ + auto imageNode = m_Controls.imageSelector->GetSelectedNode(); + auto maskNode = m_Controls.maskImageSelector->GetSelectedNode(); + + if (imageNode != nullptr) { + auto image = dynamic_cast<mitk::Image*>(imageNode->GetData()); + mitk::Image::Pointer mask = nullptr; + if (maskNode != nullptr) { + mask = dynamic_cast<mitk::Image*>(maskNode->GetData()); + } + + CalculateStatistics(image, mask); + } +} + +void QmitkImageStatisticsReloadedView::OnStatisticsCalculationEnds() +{ + mitk::StatusBar::GetInstance()->Clear(); + + if (this->m_CalculationThread->GetStatisticsUpdateSuccessFlag()) { + this->FillStatisticsWidget(m_CalculationThread->GetStatisticsData()); + this->FillHistogramWidget({ m_CalculationThread->GetTimeStepHistogram() }); + } + else { + mitk::StatusBar::GetInstance()->DisplayErrorText(m_CalculationThread->GetLastErrorMessage().c_str()); + m_Controls.widget_histogram->setEnabled(false); + m_Controls.widget_statistics->setEnabled(false); + } +} + +void QmitkImageStatisticsReloadedView::CalculateStatistics(mitk::Image::Pointer image, mitk::Image::Pointer mask) +{ + this->m_StatisticsUpdatePending = true; + this->m_CalculationThread->Initialize(image, mask, nullptr); + this->m_CalculationThread->SetTimeStep(0); + + try + { + // Compute statistics + this->m_CalculationThread->start(); + } + catch (const mitk::Exception& e) + { + mitk::StatusBar::GetInstance()->DisplayErrorText(e.GetDescription()); + this->m_StatisticsUpdatePending = false; + } + catch (const std::runtime_error &e) + { + mitk::StatusBar::GetInstance()->DisplayErrorText(e.what()); + this->m_StatisticsUpdatePending = false; + } + catch (const std::exception &e) + { + mitk::StatusBar::GetInstance()->DisplayErrorText(e.what()); + this->m_StatisticsUpdatePending = false; + } +} + void QmitkImageStatisticsReloadedView::OnSelectionChanged( berry::IWorkbenchPart::Pointer /*part*/, const QList<mitk::DataNode::Pointer> &nodes ) { } void QmitkImageStatisticsReloadedView::PrepareDataStorageComboBoxes() { auto isImage = mitk::NodePredicateDataType::New("Image"); auto isBinary = mitk::NodePredicateProperty::New("binary", mitk::BoolProperty::New(true)); + auto isNoBinary = mitk::NodePredicateNot::New(isBinary); auto isBinaryImage = mitk::NodePredicateAnd::New(isImage, isBinary); + auto isNoBinaryImage = mitk::NodePredicateAnd::New(isImage, isNoBinary); m_Controls.imageSelector->SetDataStorage(GetDataStorage()); - m_Controls.imageSelector->SetPredicate(isImage); + m_Controls.imageSelector->SetPredicate(isNoBinaryImage); m_Controls.maskImageSelector->SetDataStorage(GetDataStorage()); m_Controls.maskImageSelector->SetPredicate(isBinaryImage); } void QmitkImageStatisticsReloadedView::Activated() { } void QmitkImageStatisticsReloadedView::Deactivated() { } void QmitkImageStatisticsReloadedView::Visible() { } void QmitkImageStatisticsReloadedView::Hidden() { } void QmitkImageStatisticsReloadedView::SetFocus() { } \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.measurementtoolbox/src/internal/QmitkImageStatisticsReloadedView.h b/Plugins/org.mitk.gui.qt.measurementtoolbox/src/internal/QmitkImageStatisticsReloadedView.h index eab16362d0..95eeb6b15a 100644 --- a/Plugins/org.mitk.gui.qt.measurementtoolbox/src/internal/QmitkImageStatisticsReloadedView.h +++ b/Plugins/org.mitk.gui.qt.measurementtoolbox/src/internal/QmitkImageStatisticsReloadedView.h @@ -1,79 +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 QmitkImageStatisticsReloadedView_H__INCLUDED #define QmitkImageStatisticsReloadedView_H__INCLUDED #include "ui_QmitkImageStatisticsReloadedViewControls.h" // Qmitk includes #include <QmitkAbstractView.h> +#include "QmitkImageStatisticsCalculationThread.h" +#include <mitkImageStatisticsContainer.h> + #include <mitkILifecycleAwarePart.h> #include <berryIPartListener.h> /*! \brief QmitkImageStatisticsView is a bundle that allows statistics calculation from images. Three modes are supported: 1. Statistics of one image, 2. Statistics of an image and a segmentation, 3. Statistics of an image and a Planar Figure. The statistics calculation is realized in a separate thread to keep the gui accessible during calculation. \ingroup Plugins/org.mitk.gui.qt.measurementtoolbox */ class QmitkImageStatisticsReloadedView : public QmitkAbstractView, public mitk::ILifecycleAwarePart, public berry::IPartListener { Q_OBJECT public: - + using HistogramType = mitk::StatisticsContainer::HistogramType; /*! \brief default constructor */ QmitkImageStatisticsReloadedView(QObject *parent = nullptr, const char *name = nullptr); /*! \brief default destructor */ virtual ~QmitkImageStatisticsReloadedView(); /*! \brief method for creating the widget containing the application controls, like sliders, buttons etc. */ virtual void CreateQtPartControl(QWidget *parent) override; /*! \brief method for creating the connections of main and control widget */ virtual void CreateConnections(); /*! \brief Is called from the selection mechanism once the data manager selection has changed*/ void OnSelectionChanged(berry::IWorkbenchPart::Pointer part, const QList<mitk::DataNode::Pointer> &selectedNodes) override; void PrepareDataStorageComboBoxes(); static const std::string VIEW_ID; + void FillStatisticsWidget(const std::vector<mitk::StatisticsContainer::ConstPointer>& statistics); + void FillHistogramWidget(const std::vector<HistogramType::ConstPointer>& histogram); protected: virtual void Activated() override; virtual void Deactivated() override; virtual void Visible() override; virtual void Hidden() override; virtual void SetFocus() override; /** \brief Is called right before the view closes (before the destructor) */ virtual void PartClosed(const berry::IWorkbenchPartReference::Pointer&) override; /** \brief Required for berry::IPartListener */ virtual Events::Types GetPartEventTypes() const override { return Events::CLOSED; } + void OnImageOrMaskSelectorChanged(); + void OnStatisticsCalculationEnds(); + + void CalculateStatistics(mitk::Image::Pointer image, mitk::Image::Pointer mask); + // member variables Ui::QmitkImageStatisticsReloadedViewControls m_Controls; + +private: + QmitkImageStatisticsCalculationThread * m_CalculationThread; + bool m_StatisticsUpdatePending=false; }; #endif // QmitkImageStatisticsView_H__INCLUDED diff --git a/Plugins/org.mitk.gui.qt.measurementtoolbox/src/internal/QmitkImageStatisticsReloadedViewControls.ui b/Plugins/org.mitk.gui.qt.measurementtoolbox/src/internal/QmitkImageStatisticsReloadedViewControls.ui index 742f2e88b4..9fdb276977 100644 --- a/Plugins/org.mitk.gui.qt.measurementtoolbox/src/internal/QmitkImageStatisticsReloadedViewControls.ui +++ b/Plugins/org.mitk.gui.qt.measurementtoolbox/src/internal/QmitkImageStatisticsReloadedViewControls.ui @@ -1,255 +1,255 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>QmitkImageStatisticsReloadedViewControls</class> <widget class="QWidget" name="QmitkImageStatisticsReloadedViewControls"> <property name="enabled"> <bool>true</bool> </property> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>548</width> <height>853</height> </rect> </property> <property name="windowTitle"> <string>Form</string> </property> <layout class="QVBoxLayout" name="verticalLayout_4"> <item> <layout class="QGridLayout" name="gridLayout_4" columnstretch="0,0"> <property name="sizeConstraint"> <enum>QLayout::SetMinimumSize</enum> </property> <property name="spacing"> <number>4</number> </property> <item row="0" column="1"> <widget class="QmitkDataStorageComboBox" name="imageSelector"> <property name="sizePolicy"> <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="autoFillBackground"> <bool>false</bool> </property> </widget> </item> <item row="0" column="0"> <widget class="QLabel" name="label_calibrationImage"> <property name="sizePolicy"> <sizepolicy hsizetype="Maximum" vsizetype="Preferred"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="palette"> <palette> <active> <colorrole role="WindowText"> <brush brushstyle="SolidPattern"> <color alpha="255"> <red>0</red> <green>0</green> <blue>0</blue> </color> </brush> </colorrole> </active> <inactive> <colorrole role="WindowText"> <brush brushstyle="SolidPattern"> <color alpha="255"> <red>0</red> <green>0</green> <blue>0</blue> </color> </brush> </colorrole> </inactive> <disabled> <colorrole role="WindowText"> <brush brushstyle="SolidPattern"> <color alpha="255"> <red>120</red> <green>120</green> <blue>120</blue> </color> </brush> </colorrole> </disabled> </palette> </property> <property name="text"> <string>Image:</string> </property> </widget> </item> <item row="1" column="0"> <widget class="QLabel" name="label_maskImage"> <property name="sizePolicy"> <sizepolicy hsizetype="Maximum" vsizetype="Preferred"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="palette"> <palette> <active> <colorrole role="WindowText"> <brush brushstyle="SolidPattern"> <color alpha="255"> <red>0</red> <green>0</green> <blue>0</blue> </color> </brush> </colorrole> </active> <inactive> <colorrole role="WindowText"> <brush brushstyle="SolidPattern"> <color alpha="255"> <red>0</red> <green>0</green> <blue>0</blue> </color> </brush> </colorrole> </inactive> <disabled> <colorrole role="WindowText"> <brush brushstyle="SolidPattern"> <color alpha="255"> <red>120</red> <green>120</green> <blue>120</blue> </color> </brush> </colorrole> </disabled> </palette> </property> <property name="text"> <string>Mask image:</string> </property> </widget> </item> <item row="1" column="1"> <widget class="QmitkDataStorageComboBox" name="maskImageSelector"> <property name="sizePolicy"> <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="autoFillBackground"> <bool>false</bool> </property> </widget> </item> </layout> </item> <item> <widget class="QGroupBox" name="groupBox_statistics"> <property name="enabled"> <bool>false</bool> </property> <property name="minimumSize"> <size> <width>0</width> <height>250</height> </size> </property> <property name="title"> <string>Statistics</string> </property> <layout class="QVBoxLayout" name="verticalLayout"> <property name="leftMargin"> <number>9</number> </property> <property name="rightMargin"> <number>9</number> </property> <property name="bottomMargin"> <number>9</number> </property> <item> - <widget class="QmitkImageStatisticsWidget" name="widget_2" native="true"> + <widget class="QmitkImageStatisticsWidget" name="widget_statistics" native="true"> <property name="sizePolicy"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> </widget> </item> </layout> </widget> </item> <item> <widget class="QGroupBox" name="groupBox_histogram"> <property name="enabled"> <bool>false</bool> </property> <property name="minimumSize"> <size> <width>400</width> <height>450</height> </size> </property> <property name="title"> <string>Histogram</string> </property> <property name="checkable"> <bool>false</bool> </property> <layout class="QVBoxLayout" name="verticalLayout_3"> <item> - <widget class="HistogramVisualizationWidget" name="widget" native="true"> + <widget class="HistogramVisualizationWidget" name="widget_histogram" native="true"> <property name="sizePolicy"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> </widget> </item> </layout> </widget> </item> <item> <spacer name="verticalSpacer"> <property name="orientation"> <enum>Qt::Vertical</enum> </property> <property name="sizeHint" stdset="0"> <size> <width>20</width> <height>40</height> </size> </property> </spacer> </item> </layout> </widget> <customwidgets> <customwidget> <class>QmitkHistogramVisualizationWidget</class> <extends>QWidget</extends> <header location="global">QmitkHistogramVisualizationWidget.h</header> <container>1</container> </customwidget> <customwidget> <class>QmitkImageStatisticsWidget</class> <extends>QWidget</extends> <header location="global">QmitkImageStatisticsWidget.h</header> <container>1</container> </customwidget> </customwidgets> <resources/> <connections/> </ui>