[vtkusers] Problem with vtkMarchingCubes

Karthik Krishnan karthik.krishnan at kitware.com
Wed Aug 4 09:40:16 EDT 2010


The snippet you have below is not going to work :

  vtkImageData* imData = importer->GetOutput();
  imData->SetSpacing(im->dx, im->dy, im->dz);
  surfaceExtractor->SetInput((vtkDataObject*)imData);

What's going to happen is that the downstream filter (marching cubes) is
going to update the upstream filter (importer) which is going to overwrite
the spacing (defaults to 1 in vtkImageImport) set on its output. You can't
modify the output of a pipeline like that without disconnecting it (via
ShallowCopy)..

Try this instead...

  importer->SetDataSpacing(im->dx, im->dy, im->dz);
  vtkImageData* imData = importer->GetOutput();
  surfaceExtractor->SetInput((vtkDataObject*)imData);

--
karthik

On Wed, Aug 4, 2010 at 5:29 AM, Zeike Taylor <ztaylor at itee.uq.edu.au> wrote:

> 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
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100804/1923b912/attachment.htm>


More information about the vtkusers mailing list