#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
#include<vtkSmartPointer.h>
#include<vtkStructuredPointsReader.h>
#include<vtkPolyDataMapper.h>
#include<vtkMarchingCubes.h>
#include<vtkActor.h>
#include<vtkRenderer.h>
#include<vtkRenderWindow.h>
#include<vtkRenderWindowInteractor.h>
int main(int argc ,char * argv[]) {
vtkSmartPointer<vtkStructuredPointsReader> reader = vtkSmartPointer<vtkStructuredPointsReader>::New();
reader->SetFileName("D:/vtk/data/head.vtk");
vtkSmartPointer<vtkMarchingCubes> marchingCubes = vtkSmartPointer<vtkMarchingCubes>::New();
marchingCubes->SetInputConnection(reader->GetOutputPort());
marchingCubes->SetValue(0,500);
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(marchingCubes->GetOutputPort());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindowInteractor> interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
renWin->AddRenderer(renderer);
renderer->SetBackground(1,1,1);
renderer->AddActor(actor);
//renWin->Render();
interactor->SetRenderWindow(renWin);
interactor->Initialize();
interactor->Start();
//
getchar();
return EXIT_SUCCESS;
/**/
}
再看一个稍微复杂的可视化管线。在该示例中,先读入一个后缀为 vtk 的文件(head.vtk)然后用移动立方体法 (vtkMarchingCubes)提取等值面,最后把等值面数据经Mapper 送往渲染引擎进行显示(运行结果如图 ),
文章来源:https://uudwc.com/A/59B2Y
可视化管线总结:
文章来源地址https://uudwc.com/A/59B2Y