[vtkusers] saving voxel data to image file

David Doria daviddoria+vtk at gmail.com
Tue Mar 2 09:11:51 EST 2010


On Tue, Mar 2, 2010 at 8:24 AM, Julien Gout <julien.gout at helmholtz-berlin.de
> wrote:

> Hi everyone,
>
> I am trying to create voxel data from a mesh I extracted out of a blender
> project and save that data to a .tiff file.
>
> But apparently I fail to provide the right data format to vtkImageCast (or
> vtkImageWriter) resulting in the error
>
> ERROR: In /hmi/ftd/vtk/VTK/Imaging/vtkImageCast.cxx, line 149
> vtkImageCast (0x26114c0): Execute: Unknown input ScalarType
>
> Unfortunately the only example for the vtkVoxelModeller on the vtk Wiki
> pages is under the category "Broken/Missing"...
>
> Can anyone help with this?
>
> Here is my source code:
>
> import sys
> import bpy
> import vtk
> import VTKBlender
>
> print "retrieve mesh data from blender"
> appendFilter = vtk.vtkAppendPolyData()
> for me in bpy.data.meshes:
>    appendFilter.AddInput(VTKBlender.BlenderToPolyData(me))
> appendFilter.Update()
>
> mapper = vtk.vtkPolyDataMapper()
> mapper = appendFilter.GetOutput()
>
> print "Voxelize mesh data"
> x = y = z = 10
> xmin = ymin = zmin = -10.0
> xmax = ymax = zmax = 10.0
> voxeler = vtk.vtkVoxelModeller()
> voxeler.SetInput(mapper)
> voxeler.SetSampleDimensions(x, y, z)
> #voxeler.SetModelBounds(xmin, xmax, ymin, ymax, zmin, zmax)
> voxeler.Update()
>
> print "Cast voxel data"
> cast = vtk.vtkImageCast();
> cast.SetInputConnection(voxeler.GetOutputPort());
> cast.SetOutputScalarTypeToUnsignedChar()
> cast.Update()
>
> print "write voxel data to .tif file"
> aWriter = vtk.vtkImageWriter()
> aWriter.SetInputConnection(cast.GetOutputPort())
> aWriter.SetFileName("voxelModel.tif")
> aWriter.SetFileDimensionality(3)
> aWriter.Write()
>
> sys.exit(0)
>
>
> --
> Julien Gout
>
> Helmholtz-Zentrum Berlin für Materialien und Energie GmbH
> Institute of applied material sciences
>
>
Can you describe what are you trying to get, exactly? You start with a mesh,
and you want what?

Thanks,

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100302/b229224e/attachment.htm>


More information about the vtkusers mailing list