vtk实战(七)—读取三维点坐标

时间:2023-01-08 10:03:56

改程序主要用到的类:

vtksimplepointsreader()

vtksimplepointsreader( ) 类主要实现从源对象文件读取点,每一点的坐标包含三个浮点数值,每一行对应一个点的x,y,z值。

#include <vtkSmartPointer.h>
#include <vtkSimplePointsReader.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>

int main(int argc, char* argv[])
{
char* filename = "simple.xyz";
vtkSmartPointer<vtkSimplePointsReader> reader =
vtkSmartPointer<vtkSimplePointsReader>::New();
reader->SetFileName(filename);
reader->Update();
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();
renderer->AddActor(actor);
renderer->SetBackground(.3, .6, .3); // Background color green

vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);

vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
renderWindow->Render();
renderWindowInteractor->Start();

return EXIT_SUCCESS;
}

vtk实战(七)—读取三维点坐标

程序代码:http://pan.baidu.com/s/1o8qznIU