VTK6 error: no override found for

本文档详细介绍了如何在不使用CMake的情况下正确配置VTK,并确保所有模块的自动初始化,以避免链接错误和NULL指针问题。通过提供具体的预处理器定义和宏示例,帮助读者解决VTK配置中常见的难题。


If you build your project with CMake, and you use the standard find_package(VTK) and include(${VTK_USE_FILE}) then this problem should not occur. (Because the defines will be automatically added for you by virtue of the include(${VTK_USE_FILE})...)


The factory methods now require "auto-initialization" depending on what modules are enabled at VTK configure time. If you are enabling all modules, and building your project without using CMake, you will need some defines in your project in order to make the factories work properly.


On September 10, 2013 a new macro was added to make this process a little simpler for projects that just want to initialize modules, where ordering ceases to be important but you must still build a source file into your application that has something along with following (with one entry for each module that should be initialized).

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

This will initialize the vtkRenderingOpenGL object factories, and should be done for each module. If you are using an older version of VTK (6.0 or master from before the date above) than you can try including this snippet in all your code that includes VTK usage, BEFORE including ANY VTK header files:

 #define vtkRenderingCore_AUTOINIT 4(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingFreeTypeOpenGL,vtkRenderingOpenGL)
 #define vtkRenderingVolume_AUTOINIT 1(vtkRenderingVolumeOpenGL)

See these references (and follow the mailing list threads to their conclusions) for more info:

I have also had the NULL pointer; surely the code should not compile and just dump a NULL pointer as a result of a call to

   theMapper = vtkPolyDataMapper::New();

However after setting the above options (in Windows VStudio 2008 v9 "Property Pages->Preprocessor definitions" for the program I am linking) I get a message from my compiler that some (20) functions were not found. The user at ref [1] seems to have hundreds of missing links.

"2>vtkSDIView.obj : error LNK2001: unresolved external symbol "void __cdecl vtkInteractionStyle_AutoInit_Construct(void)" (?vtkInteractionStyle_AutoInit_Construct@@YAXXZ) 2>vtkSDI.cpp.obj : error LNK2001: unresolved external symbol "void __cdecl vtkInteractionStyle_AutoInit_Destruct(void)"(?vtkInteractionStyle_AutoInit_Destruct@@YAXXZ)"

After linking all the libraries found in the example code (eg the Cone example) these link errors go away. This required adding several tens of new libraries that I had not needed to link for version 5.8 which is slightly annoying. The preprocessor definitions I mention above can also be copied from the Cone example.


### 如何在Qt中进行VTK测试 为了实现Qt与VTK的集成并完成基本的功能测试,以下是详细的说明以及示例代码。 #### 配置项目文件 `.pro` 在项目的`.pro`文件中,需要指定VTK的相关路径和库文件位置。这一步非常重要,因为它决定了编译器能否找到所需的头文件和链接库[^1]。 ```plaintext QMAKE_PROJECT_DEPTH = 0 win32 { VTK_DIR = D:/VTK INCLUDEPATH += $$VTK_DIR/include/vtk-9.3 LIBS += $$VTK_DIR/lib/vtk*.lib } ``` 上述配置假设VTK安装在 `D:/VTK` 路径下,并且版本号为 `9.3`。如果实际路径不同,则需调整相应变量值。 --- #### 主程序入口 `main.cpp` 在主程序文件中初始化VTK渲染窗口及其交互器。通过这种方式可以在Qt应用程序中显示三维模型或其他可视化数据[^3]。 ```cpp #include <QApplication> #include <vtkSmartPointer.h> #include <vtkRenderer.h> #include <vtkRenderWindow.h> #include <vtkRenderWindowInteractor.h> int main(int argc, char *argv[]) { QApplication app(argc, argv); vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New(); vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New(); renderWindow->AddRenderer(renderer); vtkSmartPointer<vtkRenderWindowInteractor> interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New(); renderWindow->SetInteractor(interactor); // 设置窗口大小和其他属性 renderWindow->Render(); interactor->Initialize(); QObject::connect(renderWindow.get(), SIGNAL(Closed()), qApp, SLOT(quit())); return app.exec(); } ``` 此部分实现了基础的VTK渲染框架设置,后续可以根据需求加载具体的数据源或几何对象。 --- #### 处理常见错误 当尝试运行以上代码时可能会遇到某些报错情况,例如: - **Error: no override found for 'vtkPolyDataMapper'** 这种问题通常是因为缺少必要的依赖项或者未正确导入对应的头文件所致。解决办法包括确认已添加所有必需的VTK模块到项目中,并确保这些模块已被成功构建[^5]。 --- #### 测试案例分析 对于更复杂的场景,比如将VTK嵌入到自定义UI界面中的操作,可以参考完整的例子结构[^4]。下面是一个简化版的MainWindow类定义片段用于展示如何组合两者功能: ##### 文件 `mainwindow.h` ```cpp #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <vtkSmartPointer.h> #include <vtkGenericOpenGLRenderWindow.h> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); private slots: void on_actionExit_triggered(); private: Ui::MainWindow *ui; protected: virtual void showEvent(QShowEvent* event) override; }; #endif // MAINWINDOW_H ``` ##### 文件 `mainwindow.cpp` ```cpp #include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); auto renWin = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New(); this->ui->qvtkWidget->SetRenderWindow(renWin); // 假设存在名为qvtkWidget的小部件 } void MainWindow::showEvent(QShowEvent* event) { if (!event->spontaneous()) { this->ui->qvtkWidget->GetRenderWindow()->Render(); // 渲染更新 } QMainWindow::showEvent(event); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_actionExit_triggered() { close(); } ``` 这里假定已经创建了一个继承自 `QWidget` 的子组件来承载VTK视图区域(即 `qvtkWidget`),并通过其关联至实际的渲染引擎实例。 --- #### 结果演示 最终效果取决于所使用的输入数据集形式以及具体的算法逻辑设计。一般情况下应该能看到一个空白画布等待进一步填充内容;而一旦附加额外的对象映射关系之后便能呈现出相应的图形表现形式。 ---
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值