diff --git a/Modules/ImageStatisticsUI/Qmitk/QmitkHistogramVisualizationControls.ui b/Modules/ImageStatisticsUI/Qmitk/QmitkHistogramVisualizationControls.ui new file mode 100644 index 0000000000..8c29972cc9 --- /dev/null +++ b/Modules/ImageStatisticsUI/Qmitk/QmitkHistogramVisualizationControls.ui @@ -0,0 +1,401 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>QmitkHistogramVisualizationControls</class> + <widget class="QWidget" name="QmitkHistogramVisualizationControls"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>318</width> + <height>400</height> + </rect> + </property> + <property name="minimumSize"> + <size> + <width>300</width> + <height>300</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> + </property> + <property name="minimumSize"> + <size> + <width>300</width> + <height>300</height> + </size> + </property> + <property name="title"> + <string>Histogram</string> + </property> + <property name="checkable"> + <bool>false</bool> + </property> + <layout class="QVBoxLayout" name="verticalLayout_4"> + <item> + <widget class="QLabel" name="labelHistogramIsInvisibleWarning"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="palette"> + <palette> + <active> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>0</green> + <blue>0</blue> + </color> + </brush> + </colorrole> + <colorrole role="Text"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>0</green> + <blue>0</blue> + </color> + </brush> + </colorrole> + <colorrole role="ButtonText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>0</green> + <blue>0</blue> + </color> + </brush> + </colorrole> + </active> + <inactive> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>0</green> + <blue>0</blue> + </color> + </brush> + </colorrole> + <colorrole role="Text"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>0</green> + <blue>0</blue> + </color> + </brush> + </colorrole> + <colorrole role="ButtonText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</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> + <colorrole role="Text"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>120</red> + <green>120</green> + <blue>120</blue> + </color> + </brush> + </colorrole> + <colorrole role="ButtonText"> + <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/> + </property> + </widget> + </item> + <item> + <widget class="QGroupBox" name="groupBoxPlot"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>0</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>16777215</width> + <height>16777215</height> + </size> + </property> + <property name="title"> + <string>Plot</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_5"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QRadioButton" name="radioButtonBarchart"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="styleSheet"> + <string notr="true"/> + </property> + <property name="text"> + <string>Barchart</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="radioButtonLinegraph"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>0</height> + </size> + </property> + <property name="text"> + <string>Linegraph</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <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> + </item> + <item> + <widget class="QCheckBox" name="checkBoxShowSubchart"> + <property name="text"> + <string>Show Subchart</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBoxUseDefaultNBins"> + <property name="text"> + <string>Use default #bins</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QFrame" name="FrameBinSize"> + <property name="frameShape"> + <enum>QFrame::NoFrame</enum> + </property> + <property name="frameShadow"> + <enum>QFrame::Raised</enum> + </property> + <layout class="QGridLayout" name="gridLayout_2"> + <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> + <property name="spacing"> + <number>0</number> + </property> + <item row="1" column="0"> + <widget class="QLabel" name="labelNBins"> + <property name="minimumSize"> + <size> + <width>60</width> + <height>0</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>100</width> + <height>16777215</height> + </size> + </property> + <property name="text"> + <string># bins:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QSpinBox" name="spinBoxNBins"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="toolTip"> + <string>Press enter to recalculate statistics with new bin size.</string> + </property> + <property name="minimum"> + <number>1</number> + </property> + <property name="maximum"> + <number>10000</number> + </property> + <property name="value"> + <number>100</number> + </property> + </widget> + </item> + </layout> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QStackedWidget" name="stackWidgetChart"> + <property name="minimumSize"> + <size> + <width>0</width> + <height>0</height> + </size> + </property> + <property name="currentIndex"> + <number>0</number> + </property> + <widget class="QmitkChartWidget" name="chartWidget"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </widget> + </item> + <item> + <widget class="QLabel" name="labelInfo"> + <property name="text"> + <string/> + </property> + </widget> + </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="buttonCopyHistogramToClipboard"> + <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_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> + <customwidgets> + <customwidget> + <class>QmitkChartWidget</class> + <extends>QWidget</extends> + <header location="global">QmitkChartWidget.h</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> diff --git a/Modules/ImageStatisticsUI/Qmitk/QmitkHistogramVisualizationWidget.cpp b/Modules/ImageStatisticsUI/Qmitk/QmitkHistogramVisualizationWidget.cpp index b6d877b6b6..933af435b1 100644 --- a/Modules/ImageStatisticsUI/Qmitk/QmitkHistogramVisualizationWidget.cpp +++ b/Modules/ImageStatisticsUI/Qmitk/QmitkHistogramVisualizationWidget.cpp @@ -1,127 +1,130 @@ /*=================================================================== 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 "QmitkHistogramVisualizationWidget.h" #include <qclipboard> QmitkHistogramVisualizationWidget::QmitkHistogramVisualizationWidget(QWidget* parent) : QWidget(parent) { m_Controls.setupUi(this); CreateConnections(); + m_Controls.labelInfo->setVisible(false); + m_Controls.labelHistogramIsInvisibleWarning->setVisible(false); + m_Controls.checkBoxShowSubchart->setChecked(false); } -void QmitkHistogramVisualizationWidget::setHistogram(itk::Statistics::Histogram<double>::ConstPointer histogram, const std::string& dataLabel) +void QmitkHistogramVisualizationWidget::SetHistogram(itk::Statistics::Histogram<double>::ConstPointer histogram, const std::string& dataLabel) { if (histogram == nullptr) return; m_Histogram = histogram; m_Controls.chartWidget->AddData2D(ConvertHistogramToMap(m_Histogram), dataLabel); m_Controls.chartWidget->SetChartType(dataLabel, QmitkChartWidget::ChartType::bar); m_Controls.chartWidget->SetXAxisLabel("Gray value"); m_Controls.chartWidget->SetYAxisLabel("Frequency"); m_Controls.chartWidget->Show(m_Controls.checkBoxShowSubchart->isChecked()); SetGUIElementsEnabled(true); } void QmitkHistogramVisualizationWidget::Reset() { m_Controls.chartWidget->Clear(); SetGUIElementsEnabled(false); } void QmitkHistogramVisualizationWidget::CreateConnections() { connect(m_Controls.buttonCopyHistogramToClipboard, &QPushButton::clicked, this, &QmitkHistogramVisualizationWidget::OnClipboardButtonClicked); connect(m_Controls.checkBoxUseDefaultNBins, &QCheckBox::clicked, this, &QmitkHistogramVisualizationWidget::OnDefaultNBinsCheckBoxChanged); connect(m_Controls.spinBoxNBins, &QSpinBox::editingFinished, this, &QmitkHistogramVisualizationWidget::OnNBinsSpinBoxValueChanged); connect(m_Controls.checkBoxShowSubchart, &QCheckBox::clicked, this, &QmitkHistogramVisualizationWidget::OnShowSubchartCheckBoxChanged); } void QmitkHistogramVisualizationWidget::SetGUIElementsEnabled(bool enabled) { this->setEnabled(enabled); m_Controls.groupBoxHistogram->setEnabled(enabled); m_Controls.groupBoxPlot->setEnabled(enabled); m_Controls.checkBoxShowSubchart->setEnabled(enabled); m_Controls.checkBoxUseDefaultNBins->setEnabled(enabled); m_Controls.spinBoxNBins->setEnabled(!m_Controls.checkBoxUseDefaultNBins->isChecked()); m_Controls.buttonCopyHistogramToClipboard->setEnabled(enabled); } std::map<double, double> QmitkHistogramVisualizationWidget::ConvertHistogramToMap(itk::Statistics::Histogram<double>::ConstPointer histogram) const { std::map<double, double> histogramMap; if (histogram) { auto endIt = histogram->End(); auto it = histogram->Begin(); // generating Lists of measurement and frequencies for (; it != endIt; ++it) { double frequency = it.GetFrequency(); double measurement = it.GetMeasurementVector()[0]; histogramMap.emplace(measurement, frequency); } } return histogramMap; } void QmitkHistogramVisualizationWidget::OnClipboardButtonClicked() { if (m_Histogram) { QApplication::clipboard()->clear(); QString clipboard("Measurement \t Frequency\n"); auto iter = m_Histogram->Begin(); auto iterEnd = m_Histogram->End(); for (; iter != iterEnd; ++iter) { clipboard = clipboard.append("%L1 \t %L2\n") .arg(iter.GetMeasurementVector()[0], 0, 'f', 2) .arg(iter.GetFrequency()); } QApplication::clipboard()->setText(clipboard, QClipboard::Clipboard); } } void QmitkHistogramVisualizationWidget::OnDefaultNBinsCheckBoxChanged() { if (m_Controls.checkBoxUseDefaultNBins->isChecked()) { m_Controls.spinBoxNBins->setEnabled(false); m_Controls.spinBoxNBins->setValue(100); } else { m_Controls.spinBoxNBins->setEnabled(true); } } void QmitkHistogramVisualizationWidget::OnNBinsSpinBoxValueChanged() { emit RequestHistogramUpdate(m_Controls.spinBoxNBins->value()); } void QmitkHistogramVisualizationWidget::OnShowSubchartCheckBoxChanged() { m_Controls.chartWidget->Show(m_Controls.checkBoxShowSubchart->isChecked()); } \ No newline at end of file diff --git a/Modules/ImageStatisticsUI/Qmitk/QmitkHistogramVisualizationWidget.h b/Modules/ImageStatisticsUI/Qmitk/QmitkHistogramVisualizationWidget.h index 3f3c2885ae..c300f847a5 100644 --- a/Modules/ImageStatisticsUI/Qmitk/QmitkHistogramVisualizationWidget.h +++ b/Modules/ImageStatisticsUI/Qmitk/QmitkHistogramVisualizationWidget.h @@ -1,71 +1,71 @@ /*=================================================================== 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 QmitkHistogramVisualizationWidget_H__INCLUDED #define QmitkHistogramVisualizationWidget_H__INCLUDED //Qt #include <QWidget> #include <MitkImageStatisticsUIExports.h> #include <ui_QmitkHistogramVisualizationWidget.h> //itk #include <itkHistogram.h> /** * \brief Widget for displaying Histograms. */ class MITKIMAGESTATISTICSUI_EXPORT QmitkHistogramVisualizationWidget : public QWidget { Q_OBJECT public: QmitkHistogramVisualizationWidget(QWidget* parent = nullptr); /** \brief Draws the histogram and enables the GUI elements. */ - void setHistogram(itk::Statistics::Histogram<double>::ConstPointer histogram, const std::string& dataLabel); + void SetHistogram(itk::Statistics::Histogram<double>::ConstPointer histogram, const std::string& dataLabel); /** \brief Clears the histogram and disables all GUI elements. */ void Reset(); signals: /** \brief Signal to be emitted when the number of bins is changed by the user. The HistogramCalculator should connect to this signal and recalculate the data accordingly. */ void RequestHistogramUpdate(unsigned int nBins); private: void CreateConnections(); void SetGUIElementsEnabled(bool enabled); /** \brief Helper function to convert the histogram in order to forward it to the ChartWidget. */ std::map<double, double> ConvertHistogramToMap(itk::Statistics::Histogram<double>::ConstPointer histogram) const; //slots /** \brief Saves the histogram to the clipboard. */ void OnClipboardButtonClicked(); /** \brief Enables / Disables SpinBox to change the number of bins. */ void OnDefaultNBinsCheckBoxChanged(); /** \brief Emits the signal RequestHistogramUpdate(unsigned int nBins) with the updated value. */ void OnNBinsSpinBoxValueChanged(); /** \brief Shows / Hides the subchart. */ void OnShowSubchartCheckBoxChanged(); private: Ui::QmitkHistogramVisualizationControls m_Controls; itk::Statistics::Histogram<double>::ConstPointer m_Histogram; }; #endif //QmitkHistogramVisualizationWidget_H__INCLUDED \ No newline at end of file diff --git a/Modules/ImageStatisticsUI/Qmitk/QmitkImageStatisticsWidget.cpp b/Modules/ImageStatisticsUI/Qmitk/QmitkImageStatisticsWidget.cpp index 9428d3186d..20ce153c30 100644 --- a/Modules/ImageStatisticsUI/Qmitk/QmitkImageStatisticsWidget.cpp +++ b/Modules/ImageStatisticsUI/Qmitk/QmitkImageStatisticsWidget.cpp @@ -1,64 +1,66 @@ /*=================================================================== 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 "QmitkImageStatisticsWidget.h" QmitkImageStatisticsWidget::QmitkImageStatisticsWidget(QWidget* parent) : QWidget(parent) { m_Controls.setupUi(parent); m_imageStatisticsModel = new QmitkImageStatisticsTableModel(parent); CreateConnections(); } void QmitkImageStatisticsWidget::SetStatistics(const std::vector<mitk::StatisticsContainer::ConstPointer>& sc) { m_imageStatisticsModel->SetStatistics(sc); m_Controls.tableViewStatistics->setModel(m_imageStatisticsModel); m_Controls.tableViewStatistics->resizeColumnsToContents(); m_Controls.tableViewStatistics->resizeRowsToContents(); + EnableAllGUIElements(); } void QmitkImageStatisticsWidget::SetImageNodes(const std::vector<mitk::DataNode::ConstPointer>& nodes) { m_imageStatisticsModel->SetImageNodes(nodes); } void QmitkImageStatisticsWidget::SetMaskNodes(const std::vector<mitk::DataNode::ConstPointer>& nodes) { m_imageStatisticsModel->SetMaskNodes(nodes); } void QmitkImageStatisticsWidget::Reset() { m_imageStatisticsModel->Clear(); } void QmitkImageStatisticsWidget::CreateConnections() { connect(m_Controls.buttonCopyImageStatisticsToClipboard, &QPushButton::clicked, this, &QmitkImageStatisticsWidget::OnClipboardButtonClicked); } void QmitkImageStatisticsWidget::EnableAllGUIElements() { this->setEnabled(true); m_Controls.buttonCopyImageStatisticsToClipboard->setEnabled(true); m_Controls.checkBox4dCompleteTable->setEnabled(true); m_Controls.tableViewStatistics->setEnabled(true); + m_Controls.groupBoxStatistics->setEnabled(true); } void QmitkImageStatisticsWidget::OnClipboardButtonClicked() { } diff --git a/Modules/ImageStatisticsUI/Qmitk/QmitkImageStatisticsWidget.ui b/Modules/ImageStatisticsUI/Qmitk/QmitkImageStatisticsWidget.ui index 9e537f6d8b..6a616a15c1 100644 --- a/Modules/ImageStatisticsUI/Qmitk/QmitkImageStatisticsWidget.ui +++ b/Modules/ImageStatisticsUI/Qmitk/QmitkImageStatisticsWidget.ui @@ -1,142 +1,120 @@ <?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>318</width> - <height>320</height> + <height>400</height> </rect> </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> <property name="minimumSize"> <size> <width>300</width> - <height>250</height> + <height>300</height> </size> </property> <property name="windowTitle"> <string>Form</string> </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> - <widget class="QGroupBox" name="groupBox"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> + <widget class="QGroupBox" name="groupBoxStatistics"> + <property name="enabled"> + <bool>false</bool> </property> <property name="minimumSize"> <size> <width>300</width> <height>250</height> </size> </property> <property name="title"> <string>Statistics</string> </property> <layout class="QVBoxLayout" name="verticalLayout_2"> <item> <widget class="QTableView" name="tableViewStatistics"> <property name="minimumSize"> <size> <width>0</width> <height>150</height> </size> </property> </widget> </item> <item> <layout class="QHBoxLayout" name="horizontalLayout"> <property name="spacing"> <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> </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> <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 40d780a6a1..7dab5a4c1c 100644 --- a/Plugins/org.mitk.gui.qt.measurementtoolbox/src/internal/QmitkImageStatisticsReloadedView.cpp +++ b/Plugins/org.mitk.gui.qt.measurementtoolbox/src/internal/QmitkImageStatisticsReloadedView.cpp @@ -1,181 +1,181 @@ /*=================================================================== 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->SetImageNodes({m_selectedImageNode}); if (m_selectedMaskNode) { m_Controls.widget_statistics->SetMaskNodes({ m_selectedMaskNode }); } m_Controls.widget_statistics->setEnabled(true); } -void QmitkImageStatisticsReloadedView::FillHistogramWidget(const std::vector<HistogramType::ConstPointer>& histogram) +void QmitkImageStatisticsReloadedView::FillHistogramWidget(const std::vector<HistogramType::ConstPointer>& histogram, const std::vector<std::string>& dataLabels) { - //m_Controls.widget_histogram->SetHistogram(histogram); + m_Controls.widget_histogram->SetHistogram(histogram.front(), dataLabels.front()); //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); 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() { m_selectedImageNode = m_Controls.imageSelector->GetSelectedNode(); m_selectedMaskNode = m_Controls.maskImageSelector->GetSelectedNode(); if (m_selectedImageNode != nullptr) { auto image = dynamic_cast<mitk::Image*>(m_selectedImageNode->GetData()); mitk::Image::Pointer mask = nullptr; if (m_selectedMaskNode != nullptr) { mask = dynamic_cast<mitk::Image*>(m_selectedMaskNode->GetData()); } CalculateStatistics(image, mask); } else { m_Controls.widget_statistics->Reset(); m_Controls.widget_statistics->setEnabled(false); m_Controls.widget_histogram->Reset(); m_Controls.widget_histogram->setEnabled(false); } } void QmitkImageStatisticsReloadedView::OnStatisticsCalculationEnds() { mitk::StatusBar::GetInstance()->Clear(); if (this->m_CalculationThread->GetStatisticsUpdateSuccessFlag()) { this->FillStatisticsWidget(m_CalculationThread->GetStatisticsData()); - this->FillHistogramWidget({ m_CalculationThread->GetTimeStepHistogram() }); + this->FillHistogramWidget({ m_CalculationThread->GetTimeStepHistogram() }, {m_selectedImageNode->GetName()}); } 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(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 07d979657f..33c79e9932 100644 --- a/Plugins/org.mitk.gui.qt.measurementtoolbox/src/internal/QmitkImageStatisticsReloadedView.h +++ b/Plugins/org.mitk.gui.qt.measurementtoolbox/src/internal/QmitkImageStatisticsReloadedView.h @@ -1,94 +1,94 @@ /*=================================================================== 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); + void FillHistogramWidget(const std::vector<HistogramType::ConstPointer>& histogram, const std::vector<std::string>& dataLabels); 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; mitk::DataNode::ConstPointer m_selectedImageNode, m_selectedMaskNode; }; #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 4ea9d0bad2..c43b6b4eea 100644 --- a/Plugins/org.mitk.gui.qt.measurementtoolbox/src/internal/QmitkImageStatisticsReloadedViewControls.ui +++ b/Plugins/org.mitk.gui.qt.measurementtoolbox/src/internal/QmitkImageStatisticsReloadedViewControls.ui @@ -1,243 +1,228 @@ <?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>419</width> <height>1016</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="minimumSize"> <size> <width>0</width> <height>200</height> </size> </property> <property name="title"> <string>Statistics</string> </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> - <widget class="QmitkImageStatisticsWidget" name="widget_statistics" native="true"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - </widget> + <widget class="QmitkImageStatisticsWidget" name="widget_statistics" native="true"/> </item> </layout> </widget> </item> <item> <widget class="QGroupBox" name="groupBox_histogram"> <property name="minimumSize"> <size> <width>0</width> <height>200</height> </size> </property> <property name="title"> <string>Histogram</string> </property> <layout class="QVBoxLayout" name="verticalLayout_2"> <item> - <widget class="HistogramVisualizationWidget" name="widget_histogram" native="true"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - </widget> + <widget class="QmitkHistogramVisualizationWidget" name="widget_histogram" native="true"/> </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>QmitkDataStorageComboBox</class> + <extends>QComboBox</extends> + <header location="global">QmitkDataStorageComboBox.h</header> + </customwidget> <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>