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 135 136 137
|
package require vtk
package require vtkinteraction
#
# write to the temp directory if possible, otherwise use .
#
set dir "."
if {[info commands "rtTester"] == "rtTester"} {
set dir [rtTester GetTempDirectory]
}
vtkRenderer ren1
ren1 SetViewport 0 0 0.33 1
vtkRenderer ren2
ren2 SetViewport 0.33 0 0.67 1
vtkRenderer ren3
ren3 SetViewport 0.67 0 1 1
vtkRenderWindow renWin
renWin SetSize 600 200
renWin AddRenderer ren1
renWin AddRenderer ren2
renWin AddRenderer ren3
renWin SetMultiSamples 0
vtkProperty property0
property0 SetDiffuseColor 0.95 0.90 0.70
set filename "$VTK_DATA_ROOT/Data/mni-surface-mesh.obj"
vtkMNIObjectReader asciiReader
set property1 [asciiReader GetProperty]
if { [asciiReader CanReadFile "$filename"] != 0 } {
asciiReader SetFileName "$filename"
}
# this is just to remove the normals, to increase coverage,
# i.e. by forcing the writer to generate normals
vtkClipClosedSurface removeNormals
removeNormals SetInputConnection [asciiReader GetOutputPort]
# this is to make triangle strips, also to increase coverage,
# because it forces the writer to decompose the strips
vtkStripper stripper
stripper SetInputConnection [removeNormals GetOutputPort]
# test binary writing and reading for polygons
vtkMNIObjectWriter binaryWriter
binaryWriter SetInputConnection [stripper GetOutputPort]
binaryWriter SetFileName "$dir/mni-surface-mesh-binary.obj"
binaryWriter SetProperty property0
binaryWriter SetFileTypeToBinary
binaryWriter Write
vtkMNIObjectReader binaryReader
binaryReader SetFileName "$dir/mni-surface-mesh-binary.obj"
set property2 [binaryReader GetProperty]
# make a polyline object with color scalars
vtkCurvatures scalars
scalars SetInputConnection [asciiReader GetOutputPort]
vtkLookupTable colors
colors SetRange -14.5104 29.0208
colors SetAlphaRange 1.0 1.0
colors SetSaturationRange 1.0 1.0
colors SetValueRange 1.0 1.0
colors SetHueRange 0.0 1.0
colors Build
# this is just to test using the SetMapper option of vtkMNIObjectWriter
vtkDataSetMapper mapper
mapper SetLookupTable colors
mapper UseLookupTableScalarRangeOn
vtkExtractEdges edges
edges SetInputConnection [scalars GetOutputPort]
# test ascii writing and reading for lines
vtkMNIObjectWriter lineWriter
lineWriter SetMapper mapper
#lineWriter SetLookupTable colors
lineWriter SetInputConnection [edges GetOutputPort]
lineWriter SetFileName "$dir/mni-wire-mesh-ascii.obj"
lineWriter Write
vtkMNIObjectReader lineReader
lineReader SetFileName "$dir/mni-wire-mesh-ascii.obj"
# display all the results
vtkDataSetMapper mapper1
mapper1 SetInputConnection [asciiReader GetOutputPort]
vtkDataSetMapper mapper2
mapper2 SetInputConnection [binaryReader GetOutputPort]
vtkDataSetMapper mapper3
mapper3 SetInputConnection [lineReader GetOutputPort]
vtkActor actor1
actor1 SetMapper mapper1
actor1 SetProperty $property1
vtkActor actor2
actor2 SetMapper mapper2
actor2 SetProperty $property2
vtkActor actor3
actor3 SetMapper mapper3
ren1 AddActor actor1
ren2 AddActor actor2
ren3 AddActor actor3
vtkRenderWindowInteractor iren
iren SetRenderWindow renWin
ren1 ResetCamera
[ren1 GetActiveCamera] Dolly 1.2
ren1 ResetCameraClippingRange
ren2 ResetCamera
[ren2 GetActiveCamera] Dolly 1.2
ren2 ResetCameraClippingRange
ren3 ResetCamera
[ren3 GetActiveCamera] Dolly 1.2
ren3 ResetCameraClippingRange
iren Render
# render the image
#
iren AddObserver UserEvent {wm deiconify .vtkInteract}
iren Initialize
wm withdraw .
|