python - Vtk - 鼠标位置的世界坐标

标签 python qt opengl pyqt vtk

有没有可能在x-z平面(y=0)上通过鼠标在渲染窗口中的位置获取世界坐标?

最佳答案

这应该是可能的,但也许需要一些计算。 我将从这个 this example 开始.抓取鼠标移动或鼠标单击等鼠标事件,并使用 vtkCoordinate 将其转换为世界坐标。

来自示例(不是 python,但应该足以理解这个想法):

virtual void OnLeftButtonDown() 
    {
      std::cout << "Pressed left mouse button." << std::endl;
      int x = this->Interactor->GetEventPosition()[0];
      int y = this->Interactor->GetEventPosition()[1];
      std::cout << "(x,y) = (" << x << "," << y << ")" << std::endl;
      vtkSmartPointer<vtkCoordinate> coordinate = 
        vtkSmartPointer<vtkCoordinate>::New();
      coordinate->SetCoordinateSystemToDisplay();
      coordinate->SetValue(x,y,0);

      // This doesn't produce the right value if the sphere is zoomed in???
      double* world = coordinate->GetComputedWorldValue(this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer());
      std::cout << "World coordinate: " << world[0] << ", " << world[1] << ", " << world[2] << std::endl;

      // Forward events
      vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
    }

现在,当您在单击时获得世界坐标时,您可能需要计算直线 cameraposition 到 mouseposition(在世界中)的交点以及它与 x-z 平面的交点。

关于python - Vtk - 鼠标位置的世界坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59724217/

相关文章:

c++ - 如何使用 Qt C++ 从 linux 桌面环境获取当前主题名称

opengl - 正确使用glCopyBufferSubData

opengl - 如何求 3D 平面的斜率

c++ - 了解用于在 OpenGL 3.3+ 核心中使用三角形绘制四边形的代码

python - 从字符串中提取特定值

python - 如何将 Django 查询集转换为字典以用作模板上下文

python - 使用来自另一个 DataFrame 的文本选择 Pandas DataFrame

Python 哈希表和链表。如何从 HashTable 类打印列表

c++ - 如何在qt中删除之前检查指针是否存在

qt - 无法将 Visual Studio 项目导出到 Qt Creator