4 #include <vtkPolyData.h>
8 #include <vtkCellArray.h>
9 #include "vtkCardinalSpline.h"
35 int N = centerline->GetNumberOfPoints();
36 Eigen::MatrixXd CLpoints(3,N);
37 for(vtkIdType i = 0; i < N; i++)
40 centerline->GetPoint(i,p);
41 Eigen::Vector3d position;
42 position(0) = p[0]; position(1) = p[1]; position(2) = p[2];
43 CLpoints.block(0 , i , 3 , 1) = position;
51 mBranchListPtr->deleteAllBranches();
55 mBranchListPtr->findBranchesInCenterline(CLpoints);
57 mBranchListPtr->calculateOrientations();
58 mBranchListPtr->smoothOrientations();
60 std::cout <<
"Number of branches in CT centerline: " << mBranchListPtr->getBranches().size() << std::endl;
67 double minDistance = 100000;
68 int minDistancePositionIndex;
70 std::vector<BranchPtr> branches = mBranchListPtr->getBranches();
71 for (
int i = 0; i < branches.size(); i++)
73 Eigen::MatrixXd positions = branches[i]->getPositions();
74 for (
int j = 0; j < positions.cols(); j++)
76 double D =
findDistance(positions.col(j), targetCoordinate);
80 minDistanceBranch = branches[i];
81 minDistancePositionIndex = j;
86 mProjectedBranchPtr = minDistanceBranch;
87 mProjectedIndex = minDistancePositionIndex;
93 mRoutePositions.clear();
100 Eigen::MatrixXd positions = searchBranchPtr->getPositions();
102 for (
int i = startIndex; i>=0; i--)
103 mRoutePositions.push_back(positions.col(i));
105 BranchPtr parentBranchPtr = searchBranchPtr->getParentBranch();
107 searchBranchUp(parentBranchPtr, parentBranchPtr->getPositions().cols()-1);
129 int numberOfPositions = mRoutePositions.size();
130 for (
int j = numberOfPositions - 1; j >= 0; j--)
132 points->InsertNextPoint(mRoutePositions[j](0),mRoutePositions[j](1),mRoutePositions[j](2));
134 for (
int j = 0; j < numberOfPositions-1; j++)
136 vtkIdType connection[2] = {j, j+1};
137 lines->InsertNextCell(2, connection);
139 retval->SetPoints(points);
140 retval->SetLines(lines);
144 void RouteToTarget::smoothPositions()
146 int numberOfInputPoints = mRoutePositions.size();
147 int controlPointFactor = 10;
148 int numberOfControlPoints = numberOfInputPoints / controlPointFactor;
154 if (numberOfControlPoints >= 2)
157 for(
int j=0; j<numberOfControlPoints; j++)
159 int indexP = (j*numberOfInputPoints)/numberOfControlPoints;
160 splineX->AddPoint(indexP,mRoutePositions[indexP](0));
161 splineY->AddPoint(indexP,mRoutePositions[indexP](1));
162 splineZ->AddPoint(indexP,mRoutePositions[indexP](2));
165 splineX->AddPoint(numberOfInputPoints-1,mRoutePositions[numberOfInputPoints-1](0));
166 splineY->AddPoint(numberOfInputPoints-1,mRoutePositions[numberOfInputPoints-1](1));
167 splineZ->AddPoint(numberOfInputPoints-1,mRoutePositions[numberOfInputPoints-1](2));
171 std::vector< Eigen::Vector3d > smoothingResult;
172 for(
int j=0; j<numberOfInputPoints; j++)
174 double splineParameter = j;
175 Eigen::Vector3d tempPoint;
176 tempPoint(0) = splineX->Evaluate(splineParameter);
177 tempPoint(1) = splineY->Evaluate(splineParameter);
178 tempPoint(2) = splineZ->Evaluate(splineParameter);
179 smoothingResult.push_back(tempPoint);
181 mRoutePositions.clear();
182 mRoutePositions = smoothingResult;
189 double d0 = p1(0) - p2(0);
190 double d1 = p1(1) - p2(1);
191 double d2 = p1(2) - p2(2);
193 double D = sqrt( d0*d0 + d1*d1 + d2*d2 );
void findClosestPointInBranches(Vector3D targetCoordinate)
vtkSmartPointer< class vtkCellArray > vtkCellArrayPtr
void setCenterline(vtkPolyDataPtr centerline)
void processCenterline(vtkPolyDataPtr centerline)
boost::shared_ptr< class Branch > BranchPtr
double findDistance(Eigen::MatrixXd p1, Eigen::MatrixXd p2)
vtkSmartPointer< class vtkPolyData > vtkPolyDataPtr
void searchBranchUp(BranchPtr searchBranchPtr, int startIndex)
vtkSmartPointer< class vtkCardinalSpline > vtkCardinalSplinePtr
vtkPolyDataPtr findRouteToTarget(Vector3D targetCoordinate)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
vtkPolyDataPtr addVTKPoints()
void findRoutePositions()
vtkSmartPointer< class vtkPoints > vtkPointsPtr
Eigen::MatrixXd getCenterlinePositions(vtkPolyDataPtr centerline)