13#include "ui_QmitkUSNavigationStepTumourSelection.h"
15#include "usModuleRegistry.h"
17#include "mitkDataNode.h"
18#include "mitkSurface.h"
26#include "mitkIOUtil.h"
28#include "vtkSmartPointer.h"
29#include "vtkDoubleArray.h"
30#include "vtkPolyData.h"
31#include "vtkPointData.h"
32#include "vtkWarpScalar.h"
36 m_targetSelectionOptional(false),
37 m_SecurityDistance(0),
38 m_Interactor(
mitk::USZonesInteractor::New()),
39 m_NodeDisplacementFilter(
mitk::NodeDisplacementFilter::New()),
40 m_StateMachineFilename(
"USZoneInteractions.xml"),
41 m_ReferenceSensorIndex(1),
47 connect(ui->freezeImageButton, SIGNAL(SignalFreezed(
bool)),
this, SLOT(
OnFreeze(
bool)));
48 connect(ui->tumourSizeSlider, SIGNAL(valueChanged(
int)),
this, SLOT(
OnTumourSizeChanged(
int)));
83 this->
GetDataStorage()->ChangedNodeEvent.AddListener(m_ListenerChangeNode);
103 ui->freezeImageButton->Unfreeze();
107 mitk::DataStorage::Pointer dataStorage = this->
GetDataStorage(
false);
108 if (dataStorage.IsNotNull())
113 dataStorage->ChangedNodeEvent.RemoveListener(m_ListenerChangeNode);
118 MITK_INFO(
"QmitkUSAbstractNavigationStep")(
"QmitkUSNavigationStepTumourSelection")
119 <<
"Removing tumour.";
126 ui->tumourSizeExplanationLabel->setEnabled(
false);
127 ui->tumourSizeLabel->setEnabled(
false);
128 ui->tumourSizeSlider->setEnabled(
false);
129 ui->deleteTumourButton->setEnabled(
false);
131 ui->tumourSizeSlider->blockSignals(
true);
132 ui->tumourSizeSlider->setValue(0);
133 ui->tumourSizeSlider->blockSignals(
false);
174 ui->freezeImageButton->Unfreeze();
190 ui->bodyMarkerTrackingStatusLabel->setStyleSheet(
191 "background-color: #8bff8b; margin-right: 1em; margin-left: 1em; border: 1px solid grey");
192 ui->bodyMarkerTrackingStatusLabel->setText(
"Body marker is inside the tracking volume.");
196 ui->bodyMarkerTrackingStatusLabel->setStyleSheet(
197 "background-color: #ff7878; margin-right: 1em; margin-left: 1em; border: 1px solid grey");
198 ui->bodyMarkerTrackingStatusLabel->setText(
"Body marker is not inside the tracking volume.");
201 ui->freezeImageButton->setEnabled(valid);
206 ui->tumourSearchExplanationLabel->setEnabled(valid);
212 if (settingsNode.IsNull()) {
return; }
214 float securityDistance;
215 if (settingsNode->GetFloatProperty(
"settings.security-distance", securityDistance))
220 std::string stateMachineFilename;
221 if (settingsNode->GetStringProperty(
"settings.interaction-concept", stateMachineFilename) && stateMachineFilename !=
m_StateMachineFilename)
224 m_Interactor->LoadStateMachine(stateMachineFilename, us::ModuleRegistry::GetModule(
"MitkUS"));
227 std::string referenceSensorName;
228 if (settingsNode->GetStringProperty(
"settings.reference-name-selected", referenceSensorName))
238 return "Localisation of Tumour Position";
250 ui->tumourSelectionExplanation1Label->setEnabled(freezed);
251 ui->tumourSelectionExplanation2Label->setEnabled(freezed);
269 if (
m_TumourNode->GetBoolProperty(
"zone.created", value) && value)
271 ui->freezeImageButton->setEnabled(
false);
272 ui->tumourSearchExplanationLabel->setEnabled(
false);
281 mitk::AbstractUltrasoundTrackerDevice::Pointer combinedModality = this->
GetCombinedModality(
false);
282 if (combinedModality.IsNotNull())
298 m_TumourNode->SetFloatProperty(
"zone.size",
static_cast<float>(size));
301 MITK_INFO(
"QmitkUSAbstractNavigationStep")(
"QmitkUSNavigationStepTumourSelection")
302 <<
"Changing tumour radius to " << size <<
".";
316 dataNode->GetFloatProperty(
"zone.size", size);
318 ui->tumourSizeSlider->setValue(
static_cast<int>(size));
321 if (dataNode->GetBoolProperty(
"zone.created", created) && created)
323 if (ui->freezeImageButton->isChecked())
330 MITK_INFO(
"QmitkUSAbstractNavigationStep")(
"QmitkUSNavigationStepTumourSelection")
331 <<
"Tumour created with center " << dataNode->GetData()->GetGeometry()->GetOrigin()
332 <<
" and radius " << size <<
".";
334 mitk::DataNode::Pointer tumourResultNode = mitk::DataNode::New();
335 tumourResultNode->SetName(
"TumourResult");
336 tumourResultNode->SetProperty(
"USNavigation::TumourCenter",
337 mitk::Point3dProperty::New(dataNode->GetData()->GetGeometry()->GetOrigin()));
338 tumourResultNode->SetProperty(
"USNavigation::TumourRadius", mitk::DoubleProperty::New(size));
342 ui->freezeImageButton->Unfreeze();
345 ui->tumourSearchExplanationLabel->setEnabled(
false);
346 ui->tumourSizeExplanationLabel->setEnabled(
true);
347 ui->tumourSizeLabel->setEnabled(
true);
348 ui->tumourSizeSlider->setEnabled(
true);
349 ui->deleteTumourButton->setEnabled(
true);
357 mitk::Surface::Pointer tumourSurface =
dynamic_cast<mitk::Surface*
>(
m_TumourNode->GetData());
359 if (tumourSurface.IsNull())
361 MITK_WARN <<
"No target selected, cannot create surface!";
362 return mitk::Surface::New();
367 tumourSurfaceVtk->DeepCopy(tumourSurface->GetVtkPolyData());
371 int numberOfPoints = tumourSurfaceVtk->GetNumberOfPoints();
372 scalars->SetNumberOfTuples(numberOfPoints);
375 for (vtkIdType i = 0; i < numberOfPoints; ++i) { scalars->SetTuple1(i,
m_SecurityDistance * 10); }
376 tumourSurfaceVtk->GetPointData()->SetScalars(scalars);
379 warpScalar->SetInputData(tumourSurfaceVtk);
380 warpScalar->SetScaleFactor(1);
381 warpScalar->Update();
388 tumourSurfaceVtk->SetPoints(targetSurfaceVtk->GetPoints());
390 mitk::Surface::Pointer targetSurface = mitk::Surface::New();
391 targetSurface->SetVtkPolyData(tumourSurfaceVtk);
392 targetSurface->GetGeometry()->SetOrigin(tumourSurface->GetGeometry()->GetOrigin());
394 return targetSurface;
412 catch (
const std::exception &e)
414 MITK_WARN(
"QmitkUSAbstractNavigationStep")(
"QmitkUSNavigationStepTumourSelection")
415 <<
"Cannot get index for reference sensor name: " << e.what();
Abstract base class for navigation step widgets.
itk::SmartPointer< mitk::DataStorage > GetDataStorage(bool throwNull=true)
Returns the data storage set for the navigation step.
NavigationStepState GetNavigationStepState()
Get the current state of the navigation step.
void SignalReadyForNextStep()
Signals that all necessary actions where done. The user can proceed with the next stept after this wa...
static const char * DATANAME_BASENODE
itk::SmartPointer< mitk::DataNode > GetNamedDerivedNodeAndCreate(const char *name, const char *sourceName)
Returns node with the given name and the given source node (parent) from the data storage....
itk::SmartPointer< mitk::AbstractUltrasoundTrackerDevice > GetCombinedModality(bool throwNull=true)
Returns the combined modality set for the navigation step.
std::vector< itk::SmartPointer< mitk::NavigationDataToNavigationDataFilter > > FilterVector
virtual bool OnRestartStep()
Called when restarting a navigation step. This method may be implemented by a concrete subclass to ha...
void SignalIntermediateResult(const itk::SmartPointer< mitk::DataNode >)
Signals that an intermediate result was produced. The properties of the given data node must contain ...
static const char * DATANAME_TUMOUR
static const char * DATANAME_TARGETSURFACE
Navigation step for marking the tumor position and extent. The user can mark the position by interact...
void OnDeleteButtonClicked()
Just restarts the navigation step for deleting the tumour.
bool OnStartStep() override
Initializes tumour and target surface.
void OnTumourSizeChanged(int)
Updates the surface of the tumor node according to the new size.
std::string m_ReferenceSensorName
itk::SmartPointer< mitk::Surface > CreateTargetSurface()
itk::SmartPointer< mitk::DataNode > m_TumourNode
QmitkUSNavigationStepTumourSelection(QWidget *parent=nullptr)
void OnFreeze(bool freezed)
Activates or deactivates the ineractor for tumour creation.
unsigned int m_ReferenceSensorIndex
itk::SmartPointer< mitk::NavigationDataSource > m_NavigationDataSource
itk::SmartPointer< mitk::USZonesInteractor > m_Interactor
void OnSetCombinedModality() override
Called every time SetCombinedModality() was called. This method may be implemented by a concrete subc...
std::string m_StateMachineFilename
QString GetTitle() override
Getter for the title of the navigation step. This title should be human readable and can be used to d...
bool OnFinishStep() override
(Re)creates the target surface.
itk::SmartPointer< mitk::NodeDisplacementFilter > m_NodeDisplacementFilter
void SetTumorColor(mitk::Color c)
void TumourNodeChanged(const mitk::DataNode *)
bool OnRestartStep() override
Reinitializes buttons and sliders in addition of calling the default implementation.
FilterVector GetFilter() override
itk::SmartPointer< mitk::DataNode > m_TargetSurfaceNode
bool OnActivateStep() override
Initializes (but not activates) the interactor for tumour selection.
void UpdateReferenceSensorName()
bool OnStopStep() override
Removes target surface and tumour node from the data storage. Additionally an unfreeze is done and th...
mitk::Color m_SphereColor
void OnSettingsChanged(const itk::SmartPointer< mitk::DataNode > settingsNode) override
~QmitkUSNavigationStepTumourSelection() override
bool m_targetSelectionOptional
void OnUpdate() override
Updates tracking validity status and checks tumour node for the end of tumour creation.
itk::SmartPointer< mitk::NodeDisplacementFilter > GetTumourNodeDisplacementFilter()
bool OnDeactivateStep() override
Deactivates the interactor for tumour selection and removes data of the tumour node if selection wasn...
void SetTargetSelectionOptional(bool t)
static void UpdateSurface(itk::SmartPointer< mitk::DataNode >)
Creates Vtk Sphere according to current radius. The radius is gotten from the float property "zone....