VTK编译报错no override found for vtkpolydatamapper 发表于 2018-04-12 | 报错原因是通过IDE编译而不是直接通过cmake,因此要添加如下代码段: 123#include "vtkAutoInit.h" VTK_MODULE_INIT(vtkRenderingOpenGL2); VTK_MODULE_INIT(vtkInteractionStyle); 先记录解决办法,more details 留到以后。 基础测试: 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647#include "vtkAutoInit.h"VTK_MODULE_INIT(vtkRenderingOpenGL2); // VTK was built with vtkRenderingOpenGL2VTK_MODULE_INIT(vtkInteractionStyle);#include <vtkSphereSource.h>#include <vtkPolyData.h>#include <vtkSmartPointer.h>#include <vtkPolyDataMapper.h>#include <vtkActor.h>#include <vtkRenderWindow.h>#include <vtkRenderer.h>#include <vtkRenderWindowInteractor.h>int main(int, char *[]){ // Create a sphere vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New(); sphereSource->SetCenter(0.0, 0.0, 0.0); sphereSource->SetRadius(5.0); //mapper vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); mapper->SetInputConnection(sphereSource->GetOutputPort()); //actor vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); actor->SetMapper(mapper); //renderer ,renderWindow, renderWindowInteractor. 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;}