码迷,mamicode.com
首页 > 其他好文 > 详细

VTK 6.3.0 Qt 5.4 MinGW 4.9.1 Configuration 配置

时间:2016-07-23 07:31:07      阅读:417      评论:0      收藏:0      [点我收藏+]

标签:

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, selectModule_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 aQWidget 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

 

http://www.cnblogs.com/grandyang/p/4884184.html

VTK 6.3.0 Qt 5.4 MinGW 4.9.1 Configuration 配置

标签:

原文地址:http://www.cnblogs.com/findumars/p/5697768.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!