NorMIT-nav  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
cx::Branch::calculateOrientations
void calculateOrientations()
Definition: cxBranch.cpp:89
cx::Branch::getOrientations
Eigen::MatrixXd getOrientations()
Definition: cxBranch.cpp:40
cx::Branch::setRadius
void setRadius(Eigen::VectorXd r)
Definition: cxBranch.cpp:45
cx::Branch::setPositions
void setPositions(Eigen::MatrixXd pos)
Definition: cxBranch.cpp:23
cx::Branch::getParentBranch
BranchPtr getParentBranch()
Definition: cxBranch.cpp:84
cx::Branch::addChildBranch
void addChildBranch(BranchPtr child)
Definition: cxBranch.cpp:60
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::Branch::getBronchoscopeBendingDirection
Vector3D getBronchoscopeBendingDirection()
Definition: cxBranch.cpp:163
cx::Branch::getAverageRadius
double getAverageRadius()
Definition: cxBranch.cpp:55
cx::Branch::Branch
Branch()
Definition: cxBranch.cpp:16
cx::Branch::deleteChildBranches
void deleteChildBranches()
Definition: cxBranch.cpp:70
cx::Branch::setBronchoscopeRotation
void setBronchoscopeRotation(double rotation)
Definition: cxBranch.cpp:168
cx::Branch::removeEqualPositions
void removeEqualPositions()
Definition: cxBranch.cpp:178
cx::Branch::setParentBranch
void setParentBranch(BranchPtr parent)
Definition: cxBranch.cpp:80
cx::BranchPtr
boost::shared_ptr< class Branch > BranchPtr
Definition: cxForwardDeclarations.h:150
cx::Branch::findGenerationNumber
int findGenerationNumber()
Definition: cxBranch.cpp:120
cx::Branch::getLap
QString getLap()
Definition: cxBranch.cpp:207
cx::Branch::setLap
void setLap(QString lap)
Definition: cxBranch.cpp:202
cx::Branch::getChildBranches
branchVector getChildBranches()
Definition: cxBranch.cpp:75
cx::Branch::setOrientations
void setOrientations(Eigen::MatrixXd orient)
Definition: cxBranch.cpp:35
cxBranch.h
cx::branchVector
std::vector< BranchPtr > branchVector
Definition: cxBranch.h:28
cx::Branch::getPositions
Eigen::MatrixXd getPositions()
Definition: cxBranch.cpp:30
cx::Branch::setBronchoscopeBendingDirection
void setBronchoscopeBendingDirection(Vector3D bendingDirection)
Definition: cxBranch.cpp:158
cx::Branch::setChildBranches
void setChildBranches(branchVector children)
Definition: cxBranch.cpp:65
cx::Branch::findBranchRadius
double findBranchRadius()
Definition: cxBranch.cpp:139
cx::Branch::getRadius
Eigen::VectorXd getRadius()
Definition: cxBranch.cpp:50
cx::Branch::getBronchoscopeRotation
double getBronchoscopeRotation()
Definition: cxBranch.cpp:173
cx::similar
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
Definition: cxCameraStyleForView.cpp:506
cx::Vector3D
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
cx::Branch::~Branch
virtual ~Branch()
Definition: cxBranch.cpp:213
cx::Branch::findParentIndex
int findParentIndex(branchVector bv) const
Branch::findParentIndex Given a vector of branches, find this branch's parent branch in that vector....
Definition: cxBranch.cpp:109