vtk讀取檔案中點座標[轉]

來源:互聯網
上載者:User

標籤: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

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.