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