关于vtkCommand的各种事件的解释

 

 

superclass for callback/observer methods

vtkCommand is an implementation of the observer/command design pattern. In this design pattern, any instance of vtkObject can be "observed" for any events it might invoke. For example, vtkRenderer invokes a StartEvent as it begins to render and a EndEvent when it finishes rendering. Filters (subclasses of vtkProcessObject) invoke StartEvent, ProgressEvent, and EndEvent as the filter processes data. Observers of events are added with the AddObserver() method found in vtkObject. AddObserver(), besides requiring an event id or name, also takes an instance of vtkCommand (or a subclasses). Note that vtkCommand is meant to be subclassed, so that you can package the information necessary to support your callback.

Event processing can be organized in priority lists, so it is possible to truncate the processing of a particular event by setting the AbortFlag variable. The priority is set using the AddObserver() method. By default the priority is 0, events of the same priority are processed in last-in-first-processed order. The ordering/aborting of events is important for things like 3D widgets, which handle an event if the widget is selected (and then aborting further processing of that event). Otherwise. the event is passed along for further processing.

When an instance of vtkObject invokes an event, it also passes an optional void pointer to a callData. This callData is NULL most of the time. The callData is not specific to a type of event but specific to a type of vtkObject invoking a specific event. For instance, vtkCommand::PickEvent is invoked by vtkProp with a NULL callData but is invoked by vtkInteractorStyleImage with a pointer to the vtkInteractorStyleImage object itself.

