网上的VTK9.0编译并集成到qt designer中大多有问题,下面这个是我自己编译成功的
设置好source code位置,设置好编译位置
需要使用QT的话,
设置vtk_group_enable_qt为yes
设置Qt5_DIR为QT安装目录下cmake文件的位置,反复configure,直到没有飘红
之后generate生成平台项目
本人使用VS2019,直接运行,编译即可
最后再次编译install项目才会生成
这些文件,否则,头文件和库文件是散落在各处的
关于和QT集成的问题
新版的VTK已经删除了QVTKWidget这个类,需要使用QVTKOpenGLNativeWidget
直接看头文件里的说明,不但没有QVTKWidget这个类,立体渲染也是另外一个类,所以网络上互相抄袭的文章该升级一下了
/** * @class QVTKOpenGLNativeWidget * @brief QOpenGLWidget subclass to house a vtkGenericOpenGLRenderWindow in a Qt * application. * * QVTKOpenGLNativeWidget extends QOpenGLWidget to make it work with a * vtkGenericOpenGLRenderWindow. * * Please note that QVTKOpenGLNativeWidget only works with vtkGenericOpenGLRenderWindow. * This is necessary since QOpenGLWidget wants to take over the window management as * well as the OpenGL context creation. Getting that to work reliably with * vtkXRenderWindow or vtkWin32RenderWindow (and other platform specific * vtkRenderWindow subclasses) was tricky and fraught with issues. * * Since QVTKOpenGLNativeWidget uses QOpenGLWidget to create the OpenGL context, * it uses QSurfaceFormat (set using `QOpenGLWidget::setFormat` or * `QSurfaceFormat::setDefaultFormat`) to create appropriate window and context. * You can use `QVTKOpenGLNativeWidget::copyToFormat` to obtain a QSurfaceFormat * appropriate for a vtkRenderWindow. * * A typical usage for QVTKOpenGLNativeWidget is as follows: * @code{.cpp} * * // before initializing QApplication, set the default surface format. * QSurfaceFormat::setDefaultFormat(QVTKOpenGLNativeWidget::defaultFormat()); * * vtkNew<vtkGenericOpenGLRenderWindow> window; * QPointer<QVTKOpenGLNativeWidget> widget = new QVTKOpenGLNativeWidget(...); * widget->SetRenderWindow(window.Get()); * * // If using any of the standard view e.g. vtkContextView, then * // you can do the following. * vtkNew<vtkContextView> view; * view->SetRenderWindow(window.Get()); * * // You can continue to use `window` as a regular vtkRenderWindow * // including adding renderers, actors etc. * * @endcode * * @section OpenGLContext OpenGL Context * * In QOpenGLWidget (superclass for QVTKOpenGLNativeWidget), all rendering happens in a * framebuffer object. Thus, care must be taken in the rendering code to never * directly re-bind the default framebuffer i.e. ID 0. * * QVTKOpenGLNativeWidget creates an internal QOpenGLFramebufferObject, independent of the * one created by superclass, for vtkRenderWindow to do the rendering in. This * explicit double-buffering is useful in avoiding temporary back-buffer only * renders done in VTK (e.g. when making selections) from destroying the results * composed on screen. * * @section RenderAndPaint Handling Render and Paint. * * QWidget subclasses (including `QOpenGLWidget` and `QVTKOpenGLNativeWidget`) display * their contents on the screen in `QWidget::paint` in response to a paint event. * `QOpenGLWidget` subclasses are expected to do OpenGL rendering in * `QOpenGLWidget::paintGL`. QWidget can receive paint events for various * reasons including widget getting focus/losing focus, some other widget on * the UI e.g. QProgressBar in status bar updating, etc. * * In VTK applications, any time the vtkRenderWindow needs to be updated to * render a new result, one call `vtkRenderWindow::Render` on it. * vtkRenderWindowInteractor set on the render window ensures that as * interactions happen that affect the rendered result, it calls `Render` on the * render window. * * Since paint in Qt can be called more often then needed, we avoid potentially * expensive `vtkRenderWindow::Render` calls each time that happens. Instead, * QVTKOpenGLNativeWidget relies on the VTK application calling * `vtkRenderWindow::Render` on the render window when it needs to update the * rendering. `paintGL` simply passes on the result rendered by the most render * vtkRenderWindow::Render to Qt windowing system for composing on-screen. * * There may still be occasions when we may have to render in `paint` for * example if the window was resized or Qt had to recreate the OpenGL context. * In those cases, `QVTKOpenGLNativeWidget::paintGL` can request a render by calling * `QVTKOpenGLNativeWidget::renderVTK`. * * @section Caveats * QVTKOpenGLNativeWidget does not support stereo, * please use QVTKOpenGLStereoWidget if you need support for stereo rendering * * QVTKOpenGLNativeWidget is targeted for Qt version 5.5 and above. * * @sa QVTKOpenGLStereoWidget QVTKRenderWidget * */
直接复制dll文件到QT plugin文件下来使用QVTKOpenGLNativeWidget的方法并不好用,貌似只有版本完全对应才可以,
所以,使用把QOpenGLWidget提升为QVTKOpenGLNativeWidget的方法好一些。
详见:Using Custom Widgets with Qt Designer | Qt Designer Manual
VTK cmake都是kitware在维护的软件,一样没有一个好的官方文档,尽管如此,
VTK编程还是推荐使用cmake,稍微折腾一下cmake,可以免去很多配置依赖库的麻烦