Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkSinglePointDataInteractor.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 #include "mitkMouseMoveEvent.h"
15 
16 #include "mitkInteractionConst.h" // TODO: refactor file
17 #include "mitkInternalEvent.h"
18 #include "mitkOperationEvent.h"
19 #include "mitkRenderingManager.h"
20 #include <mitkPointOperation.h>
21 //
22 #include "mitkBaseRenderer.h"
23 #include "mitkDispatcher.h"
24 
25 #include "mitkUndoController.h"
26 
28 {
29  this->SetMaxPoints(1);
30 }
31 
33 {
34 }
35 
37  InteractionEvent *interactionEvent)
38 {
39  unsigned int timeStep = interactionEvent->GetSender()->GetTimeStep(GetDataNode()->GetData());
40  ScalarType timeInMs = interactionEvent->GetSender()->GetTime();
41 
42  // To add a point the minimal information is the position, this method accepts all InteractionsPositionEvents
43  auto *positionEvent = dynamic_cast<InteractionPositionEvent *>(interactionEvent);
44  if (positionEvent != nullptr)
45  {
46  PointOperation *doOp;
47  PointOperation *undoOp;
48 
49  if (m_PointSet->IndexExists(0, timeStep))
50  {
51  PointSet::PointType pt = m_PointSet->GetPoint(0, timeStep);
52  Point3D itkPoint;
53  itkPoint[0] = pt[0];
54  itkPoint[1] = pt[1];
55  itkPoint[2] = pt[2];
56 
57  doOp = new mitk::PointOperation(OpMOVE, timeInMs, positionEvent->GetPositionInWorld(), 0);
58  undoOp = new mitk::PointOperation(OpMOVE, timeInMs, itkPoint, 0);
59  }
60  else
61  {
62  doOp = new mitk::PointOperation(OpINSERT, timeInMs, positionEvent->GetPositionInWorld(), 0);
63  undoOp = new mitk::PointOperation(OpREMOVE, timeInMs, positionEvent->GetPositionInWorld(), 0);
64  }
65 
66  if (m_UndoEnabled)
67  {
68  OperationEvent *operationEvent = new OperationEvent(m_PointSet, doOp, undoOp, "Move point");
70 
71  m_UndoController->SetOperationEvent(operationEvent);
72  }
73  // execute the Operation
74  m_PointSet->ExecuteOperation(doOp);
75 
76  if (!m_UndoEnabled)
77  delete doOp;
78 
80  }
81 }
82 
83 /*
84  * Check whether the DataNode contains a pointset, if not create one and add it.
85  */
87 {
88  if (GetDataNode() != nullptr)
89  {
90  auto *points = dynamic_cast<PointSet *>(GetDataNode()->GetData());
91  if (points == nullptr)
92  {
95  }
96  else
97  {
98  points->Clear();
99  m_PointSet = points;
100  }
101  }
102 }
ScalarType GetTime() const
Get the time in ms of the currently displayed content.
Super class for all position events.
double ScalarType
static Pointer New()
virtual void SetData(mitk::BaseData *baseData)
Set the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
Constants for most interaction classes, due to the generic StateMachines.
bool SetOperationEvent(UndoStackItem *operationEvent)
DataNode * GetDataNode() const
virtual void SetMaxPoints(unsigned int=0)
SetMaxPoints Sets the maximal number of points for the pointset Overwritten, per design this class wi...
BaseRenderer * GetSender() const
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
Data structure which stores a set of points. Superclass of mitk::Mesh.
Definition: mitkPointSet.h:75
static RenderingManager * GetInstance()
Represents an action, that is executed after a certain event (in statemachine-mechanism) TODO: implem...
virtual unsigned int GetTimeStep() const
Operation that handles all actions on one Point.
void AddPoint(StateMachineAction *, InteractionEvent *event) override
static void IncCurrObjectEventId()
Increases the current ObjectEventId For example if a button click generates operations the ObjectEven...
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
Represents a pair of operations: undo and the according redo.