Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkTubeGraphPicker.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 "mitkTubeGraphPicker.h"
18 
20 {
21  m_WorldPosition.Fill(0.0);
22 }
23 
25 {
26 }
27 
29 {
30  m_TubeGraph = const_cast<mitk::TubeGraph *>(tubeGraph);
31  m_TubeGraphProperty =
32  dynamic_cast<TubeGraphProperty *>(m_TubeGraph->GetProperty("Tube Graph.Visualization Information").GetPointer());
33 }
34 
38 std::pair<mitk::TubeGraph::TubeDescriptorType, mitk::TubeElement *> mitk::TubeGraphPicker::GetPickedTube(
39  const Point3D pickedPosition)
40 {
41  if (!m_TubeGraph)
42  {
43  MITK_ERROR << "mitk::TubeGraphPicker: No tube graph available. Please set an input!" << std::endl;
44  mitk::TubeElement *nullPointer = nullptr;
45  return std::pair<mitk::TubeGraph::TubeDescriptorType, mitk::TubeElement *>(TubeGraph::ErrorId, nullPointer);
46  }
47  m_WorldPosition = pickedPosition;
48 
49  Point3D currentPosition;
52  float currentRadius = 0;
53 
56  TubeElement *tubeElement;
57 
58  // iterate over all edges and find the edge, which element is near by the clicked point
59  std::vector<mitk::TubeGraphEdge> allEdges = m_TubeGraph->GetVectorOfAllEdges();
60  for (auto edge = allEdges.begin(); edge != allEdges.end(); ++edge)
61  {
62  std::pair<mitk::TubeGraphVertex, mitk::TubeGraphVertex> soureTargetPair =
63  m_TubeGraph->GetVerticesOfAnEdge(m_TubeGraph->GetEdgeDescriptor(*edge));
64 
65  currentTubeId = TubeGraph::TubeDescriptorType(m_TubeGraph->GetVertexDescriptor(soureTargetPair.first),
66  m_TubeGraph->GetVertexDescriptor(soureTargetPair.second));
67  // check if the tube is visible, if not pass this tube. User can not choose a tube, which he can't see
68  if (m_TubeGraphProperty->IsTubeVisible(currentTubeId))
69  {
70  std::vector<mitk::TubeElement *> allElements = edge->GetElementVector();
71  for (unsigned int index = 0; index < edge->GetNumberOfElements(); index++)
72  {
73  currentPosition = allElements[index]->GetCoordinates();
74  if (dynamic_cast<mitk::CircularProfileTubeElement *>(allElements[index]))
75  currentRadius = ((dynamic_cast<mitk::CircularProfileTubeElement *>(allElements[index]))->GetDiameter()) / 2;
76  else
77  currentRadius = 0;
78 
79  // calculate point->point distance
80  currentDistance = m_WorldPosition.EuclideanDistanceTo(currentPosition);
81  if (currentDistance < closestDistance && (currentDistance - currentRadius) < 1.0)
82  {
83  closestDistance = currentDistance;
84  tubeId = currentTubeId;
85  tubeElement = allElements[index];
86  }
87  }
88  }
89  }
90  std::pair<mitk::TubeGraph::TubeDescriptorType, mitk::TubeElement *> pickedTubeWithElement(tubeId, tubeElement);
91  return pickedTubeWithElement;
92 }
void SetTubeGraph(const TubeGraph *tubeGraph)
static const TubeDescriptorType ErrorId
Definition: mitkTubeGraph.h:55
#define MITK_ERROR
Definition: mitkLogMacros.h:24
Base Class for Tube Graphs.
Definition: mitkTubeGraph.h:37
double ScalarType
Abstract class for elements which describes tubular structur.
std::pair< mitk::TubeGraph::TubeDescriptorType, mitk::TubeElement * > GetPickedTube(const Point3D pickedPosition)
std::pair< VertexDescriptorType, VertexDescriptorType > TubeDescriptorType
Definition: mitkTubeGraph.h:43
Property for tube graphs.
Class for elements which describes tubular structur with a circular cross section.
static T max(T x, T y)
Definition: svm.cpp:70