文章目录
- 前言
- 一、消失的vtkCallbackCommand
- 二、自定义命令vtkCommand
- 1、自定义一个左键双击事件的命令
- 2、使用观察者/命令模式
- 3、结果
- 三、vtkObject类中的事件
- 1、vtkCommand中所有的事件
- 2、鼠标事件测试
- 3、如何添加左键的双击事件
- 四、总结
前言
在C++的VTK中,我们常用vtkCallbackCommand来触发回调,利用观察者/命令模式,实现vtkCommand中的事件。
一、消失的vtkCallbackCommand
1、在ActiViz 9.3版本中,vtkCallbackCommand类已经消失了。在源码和官方示例中,到处都找不到vtkCallbackCommand的身影。
2、在ActiViz 9.3版本中,与vtkCallbackCommand一起消失的还有vtkOldStyleCallbackCommand,以及观察者/命令模式的使用。
二、自定义命令vtkCommand
1、自定义一个左键双击事件的命令
示例代码
public class LeftButtonDoubleClickCommand : vtkCommand
{
public LeftButtonDoubleClickCommand() : base(IntPtr.Zero, false, false)
{
}
public override void Execute(vtkObject caller, uint eventId, IntPtr callData)
{
base.Execute(caller, eventId, callData);
MessageBox.Show("鼠标双击了!");
}
}
2、使用观察者/命令模式
_renderWindow.AddObserver((uint)vtkCommand.EventIds.LeftButtonDoubleClickEvent, new LeftButtonDoubleClickCommand(), 1f);
_renderWindow.Render();
3、结果
按照上述自定义命令,使用观察者/命令模式,大概率会得到以下结果:
三、vtkObject类中的事件
1、vtkCommand中所有的事件
/// <summary>enum member</summary>
AbortCheckEvent = 10,
/// <summary>enum member</summary>
ActiveCameraEvent = 29,
/// <summary>enum member</summary>
AnimationCueTickEvent = 59,
/// <summary>enum member</summary>
AnnotationChangedEvent = 78,
/// <summary>enum member</summary>
AnyEvent = 1,
/// <summary>enum member</summary>
Button3DEvent = 122,
/// <summary>enum member</summary>
CharEvent = 22,
/// <summary>enum member</summary>
Clip3DEvent = 132,
/// <summary>enum member</summary>
ComputeVisiblePropBoundsEvent = 84,
/// <summary>enum member</summary>
ConfigureEvent = 24,
/// <summary>enum member</summary>
ConnectionClosedEvent = 71,
/// <summary>enum member</summary>
ConnectionCreatedEvent = 70,
/// <summary>enum member</summary>
CreateCameraEvent = 30,
/// <summary>enum member</summary>
CreateTimerEvent = 48,
/// <summary>enum member</summary>
CurrentChangedEvent = 83,
/// <summary>enum member</summary>
CursorChangedEvent = 53,
/// <summary>enum member</summary>
DeleteEvent = 2,
/// <summary>enum member</summary>
DeletePointEvent = 51,
/// <summary>enum member</summary>
DestroyTimerEvent = 49,
/// <summary>enum member</summary>
DisableEvent = 47,
/// <summary>enum member</summary>
DomainModifiedEvent = 72,
/// <summary>enum member</summary>
DropFilesEvent = 42,
/// <summary>enum member</summary>
Elevation3DEvent = 136,
/// <summary>enum member</summary>
EnableEvent = 46,
/// <summary>enum member</summary>
EndAnimationCueEvent = 60,
/// <summary>enum member</summary>
EndEvent = 4,
/// <summary>enum member</summary>
EndInteractionEvent = 45,
/// <summary>enum member</summary>
EndPanEvent = 114,
/// <summary>enum member</summary>
EndPickEvent = 9,
/// <summary>enum member</summary>
EndPinchEvent = 108,
/// <summary>enum member</summary>
EndRotateEvent = 111,
/// <summary>enum member</summary>
EndSwipeEvent = 105,
/// <summary>enum member</summary>
EndWindowLevelEvent = 36,
/// <summary>enum member</summary>
EnterEvent = 18,
/// <summary>enum member</summary>
ErrorEvent = 39,
/// <summary>enum member</summary>
ExecuteInformationEvent = 54,
/// <summary>enum member</summary>
ExitEvent = 11,
/// <summary>enum member</summary>
ExposeEvent = 23,
/// <summary>enum member</summary>
FifthButtonPressEvent = 119,
/// <summary>enum member</summary>
FifthButtonReleaseEvent = 120,
/// <summary>enum member</summary>
FourthButtonPressEvent = 117,
/// <summary>enum member</summary>
FourthButtonReleaseEvent = 118,
/// <summary>enum member</summary>
HighlightEvent = 95,
/// <summary>enum member</summary>
HoverEvent = 88,
/// <summary>enum member</summary>
InteractionEvent = 44,
/// <summary>enum member</summary>
KeyPressEvent = 20,
/// <summary>enum member</summary>
KeyReleaseEvent = 21,
/// <summary>enum member</summary>
LeaveEvent = 19,
/// <summary>enum member</summary>
LeftButtonDoubleClickEvent = 124,
/// <summary>enum member</summary>
LeftButtonPressEvent = 12,
/// <summary>enum member</summary>
LeftButtonReleaseEvent = 13,
/// <summary>enum member</summary>
LoadStateEvent = 89,
/// <summary>enum member</summary>
LongTapEvent = 116,
/// <summary>enum member</summary>
Menu3DEvent = 130,
/// <summary>enum member</summary>
MessageEvent = 102,
/// <summary>enum member</summary>
MiddleButtonDoubleClickEvent = 125,
/// <summary>enum member</summary>
MiddleButtonPressEvent = 14,
/// <summary>enum member</summary>
MiddleButtonReleaseEvent = 15,
/// <summary>enum member</summary>
ModifiedEvent = 33,
/// <summary>enum member</summary>
MouseMoveEvent = 26,
/// <summary>enum member</summary>
MouseWheelBackwardEvent = 28,
/// <summary>enum member</summary>
MouseWheelForwardEvent = 27,
/// <summary>enum member</summary>
MouseWheelLeftEvent = 127,
/// <summary>enum member</summary>
MouseWheelRightEvent = 128,
/// <summary>enum member</summary>
Move3DEvent = 121,
/// <summary>enum member</summary>
NextPose3DEvent = 131,
/// <summary>enum member</summary>
NoEvent = 0,
/// <summary>enum member</summary>
PanEvent = 113,
/// <summary>enum member</summary>
Pick3DEvent = 134,
/// <summary>enum member</summary>
PickEvent = 7,
/// <summary>enum member</summary>
PinchEvent = 107,
/// <summary>enum member</summary>
PlacePointEvent = 50,
/// <summary>enum member</summary>
PlaceWidgetEvent = 52,
/// <summary>enum member</summary>
PositionProp3DEvent = 133,
/// <summary>enum member</summary>
ProgressEvent = 6,
/// <summary>enum member</summary>
PropertyModifiedEvent = 73,
/// <summary>enum member</summary>
RegisterEvent = 75,
/// <summary>enum member</summary>
RenderEvent = 5,
/// <summary>enum member</summary>
RenderWindowMessageEvent = 55,
/// <summary>enum member</summary>
ResetCameraClippingRangeEvent = 32,
/// <summary>enum member</summary>
ResetCameraEvent = 31,
/// <summary>enum member</summary>
ResetWindowLevelEvent = 37,
/// <summary>enum member</summary>
ResliceAxesChangedEvent = 58,
/// <summary>enum member</summary>
RightButtonDoubleClickEvent = 126,
/// <summary>enum member</summary>
RightButtonPressEvent = 16,
/// <summary>enum member</summary>
RightButtonReleaseEvent = 17,
/// <summary>enum member</summary>
RotateEvent = 110,
/// <summary>enum member</summary>
SaveStateEvent = 90,
/// <summary>enum member</summary>
Select3DEvent = 135,
/// <summary>enum member</summary>
SelectionChangedEvent = 79,
/// <summary>enum member</summary>
SetOutputEvent = 38,
/// <summary>enum member</summary>
StartAnimationCueEvent = 57,
/// <summary>enum member</summary>
StartEvent = 3,
/// <summary>enum member</summary>
StartInteractionEvent = 41,
/// <summary>enum member</summary>
StartPanEvent = 112,
/// <summary>enum member</summary>
StartPickEvent = 8,
/// <summary>enum member</summary>
StartPinchEvent = 106,
/// <summary>enum member</summary>
StartRotateEvent = 109,
/// <summary>enum member</summary>
StartSwipeEvent = 103,
/// <summary>enum member</summary>
StartWindowLevelEvent = 35,
/// <summary>enum member</summary>
StateChangedEvent = 91,
/// <summary>enum member</summary>
SwipeEvent = 104,
/// <summary>enum member</summary>
TDxButtonPressEvent = 86,
/// <summary>enum member</summary>
TDxButtonReleaseEvent = 87,
/// <summary>enum member</summary>
TDxMotionEvent = 85,
/// <summary>enum member</summary>
TapEvent = 115,
/// <summary>enum member</summary>
TextEvent = 123,
/// <summary>enum member</summary>
TimerEvent = 25,
/// <summary>enum member</summary>
UnRegisterEvent = 76,
/// <summary>enum member</summary>
UncheckedPropertyModifiedEvent = 100,
/// <summary>enum member</summary>
UpdateDataEvent = 82,
/// <summary>enum member</summary>
UpdateDropLocationEvent = 43,
/// <summary>enum member</summary>
UpdateEvent = 74,
/// <summary>enum member</summary>
UpdateInformationEvent = 77,
/// <summary>enum member</summary>
UpdatePropertyEvent = 80,
/// <summary>enum member</summary>
UpdateShaderEvent = 101,
/// <summary>enum member</summary>
UserEvent = 1000,
/// <summary>enum member</summary>
ViewProgressEvent = 81,
/// <summary>enum member</summary>
ViewerMovement3DEvent = 129,
/// <summary>enum member</summary>
VolumeMapperComputeGradientsEndEvent = 64,
/// <summary>enum member</summary>
VolumeMapperComputeGradientsProgressEvent = 65,
/// <summary>enum member</summary>
VolumeMapperComputeGradientsStartEvent = 66,
/// <summary>enum member</summary>
VolumeMapperRenderEndEvent = 61,
/// <summary>enum member</summary>
VolumeMapperRenderProgressEvent = 62,
/// <summary>enum member</summary>
VolumeMapperRenderStartEvent = 63,
/// <summary>enum member</summary>
WarningEvent = 40,
/// <summary>enum member</summary>
WidgetActivateEvent = 69,
/// <summary>enum member</summary>
WidgetModifiedEvent = 67,
/// <summary>enum member</summary>
WidgetValueChangedEvent = 68,
/// <summary>enum member</summary>
WindowFrameEvent = 94,
/// <summary>enum member</summary>
WindowIsCurrentEvent = 93,
/// <summary>enum member</summary>
WindowIsDirectEvent = 97,
/// <summary>enum member</summary>
WindowLevelEvent = 34,
/// <summary>enum member</summary>
WindowMakeCurrentEvent = 92,
/// <summary>enum member</summary>
WindowResizeEvent = 99,
/// <summary>enum member</summary>
WindowStereoTypeChangedEvent = 98,
/// <summary>enum member</summary>
WindowSupportsOpenGLEvent = 96,
/// <summary>enum member</summary>
WrongTagEvent = 56
2、鼠标事件测试
由于vtkObject是很多vtk类的基类,也就是说我们常用的vtkActor和vtkInteractorStyle,直接添加事件都是一样使用的vtkObject。
经过测试:
正常触发: LeftButtonPressEvt、RightButtonPressEvt等单击、MouseMoveEvt,正常触发。
无法触发: LeftButtonDoubleClickEvt、RightButtonDoubleClickEvt等双击,无法触发。
3、如何添加左键的双击事件
目前我所能想到的就是利用单击事件来自定义实现双击事件。原理很简单,在短时间内,单击次数是2次时,判定为双击事件,具体代码可自行实现。
四、总结
观察者/命令模式不可用,原因未知;鼠标单击事件可用,双击事件不触发。目前发现的ActiViz鼠标交互问题就以上这些,如果大家有什么新发现,可评论留言。