VTK 6.3.0 Qt 5.4 MinGW 4.9.1 Configuration 配置

简介:

Download VTK 6.3.0

Download Qt 5.4 with MinGW 4.9.1

Download CMake 3.2.0

I assume you've already installed Qt 5.4 with MinGW 4.9.1 and CMake 3.2.0 correctly.

Pre-process the VTK:

Open CMakeLists.txt in your extracted VTK-6.3.0 folder, find set(VTK_USE_WIN32_THREADS 1), change it to: set(VTK_USE_PTHREADS 1)

mark_as_advanced(VTK_THREAD_MODEL)
if(CMAKE_USE_WIN32_THREADS_INIT)
  set(VTK_USE_PTHREADS 1)
  set(CMAKE_THREAD_LIBS_INIT "")
elseif(CMAKE_USE_PTHREADS_INIT)
  set(VTK_USE_PTHREADS 1)
  if(CMAKE_HP_PTHREADS_INIT)
    set(VTK_HP_PTHREADS 1)
  endif()
elseif(CMAKE_USE_SPROC_INIT)
  set(VTK_USE_SPROC 1)
endif()
set(CMAKE_THREAD_LIBS "${CMAKE_THREAD_LIBS_INIT}" CACHE STRING "Thread library used.")

Open C:\VTK6.3.0\VTK-6.3.0\ThirdParty\libxml2\vtklibxml2\threads.c , add #undef HAVE_WIN32_THREADS after #include "libxml.h"

#define IN_LIBXML
#include "libxml.h"
#undef HAVE_WIN32_THREADS
#include <string.h>

Compile the VTK:

Start CMake 3.2.0, fill the source and destination:

source: C:/VTK6.3.0/VTK-6.3.0

destination: C:/VTK6.3.0/build

Click Configure and use MinGW Makefiles to complie.

When first configure is done, select Grouped and Advanced.

Go to CMAKE->CMAKE_INSTALL_PREFIX, change the value to C:/VTK6.3.0/MinGW

Go to Module, select Module_vtkGUISupportQtModule_vtkGUISupportQtOpenGLModule_vtkGUISupportQtSQLModule_vtkGUISupportQtWebkitModule_vtkRenderingQtModule_vtkViewsQt

Go to VTK, select VTK_Group_Qt

Go CMake->CMAKE_BUILD_TYPEchange value to Release

Click Add Entry, add QT_QMAKE_EXECUTABLE as Name, PATH as Type, C:/Qt/5.4/mingw491_32/bin/qmake.exe as value:

 

Click Add Entry, add CMAKE_PREFIX_PATH as Name, PATH as Type, C:/Qt/5.4/mingw491_32 as value:

 

Click Configure again, and you gonna get an error said: "Error in configuration processs, project files may be invalid."

Go to Ungrouped Entries->QT_VTK_VERSION, change value to 5, then click Configure again.

After configure is done, click Generate.

Go back to your build folder, open command line, type: mingw32-make

Wait a long time for make process, have a cup of coffee :)

After make is done, type mingw32-make install

Now, the configuration is done, enjoy it :)

Use the VTK:

Create new Qt Widgets, change .pro file to:

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = ImageViewer
TEMPLATE = app

SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

INCLUDEPATH += C:\VTK6.3.0\MinGW\include\vtk-6.3

LIBS += -LC:\\VTK6.3.0\\MinGW\\bin \
        libvtkGUISupportQt-6.3 \
        libvtkIOImage-6.3 \
        libvtkInteractionImage-6.3 \
        libvtkRenderingCore-6.3 \
        libvtkCommonExecutionModel-6.3 \
        libvtkCommonCore-6.3 \
        libvtkRenderingOpenGL-6.3 \
        libvtkInteractionStyle-6.3 \

and the main.cpp :

#include "mainwindow.h"
#include <QApplication>
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL)
VTK_MODULE_INIT(vtkInteractionStyle)
#include "vtkImageViewer.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkPNGReader.h"
#include "QVTKWidget.h"
#include "vtkImageData.h"
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QVTKWidget widget;

    char filename[] = "img.png";
    vtkPNGReader* reader = vtkPNGReader::New();
    reader->SetFileName(filename);
    reader->Update();

    vtkImageViewer* imageView = vtkImageViewer::New();
    imageView->SetInputConnection(reader->GetOutputPort());

    widget.SetRenderWindow(imageView->GetRenderWindow());
    imageView->SetupInteractor(widget.GetRenderWindow()->GetInteractor());
    imageView->SetColorLevel(138.5);
    imageView->SetColorWindow(233);

    int *dims = reader->GetOutput()->GetDimensions();
    widget.resize(dims[0], dims[1]);
    widget.show();

    app.exec();

    imageView->Delete();
    reader->Delete();
    return 0;
}

Use the QVTKWidget in Qt Designer:

Copy libQVTKWidgetPlugin.dll from C:\VTK6.3.0\MinGW\plugins\designer to:

C:\Qt\5.4\mingw491_32\plugins\designer

C:\Qt\Tools\QtCreator\bin\plugins\designer

If you use independent Qt Designer, you will find QVTK after Display Widgets.

If you want to use QVTKWidget inside QtCreator, it might not show in the left list, but you can promote a QWidget to QVTKWidget with including the QVTKWidget.h

Here is How to configure ITK:

ITK 4.8.1 Qt 5.4 MinGW 4.9.1 Configuration 配置

Reference:

http://zhangxc.com/2015/02/qt5-mingw-cmake-vtk6

本文转自博客园Grandyang的博客,原文链接:Configuration 配置VTK 6.3.0 Qt 5.4 MinGW 4.9.1 ,如需转载请自行联系原博主。

相关文章
|
SQL 数据库连接 数据库
Qt实用技巧:Qt连接SQL Server数据库(需要配置ODBC)
Qt实用技巧:Qt连接SQL Server数据库(需要配置ODBC)
|
存储 安全 前端开发
QT应用编程: QtCreator配置Git版本控制(码云)
QT应用编程: QtCreator配置Git版本控制(码云)
572 0
QT应用编程: QtCreator配置Git版本控制(码云)
|
4月前
|
C++
[项目配置] 配置Qt函数库和ui界面库的封装并调用的项目(二)
[项目配置] 配置Qt函数库和ui界面库的封装并调用的项目
44 0
|
4月前
|
算法 关系型数据库 编译器
[项目配置] 配置Qt函数库和ui界面库的封装并调用的项目(一)
[项目配置] 配置Qt函数库和ui界面库的封装并调用的项目
69 0
|
4月前
|
C++ 计算机视觉
[软件配置] VS2012&QT5&Opencv的配置教程
[软件配置] VS2012&QT5&Opencv的配置教程
40 0
|
7月前
vs2022配置Qt6
vs2022配置Qt6
94 1
|
7月前
Mac配置QT
Mac配置QT
154 0
Mac配置QT
|
8月前
|
Ubuntu Linux 网络安全
clion配置Linux远程开发环境–开发QT桌面软件
接下来可以开始配置clion的远程开发环境 1.配置Clion工具链
440 0
|
10月前
|
C++
VS2019 + Qt5.12 配置完成后,无法打开 Qt 源文件解决方案(非常实用)
VS2019 + Qt5.12 配置完成后,无法打开 Qt 源文件解决方案(非常实用)
|
10月前
|
C++
Visual Studio C++ 配置Qt
Visual Studio C++ 配置Qt

推荐镜像

更多