[vtkusers] drawing a simple volumetric cube

Vladislav Petyuk petyuk at gmail.com
Tue Apr 3 18:54:23 EDT 2007


Hi,

I have a very basic question: what is the right way to create a volumetric
cube or voxel with a certain scalar value associated with it. The way I've
done it so far is show below with Python code. It just seems a little bit
awkward to me, that I have to define quite a bit of points instead of just 8
to draw a cube with vtkVolumeRayCastCompositeFunction. If I use N = 2 (that
is 8 points) it does not looks like a cube any more. It looks like a cube
again if I switch to vtkVolumeRayCastIsosurfaceFunction or
vtkVolumeRayCastMIPFunction, but transparency and color function do not work
in the first case and shade in the second. I'm not sure if I'm drawing a
cube in a right way.



So my question is: how one should draw a volumetric cube or voxel by
defining just 8 points, so the transparency and color can be set according
to a scalar value, and with shades?



I'm planning to use those cubes/voxels for a 3D object reconstruction (with
non-hexahedral shape), which was cut into bunch of cubes. Scalar values
associated with those cubes represent the intensities of a certain measured
parameter.



Thank you for any advice,

Vlad







import vtk



ren = vtk.vtkRenderer()

renWin = vtk.vtkRenderWindow()

renWin.AddRenderer(ren)

iren = vtk.vtkRenderWindowInteractor()

iren.SetRenderWindow(renWin)



N = 10 #number of points along a dimension.

#cube looks awkward if N < 4

imData = vtk.vtkImageData()

imData.SetDimensions(N,N,N)



scalars = vtk.vtkUnsignedShortArray()

scalars.SetNumberOfValues(N**3)



value = 100 #some fixed value to assign

for x in range(N**3):

            scalars.SetValue(x,value)



imData.GetPointData().SetScalars(scalars)



opacityTransferFunction = vtk.vtkPiecewiseFunction()

opacityTransferFunction.AddPoint(0.0, 0.3)

opacityTransferFunction.AddPoint(255.0, 0.3)



colorTransferFunction = vtk.vtkColorTransferFunction()

colorTransferFunction.AddRGBPoint(0.0, 1,0,0)

colorTransferFunction.AddRGBPoint(127.0, 0,1,0)

colorTransferFunction.AddRGBPoint(255.0, 0,0,1)



volumeProperty = vtk.vtkVolumeProperty()

volumeProperty.SetScalarOpacity(opacityTransferFunction)

volumeProperty.SetColor(colorTransferFunction)

volumeProperty.ShadeOn()

volumeProperty.SetInterpolationTypeToNearest()



rayCastFunction = vtk.vtkVolumeRayCastCompositeFunction()

##rayCastFunction = vtk.vtkVolumeRayCastMIPFunction()

##rayCastFunction = vtk.vtkVolumeRayCastIsosurfaceFunction()

volumeMapper = vtk.vtkVolumeRayCastMapper()

volumeMapper.SetVolumeRayCastFunction(rayCastFunction)

volumeMapper.SetInput(imData)



volume = vtk.vtkVolume()

volume.SetMapper(volumeMapper)

volume.SetProperty(volumeProperty)



ren.AddVolume(volume)

ren.SetBackground(0.5,0.5,0.5)

renWin.SetSize(600,600)

iren.Initialize()

renWin.Render()

iren.Start()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070403/17b5c99d/attachment.htm>


More information about the vtkusers mailing list