shamantou blog site

shamantou@gmail.com

导航

simple exam of vtk render pipeline
#include "../vtk/include/vtkconesource.h"
#include "../vtk/include/vtkpolydatamapper.h"
#include "../vtk/include/vtkactor.h"
#include "../vtk/include/vtkrenderer.h"
#include "../vtk/include/vtkrenderwindow.h"
#include "../vtk/include/vtkRenderWindowInteractor.h"
#include "../vtk/include/vtkInteractorStyleTrackballCamera.h"
#include "../vtk/include/vtkInteractorStyleTrackballActor.h"


int main(int argc, char* argv[])
{
//建立模型1
vtkConeSource *cone=vtkConeSource::New();
cone->SetHeight(5);
cone->SetCenter(0,0,0);
cone->SetRadius(2);
cone->SetResolution(100);

vtkPolyDataMapper * map=vtkPolyDataMapper::New();
map->SetInput(cone->GetOutput());

vtkActor *actor=vtkActor::New();
actor->SetMapper(map);

//建立模型2
vtkConeSource *cone1=vtkConeSource::New();
cone1->SetHeight(5);
cone1->SetCenter(10,0,0);
cone1->SetRadius(2);
cone1->SetResolution(100);

vtkPolyDataMapper * map1=vtkPolyDataMapper::New();
map1->SetInput(cone1->GetOutput());

vtkActor *actor1=vtkActor::New();
actor1->SetMapper(map1);

//建立模型3
vtkConeSource *cone2=vtkConeSource::New();
cone2->SetHeight(5);
cone2->SetCenter(20,0,0);
cone2->SetRadius(2);
cone2->SetResolution(100);

vtkPolyDataMapper * map2=vtkPolyDataMapper::New();
map2->SetInput(cone2->GetOutput());

vtkActor *actor2=vtkActor::New();
actor2->SetMapper(map2);

//设置render
vtkRenderer * ren=vtkRenderer::New();
ren->AddActor(actor);
ren->AddActor(actor1);
ren->AddActor(actor2);
ren->SetBackground(.9,.5,.4);


vtkRenderWindow* win=vtkRenderWindow::New();
win->AddRenderer(ren);
win->SetSize(600,480);

vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(win);
iren->Initialize();

//设置观察交互模式
//vtkInteractorStyleTrackballCamera *pvtkInteractorStyleTrackballCamera=vtkInteractorStyleTrackballCamera::New();
//iren->SetInteractorStyle(pvtkInteractorStyleTrackballCamera);
vtkInteractorStyleTrackballActor *pvtkInteractorStyleTrackballActor=vtkInteractorStyleTrackballActor::New();
iren->SetInteractorStyle(pvtkInteractorStyleTrackballActor);

win->Render();

//开始交互
iren->Start();

return 0;
}

<< 【转载】哈希gdb >>

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最近发表

Powered By Z-Blog 1.8 Arwen Build 81206 Copyright 2006-2009 | ooplab.org | shamantou@gmail.com | 沪ICP备08011244号 | Some Rights Reserved.