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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
package require vtk
package require vtkinteraction
# Simple volume rendering example.
vtkSLCReader reader
reader SetFileName "$VTK_DATA_ROOT/Data/sphere.slc"
# Create transfer functions for opacity and color
vtkPiecewiseFunction opacityTransferFunction
opacityTransferFunction AddPoint 0 0.0
opacityTransferFunction AddPoint 30 0.0
opacityTransferFunction AddPoint 80 0.5
opacityTransferFunction AddPoint 255 0.5
vtkColorTransferFunction colorTransferFunction
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
vtkVolumeProperty volumeProperty
volumeProperty SetColor colorTransferFunction
volumeProperty SetScalarOpacity opacityTransferFunction
volumeProperty SetInterpolationTypeToLinear
volumeProperty ShadeOn
vtkRenderer ren1
vtkRenderWindow renWin
renWin AddRenderer ren1
renWin SetSize 600 300
vtkRenderWindowInteractor iren
iren SetRenderWindow renWin
renWin SetMultiSamples 0
ren1 SetBackground 0.1 0.2 0.4
for { set i 0 } { $i < 2 } { incr i } {
for { set j 0 } { $j < 4 } { incr j } {
vtkVolumeTextureMapper2D volumeMapper_${i}_${j}
volumeMapper_${i}_${j} SetInputConnection [reader GetOutputPort]
volumeMapper_${i}_${j} CroppingOn
volumeMapper_${i}_${j} SetCroppingRegionPlanes 17.5 32.5 17.5 32.5 17.5 32.5
vtkVolume volume_${i}_${j}
volume_${i}_${j} SetMapper volumeMapper_${i}_${j}
volume_${i}_${j} SetProperty volumeProperty
vtkVolumeOutlineSource outline_${i}_${j}
outline_${i}_${j} SetVolumeMapper volumeMapper_${i}_${j}
vtkDataSetMapper outlineMapper_${i}_${j}
outlineMapper_${i}_${j} SetInputConnection [outline_${i}_${j} GetOutputPort]
vtkActor outlineActor_${i}_${j}
outlineActor_${i}_${j} SetMapper outlineMapper_${i}_${j}
vtkTransform userMatrix_${i}_${j}
userMatrix_${i}_${j} PostMultiply
userMatrix_${i}_${j} Identity
userMatrix_${i}_${j} Translate -25 -25 -25
if { $i == 0 } {
userMatrix_${i}_${j} RotateX [expr $j*87 + 23]
userMatrix_${i}_${j} RotateY 16
} else {
userMatrix_${i}_${j} RotateX 27
userMatrix_${i}_${j} RotateY [expr $j*87 + 19]
}
userMatrix_${i}_${j} Translate [expr $j*65 + 25] [expr $i*55 + 25] 0
volume_${i}_${j} SetUserTransform userMatrix_${i}_${j}
outlineActor_${i}_${j} SetUserTransform userMatrix_${i}_${j}
ren1 AddViewProp outlineActor_${i}_${j}
ren1 AddViewProp volume_${i}_${j}
}
}
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
outline_0_1 GenerateScalarsOn
outline_0_2 GenerateScalarsOn
outline_0_2 SetActivePlaneId 1
outline_0_2 SetColor 1 0 1
outline_0_3 GenerateScalarsOn
outline_0_3 SetActivePlaneId 2
outline_0_3 SetActivePlaneColor 0 1 1
[outlineActor_1_0 GetProperty] SetColor 0 1 0
outline_1_1 GenerateFacesOn
volume_1_1 VisibilityOff
outline_1_2 GenerateFacesOn
outline_1_2 GenerateScalarsOn
volume_1_2 VisibilityOff
outline_1_3 GenerateFacesOn
outline_1_3 GenerateScalarsOn
outline_1_3 SetActivePlaneId 1
volume_1_3 VisibilityOff
[ren1 GetCullers] InitTraversal
set culler [[ren1 GetCullers] GetNextItem]
$culler SetSortingStyleToBackToFront
ren1 ResetCamera
[ren1 GetActiveCamera] Zoom 2.35
renWin Render
proc TkCheckAbort {} {
set foo [renWin GetEventPending]
if {$foo != 0} {renWin SetAbortRender 1}
}
renWin AddObserver "AbortCheckEvent" {TkCheckAbort}
iren AddObserver UserEvent {wm deiconify .vtkInteract}
iren Initialize
wm withdraw .
|