Skip to content
Snippets Groups Projects
Commit 66cc5e93 authored by Brad King's avatar Brad King Committed by Code Review
Browse files

Merge topic 'residue-rendering-tcl-tests' into master

77bcbd75 Residue of code previously moved to VolumeRendering/Testing/Tcl
parents a19e8705 77bcbd75
No related branches found
No related tags found
No related merge requests found
package require vtk
package require vtkinteraction
# Create the standard renderer, render window
# and interactor
vtkRenderer ren1
vtkRenderWindow renWin
renWin AddRenderer ren1
vtkRenderWindowInteractor iren
iren SetRenderWindow renWin
iren SetDesiredUpdateRate 3
# Create the reader for the data
# This is the data the will be volume rendered
vtkStructuredPointsReader reader
reader SetFileName "$VTK_DATA_ROOT/Data/ironProt.vtk"
# create a reader for the other data that will
# be contoured and displayed as a polygonal mesh
vtkSLCReader reader2
reader2 SetFileName "$VTK_DATA_ROOT/Data/neghip.slc"
# convert from vtkImageData to vtkUnstructuredGrid, remove
# any cells where all values are below 80
vtkThreshold thresh
thresh ThresholdByUpper 80
thresh AllScalarsOff
thresh SetInputConnection [reader GetOutputPort]
# make sure we have only tetrahedra
vtkDataSetTriangleFilter trifilter
trifilter SetInputConnection [thresh GetOutputPort]
# Create transfer mapping scalar value to opacity
vtkPiecewiseFunction opacityTransferFunction
opacityTransferFunction AddPoint 80 0.0
opacityTransferFunction AddPoint 120 0.2
opacityTransferFunction AddPoint 255 0.2
# Create transfer mapping scalar value to color
vtkColorTransferFunction colorTransferFunction
colorTransferFunction AddRGBPoint 80.0 0.0 0.0 0.0
colorTransferFunction AddRGBPoint 120.0 0.0 0.0 1.0
colorTransferFunction AddRGBPoint 160.0 1.0 0.0 0.0
colorTransferFunction AddRGBPoint 200.0 0.0 1.0 0.0
colorTransferFunction AddRGBPoint 255.0 0.0 1.0 1.0
# The property describes how the data will look
vtkVolumeProperty volumeProperty
volumeProperty SetColor colorTransferFunction
volumeProperty SetScalarOpacity opacityTransferFunction
volumeProperty ShadeOff
volumeProperty SetInterpolationTypeToLinear
# The mapper / ray cast function know how to render the data
vtkUnstructuredGridVolumeRayCastMapper volumeMapper
volumeMapper SetInputConnection [trifilter GetOutputPort]
# The volume holds the mapper and the property and
# can be used to position/orient the volume
vtkVolume volume
volume SetMapper volumeMapper
volume SetProperty volumeProperty
# contour the second dataset
vtkContourFilter contour
contour SetValue 0 80
contour SetInputConnection [reader2 GetOutputPort]
# create a mapper for the polygonal data
vtkPolyDataMapper mapper
mapper SetInputConnection [contour GetOutputPort]
mapper ScalarVisibilityOff
# create an actor for the polygonal data
vtkActor actor
actor SetMapper mapper
ren1 AddViewProp actor
ren1 AddVolume volume
renWin SetSize 300 300
[ren1 GetActiveCamera] Azimuth 20.0
[ren1 GetActiveCamera] Elevation 10.0
[ren1 GetActiveCamera] Zoom 1.5
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 .
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
vtkVolumeRayCastCompositeFunction compositeFunction
vtkRenderer ren1
vtkRenderWindow renWin
renWin AddRenderer ren1
renWin SetSize 600 300
vtkRenderWindowInteractor iren
iren SetRenderWindow renWin
ren1 SetBackground 0.1 0.2 0.4
for { set i 0 } { $i < 2 } { incr i } {
for { set j 0 } { $j < 4 } { incr j } {
vtkVolumeRayCastMapper volumeMapper_${i}_${j}
volumeMapper_${i}_${j} SetInputConnection [reader GetOutputPort]
volumeMapper_${i}_${j} SetVolumeRayCastFunction compositeFunction
volumeMapper_${i}_${j} SetSampleDistance 0.4
volumeMapper_${i}_${j} CroppingOn
volumeMapper_${i}_${j} SetCroppingRegionPlanes 17 33 17 33 17 33
vtkVolume volume_${i}_${j}
volume_${i}_${j} SetMapper volumeMapper_${i}_${j}
volume_${i}_${j} SetProperty volumeProperty
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*55 + 25] [expr $i*55 + 25] 0
volume_${i}_${j} SetUserTransform userMatrix_${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
[ren1 GetCullers] InitTraversal
set culler [[ren1 GetCullers] GetNextItem]
$culler SetSortingStyleToBackToFront
ren1 ResetCamera
[ren1 GetActiveCamera] Zoom 3.0
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 .
package require vtk
# Simple volume rendering example.
vtkImageReader reader
reader SetDataByteOrderToLittleEndian
reader SetDataExtent 0 63 0 63 1 93
reader SetFilePrefix "$VTK_DATA_ROOT/Data/headsq/quarter"
reader SetDataMask 0x7fff
reader SetDataSpacing 2 2 1
reader SetDataScalarTypeToUnsignedShort
reader Update
set readerOutput [reader GetOutput]
$readerOutput SetOrigin -63 -63 -46
# Disconnect the output from its reader. First get an extra reference.
$readerOutput Register {}
$readerOutput SetSource {}
# Create transfer functions for opacity and color
vtkPiecewiseFunction opacityTransferFunction
opacityTransferFunction AddPoint 600 0.0
opacityTransferFunction AddPoint 2000 1.0
vtkColorTransferFunction colorTransferFunction
colorTransferFunction ClampingOff
colorTransferFunction AddHSVPoint 0.0 0.01 1.0 1.0
colorTransferFunction AddHSVPoint 1000.0 0.50 1.0 1.0
colorTransferFunction AddHSVPoint 2000.0 0.99 1.0 1.0
colorTransferFunction SetColorSpaceToHSV
# Create properties, mappers, volume actors, and ray cast function
vtkVolumeProperty volumeProperty
volumeProperty SetColor colorTransferFunction
volumeProperty SetScalarOpacity opacityTransferFunction
volumeProperty SetInterpolationTypeToLinear
vtkVolumeRayCastCompositeFunction f
vtkVolumeRayCastMapper volumeMapper
volumeMapper SetInput $readerOutput
volumeMapper SetVolumeRayCastFunction f
volumeMapper SetSampleDistance 0.3
# The data object is now referenced by the connection.
$readerOutput UnRegister {}
vtkVolume volume
volume SetMapper volumeMapper
volume SetProperty volumeProperty
# Create geometric sphere
vtkSphereSource sphereSource
sphereSource SetRadius 65
sphereSource SetThetaResolution 20
sphereSource SetPhiResolution 40
# Compute random scalars (colors) for each cell
vtkProgrammableAttributeDataFilter randomColors
randomColors SetInputConnection [sphereSource GetOutputPort]
randomColors SetExecuteMethod colorCells
proc colorCells {} {
vtkMath randomColorGenerator
set input [randomColors GetInput]
set output [randomColors GetOutput]
set numCells [$input GetNumberOfCells]
vtkFloatArray colors
colors SetNumberOfTuples $numCells
for {set i 0} {$i < $numCells} {incr i} {
colors SetValue $i [randomColorGenerator Random 0 1]
}
[$output GetCellData] CopyScalarsOff
[$output GetCellData] PassData [$input GetCellData]
[$output GetCellData] SetScalars colors
colors Delete; #reference counting - it's ok
randomColorGenerator Delete
}
vtkPolyDataMapper sphereMapper
sphereMapper SetInput [randomColors GetPolyDataOutput]
vtkActor sphereActor
sphereActor SetMapper sphereMapper
# Set up the planes
vtkPlane plane1
plane1 SetOrigin 0 0 -10
plane1 SetNormal 0 0 1
vtkPlane plane2
plane2 SetOrigin 0 0 10
plane2 SetNormal 0 0 -1
vtkPlane plane3
plane3 SetOrigin -10 0 0
plane3 SetNormal 1 0 0
vtkPlane plane4
plane4 SetOrigin 10 0 0
plane4 SetNormal -1 0 0
sphereMapper AddClippingPlane plane1
sphereMapper AddClippingPlane plane2
volumeMapper AddClippingPlane plane3
volumeMapper AddClippingPlane plane4
# Okay now the graphics stuff
vtkRenderer ren1
vtkRenderWindow renWin
renWin AddRenderer ren1
renWin SetSize 256 256
vtkRenderWindowInteractor iren
iren SetRenderWindow renWin
[ren1 GetCullers] InitTraversal
set culler [[ren1 GetCullers] GetNextItem]
$culler SetSortingStyleToBackToFront
ren1 AddViewProp sphereActor
ren1 AddViewProp volume
ren1 SetBackground 0.1 0.2 0.4
renWin Render
[ren1 GetActiveCamera] Azimuth 45
[ren1 GetActiveCamera] Elevation 15
[ren1 GetActiveCamera] Roll 45
[ren1 GetActiveCamera] Zoom 2.0
wm withdraw .
iren Initialize
for { set i 0 } { $i < 5 } { incr i } {
volume RotateY 17
volume RotateZ 13
sphereActor RotateX 13
sphereActor RotateY 17
}
renWin Render
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
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 33 17 33 17 33
vtkVolume volume_${i}_${j}
volume_${i}_${j} SetMapper volumeMapper_${i}_${j}
volume_${i}_${j} SetProperty volumeProperty
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*90 + 20]
userMatrix_${i}_${j} RotateY 20
} else {
userMatrix_${i}_${j} RotateX 20
userMatrix_${i}_${j} RotateY [expr $j*90 + 20]
}
userMatrix_${i}_${j} Translate [expr $j*55 + 25] [expr $i*55 + 25] 0
volume_${i}_${j} SetUserTransform userMatrix_${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
[ren1 GetCullers] InitTraversal
set culler [[ren1 GetCullers] GetNextItem]
$culler SetSortingStyleToBackToFront
ren1 ResetCamera
[ren1 GetActiveCamera] Zoom 3.0
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 .
package require vtk
# Simple volume rendering example.
vtkImageReader reader
reader SetDataByteOrderToLittleEndian
reader SetDataExtent 0 63 0 63 1 93
reader SetFilePrefix "$VTK_DATA_ROOT/Data/headsq/quarter"
reader SetDataMask 0x7fff
reader SetDataSpacing 2 2 1
reader SetDataScalarTypeToUnsignedShort
reader Update
set readerOutput [reader GetOutput]
$readerOutput SetOrigin -63 -63 -46
# Disconnect the output from its reader. First get an extra reference.
$readerOutput Register {}
$readerOutput SetSource {}
# Create transfer functions for opacity and color
vtkPiecewiseFunction opacityTransferFunction
opacityTransferFunction AddPoint 600 0.0
opacityTransferFunction AddPoint 2000 1.0
vtkColorTransferFunction colorTransferFunction
colorTransferFunction ClampingOff
colorTransferFunction AddHSVPoint 0.0 0.01 1.0 1.0
colorTransferFunction AddHSVPoint 1000.0 0.50 1.0 1.0
colorTransferFunction AddHSVPoint 2000.0 0.99 1.0 1.0
colorTransferFunction SetColorSpaceToHSV
# Create properties, mappers, volume actors, and ray cast function
vtkVolumeProperty volumeProperty
volumeProperty SetColor colorTransferFunction
volumeProperty SetScalarOpacity opacityTransferFunction
vtkVolumeTextureMapper2D volumeMapper
volumeMapper SetInput $readerOutput
volumeMapper SetMaximumStorageSize 10000000
# The data object is now referenced by the connection.
$readerOutput UnRegister {}
vtkVolume volume
volume SetMapper volumeMapper
volume SetProperty volumeProperty
# Create geometric sphere
vtkSphereSource sphereSource
sphereSource SetRadius 65
sphereSource SetThetaResolution 20
sphereSource SetPhiResolution 40
# Compute random scalars (colors) for each cell
vtkProgrammableAttributeDataFilter randomColors
randomColors SetInputConnection [sphereSource GetOutputPort]
randomColors SetExecuteMethod colorCells
proc colorCells {} {
vtkMath randomColorGenerator
set input [randomColors GetInput]
set output [randomColors GetOutput]
set numCells [$input GetNumberOfCells]
vtkFloatArray colors
colors SetNumberOfTuples $numCells
for {set i 0} {$i < $numCells} {incr i} {
colors SetValue $i [randomColorGenerator Random 0 1]
}
[$output GetCellData] CopyScalarsOff
[$output GetCellData] PassData [$input GetCellData]
[$output GetCellData] SetScalars colors
colors Delete; #reference counting - it's ok
randomColorGenerator Delete
}
vtkPolyDataMapper sphereMapper
sphereMapper SetInput [randomColors GetPolyDataOutput]
vtkActor sphereActor
sphereActor SetMapper sphereMapper
# Set up the planes
vtkPlane plane1
plane1 SetOrigin 0 0 -10
plane1 SetNormal 0 0 1
vtkPlane plane2
plane2 SetOrigin 0 0 10
plane2 SetNormal 0 0 -1
vtkPlane plane3
plane3 SetOrigin -10 0 0
plane3 SetNormal 1 0 0
vtkPlane plane4
plane4 SetOrigin 10 0 0
plane4 SetNormal -1 0 0
sphereMapper AddClippingPlane plane1
sphereMapper AddClippingPlane plane2
volumeMapper AddClippingPlane plane3
volumeMapper AddClippingPlane plane4
# Okay now the graphics stuff
vtkRenderer ren1
vtkRenderWindow renWin
renWin AddRenderer ren1
renWin SetSize 256 256
vtkRenderWindowInteractor iren
iren SetRenderWindow renWin
[ren1 GetCullers] InitTraversal
set culler [[ren1 GetCullers] GetNextItem]
$culler SetSortingStyleToBackToFront
ren1 AddViewProp sphereActor
ren1 AddViewProp volume
ren1 SetBackground 0.1 0.2 0.4
renWin Render
[ren1 GetActiveCamera] Azimuth 45
[ren1 GetActiveCamera] Elevation 15
[ren1 GetActiveCamera] Roll 45
[ren1 GetActiveCamera] Zoom 2.0
wm withdraw .
iren Initialize
for { set i 0 } { $i < 5 } { incr i } {
volume RotateY 17
volume RotateZ 13
sphereActor RotateX 13
sphereActor RotateY 17
renWin Render
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment