Qcretor中使用ITK4.13

有了Qcreator使用VTK的基础,那么我们在Qcreator使用ITK就简单多了。

具体Qcreator和ITK的安装和相关的版本号,请参考我之前的文章:
win10安装vs2017+qt5.11+vtk8.1.1+itk4.13 , 这里就不介绍过多了。

本项目Github地址: Alxemade/VTK_ITK_SimpleTest/test_itk/ 欢迎Star和Fork。

1. 编写代码:

Qcretor中使用ITK4.13_第1张图片

首先建立如图的结构。

1.1 test_itk.pro文件

然后在test_itk.pro输入以下代码:

QT -= gui

CONFIG += c++11 console
CONFIG -= app_bundle


QT += widgets

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
        main.cpp


SysStatus = $$system(if exist %windir%/SysWOW64 echo x64)  ## if contains SysWOW64 prove the windows is 64 bit

win32 {
    ## Windows common build here
    !contains(SysStatus, x64) {
        message("x86 build ")
        ## Windows x86 (32bit) specific build here

    } else {
        message("x86_64 build")
        ## Windows x64 (64bit) specific build here
        ##LABMR_PREFIX = E:\XC\itk\Bin\lib
        ## TOOLS_PREFIX = quote(C:/Program Files)
    }
}
##ITK INCLUDEPATH Starts
INCLUDEPATH += $$quote(E:/XC/itk/Bin/include/ITK-4.13)
##ITK Ends

CONFIG(debug, debug|release) {

## ITK Debug LIB Starts
LIBS += $$quote(E:/XC/itk/Bin/lib/itk*.lib)
LIBS += $$quote(E:/XC/itk/Bin/lib/ITK*.lib)
## ITK Debug LIB Ends

} else {

## VTK Release LIB Starts
##LIBS += $${LABMR_PREFIX}/Release/vtk*.lib
## VTK Release LIB Ends

}

这里的INCLUDEPATHLIBS需要变成自己itk最后生成的位置,也就是安装ITK中CMAKE_INSTALL_PREFIX的安装位置。

1. 2 main.cpp文件

#include 

#include 
#include
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    typedef itk::Image<unsigned short, 3>ImageType;
    ImageType::Pointer image = ImageType::New();
    int i;

    std::cout<<"ITK hello world !"<<std::endl;
    std::cin>>i;
    return a.exec();
}

2. cmake, 编译, 运行

Qcretor中使用ITK4.13_第2张图片

基本上可以确定ITK是没有问题的~ 还需要后续进一步验证。

下一篇文章应该是将qcreator + vtk + itk联合进行编译。

你可能感兴趣的:(ITK)