19 #include <vtkPolyLine.h>
20 #include <vtkCellArray.h>
21 #include <vtkCellData.h>
22 #include <boost/progress.hpp>
26 template<
class OutputImageType >
28 : m_InvertImage(false)
29 , m_UpsamplingFactor(1)
31 , m_UseImageGeometry(false)
32 , m_BinaryOutput(false)
37 template<
class OutputImageType >
42 template<
class OutputImageType >
45 itk::Point<float, 3> itkPoint;
46 itkPoint[0] = point[0];
47 itkPoint[1] = point[1];
48 itkPoint[2] = point[2];
52 template<
class OutputImageType >
60 itk::Vector<double, 3> newSpacing;
62 itk::Matrix<double, 3, 3> newDirection;
63 ImageRegion<3> upsampledRegion;
64 if (m_UseImageGeometry && !m_InputImage.IsNull())
66 newSpacing = m_InputImage->GetSpacing()/m_UpsamplingFactor;
67 upsampledRegion = m_InputImage->GetLargestPossibleRegion();
68 newOrigin = m_InputImage->GetOrigin();
69 typename OutputImageType::RegionType::SizeType size = upsampledRegion.GetSize();
70 size[0] *= m_UpsamplingFactor;
71 size[1] *= m_UpsamplingFactor;
72 size[2] *= m_UpsamplingFactor;
73 upsampledRegion.SetSize(size);
74 newDirection = m_InputImage->GetDirection();
78 newSpacing = geometry->GetSpacing()/m_UpsamplingFactor;
79 newOrigin = geometry->GetOrigin();
81 newOrigin[0] += bounds.GetElement(0);
82 newOrigin[1] += bounds.GetElement(2);
83 newOrigin[2] += bounds.GetElement(4);
85 for (
int i=0; i<3; i++)
86 for (
int j=0; j<3; j++)
87 newDirection[j][i] = geometry->GetMatrixColumn(i)[j];
88 upsampledRegion.SetSize(0, geometry->GetExtent(0)*m_UpsamplingFactor);
89 upsampledRegion.SetSize(1, geometry->GetExtent(1)*m_UpsamplingFactor);
90 upsampledRegion.SetSize(2, geometry->GetExtent(2)*m_UpsamplingFactor);
92 typename OutputImageType::RegionType::SizeType upsampledSize = upsampledRegion.GetSize();
95 outImage->SetSpacing( newSpacing );
96 outImage->SetOrigin( newOrigin );
97 outImage->SetDirection( newDirection );
98 outImage->SetRegions( upsampledRegion );
101 int w = upsampledSize[0];
102 int h = upsampledSize[1];
103 int d = upsampledSize[2];
107 for (
int i=0; i<w*h*d; i++)
108 outImageBufferPointer[i] = 0;
111 float minSpacing = 1;
112 if(newSpacing[0]<newSpacing[1] && newSpacing[0]<newSpacing[2])
113 minSpacing = newSpacing[0];
114 else if (newSpacing[1] < newSpacing[2])
115 minSpacing = newSpacing[1];
117 minSpacing = newSpacing[2];
119 vtkSmartPointer<vtkPolyData> fiberPolyData = m_FiberBundle->GetFiberPolyData();
120 vtkSmartPointer<vtkCellArray> vLines = fiberPolyData->GetLines();
121 vLines->InitTraversal();
123 int numFibers = m_FiberBundle->GetNumFibers();
124 boost::progress_display disp(numFibers);
125 for(
int i=0; i<numFibers; i++ )
128 vtkIdType numPoints(0);
129 vtkIdType* points(NULL);
130 vLines->GetNextCell ( numPoints, points );
135 itk::Point<float, 3> vertex = GetItkPoint(fiberPolyData->GetPoint(points[0]));
137 outImage->TransformPhysicalPointToIndex(vertex, index);
139 outImage->SetPixel(index, 1);
141 outImage->SetPixel(index, outImage->GetPixel(index)+1);
146 itk::Point<float, 3> vertex = GetItkPoint(fiberPolyData->GetPoint(points[numPoints-1]));
148 outImage->TransformPhysicalPointToIndex(vertex, index);
150 outImage->SetPixel(index, 1);
152 outImage->SetPixel(index, outImage->GetPixel(index)+1);
157 for (
int i=0; i<w*h*d; i++)
158 outImageBufferPointer[i] = 1-outImageBufferPointer[i];
itk::SmartPointer< Self > Pointer
BoundingBoxType::BoundsArrayType BoundsArrayType
TractsToFiberEndingsImageFilter()
OutputImageType::PixelType OutPixelType
itk::Point< float, 3 > GetItkPoint(double point[3])
virtual ~TractsToFiberEndingsImageFilter()