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[] )
{
#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
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() );
// 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 );
coneActor->SetMapper( coneMapper );
5.Render,貌似是渲染图片了,感觉和MFC里面的VIEW差不多吧
vtkRenderer *ren1= vtkRenderer::New();
ren1->AddActor( coneActor );
ren1->SetBackground( 0.1, 0.2, 0.4 );
ren1->AddActor( coneActor );
ren1->SetBackground( 0.1, 0.2, 0.4 );
6.Renderwindow,顾名思义了
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer( ren1 );
renWin->SetSize( 300, 300 );
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 );
}
// 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();
return0;
}
coneMapper->Delete();
coneActor->Delete();
ren1->Delete();
renWin->Delete();
return0;
}
由上面的这些代码推断这样一个结论吧,可能不是很成熟。
vtkRenderWindow作为后面的容器
( vtkRender作为后面的容器
( vtkActor作为后面的容器
( vtkPolyDataMapper作为后面的容器
( vtkConeSource ))))