no override found for 'vtkPolyDataMapper'

2020-02-08 05:52发布

I'm trying to use vtk in my code, but I'm having problems running an example. I have almost no clue about the reasons since it's the first time I'm using it and I'm not very experienced. I'm using visual studio 2012 and x64 platform. Since I don't really know which libs should I use I added all of them to the "Additional Dependencies". The example is given in this link. The problem is that when I run it, the window shows this message

Generic Warning: In C:\location\VTK6.0.0\Rendering\Core\vtkPolyDataMapper.cxx, line 27
Error: no override found for 'vtkPolyDataMapper'.

which corresponds to this line

// Return NULL if no override is supplied.
vtkAbstractObjectFactoryNewMacro(vtkPolyDataMapper)

And the error that visual studio shows is

First-chance exception at 0x000007F7AA106C8F in Test.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

Does anyone know how to solve this problem or at least what does this error mean?

8条回答
一夜七次
2楼-- · 2020-02-08 06:14

I too was getting this error. The error means that the linker can't find the definition for the vtkPolyDataMapper method. One has to note which vtk rendering backend they used, during build. It will probably be either vtkRenderingOpenGL, or vtkRenderingOpenGL2. Go to your build/lib folder and search for either one of these. I have VS 2015 Community and had the vtkRenderingOpenGL2, with vtk-7.1 built on Windows 8.1, x86_64 Platform, Release configuration.

I fixed the issue by inserting the 3 following lines at the very top of my source files, before any other preprocessor directives:

#include "vtkAutoInit.h" 
VTK_MODULE_INIT(vtkRenderingOpenGL2); // VTK was built with vtkRenderingOpenGL2
VTK_MODULE_INIT(vtkInteractionStyle);

This initializes the specified VTK modules. CMake includes these by default, but other compilers such as VS do not.

The last two lines can be combined into the following:

#define vtkRenderingCore_AUTOINIT 2(vtkRenderingOpenGL2, vtkInteractionStyle)
查看更多
聊天终结者
3楼-- · 2020-02-08 06:14

Assuming your are using OpenGL2, you should initialise the vtkRenderingOpenGL2 module, ensuring its object factory is correctly registered:

VTK_MODULE_INIT(vtkRenderingOpenGL2)

You should call this macro in the global scope (ex. main.cpp) as documented in the source code:

Initialize the named module, ensuring its object factory is correctly registered and unregistered. 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).

#include "vtkAutoInit.h"
VTK_MODULE_INIT(vtkRenderingOpenGL);

The above snippet if included in the global scope will ensure the object factories for vtkRenderingOpenGL are correctly registered and unregistered.

How do you know which module to include?

The easiest method is to search in the VTK build folder for "vtkClassThatNeedsAnOverride", i.e. "vtkPolyDataMapper" in your case (note the use of quotes ".) and looking for a *ObjectFactory in your search results:

Rendering/OpenGL2/vtkRenderingOpenGL2ObjectFactory.cxx:

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

It may be even more beneficial to look for RegisterOverride("vtkPolyDataMapper".

Which object factories exist?

To obtain a list of all existing modules that you could initialise, you can search for _AutoInit_Construct. *_AutoInit_Construct is the method that is called by VTK_MODULE_INIT.

As an alternative, you can look at all classes that derive from vtkObjectFactory.

A second alternative is to look for all calls to RegisterOverride.

Further information

Note that I originally wrote this answer for a duplicate question, but I think the general information about solving this problem may be of interest for other people with the same error message.

查看更多
够拽才男人
4楼-- · 2020-02-08 06:15

According to the VTK migration guide, if you are not using CMake to compile your code, you need to add some #defines. For VTK 6.0, these lines need to go before any other VTK #includes:

#define vtkRenderingCore_AUTOINIT 4(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingFreeTypeOpenGL,vtkRenderingOpenGL)
#define vtkRenderingVolume_AUTOINIT 1(vtkRenderingVolumeOpenGL)
查看更多
ら.Afraid
5楼-- · 2020-02-08 06:20

I would recommend following the guide here, with the VTK_MODULE_INIT macro being the most reliable, with the guide here providing a high level overview of the changes needed. You must link to vtkRenderingOpenGL for example to get most of the standard overrides. If you use CMake then specifying it on the COMPONENTS argument to find_package would cause it to be added to VTK_LIBRARIES, and including VTK_USE_FILE would cause the correct compiler definitions to be added.

查看更多
Evening l夕情丶
6楼-- · 2020-02-08 06:21

When using ParaView's Catalyst libraries you have to add the following in addition to include("${PARAVIEW_USE_FILE}"):

set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS ${VTK_DEFINITIONS})
查看更多
一夜七次
7楼-- · 2020-02-08 06:21

I had the same issue at my platform; Visual Studio 2015 Windows 7 VTK 6.3

I followed VTK/Build System Migration from Marcus D. Hanwell's post, and it works. My additonal lines are;

#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL);
VTK_MODULE_INIT(vtkInteractionStyle);

on the top of preprocessor. The difference from RestlessC0bra's post is probably OpenGL version.

查看更多
登录 后发表回答