Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkTubeGraphEdge.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 "mitkTubeGraphEdge.h"
14 
15 mitk::TubeGraphEdge::TubeGraphEdge() : m_ElementVector(0)
16 {
17 }
18 
20 {
21  /*while(!m_ElementVector.empty())
22  {
23  delete m_ElementVector.back();
24  m_ElementVector.pop_back();
25  }*/
26  m_ElementVector.clear();
27 }
28 
29 std::vector<mitk::TubeElement *> mitk::TubeGraphEdge::GetElementVector()
30 {
31  return m_ElementVector;
32 }
33 
34 void mitk::TubeGraphEdge::SetElementVector(std::vector<mitk::TubeElement *> elementVector)
35 {
36  m_ElementVector = elementVector;
37 }
38 
40 {
41  return m_ElementVector.size();
42 }
43 
45 {
46  m_ElementVector.push_back(element);
47 }
48 
49 void mitk::TubeGraphEdge::AddTubeElementAt(unsigned int position, TubeElement *element)
50 {
51  m_ElementVector.insert(m_ElementVector.begin() + position, element);
52 }
53 
55 {
56  if (position >= GetNumberOfElements())
57  throw std::runtime_error("Exception thrown in TubeGraphEdge::getTubeElement(uint): getTubeElement(uint)");
58  else
59  return m_ElementVector[position];
60 }
61 
63 {
64  float length = 0.0f;
65  mitk::Point3D pos1, pos2;
66  std::vector<float> diff;
67  diff.resize(3);
68  unsigned int numberOfElements = this->GetNumberOfElements();
69 
70  // if there are no elements return 0
71  if (numberOfElements == 0)
72  {
73  // If the edge has no elements, then take the difference between the vertices directly
74  pos1 = (source.GetTubeElement())->GetCoordinates();
75  pos2 = (target.GetTubeElement())->GetCoordinates();
76 
77  diff[0] = pos1[0] - pos2[0];
78  diff[1] = pos1[1] - pos2[1];
79  diff[2] = pos1[2] - pos2[2];
80 
81  float sum = diff[0] * diff[0] + diff[1] * diff[1] + diff[2] * diff[2];
82  length = length + std::sqrt(sum);
83  }
84  else
85  {
86  // difference between source and first element of the edge
87  pos1 = (source.GetTubeElement())->GetCoordinates();
88  pos2 = (this->GetTubeElement(0))->GetCoordinates();
89 
90  diff[0] = pos1[0] - pos2[0];
91  diff[1] = pos1[1] - pos2[1];
92  diff[2] = pos1[2] - pos2[2];
93 
94  float sum = diff[0] * diff[0] + diff[1] * diff[1] + diff[2] * diff[2];
95  length = length + std::sqrt(sum);
96 
97  // Differences within the edge
98  for (unsigned int i = 0; i < numberOfElements - 1; ++i)
99  {
100  pos1 = (this->GetTubeElement(i))->GetCoordinates();
101  pos2 = (this->GetTubeElement(i + 1))->GetCoordinates();
102 
103  diff[0] = pos1[0] - pos2[0];
104  diff[1] = pos1[1] - pos2[1];
105  diff[2] = pos1[2] - pos2[2];
106 
107  sum = diff[0] * diff[0] + diff[1] * diff[1] + diff[2] * diff[2];
108  length = length + std::sqrt(sum);
109  }
110 
111  // difference between last element and target of the edge
112  pos1 = (this->GetTubeElement(numberOfElements - 1))->GetCoordinates();
113  pos2 = (target.GetTubeElement())->GetCoordinates();
114 
115  diff[0] = pos1[0] - pos2[0];
116  diff[1] = pos1[1] - pos2[1];
117  diff[2] = pos1[2] - pos2[2];
118 
119  sum = diff[0] * diff[0] + diff[1] * diff[1] + diff[2] * diff[2];
120  length = length + std::sqrt(sum);
121  }
122 
123  return length;
124 }
125 
127 {
128  float diameterSum = 0.0;
129  unsigned int numberOfElements = this->GetNumberOfElements();
130 
131  // add source diameter
132  if (dynamic_cast<const mitk::CircularProfileTubeElement *>(source.GetTubeElement()))
133  diameterSum += (dynamic_cast<const mitk::CircularProfileTubeElement *>(source.GetTubeElement()))->GetDiameter();
134  ;
135 
136  // add all edge element diameter
137  for (unsigned int i = 0; i < numberOfElements; i++)
138  {
139  if (dynamic_cast<const mitk::CircularProfileTubeElement *>(this->GetTubeElement(i)))
140  diameterSum += (dynamic_cast<const mitk::CircularProfileTubeElement *>(this->GetTubeElement(i)))->GetDiameter();
141  }
142 
143  // add target diameter
144  if (dynamic_cast<const mitk::CircularProfileTubeElement *>(target.GetTubeElement()))
145  diameterSum += (dynamic_cast<const mitk::CircularProfileTubeElement *>(target.GetTubeElement()))->GetDiameter();
146 
147  return diameterSum / (numberOfElements + 2);
148 }
149 
151 {
152  return (m_ElementVector == right.m_ElementVector);
153 }
bool operator==(const TubeGraphEdge &right) const
float GetEdgeLength(TubeGraphVertex &source, TubeGraphVertex &target)
void SetElementVector(std::vector< TubeElement *> elementVector)
Base Class for Tube Graph Vertices.
void AddTubeElement(TubeElement *element)
Abstract class for elements which describes tubular structur.
float GetEdgeAverageDiameter(TubeGraphVertex &source, TubeGraphVertex &target)
Class for elements which describes tubular structur with a circular cross section.
Base Class for Tube Graph Edges.
const TubeElement * GetTubeElement() const
TubeElement * GetTubeElement(unsigned int position)
std::vector< TubeElement * > GetElementVector()
unsigned int GetNumberOfElements() const
void AddTubeElementAt(unsigned int position, TubeElement *element)