[vtkusers] saving voxel data to image file

Julien Gout julien.gout at helmholtz-berlin.de
Tue Mar 2 08:24:22 EST 2010


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

Hahn-Meitner-Platz 1
D-14109 Berlin
phone:  +49 (0)30 8062-2377
fax:    +49 (0)30 8062-2377
E-Mail:  julien.gout at helmholtz-berlin.de




More information about the vtkusers mailing list