在读取.VTK文件的时候出现如标题错误,代码如下
1 #include<vtkSmartPointer.h> 2 #include<vtkRenderWindow.h> 3 #include<vtkRenderer.h> 4 #include<vtkRenderWindowInteractor.h> 5 #include<vtkInteractorStyleTrackballCamera.h> 6 #include<vtkCylinderSource.h> 7 #include<vtkPolyDataMapper.h> 8 #include<vtkActor.h> 9 #include<vtkLight.h> 10 #include<vtkCamera.h> 11 #include<vtkJPEGReader.h> 12 #include<vtkTexture.h> 13 #include<vtkPlaneSource.h> 14 #include<vtkStructuredPointsReader.h> 15 #include<vtkMarchingCubes.h> 16 #include "vtkOpenGLRenderWindow.h" 17 18 void showMarchingCubes() 19 { 20 vtkSmartPointer<vtkStructuredPointsReader> reader = vtkSmartPointer<vtkStructuredPointsReader>::New(); 21 reader->SetFileName("D:\\zeng\\vtkData\\CT-Head.vtk"); 22 23 vtkSmartPointer<vtkMarchingCubes> marchingCubes = vtkSmartPointer<vtkMarchingCubes>::New(); 24 marchingCubes->SetInputConnection(reader->GetOutputPort()); 25 marchingCubes->SetValue(0,200); 26 27 vtkSmartPointer<vtkPolyDataMapper> manpper = vtkSmartPointer<vtkPolyDataMapper>::New(); 28 manpper->SetInputConnection(marchingCubes->GetOutputPort()); 29 30 vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); 31 actor->SetMapper(manpper); 32 33 vtkSmartPointer<vtkRenderer> marchingCubesRender = vtkSmartPointer<vtkRenderer>::New(); 34 vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New(); 35 vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New(); 36 renWin->AddRenderer(marchingCubesRender); 37 iren->SetRenderWindow(renWin); 38 marchingCubesRender->AddActor(actor); 39 marchingCubesRender->Render(); 40 41 iren->Initialize(); 42 iren->Start(); 43 }
出现如下错误
通过查资料,可通过如下方式编译通过
I finally got the answer by myself, I needed to delete the ren->Render()
line.
注释掉: marchingCubesRender->Render();