使用vtkImageViewer展示读到的图片:
tcl脚本如下

package require vtk

vtkPNGReader reader
reader SetFileName "/Users/weiyang/Downloads/VTKData/Data/vtk.png"
reader Update

vtkImageViewer viewer
  viewer SetInputConnection [reader GetOutputPort] ;#[imCan GetOutputPort]
  viewer SetColorWindow 256
  viewer SetColorLevel 127.5

vtkRenderWindow renWin
  renWin SetSize 256 256

viewer SetRenderWindow renWin

vtkRenderWindowInteractor iren
  iren SetRenderWindow renWin

# Withdraw the default tk window
wm withdraw .

iren Start  




vtkUsersGuide.pdf中的ImageCanvasSource2D例子:
使用ImageCanvasSource2D画出不同的二维图案,由vtkImageViewer显示出来。



vtkImageCanvasSource2D提供了空间数据(source)

vtkImageCanvasSource2D imCan
  imCan SetScalarTypeToUnsignedChar
  imCan SetExtent 0 511 0 511 0 0
# Draw various primitives
  imCan SetDrawColor 86
  imCan FillBox 0 511 0 511
  imCan SetDrawColor 0
  imCan FillTube 500 20 30 400 5
  imCan SetDrawColor 255
  imCan DrawSegment 10 20 500 510
  imCan SetDrawColor 0
  imCan DrawCircle 400 350 80.0
  imCan SetDrawColor 255
  imCan FillPixel 450 350
  imCan SetDrawColor 170
  imCan FillTriangle 100 100 300 150 150 300

vtkImageViewer viewer
  viewer SetInputConnection [imCan GetOutputPort] ;#[imCan GetOutputPort]
  viewer SetColorWindow 256
  viewer SetColorLevel 127.5

还可以给viewer设置交互:
viewer SetRenderWindow renWin

分类: TCL

发表评论

电子邮件地址不会被公开。 必填项已用*标注