Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
Step10.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 
13 #include "Step10.h"
14 #include "mitkInternalEvent.h"
15 #include "mitkMouseMoveEvent.h"
16 #include "mitkRenderingManager.h"
17 #include <mitkPointOperation.h>
18 //
19 #include "mitkBaseRenderer.h"
20 #include "mitkDispatcher.h"
21 #include <mitkPropertyList.h>
22 
24 {
25  // connect the action and condition names of the state machine pattern with function within
26  // this DataInteractor
27  CONNECT_CONDITION("checkPoint", CheckPoint);
28  CONNECT_FUNCTION("addPoint", AddPoint);
29  CONNECT_FUNCTION("enoughPoints", EnoughPoints);
30 }
31 
32 bool mitk::ExampleInteractor::CheckPoint(const InteractionEvent *interactionEvent)
33 {
34  // check if a point close to the clicked position already exists
35  float epsilon = 0.3; // do not accept new points within 3mm range of existing points
36  InteractionPositionEvent *positionEvent = dynamic_cast<InteractionPositionEvent *>(interactionEvent);
37  if (positionEvent != nullptr)
38  {
39  // query the position of the mouse in the world geometry
40  mitk::Point3D point = positionEvent->GetPositionInWorld();
41  int retVal = m_PointSet->SearchPoint(point, epsilon);
42  if (retVal == -1) // SearchPoint returns -1 if no point was found within given range
43  return true;
44  }
45  return false; // if the positionEvent is nullptr or a point was found return false. AddPoint will not be executed
46  // end
47 }
48 
49 bool mitk::ExampleInteractor::AddPoint(StateMachineAction *, InteractionEvent *interactionEvent)
50 {
51  // cast InteractionEvent to a position event in order to read out the mouse position
52  // we stay here as general as possible so that a different state machine pattern
53  // can reuse this code with MouseRelease or MouseMoveEvents.
54  InteractionPositionEvent *positionEvent = dynamic_cast<InteractionPositionEvent *>(interactionEvent);
55  if (positionEvent != nullptr)
56  {
57  // query the position of the mouse in the world geometry
58  mitk::Point3D point = positionEvent->GetPositionInWorld();
59  m_PointSet->InsertPoint(m_NumberOfPoints, point, 0);
60  m_NumberOfPoints++;
61  GetDataNode()->SetData(m_PointSet);
62  GetDataNode()->Modified();
63 
64  if (m_NumberOfPoints != 0 && m_NumberOfPoints >= m_MaximalNumberOfPoints)
65  {
66  // create internal event that signal that the maximal number of points is reached
67  InternalEvent::Pointer event = InternalEvent::New(nullptr, this, "enoughPointsAdded");
68  // add the internal event to the event queue of the Dispatcher
69  positionEvent->GetSender()->GetDispatcher()->QueueEvent(event.GetPointer());
70  }
71  // update the RenderWindow to show new points
73  return true;
74  }
75  else
76  {
77  return false;
78  }
79 }
80 
81 bool mitk::ExampleInteractor::EnoughPoints(StateMachineAction *, InteractionEvent *)
82 {
83  GetDataNode()->SetProperty("contourcolor", ColorProperty::New(1.0, 1.0, 0.0));
85  return true;
86 } //-
87 
89 {
90  m_NumberOfPoints = 0;
91  m_MaximalNumberOfPoints = 0;
92  m_PointSet = PointSet::New(); // create PointSet to store our point in
93 }
94 
96 {
97 }
98 
100 {
101  // read how many points we accept from the config properties
102  mitk::PropertyList::Pointer properties = GetPropertyList();
103  std::string maxNumber;
104  properties->GetStringProperty("NumberOfPoints", maxNumber);
105  m_MaximalNumberOfPoints = atoi(maxNumber.c_str());
106 }
virtual ~ExampleInteractor()
Definition: Step10.cpp:95
Super class for all position events.
static Pointer New()
static Pointer New()
virtual void SetData(mitk::BaseData *baseData)
Set the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
virtual void ConfigurationChanged()
Definition: Step10.cpp:99
DataNode * GetDataNode() const
BaseRenderer * GetSender() const
void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName="", bool fallBackOnDefaultContext=false) override
Add new or change existent property.
static RenderingManager * GetInstance()
Represents an action, that is executed after a certain event (in statemachine-mechanism) TODO: implem...
virtual void ConnectActionsAndFunctions()
Definition: Step10.cpp:23
#define CONNECT_CONDITION(a, f)
Dispatcher::Pointer GetDispatcher() const
Returns the Dispatcher which handles Events for this BaseRenderer.
static Pointer New(BaseRenderer *_arga, DataInteractor *_argb, const std::string &_argc)
#define CONNECT_FUNCTION(a, f)
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)