13 #include <boost/math/special_functions/round.hpp> 14 #include <vtkPolyData.h> 17 #include "vtkCardinalSpline.h" 20 #include <vtkImageData.h> 21 #include <vtkPointData.h> 30 mAirwaysVolumeBoundaryExtention(10),
31 mAirwaysVolumeBoundaryExtentionTracheaStart(2),
32 mAirwaysVolumeSpacing(0.5)
43 int N = centerline_r->GetNumberOfPoints();
44 Eigen::MatrixXd CLpoints(3,N);
45 for(vtkIdType i = 0; i < N; i++)
48 centerline_r->GetPoint(i,p);
49 Eigen::Vector3d position;
50 position(0) = p[0]; position(1) = p[1]; position(2) = p[2];
51 CLpoints.block(0 , i , 3 , 1) = position;
59 mBranchListPtr->deleteAllBranches();
63 mBranchListPtr->findBranchesInCenterline(CLpoints_r);
65 mBranchListPtr->smoothBranchPositions(40);
66 mBranchListPtr->interpolateBranchPositions(5);
99 std::vector<BranchPtr> branches = mBranchListPtr->getBranches();
102 int numberOfPoints = 0;
103 for (
int i = 0; i < branches.size(); i++)
104 numberOfPoints += branches[i]->getPositions().cols();
106 pointsPtr->SetNumberOfPoints(numberOfPoints);
109 for (
int i = 0; i < branches.size(); i++)
111 Eigen::MatrixXd positions = branches[i]->getPositions();
112 for (
int j = 0; j < positions.cols(); j++)
114 pointsPtr->SetPoint(pointIndex, positions(0,j), positions(1,j), positions(2,j));
119 pointsPtr->GetBounds(mBounds);
122 mBounds[0] -= mAirwaysVolumeBoundaryExtention;
123 mBounds[1] += mAirwaysVolumeBoundaryExtention;
124 mBounds[2] -= mAirwaysVolumeBoundaryExtention;
125 mBounds[3] += mAirwaysVolumeBoundaryExtention;
126 mBounds[4] -= mAirwaysVolumeBoundaryExtention;
127 mBounds[5] -= mAirwaysVolumeBoundaryExtentionTracheaStart;
129 mSpacing[0] = mAirwaysVolumeSpacing;
130 mSpacing[1] = mAirwaysVolumeSpacing;
131 mSpacing[2] = mAirwaysVolumeSpacing;
134 for (
int i = 0; i < 3; i++)
135 mDim[i] = static_cast<int>(
std::ceil((mBounds[i * 2 + 1] - mBounds[i * 2]) / mSpacing[i]));
137 mOrigin[0] = mBounds[0] + mSpacing[0] / 2;
138 mOrigin[1] = mBounds[2] + mSpacing[1] / 2;
139 mOrigin[2] = mBounds[4] + mSpacing[2] / 2;
142 airwaysVolumePtr->SetOrigin(mOrigin);
144 return airwaysVolumePtr;
150 std::vector<BranchPtr> branches = mBranchListPtr->getBranches();
152 for (
int i = 0; i < branches.size(); i++)
154 Eigen::MatrixXd positions = branches[i]->getPositions();
156 int numberOfPositionsInBranch = positions.cols();
157 pointsPtr->SetNumberOfPoints(numberOfPositionsInBranch);
158 double radius = branches[i]->findBranchRadius();
160 for (
int j = 0; j < numberOfPositionsInBranch; j++)
163 spherePos[0] = positions(0,j);
164 spherePos[1] = positions(1,j);
165 spherePos[2] = positions(2,j);
169 return airwaysVolumePtr;
176 int sphereBoundingBoxIndex[6];
178 for (
int i=0; i<3; i++)
180 centerIndex[i] =
static_cast<int>(
boost::math::round( (position[i]-mOrigin[i]) / mSpacing[i] ));
181 sphereBoundingBoxIndex[2*i] = std::max(
182 static_cast<int>(
boost::math::round( (position[i]-mOrigin[i] - radius) / mSpacing[i] )),
184 sphereBoundingBoxIndex[2*i+1] = std::min(
185 static_cast<int>(
boost::math::round( (position[i]-mOrigin[i] + radius) / mSpacing[i] )),
190 for (
int x = sphereBoundingBoxIndex[0]; x<=sphereBoundingBoxIndex[1]; x++)
191 for (
int y = sphereBoundingBoxIndex[2]; y<=sphereBoundingBoxIndex[3]; y++)
192 for (
int z = sphereBoundingBoxIndex[4]; z<=sphereBoundingBoxIndex[5]; z++)
194 double distanceFromCenter = sqrt((x-centerIndex[0])*mSpacing[0]*(x-centerIndex[0])*mSpacing[0] +
195 (y-centerIndex[1])*mSpacing[1]*(y-centerIndex[1])*mSpacing[1] +
196 (z-centerIndex[2])*mSpacing[2]*(z-centerIndex[2])*mSpacing[2]);
198 if (distanceFromCenter < radius)
200 unsigned char* dataPtrImage =
static_cast<unsigned char*
>(airwaysVolumePtr->GetScalarPointer(x,y,z));
201 dataPtrImage[0] = value;
205 return airwaysVolumePtr;
217 std::vector<BranchPtr> branches = mBranchListPtr->getBranches();
220 for (
int i = 0; i < branches.size(); i++)
222 Eigen::MatrixXd positions = branches[i]->getPositions();
223 int numberOfPositions = positions.cols();
225 if (branches[i]->getParentBranch())
227 Eigen::MatrixXd parentPositions = branches[i]->getParentBranch()->getPositions();
228 points->InsertNextPoint(parentPositions(0,parentPositions.cols()-1),parentPositions(1,parentPositions.cols()-1),parentPositions(2,parentPositions.cols()-1));
232 for (
int j = 0; j < numberOfPositions; j++)
234 points->InsertNextPoint(positions(0,j),positions(1,j),positions(2,j));
236 if (j>1 || branches[i]->getParentBranch())
238 vtkIdType connection[2] = {pointIndex-1, pointIndex};
239 lines->InsertNextCell(2, connection);
245 retval->SetPoints(points);
246 retval->SetLines(lines);
Vector3D ceil(const Vector3D &a)
vtkSmartPointer< class vtkCellArray > vtkCellArrayPtr
vtkPolyDataPtr getVTKPoints()
vtkImageDataPtr addSphereToImage(vtkImageDataPtr airwaysVolumePtr, double position[3], double radius)
vtkSmartPointer< vtkPoints > vtkPointsPtr
Eigen::MatrixXd getCenterlinePositions(vtkPolyDataPtr centerline_r)
void processCenterline(vtkPolyDataPtr centerline_r)
vtkImageDataPtr initializeAirwaysVolume()
virtual ~AirwaysFromCenterline()
vtkImageDataPtr generateVtkImageData(Eigen::Array3i dim, Vector3D spacing, const unsigned char initValue, int components)
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
vtkPolyDataPtr generateTubes()
vtkImageDataPtr addSpheresAlongCenterlines(vtkImageDataPtr airwaysVolumePtr)
Vector3D round(const Vector3D &a)
Namespace for all CustusX production code.