这一次学习,个人将其中的图像的显示过程抽象成自己认为的便于理解的语言:
#include "vtkAutoInit.h"
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
#include <vtkSmartPointer.h>
#include <vtkConeSource.h> //主要是生成圆锥的类
#include <vtkPolyDataMapper.h> //数据映射到图形硬件上
#include <vtkRenderer.h> //绘制器
#include <vtkRenderWindow.h> //绘制窗口
#include <vtkActor.h> //演员
#include <vtkCamera.h> //照相机
#include <vtkRenderWindowInteractor.h>//加入交互机制类
#include<vtkInteractorStyleTrackballCamera.h> //操作相机
#include<vtkInteractorStyleTrackballActor.h> //操作演员
int main()
{
vtkSmartPointer<vtkConeSource> m_mapper = vtkSmartPointer<vtkConeSource>::New();
m_mapper->SetResolution(5);
m_mapper->SetHeight(3);
m_mapper->SetRadius(1);
//将几何数据转为渲染器可以理解的格式
vtkSmartPointer<vtkPolyDataMapper> m_poly = vtkSmartPointer<vtkPolyDataMapper>::New();
m_poly->SetInputConnection(m_mapper->GetOutputPort());
//将演员指定格式进行映射,可以理解为经过vtkPolyDataMapper处理过的圆锥
vtkActor* coneActor = vtkActor::New();
coneActor->SetMapper(m_poly);
//管理和渲染所有的演员对象--->只处理不负责显示图像
vtkRenderer *renderer = vtkRenderer::New();
renderer->AddActor(coneActor);
renderer->SetBackground(0.1, 0.2, 0.4);
//用来管理和显示渲染结果
vtkRenderWindow* renWin = vtkRenderWindow::New();
renWin->SetSize(400, 200);
renWin->AddRenderer(renderer);
//renWin->Render();
//renWin->Start();
//用来与用户交互的
vtkRenderWindowInteractor* interactor = vtkRenderWindowInteractor::New();//交互对象加入renWin窗口中
interactor->SetRenderWindow(renWin);
vtkInteractorStyleTrackballActor* style =
vtkInteractorStyleTrackballActor::New();
interactor->SetInteractorStyle(style);
renWin->Render();//绘制舞台上的东西
interactor->Initialize();//交互对象初始化
interactor->Start();
coneActor->Delete();
renderer->Delete();
renWin->Delete();
interactor->Delete();
style->Delete();
return 0;
}