Medical Imaging Interaction Toolkit  2016.11.0
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,
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 #include "mitkMouseMoveEvent.h"
19 
20 #include "mitkInteractionConst.h" // TODO: refactor file
21 #include "mitkInternalEvent.h"
22 #include "mitkOperationEvent.h"
23 #include "mitkRenderingManager.h"
24 #include <mitkPointOperation.h>
25 //
26 #include "mitkBaseRenderer.h"
27 #include "mitkDispatcher.h"
28 
29 #include "mitkUndoController.h"
30 
32 {
33  this->SetMaxPoints(1);
34 }
35 
37 {
38 }
39 
41  InteractionEvent *interactionEvent)
42 {
43  unsigned int timeStep = interactionEvent->GetSender()->GetTimeStep(GetDataNode()->GetData());
44  ScalarType timeInMs = interactionEvent->GetSender()->GetTime();
45 
46  // To add a point the minimal information is the position, this method accepts all InteractionsPositionEvents
47  InteractionPositionEvent *positionEvent = dynamic_cast<InteractionPositionEvent *>(interactionEvent);
48  if (positionEvent != NULL)
49  {
50  PointOperation *doOp;
51  PointOperation *undoOp;
52 
53  if (m_PointSet->IndexExists(0, timeStep))
54  {
55  PointSet::PointType pt = m_PointSet->GetPoint(0, timeStep);
56  Point3D itkPoint;
57  itkPoint[0] = pt[0];
58  itkPoint[1] = pt[1];
59  itkPoint[2] = pt[2];
60 
61  doOp = new mitk::PointOperation(OpMOVE, timeInMs, positionEvent->GetPositionInWorld(), 0);
62  undoOp = new mitk::PointOperation(OpMOVE, timeInMs, itkPoint, 0);
63  }
64  else
65  {
66  doOp = new mitk::PointOperation(OpINSERT, timeInMs, positionEvent->GetPositionInWorld(), 0);
67  undoOp = new mitk::PointOperation(OpREMOVE, timeInMs, positionEvent->GetPositionInWorld(), 0);
68  }
69 
70  if (m_UndoEnabled)
71  {
72  OperationEvent *operationEvent = new OperationEvent(m_PointSet, doOp, undoOp, "Move point");
74 
75  m_UndoController->SetOperationEvent(operationEvent);
76  }
77  // execute the Operation
78  m_PointSet->ExecuteOperation(doOp);
79 
80  if (!m_UndoEnabled)
81  delete doOp;
82 
83  // Request update
84  interactionEvent->GetSender()->GetRenderingManager()->RequestUpdateAll();
85  }
86 }
87 
88 /*
89  * Check whether the DataNode contains a pointset, if not create one and add it.
90  */
92 {
93  if (GetDataNode() != nullptr)
94  {
95  PointSet *points = dynamic_cast<PointSet *>(GetDataNode()->GetData());
96  if (points == NULL)
97  {
98  m_PointSet = PointSet::New();
99  GetDataNode()->SetData(m_PointSet);
100  }
101  else
102  {
103  points->Clear();
104  m_PointSet = points;
105  }
106  }
107 }
Super class for all position events.
BaseRenderer * GetSender() const
double ScalarType
static Pointer New()
ScalarType GetTime() const
Get the time in ms of the currently displayed content.
Constants for most interaction classes, due to the generic StateMachines.
virtual void SetMaxPoints(unsigned int=0)
SetMaxPoints Sets the maximal number of points for the pointset Overwritten, per design this class wi...
T::Pointer GetData(const std::string &name)
Data structure which stores a set of points. Superclass of mitk::Mesh.
Definition: mitkPointSet.h:79
virtual mitk::RenderingManager * GetRenderingManager() const
Setter for the RenderingManager that handles this instance of BaseRenderer.
Represents an action, that is executed after a certain event (in statemachine-mechanism) TODO: implem...
Operation that handles all actions on one Point.
virtual unsigned int GetTimeStep() const
virtual void AddPoint(StateMachineAction *, InteractionEvent *event) override
virtual void Clear()
Calls ClearData() and InitializeEmpty();.
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.