or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
Create Elegant C++ Spatial Processing Pipelines in WebAssembly
tags:
post
,itk-wasm
,webassembly
,cli11
By: Matt McCormick
, Mary Elise Dedicke
, Henry Schreiner 
WebAssembly's origins date back to Alon Zakai's incredible effort to build C++ to JavaScript. In 2015, we demonstrated the power of this technology to make scientific computational sustainable and accessible. Try it – reproducibility is still possible all these years later, with no installation (or maintenance!) required.
An interactive, accessible and sustainable open science publication on anisotropic diffusion where C++ is built into JavaScript for browser execution.
Since that time, Emscripten's capabilities have advanced and been standardized with WebAssembly (Wasm) in the Web Platform. Moreover, Wasm's scope has expanded dramatically with the advent of the WebAssembly System Interface, WASI, and The Component Model.
However, there was a significant gap in capabilites for research software developers who aimed to create data and computationally intense scientific processing pipelines for applications like spatial analysis and visualization. Namely,
In this post, adapted from itk-wasm's documentation, we provide a C++ Wasm processing pipeline tutorial that demonstrates how we can write elegant processing pipelines in C++ via itk-wasm's CLI11 command line parser, which provides a rich feature set with a simple and intuitive interface. At the end of this tutorial, you will have built and executed C++ code to Wasm for standalone execution on the command line and in the browser.
itk-wasm combines the Insight Toolkit (ITK) and WebAssembly to enable high-performance spatial analysis in a web browser, Node.js, and reproducible execution across programming languages and hardware architectures.
CLI11 provides all the features you expect in a powerful command line parser, with a beautiful, minimal syntax and no dependencies beyond C++11. itk-wasm enhances CLI11 with a
itk::wasm::Pipeline
wrapper to support efficient execution in multiple Wasm contexts, scientific data structures, and lovely colorized help output 🥰.Let's get started! 🚀
0. Preliminaries
Before starting this tutorial, check out our Hello Wasm World tutorial.
1. Write the code
First, let's create a new directory to house our project.
Let's write some code! Populate hello-pipeline.cxx first with the headers we need:
The itkPipeline.h and itkInputImage.h headers come from the itk-wasm WebAssemblyInterface ITK module.
The itkImage.h header is ITK's standard n-dimensional image data structure.
Next, create a standard
main
C command line interface function and anitk::wasm::Pipeline
:The
itk::wasm::Pipeline
extends the CLI11 modern C++ command line parser. In addition to all of CLI11's functionality,itk::wasm::Pipeline
's adds:Image
,Mesh
,PolyData
, andTransform
Add a standard CLI11 flag to the pipeline:
Add an input image argument to the pipeline:
The
inputImage
variable is populated from the filesystem if built as a native executable or a WASI binary run from the command line. When running in the browser or in a wrapped language,inputImage
is read from WebAssembly memory without file IO.Parse the command line arguments with the
ITK_WASM_PARSE
macro:If
-q
or--quiet
is set, thequiet
variable will be set totrue
. Missing or invalid arguments will print an error and exit. The-h
and--help
flags are automatically generated from pipeline arguments to print usage information.Finally, run the pipeline:
Next, provide a CMake build configuration in CMakeLists.txt:
2. Create and Run WebAssembly binary
Build the WASI binary:
And check the generated help output:
The two
--
's are to separate arguments for the Wasm module from arguments to theitk-wasm
CLI and the WebAssembly interpreter.Try running on an example image.
And with the
--quiet
flag:Congratulations! You just executed a C++ pipeline capable of processsing a scientific image in WebAssembly. 🎉
What's next
We created a processing pipeline that works with real data – exciting! When creating these pipelines, however, we will sometimes need a more detailed understanding of their execution. In our next post, we will address this need by describing how to debug itk-wasm WASI modules.