第一部分vtk程序一般流程-金锄头文库-凯发k8网页登录

上传人:pu****.1 文档编号:580991972 上传时间:2024-08-29 格式:ppt 页数:24 大小:842.50kb
第一部分vtk程序一般流程_第1页
第1页 / 共24页
第一部分vtk程序一般流程_第2页
第2页 / 共24页
第一部分vtk程序一般流程_第3页
第3页 / 共24页
第一部分vtk程序一般流程_第4页
第4页 / 共24页
第一部分vtk程序一般流程_第5页
第5页 / 共24页
点击查看更多>>
资源描述

《第一部分vtk程序一般流程》由会员分享,可在线阅读,更多相关《第一部分vtk程序一般流程(24页珍藏版)》请在金锄头文库上搜索。

1、报告人:邹水中报告人:邹水中日日 期:期:2010.4.22010.4.2vtk使用总结使用总结内容简介内容简介一、一、vtk程序一般流程程序一般流程二、二、vtk的数据对象接口的数据对象接口三、三、 vtk的面绘制、体绘制、多平面显示的面绘制、体绘制、多平面显示四、四、视点变换与相机控制视点变换与相机控制五、五、 vtk事件交互、事件交互、vtk与与mfc混合编程混合编程六、六、vtk视窗控制与文视窗控制与文本本标注标注七、七、vtk在测量中应用与在测量中应用与vtk数据切割数据切割第一部分 vtk程序一般流程visualization toolkit 的机制visualization to

2、olkit 是一个用于可视化应用程序构造与运行的支撑环境,它是在三维函数库opengl 的基础上采用面向对象的设计方法发展起来的。它将在可视化开发过程中会经常遇到的细节屏蔽起来,并将一些常用的算法封装起来。比如visualization toolkit 将在表面重建中比较常见的marching cubes 算法封装起来,以类的形式给以支持,这样在对三维规则点阵数据进行表面重建时就不必再重复编写marching cubes 算法的代码而直接使用visualization toolkit 中已经提供的vtkmarchingcubes 类。visualization toolkit visualiz

3、ation toolkit 的框架结构的框架结构图形流水线:将几何数据转换为图像;可视化流水线:将信息转换为几何数据.另一种看法是:可视化流水线:负责构建几何表示;图形流水线:负责绘制. vtk使用一种lazy评价机制.对于lazy评价机制,通常无需人工地调用update(),因为filters连接着可视化流水线,当actor接收到绘制本身的要求会将方法回馈到他的mapper,然后update方法自动发送至可视化流水线。render方法通常开始数据要求,数据被通过流水线向下投递。依赖于流水线的哪个端口过时,流水线中的filters可能重新执行,将数据送至更新的流水线末端,通过actor绘制.可

4、视化模型可视化模型vtk 图形模型由以下核心对象组成vtkactor,vtkactor2d,vtkvolume vtkprop 和/或vtpprop3d 的子类vtklightvtkcameravtkproperty,vtkproperty2dvtkmaper,vtkmapper2d vtkabstractmapper 的子类vtktransformvtklookuptable,vtkcolortransferfunction- vtkscalarstocolors 的子类/for objects that convert scalars to colors vtkrendervtkrende

5、rwindowvtkrenderwindowinteractor图形模型图形模型vtklight用来展示和操控场景中的灯光,只在3d中用到.vtkcamera控制3d几何投影到2d。定位:定点、方向,还控制视角投影和立体视图.vtkmapper与查找表vtklookuptable联合使用,用于转换和绘制几何体。mapper提供可视化流水线和图形模型.vtklookuptable是vtkscalarstocolors和vtkcolortransferfunction的子类.vtkrenderer和vtkrenderwindow用来管理图形机与电脑窗口系统的接口.可以生成多个render wind

6、ows,每个render windows中有多个renderer去绘制.一个render window中可以有多个区域(视窗).vtkrenderwindowinteractor用于与场景交互,操纵camera,选择对象.vtkwin32openglrenderwindow和vtkwin32renderwindowinteractorvtkwin32openglrenderwindow is a concrete implementation of the abstract class vtkrenderwindow. vtkwin32openglrenderer interfaces to

7、the standard opengl graphics library in the windows/nt environment.implements win32 specific functions required by vtkrenderwindowinteractor. vtkactor的子类vtkassembly,vtkfollower,vtklodactor等.vtkassembly允许actors分层,在层级平移、旋转、缩放时合理转换.vtklodactor在改变几何表示时保持交互帧速率示例代码1演示vtk一般流程及常用类的使用vtkvolume16reader *v16 =

