[vtkusers] Converting vtkStructuredGrid to vtkImageData using vtkProbeFilter

Mark Gooding mark.gooding at gmail.com
Tue Mar 6 11:58:19 EST 2007


Hi all,

I'm struggling to get my resampling working using a vtkProbeFilter.
>From what I've found in the archive and on the wiki it doesn't seem
like it should be that complicated, but my output extent/spacing
doesn't match my input extent/spacing. In fact the output extent comes
back as [0 -1 0 -1 0 -1] so I guess I've got something wrong.

To test the code I have been using a vtkStructuredGrid which happens
to contain data in a cartesian format anyway, so that working out the
vtkImageData dimensions is simple at this stage. And so I know what
result to expect.  I'm hoping that I'm setting up the
vtkStructuredGrid right, but even if I'm not, sure then the probe
output should still be the same size as the input, just with a whole
load of nothing?

Any suggestions/help appreiciated!

Cheers,

Mark

imageDataPoints = vtkPoints::New();
imageDataPoints->SetDataTypeToFloat();
imageDataPoints->SetNumberOfPoints(imageDataScalars->GetNumberOfTuples());
for(i=0;i<discrete_size[0];i++){
	for(j=0;j<discrete_size[1];j++){
		for(k=0;k<discrete_size[2];k++){
imageDataPoints->SetPoint((k+(j+i*discrete_size[1])*discrete_size[2]),(double)i*voxelResolution[0],(double)j*voxelResolution[1],(double)k*voxelResolution[2]);
		}
	}
}

imageDataStructuredGrid = vtkStructuredGrid::New();
imageDataStructuredGrid->SetDimensions(discrete_size[0],
discrete_size[1], discrete_size[2]);
imageDataStructuredGrid->SetPoints(imageDataPoints);
imageDataStructuredGrid->GetPointData()->SetScalars(imageDataScalars);
imageDataStructuredGrid->Update();

vtkImageData* samplingArray = vtkImageData::New();
samplingArray->SetNumberOfScalarComponents(1);
samplingArray->SetScalarTypeToUnsignedChar();
samplingArray->SetSpacing(voxelResolution[0],voxelResolution[1],voxelResolution[2]);
samplingArray->SetDimensions(discrete_size[0], discrete_size[1],
discrete_size[2]);
samplingArray->SetOrigin( 0,0,0 );
samplingArray->Update();

vtkProbeFilter* resampler = vtkProbeFilter::New();
resampler->SetSource(imageDataStructuredGrid);
resampler->SetInput(samplingArray);
			
imageCartesianData = vtkImageData::New();
imageCartesianData->DeepCopy(resampler->GetImageDataOutput());



More information about the vtkusers mailing list