学习例子

vtk自带的probeComb.tcl,下面的代码在源文件的基础上稍作改造。



package require vtk
package require vtkinteraction

# create pipeline
#
vtkMultiBlockPLOT3DReader pl3d
    pl3d SetXYZFileName "$VTK_DATA_ROOT/Data/combxyz.bin"
    pl3d SetQFileName "$VTK_DATA_ROOT/Data/combq.bin"
    pl3d SetScalarFunctionNumber 100
    pl3d SetVectorFunctionNumber 202
    pl3d Update

set pl3dOutput [[pl3d GetOutput] GetBlock 0]

# create one plane and three position
vtkPlaneSource plane
    plane SetResolution 50 50

vtkTransform transP1
    transP1 Translate 3.7 0.0 28.37
    transP1 Scale 5 5 5
    transP1 RotateY 90
vtkTransformPolyDataFilter tpd1
    tpd1 SetInputConnection [plane GetOutputPort]
    tpd1 SetTransform transP1

vtkTransform transP2
    transP2 Translate 9.2 0.0 31.20
    transP2 Scale 5 5 5
    transP2 RotateY 90
vtkTransformPolyDataFilter tpd2
    tpd2 SetInputConnection [plane GetOutputPort]
    tpd2 SetTransform transP2

vtkTransform transP3
    transP3 Translate 13.27 0.0 33.30
    transP3 Scale 5 5 5
    transP3 RotateY 90
vtkTransformPolyDataFilter tpd3
    tpd3 SetInputConnection [plane GetOutputPort]
    tpd3 SetTransform transP3

# combine them
vtkAppendPolyData appendF
    appendF AddInputConnection [tpd1 GetOutputPort]
    appendF AddInputConnection [tpd2 GetOutputPort]
    appendF AddInputConnection [tpd3 GetOutputPort]

vtkProbeFilter probe
    probe SetInputConnection [appendF GetOutputPort]
    probe SetSourceData $pl3dOutput

# use vtkContourFilter to draw them
vtkContourFilter contour
    contour SetInputConnection [probe GetOutputPort]
    eval contour GenerateValues 50 [$pl3dOutput GetScalarRange]
vtkPolyDataMapper contourMapper
    contourMapper SetInputConnection [contour GetOutputPort]
    eval contourMapper SetScalarRange [$pl3dOutput GetScalarRange]
vtkActor planeActor
    planeActor SetMapper contourMapper

vtkStructuredGridOutlineFilter outline
    outline SetInputData $pl3dOutput
vtkPolyDataMapper outlineMapper
    outlineMapper SetInputConnection [outline GetOutputPort]
vtkActor outlineActor
    outlineActor SetMapper outlineMapper
    [outlineActor GetProperty] SetColor 0 0 0

vtkRenderer ren1
vtkRenderWindow renWin
    renWin AddRenderer ren1
vtkRenderWindowInteractor iren
    iren SetRenderWindow renWin

ren1 AddActor outlineActor
ren1 AddActor planeActor
ren1 SetBackground 1 1 1
renWin SetSize 400 400

ren1 ResetCamera
set cam1 [ren1 GetActiveCamera]
$cam1 SetClippingRange 3.95297 50
$cam1 SetFocalPoint 8.88908 0.595038 29.3342
$cam1 SetPosition -12.3332 31.7479 41.2387
$cam1 SetViewUp 0.060772 -0.319905 0.945498
iren Initialize


# prevent the tk window from showing up then start the event loop
wm withdraw .

iren Start

其中,contour GenerateValues 50 [$pl3dOutput GetScalarRange]是指使用contour在scalar为$pl3dOutput GetScalarRange的情况下产生50等分的等高线。假设50这个参数变大,比如500,那么线会越来越密,局部形成面。




对于

vtkProbeFilter probe
    probe SetInputConnection [appendF GetOutputPort]
    probe SetSourceData $pl3dOutput

vtkProbeFilter对象需要输入两个参数才能正常工作,一个是vtkAlgorithmOutput对象,另一个是vtkDataObject对象。他输出的数据结构和SetInputConnection传入的几何图形一样,但是带上和SetSourceData参数的数据信息。

练习例子

在球体上画等高线



package require vtk

vtkSphereSource sphere
    sphere SetRadius 10
    sphere Update

vtkPolyData polyData
    polyData SetPoints [[sphere GetOutput] GetPoints]

#Construct the surface and create isosurface.
vtkSurfaceReconstructionFilter surf
    surf SetInputData polyData 

vtkContourFilter contour
    contour SetInputConnection [surf GetOutputPort]
    eval contour GenerateValues 1 [polyData GetScalarRange]
    #contour SetValue 0 0 ;# full cover

vtkPolyDataMapper contourMapper
    contourMapper SetInputConnection [contour GetOutputPort]
    eval contourMapper SetScalarRange [[sphere GetOutput] GetScalarRange] 

vtkActor contourActor
    contourActor SetMapper contourMapper
    [contourActor GetProperty] SetColor 1 0 0

vtkRenderer ren1
    ren1 AddActor contourActor
    ren1 SetBackground 0 0 0

vtkRenderWindow renWin
    renWin AddRenderer ren1

vtkRenderWindowInteractor iren
    iren SetRenderWindow renWin

# Withdraw the default tk window
wm withdraw .

iren Start

result:




对于eval contour GenerateValues 1 [polyData GetScalarRange],如果设置产生0个轮廓,自然是什么都没有。

分类: TCL

发表评论

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