8、 vtkvolume16reader:new();v16-setdatadimensions(64,64);v16-setdatabyteordertolittleendian();v16-setfileprefix (d:/vtk 5.4/vtkdata/data/headsq/quarter);v16-setimagerange(1, 93);v16-setdataspacing (3.2, 3.2, 1.5);vtkcontourfilter *skinextractor = vtkcontourfilter:new();skinextractor-setinputconnection(

9、 v16-getoutputport();skinextractor-setvalue(0, 500);vtkpolydatanormals *skinnormals = vtkpolydatanormals:new();skinnormals-setinputconnection(skinextractor-getoutputport();skinnormals-setfeatureangle(60.0);/if the surface normal between two adjacent triangles is = featureangle, an edge exists vtkstr

10、ipper *skinstripper = vtkstripper:new();skinstripper-setinputconnection(skinnormals-getoutputport();vtkpolydatamapper *skinmapper = vtkpolydatamapper:new();skinmapper-setinputconnection(skinstripper-getoutputport();skinmapper-scalarvisibilityoff();示例代码1vtkactor *skin = vtkactor:new();skin-setmapper(

11、skinmapper);skin-getproperty()-setdiffusecolor(1, .49, .25);skin-getproperty()-setspecular(.3);skin-getproperty()-setspecularpower(20);vtklookuptable *bwlut = vtklookuptable:new();bwlut-settablerange (0, 2000);bwlut-setsaturationrange(0, 1);bwlut-sethuerange (0, 1);bwlut-setvaluerange (0.5, 1);bwlut

12、-build(); /effective built/ the result is an image of type vtk_unsigned_char vtkimagemaptocolors *saggitalcolors = vtkimagemaptocolors:new();saggitalcolors-setinputconnection(v16-getoutputport();saggitalcolors-setlookuptable(bwlut);vtkimageactor *saggital = vtkimageactor:new();saggital-setinput(sagg

13、italcolors-getoutput();saggital-setdisplayextent(32,32, 0,63, 0,92);vtkrenderer *arenderer = vtkrenderer:new();vtkrenderwindow *renwin = vtkrenderwindow:new();renwin-addrenderer(arenderer);vtkrenderwindowinteractor *iren = vtkrenderwindowinteractor:new();iren-setrenderwindow(renwin);vtkcamera *acame

14、ra = vtkcamera:new();acamera-setviewup (0, 0, -1);acamera-setposition (0, 1, 0);acamera-setfocalpoint (0, 0, 0);acamera-computeviewplanenormal();arenderer-addactor(saggital);skin-getproperty()-setopacity(0.5);arenderer-setactivecamera(acamera);arenderer-render();arenderer-resetcamera ();acamera-doll

15、y(1.5);arenderer-setbackground(1,1,1);arenderer-resetcameraclippingrange ();renwin-setsize(640, 480);iren-initialize();iren-start(); 示例代码3演示视窗显示控制、相机控制class vtkwidgetwindowlevelcallback : public vtkcommandpublic: static vtkwidgetwindowlevelcallback *new() return new vtkwidgetwindowlevelcallback; voi

16、d execute( vtkobject *caller, unsigned long vtknotused( event ), void *calldata ) vtkimageplanewidget* self = reinterpret_cast( caller ); if(!self) return; double* wl = static_cast( calldata ); if ( self = this-widgetx ) this-widgety-setwindowlevel(wl0,wl1); this-widgetz-setwindowlevel(wl0,wl1); els

17、e if( self = this-widgety ) this-widgetx-setwindowlevel(wl0,wl1); this-widgetz-setwindowlevel(wl0,wl1); else if (self = this-widgetz) this-widgetx-setwindowlevel(wl0,wl1); this-widgety-setwindowlevel(wl0,wl1); vtkwidgetwindowlevelcallback():widgetx( 0 ), widgety( 0 ), widgetz ( 0 ) vtkimageplanewidg

18、et* widgetx; vtkimageplanewidget* widgety; vtkimageplanewidget* widgetz;int main( int argc, char *argv ) vtkrenderer* ren1 = vtkrenderer:new(); vtkrenderer* ren2 = vtkrenderer:new(); vtkrenderer* ren3 = vtkrenderer:new(); vtkrenderer* ren = vtkrenderer:new(); vtkrenderwindow* renwin = vtkrenderwindo

19、w:new(); vtkrenderwindowinteractor* iren = vtkrenderwindowinteractor:new(); iren-setrenderwindow(renwin); renwin-addrenderer(ren1); renwin-addrenderer(ren2); renwin-addrenderer(ren3); renwin-addrenderer(ren);vtkdicomimagereader *v16 = vtkdicomimagereader:new();v16-setdatabyteordertolittleendian();v1

20、6-setdirectoryname(e:/medimagedata/336);v16-update();vtkoutlinefilter* outline = vtkoutlinefilter:new();outline-setinputconnection(v16-getoutputport();vtkpolydatamapper* outlinemapper = vtkpolydatamapper:new();outlinemapper-setinputconnection(outline-getoutputport();vtkactor* outlineactor = vtkactor

21、:new();outlineactor-setmapper( outlinemapper); vtkwidgetwindowlevelcallback* cbk = vtkwidgetwindowlevelcallback:new();cbk-widgetx = planewidgetx;cbk-widgety = planewidgety;cbk-widgetz = planewidgetz;/ planewidgetx-addobserver( vtkcommand:endwindowlevelevent, cbk );/planewidgety-addobserver( vtkcomma

22、nd:endwindowlevelevent, cbk );/planewidgetz-addobserver( vtkcommand:endwindowlevelevent, cbk );cbk-delete();vtkimagemaptocolors* colormap1 = vtkimagemaptocolors:new();colormap1-passalphatooutputoff();colormap1-setactivecomponent(0);colormap1-setoutputformattoluminance();colormap1-setinput(planewidge

23、tx-getresliceoutput();colormap1-setlookuptable(planewidgetx-getlookuptable();vtkimageactor* imageactor1 = vtkimageactor:new();imageactor1-pickableoff();imageactor1-setinput(colormap1-getoutput(); ren-addactor( outlineactor); ren1-addactor( imageactor1); ren2-addactor( imageactor2); ren3-addactor( im

24、ageactor3); ren-setbackground( 0.1, 0.1, 0.2); ren1-setbackground( 0.1, 0.2, 0.1); ren2-setbackground( 0.2, 0.1, 0.2); ren3-setbackground( 0.2, 0.2, 0.2); renwin-setsize( 600, 400); ren-setviewport(0,0.5,0.5,1); ren1-setviewport(0.5,0.5,1,1); ren2-setviewport(0,0,0.5,0.5); ren3-setviewport(0.5,0,1,0

25、.5); renwin-render(); ren-getactivecamera()-elevation(110); ren-getactivecamera()-setviewup(0, 0, -1); ren-getactivecamera()-azimuth(45); ren-getactivecamera()-dolly(1.15); ren-resetcameraclippingrange(); iren-initialize(); iren-start(); renwin-render(); iren-setkeycode(z); iren-invokeevent(vtkcomma

26、nd:charevent,null); iren-setkeycode(z); iren-invokeevent(vtkcommand:charevent,null); iren-start();vtkcellpicker* picker = vtkcellpicker:new();picker-settolerance(0.005);vtkproperty* ipwprop = vtkproperty:new();/assign default props to the ipws texture plane actorvtkimageplanewidget* planewidgetx = v

27、tkimageplanewidget:new();planewidgetx-setinteractor( iren);planewidgetx-setkeypressactivationvalue(x);planewidgetx-setpicker(picker);planewidgetx-restrictplanetovolumeon();planewidgetx-getplaneproperty()-setcolor(1,0,0);planewidgetx-settextureplaneproperty(ipwprop);planewidgetx-textureinterpolateoff();planewidgetx-setresliceinterpolatetonearestneighbour();planewidgetx-setinput(v16-getoutput();planewidgetx-setplaneorientationtoxaxes();planewidgetx-setsliceindex(32);planewidgetx-gettextureplaneproperty()-setopacity(1);planewidgetx-displaytexton();planewidgetx-on();planewidgetx-interactionon();

展开阅读全文
相关搜索

最新文档


当前位置:凯发k8网页登录 > 文学/艺术/历史 > 人文/社科

 |金锄头文库凯发k8网页登录的版权所有
经营许可证:蜀icp备13022795号 | 川公网安备 51140202000112号

网站地图