[vtkusers] Problem with vtkMarchingCubes

Zeike Taylor ztaylor at itee.uq.edu.au
Tue Aug 3 19:59:24 EDT 2010


Hello,

I'm having trouble with vtkMarchingCubes, and I think it is to do with
the anisotropic voxel sizes (0.9375x0.9375x4mm) of my images. I'm using
nifti images, which I import using vtkImageImport. The marching cubes
algorithm extracts a surface well enough and it can be seen to be
"approximately" correct, however the z-coords are squashed. If I
multiply each z-coord by 4 and redraw, the mesh looks roughly as it
should. However, this is no good as the facets are now stretched in the
z-dir'n, making them unsuitable for the subsequent application.

My (partial) pipeline is as follows:

// Load nifti img
nifti_image *im = nifti_image_read(imgName,true);

// Set up vtk image data
vtkImageImport* importer = vtkImageImport::New();
importer->SetImportVoidPointer((void*)im->data);
importer->SetDataScalarTypeToFloat();
importer->SetDataExtent(0, im->nx-1, 0, im->ny-1, 0, im->nz-1);
importer->SetWholeExtent(0, im->nx-1, 0, im->ny-1, 0, im->nz-1);
vtkImageData* imData = importer->GetOutput();
imData->SetScalarTypeToFloat();
imData->SetExtent(0, im->nx-1, 0, im->ny-1, 0, im->nz-1);
imData->SetSpacing(im->dx, im->dy, im->dz);

// Apply the Marching Cubes algorithm
vtkMarchingCubes* surfaceExtractor = vtkMarchingCubes::New();
surfaceExtractor->SetValue(0, isoVal);
surfaceExtractor->SetInput((vtkDataObject*)imData);
vtkPolyData* surface = surfaceExtractor->GetOutput();
surfaceExtractor->Update();

The image dimensions and spacing seem to transfer properly to imData:
i.e. the vals returned by imData->GetDimensions() and
imData->GetSpacing() are correct, but it's as if vtkMarchingCubes
ignores them. I also tried resampling with isotropic voxels using
vtkImageResample, with no luck.

Any advice welcome.
Thanks,
Zeike



More information about the vtkusers mailing list