Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/itkSupportInputTransformTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class PipelineFunctor
int
main(int argc, char * argv[])
{
itk::wasm::Pipeline pipeline("support-multiple", "Test supporting multiple input polydata types", argc, argv);
itk::wasm::Pipeline pipeline("support-multiple", "Test supporting multiple input transform types", argc, argv);

// Supports the parameters types float, double, and dimensions 2 and 3
return itk::wasm::SupportInputTransformTypes<PipelineFunctor, float, double>
Expand Down
3 changes: 3 additions & 0 deletions itk_wasm_env.bash
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ export ITK_WASM_MESH_IO_TEST_DATA_URLS=${ITK_WASM_MESH_IO_TEST_DATA_URLS:-$(cat

export ITK_WASM_TRANSFORM_IO_TEST_DATA_HASH=${ITK_WASM_TRANSFORM_IO_TEST_DATA_HASH:-$(cat packages/transform-io/package.json | jq -e -r '."itk-wasm"."test-data-hash"')}
export ITK_WASM_TRANSFORM_IO_TEST_DATA_URLS=${ITK_WASM_TRANSFORM_IO_TEST_DATA_URLS:-$(cat packages/transform-io/package.json | jq -e -r '."itk-wasm"."test-data-urls" | join(" ")')}

export ITK_WASM_TRANSFORM_TEST_DATA_HASH=${ITK_WASM_TRANSFORM_TEST_DATA_HASH:-$(cat packages/transform/package.json | jq -e -r '."itk-wasm"."test-data-hash"')}
export ITK_WASM_TRANSFORM_TEST_DATA_URLS=${ITK_WASM_TRANSFORM_TEST_DATA_URLS:-$(cat packages/transform/package.json | jq -e -r '."itk-wasm"."test-data-urls" | join(" ")')}
9 changes: 8 additions & 1 deletion packages/downsample/downsample-bin-shrink.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "itkOutputImage.h"
#include "itkSupportInputImageTypes.h"

#include "itkVectorImage.h"
#include "itkBinShrinkImageFilter.h"

template <typename TImage>
Expand Down Expand Up @@ -92,5 +93,11 @@ main(int argc, char * argv[])
uint64_t,
int64_t,
float,
double>::Dimensions<2U, 3U, 4U, 5U>("input", pipeline);
double,
itk::VariableLengthVector<uint8_t>,
itk::VariableLengthVector<uint16_t>,
itk::VariableLengthVector<int16_t>,
itk::VariableLengthVector<float>,
itk::VariableLengthVector<double>
>::Dimensions<2U, 3U, 4U, 5U>("input", pipeline);
}
18 changes: 18 additions & 0 deletions packages/transform/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
emscripten-build/
wasi-build/
python/itkwasm-transform-wasi/itkwasm_transform_wasi/wasm_modules/
typescript/dist/
typescript/test/browser/demo-app/public/
typescript/demo-app/
typescript/src/version.ts
test/pyodide-dispatch.tar.bz2
test/pyodide-emscripten.tar.bz2
test/data/
tests/data/
test/data.tar.gz
test/data/baseline/
test/data/python/
python/itkwasm-transform-emscripten/dist/
python/itkwasm-transform-wasi/dist/
python/itkwasm-transform/dist/
pyodide/
1 change: 1 addition & 0 deletions packages/transform/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
git-checks=false
102 changes: 102 additions & 0 deletions packages/transform/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
cmake_minimum_required(VERSION 3.16)
project(itkwasm-downsample LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)

if(EMSCRIPTEN)
set(io_components
)
elseif(WASI)
set(io_components
)
else()
set(io_components
ITKTransformIO
)
endif()

find_package(ITK REQUIRED
COMPONENTS
WebAssemblyInterface
${io_components}
)
include(${ITK_USE_FILE})

foreach(transform
"composite"
"identity"
"translation"
"euler2d"
"euler3d"
"rigid2d"
"rigid3d"
"rigid3d-perspective"
"versor-rigid3d"
"versor"
"scale"
"scale-logarithmic"
"scale-skew-versor3d"
"similarity2d"
"similarity3d"
"quaternion-rigid"
"affine"
"scalable-affine"
"azimuth-elevation-to-cartesian"
"bspline"
"bspline-smoothing-on-update-displacement-field"
"constant-velocity-field"
"displacement-field"
"gaussian-smoothing-on-update-displacement-field"
"gaussian-exponential-diffeomorphic"
"velocity-field"
"time-varying-velocity-field"
"gaussian-smoothing-on-update-time-varying-velocity-field"
)
set(pipeline create-${transform}-transform)
add_executable(${pipeline} create-transform.cxx)
target_link_libraries(${pipeline} PUBLIC ${ITK_LIBRARIES})
target_include_directories(${pipeline} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

# Convert transform name to a valid macro name by replacing hyphens with underscores
string(REPLACE "-" "_" transform_macro ${transform})
string(TOUPPER ${transform_macro} transform_macro)

target_compile_definitions(${pipeline} PUBLIC
-DTRANSFORM_NAME=${transform}
-DTRANSFORM_${transform_macro}=1
)
endforeach()

# Add affine-ops pipeline
add_executable(affine-ops affine-ops.cxx)
target_link_libraries(affine-ops PUBLIC ${ITK_LIBRARIES})
target_include_directories(affine-ops PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

enable_testing()
add_test(NAME create-translation-transform
COMMAND create-translation-transform
${CMAKE_CURRENT_BINARY_DIR}/create-translation.iwt
--dimension 2
--parameters-type float32
)

add_test(NAME create-affine-transform
COMMAND create-affine-transform
${CMAKE_CURRENT_BINARY_DIR}/create-affine.iwt
--dimension 3
--parameters-type float64
)

add_test(NAME create-affine-defaults
COMMAND create-affine-transform
${CMAKE_CURRENT_BINARY_DIR}/create-affine-defaults.iwt
)

add_test(NAME affine-ops-test
COMMAND affine-ops
${CMAKE_CURRENT_BINARY_DIR}/create-affine.iwt
${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/affine-ops-input.json
${CMAKE_CURRENT_BINARY_DIR}/affine-ops-output.iwt
)

set_tests_properties(affine-ops-test PROPERTIES DEPENDS create-affine-transform)
131 changes: 131 additions & 0 deletions packages/transform/README-affine-ops.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Affine Operations Pipeline

The `affine-ops` pipeline applies a sequence of operations to an affine transform.

## Usage

```bash
affine-ops input-transform output-transform operations
```

Where:
- `input-transform`: An input affine transform file
- `output-transform`: The output transform file after applying operations
- `operations`: A JSON array of operations to apply sequentially

## Operations Format

The operations parameter should be a JSON array where each element describes an operation to apply to the affine transform. Each operation object must have a `method` field specifying the operation type.

### Supported Operations

#### SetIdentity
Resets the transform to identity.
```json
{"method": "SetIdentity"}
```

#### Translate
Translates the transform by a vector.
```json
{
"method": "Translate",
"translation": [x, y, z],
"pre": false
}
```
- `translation`: Vector of translation values (length must match transform dimension)
- `pre`: Optional boolean, if true applies pre-composition (default: false)

#### Scale
Scales the transform by a factor or vector of factors.
```json
{
"method": "Scale",
"factor": 2.0,
"pre": false
}
```
or
```json
{
"method": "Scale",
"factor": [2.0, 1.5, 0.8],
"pre": false
}
```
- `factor`: Scalar value or vector of scale factors
- `pre`: Optional boolean, if true applies pre-composition (default: false)

#### Rotate
Rotates around two axes by an angle.
```json
{
"method": "Rotate",
"axis1": 0,
"axis2": 1,
"angle": 1.57,
"pre": false
}
```
- `axis1`, `axis2`: Axis indices for rotation plane
- `angle`: Rotation angle in radians
- `pre`: Optional boolean, if true applies pre-composition (default: false)

#### Rotate2D (2D transforms only)
Rotates in 2D by an angle.
```json
{
"method": "Rotate2D",
"angle": 1.57,
"pre": false
}
```
- `angle`: Rotation angle in radians
- `pre`: Optional boolean, if true applies pre-composition (default: false)

#### Rotate3D (3D transforms only)
Rotates around a specified axis.
```json
{
"method": "Rotate3D",
"axis": [0, 0, 1],
"angle": 1.57,
"pre": false
}
```
- `axis`: 3D vector specifying rotation axis
- `angle`: Rotation angle in radians
- `pre`: Optional boolean, if true applies pre-composition (default: false)

#### Shear
Applies a shear transformation.
```json
{
"method": "Shear",
"axis1": 0,
"axis2": 1,
"coef": 0.5,
"pre": false
}
```
- `axis1`, `axis2`: Axis indices for shear
- `coef`: Shear coefficient
- `pre`: Optional boolean, if true applies pre-composition (default: false)

## Example

```bash
# Create an affine transform
create-affine-transform identity.iwt

# Apply operations: reset to identity, translate, then scale
affine-ops identity.iwt result.iwt \
'[
{"method": "SetIdentity"},
{"method": "Translate", "translation": [1.0, 2.0, 3.0]},
{"method": "Scale", "factor": 2.0}
]'
```

This will create a transform that first translates by (1,2,3) and then scales by a factor of 2.
Loading
Loading