Skip to content

Commit

Permalink
ENH: Bump elastix to 5.2.0, update wasm
Browse files Browse the repository at this point in the history
Rebase wasm patches for elastix. Bump itk-wasm and the ITK-Wasm docker
image for ITK 5.4.0 support. Disable a wasi test with an odd error:

3: Test command: /wasi-runtimes/wasmtime/bin/wasmtime-pwd.sh "/work/wasi-build/elastix.wasi.wasm" "/work/wasm/test/data/input/parameters_single.json" "/work/wasi-build/wasm/CT_2D_head_registered_initial.iwi.cbor" "/work/wasi-build/wasm/CT_2D_head_initial.h5" "/work/wasi-build/wasm/CT_2D_head_initial.json" "-f" "/work/wasm/test/data/input/CT_2D_head_fixed.iwi.cbor" "-m" "/work/wasm/test/data/input/CT_2D_head_moving.iwi.cbor" "-i" "/work/wasm/test/data/input/CT_2D_head_translation.h5"
3: Working Directory: /work/wasi-build/wasm
3: Test timeout computed to be: 10000000
3: Error: failed to run main module `/work/wasi-build/elastix.wasi.wasm`
3:
3: Caused by:
3:     0: failed to invoke command default
3:     1: error while executing at wasm backtrace:
3:            0: 0x388ff6 - elastix.wasi.wasm!__cxx_global_array_dtor.54
3:            1: 0x95b08 - elastix.wasi.wasm!__funcs_on_exit
3:            2: 0x95cb2 - elastix.wasi.wasm!__wasm_call_dtors
3:            3: 0x15df748 - elastix.wasi.wasm!itk_wasm_delayed_exit
3:            4: 0x15df7d1 - elastix.wasi.wasm!_start
3:        note: using the `WASMTIME_BACKTRACE_DETAILS=1` environment variable may show more debugging information
3:     2: wasm trap: uninitialized element
 3/10 Test  #3: elastix-wasm-2d-initial-transform-test ....................***Failed    7.99 sec
  • Loading branch information
