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