I want to pick the vtkScalarBarActor
using vtkCellPicker
, but it failed.
The code to reproduce my problem is:
import vtkmodules.all as vtk
actor = vtk.vtkScalarBarActor()
actor.SetNumberOfLabels(4)
actor.SetDrawFrame(False)
actor.SetDrawBackground(False)
actor.UnconstrainedFontSizeOn()
actor.DrawAnnotationsOn()
actor.DrawTickLabelsOn()
actor.AnnotationTextScalingOff()
actor.GetLabelTextProperty().SetFontSize(10)
lut = vtk.vtkLookupTable()
actor.SetLookupTable(lut)
render = vtk.vtkRenderer()
render.AddActor(actor)
render.SetBackground(1, 1, 1)
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(render)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
def mouseMoveEvent(iren, event):
x, y = iren.GetEventPosition()
picker = vtk.vtkCellPicker()
# picker = vtk.vtkPropPicker()
picker.Pick(x, y, 0, render)
actor = picker.GetViewProp()
print(actor)
iren.AddObserver('MouseMoveEvent', mouseMoveEvent)
iren.Initialize()
iren.Start()
I found that the printed actor is always None
when the mouse is moved on the vtkScalarBarActor
.
How to pick the vtkScalarBarActor
using vtkCellPicker
?
Also, I found vtkPropPicker
can pick vtkScalarBarActor
, but it don’t implement the SetTolerance
method. And it is the reason why I perfer the vtkCellPicker
.
Any suggestion is appreciated~~~