Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkContourModelInteractor.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 
15 #include "mitkToolManager.h"
16 
17 #include "mitkBaseRenderer.h"
18 #include "mitkRenderingManager.h"
19 
21 
22 #include <mitkInteractionConst.h>
23 
25 {
26 }
27 
29 {
30  CONNECT_CONDITION("checkisOverPoint", OnCheckPointClick);
31  CONNECT_CONDITION("mouseMove", IsHovering);
32 
33  CONNECT_FUNCTION("movePoints", OnMovePoint);
34  CONNECT_FUNCTION("deletePoint", OnDeletePoint);
36 }
37 
39 {
40 }
41 
43 {
44  const auto *positionEvent =
45  dynamic_cast<const mitk::InteractionPositionEvent *>(interactionEvent);
46  if (!positionEvent)
47  return false;
48 
49  int timestep = positionEvent->GetSender()->GetTimeStep();
50 
51  auto *contour = dynamic_cast<mitk::ContourModel *>(this->GetDataNode()->GetData());
52 
53  contour->Deselect();
54 
55  mitk::Point3D click = positionEvent->GetPositionInWorld();
56 
57  if (contour->SelectVertexAt(click, 1.5, timestep))
58  {
59  contour->SetSelectedVertexAsControlPoint();
61  m_lastMousePosition = click;
62 
63  auto *contourGeometry = dynamic_cast<Geometry3D *>(contour->GetGeometry(timestep));
64 
65  if (contourGeometry->IsInside(click))
66  {
67  m_lastMousePosition = click;
68  return true;
69  }
70  else
71  return false;
72  }
73  else
74  {
75  return false;
76  }
77  return true;
78 }
79 
81 {
82  auto *contour = dynamic_cast<mitk::ContourModel *>(this->GetDataNode()->GetData());
83  contour->RemoveVertex(contour->GetSelectedVertex());
84 }
85 
87 {
88  const auto *positionEvent = dynamic_cast<const InteractionPositionEvent *>(interactionEvent);
89  if (!positionEvent)
90  return false;
91 
92  int timestep = positionEvent->GetSender()->GetTimeStep();
93 
94  auto *contour = dynamic_cast<mitk::ContourModel *>(this->GetDataNode()->GetData());
95 
96  mitk::Point3D currentPosition = positionEvent->GetPositionInWorld();
97 
98  bool isHover = false;
99  this->GetDataNode()->GetBoolProperty("contour.hovering", isHover, positionEvent->GetSender());
100  if (contour->IsNearContour(currentPosition, 1.5, timestep))
101  {
102  if (isHover == false)
103  {
104  this->GetDataNode()->SetBoolProperty("contour.hovering", true);
105  mitk::RenderingManager::GetInstance()->RequestUpdate(positionEvent->GetSender()->GetRenderWindow());
106  }
107  }
108  else
109  {
110  if (isHover == true)
111  {
112  this->GetDataNode()->SetBoolProperty("contour.hovering", false);
113  mitk::RenderingManager::GetInstance()->RequestUpdate(positionEvent->GetSender()->GetRenderWindow());
114  }
115  }
116  return false;
117 }
118 
120 {
121  const auto *positionEvent = dynamic_cast<const InteractionPositionEvent *>(interactionEvent);
122  if (!positionEvent)
123  return;
124 
125  auto *contour = dynamic_cast<mitk::ContourModel *>(this->GetDataNode()->GetData());
126 
127  mitk::Vector3D translation;
128  mitk::Point3D currentPosition = positionEvent->GetPositionInWorld();
129  translation[0] = currentPosition[0] - this->m_lastMousePosition[0];
130  translation[1] = currentPosition[1] - this->m_lastMousePosition[1];
131  translation[2] = currentPosition[2] - this->m_lastMousePosition[2];
132  contour->ShiftSelectedVertex(translation);
133 
134  this->m_lastMousePosition = positionEvent->GetPositionInWorld();
135  mitk::RenderingManager::GetInstance()->RequestUpdate(positionEvent->GetSender()->GetRenderWindow());
136 }
137 
139 {
140  const auto *positionEvent = dynamic_cast<const InteractionPositionEvent *>(interactionEvent);
141  if (!positionEvent)
142  return;
143 
144  int timestep = positionEvent->GetSender()->GetTimeStep();
145 
146  auto *contour = dynamic_cast<mitk::ContourModel *>(this->GetDataNode()->GetData());
147  mitk::Vector3D translation;
148  mitk::Point3D currentPosition = positionEvent->GetPositionInWorld();
149  translation[0] = currentPosition[0] - this->m_lastMousePosition[0];
150  translation[1] = currentPosition[1] - this->m_lastMousePosition[1];
151  translation[2] = currentPosition[2] - this->m_lastMousePosition[2];
152  contour->ShiftContour(translation, timestep);
153 
154  this->m_lastMousePosition = positionEvent->GetPositionInWorld();
155 
156  mitk::RenderingManager::GetInstance()->RequestUpdate(positionEvent->GetSender()->GetRenderWindow());
157 }
158 
160 {
161  auto *contour = dynamic_cast<mitk::ContourModel *>(this->GetDataNode()->GetData());
162  contour->Deselect();
164 }
virtual void OnMovePoint(StateMachineAction *, InteractionEvent *interactionEvent)
ContourModel is a structure of linked vertices defining a contour in 3D space. The vertices are store...
Super class for all position events.
Standard implementation of BaseGeometry.
virtual void OnFinishEditing(StateMachineAction *, InteractionEvent *interactionEvent)
void Deselect()
Deselect vertex.
Constants for most interaction classes, due to the generic StateMachines.
bool GetBoolProperty(const char *propertyKey, bool &boolValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for bool properties (instances of BoolProperty)
DataNode * GetDataNode() const
BaseRenderer * GetSender() const
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
static RenderingManager * GetInstance()
Represents an action, that is executed after a certain event (in statemachine-mechanism) TODO: implem...
virtual unsigned int GetTimeStep() const
virtual bool IsHovering(const InteractionEvent *interactionEvent)
void SetBoolProperty(const char *propertyKey, bool boolValue, const mitk::BaseRenderer *renderer=nullptr)
Convenience method for setting boolean properties (instances of BoolProperty)
void RequestUpdate(vtkRenderWindow *renderWindow)
vtkRenderWindow * GetRenderWindow() const
Access the RenderWindow into which this renderer renders.
#define CONNECT_CONDITION(a, f)
virtual void OnDeletePoint(StateMachineAction *, InteractionEvent *interactionEvent)
#define CONNECT_FUNCTION(a, f)
bool RemoveVertex(const VertexType *vertex, int timestep=0)
Remove a vertex at given timestep within the container.
virtual void OnMoveContour(StateMachineAction *, InteractionEvent *interactionEvent)
virtual bool OnCheckPointClick(const InteractionEvent *interactionEvent)