Skip to content

Commit b249188

Browse files
committed
feat(transform): add affine-ops pipeline
1 parent aa46e1a commit b249188

4 files changed

Lines changed: 575 additions & 1 deletion

File tree

packages/transform/CMakeLists.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ foreach(transform
6767
)
6868
endforeach()
6969

70+
# Add affine-ops pipeline
71+
add_executable(affine-ops affine-ops.cxx)
72+
target_link_libraries(affine-ops PUBLIC ${ITK_LIBRARIES})
73+
target_include_directories(affine-ops PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
74+
7075
enable_testing()
7176
add_test(NAME create-translation-transform
7277
COMMAND create-translation-transform
@@ -85,4 +90,13 @@ add_test(NAME create-affine-transform
8590
add_test(NAME create-affine-defaults
8691
COMMAND create-affine-transform
8792
${CMAKE_CURRENT_BINARY_DIR}/create-affine-defaults.iwt
88-
)
93+
)
94+
95+
add_test(NAME affine-ops-test
96+
COMMAND affine-ops
97+
${CMAKE_CURRENT_BINARY_DIR}/create-affine.iwt
98+
${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/affine-ops-input.json
99+
${CMAKE_CURRENT_BINARY_DIR}/affine-ops-output.iwt
100+
)
101+
102+
set_tests_properties(affine-ops-test PROPERTIES DEPENDS create-affine-transform)
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# Affine Operations Pipeline
2+
3+
The `affine-ops` pipeline applies a sequence of operations to an affine transform.
4+
5+
## Usage
6+
7+
```bash
8+
affine-ops input-transform output-transform operations
9+
```
10+
11+
Where:
12+
- `input-transform`: An input affine transform file
13+
- `output-transform`: The output transform file after applying operations
14+
- `operations`: A JSON array of operations to apply sequentially
15+
16+
## Operations Format
17+
18+
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.
19+
20+
### Supported Operations
21+
22+
#### SetIdentity
23+
Resets the transform to identity.
24+
```json
25+
{"method": "SetIdentity"}
26+
```
27+
28+
#### Translate
29+
Translates the transform by a vector.
30+
```json
31+
{
32+
"method": "Translate",
33+
"translation": [x, y, z],
34+
"pre": false
35+
}
36+
```
37+
- `translation`: Vector of translation values (length must match transform dimension)
38+
- `pre`: Optional boolean, if true applies pre-composition (default: false)
39+
40+
#### Scale
41+
Scales the transform by a factor or vector of factors.
42+
```json
43+
{
44+
"method": "Scale",
45+
"factor": 2.0,
46+
"pre": false
47+
}
48+
```
49+
or
50+
```json
51+
{
52+
"method": "Scale",
53+
"factor": [2.0, 1.5, 0.8],
54+
"pre": false
55+
}
56+
```
57+
- `factor`: Scalar value or vector of scale factors
58+
- `pre`: Optional boolean, if true applies pre-composition (default: false)
59+
60+
#### Rotate
61+
Rotates around two axes by an angle.
62+
```json
63+
{
64+
"method": "Rotate",
65+
"axis1": 0,
66+
"axis2": 1,
67+
"angle": 1.57,
68+
"pre": false
69+
}
70+
```
71+
- `axis1`, `axis2`: Axis indices for rotation plane
72+
- `angle`: Rotation angle in radians
73+
- `pre`: Optional boolean, if true applies pre-composition (default: false)
74+
75+
#### Rotate2D (2D transforms only)
76+
Rotates in 2D by an angle.
77+
```json
78+
{
79+
"method": "Rotate2D",
80+
"angle": 1.57,
81+
"pre": false
82+
}
83+
```
84+
- `angle`: Rotation angle in radians
85+
- `pre`: Optional boolean, if true applies pre-composition (default: false)
86+
87+
#### Rotate3D (3D transforms only)
88+
Rotates around a specified axis.
89+
```json
90+
{
91+
"method": "Rotate3D",
92+
"axis": [0, 0, 1],
93+
"angle": 1.57,
94+
"pre": false
95+
}
96+
```
97+
- `axis`: 3D vector specifying rotation axis
98+
- `angle`: Rotation angle in radians
99+
- `pre`: Optional boolean, if true applies pre-composition (default: false)
100+
101+
#### Shear
102+
Applies a shear transformation.
103+
```json
104+
{
105+
"method": "Shear",
106+
"axis1": 0,
107+
"axis2": 1,
108+
"coef": 0.5,
109+
"pre": false
110+
}
111+
```
112+
- `axis1`, `axis2`: Axis indices for shear
113+
- `coef`: Shear coefficient
114+
- `pre`: Optional boolean, if true applies pre-composition (default: false)
115+
116+
## Example
117+
118+
```bash
119+
# Create an affine transform
120+
create-affine-transform identity.iwt
121+
122+
# Apply operations: reset to identity, translate, then scale
123+
affine-ops identity.iwt result.iwt \
124+
'[
125+
{"method": "SetIdentity"},
126+
{"method": "Translate", "translation": [1.0, 2.0, 3.0]},
127+
{"method": "Scale", "factor": 2.0}
128+
]'
129+
```
130+
131+
This will create a transform that first translates by (1,2,3) and then scales by a factor of 2.

0 commit comments

Comments
 (0)