【003】ITK 之 HelloWorld

ITK 之 HelloWorld



0.前言

前面一篇文章已经编译并配置好了ITK ,我们如何使用 ITK 库 呢?
这里,我选择了 Qt Creator 作为 IDE ,使用 CMake 管理项目的方式使用 ITK 库

1.新建 HelloWorld 项目

  • 打开Qt Creator 选则【新建文件或项目】–> 【Non-Qt Project】–>【Plain C++ Application】
  • 这里选择了 非 Qt 项目,纯 C++ 应用程序
    在这里插入图片描述
  • 指定项目的名称
  • 项目路径不可以有中文
    在这里插入图片描述
  • 此处选择 CMake 作为 构建工具
    在这里插入图片描述
  • 选择本项目使用的构建套件,因为我们的 ITK 库编译使用的是VS 2017 64位,因此,此处我们选择了对应的MSVC2017 64 bit`。
    在这里插入图片描述
  • 此处可以指定版本控制,我们这里就不指定了,直接点击完成即可。
    在这里插入图片描述

2.实现 HelloWorld 代码

2.1 CMakeLists.txt

cmake_minimum_required(VERSION 3.5)

project(HelloWorld LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(ITK REQUIRED)
#loads the UseITK.cmake file which contains the configuration information about the specified ITK build.
include(${ITK_USE_FILE})
# first argument the name of the executable that will be produced as result of this project.
# The remaining argument(s) of add executable are the names of the source files to be compiled.
add_executable(HelloWorld main.cpp)
# call specifies which ITK libraries will be linked against this project
target_link_libraries(HelloWorld ${ITK_LIBRARIES})

2.2 main.cpp

#include "itkImage.h"
#include <iostream>
using namespace std;

int main()
{
    using ImageType = itk::Image< unsigned short, 3>;
    ImageType::Pointer image = ImageType::New();

    cout << "Hello World!" << endl;
    return 0;
}

3.编译运行

  • 一定要注意一个细节,如果我们使用的是 Debug 版本的 ITK 库 此时我们只能选择 Debug,构建 Release会出现库不相符的情况而报错。
  • 如果我们使用的是 Release 版本的 ITK 库 此时我们只能选择 Release
    在这里插入图片描述

4.运行结果

  • 如果应用程序输出了 HelloWorld ,则我们的 ITK 库已经可以正常使用了。
    在这里插入图片描述
  • 如果,您这里报错,找不到 ITK_DIR 建议看一下上一篇文章最后,配置 ITK 环境变量。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值