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. 編寫代碼:

在這裏插入圖片描述

首先建立如圖的結構。

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 <QApplication>

#include <itkImage.h>
#include<iostream>
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, 編譯, 運行

在這裏插入圖片描述

基本上可以確定ITK是沒有問題的~ 還需要後續進一步驗證。

下一篇文章應該是將qcreator + vtk + itk聯合進行編譯。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章