Interactor中的事件系统的使用
vtkRenderWindowInteractor routes events through VTK's command/observer
design pattern. That is, when vtkRenderWindowInteractor (actually, one of
its subclasses) sees an event, it translates it into
a VTK event using the InvokeEvent() method. Afterward, any vtkInteractorObservers
registered for that event are expected to respond appropriately.
1.Interactor首先在初始化中对所有事件进行设计模式相关方法的绑定
const handledEvents = [
'StartAnimation',
'Animation',
'EndAnimation',
'StartMouseMove',
'MouseMove',
'EndMouseMove',
'LeftButtonPress',
...
export function extend(publicAPI, model, initialValues = {}) {
...
macro.event(publicAPI, model, 'RenderEvent');
handledEvents.forEach((eventName) =>
macro.event(publicAPI, model, eventName)
);
...
}
macro.event注册后会生成invokeEvent(),onEvent(callback,priority),delete()三个方法来分发事件,注册事件钩子,

本文详细介绍了VTK库中RenderWindowInteractor如何通过command/observer设计模式处理事件,包括事件的初始化绑定、事件方法生成、DOM事件的绑定以及macro.event方法在事件系统中的作用。重点展示了如何创建和响应各类事件,如StartAnimation、MouseMove等。
最低0.47元/天 解锁文章
1965