Here is the list of events that may be invoked with a non-NULL callData.

  • vtkCommand::ProgressEvent
    • most of the objects return a pointer to a double value ranged between 0.0 and 1.0
    • Infovis/vtkFixedWidthTextReader returns a pointer to a float value equal to the number of lines read so far.
  • vtkCommand::ErrorEvent
    • an error message as a const char * string
  • vtkCommand::WarningEvent
    • a warning message as a const char * string
  • vtkCommand::StartAnimationCueEvent
  • vtkCommand::EndAnimationCueEvent
  • vtkCommand::AnimationCueTickEvent
  • vtkCommand::PickEvent
    • Common/vtkProp returns NULL
    • Rendering/vtkInteractorStyleImage returns a pointer to itself
  • vtkCommand::StartPickEvent
    • Rendering/vtkPropPicker returns NULL
    • Rendering/vtkInteractorStyleImage returns a pointer to itself
  • vtkCommand::EndPickEvent
    • Rendering/vtkPropPicker returns NULL
    • Rendering/vtkInteractorStyleImage returns a pointer to itself
  • vtkCommand::WrongTagEvent
    • Parallel/vtkSocketCommunicator returns a received tag as a char *
  • vtkCommand::SelectionChangedEvent
  • vtkCommand::AnnotationChangedEvent
  • vtkCommand::PlacePointEvent
    • Widgets/vtkSeedWidget returns a pointer to an int, being the current handle number
  • vtkCommand::ResetWindowLevelEvent
    • Widgets/vtkImagePlaneWidget returns an array of 2 double values (window and level)
    • Rendering/vtkInteractorStyleImage returns a pointer to itself
  • vtkCommand::StartWindowLevelEvent
    • Widgets/vtkImagePlaneWidget returns an array of 2 double values (window and level)
    • Rendering/vtkInteractorStyleImage returns a pointer to itself
  • vtkCommand::EndWindowLevelEvent
    • Widgets/vtkImagePlaneWidget returns an array of 2 double values (window and level)
    • Rendering/vtkInteractorStyleImage returns a pointer to itself
  • vtkCommand::WindowLevelEvent
    • Widgets/vtkImagePlaneWidget returns an array of 2 double values (window and level)
    • Rendering/vtkInteractorStyleImage returns a pointer to itself
  • vtkCommand::CharEvent
    • most of the objects return NULL
    • GUISupport/Qt/QVTKWidget returns a QKeyEvent *
  • vtkCommand::TimerEvent
    • most of the objects return a to an int representing a timer id
    • Rendering/vtkXRenderWindowTclInteractor returns NULL
    • Widgets/vtkHoverWidget returns NULL
  • vtkCommand::CreateTimerEvent
    • Rendering/vtkGenericRenderWindowInteractor returns a to an int representing a timer id
  • vtkCommand::DestroyTimerEvent
    • Rendering/vtkGenericRenderWindowInteractor returns a to an int representing a timer id
  • vtkCommand::UserEvent
    • most of the objects return NULL
    • Infovis/vtkInteractorStyleTreeMapHover returns a pointer to a vtkIdType representing a pedigree id
  • vtkCommand::KeyPressEvent
    • most of the objects return NULL
    • GUISupport/Qt/QVTKWidget returns a QKeyEvent*
  • vtkCommand::KeyReleaseEvent
    • most of the objects return NULL
    • GUISupport/Qt/QVTKWidget returns a QKeyEvent*
  • vtkCommand::LeftButtonPressEvent
    • most of the objects return NULL
    • GUISupport/Qt/QVTKWidget returns a QMouseEvent*
  • vtkCommand::LeftButtonReleaseEvent
    • most of the objects return NULL
    • GUISupport/Qt/QVTKWidget returns a QMouseEvent*
  • vtkCommand::MouseMoveEvent
    • most of the objects return NULL
    • GUISupport/Qt/QVTKWidget returns a QMouseEvent*
  • vtkCommand::MouseWheelForwardEvent
    • most of the objects return NULL
    • GUISupport/Qt/QVTKWidget returns a QWheelEvent*
  • vtkCommand::MouseWheelBackwardEvent
    • most of the objects return NULL
    • GUISupport/Qt/QVTKWidget returns a QWheelEvent*
  • vtkCommand::RightButtonPressEvent
    • most of the objects return NULL
    • GUISupport/Qt/QVTKWidget returns a QMouseEvent*
  • vtkCommand::RightButtonReleaseEvent
    • most of the objects return NULL
    • GUISupport/Qt/QVTKWidget returns a QMouseEvent*
  • vtkCommand::MiddleButtonPressEvent
    • most of the objects return NULL
    • GUISupport/Qt/QVTKWidget returns a QMouseEvent*
  • vtkCommand::MiddleButtonReleaseEvent
    • most of the objects return NULL
    • GUISupport/Qt/QVTKWidget returns a QMouseEvent*
  • vtkCommand::CursorChangedEvent
    • most of the objects return a pointer to an int representing a shape
    • Rendering/vtkInteractorObserver returns NULL
  • vtkCommand::ResetCameraEvent
    • Rendering/vtkRenderer returns a pointer to itself
  • vtkCommand::ResetCameraClippingRangeEvent
    • Rendering/vtkRenderer returns a pointer to itself
  • vtkCommand::ActiveCameraEvent
    • Rendering/vtkRenderer returns a pointer to the active camera
  • vtkCommand::CreateCameraEvent
    • Rendering/vtkRenderer returns a pointer to the created camera
  • vtkCommand::EnterEvent
    • most of the objects return NULL
    • GUISupport/Qt/QVTKWidget returns a QEvent*
  • vtkCommand::LeaveEvent
    • most of the objects return NULL
    • GUISupport/Qt/QVTKWidget returns a QEvent*
  • vtkCommand::RenderWindowMessageEvent
    • Rendering/vtkWin32OpenGLRenderWindow return a pointer to a UINT message
  • vtkCommand::ComputeVisiblePropBoundsEvent
    • Rendering/vtkRenderer returns a pointer to itself
  • QVTKWidget::ContextMenuEvent
    • GUISupport/Qt/QVTKWidget returns a QContextMenuEvent*
  • QVTKWidget::DragEnterEvent
    • GUISupport/Qt/QVTKWidget returns a QDragEnterEvent*
  • QVTKWidget::DragMoveEvent
    • GUISupport/Qt/QVTKWidget returns a QDragMoveEvent*
  • QVTKWidget::DragLeaveEvent
    • GUISupport/Qt/QVTKWidget returns a QDragLeaveEvent*
  • QVTKWidget::DropEvent
    • GUISupport/Qt/QVTKWidget returns a QDropEvent*
  • vtkCommand::ViewProgressEvent
    • View/vtkView returns a ViewProgressEventCallData*
  • vtkCommand::VolumeMapperRenderProgressEvent
    • A pointer to a double value between 0.0 and 1.0
  • vtkCommand::VolumeMapperComputeGradientsProgressEvent
    • A pointer to a double value between 0.0 and 1.0
  • vtkCommand::TDxMotionEvent (TDx=3DConnexion)
    • A vtkTDxMotionEventInfo*
  • vtkCommand::TDxButtonPressEvent
    • A int* being the number of the button
  • vtkCommand::TDxButtonReleaseEvent
    • A int* being the number of the button
  • vtkCommand::UpdateShaderEvent
    • A vtkOpenGLHelper* currently being used

