33 #ifndef __vtkvmtkITKFilterUtilities_h 34 #define __vtkvmtkITKFilterUtilities_h 37 #include "vtkvmtkWin32Header.h" 39 #include "vtkImageData.h" 41 #include "itkCommand.h" 47 template<
typename TImage>
51 typedef TImage ImageType;
52 typedef typename ImageType::Pointer ImagePointer;
53 typedef typename ImageType::PixelType PixelType;
56 input->GetDimensions(dims);
58 input->GetSpacing(spacing);
60 input->GetOrigin(origin);
62 input->GetExtent(extent);
64 output->GetPixelContainer()->SetImportPointer(static_cast<PixelType*>(input->GetScalarPointer()),dims[0]*dims[1]*dims[2],
false);
65 typename ImageType::RegionType region;
66 typename ImageType::IndexType index;
67 typename ImageType::SizeType size;
75 size[0] = extent[1] - extent[0] + 1;
76 size[1] = extent[3] - extent[2] + 1;
77 size[2] = extent[5] - extent[4] + 1;
78 region.SetIndex(index);
80 output->SetLargestPossibleRegion(region);
81 output->SetBufferedRegion(region);
82 output->SetSpacing(spacing);
83 output->SetOrigin(origin);
86 template<
typename TImage>
90 typedef TImage ImageType;
91 typedef typename ImageType::Pointer ImagePointer;
92 typedef typename ImageType::PixelType PixelType;
93 typedef typename ImageType::InternalPixelType InternalPixelType;
96 input->GetDimensions(dims);
98 input->GetSpacing(spacing);
99 int components = input->GetNumberOfScalarComponents();
101 input->GetOrigin(origin);
103 input->GetExtent(extent);
105 output->GetPixelContainer()->SetImportPointer(static_cast<InternalPixelType*>(input->GetScalarPointer()),dims[0]*dims[1]*dims[2]*components,
false);
106 typename ImageType::RegionType region;
107 typename ImageType::IndexType index;
108 typename ImageType::SizeType size;
113 index[0] = extent[0];
114 index[1] = extent[2];
115 index[2] = extent[4];
116 size[0] = extent[1] - extent[0] + 1;
117 size[1] = extent[3] - extent[2] + 1;
118 size[2] = extent[5] - extent[4] + 1;
119 region.SetIndex(index);
120 region.SetSize(size);
121 output->SetLargestPossibleRegion(region);
122 output->SetBufferedRegion(region);
123 output->SetSpacing(spacing);
124 output->SetOrigin(origin);
125 output->SetVectorLength(components);
128 template<
typename TImage>
132 typedef TImage ImageType;
133 typedef typename ImageType::Pointer ImagePointer;
134 typedef typename ImageType::PixelType PixelType;
135 typedef typename ImageType::PointType PointType;
136 typedef typename ImageType::SpacingType SpacingType;
137 typedef typename ImageType::RegionType RegionType;
138 typedef typename ImageType::IndexType IndexType;
139 typedef typename ImageType::SizeType SizeType;
141 PointType origin = input->GetOrigin();
142 SpacingType spacing = input->GetSpacing();
144 double outputOrigin[3];
145 double outputSpacing[3];
147 outputOrigin[0] = origin[0];
148 outputOrigin[1] = origin[1];
149 outputOrigin[2] = origin[2];
151 outputSpacing[0] = spacing[0];
152 outputSpacing[1] = spacing[1];
153 outputSpacing[2] = spacing[2];
155 output->SetOrigin(outputOrigin);
156 output->SetSpacing(outputSpacing);
158 RegionType region = input->GetBufferedRegion();
159 IndexType index = region.GetIndex();
160 SizeType size = region.GetSize();
167 extent[0] = index[0];
168 extent[1] = index[0] + size[0] - 1;
169 extent[2] = index[1];
170 extent[3] = index[1] + size[1] - 1;
171 extent[4] = index[2];
172 extent[5] = index[2] + size[2] - 1;
174 int components = input->GetNumberOfComponentsPerPixel();
175 int dataType = output->GetScalarType();
178 output->SetExtent(extent);
179 output->AllocateScalars(dataType,components);
181 memcpy(static_cast<PixelType*>(output->GetScalarPointer()),input->GetBufferPointer(),input->GetBufferedRegion().GetNumberOfPixels()*
sizeof(PixelType));
187 ((vtkAlgorithm*)data)->UpdateProgress(dynamic_cast<const itk::ProcessObject*>(o)->GetProgress());
193 itk::CStyleCommand::Pointer progressCommand = itk::CStyleCommand::New();
195 progressCommand->SetClientData(alg);
196 obj->AddObserver(itk::ProgressEvent(),progressCommand);
209 template<
class TInputPixel,
class TOutputPixel>
211 vtkvmtkSimpleImageToImageITKFilter<TInputPixel,TOutputPixel>::
212 SimpleExecute(vtkImageData *input, vtkImageData *output)
215 input->GetDimensions(inputDims);
216 double inputSpacing[3];
217 input->GetSpacing(inputSpacing);
219 InputImagePointer inImage = InputImageType::New();
220 inImage->GetPixelContainer()->SetImportPointer(static_cast<InputPixelType*>(input->GetScalarPointer()),inputDims[0]*inputDims[1]*inputDims[2],
false);
221 typename InputImageType::RegionType inputRegion;
222 typename InputImageType::IndexType inputIndex;
223 typename InputImageType::SizeType inputSize;
224 inputIndex[0] = inputIndex[1] = inputIndex[2] = 0;
225 inputSize[0] = inputDims[0];
226 inputSize[1] = inputDims[1];
227 inputSize[2] = inputDims[2];
228 inputRegion.SetIndex(inputIndex);
229 inputRegion.SetSize(inputSize);
230 inImage->SetLargestPossibleRegion(inputRegion);
231 inImage->SetBufferedRegion(inputRegion);
232 inImage->SetSpacing(inputSpacing);
235 output->GetDimensions(outputDims);
236 double outputSpacing[3];
237 output->GetSpacing(outputSpacing);
239 OutputImagePointer outImage = OutputImageType::New();
240 outImage->GetPixelContainer()->SetImportPointer(static_cast<OutputPixelType*>(output->GetScalarPointer()),outputDims[0]*outputDims[1]*outputDims[2],
false);
241 typename OutputImageType::RegionType outputRegion;
242 typename OutputImageType::IndexType outputIndex;
243 typename OutputImageType::SizeType outputSize;
244 outputIndex[0] = outputIndex[1] = outputIndex[2] = 0;
245 outputSize[0] = outputDims[0];
246 outputSize[1] = outputDims[1];
247 outputSize[2] = outputDims[2];
248 outputRegion.SetIndex(outputIndex);
249 outputRegion.SetSize(outputSize);
250 outImage->SetLargestPossibleRegion(outputRegion);
251 outImage->SetBufferedRegion(outputRegion);
252 outImage->SetSpacing(outputSpacing);
254 this->SimpleExecuteITK(inImage,outImage);
256 memcpy(static_cast<OutputPixelType*>(output->GetScalarPointer()),outImage->GetBufferPointer(),outImage->GetBufferedRegion().GetNumberOfPixels()*
sizeof(OutputPixelType));
259 typedef vtkvmtkSimpleImageToImageITKFilter<float,float> vtkvmtkSimpleImageToImageITKFilterFF;
vtkvmtkITKFilterUtilities()
~vtkvmtkITKFilterUtilities()
static void ProgressCallback(itk::Object *o, const itk::EventObject &, void *data)
static void ITKToVTKImage(typename TImage::Pointer input, vtkImageData *output)
static void VTKToITKVectorImage(vtkImageData *input, typename TImage::Pointer output)
static void VTKToITKImage(vtkImageData *input, typename TImage::Pointer output)
Abstract class for wrapping ITK filters.
static void ConnectProgress(itk::Object *obj, vtkAlgorithm *alg)