Fraxinus  2023.01.05-dev+develop.0da12
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 
159 {
160  mBendingDirection = bendingDirection;
161 }
162 
164 {
165  return mBendingDirection;
166 }
167 
168 void Branch::setBronchoscopeRotation(double rotation)
169 {
170  mBronchoscopeRotation = rotation;
171 }
172 
174 {
175  return mBronchoscopeRotation;
176 }
177 
179 {
180  Eigen::MatrixXd positions = this->getPositions();
181  Eigen::MatrixXd orientations = this->getOrientations();
182  bool resizeOrientations = false;
183  if (positions.cols() == orientations.cols())
184  resizeOrientations = true;
185 
186  for (int i = positions.cols() - 1; i > 0; i--)
187  {
188  if (similar( (positions.col(i)-positions.col(i-1)).cwiseAbs().sum(), 0))
189  {
190  positions.block(0 , i , positions.rows() , positions.cols() - i - 1) = positions.rightCols(positions.cols() - i - 1);
191  positions.conservativeResize(Eigen::NoChange, positions.cols() - 1);
192  if (resizeOrientations)
193  orientations.conservativeResize(Eigen::NoChange, orientations.cols() - 1);
194  }
195  }
196 
197  mPositions = positions;
198  if (resizeOrientations)
199  mOrientations = orientations;
200 }
201 
202 void Branch::setLap(QString lap)
203 {
204  mLap = lap;
205 }
206 
207 QString Branch::getLap()
208 {
209  return mLap;
210 }
211 
212 
214 {
215 
216 }
217 
218 }//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
boost::shared_ptr< class Branch > BranchPtr
int findGenerationNumber()
Definition: cxBranch.cpp:120
void removeEqualPositions()
Definition: cxBranch.cpp:178
Vector3D getBronchoscopeBendingDirection()
Definition: cxBranch.cpp:163
double getAverageRadius()
Definition: cxBranch.cpp:55
Eigen::MatrixXd getOrientations()
Definition: cxBranch.cpp:40
virtual ~Branch()
Definition: cxBranch.cpp:213
void setBronchoscopeBendingDirection(Vector3D bendingDirection)
Definition: cxBranch.cpp:158
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:207
Eigen::VectorXd getRadius()
Definition: cxBranch.cpp:50
Eigen::MatrixXd getPositions()
Definition: cxBranch.cpp:30
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
void calculateOrientations()
Definition: cxBranch.cpp:89
void setLap(QString lap)
Definition: cxBranch.cpp:202
double getBronchoscopeRotation()
Definition: cxBranch.cpp:173
void setBronchoscopeRotation(double rotation)
Definition: cxBranch.cpp:168
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.