4 #include <vtkPolyData.h>
8 #include <vtkCellArray.h>
9 #include "vtkCardinalSpline.h"
37 int N = centerline_r->GetNumberOfPoints();
38 Eigen::MatrixXd CLpoints(3,N);
39 for(vtkIdType i = 0; i < N; i++)
42 centerline_r->GetPoint(i,p);
43 Eigen::Vector3d position;
44 position(0) = p[0]; position(1) = p[1]; position(2) = p[2];
45 CLpoints.block(0 , i , 3 , 1) = position;
53 mBranchListPtr->deleteAllBranches();
57 mBranchListPtr->findBranchesInCenterline(CLpoints_r);
59 mBranchListPtr->calculateOrientations();
60 mBranchListPtr->smoothOrientations();
62 std::cout <<
"Number of branches in CT centerline: " << mBranchListPtr->getBranches().size() << std::endl;
69 double minDistance = 100000;
70 int minDistancePositionIndex;
72 std::vector<BranchPtr> branches = mBranchListPtr->getBranches();
73 for (
int i = 0; i < branches.size(); i++)
75 Eigen::MatrixXd positions = branches[i]->getPositions();
76 for (
int j = 0; j < positions.cols(); j++)
78 double D =
findDistance(positions.col(j), targetCoordinate_r);
82 minDistanceBranch = branches[i];
83 minDistancePositionIndex = j;
88 mProjectedBranchPtr = minDistanceBranch;
89 mProjectedIndex = minDistancePositionIndex;
95 mRoutePositions.clear();
102 Eigen::MatrixXd positions = searchBranchPtr->getPositions();
104 for (
int i = startIndex; i>=0; i--)
105 mRoutePositions.push_back(positions.col(i));
107 BranchPtr parentBranchPtr = searchBranchPtr->getParentBranch();
109 searchBranchUp(parentBranchPtr, parentBranchPtr->getPositions().cols()-1);
131 int numberOfPositions = mRoutePositions.size();
132 for (
int j = numberOfPositions - 1; j >= 0; j--)
134 points->InsertNextPoint(mRoutePositions[j](0),mRoutePositions[j](1),mRoutePositions[j](2));
136 for (
int j = 0; j < numberOfPositions-1; j++)
138 vtkIdType connection[2] = {j, j+1};
139 lines->InsertNextCell(2, connection);
141 retval->SetPoints(points);
142 retval->SetLines(lines);
146 void RouteToTarget::smoothPositions()
148 int numberOfInputPoints = mRoutePositions.size();
149 int controlPointFactor = 10;
150 int numberOfControlPoints = numberOfInputPoints / controlPointFactor;
156 if (numberOfControlPoints >= 2)
159 for(
int j=0; j<numberOfControlPoints; j++)
161 int indexP = (j*numberOfInputPoints)/numberOfControlPoints;
162 splineX->AddPoint(indexP,mRoutePositions[indexP](0));
163 splineY->AddPoint(indexP,mRoutePositions[indexP](1));
164 splineZ->AddPoint(indexP,mRoutePositions[indexP](2));
167 splineX->AddPoint(numberOfInputPoints-1,mRoutePositions[numberOfInputPoints-1](0));
168 splineY->AddPoint(numberOfInputPoints-1,mRoutePositions[numberOfInputPoints-1](1));
169 splineZ->AddPoint(numberOfInputPoints-1,mRoutePositions[numberOfInputPoints-1](2));
173 std::vector< Eigen::Vector3d > smoothingResult;
174 for(
int j=0; j<numberOfInputPoints; j++)
176 double splineParameter = j;
177 Eigen::Vector3d tempPoint;
178 tempPoint(0) = splineX->Evaluate(splineParameter);
179 tempPoint(1) = splineY->Evaluate(splineParameter);
180 tempPoint(2) = splineZ->Evaluate(splineParameter);
181 smoothingResult.push_back(tempPoint);
183 mRoutePositions.clear();
184 mRoutePositions = smoothingResult;
191 double d0 = p1(0) - p2(0);
192 double d1 = p1(1) - p2(1);
193 double d2 = p1(2) - p2(2);
195 double D = sqrt( d0*d0 + d1*d1 + d2*d2 );
vtkSmartPointer< class vtkCellArray > vtkCellArrayPtr
boost::shared_ptr< class Branch > BranchPtr
double findDistance(Eigen::MatrixXd p1, Eigen::MatrixXd p2)
vtkSmartPointer< class vtkPolyData > vtkPolyDataPtr
void findClosestPointInBranches(Vector3D targetCoordinate_r)
void searchBranchUp(BranchPtr searchBranchPtr, int startIndex)
void processCenterline(vtkPolyDataPtr centerline_r)
vtkSmartPointer< class vtkCardinalSpline > vtkCardinalSplinePtr
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
vtkPolyDataPtr findRouteToTarget(Vector3D targetCoordinate_r)
vtkPolyDataPtr addVTKPoints()
void findRoutePositions()
vtkSmartPointer< class vtkPoints > vtkPointsPtr
Eigen::MatrixXd getCenterlinePositions(vtkPolyDataPtr centerline_r)