Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 
19 #include "mitkToolManager.h"
20 
21 #include "mitkBaseRenderer.h"
22 #include "mitkRenderingManager.h"
23 
25 
26 #include <mitkInteractionConst.h>
27 
29 {
30 }
31 
33 {
34  CONNECT_CONDITION("checkisOverPoint", OnCheckPointClick);
35  CONNECT_CONDITION("mouseMove", IsHovering);
36 
37  CONNECT_FUNCTION("movePoints", OnMovePoint);
38  CONNECT_FUNCTION("deletePoint", OnDeletePoint);
39  CONNECT_FUNCTION("finish", OnFinishEditing);
40 }
41 
43 {
44 }
45 
47 {
48  const InteractionPositionEvent *positionEvent =
49  dynamic_cast<const mitk::InteractionPositionEvent *>(interactionEvent);
50  if (!positionEvent)
51  return false;
52 
53  int timestep = positionEvent->GetSender()->GetTimeStep();
54 
55  mitk::ContourModel *contour = dynamic_cast<mitk::ContourModel *>(this->GetDataNode()->GetData());
56 
57  contour->Deselect();
58 
59  mitk::Point3D click = positionEvent->GetPositionInWorld();
60 
61  if (contour->SelectVertexAt(click, 1.5, timestep))
62  {
65  m_lastMousePosition = click;
66 
67  mitk::Geometry3D *contourGeometry = dynamic_cast<Geometry3D *>(contour->GetGeometry(timestep));
68 
69  if (contourGeometry->IsInside(click))
70  {
71  m_lastMousePosition = click;
72  return true;
73  }
74  else
75  return false;
76  }
77  else
78  {
79  return false;
80  }
81  return true;
82 }
83 
85 {
86  mitk::ContourModel *contour = dynamic_cast<mitk::ContourModel *>(this->GetDataNode()->GetData());
87  contour->RemoveVertex(contour->GetSelectedVertex());
88 }
89 
91 {
92  const InteractionPositionEvent *positionEvent = dynamic_cast<const InteractionPositionEvent *>(interactionEvent);
93  if (!positionEvent)
94  return false;
95 
96  int timestep = positionEvent->GetSender()->GetTimeStep();
97 
98  mitk::ContourModel *contour = dynamic_cast<mitk::ContourModel *>(this->GetDataNode()->GetData());
99 
100  mitk::Point3D currentPosition = positionEvent->GetPositionInWorld();
101 
102  bool isHover = false;
103  this->GetDataNode()->GetBoolProperty("contour.hovering", isHover, positionEvent->GetSender());
104  if (contour->IsNearContour(currentPosition, 1.5, timestep))
105  {
106  if (isHover == false)
107  {
108  this->GetDataNode()->SetBoolProperty("contour.hovering", true);
110  }
111  }
112  else
113  {
114  if (isHover == true)
115  {
116  this->GetDataNode()->SetBoolProperty("contour.hovering", false);
118  }
119  }
120  return false;
121 }
122 
124 {
125  const InteractionPositionEvent *positionEvent = dynamic_cast<const InteractionPositionEvent *>(interactionEvent);
126  if (!positionEvent)
127  return;
128 
129  mitk::ContourModel *contour = dynamic_cast<mitk::ContourModel *>(this->GetDataNode()->GetData());
130 
131  mitk::Vector3D translation;
132  mitk::Point3D currentPosition = positionEvent->GetPositionInWorld();
133  translation[0] = currentPosition[0] - this->m_lastMousePosition[0];
134  translation[1] = currentPosition[1] - this->m_lastMousePosition[1];
135  translation[2] = currentPosition[2] - this->m_lastMousePosition[2];
136  contour->ShiftSelectedVertex(translation);
137 
138  this->m_lastMousePosition = positionEvent->GetPositionInWorld();
140 }
141 
143 {
144  const InteractionPositionEvent *positionEvent = dynamic_cast<const InteractionPositionEvent *>(interactionEvent);
145  if (!positionEvent)
146  return;
147 
148  int timestep = positionEvent->GetSender()->GetTimeStep();
149 
150  mitk::ContourModel *contour = dynamic_cast<mitk::ContourModel *>(this->GetDataNode()->GetData());
151  mitk::Vector3D translation;
152  mitk::Point3D currentPosition = positionEvent->GetPositionInWorld();
153  translation[0] = currentPosition[0] - this->m_lastMousePosition[0];
154  translation[1] = currentPosition[1] - this->m_lastMousePosition[1];
155  translation[2] = currentPosition[2] - this->m_lastMousePosition[2];
156  contour->ShiftContour(translation, timestep);
157 
158  this->m_lastMousePosition = positionEvent->GetPositionInWorld();
159 
161 }
162 
164 {
165  mitk::ContourModel *contour = dynamic_cast<mitk::ContourModel *>(this->GetDataNode()->GetData());
166  contour->Deselect();
168 }
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)
BaseRenderer * GetSender() const
void Deselect()
Deselect vertex.
Constants for most interaction classes, due to the generic StateMachines.
bool SelectVertexAt(int index, int timestep=0)
Mark a vertex at an index in the container as selected.
virtual void ConnectActionsAndFunctions() override
virtual bool IsNearContour(mitk::Point3D &point, float eps, int timestep)
Check if mouse cursor is near the contour.
VertexType * GetSelectedVertex()
Get the current selected vertex.
static RenderingManager * GetInstance()
Represents an action, that is executed after a certain event (in statemachine-mechanism) TODO: implem...
void ShiftSelectedVertex(mitk::Vector3D &translate)
Shift the currently selected vertex by a translation vector.
virtual mitk::BaseGeometry * GetGeometry(int t=0) const
Get the BaseGeometry for timestep t.
void SetSelectedVertexAsControlPoint(bool isControlPoint=true)
Set selected vertex as control point.
virtual bool IsHovering(const InteractionEvent *interactionEvent)
void ShiftContour(mitk::Vector3D &translate, int timestep=0)
Shift the whole contour by a translation vector at given timestep.
virtual unsigned int GetTimeStep() const
void RequestUpdate(vtkRenderWindow *renderWindow)
#define CONNECT_CONDITION(a, f)
virtual void OnDeletePoint(StateMachineAction *, InteractionEvent *interactionEvent)
#define CONNECT_FUNCTION(a, f)
bool IsInside(const mitk::Point3D &p) const
Test whether the point p (world coordinates in mm) is inside the bounding box.
bool RemoveVertex(const VertexType *vertex, int timestep=0)
Remove a vertex at given timestep within the container.
virtual void OnMoveContour(StateMachineAction *, InteractionEvent *interactionEvent)
vtkRenderWindow * GetRenderWindow() const
Access the RenderWindow into which this renderer renders.
virtual bool OnCheckPointClick(const InteractionEvent *interactionEvent)