The snippet you have below is not going to work :<br><br> vtkImageData* imData = importer->GetOutput();<br> imData->SetSpacing(im->dx, im->dy, im->dz);<br> surfaceExtractor->SetInput((vtkDataObject*)imData);<br>
<br>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)..<br>
<br>Try this instead...<br><br> importer->SetDataSpacing(im->dx, im->dy, im->dz);<br> vtkImageData* imData = importer->GetOutput();<br> surfaceExtractor->SetInput((vtkDataObject*)imData);<br>
<br>--<br>karthik<br><br><div class="gmail_quote">On Wed, Aug 4, 2010 at 5:29 AM, Zeike Taylor <span dir="ltr"><<a href="mailto:ztaylor@itee.uq.edu.au">ztaylor@itee.uq.edu.au</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello,<br>
<br>
I'm having trouble with vtkMarchingCubes, and I think it is to do with<br>
the anisotropic voxel sizes (0.9375x0.9375x4mm) of my images. I'm using<br>
nifti images, which I import using vtkImageImport. The marching cubes<br>
algorithm extracts a surface well enough and it can be seen to be<br>
"approximately" correct, however the z-coords are squashed. If I<br>
multiply each z-coord by 4 and redraw, the mesh looks roughly as it<br>
should. However, this is no good as the facets are now stretched in the<br>
z-dir'n, making them unsuitable for the subsequent application.<br>
<br>
My (partial) pipeline is as follows:<br>
<br>
// Load nifti img<br>
nifti_image *im = nifti_image_read(imgName,true);<br>
<br>
// Set up vtk image data<br>
vtkImageImport* importer = vtkImageImport::New();<br>
importer->SetImportVoidPointer((void*)im->data);<br>
importer->SetDataScalarTypeToFloat();<br>
importer->SetDataExtent(0, im->nx-1, 0, im->ny-1, 0, im->nz-1);<br>
importer->SetWholeExtent(0, im->nx-1, 0, im->ny-1, 0, im->nz-1);<br>
vtkImageData* imData = importer->GetOutput();<br>
imData->SetScalarTypeToFloat();<br>
imData->SetExtent(0, im->nx-1, 0, im->ny-1, 0, im->nz-1);<br>
imData->SetSpacing(im->dx, im->dy, im->dz);<br>
<br>
// Apply the Marching Cubes algorithm<br>
vtkMarchingCubes* surfaceExtractor = vtkMarchingCubes::New();<br>
surfaceExtractor->SetValue(0, isoVal);<br>
surfaceExtractor->SetInput((vtkDataObject*)imData);<br>
vtkPolyData* surface = surfaceExtractor->GetOutput();<br>
surfaceExtractor->Update();<br>
<br>
The image dimensions and spacing seem to transfer properly to imData:<br>
i.e. the vals returned by imData->GetDimensions() and<br>
imData->GetSpacing() are correct, but it's as if vtkMarchingCubes<br>
ignores them. I also tried resampling with isotropic voxels using<br>
vtkImageResample, with no luck.<br>
<br>
Any advice welcome.<br>
Thanks,<br>
Zeike<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
</blockquote></div><br>