diff --git a/Plugins/org.mitk.gui.qt.examples/src/internal/simplemeasurement/QmitkSimpleMeasurement.cpp b/Plugins/org.mitk.gui.qt.examples/src/internal/simplemeasurement/QmitkSimpleMeasurement.cpp index bbc4eb717e..07d58e3afb 100644 --- a/Plugins/org.mitk.gui.qt.examples/src/internal/simplemeasurement/QmitkSimpleMeasurement.cpp +++ b/Plugins/org.mitk.gui.qt.examples/src/internal/simplemeasurement/QmitkSimpleMeasurement.cpp @@ -1,192 +1,284 @@ /*=================================================================== 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 "QmitkSimpleMeasurement.h" // #include #include #include #include #include #include #include #include #include -/* -QmitkSimpleMeasurement::QmitkSimpleMeasurement(QObject *parent, const char *name, QmitkStdMultiWidget *mitkStdMultiWidget, mitk::DataTreeIteratorBase* it) - : QmitkFunctionality(parent, name, it) , m_MultiWidget(mitkStdMultiWidget), m_Controls(NULL) -{ - SetAvailability(true); -} -*/ + QmitkSimpleMeasurement::~QmitkSimpleMeasurement() { +//remove all measurements when view is closed +for (int i=0; iGetDataStorage()->Remove(m_CreatedDistances.at(i));} +for (int i=0; iGetDataStorage()->Remove(m_CreatedAngles.at(i));} +for (int i=0; iGetDataStorage()->Remove(m_CreatedPaths.at(i));} } void QmitkSimpleMeasurement::Activated() { std::vector selection = this->GetDataManagerSelection(); this->OnSelectionChanged( selection ); + } void QmitkSimpleMeasurement::Deactivated() { std::vector selection; this->OnSelectionChanged( selection ); } void QmitkSimpleMeasurement::AddDistanceSimpleMeasurement() { mitk::PointSet::Pointer pointSet = mitk::PointSet::New(); + + QString name = "Distance " + QString::number(m_CreatedDistances.size()+1); - mitk::DataNode::Pointer _CurrentPointSetNode = mitk::DataNode::New(); - _CurrentPointSetNode->SetData(pointSet); - _CurrentPointSetNode->SetProperty("show contour", mitk::BoolProperty::New(true)); - _CurrentPointSetNode->SetProperty("name", mitk::StringProperty::New("distance")); - _CurrentPointSetNode->SetProperty("show distances", mitk::BoolProperty::New(true)); + mitk::DataNode::Pointer CurrentPointSetNode = mitk::DataNode::New(); + CurrentPointSetNode->SetData(pointSet); + CurrentPointSetNode->SetProperty("show contour", mitk::BoolProperty::New(true)); + CurrentPointSetNode->SetProperty("name", mitk::StringProperty::New(name.toStdString())); + CurrentPointSetNode->SetProperty("show distances", mitk::BoolProperty::New(true)); // add to ds and remember as created - this->GetDataStorage()->Add(_CurrentPointSetNode); - m_CreatedPointSetNodes.push_back( _CurrentPointSetNode ); - + m_CreatedDistances.push_back(CurrentPointSetNode); + this->GetDataStorage()->Add(CurrentPointSetNode); + // make new selection std::vector selection; - selection.push_back( _CurrentPointSetNode ); + selection.push_back( CurrentPointSetNode ); this->FireNodesSelected( selection ); this->OnSelectionChanged( selection ); } void QmitkSimpleMeasurement::AddAngleSimpleMeasurement() { mitk::PointSet::Pointer pointSet = mitk::PointSet::New(); + QString name = "Angle " + QString::number(m_CreatedAngles.size()+1); + mitk::DataNode::Pointer _CurrentPointSetNode = mitk::DataNode::New(); _CurrentPointSetNode->SetData(pointSet); _CurrentPointSetNode->SetProperty("show contour", mitk::BoolProperty::New(true)); - _CurrentPointSetNode->SetProperty("name", mitk::StringProperty::New("angle")); + _CurrentPointSetNode->SetProperty("name", mitk::StringProperty::New(name.toStdString())); _CurrentPointSetNode->SetProperty("show angles", mitk::BoolProperty::New(true)); // add to ds and remember as created this->GetDataStorage()->Add(_CurrentPointSetNode); - m_CreatedPointSetNodes.push_back( _CurrentPointSetNode ); + m_CreatedAngles.push_back( _CurrentPointSetNode ); // make new selection std::vector selection; selection.push_back( _CurrentPointSetNode ); this->FireNodesSelected( selection ); this->OnSelectionChanged( selection ); } void QmitkSimpleMeasurement::AddPathSimpleMeasurement() { mitk::PointSet::Pointer pointSet = mitk::PointSet::New(); + QString name = "Path " + QString::number(m_CreatedPaths.size()+1); + mitk::DataNode::Pointer _CurrentPointSetNode = mitk::DataNode::New(); _CurrentPointSetNode->SetData(pointSet); _CurrentPointSetNode->SetProperty("show contour", mitk::BoolProperty::New(true)); - _CurrentPointSetNode->SetProperty("name", mitk::StringProperty::New("path")); + _CurrentPointSetNode->SetProperty("name", mitk::StringProperty::New(name.toStdString())); _CurrentPointSetNode->SetProperty("show distances", mitk::BoolProperty::New(true)); _CurrentPointSetNode->SetProperty("show angles", mitk::BoolProperty::New(true)); // add to ds and remember as created this->GetDataStorage()->Add(_CurrentPointSetNode); - m_CreatedPointSetNodes.push_back( _CurrentPointSetNode ); + m_CreatedPaths.push_back( _CurrentPointSetNode ); // make new selection std::vector selection; selection.push_back( _CurrentPointSetNode ); this->FireNodesSelected( selection ); this->OnSelectionChanged( selection ); } void QmitkSimpleMeasurement::CreateQtPartControl( QWidget* parent ) { + m_CreatedDistances = std::vector(); + m_CreatedAngles = std::vector(); + m_CreatedPaths = std::vector(); + + m_Controls = new Ui::QmitkSimpleMeasurementControls; m_Controls->setupUi(parent); connect( (QObject*)(m_Controls->pbDistance), SIGNAL(clicked()),(QObject*) this, SLOT(AddDistanceSimpleMeasurement()) ); connect( (QObject*)(m_Controls->pbAngle), SIGNAL(clicked()),(QObject*) this, SLOT(AddAngleSimpleMeasurement()) ); connect( (QObject*)(m_Controls->pbPath), SIGNAL(clicked()),(QObject*) this, SLOT(AddPathSimpleMeasurement()) ); + connect( (QObject*)(m_Controls->m_Finished), SIGNAL(clicked()),(QObject*) this, SLOT(Finished()) ); + + EndEditingMeasurement(); + +} + +void QmitkSimpleMeasurement::Finished() +{ + OnSelectionChanged(std::vector()); } void QmitkSimpleMeasurement::OnSelectionChanged( std::vector nodes ) { mitk::DataNode* selectedNode = 0; if(nodes.size() > 0) selectedNode = nodes.front(); mitk::PointSet* pointSet = 0; if(selectedNode) pointSet = dynamic_cast ( selectedNode->GetData() ); // something else was selected. remove old interactor if (m_PointSetInteractor.IsNotNull()) { mitk::GlobalInteraction::GetInstance()->RemoveInteractor(m_PointSetInteractor); } bool pointsetCreatedByThis = false; // only go further if a pointset was selected if(pointSet) { // see if this pointset was created by us - std::vector::iterator it = std::find( m_CreatedPointSetNodes.begin() - , m_CreatedPointSetNodes.end(), selectedNode); - if(it != m_CreatedPointSetNodes.end()) - pointsetCreatedByThis = true; + std::vector::iterator it = std::find( m_CreatedDistances.begin() + , m_CreatedDistances.end(), selectedNode); + if (it != m_CreatedDistances.end()) pointsetCreatedByThis = true; + + it = std::find( m_CreatedAngles.begin() + , m_CreatedAngles.end(), selectedNode); + if (it != m_CreatedAngles.end()) pointsetCreatedByThis = true; + + it = std::find( m_CreatedPaths.begin() + , m_CreatedPaths.end(), selectedNode); + if (it != m_CreatedPaths.end()) pointsetCreatedByThis = true; } // do nothing if it was not created by us or it is no pointset node or we are not activated if(pointsetCreatedByThis && this->IsActivated()) { // otherwise: set text and add interactor for the pointset m_Controls->selectedPointSet->setText( QString::fromStdString(selectedNode->GetName()) ); mitk::PointSetInteractor::Pointer newPointSetInteractor = mitk::PointSetInteractor::New("pointsetinteractor", selectedNode); mitk::GlobalInteraction::GetInstance()->AddInteractor(newPointSetInteractor); m_PointSetInteractor = newPointSetInteractor; float green[] = { 0, 255, 0 }; float red[] = { 255, 0, 0 }; selectedNode->SetColor(green); if(m_SelectedPointSetNode.IsNotNull()) m_SelectedPointSetNode->SetColor(red); m_SelectedPointSetNode = selectedNode; + StartEditingMeasurement(); } else { - // revert text - m_Controls->selectedPointSet->setText( "None" ); + EndEditingMeasurement(); } } bool QmitkSimpleMeasurement::IsExclusiveFunctionality() const { return true; } void QmitkSimpleMeasurement::NodeRemoved( const mitk::DataNode* node ) { // remove a node if it is destroyed from our created array - std::vector::iterator it = std::find( m_CreatedPointSetNodes.begin() - , m_CreatedPointSetNodes.end(), node); - if(it != m_CreatedPointSetNodes.end()) - m_CreatedPointSetNodes.erase(it); + std::vector::iterator it = std::find( m_CreatedDistances.begin() + , m_CreatedDistances.end(), node); + if(it != m_CreatedDistances.end()) + m_CreatedDistances.erase(it); + + it = std::find( m_CreatedAngles.begin() + , m_CreatedAngles.end(), node); + if(it != m_CreatedAngles.end()) + m_CreatedAngles.erase(it); + + it = std::find( m_CreatedPaths.begin() + , m_CreatedPaths.end(), node); + if(it != m_CreatedPaths.end()) + m_CreatedPaths.erase(it); } + +void QmitkSimpleMeasurement::StartEditingMeasurement() +{ +m_Controls->explain_label->setVisible(true); +m_Controls->m_Finished->setVisible(true); +m_Controls->pbDistance->setEnabled(false); +m_Controls->pbAngle->setEnabled(false); +m_Controls->pbPath->setEnabled(false); +UpdateMeasurementList(); +} + +void QmitkSimpleMeasurement::EndEditingMeasurement() +{ +m_Controls->pbDistance->setEnabled(true); +m_Controls->pbAngle->setEnabled(true); +m_Controls->pbPath->setEnabled(true); +m_Controls->explain_label->setVisible(false); +m_Controls->m_Finished->setVisible(false); +m_Controls->selectedPointSet->setText( "None" ); +UpdateMeasurementList(); +} + +void QmitkSimpleMeasurement::UpdateMeasurementList() +{ +m_Controls->m_MeasurementList->clear(); + +for (int i=0; i(m_CreatedDistances.at(i)->GetData()); + if(points->GetSize()<2) distance = "not available"; + else distance = QString::number(points->GetPoint(0).EuclideanDistanceTo(points->GetPoint(1))) + " mm"; + QString name = QString(m_CreatedDistances.at(i)->GetName().c_str()) + " (" + distance + ")"; + newItem->setText(name); + m_Controls->m_MeasurementList->insertItem(m_Controls->m_MeasurementList->count(), newItem); + } +for (int i=0; iGetName().c_str(); + newItem->setText(name); + m_Controls->m_MeasurementList->insertItem(m_Controls->m_MeasurementList->count(), newItem); + } +for (int i=0; iGetName().c_str(); + newItem->setText(name); + m_Controls->m_MeasurementList->insertItem(m_Controls->m_MeasurementList->count(), newItem); + } + +} \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.examples/src/internal/simplemeasurement/QmitkSimpleMeasurement.h b/Plugins/org.mitk.gui.qt.examples/src/internal/simplemeasurement/QmitkSimpleMeasurement.h index 87ec06a1dc..d3bbceec6c 100644 --- a/Plugins/org.mitk.gui.qt.examples/src/internal/simplemeasurement/QmitkSimpleMeasurement.h +++ b/Plugins/org.mitk.gui.qt.examples/src/internal/simplemeasurement/QmitkSimpleMeasurement.h @@ -1,101 +1,114 @@ /*=================================================================== 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. ===================================================================*/ -#if !defined(QMITK_MEASUREMENT_H__INCLUDED) -#define QMITK_MEASUREMENT_H__INCLUDED +#ifndef MITKSIMPELEMEASUREMENT_H +#define MITKSIMPELEMEASUREMENT_H //#include "QmitkFunctionality.h" #include #include #include #include #include #include "ui_QmitkSimpleMeasurementControls.h" class QmitkStdMultiWidget; //!mm //class QmitkSimpleMeasurementControls; //! /*! \brief SimpleMeasurement Allows to measure distances, angles, etc. \sa QmitkFunctionality \ingroup org_mitk_gui_qt_simplemeasurement_internal */ class QmitkSimpleMeasurement : public QmitkFunctionality { Q_OBJECT public: - QmitkSimpleMeasurement() {} - QmitkSimpleMeasurement(const QmitkSimpleMeasurement& other) - { - Q_UNUSED(other) - throw std::runtime_error("Copy constructor not implemented"); - } + QmitkSimpleMeasurement(){} + + QmitkSimpleMeasurement(const QmitkSimpleMeasurement& other) + { + Q_UNUSED(other) + throw std::runtime_error("Copy constructor not implemented"); + } + + virtual ~QmitkSimpleMeasurement(); virtual void Activated(); virtual void Deactivated(); virtual bool IsExclusiveFunctionality() const; /// /// Called when the selection in the workbench changed /// virtual void OnSelectionChanged(std::vector nodes); virtual void NodeRemoved(const mitk::DataNode* node); protected: // Pseudo Ctor void CreateQtPartControl(QWidget* parent); protected slots: void AddDistanceSimpleMeasurement(); void AddAngleSimpleMeasurement(); void AddPathSimpleMeasurement(); + void Finished(); + protected: + /*! * controls containing sliders for scrolling through the slices */ Ui::QmitkSimpleMeasurementControls * m_Controls; /* * Interactor for performing the simplemeasurements. */ mitk::WeakPointer m_PointSetInteractor; /* * Interactor for performing the simplemeasurements. */ mitk::WeakPointer m_SelectedPointSetNode; - /* - * Node representing the PointSet last created. It is used to delete empty point sets. + /** @brief + * Node representing the PointSets which were created by this application. */ - std::vector m_CreatedPointSetNodes; + std::vector m_CreatedDistances; + std::vector m_CreatedAngles; + std::vector m_CreatedPaths; + + void StartEditingMeasurement(); + void EndEditingMeasurement(); + void UpdateMeasurementList(); + }; #endif // !defined(QMITK_MEASUREMENT_H__INCLUDED) diff --git a/Plugins/org.mitk.gui.qt.examples/src/internal/simplemeasurement/QmitkSimpleMeasurementControls.ui b/Plugins/org.mitk.gui.qt.examples/src/internal/simplemeasurement/QmitkSimpleMeasurementControls.ui index 81cc262a72..6ae2565ac2 100644 --- a/Plugins/org.mitk.gui.qt.examples/src/internal/simplemeasurement/QmitkSimpleMeasurementControls.ui +++ b/Plugins/org.mitk.gui.qt.examples/src/internal/simplemeasurement/QmitkSimpleMeasurementControls.ui @@ -1,199 +1,258 @@ QmitkSimpleMeasurementControls 0 0 - 227 + 398 605 0 0 SimpleMeasurement - + - - - - - - Working PointSet: - - - - - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> + + + + + Working PointSet: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt; font-weight:600;">None</span></p></body></html> - - - - - - - - - - - 0 - 0 - - - - - 150 - 25 - - - - QFrame::NoFrame - - - QFrame::Plain - - - 1 - - - <p align="center">Select one option</p> - - - Qt::AlignVCenter - - - false - - - - - - - calculates the distance between two points - - - Distance - - - false - - - false - - - - - - - calculates the angle between two lines - - - Angle - - - false - - + + + + - - - ArrowCursor - - - false - - - calculates the distance between two or more points - - - Path - - - false - - - false - - - false - - - false - - - false - - - false + + + Qt::Horizontal - - - - 0 - 0 - - - - - 150 - 65 - - - - QFrame::NoFrame - - - QFrame::Plain - - - 1 - - - <p align="center">Hold <i>shift + click</i><br>to insert a point</p> - - - Qt::AlignVCenter - - - false - - + + + + + + + + + + + 0 + 0 + + + + + 0 + 25 + + + + + 110 + 16777215 + + + + QFrame::NoFrame + + + QFrame::Plain + + + 1 + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:7.8pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">Add Measurement:</span></p></body></html> + + + Qt::AlignVCenter + + + false + + + + + + + calculates the distance between two points + + + Distance + + + false + + + false + + + + + + + calculates the angle between two lines + + + Angle + + + false + + + + + + + ArrowCursor + + + false + + + calculates the distance between two or more points + + + Path + + + false + + + false + + + false + + + false + + + false + + + false + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 0 + 0 + + + + + 110 + 65 + + + + QFrame::NoFrame + + + QFrame::Plain + + + 1 + + + <p align="center">Hold <i>shift + click</i><br>to insert a point</p> + + + Qt::AlignVCenter + + + false + + + + + + + Finished + + + + + + Qt::Vertical QSizePolicy::Expanding 20 390