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 7dab5a4c1c..ead1507560 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,184 @@ /*=================================================================== 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, const std::vector<std::string>& dataLabels) { 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(m_Controls.maskImageSelector, 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() }, {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); + m_Controls.maskImageSelector->SetZeroEntryText("<none>"); } 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/QmitkImageStatisticsReloadedViewControls.ui b/Plugins/org.mitk.gui.qt.measurementtoolbox/src/internal/QmitkImageStatisticsReloadedViewControls.ui index 2ab3d1e06f..0b1522bf3f 100644 --- a/Plugins/org.mitk.gui.qt.measurementtoolbox/src/internal/QmitkImageStatisticsReloadedViewControls.ui +++ b/Plugins/org.mitk.gui.qt.measurementtoolbox/src/internal/QmitkImageStatisticsReloadedViewControls.ui @@ -1,198 +1,233 @@ <?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"> + <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>Image:</string> + <string>Mask image:</string> </property> </widget> </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_maskImage"> + <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>Mask image:</string> + <string>Image:</string> + </property> + </widget> + </item> + <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="1" column="1"> - <widget class="QmitkDataStorageComboBox" name="maskImageSelector"> + <widget class="QmitkDataStorageComboBoxWithSelectNone" 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="QmitkImageStatisticsWidget" name="widget_statistics" native="true"/> + <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"/> + </item> + </layout> + </widget> </item> <item> - <widget class="QmitkHistogramVisualizationWidget" name="widget_histogram" native="true"/> + <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="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> + <customwidget> + <class>QmitkDataStorageComboBoxWithSelectNone</class> + <extends>QComboBox</extends> + <header location="global">QmitkDataStorageComboBoxWithSelectNone.h</header> + </customwidget> </customwidgets> <resources/> <connections/> </ui>