繁体   English   中英

如何使用VTK将窗口坐标映射到对象坐标

[英]How to map window coordinates into object coordinates using vtk

我正在执行vtk程序,因为我需要使用vtk将窗口坐标映射到对象坐标

我的OpenGL代码为:

  winX = 0.2;//some float values
  winY = 0.43;//some float values
  double posX, posY, posZ;

glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
glGetDoublev( GL_PROJECTION_MATRIX, projection );
glGetIntegerv( GL_VIEWPORT, viewport );
glReadPixels(winX, winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ)
gluUnProject(winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);

我不知道如何使用vtk做到这一点?任何帮助将不胜感激。

      renderWindow->GetRenderers()->GetFirstRenderer()->GetActiveCamera()->GetViewTransformMatrix();

但是我不知道如何在vtk中将窗口坐标映射为对象坐标

是的,VTK可以将屏幕坐标映射到世界坐标。 您可以根据需要调整以下代码(仅在2D情况下):

// 1. Get the position in the widget.
int* clickPosition = this->GetInteractor()->GetEventPosition();
const int x = clickPosition[0];
const int y = clickPosition[1];

// 2. Transform screen coordinates to "world coordinates" i.e. into real coordinates.
vtkSmartPointer<vtkCoordinate> coordinate = vtkSmartPointer<vtkCoordinate>::New();
coordinate->SetCoordinateSystemToDisplay();
coordinate->SetValue(x, y, 0);
double* worldCoordinates = coordinate->GetComputedWorldValue(widget->GetRenderWindow()->GetRenderers()->GetFirstRenderer());

double worldX(worldCoordinates[0]), worldY(worldCoordinates[1]);

这是一个不适的问题,因为您无法从单个2D位置找到深度信息。 在一般情况下,没有唯一的解决方案。

但是存在一些选择:

  1. 您已经完成了从对象坐标到屏幕坐标的投影,并且可以将深度信息保留在某个位置以进行反向投影。
  2. 您想要获取对象在屏幕上的3D位置。 因此,您使用视频游戏技术,例如光线追踪。 这个想法是从照相机发出光线,并将光线和物体之间的交点作为物体位置。 它在vtk https://blog.kitware.com/ray-casting-ray-tracing-with-vtk/中实现 在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM