常用的VTK工具/控件(VTK Widget)

小前言

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();


简单来讲,就是为管线流程中 vtkRenderWindowInteractor 添加小部件

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值