码迷,mamicode.com
首页 > 其他好文 > 详细

vtk读取文件中点坐标[转]

时间:2014-06-25 00:57:39      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   http   tar   

vtk基础编程(2)-读取数据文件中的坐标点

1. 案例说明

在实际计算中,常常需要大量的数据, 这个时候数据文件就必不可少, 例如

数据文件points.dat, 中存放了三个点的坐标,

        0.0 0.0 0.0
        1.0 0.0 0.0
        0.0 1.0 0.0
        1.0 1.0 0.0
读取坐标文件最简单的方法就是使用vtkSimplePointsReader, 比如下面的形式

         vtkSmartPointer<vtkSimplePointsReader> reader = vtkSmartPointer<vtkSimplePointsReader>::New();
         reader->SetFileName ( "points.dat" );
         reader->Update();

vtkSimplePointsReader的继承关系如下图所示:

bubuko.com,布布扣

 

 

 1 int main(int argc, char* argv[])
 2 {
 3   // Verify input arguments
 4   if ( argc != 2 )
 5     {
 6     std::cout << "Usage: " << argv[0]
 7               << " Filename(.xyz)" << std::endl;
 8     return EXIT_FAILURE;
 9     }
10 
11   // Read the file
12   vtkSmartPointer<vtkSimplePointsReader> reader =
13     vtkSmartPointer<vtkSimplePointsReader>::New();
14   reader->SetFileName ( argv[1] );
15   reader->Update();
16 
17   // Visualize
18   vtkSmartPointer<vtkPolyDataMapper> mapper =
19     vtkSmartPointer<vtkPolyDataMapper>::New();
20   mapper->SetInputConnection(reader->GetOutputPort());
21 
22   vtkSmartPointer<vtkActor> actor =
23     vtkSmartPointer<vtkActor>::New();
24   actor->SetMapper(mapper);
25   actor->GetProperty()->SetPointSize(4);
26 
27   vtkSmartPointer<vtkRenderer> renderer =
28     vtkSmartPointer<vtkRenderer>::New();
29   vtkSmartPointer<vtkRenderWindow> renderWindow =
30     vtkSmartPointer<vtkRenderWindow>::New();
31   renderWindow->AddRenderer(renderer);
32   vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
33     vtkSmartPointer<vtkRenderWindowInteractor>::New();
34   renderWindowInteractor->SetRenderWindow(renderWindow);
35 
36   renderer->AddActor(actor);
37   renderer->SetBackground(.3, .6, .3); // Background color green
38 
39   renderWindow->Render();
40   renderWindowInteractor->Start();
41 
42   return EXIT_SUCCESS;
43 }

 

3.程序运行效果

bubuko.com,布布扣


原文地址: http://blog.csdn.net/chinamming/article/details/16860051

 程序源码下载地址:

 http://download.csdn.net/detail/chinamming/6587083

 

vtk读取文件中点坐标[转],布布扣,bubuko.com

vtk读取文件中点坐标[转]

标签:style   class   blog   code   http   tar   

原文地址:http://www.cnblogs.com/vranger/p/3806995.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!