小前言
vtkInteractorStyleImage 预设了针对二维图像的交互功能:
Ctrl + 鼠标左键 - 图像的旋转
Shift + 鼠标左键 - 图像的平移
鼠标左键 长按 + 移动 - 图像窗宽和窗位的调节
R - 图像的窗宽和窗位的重置
鼠标滚轮 - 图像的缩放
等等
正文
【仿射控件】Affine Widget
用来表示VTK对象的仿射变换(平移 translation, 缩放 scaling, 旋转 rotation, and 剪切shearing)
这个工具可以设置 widget representation (我不知道这个应该怎么翻译比较好)
监听的事件:
- 默认:
-
LeftButtonPressEvent - select widget: depending on which part is selected translation, rotation, scaling, or shearing may follow.
LeftButtonReleaseEvent - end selection of widget.
MouseMoveEvent - interactive movement across widg
- 其他:
- vtkWidgetEvent::Select -- focal point is being selected
- vtkWidgetEvent::EndSelect -- the selection process has completed
- vtkWidgetEvent::Move -- a request for widget motion
vtkCommand::StartInteractionEvent (on vtkWidgetEvent::Select)
vtkCommand::EndInteractionEvent (on vtkWidgetEvent::EndSelect)
vtkCommand::InteractionEvent (on vtkWidgetEvent::Move)
<span style="background-color: rgb(255, 255, 102);">vtkSmartPointer<vtkAffineWidget> affineWidget = vtkSmartPointer<vtkAffineWidget>::New();</span>
affineWidget->SetInteractor(renderWindowInteractor);
affineWidget->CreateDefaultRepresentation();
vtkAffineRepresentation2D::SafeDownCast(affineWidget->GetRepresentation())->PlaceWidget(actor->GetBounds());
vtkSmartPointer<vtkAffineCallback> affineCallback = vtkSmartPointer<vtkAffineCallback>::New();
affineCallback->Actor = actor;
affineCallback->AffineRep = vtkAffineRepresentation2D::SafeDownCast(affineWidget->GetRepresentation());
affineWidget->AddObserver(vtkCommand::InteractionEvent,affineCallback);
affineWidget->AddObserver(vtkCommand::EndInteractionEvent,affineCallback);
affineWidget->On();
从 vtkCommand 派生出一个子类,定义交互内容
<span style="font-size:10px;">class vtkAffineCallback : public vtkCommand
{
public:
static vtkAffineCallback *New()
{ return new vtkAffineCallback; }
virtual void Execute(vtkObject *caller, unsigned long, void*);
vtkAffineCallback():Actor(0),AffineRep(0)
{
this->Transform = vtkTransform::New();
}
~vtkAffineCallback()
{
this->Transform->Delete();
}
vtkActor *Actor;
vtkAffineRepresentation2D *AffineRep;
vtkTransform *Transform;
};
void vtkAffineCallback::Execute(vtkObject*, unsigned long vtkNotUsed(event), void*)
{
this->AffineRep->GetTransform(this->Transform);
this->Actor->SetUserTransform(this->Transform);
}</span>
【气泡控件】 Balloon widget
// Create the widget
vtkSmartPointer<vtkBalloonRepresentation> balloonRep = vtkSmartPointer<vtkBalloonRepresentation>::New();
balloonRep->SetBalloonLayoutToImageRight();
vtkSmartPointer<vtkBalloonWidget> balloonWidget = vtkSmartPointer<vtkBalloonWidget>::New();
balloonWidget->SetInteractor(renderWindowInteractor);
balloonWidget->SetRepresentation(balloonRep);
balloonWidget->AddBalloon(sphereActor, "This is a sphere", NULL);
balloonWidget->AddBalloon(regularPolygonActor, "This is a regular polygon", NULL); balloonWidget->EnabledOn();