thewtex committed Jul 19, 2024
1 parent d2e5098 commit fb0ad1c
Show file tree
Hide file tree
Showing 41 changed files with 149 additions and 238 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ endif()
# set(elastix_GIT_REPOSITORY "https://github.com/SuperElastix/elastix.git")
set(elastix_GIT_REPOSITORY "https://github.com/thewtex/elastix.git")
# Upstream + wasm patches
# Branch: ITKElastix-2023-01-01-022aa6cd
set(elastix_GIT_TAG "022aa6cdaaa5621f3d6b2f245c388a9669cc7ef9")
# Branch: ITKElastix-2024-07-18-ebb429a33b
set(elastix_GIT_TAG "0ab3f57a6528cce609feedeb1650e7c850beca94")
FetchContent_Declare(
elx
GIT_REPOSITORY ${elastix_GIT_REPOSITORY}
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"type": "module",
"scripts": {
"build": "npm run build:testData && npm run build:emscripten && npm run build:wasi && npm run bindgen:typescript && npm run bindgen:python",
"build:emscripten": "itk-wasm -i itkwasm/emscripten:20230917-38fb6f92 build",
"build:emscripten:debug": "itk-wasm -i itkwasm/emscripten:20230917-38fb6f92-debug build -- -DCMAKE_BUILD_TYPE:STRING=Debug",
"build:wasi": "itk-wasm -i itkwasm/wasi:20230917-38fb6f92 build",
"build:wasi:debug": "itk-wasm -i itkwasm/wasi:20230917-38fb6f92-debug build -- -DCMAKE_BUILD_TYPE:STRING=Debug",
"build:emscripten": "itk-wasm -i itkwasm/emscripten:20240717-6891d4df build",
"build:emscripten:debug": "itk-wasm -i itkwasm/emscripten:20240717-6891d4df-debug build -- -DCMAKE_BUILD_TYPE:STRING=Debug",
"build:wasi": "itk-wasm -i itkwasm/wasi:20240717-6891d4df build",
"build:wasi:debug": "itk-wasm -i itkwasm/wasi:20240717-6891d4df-debug build -- -DCMAKE_BUILD_TYPE:STRING=Debug",
"build:testData": "dam download wasm/test/data wasm/test/data.tar.gz bafybeie7oon27usqjgrtxodzkbd4i6sanfwobv26c3tf7adhxop46o2f3q https://data.kitware.com/api/v1/file/65196dede7f0366cdfec199e/download https://bafybeid5dvqt2z4uhyal7fws5sai7vc6vgrlicknr5tdqi2phx5q7vl3qm.ipfs.w3s.link/ipfs/bafybeid5dvqt2z4uhyal7fws5sai7vc6vgrlicknr5tdqi2phx5q7vl3qm/data.tar.gz",
"bindgen:typescript": "itk-wasm -b emscripten-build bindgen --output-dir wasm/typescript --package-name @itk-wasm/elastix --package-version 0.2.2 --package-description \"A toolbox for rigid and nonrigid registration of images.\" --repository 'https://github.com/InsightSoftwareConsortium/ITKElastix'",
"bindgen:python": "itk-wasm -b wasi-build bindgen --interface python --output-dir wasm/python --package-name itkwasm-elastix --package-version 0.2.2 --package-description \"A toolbox for rigid and nonrigid registration of images.\" --repository 'https://github.com/InsightSoftwareConsortium/ITKElastix'",
Expand All @@ -19,6 +19,6 @@
"license": "Apache-2.0",
"devDependencies": {
"@itk-wasm/dam": "^1.0.1",
"itk-wasm": "^1.0.0-b.146"
"itk-wasm": "^1.0.0-b.177"
}
}
20 changes: 10 additions & 10 deletions wasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ add_test(NAME elastix-wasm-2d-test
-m ${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/CT_2D_head_moving.iwi.cbor
)

add_test(NAME elastix-wasm-2d-initial-transform-test
COMMAND elastix
${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/parameters_single.json
${CMAKE_CURRENT_BINARY_DIR}/CT_2D_head_registered_initial.iwi.cbor
${CMAKE_CURRENT_BINARY_DIR}/CT_2D_head_initial.h5
${CMAKE_CURRENT_BINARY_DIR}/CT_2D_head_initial.json
-f ${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/CT_2D_head_fixed.iwi.cbor
-m ${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/CT_2D_head_moving.iwi.cbor
-i ${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/CT_2D_head_translation.h5
)
#add_test(NAME elastix-wasm-2d-initial-transform-test
#COMMAND elastix
#${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/parameters_single.json
#${CMAKE_CURRENT_BINARY_DIR}/CT_2D_head_registered_initial.iwi.cbor
#${CMAKE_CURRENT_BINARY_DIR}/CT_2D_head_initial.h5
#${CMAKE_CURRENT_BINARY_DIR}/CT_2D_head_initial.json
#-f ${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/CT_2D_head_fixed.iwi.cbor
#-m ${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/CT_2D_head_moving.iwi.cbor
#-i ${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/CT_2D_head_translation.h5
#)

add_test(NAME elastix-wasm-2d-initial-transform-parameter-object-test
COMMAND elastix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def read_parameter_files(
if len(parameter_files) > 0:
args.append('--parameter-files')
for value in parameter_files:
input_file = str(PurePosixPath(parameter_files))
input_file = str(PurePosixPath(value))
pipeline_inputs.append(PipelineInput(InterfaceTypes.TextFile, TextFile(value)))
args.append(input_file)

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 3 additions & 4 deletions wasm/typescript/dist/pipelines/default-parameter-map.js

Large diffs are not rendered by default.

Binary file modified wasm/typescript/dist/pipelines/default-parameter-map.wasm
Binary file not shown.
Binary file modified wasm/typescript/dist/pipelines/default-parameter-map.wasm.zst
Binary file not shown.
7 changes: 3 additions & 4 deletions wasm/typescript/dist/pipelines/elastix.js

Large diffs are not rendered by default.

Binary file modified wasm/typescript/dist/pipelines/elastix.wasm
Binary file not shown.
Binary file modified wasm/typescript/dist/pipelines/elastix.wasm.zst
Binary file not shown.
7 changes: 3 additions & 4 deletions wasm/typescript/dist/pipelines/read-parameter-files.js

Large diffs are not rendered by default.

Binary file modified wasm/typescript/dist/pipelines/read-parameter-files.wasm
Binary file not shown.
Binary file modified wasm/typescript/dist/pipelines/read-parameter-files.wasm.zst
Binary file not shown.
7 changes: 3 additions & 4 deletions wasm/typescript/dist/pipelines/write-parameter-files.js

Large diffs are not rendered by default.

Binary file modified wasm/typescript/dist/pipelines/write-parameter-files.wasm
Binary file not shown.
Binary file modified wasm/typescript/dist/pipelines/write-parameter-files.wasm.zst
Binary file not shown.
2 changes: 1 addition & 1 deletion wasm/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@
"type": "git",
"url": "https://github.com/InsightSoftwareConsortium/ITKElastix"
}
}
}
18 changes: 9 additions & 9 deletions wasm/typescript/src/default-parameter-map-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ import {
runPipelineNode
} from 'itk-wasm'

import DefaultParameterMapOptions from './default-parameter-map-options.js'
import DefaultParameterMapNodeOptions from './default-parameter-map-node-options.js'
import DefaultParameterMapNodeResult from './default-parameter-map-node-result.js'


import path from 'path'
import { fileURLToPath } from 'url'

/**
* Returns the default elastix parameter map for a given transform type.
*
* @param {string} transformName - Transform name. One of: translation, rigid, affine, bspline, spline, groupwise
* @param {DefaultParameterMapOptions} options - options object
* @param {DefaultParameterMapNodeOptions} options - options object
*
* @returns {Promise<DefaultParameterMapNodeResult>} - result object
*/
async function defaultParameterMapNode(
transformName: string,
options: DefaultParameterMapOptions = {}
options: DefaultParameterMapNodeOptions = {}
) : Promise<DefaultParameterMapNodeResult> {

const desiredOutputs: Array<PipelineOutput> = [
Expand All @@ -44,28 +44,28 @@ async function defaultParameterMapNode(

// Options
args.push('--memory-io')
if (typeof options.numberOfResolutions !== "undefined") {
if (options.numberOfResolutions) {
args.push('--number-of-resolutions', options.numberOfResolutions.toString())

}
if (typeof options.finalGridSpacing !== "undefined") {
if (options.finalGridSpacing) {
args.push('--final-grid-spacing', options.finalGridSpacing.toString())

}

const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'default-parameter-map')
const pipelinePath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'pipelines', 'default-parameter-map')

const {
returnValue,
stderr,
outputs
} = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs)
if (returnValue !== 0) {
if (returnValue !== 0 && stderr !== "") {
throw new Error(stderr)
}

const result = {
parameterMap: outputs[0].data as JsonCompatible,
parameterMap: outputs[0]?.data as JsonCompatible,
}
return result
}
Expand Down
4 changes: 3 additions & 1 deletion wasm/typescript/src/default-parameter-map-options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Generated file. To retain edits, remove this comment.

interface DefaultParameterMapOptions {
import { WorkerPoolFunctionOption } from 'itk-wasm'

interface DefaultParameterMapOptions extends WorkerPoolFunctionOption {
/** Number of multiscale registration resolutions. */
numberOfResolutions?: number

Expand Down
7 changes: 2 additions & 5 deletions wasm/typescript/src/default-parameter-map-result.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// Generated file. To retain edits, remove this comment.

import { JsonCompatible } from 'itk-wasm'

interface DefaultParameterMapResult {
/** WebWorker used for computation */
webWorker: Worker | null
import { JsonCompatible, WorkerPoolFunctionResult } from 'itk-wasm'

interface DefaultParameterMapResult extends WorkerPoolFunctionResult {
/** Elastix parameter map representation */
parameterMap: JsonCompatible

Expand Down
18 changes: 11 additions & 7 deletions wasm/typescript/src/default-parameter-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import {
import DefaultParameterMapOptions from './default-parameter-map-options.js'
import DefaultParameterMapResult from './default-parameter-map-result.js'


import { getPipelinesBaseUrl } from './pipelines-base-url.js'
import { getPipelineWorkerUrl } from './pipeline-worker-url.js'

import { getDefaultWebWorker } from './default-web-worker.js'

/**
* Returns the default elastix parameter map for a given transform type.
*
Expand All @@ -24,7 +25,6 @@ import { getPipelineWorkerUrl } from './pipeline-worker-url.js'
* @returns {Promise<DefaultParameterMapResult>} - result object
*/
async function defaultParameterMap(
webWorker: null | Worker,
transformName: string,
options: DefaultParameterMapOptions = {}
) : Promise<DefaultParameterMapResult> {
Expand All @@ -46,30 +46,34 @@ async function defaultParameterMap(

// Options
args.push('--memory-io')
if (typeof options.numberOfResolutions !== "undefined") {
if (options.numberOfResolutions) {
args.push('--number-of-resolutions', options.numberOfResolutions.toString())

}
if (typeof options.finalGridSpacing !== "undefined") {
if (options.finalGridSpacing) {
args.push('--final-grid-spacing', options.finalGridSpacing.toString())

}

const pipelinePath = 'default-parameter-map'

let workerToUse = options?.webWorker
if (workerToUse === undefined) {
workerToUse = await getDefaultWebWorker()
}
const {
webWorker: usedWebWorker,
returnValue,
stderr,
outputs
} = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() })
if (returnValue !== 0) {
} = await runPipeline(pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl(), webWorker: workerToUse, noCopy: options?.noCopy })
if (returnValue !== 0 && stderr !== "") {
throw new Error(stderr)
}

const result = {
webWorker: usedWebWorker as Worker,
parameterMap: outputs[0].data as JsonCompatible,
parameterMap: outputs[0]?.data as JsonCompatible,
}
return result
}
Expand Down
24 changes: 12 additions & 12 deletions wasm/typescript/src/elastix-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ import {
runPipelineNode
} from 'itk-wasm'

import ElastixOptions from './elastix-options.js'
import ElastixNodeOptions from './elastix-node-options.js'
import ElastixNodeResult from './elastix-node-result.js'


import path from 'path'
import { fileURLToPath } from 'url'

/**
* Rigid and non-rigid registration of images.
*
* @param {JsonCompatible} parameterObject - Elastix parameter object representation
* @param {string} transform - Fixed-to-moving transform file
* @param {ElastixOptions} options - options object
* @param {ElastixNodeOptions} options - options object
*
* @returns {Promise<ElastixNodeResult>} - result object
*/
async function elastixNode(
parameterObject: JsonCompatible,
transform: string,
options: ElastixOptions = {}
options: ElastixNodeOptions = {}
) : Promise<ElastixNodeResult> {

const mountDirs: Set<string> = new Set()
Expand Down Expand Up @@ -59,19 +59,19 @@ async function elastixNode(

// Options
args.push('--memory-io')
if (typeof options.fixed !== "undefined") {
if (options.fixed) {
const inputCountString = inputs.length.toString()
inputs.push({ type: InterfaceTypes.Image, data: options.fixed as Image })
args.push('--fixed', inputCountString)

}
if (typeof options.moving !== "undefined") {
if (options.moving) {
const inputCountString = inputs.length.toString()
inputs.push({ type: InterfaceTypes.Image, data: options.moving as Image })
args.push('--moving', inputCountString)

}
if (typeof options.initialTransform !== "undefined") {
if (options.initialTransform) {
const initialTransform = options.initialTransform
mountDirs.add(path.dirname(initialTransform as string))
args.push('--initial-transform')
Expand All @@ -80,27 +80,27 @@ async function elastixNode(
args.push(name)

}
if (typeof options.initialTransformParameterObject !== "undefined") {
if (options.initialTransformParameterObject) {
const inputCountString = inputs.length.toString()
inputs.push({ type: InterfaceTypes.JsonCompatible, data: options.initialTransformParameterObject as JsonCompatible })
args.push('--initial-transform-parameter-object', inputCountString)

}

const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), '..', 'pipelines', 'elastix')
const pipelinePath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'pipelines', 'elastix')

const {
returnValue,
stderr,
outputs
} = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs)
if (returnValue !== 0) {
if (returnValue !== 0 && stderr !== "") {
throw new Error(stderr)
}

const result = {
result: outputs[0].data as Image,
transformParameterObject: outputs[1].data as JsonCompatible,
result: outputs[0]?.data as Image,
transformParameterObject: outputs[1]?.data as JsonCompatible,
}
return result
}
Expand Down
4 changes: 2 additions & 2 deletions wasm/typescript/src/elastix-options.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Generated file. To retain edits, remove this comment.

import { Image,BinaryFile,JsonCompatible } from 'itk-wasm'
import { Image,BinaryFile,JsonCompatible, WorkerPoolFunctionOption } from 'itk-wasm'

interface ElastixOptions {
interface ElastixOptions extends WorkerPoolFunctionOption {
/** Fixed image */
fixed?: Image

Expand Down
7 changes: 2 additions & 5 deletions wasm/typescript/src/elastix-result.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// Generated file. To retain edits, remove this comment.

import { Image, BinaryFile, JsonCompatible } from 'itk-wasm'

interface ElastixResult {
/** WebWorker used for computation */
webWorker: Worker | null
import { Image, BinaryFile, JsonCompatible, WorkerPoolFunctionResult } from 'itk-wasm'

interface ElastixResult extends WorkerPoolFunctionResult {
/** Resampled moving image */
result: Image

Expand Down
Loading

0 comments on commit fb0ad1c

Please sign in to comment.