標籤: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的繼承關係如所示:
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 file12 vtkSmartPointer<vtkSimplePointsReader> reader =13 vtkSmartPointer<vtkSimplePointsReader>::New();14 reader->SetFileName ( argv[1] );15 reader->Update();16 17 // Visualize18 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 green38 39 renderWindow->Render();40 renderWindowInteractor->Start();41 42 return EXIT_SUCCESS;43 }
3.程式運行效果
原文地址: http://blog.csdn.net/chinamming/article/details/16860051
程式源碼:
http://download.csdn.net/detail/chinamming/6587083