最近用vtk显示图像遇到一个问题:图像以一个比较小的scale显示在RenderWindow上,虽然可以通过交互另其放大缩小,但在做navigation的时候不可能再去手动的缩放图像的,所以就想另图像显示的时候令其fill full整个显示窗口,下面是具体实现:
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actor);
vtkCamera* camera = renderer->GetActiveCamera();
camera->ParallelProjectionOn();
renderer->SetBackground(0,0,0);
float xc = origin[0] + 0.5*(bounds[0] + bounds[1])*spacing[0];
float yc = origin[1] + 0.5*(bounds[2] + bounds[3])*spacing[1];
// float xd = (extent[1] - extent[0] + 1)*spacing[0]; // not used
float yd = (bounds[3] - bounds[2] + 1)*spacing[1];
float d = camera->GetDistance();
camera->SetParallelScale(0.5f*static_cast<float>(yd));
camera->SetFocalPoint(xc,yc,0.0);
camera->SetPosition(xc,yc,+d);
vtk/example中有该案例源码:http://www.vtk.org/Wiki/VTK/Examples/Cxx/Images/FillWindow
另外,有关vtkCamera的中文资料可以参考:http://blog.youkuaiyun.com/colddie/article/details/16948231
本文介绍如何使用VTK库调整图像显示,使其完全填充显示窗口,包括设置渲染器、相机参数和距离等操作。提供了一个具体实现案例,并推荐了中文资料供进一步学习。
422

被折叠的 条评论
为什么被折叠?



