1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
# Simple volume rendering example.
reader = vtk.vtkSLCReader()
reader.SetFileName(VTK_DATA_ROOT + "/Data/sphere.slc")
# Create transfer functions for opacity and color
opacityTransferFunction = vtk.vtkPiecewiseFunction()
opacityTransferFunction.AddPoint(0, 0.0)
opacityTransferFunction.AddPoint(30, 0.0)
opacityTransferFunction.AddPoint(80, 0.5)
opacityTransferFunction.AddPoint(255, 0.5)
colorTransferFunction = vtk.vtkColorTransferFunction()
colorTransferFunction.AddRGBPoint(0.0, 0.0, 0.0, 0.0)
colorTransferFunction.AddRGBPoint(64.0, 1.0, 0.0, 0.0)
colorTransferFunction.AddRGBPoint(128.0, 0.0, 0.0, 1.0)
colorTransferFunction.AddRGBPoint(192.0, 0.0, 1.0, 0.0)
colorTransferFunction.AddRGBPoint(255.0, 0.0, 0.2, 0.0)
# Create properties, mappers, volume actors, and ray cast function
volumeProperty = vtk.vtkVolumeProperty()
volumeProperty.SetColor(colorTransferFunction)
volumeProperty.SetScalarOpacity(opacityTransferFunction)
volumeProperty.SetInterpolationTypeToLinear()
volumeProperty.ShadeOn()
ren1 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
renWin.SetSize(600, 300)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
ren1.SetBackground(0.1, 0.2, 0.4)
renWin.Render()
i = 0
while i < 2:
j = 0
while j < 4:
idx = str(i) + "_" + str(j)
exec("volumeMapper_" + idx + " = vtk.vtkVolumeTextureMapper3D()")
eval("volumeMapper_" + idx).SetInputConnection(reader.GetOutputPort())
eval("volumeMapper_" + idx).SetSampleDistance(0.25)
eval("volumeMapper_" + idx).CroppingOn()
eval("volumeMapper_" + idx).SetCroppingRegionPlanes(
17, 33, 17, 33, 17, 33)
exec("volume_" + idx + " = vtk.vtkVolume()")
eval("volume_" + idx).SetMapper(eval("volumeMapper_" + idx))
eval("volume_" + idx).SetProperty(volumeProperty)
exec("userMatrix_" + idx + " = vtk.vtkTransform()")
eval("userMatrix_" + idx).PostMultiply()
eval("userMatrix_" + idx).Identity()
eval("userMatrix_" + idx).Translate(-25, -25, -25)
if (i == 0):
eval("userMatrix_" + idx).RotateX(j * 90 + 20)
eval("userMatrix_" + idx).RotateY(20)
pass
else:
eval("userMatrix_" + idx).RotateX(20)
eval("userMatrix_" + idx).RotateY(j * 90 + 20)
pass
eval("userMatrix_" + idx).Translate(j * 55 + 25, i * 55 + 25, 0)
eval("volume_" + idx).SetUserTransform(eval("userMatrix_" + idx))
ren1.AddViewProp(eval("volume_" + idx))
j += 1
i += 1
volumeMapper_0_0.SetCroppingRegionFlagsToSubVolume()
volumeMapper_0_1.SetCroppingRegionFlagsToCross()
volumeMapper_0_2.SetCroppingRegionFlagsToInvertedCross()
volumeMapper_0_3.SetCroppingRegionFlags(24600)
volumeMapper_1_0.SetCroppingRegionFlagsToFence()
volumeMapper_1_1.SetCroppingRegionFlagsToInvertedFence()
volumeMapper_1_2.SetCroppingRegionFlags(1)
volumeMapper_1_3.SetCroppingRegionFlags(67117057)
ren1.GetCullers().InitTraversal()
culler = ren1.GetCullers().GetNextItem()
culler.SetSortingStyleToBackToFront()
valid = volumeMapper_0_0.IsRenderSupported(volumeProperty, ren1)
if not valid:
ren1.RemoveAllViewProps()
t = vtk.vtkTextActor()
t.SetInput("Required Extensions Not Supported")
t.SetDisplayPosition(300, 150)
t.GetTextProperty().SetJustificationToCentered()
ren1.AddViewProp(t)
pass
ren1.ResetCamera()
ren1.GetActiveCamera().Zoom(3.0)
renWin.Render()
def TkCheckAbort (object_binding, event_name):
foo = renWin.GetEventPending()
if (foo != 0):
renWin.SetAbortRender(1)
iren.Initialize()
#iren.Start()
|