CustusX  22.04
An IGT application
cxBranch.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 #include "cxBranch.h"
12 
13 namespace cx
14 {
15 
17  mParentBranch(BranchPtr())
18 {
19  // TODO Auto-generated constructor stub
20 
21 }
22 
23 void Branch::setPositions(Eigen::MatrixXd pos)
24 {
25  mPositions = pos;
26  this->removeEqualPositions();
27  this->calculateOrientations();
28 }
29 
30 Eigen::MatrixXd Branch::getPositions()
31 {
32  return mPositions;
33 }
34 
35 void Branch::setOrientations(Eigen::MatrixXd orient)
36 {
37  mOrientations = orient;
38 }
39 
40 Eigen::MatrixXd Branch::getOrientations()
41 {
42  return mOrientations;
43 }
44 
45 void Branch::setRadius(Eigen::VectorXd r)
46 {
47  mRadius = r;
48 }
49 
50 Eigen::VectorXd Branch::getRadius()
51 {
52  return mRadius;
53 }
54 
56 {
57  return mRadius.mean();
58 }
59 
61 {
62  mChildBranches.push_back(child);
63 }
64 
66 {
67  mChildBranches = children;
68 }
69 
71 {
72  mChildBranches.clear();
73 }
74 
76 {
77  return mChildBranches;
78 }
79 
81 {
82  mParentBranch = parent;
83 }
85 {
86  return mParentBranch;
87 }
88 
90 {
91  Eigen::MatrixXd positions = this->getPositions();
92  Eigen::MatrixXd diff = positions.rightCols(positions.cols() - 1) - positions.leftCols(positions.cols() - 1);
93  Eigen::MatrixXd orientations(positions.rows(),positions.cols());
94  orientations.leftCols(orientations.cols() - 1) = diff / diff.norm();
95  orientations.rightCols(1) = orientations.col(orientations.cols() - 1);
96  this->setOrientations(orientations);
97 }
98 
110 {
111  for(size_t i = 0; i < bv.size(); ++i)
112  {
113  if(bv[i] == mParentBranch)
114  return static_cast<int>(i);
115  }
116 
117  return -1;
118 }
119 
121 {
122  int generationNumber = 1;
123 
124  BranchPtr parentBranchPtr = this->getParentBranch();
125  while (parentBranchPtr)
126  {
127  if (parentBranchPtr->getChildBranches().size() > 1) // Do not count generation if it is not a real division
128  generationNumber = generationNumber + 1;
129 
130  parentBranchPtr = parentBranchPtr->getParentBranch();
131 
132  if (generationNumber > 23) //maximum possible generations - avoiding infinite loop
133  break;
134  }
135 
136  return generationNumber;
137 }
138 
140 {
141  int generationNumber = this->findGenerationNumber();
142 
143  if (generationNumber == 1)
144  return 8;
145  if (generationNumber == 2)
146  return 6;
147  if (generationNumber == 3)
148  return 4;
149  if (generationNumber == 4)
150  return 3;
151  if (generationNumber == 5)
152  return 2.5;
153  else
154  return 2;
155 }
156 
157 void Branch::setBronchoscopeRotation(double rotation)
158 {
159  mBronchoscopeRotation = rotation;
160 }
161 
163 {
164  return mBronchoscopeRotation;
165 }
166 
168 {
169  Eigen::MatrixXd positions = this->getPositions();
170  Eigen::MatrixXd orientations = this->getOrientations();
171  bool resizeOrientations = false;
172  if (positions.cols() == orientations.cols())
173  resizeOrientations = true;
174 
175  for (int i = positions.cols() - 1; i > 0; i--)
176  {
177  if (similar( (positions.col(i)-positions.col(i-1)).cwiseAbs().sum(), 0))
178  {
179  positions.block(0 , i , positions.rows() , positions.cols() - i - 1) = positions.rightCols(positions.cols() - i - 1);
180  positions.conservativeResize(Eigen::NoChange, positions.cols() - 1);
181  if (resizeOrientations)
182  orientations.conservativeResize(Eigen::NoChange, orientations.cols() - 1);
183  }
184  }
185 
186  mPositions = positions;
187  if (resizeOrientations)
188  mOrientations = orientations;
189 }
190 
191 void Branch::setLap(QString lap)
192 {
193  mLap = lap;
194 }
195 
196 QString Branch::getLap()
197 {
198  return mLap;
199 }
200 
201 
203 {
204 
205 }
206 
207 }//namespace cx
void deleteChildBranches()
Definition: cxBranch.cpp:70
void addChildBranch(BranchPtr child)
Definition: cxBranch.cpp:60
void setPositions(Eigen::MatrixXd pos)
Definition: cxBranch.cpp:23
void setRadius(Eigen::VectorXd r)
Definition: cxBranch.cpp:45
branchVector getChildBranches()
Definition: cxBranch.cpp:75
double findBranchRadius()
Definition: cxBranch.cpp:139
int findGenerationNumber()
Definition: cxBranch.cpp:120
void removeEqualPositions()
Definition: cxBranch.cpp:167
double getAverageRadius()
Definition: cxBranch.cpp:55
boost::shared_ptr< class Branch > BranchPtr
Eigen::MatrixXd getOrientations()
Definition: cxBranch.cpp:40
virtual ~Branch()
Definition: cxBranch.cpp:202
int findParentIndex(branchVector bv) const
Branch::findParentIndex Given a vector of branches, find this branch&#39;s parent branch in that vector...
Definition: cxBranch.cpp:109
BranchPtr getParentBranch()
Definition: cxBranch.cpp:84
void setOrientations(Eigen::MatrixXd orient)
Definition: cxBranch.cpp:35
QString getLap()
Definition: cxBranch.cpp:196
Eigen::VectorXd getRadius()
Definition: cxBranch.cpp:50
Eigen::MatrixXd getPositions()
Definition: cxBranch.cpp:30
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
void calculateOrientations()
Definition: cxBranch.cpp:89
void setLap(QString lap)
Definition: cxBranch.cpp:191
double getBronchoscopeRotation()
Definition: cxBranch.cpp:162
void setBronchoscopeRotation(double rotation)
Definition: cxBranch.cpp:157
void setChildBranches(branchVector children)
Definition: cxBranch.cpp:65
void setParentBranch(BranchPtr parent)
Definition: cxBranch.cpp:80
std::vector< BranchPtr > branchVector
Definition: cxBranch.h:28
Namespace for all CustusX production code.