VTK在同一窗口中同时显示多个渲染结果

前几个月看的发现又忘了,还是记录一下吧

        vtkConeSource cone = new vtkConeSource();  
        //设置圆锥的高度和半径  
        cone.SetHeight(3);  
        cone.SetRadius(1);  
        //设置分辨率,值越大,越趋近于圆锥体  
        cone.SetResolution(10);  
          
        vtkCubeSource cube = new vtkCubeSource();  
        //设置立方体的长宽高  
        cube.SetXLength(1);  
        cube.SetYLength(1.5);  
        cube.SetZLength(1);  
          
        //创建圆柱体  
        vtkCylinderSource cylinder = new vtkCylinderSource();  
        //创建平面  
        vtkPlaneSource plane = new vtkPlaneSource();  
        //创建对应的mapper  
        vtkPolyDataMapper coneMapper = new vtkPolyDataMapper();  
        coneMapper.SetInputConnection(cone.GetOutputPort());  
          
        vtkPolyDataMapper cubeMapper = new vtkPolyDataMapper();  
        cubeMapper.SetInput(cube.GetOutput());  
          
        vtkPolyDataMapper cylinderMapper = new vtkPolyDataMapper();  
        cylinderMapper.SetInput(cylinder.GetOutput());  
          
        vtkPolyDataMapper planeMapper = new vtkPolyDataMapper();  
        planeMapper.SetInput(plane.GetOutput());  
        //创建对应的actor,设置mapper  
        vtkActor coneActor = new vtkActor();  
        coneActor.SetMapper(coneMapper);  
          
        vtkActor cubeActor = new vtkActor();  
        cubeActor.SetMapper(cubeMapper);  
          
        vtkActor cylinderActor = new vtkActor();  
        cylinderActor.SetMapper(cylinderMapper);  
          
        vtkActor planeActor = new vtkActor();  
        planeActor.SetMapper(planeMapper);  
        //针对每个actor创建一个vtkRender,添加actor  
        vtkRenderer ren1 = new vtkRenderer();  
        ren1.AddActor(coneActor);  
        //下面的代码就是设置视口的,将屏幕分为4个视口  
        //前两个参数是视口左下角点的坐标(xmin,ymin),后两个参数是右上角的坐标(xmax,ymax)  
        ren1.SetViewport(0, 0.5, 0.5, 1);  
        ren1.SetBackground(0.1, 0.2, 0.4);  
          
        vtkRenderer ren2 = new vtkRenderer();  
        ren2.AddActor(cubeActor);  
        ren2.SetViewport(0.5, 0.5, 1, 1);  
        ren2.SetBackground(0, 1, 0);  
          
        vtkRenderer ren3 = new vtkRenderer();  
        ren3.AddActor(cylinderActor);  
        ren3.SetViewport(0, 0, 0.5, 0.5);  
          
        vtkRenderer ren4 = new vtkRenderer();  
        ren4.AddActor(planeActor);  
        ren4.SetViewport(0.5 , 0, 1, 0.5);  
        ren4.SetBackground(0, 0, 1);  
          
        vtkRenderWindow renWin = new vtkRenderWindow();  
        renWin.AddRenderer(ren1);  
        renWin.AddRenderer(ren2);  
        renWin.AddRenderer(ren3);  
        renWin.AddRenderer(ren4);  
        renWin.SetSize(500, 400);  
          
        //添加鼠标交互  
        vtkRenderWindowInteractor interactor = new vtkRenderWindowInteractor();  
        interactor.SetRenderWindow(renWin);  
        vtkInteractorStyleTrackballActor style = new vtkInteractorStyleTrackballActor();  
        interactor.SetInteractorStyle(style);  
        //初始化交互器 并开始执行事件循环  
        interactor.Initialize();  
        interactor.Start();  
    

你可能感兴趣的:(VTK)