[vtkusers] how to pick vtkActor2D?
永强 谭
yqtan at realss.com
Sat Mar 19 00:42:01 EST 2005
Hi, all,
I have come across some problem picking a line, which is a vtkActor2D.
The following bellow is a simple code. Any suggestion is greatly
appriciated. Thanks.
package require vtk
package require vtkinteraction
vtkRenderer ren
[ren GetActiveCamera] ParallelProjectionOn
vtkRenderWindow win
win AddRenderer ren
win SetSize 512 512
vtkRenderWindowInteractor iren
iren SetRenderWindow win
iren AddObserver LeftButtonPressEvent { OnLButtonDown }
vtkLineSource lineSource
lineSource SetPoint1 0 255.5 0
lineSource SetPoint2 512 255.5 0
lineSource SetResolution 100
vtkPolyDataMapper2D lineMapper
lineMapper SetInput [lineSource GetOutput]
vtkActor2D lineActor
lineActor SetMapper lineMapper
[lineActor GetProperty] SetLineWidth 5.0
ren AddActor2D lineActor
vtkCellPicker cellPicker
cellPicker SetTolerance 0.01
cellPicker AddPickList lineActor
cellPicker PickFromListOn
iren Initialize
iren Render
proc OnLButtonDown {} {
set pos [iren GetEventPosition]
set XPos [lindex $pos 0]
set YPos [lindex $pos 1]
cellPicker Pick $XPos $YPos 0 ren
set path [cellPicker GetPath]
if {$path != ""} {
set property [lineActor GetProperty]
$property SetColor 1.0 0.0 0.0
}
}
wm withdraw .
More information about the vtkusers
mailing list