ITK/HelloInsight: Difference between revisions
(Created from antonym) |
(→Write the source code: Update minimum CMake version) |
||
(9 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
= Hello Insight = | = Hello Insight = | ||
Traditionally, the very first program you learn to write in any given language is the simplest code to print "Hello World!". Following in a similar vein, we | Traditionally, the very first program you learn to write in any given language is the simplest code to print "Hello World!". Following in a similar vein, we demonstrate here a simple ITK program. While simple, it is used to demonstrate that you can build programs against your freshly installed ITK and that you can run them. If this seemingly trivial step succeeds, it means: | ||
# ITK was built successfully (the build itself succeeded) | # ITK was built successfully (the build itself succeeded) | ||
Line 9: | Line 9: | ||
All this working is a good thing. | All this working is a good thing. | ||
So without further ado, fire up your favourite text editor and get started! | So without further ado, fire up your favourite text editor and let's get started! | ||
== | == Write the source code == | ||
Create a new directory. Be imaginative and call it | Create a new directory. Be imaginative and call it ''HelloInsight''. Create a file called ''HelloInsight.cxx'' therein, and enter the following code: | ||
<pre> | |||
#include "itkImage.h" | |||
#include <iostream> | |||
int main() | |||
{ | |||
typedef itk::Image< unsigned short, 3 > ImageType; | |||
= | ImageType::Pointer image = ImageType::New(); | ||
std::cout << "Hello ITK World !" << std::endl; | |||
return 0; | |||
} | |||
</pre> | |||
Next to ''HelloInsight.cxx'', create a file, ''CMakeLists.txt'', and populate it with: | |||
<pre> | |||
cmake_minimum_required(VERSION 3.10.2) | |||
project(HelloInsight) | |||
# Find ITK. | |||
find_package(ITK REQUIRED) | |||
include(${ITK_USE_FILE}) | |||
add_executable(HelloInsight HelloInsight.cxx ) | |||
target_link_libraries(HelloInsight ${ITK_LIBRARIES}) | |||
</pre> | |||
== Build the project == | |||
Next to the ''HelloInsight'' directory, create a directory to build the project, ''HelloInsight_build''. '''cd''' into that directory: | |||
cd HelloInsight_build | |||
Run the CMake executable. You may have to specify the location of the ITK build directory if it was not installed. | |||
cmake ../HelloInsight | |||
or | |||
cmake -DITK_DIR=/path/to/ITK_build ../HelloInsight | |||
Once the CMake configuration completes successfully, build the project. On Linux or Mac, | |||
make | |||
On Windows, open the Visual Studio project file and build it. | |||
HelloInsight.sln | |||
== Run the new executable == | |||
./HelloInsight | |||
{{ITK/Template/Footer}} |
Latest revision as of 21:01, 4 December 2019
Hello Insight
Traditionally, the very first program you learn to write in any given language is the simplest code to print "Hello World!". Following in a similar vein, we demonstrate here a simple ITK program. While simple, it is used to demonstrate that you can build programs against your freshly installed ITK and that you can run them. If this seemingly trivial step succeeds, it means:
- ITK was built successfully (the build itself succeeded)
- ITK development files were installed successfully (and your compiler can find all the right headers and libraries)
- The ITK runtime is good (since your OS can find the required shared libraries and so on)
All this working is a good thing.
So without further ado, fire up your favourite text editor and let's get started!
Write the source code
Create a new directory. Be imaginative and call it HelloInsight. Create a file called HelloInsight.cxx therein, and enter the following code:
#include "itkImage.h" #include <iostream> int main() { typedef itk::Image< unsigned short, 3 > ImageType; ImageType::Pointer image = ImageType::New(); std::cout << "Hello ITK World !" << std::endl; return 0; }
Next to HelloInsight.cxx, create a file, CMakeLists.txt, and populate it with:
cmake_minimum_required(VERSION 3.10.2) project(HelloInsight) # Find ITK. find_package(ITK REQUIRED) include(${ITK_USE_FILE}) add_executable(HelloInsight HelloInsight.cxx ) target_link_libraries(HelloInsight ${ITK_LIBRARIES})
Build the project
Next to the HelloInsight directory, create a directory to build the project, HelloInsight_build. cd into that directory:
cd HelloInsight_build
Run the CMake executable. You may have to specify the location of the ITK build directory if it was not installed.
cmake ../HelloInsight
or
cmake -DITK_DIR=/path/to/ITK_build ../HelloInsight
Once the CMake configuration completes successfully, build the project. On Linux or Mac,
make
On Windows, open the Visual Studio project file and build it.
HelloInsight.sln
Run the new executable
./HelloInsight