MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkUSZonesInteractor.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
14#include "mitkDataStorage.h"
15#include "mitkDataNode.h"
16#include "mitkSurface.h"
17#include "mitkInteractionPositionEvent.h"
18
19#include <vtkSphereSource.h>
20
23
24void mitk::USZonesInteractor::UpdateSurface(mitk::DataNode::Pointer dataNode)
25{
26 if (!dataNode->GetData())
27 {
28 MITK_WARN("USZonesInteractor")("DataInteractor")
29 << "Cannot update surface for node as no data is set to the node.";
30 return;
31 }
32
33 mitk::Point3D origin = dataNode->GetData()->GetGeometry()->GetOrigin();
34
35 float radius;
36 if (!dataNode->GetFloatProperty(DATANODE_PROPERTY_SIZE, radius))
37 {
38 MITK_WARN("USZonesInteractor")("DataInteractor")
39 << "Cannut update surface for node as no radius is specified in the node properties.";
40 return;
41 }
42
43 mitk::Surface::Pointer zone = mitk::Surface::New();
44
45 // create a vtk sphere with given radius
47 vtkSphere->SetRadius(radius);
48 vtkSphere->SetCenter(0, 0, 0);
49 vtkSphere->SetPhiResolution(20);
50 vtkSphere->SetThetaResolution(20);
51 vtkSphere->Update();
52 zone->SetVtkPolyData(vtkSphere->GetOutput());
53
54 // set vtk sphere and origin to data node (origin must be set
55 // again, because of the new sphere set as data)
56 dataNode->SetData(zone);
57 dataNode->GetData()->GetGeometry()->SetOrigin(origin);
58
59 // update the RenderWindow to show the changed surface
60 mitk::RenderingManager::GetInstance()->RequestUpdateAll();
61}
62
66
70
72{
73 CONNECT_FUNCTION("addCenter", AddCenter);
74 CONNECT_FUNCTION("changeRadius", ChangeRadius);
75 CONNECT_FUNCTION("endCreation", EndCreation);
76 CONNECT_FUNCTION("abortCreation", AbortCreation);
77}
78
80{
81 mitk::DataNode::Pointer dataNode = this->GetDataNode();
82 if (dataNode.IsNotNull() && dataNode->GetData() == nullptr)
83 {
84 dataNode->SetData(mitk::Surface::New());
85 }
86}
87
88void mitk::USZonesInteractor::AddCenter(mitk::StateMachineAction*, mitk::InteractionEvent* interactionEvent)
89{
90 // cast InteractionEvent to a position event in order to read out the mouse position
91 mitk::InteractionPositionEvent* positionEvent = dynamic_cast<mitk::InteractionPositionEvent*>(interactionEvent);
92 mitk::DataNode::Pointer dataNode = this->GetDataNode();
93 dataNode->SetBoolProperty(DATANODE_PROPERTY_CREATED, false);
94
95 // make sure that data node contains data
96 mitk::BaseData::Pointer dataNodeData = this->GetDataNode()->GetData();
97 if (dataNodeData.IsNull())
98 {
99 dataNodeData = mitk::Surface::New();
100 this->GetDataNode()->SetData(dataNodeData);
101 }
102
103 // set origin of the data node to the mouse click position
104 dataNodeData->GetGeometry()->SetOrigin(positionEvent->GetPositionInWorld());
105 MITK_INFO("USNavigationLogging") << "Critical Structure added on position " << positionEvent->GetPointerPositionOnScreen() << " (Image Coordinates); "
106 << positionEvent->GetPositionInWorld() << " (World Coordinates)";
107
108 dataNode->SetFloatProperty("opacity", 0.60f);
109
110 //return true;
111}
112
113void mitk::USZonesInteractor::ChangeRadius(mitk::StateMachineAction*, mitk::InteractionEvent* interactionEvent)
114{
115 // cast InteractionEvent to a position event in order to read out the mouse position
116 mitk::InteractionPositionEvent* positionEvent = dynamic_cast<mitk::InteractionPositionEvent*>(interactionEvent);
117 mitk::DataNode::Pointer curNode = this->GetDataNode();
118 mitk::Point3D mousePosition = positionEvent->GetPositionInWorld();
119
120 mitk::ScalarType radius = mousePosition.EuclideanDistanceTo(curNode->GetData()->GetGeometry()->GetOrigin());
121 curNode->SetFloatProperty(DATANODE_PROPERTY_SIZE, radius);
122
124
125 //return true;
126}
127
128void mitk::USZonesInteractor::EndCreation(mitk::StateMachineAction*, mitk::InteractionEvent* /*interactionEvent*/)
129{
130 this->GetDataNode()->SetBoolProperty(DATANODE_PROPERTY_CREATED, true);
131 //return true;
132}
133
134void mitk::USZonesInteractor::AbortCreation(mitk::StateMachineAction*, mitk::InteractionEvent*)
135{
136 this->GetDataNode()->SetData(mitk::Surface::New());
137
138 // update the RenderWindow to remove the surface
139 mitk::RenderingManager::GetInstance()->RequestUpdateAll();
140
141 //return true;
142}
static void UpdateSurface(itk::SmartPointer< mitk::DataNode >)
Creates Vtk Sphere according to current radius. The radius is gotten from the float property "zone....
void AddCenter(StateMachineAction *, InteractionEvent *)
Sets origin of the data node to the coordinates of the position event.
void ChangeRadius(StateMachineAction *, InteractionEvent *)
Updates radius attribute according to position event. Calculates distance between the data node origi...
static const char * DATANODE_PROPERTY_SIZE
void EndCreation(StateMachineAction *, InteractionEvent *)
Sets the property "zone.created" of the data node to true.
static const char * DATANODE_PROPERTY_CREATED
void ConnectActionsAndFunctions() override
Connects the functions from the state machine to methods of this class.
void DataNodeChanged() override
Sets empty surface as data for the new data node. This is necessary as data nodes without data do not...
void AbortCreation(StateMachineAction *, InteractionEvent *)
Removes Vtk Sphere from data node.