VTK第一篇之菜鸟入门——经典的那个圆锥例子+本人几天的感受

说到这个VTK,(⊙o⊙)…,真是悲剧,本来老板是让用OPENGL做东西的,博士师姐不知何故,提议用VTK做东西,遂老板就同意了。然后,咱的英语又不是很行,教材是英文的,所以很郁闷。看了一些,一知半解。但是不能不写程序撒,要不然永远不会。今天先把那个最小的例子贴上来,顺便说说自己对VTK运作过程的理解吧。纯属自娱自乐,请勿拍砖!呃,咱这么冷清的博客,想要人拍可能还找不到人呢。

1.开篇当然是引入头文件啦,其实和OpenGL差不多,只是头文件不同罢了。在数量上倒是多了不少,复杂的程序头文件总是有一大堆的。

#include " vtkConeSource.h "
#include
" vtkPolyDataMapper.h "
#include
" vtkRenderWindow.h "
#include
" vtkCamera.h "
#include
" vtkActor.h "
#include
" vtkRenderer.h "

int main( int argc, char * argv[] )
{

2.创建和设置圆锥的代码

vtkConeSource * cone = vtkConeSource::New();//cone就是圆锥,咱英语烂啊
cone
-> SetHeight( 3.0 );
cone
-> SetRadius( 1.0 );
cone
-> SetResolution( 10 );//十个侧面组成的cone

3.Mapper???不解,只知道必须用的东西

//
// In this example we terminate the pipeline with a mapper process object.
// (Intermediate filters such as vtkShrinkPolyData could be inserted in
// between the source and the mapper.) We create an instance of
// vtkPolyDataMapper to map the polygonal data into graphics primitives. We
// connect the output of the cone souece to the input of this mapper.
//
vtkPolyDataMapper * coneMapper = vtkPolyDataMapper::New();
coneMapper
-> SetInput( cone -> GetOutput() );

4.Actor???还是不解,只知道也是不能少的,弄完这个程序之后,发现一环套一环的。

vtkActor * coneActor = vtkActor::New();
coneActor
-> SetMapper( coneMapper );

5.Render,貌似是渲染图片了,感觉和MFC里面的VIEW差不多吧

vtkRenderer * ren1 = vtkRenderer::New();
ren1
-> AddActor( coneActor );
ren1
-> SetBackground( 0.1 , 0.2 , 0.4 );

 

6.Renderwindow,顾名思义了

vtkRenderWindow * renWin = vtkRenderWindow::New();
renWin
-> AddRenderer( ren1 );
renWin
-> SetSize( 300 , 300 );

7.显示,顺便让圆锥转动起来

//
// Now we loop over 360 degreeees and render the cone each time.
//
int i;
for (i = 0 ; i < 360 ; ++ i)
{
// render the image
renWin -> Render();
// rotate the active camera by one degree
ren1 -> GetActiveCamera() -> Azimuth( 1 );
}

8.把创建的对象都删除,然后结束程序

cone -> Delete();
coneMapper
-> Delete();
coneActor
-> Delete();
ren1
-> Delete();
renWin
-> Delete();

return 0 ;
}

 

由上面的这些代码推断这样一个结论吧,可能不是很成熟。

vtkRenderWindow作为后面的容器

( vtkRender作为后面的容器

( vtkActor作为后面的容器

( vtkPolyDataMapper作为后面的容器

( vtkConeSource ))))

 

转载于:https://www.cnblogs.com/unsigned/archive/2010/03/27/1698576.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值