原文地址: http://blog.csdn.net/chinamming/article/details/16860051
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的继承关系如下图所示:
2. 完整的程序实现
int main(int argc, char* argv[]) { // Verify input arguments if ( argc != 2 ) { std::cout << "Usage: " << argv[0] << " Filename(.xyz)" << std::endl; return EXIT_FAILURE; } // Read the file vtkSmartPointer<vtkSimplePointsReader> reader = vtkSmartPointer<vtkSimplePointsReader>::New(); reader->SetFileName ( argv[1] ); reader->Update(); // Visualize vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); mapper->SetInputConnection(reader->GetOutputPort()); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); actor->SetMapper(mapper); actor->GetProperty()->SetPointSize(4); vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New(); vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New(); renderWindow->AddRenderer(renderer); vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New(); renderWindowInteractor->SetRenderWindow(renderWindow); renderer->AddActor(actor); renderer->SetBackground(.3, .6, .3); // Background color green renderWindow->Render(); renderWindowInteractor->Start(); return EXIT_SUCCESS; }
3.程序运行效果
原文地址: http://blog.csdn.net/chinamming/article/details/16860051
程序源码下载地址:
http://download.csdn.net/detail/chinamming/6587083