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