当前位置: 首页 > article >正文

VTK中坐标转换

通过屏幕点击的坐标获取体坐标(2D->3D)

1>获取点击位置的z

  z = renderer->GetZ (static_cast<int>(selectionX),static_cast<int>(selectionY));

renderer中getZ的实现:

  // Error checking// Must clear previous errors first.while(glGetError() != GL_NO_ERROR){;}// Turn of texturing in case it is on - some drivers have a problem// getting / setting pixels with texturing enabled.glDisable( GL_SCISSOR_TEST );glPixelStorei( GL_PACK_ALIGNMENT, 1 );glReadPixels( x_low, y_low,width, height,GL_DEPTH_COMPONENT, GL_FLOAT,z_data );

if z is 1.0, we assume the user has picked a point on the
screen that has not been rendered into. Use the camera’s focal
point for the z value. The test value .999999 has to be used
instead of 1.0 because for some reason our SGI Infinite Reality
engine won’t return a 1.0 from the zbuffer

如果z为1,则获取相机焦点对应屏幕坐标处的z

    // Get camera focal point and position. Convert to display (screen)// coordinates. We need a depth value for z-buffer.camera = renderer->GetActiveCamera();camera->GetFocalPoint(cameraFP); cameraFP[3] = 1.0;renderer->SetWorldPoint(cameraFP[0],cameraFP[1],cameraFP[2],cameraFP[3]);renderer->WorldToDisplay();displayCoord = renderer->GetDisplayPoint();selectionZ = displayCoord[2];

2>通过vtkRenderer设置屏幕屏幕坐标并进行转换

  renderer->SetDisplayPoint (display);renderer->DisplayToWorld ();

DisplayToWorld 实际调用:{this->DisplayToView(); this->ViewToWorld();}

DisplayToView实现:

    size = this->VTKWindow->GetSize();if (size == NULL){return;}sizex = size[0];sizey = size[1];//2* (clickX/windowwidth) - 1vx = 2.0 * (this->DisplayPoint[0] - sizex*this->Viewport[0])/(sizex*(this->Viewport[2]-this->Viewport[0])) - 1.0;//2* (clickY/windowheight) - 1vy = 2.0 * (this->DisplayPoint[1] - sizey*this->Viewport[1])/(sizey*(this->Viewport[3]-this->Viewport[1])) - 1.0;vz = this->DisplayPoint[2];

vx和vy一定在区间[-1,1]
ViewToWorld实现:

  // get the perspective transformation from the active cameravtkMatrix4x4 *matrix = this->ActiveCamera->GetCompositeProjectionTransformMatrix(this->GetTiledAspectRatio(),0,1);// use the inverse matrixvtkMatrix4x4::Invert(*matrix->Element, mat);// Transform point to world coordinatesresult[0] = x;result[1] = y;result[2] = z;result[3] = 1.0;vtkMatrix4x4::MultiplyPoint(mat,result,result);

ActiveCamera->GetCompositeProjectionTransformMatrix实现较为复杂,有时间再弄!!

3>通过vtkRenderer获取体坐标并转换

  world = renderer->GetWorldPoint ();for (int i=0; i < 3; i++){this->PickPosition[i] = world[i] / world[3];}
http://www.lryc.cn/news/2416788.html

相关文章:

  • redis三大集群使用看这篇就差不多了 | 主从哨兵Cluster
  • jsp中的request.getContextPath()
  • 【技术网站分享】全面整理了一波技术网站,分享给大家!
  • linux版drastic模拟器设置,DraStic nds模拟器下载安装及使用图文教程
  • oracle 错误 20001,LANG=c 引发的 ORA-20001 问题
  • 51CTO下载中心 移动开发的资料库
  • Filter2------原理
  • C#编写一个简易通讯录
  • ActiveX开发详解
  • 硬盘写入缓存
  • 证券交易系统设计与开发
  • java 正则 规则_Java基础-正则表达式(Regular Expression)语法规则简介
  • 大数的运算(详细思路+代码)
  • 利用模板导出文件(一)之XLSTransformer导出excel文件
  • 手动脱UPX 壳实战
  • 剖析 ADO.NET 批处理更新(深入研究数据访问)
  • 集成solr复盘
  • 分享88个ASP整站程序源码,总有一款适合您
  • form表单—2种提交方式
  • Win7系统提示找不到MSVCRTD.DLL文件的解决办法
  • MaskedTextBox
  • 缓存背后的智慧:旁路、读写穿透和写回三种策略全面解析
  • CSS——滤镜(filter )
  • 关于Loadlibrary 失败-找不到指定模块126错误
  • DAS~~
  • ThinkPHP6+Layui自定义分页样式
  • 博客搜索引擎列举|博客搜索引擎的浅比较
  • 多线程开发实战:Java实现多线程四种方式及相关方法原理
  • 端口详解及如何开起端口关闭端口
  • C语言之多线程编程