本文在 【vtk】vtk教程中的三元二次方程 的基础上继续实验。

使用vtkExtractGeometry提取部分data set

vtkExtractGeometry配合vtkImplicitFunction对象可以提取部分的data set并显示。


package require vtk
package require vtkinteraction

vtkQuadric quadric
    quadric SetCoefficients .5 1 .2 0 .1 0 0 .2 0 0
vtkSampleFunction sample
    sample SetSampleDimensions 50 50 50
    sample SetImplicitFunction quadric
    sample ComputeNormalsOff
vtkTransform trans
    #object is bigger when value is smaller
    trans Scale 0.5 0.33 0.5    

vtkSphere sphere
    sphere SetRadius 0.25
    sphere SetTransform trans

vtkExtractGeometry extract
    extract SetInputConnection [sample GetOutputPort]
    extract SetImplicitFunction sphere
vtkDataSetMapper dataMapper
    dataMapper SetInputConnection [extract GetOutputPort]
vtkActor dataActor
    dataActor SetMapper dataMapper

# The outline gives context to the original data.
vtkOutlineFilter outline
    outline SetInputConnection [sample GetOutputPort]
vtkPolyDataMapper outlineMapper
    outlineMapper SetInputConnection [outline GetOutputPort]
vtkActor outlineActor
    outlineActor SetMapper outlineMapper
set outlineProp [outlineActor GetProperty]
eval $outlineProp SetColor 0 0 0

# The usual rendering stuff is created.
vtkRenderer ren1
vtkRenderWindow renWin
    renWin AddRenderer ren1
vtkRenderWindowInteractor iren
    iren SetRenderWindow renWin

# Add the actors to the renderer, set the background and size
#
ren1 AddActor outlineActor
ren1 AddActor dataActor
ren1 SetBackground 1 1 1
renWin SetSize 500 500
ren1 ResetCamera
[ren1 GetActiveCamera] Zoom 1.5
iren Initialize

# render the image
#
iren AddObserver UserEvent {wm deiconify .vtkInteract}

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

在vtkExtractGeometry与vtkDataSetMapper的连接之间再加上一个vtkShrinkFilter对象处理,使得每个cell的大小缩小1倍。

vtkShrinkFilter shrink
    shrink SetInputConnection [extract GetOutputPort]
    shrink SetShrinkFactor 0.5


函数叠加

添加sphere2,使用vtkImplicitBoolean将其和sphere进行叠加操作。然后union作为extract SetImplicitFunction的参数

vtkTransform trans2
    #object is bigger when value is smaller
    trans2 Scale 0.33 0.5 0.33    
vtkSphere sphere2
    sphere2 SetRadius 0.25
    sphere2 SetTransform trans2

vtkImplicitBoolean union
    union AddFunction sphere
    union AddFunction sphere2
    union SetOperationType 0 ;#VTK_UNION



union SetOperationType 0 ;#VTK_UNION
相应其他参数比如:



VTK_INTERSECTION


VTK_DIFFERENCE

 

Categories: TCL

Leave a Reply

Your email address will not be published. Required fields are marked *