vtkPropPicker在图像处理中的应用

该文由Markdown编辑器编辑完成。

1. vtkPropPicker的类说明

关于vtkPropPicker的类说明,可以摘录VTK官方文档对于该类的说明。
http://www.vtk.org/doc/nightly/html/classvtkPropPicker.html#details
Pick an actor/prop using graphics hardware.
vtkPropPicker is used to pick an actor/prop given a selection point (in display coordinates) and a renderer. This class uses graphics hardware/rendering system to pick rapidly (as compared to using ray casting as does vtkCellPicker and vtkPointPicker). This class determines the actor/prop and pick position in world coordinates; point and cell ids are not determined.

翻译如下:
vtkPropPicker这个类是通过在渲染器屏幕坐标系中给定的一个点来拾取一个角色或属性。这个类相比于通过光线投射法来实现同样功能的vtkCellPicker和vtkPointPicker,通过使用显示设备或渲染系统更快地实现。这个类可以确定拾取的对象以及它在世界坐标系下的坐标,但是点或单元的id顺序无法确定。

2. vtkPropPicker在图像处理中的应用

在医学影像软件,医生需要知道图像上某一个点的灰度值,或者需要在这个点上面做一个标记,以便在另外的平面上确定这个点的位置……诸如此类的需求,都需要通过Pick的方法,来获取屏幕上的点对应的它在真实图像中的坐标位置。
以下可以通过Python展示一个vtkPropPicker的作用。这个例子的源代码如下链接:
http://www.vtk.org/Wiki/VTK/Examples/Python/Interaction/HighlightAPickedActor

这个例子首先随机地在窗口中放置几个颜色随机地小球,然后用户可以在窗口中拾取某一个小球,被拾取到的小球将会变为红色。

这里写图片描述
图1. 随机分布在窗口中,颜色和半径各异的小球

这里写图片描述
图2. 通过鼠标拾取某一个小球后,变为红色的小球

Python代码解读:
(1) 在屏幕中随机放置半径和颜色随机的15个小球:

NUMBER_OF_SPHERES = 15
for i in range(NUMBER_OF_SPHERES):
source = vtk.vtkSphereSource()

# random position and radius
x = vtk.vtkMath.Random(-5,5)
y = vtk.vtkMath.Random(-5,5)
z = vtk.vtkMath.Random(-5,5)
radius = vtk.vtkMath.Random(.5, 1.0)

source.SetRadius(radius)
source.SetCenter(x, y, z)
source.SetPhiResolution(11)
source.SetThetaResolution(21)

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(source.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)

r = vtk.vtkMath.Random(.4, 1.0)
g = vtk.vtkMath.Random(.4, 1.0)
b = vtk.vtkMath.Random(.4, 1.0)
actor.GetProperty().SetDiffuseColor(r, g, b)
actor.GetProperty().SetDiffuse(.8)
actor.GetProperty().SetSpecular(.5)
actor.GetProperty().SetSpecularColor(1.0,1.0,1.0)
actor.GetProperty().SetSpecularPower(30.0)

renderer.AddActor(actor)

参考链接:

  1. VTK拾取相关的类
    http://blog.csdn.net/jane_yuhui/article/details/52189154
  2. 关于vtkPropPicker无法在空间中拾取vtkLineSource的讨论
    http://vtk.1045678.n5.nabble.com/Line-picking-td1253732.html
    http://public.kitware.com/pipermail/vtkusers/2013-September/081802.html
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
VTK ,可以使用 vtkContextInteractorStyle 类来处理交互事件。可以继承该类并重载 Pick 事件来实现拾取点。 以下是一个示例代码: ```cpp #include <vtkContextView.h> #include <vtkContextInteractorStyle.h> #include <vtkContextScene.h> #include <vtkChartXY.h> #include <vtkPlot.h> #include <vtkTable.h> #include <vtkSmartPointer.h> #include <vtkRenderWindow.h> #include <vtkRenderWindowInteractor.h> #include <vtkRenderer.h> #include <vtkVector.h> class MyInteractorStyle : public vtkContextInteractorStyle { public: static MyInteractorStyle* New(); vtkTypeMacro(MyInteractorStyle, vtkContextInteractorStyle); virtual void OnLeftButtonDown() override { // Get the mouse position int* pos = this->Interactor->GetEventPosition(); // Convert the screen coordinates to the world coordinates double worldPos[4]; this->ComputeWorldPosition(pos[0], pos[1], 0, worldPos); // Pick a point vtkSmartPointer<vtkPropPicker> picker = vtkSmartPointer<vtkPropPicker>::New(); picker->PickProp(worldPos[0], worldPos[1], this->CurrentRenderer); if (picker->GetActor() != nullptr) { std::cout << "You picked a point!" << std::endl; } // Forward events vtkContextInteractorStyle::OnLeftButtonDown(); } }; vtkStandardNewMacro(MyInteractorStyle); int main(int argc, char** argv) { // Create a table with some data vtkSmartPointer<vtkTable> table = vtkSmartPointer<vtkTable>::New(); vtkSmartPointer<vtkFloatArray> x = vtkSmartPointer<vtkFloatArray>::New(); x->SetName("X"); x->InsertNextValue(0.0); x->InsertNextValue(1.0); x->InsertNextValue(2.0); table->AddColumn(x); vtkSmartPointer<vtkFloatArray> y = vtkSmartPointer<vtkFloatArray>::New(); y->SetName("Y"); y->InsertNextValue(0.0); y->InsertNextValue(1.0); y->InsertNextValue(2.0); table->AddColumn(y); // Create a chart with the table vtkSmartPointer<vtkContextView> view = vtkSmartPointer<vtkContextView>::New(); view->GetRenderWindow()->SetMultiSamples(0); vtkSmartPointer<vtkChartXY> chart = vtkSmartPointer<vtkChartXY>::New(); view->GetScene()->AddItem(chart); vtkSmartPointer<vtkPlot> plot = chart->AddPlot(vtkChart::POINTS); plot->SetInputData(table, 0, 1); // Set the interactor style vtkSmartPointer<MyInteractorStyle> style = vtkSmartPointer<MyInteractorStyle>::New(); style->SetCurrentRenderer(view->GetRenderer()); view->GetInteractor()->SetInteractorStyle(style); view->GetInteractor()->Initialize(); view->GetInteractor()->Start(); return 0; } ``` 在 OnLeftButtonDown 函数,我们首先获取鼠标的屏幕坐标位置,然后使用 ComputeWorldPosition 函数将其转换为世界坐标位置。接着,我们使用 vtkPropPicker 类的 PickProp 函数来拾取点。如果拾取到了一个点,就会输出 "You picked a point!"。 请注意,这里使用的是 vtkChartXY 类来绘制点图。如果您使用的是其他类型的图表,可能需要进行一些适当的修改。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

inter_peng

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值