14 #ifndef __itkImageToVTKImageDataFilter_hxx 15 #define __itkImageToVTKImageDataFilter_hxx 19 #include "vtkImageData.h" 20 #include "vtkDoubleArray.h" 21 #include "vtkPointData.h" 29 template <
class TInputImage>
39 template <
class TInputImage>
50 template <
class TInputImage>
56 this->ProcessObject::SetNthInput( 0,
57 const_cast< InputImageType * >( image ) );
63 template <
class TInputImage>
68 return itkDynamicCastInDebugMode< const TInputImage * >(this->GetPrimaryInput());
74 template <
class TInputImage>
83 InputSizeType inputSize = inputImage->GetLargestPossibleRegion().GetSize();
86 unsigned int numberOfComponentsPerPixel
87 = inputImage->GetNumberOfComponentsPerPixel();
90 m_Image = OutputImageType::New();
92 int outputSize[Dimension];
93 double outputSpacing[Dimension];
94 double outputOrigin[Dimension];
95 vtkIdType numberOfVoxels = 1;
97 for (
unsigned int k=0; k<Dimension; k++)
99 outputSize[k] = inputSize[k];
100 outputSpacing[k] = inputSpacing[k];
101 outputOrigin[k] = inputOrigin[k];
102 numberOfVoxels *= outputSize[k];
105 m_Image->SetDimensions(outputSize);
106 m_Image->SetSpacing(outputSpacing);
107 m_Image->SetOrigin(outputOrigin);
110 vtkSmartPointer<vtkDoubleArray> data =
111 vtkSmartPointer<vtkDoubleArray>::New();
113 data->SetNumberOfComponents(numberOfComponentsPerPixel);
114 data->SetNumberOfTuples(numberOfVoxels);
115 data->SetName(
"scalars");
119 inputIt(inputImage, inputImage->GetLargestPossibleRegion());
126 double dataEntry[numberOfComponentsPerPixel];
128 while(!inputIt.IsAtEnd())
130 inputPixel = inputIt.Get();
131 for (
unsigned int k = 0; k < numberOfComponentsPerPixel; k++)
133 dataEntry[k] =
static_cast<double>( inputPixel[k] );
135 data->SetTuple(i, dataEntry);
140 m_Image->GetPointData()->AddArray(data);
141 m_Image->GetPointData()->SetActiveScalars(data->GetName());
InputImageType::PointType InputPointType
ImageToVTKImageDataFilter()
InputImageType::SizeType InputSizeType
vtkImageData * GetOutput() const
virtual void SetInput(const InputImageType *image)
InputImageType::SpacingType InputSpacingType
TInputImage InputImageType
const InputImageType * GetInput() const
InputImageType::ConstPointer InputImageConstPointer
virtual void GenerateData() ITK_OVERRIDE
ImageRegionConstIterator< InputImageType > InputImageIteratorType
InputImageType::PixelType InputPixelType