VTK运行时错误信息 no override found for ‘vtkPolyDataMapper‘ 以及 Warning: Link to vtkInteractionStyle for def

项目中使用到VTK,编译后虽然能够运行,但是vtkOutputWindow弹出,有如下错误信息:

Generic Warning: In D:\vtk-v8.0.0\Rendering\Core\vtkPolyDataMapper.cxx, line 28

Error: no override found for 'vtkPolyDataMapper'.


Warning: In D:\vtk-v8.0.0\Rendering\Core\vtkInteractorStyleSwitchBase.cxx, line 43

vtkInteractorStyleSwitchBase (000002B2C1D6F2D0): Warning: Link to vtkInteractionStyle for default style selection.


Generic Warning: In D:\vtk-v8.0.0\Rendering\Core\vtkPolyDataMapper.cxx, line 28

Error: no override found for 'vtkPolyDataMapper'.

这是由于编译过程中缺少一些定义导致的,如果采用CMake构建,默认是设置好的,如果也存在类似问题,那么就需要再CMakeLists.txt中添加include(${VTK_USE_FILE})

如果采用VS或者Qt,就需要手动把下面代码放在需要使用VTK的所有代码之前(包括所有可能的预处理):

#include "vtkAutoInit.h" 
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);

#include的路径根据工程的路径设置修改,如果你的VTK采用OpenGL后端就把vtkRenderingOpenGL2替换成vtkRenderingOpenGL即可。

也可以把两行define变成一行:

#define vtkRenderingCore_AUTOINIT 2(vtkRenderingOpenGL2, vtkInteractionStyle)

背后原理是什么,可以看如下官方描述https://vtk.org/doc/nightly/html/vtkAutoInit_8h_source.html

 // Description:

 // Initialize the named module, ensuring its object factory is correctly

 // registered. This call must be made in global scope in the

 // translation unit of your executable (which can include a shared library, but

 // will not work as expected in a static library).

 //

 // @code{.cpp}

 // #include "vtkAutoInit.h"

 // VTK_MODULE_INIT(vtkRenderingOpenGL2);

 // @endcode

 //

 // The above snippet if included in the global scope will ensure the object

 // factories for vtkRenderingOpenGL2 are correctly registered and unregistered.

 类似问题如何查找对应模块呢?以本文为例,在VTK文件夹中搜索字符串"vtkPolyDataMapper"(含引号),在搜索结果中查找*ObjectFactory,如下:

Rendering/OpenGL2/vtkRenderingOpenGL2ObjectFactory.cxx:

this->RegisterOverride("vtkPolyDataMapper",
                       "vtkOpenGLPolyDataMapper",
                       "Override for vtkRenderingOpenGL2 module", 1,
                       vtkObjectFactoryCreatevtkOpenGLPolyDataMapper);

就可以看出来是哪个module需要注册了。

 

Reference:

https://stackoverflow.com/questions/18642155/no-override-found-for-vtkpolydatamapper

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值