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