vtk同一窗口中多个Renderer(渲染多个场景)示例

 vtk版本: 8.2.0

平台:Windows 10


#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#include 
#include 

int main()
{
    // 创建圆锥数据
    vtkNew cone;
    cone->SetHeight(20);         //设置圆锥的高度和半径  
    cone->SetRadius(20);  
    cone->SetResolution(100);    //设置分辨率,值越大,越趋近于圆锥体
    //创建对应的mapper 
    vtkNew coneMapper;
    coneMapper->SetInputConnection(cone->GetOutputPort());
    // 创建对应的Actor
    vtkNew coneActor;
    coneActor->SetMapper(coneMapper);
    // 针对每个actor创建一个vtkRender,添加actor 
    vtkNew coneRenderer;
    coneRenderer->AddActor(coneActor);
    //下面的代码就是设置视口的,将屏幕分为4个视口  
    //前两个参数是视口左下角点的坐标(xmin,ymin),后两个参数是右上角的坐标(xmax,ymax)  
    coneRenderer->SetViewport(0, 0.5, 0.5, 1);
    coneRenderer->SetBackground(0.1, 0.2, 0.4);

    // 创建立方体
    vtkNew cube;
    cube->SetXLength(40);     //设置立方体的长宽高  
    cube->SetYLength(50);
    cube->SetZLength(60);
    vtkNew cubeMapper;
    cubeMapper->SetInputConnection(cube->GetOutputPort());
    vtkNew cubeActor;
    cubeActor->SetMapper(cubeMapper);
    vtkNew cubeRenderer;
    cubeRenderer->AddActor(cubeActor);
    cubeRenderer->SetViewport(0.5, 0.5, 1, 1);
    cubeRenderer->SetBackground(0, 1, 0);

    //创建圆柱体  
    vtkNew cylinder;
    vtkNew cylinderMapper;
    cylinderMapper->SetInputConnection(cylinder->GetOutputPort());
    vtkNew cylinderActor;
    cylinderActor->SetMapper(cylinderMapper);
    vtkNew cylinderRenderer;
    cylinderRenderer->AddActor(cylinderActor);
    cylinderRenderer->SetViewport(0, 0, 0.5, 0.5);

    //创建平面  
    vtkNew plane;
    vtkNew planeMapper;
    planeMapper->SetInputConnection(plane->GetOutputPort());
    vtkNew planeActor;
    planeActor->SetMapper(planeMapper);
    vtkNew planeRenderer;
    planeRenderer->AddActor(planeActor);
    planeRenderer->SetViewport(0.5, 0, 1, 0.5);
    planeRenderer->SetBackground(0, 0, 1);

    vtkNew renderWindow;
    renderWindow->AddRenderer(coneRenderer);
    renderWindow->AddRenderer(cubeRenderer);
    renderWindow->AddRenderer(cylinderRenderer);
    renderWindow->AddRenderer(planeRenderer);
    renderWindow->SetSize(800, 600);
    renderWindow->Render();

    //添加鼠标交互  
    vtkNew interactor;
    interactor->SetRenderWindow(renderWindow);
    vtkNew style;
    interactor->SetInteractorStyle(style);

    //初始化交互器 并开始执行事件循环  
    interactor->Initialize();
    interactor->Start();

}

 

你可能感兴趣的:(图像处理之ITK_VTK)