Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkTubeGraphDataInteractor.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 <mitkInteractionConst.h>
21 #include <mitkStatusBar.h>
22 
23 #include "mitkTubeGraphPicker.h"
24 
25 #include <vtkCamera.h>
26 #include <vtkInteractorStyle.h>
27 #include <vtkPointData.h>
28 #include <vtkPolyData.h>
29 #include <vtkRenderWindowInteractor.h>
30 
32  : m_LastPickedTube(TubeGraph::ErrorId),
33  m_SecondLastPickedTube(TubeGraph::ErrorId),
34  m_ActivationMode(None),
35  m_ActionMode(AttributationMode)
36 {
37 }
38 
40 {
41 }
42 
44 {
45  // **Conditions** that can be used in the state machine, to ensure that certain conditions are met, before actually
46  // executing an action
47  CONNECT_CONDITION("isOverTube", CheckOverTube);
48 
49  // **Function** in the statmachine patterns also referred to as **Actions**
50  CONNECT_FUNCTION("selectTube", SelectTube);
51  CONNECT_FUNCTION("deselectTube", DeselectTube);
52 }
53 
55 {
56  if (GetDataNode() != nullptr)
57  {
58  if (GetDataNode()->GetData() != NULL)
59  {
60  m_TubeGraph = dynamic_cast<TubeGraph *>(GetDataNode()->GetData());
61  m_TubeGraphProperty = dynamic_cast<TubeGraphProperty *>(
62  m_TubeGraph->GetProperty("Tube Graph.Visualization Information").GetPointer());
63  if (m_TubeGraphProperty.IsNull())
64  MITK_ERROR << "Something went wrong! No tube graph property!";
65  }
66  else
67  m_TubeGraph = NULL;
68  }
69  else
70  m_TubeGraph = NULL;
71 }
72 
74 {
75  const InteractionPositionEvent *positionEvent = dynamic_cast<const InteractionPositionEvent *>(interactionEvent);
76  if (positionEvent == NULL)
77  return false;
78 
79  TubeGraphPicker *picker = new mitk::TubeGraphPicker();
80  picker->SetTubeGraph(m_TubeGraph);
81 
82  TubeGraph::TubeDescriptorType tubeDescriptor = picker->GetPickedTube(positionEvent->GetPositionInWorld()).first;
83 
84  if (tubeDescriptor != TubeGraph::ErrorId)
85  {
86  m_SecondLastPickedTube = m_LastPickedTube;
87  m_LastPickedTube = tubeDescriptor;
88  return true;
89  }
90  else // nothing picked
91  return false;
92 }
93 
95 {
96  if (m_TubeGraph.IsNull())
97  return;
98 
99  this->SelectTubesByActivationModus();
100 
101  interactionEvent->GetSender()->GetRenderingManager()->RequestUpdateAll();
102 
103  if (m_ActivationMode != None)
104  {
105  // show tube id on status bar
106  std::stringstream displayText;
107  displayText << "Picked tube: ID [" << m_LastPickedTube.first << "," << m_LastPickedTube.second << "]";
108  StatusBar::GetInstance()->DisplayText(displayText.str().c_str());
109  // TODO!!! this->InvokeEvent(SelectionChangedTubeGraphEvent());
110  }
111 }
112 
114 {
115  if (m_TubeGraph.IsNull())
116  return;
117 
118  if ((m_ActivationMode != Multiple) && (m_ActivationMode != Points))
119  {
120  m_TubeGraphProperty->DeactivateAllTubes();
121  interactionEvent->GetSender()->GetRenderingManager()->RequestUpdateAll();
122  // TODO!!!this->InvokeEvent(SelectionChangedTubeGraphEvent());
123  }
124  // show info on status bar
125  StatusBar::GetInstance()->DisplayText("No tube hit!");
126 }
127 
129 {
130  m_ActivationMode = activationMode;
131  if (m_TubeGraph.IsNotNull())
132  if (m_LastPickedTube != mitk::TubeGraph::ErrorId)
133  this->UpdateActivation();
134 }
135 
137 {
138  return m_ActivationMode;
139 }
140 
142 {
143  m_ActionMode = actionMode;
144 }
145 
147 {
148  return m_ActionMode;
149 }
150 
152 {
153  if (m_LastPickedTube != mitk::TubeGraph::ErrorId)
154  {
155  this->UpdateActivation();
156  }
157 }
158 
160 {
161  if (m_ActionMode == RootMode)
162  {
163  m_TubeGraphProperty->DeactivateAllTubes();
164  m_TubeGraphProperty->SetTubeActive(m_LastPickedTube, true);
165 
166  // QmitkTubeGraphSelectRootDialog* dialog = new QmitkTubeGraphSelectRootDialog(m_Parent);
167  // int dialogReturnValue = dialog->exec();
168  // delete dialog;
169 
170  // if ( dialogReturnValue != QDialog::Rejected ) // user doesn't clicked cancel or pressed Esc or something similar
171  //{
172  m_TubeGraph->SetRootTube(m_LastPickedTube);
173  //}
174  m_TubeGraphProperty->DeactivateAllTubes();
176  }
177  else
178  {
179  switch (m_ActivationMode)
180  {
181  case None:
182  {
183  m_TubeGraphProperty->DeactivateAllTubes();
184  }
185  break;
186 
187  case Single:
188  {
189  m_TubeGraphProperty->DeactivateAllTubes();
190  m_TubeGraphProperty->SetTubeActive(m_LastPickedTube, true);
191  }
192  break;
193 
194  case Multiple:
195  { // special deactivation for multiple modus
196  // if activated--> deactivate; if not activated--> activate
197  if (m_TubeGraphProperty->IsTubeActive(m_LastPickedTube))
198  m_TubeGraphProperty->SetTubeActive(m_LastPickedTube, false);
199  else
200  m_TubeGraphProperty->SetTubeActive(m_LastPickedTube, true);
201  }
202  break;
203 
204  case ToRoot:
205  {
206  m_TubeGraphProperty->DeactivateAllTubes();
207  std::vector<TubeGraph::TubeDescriptorType> activeTubes = this->GetTubesToRoot();
208  m_TubeGraphProperty->SetTubesActive(activeTubes);
209  }
210  break;
211  case ToPeriphery:
212  {
213  m_TubeGraphProperty->DeactivateAllTubes();
214  std::vector<TubeGraph::TubeDescriptorType> activeTubes = this->GetPathToPeriphery();
215  m_TubeGraphProperty->SetTubesActive(activeTubes);
216  }
217  break;
218 
219  case Points:
220  {
221  m_TubeGraphProperty->DeactivateAllTubes();
222  std::vector<TubeGraph::TubeDescriptorType> activeTubes = this->GetTubesBetweenPoints();
223  m_TubeGraphProperty->SetTubesActive(activeTubes);
224  }
225  break;
226 
227  default:
228  MITK_WARN << "Unknown tube graph interaction mode!";
229  break;
230  }
231  }
232 }
233 
234 std::vector<mitk::TubeGraph::TubeDescriptorType> mitk::TubeGraphDataInteractor::GetTubesToRoot()
235 {
236  TubeGraph::TubeDescriptorType root = m_TubeGraph->GetRootTube();
237  if (root == TubeGraph::ErrorId)
238  {
239  root = m_TubeGraph->GetThickestTube();
240  m_TubeGraph->SetRootTube(root);
241  }
242 
243  return this->GetPathBetweenTubes(m_LastPickedTube, root);
244 }
245 
246 std::vector<mitk::TubeGraph::TubeDescriptorType> mitk::TubeGraphDataInteractor::GetTubesBetweenPoints()
247 {
248  return this->GetPathBetweenTubes(m_LastPickedTube, m_SecondLastPickedTube);
249 }
250 
251 std::vector<mitk::TubeGraph::TubeDescriptorType> mitk::TubeGraphDataInteractor::GetPathBetweenTubes(
253 {
254  std::vector<mitk::TubeGraph::TubeDescriptorType> solutionPath;
255  if ((start != TubeGraph::ErrorId) && (end != TubeGraph::ErrorId))
256  {
257  if (start != end)
258  solutionPath = m_TubeGraph->SearchAllPathBetweenVertices(start, end);
259  else
260  solutionPath.push_back(start);
261  }
262 
263  return solutionPath;
264 }
265 
266 std::vector<mitk::TubeGraph::TubeDescriptorType> mitk::TubeGraphDataInteractor::GetPathToPeriphery()
267 {
268  std::vector<mitk::TubeGraph::TubeDescriptorType> solutionPath;
269 
270  if (m_LastPickedTube != TubeGraph::ErrorId)
271  solutionPath = m_TubeGraph->SearchPathToPeriphery(m_LastPickedTube);
272 
273  return solutionPath;
274 }
275 
277 {
278  m_LastPickedTube = TubeGraph::ErrorId;
279  m_SecondLastPickedTube = TubeGraph::ErrorId;
280 }
void SetTubeGraph(const TubeGraph *tubeGraph)
Super class for all position events.
BaseRenderer * GetSender() const
static const TubeDescriptorType ErrorId
Definition: mitkTubeGraph.h:55
virtual void SelectTube(StateMachineAction *, InteractionEvent *)
virtual void DeselectTube(StateMachineAction *, InteractionEvent *)
#define MITK_ERROR
Definition: mitkLogMacros.h:24
Base Class for Tube Graphs.
Definition: mitkTubeGraph.h:37
Constants for most interaction classes, due to the generic StateMachines.
std::pair< mitk::TubeGraph::TubeDescriptorType, mitk::TubeElement * > GetPickedTube(const Point3D pickedPosition)
void SetActionMode(const ActionMode &actionMode)
T::Pointer GetData(const std::string &name)
#define MITK_WARN
Definition: mitkLogMacros.h:23
virtual mitk::RenderingManager * GetRenderingManager() const
Setter for the RenderingManager that handles this instance of BaseRenderer.
std::pair< VertexDescriptorType, VertexDescriptorType > TubeDescriptorType
Definition: mitkTubeGraph.h:43
Property for tube graphs.
static RenderingManager * GetInstance()
void DisplayText(const char *t)
Send a string to the applications StatusBar.
Represents an action, that is executed after a certain event (in statemachine-mechanism) TODO: implem...
static StatusBar * GetInstance()
static method to get the GUI dependent StatusBar-instance so the methods DisplayText, etc. can be called No reference counting, cause of decentral static use!
#define CONNECT_CONDITION(a, f)
virtual bool CheckOverTube(const InteractionEvent *)
#define CONNECT_FUNCTION(a, f)
void SetActivationMode(const ActivationMode &activationMode)
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
virtual void ConnectActionsAndFunctions() override