转载于:https://www.cnblogs.com/phoenixdsg/p/6171169.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以使用 vtkContextInteractorStyle 类来处理 vtkContextView 中的交互操作,并在事件回调函数中实现拾取点的功能。以下是一个简单的示例代码,演示了如何在 vtkContextView 中通过 vtkCommand 回调实现点的拾取: ```c++ // 创建一个 vtkChartXY 对象 vtkSmartPointer<vtkChartXY> chart = vtkSmartPointer<vtkChartXY>::New(); // 创建一些测试数据 vtkNew<vtkTable> table; vtkNew<vtkFloatArray> arrX; arrX->SetName("X Axis"); table->AddColumn(arrX); vtkNew<vtkFloatArray> arrC; arrC->SetName("Cosine"); table->AddColumn(arrC); vtkNew<vtkFloatArray> arrS; arrS->SetName("Sine"); table->AddColumn(arrS); const int numPoints = 40; float inc = 7.5 / (numPoints - 1); table->SetNumberOfRows(numPoints); for (int i = 0; i < numPoints; ++i) { table->SetValue(i, 0, i * inc); table->SetValue(i, 1, cos(i * inc)); table->SetValue(i, 2, sin(i * inc)); } // 将数据添加到图表中 vtkPlot *line = chart->AddPlot(vtkChart::LINE); line->SetInputData(table, 0, 1); line = chart->AddPlot(vtkChart::LINE); line->SetInputData(table, 0, 2); // 创建一个 vtkContextView 对象,并将图表添加到其中 vtkSmartPointer<vtkContextView> view = vtkSmartPointer<vtkContextView>::New(); view->GetScene()->AddItem(chart); // 设置交互样式 vtkSmartPointer<vtkContextInteractorStyle> interactorStyle = vtkSmartPointer<vtkContextInteractorStyle>::New(); view->GetInteractor()->SetInteractorStyle(interactorStyle); // 定义事件回调函数 class PickCallback : public vtkCommand { public: static PickCallback *New() { return new PickCallback; } virtual void Execute(vtkObject *caller, unsigned long eventId, void *callData) { if (vtkCommand::MouseMoveEvent == eventId) { // 获取交互器 vtkContextInteractorStyle *style = vtkContextInteractorStyle::SafeDownCast(caller); if (!style) { return; } // 获取拾取点 int x = style->GetInteractor()->GetEventPosition()[0]; int y = style->GetInteractor()->GetEventPosition()[1]; vtkPlot *plot = style->GetScene()->PickProp(x, y); if (!plot) { return; } // 获取拾取点的坐标 vtkIdType index = plot->GetNearestPoint(x, y); double *point = plot->GetData()->GetPoint(index); std::cout << "Picked point: (" << point[0] << ", " << point[1] << ")" << std::endl; } } }; // 创建回调对象并将其添加到交互器中 vtkSmartPointer<PickCallback> pickCallback = vtkSmartPointer<PickCallback>::New(); interactorStyle->AddObserver(vtkCommand::MouseMoveEvent, pickCallback); // 启动交互器 view->GetInteractor()->Initialize(); view->GetInteractor()->Start(); ``` 在此示例中,我们创建了一个 vtkChartXY 对象并将一些测试数据添加到其中。然后,我们创建了一个 vtkContextView 对象,并将图表添加到其中。接下来,我们创建了一个 vtkContextInteractorStyle 对象,并将其设置为交互器的样式。然后,我们定义了一个 PickCallback 类来处理事件回调函数,其中我们使用 GetScene()->PickProp(x, y) 方法获取拾取的 plot 对象,然后使用 GetNearestPoint(x, y) 方法获取拾取点的索引,最后使用 GetData()->GetPoint(index) 方法获取拾取点的坐标。最后,我们创建了回调对象并将其添加到交互器中,然后启动交互器。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值