diff --git a/Plugins/org.mitk.gui.qt.activelearning/src/internal/QmitkActiveLearning.cpp b/Plugins/org.mitk.gui.qt.activelearning/src/internal/QmitkActiveLearning.cpp index 595b03ad14..d1530846e4 100644 --- a/Plugins/org.mitk.gui.qt.activelearning/src/internal/QmitkActiveLearning.cpp +++ b/Plugins/org.mitk.gui.qt.activelearning/src/internal/QmitkActiveLearning.cpp @@ -1,151 +1,200 @@ /*=================================================================== 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. ===================================================================*/ // Blueberry #include #include // Qmitk #include "QmitkActiveLearning.h" #include // MITK #include +#include #include #include +// Create an image filled with zeros that has the geometry of a template image +template +static mitk::Image::Pointer MakeZeroImage(const mitk::Image* templateImage) +{ + auto zeroImage = mitk::Image::New(); + const mitk::PixelType pixelType(mitk::MakeScalarPixelType()); + zeroImage->Initialize(pixelType, templateImage->GetDimension(), templateImage->GetDimensions()); + zeroImage->SetClonedTimeGeometry(templateImage->GetTimeGeometry()); + unsigned int size = sizeof(PixelType); + for (unsigned int dim = 0; dim < zeroImage->GetDimension(); ++dim) + { + size *= zeroImage->GetDimension(dim); + } + mitk::ImageWriteAccessor imageAccessor(zeroImage); + memset(imageAccessor.GetData(), 0, size); + + return zeroImage; +} + +// Returns true if list has at least one entry and all entries are valid mitk::Images, otherwise false +static bool SelectionAllImages(const QList& nodes) +{ + if (nodes.empty()) + { + return false; + } + for (const auto& node : nodes) + { + if(!(node.IsNotNull() && dynamic_cast(node->GetData()) != nullptr)) return false; + } + return true; +} + + /* ================================================================== - * PUBLIC + * PUBLIC SLOTS * =============================================================== */ -const std::string ActiveLearning::VIEW_ID = "org.mitk.views.activelearning"; - void ActiveLearning::Initialize() { auto nodes = this->GetDataManagerSelection(); // CALCULATE FEATURES HERE - // Create label interaction widget -// QmitkLabelSetWidget labelSetWidget = QmitkLabelSetWidget(); -// m_Controls.labelControlsFrame->layout()->addWidget(&labelSetWidget); m_Controls.labelControlsFrame->setVisible(true); } +/* ================================================================== + * PUBLIC + * =============================================================== */ + + +const std::string ActiveLearning::VIEW_ID = "org.mitk.views.activelearning"; + + +/* ================================================================== + * PROTECTED SLOTS + * =============================================================== */ + + +void ActiveLearning::OnAddLabelPushButtonClicked() +{ + +} + +void ActiveLearning::OnRemoveLabelPushButtonClicked() +{ + +} + +void ActiveLearning::OnPaintToolButtonClicked() +{ + +} + +void ActiveLearning::OnEraseToolButtonClicked() +{ + +} + + /* ================================================================== * PROTECTED * =============================================================== */ void ActiveLearning::CreateQtPartControl( QWidget *parent ) { m_Controls.setupUi(parent); // Connections connect(m_Controls.initializePushButton, SIGNAL(clicked(bool)), this, SLOT(Initialize())); // Set start configuration m_Controls.labelControlsFrame->setVisible(false); SetInitializeReady(false); } void ActiveLearning::OnSelectionChanged(berry::IWorkbenchPart::Pointer source, const QList& nodes) { - if (nodes.empty()) - { - SetInitializeReady(false); - return; - } - - mitk::DataNode::Pointer referenceNode = nodes[0]; - if (referenceNode.IsNull() || dynamic_cast(referenceNode->GetData()) == nullptr) + if (!SelectionAllImages(nodes)) { - MITK_DEBUG << "Could not find image in selected node: 0"; SetInitializeReady(false); return; } if (nodes.length() >= 2) { // First selection is the reference (could be any other) - mitk::Image::Pointer referenceImage = dynamic_cast(referenceNode->GetData()); + mitk::Image::Pointer referenceImage = dynamic_cast(nodes[0]->GetData()); mitk::BaseGeometry* referenceGeometry = referenceImage->GetTimeGeometry()->GetGeometryForTimeStep(0); // This needs to be current timestep for (int i=1; i(nodes[i]->GetData()) == nullptr) - { - MITK_DEBUG << "Could not find image in selected node: " << i; - SetInitializeReady(false); - return; - } - mitk::Image::Pointer currentImage = dynamic_cast(nodes[i]->GetData()); mitk::BaseGeometry* currentGeometry = currentImage->GetTimeGeometry()->GetGeometryForTimeStep(0); // This needs to be current timestep if (!mitk::Equal(*currentGeometry, *referenceGeometry, mitk::eps, true)) { SetInitializeReady(false); return; } } } // All nodes have the same geometry, allow init SetInitializeReady(true); } void ActiveLearning::SetFocus() { } /* ================================================================== * PRIVATE * =============================================================== */ void ActiveLearning::SetInitializeReady(bool ready) { if (ready) { - // get selection - QList nodes = this->GetDataManagerSelection(); - if (nodes.length() == 0) return; + // get selection, check again just to be sure + auto nodes = this->GetDataManagerSelection(); + if (!SelectionAllImages(nodes)) return; m_Controls.initializePushButton->setEnabled(true); QString nameList = QString::fromStdString(nodes[0]->GetName()); if (nodes.length() >= 2) { for (int i=1; i"); nameList += QString::fromStdString(nodes[i]->GetName()); } } m_Controls.initializeLabel->setText(nameList); } else { m_Controls.initializePushButton->setDisabled(true); m_Controls.initializeLabel->setText("Selected images must have matching geometries"); } } diff --git a/Plugins/org.mitk.gui.qt.activelearning/src/internal/QmitkActiveLearning.h b/Plugins/org.mitk.gui.qt.activelearning/src/internal/QmitkActiveLearning.h index 554d4bf648..3aee523478 100644 --- a/Plugins/org.mitk.gui.qt.activelearning/src/internal/QmitkActiveLearning.h +++ b/Plugins/org.mitk.gui.qt.activelearning/src/internal/QmitkActiveLearning.h @@ -1,67 +1,76 @@ /*=================================================================== 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 ActiveLearning_h #define ActiveLearning_h #include #include #include "ui_QmitkActiveLearningControls.h" /** \brief ActiveLearning \warning This class is not yet documented. Use "git blame" and ask the author to provide basic documentation. \sa QmitkAbstractView \ingroup ${plugin_target}_internal */ class ActiveLearning : public QmitkAbstractView { Q_OBJECT public slots: void Initialize(); public: typedef float SegmentationType; static const std::string VIEW_ID; protected slots: + void OnAddLabelPushButtonClicked(); + + void OnRemoveLabelPushButtonClicked(); + + void OnPaintToolButtonClicked(); + + void OnEraseToolButtonClicked(); + protected: void CreateQtPartControl(QWidget *parent) override; - void OnSelectionChanged(berry::IWorkbenchPart::Pointer source, const QList& nodes) override; + void OnSelectionChanged(berry::IWorkbenchPart::Pointer source, + const QList& nodes) override; void SetFocus() override; Ui::ActiveLearningControls m_Controls; private: void SetInitializeReady(bool ready); }; #endif // ActiveLearning_h diff --git a/Plugins/org.mitk.gui.qt.activelearning/src/internal/QmitkActiveLearningControls.ui b/Plugins/org.mitk.gui.qt.activelearning/src/internal/QmitkActiveLearningControls.ui index 66e79491e4..dbd7ac0c83 100644 --- a/Plugins/org.mitk.gui.qt.activelearning/src/internal/QmitkActiveLearningControls.ui +++ b/Plugins/org.mitk.gui.qt.activelearning/src/internal/QmitkActiveLearningControls.ui @@ -1,148 +1,230 @@ ActiveLearningControls 0 0 352 532 0 0 QmitkTemplate Initialize with selection false false false false <font color="red">Selection must have matching dimensions and transforms</font> true QFrame::NoFrame QFrame::Raised 0 0 0 0 QFrame::NoFrame QFrame::Raised 0 0 0 0 - + - Add Label + Add Label - + - Remove Label + Remove Label Qt::Horizontal - - QSizePolicy::Minimum - - 6 + 40 20 + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + ... + + + true + + + true + + + + + + + + 0 + 0 + + + + + 0 + 40 + + + + ... + + + true + + + true + + + + + + Qt::Vertical 20 40 + + + QmitkLabelSetWidget + QWidget +
QmitkLabelSetWidget.h
+ 1 +
+