Skip to content

Commit 7113730

Browse files
committed
feat(itkwasm): Add PointSet, PointSetType
1 parent b2164f3 commit 7113730

File tree

6 files changed

+80
-2
lines changed

6 files changed

+80
-2
lines changed

src/python/itkwasm/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
"""itkwasm: Python interface to itk-wasm WebAssembly modules."""
22

3-
__version__ = "1.0a0"
3+
__version__ = "1.0b0"
44

55
from .image import Image, ImageType
66
from .mesh import Mesh, MeshType
7+
from .pointset import PointSet, PointSetType
78

89
__all__ = [
910
"Image",
1011
"ImageType",
1112
"Mesh",
1213
"MeshType",
14+
"PointSet",
15+
"PointSetType",
1316
]

src/python/itkwasm/mesh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from dataclasses import dataclass
22

3-
from typing import Sequence, Optional
3+
from typing import Optional
44

55
try:
66
from numpy.typing import ArrayLike

src/python/itkwasm/pointset.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from dataclasses import dataclass
2+
3+
from typing import Optional
4+
5+
try:
6+
from numpy.typing import ArrayLike
7+
except ImportError:
8+
from numpy import ndarray as ArrayLike
9+
10+
@dataclass
11+
class PointSetType:
12+
dimension: int
13+
14+
pointComponentType: str
15+
pointPixelComponentType: str
16+
pointPixelType: str
17+
pointPixelComponents: int
18+
19+
20+
@dataclass
21+
class PointSet:
22+
pointSetType: PointSetType
23+
24+
name: str
25+
26+
numberOfPoints: int
27+
points: Optional[ArrayLike]
28+
29+
numberOfPointPixels: int
30+
pointData: Optional[ArrayLike]

src/python/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ dynamic = ["version", "description"]
2828

2929
requires-python = ">=3.7"
3030
dependencies = [
31+
"numpy",
3132
]
3233

3334
[project.urls]

src/python/test/test_mesh.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def test_mesh():
2121
meshType = itk_mesh_dict["meshType"]
2222
meshType_roundtrip = itk_mesh_roundtrip_dict["meshType"]
2323
assert meshType["dimension"] == meshType_roundtrip["dimension"]
24+
2425
assert meshType["pointComponentType"] == meshType_roundtrip["pointComponentType"]
2526
assert meshType["pointPixelComponentType"] == meshType_roundtrip["pointPixelComponentType"]
2627
assert meshType["pointPixelType"] == meshType_roundtrip["pointPixelType"]

src/python/test/test_pointset.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import itk
2+
3+
from itkwasm import PointSet
4+
from dataclasses import asdict
5+
import numpy as np
6+
7+
def test_pointset():
8+
n_points = 5
9+
dimension = 3
10+
11+
PointSetType = itk.PointSet[itk.F, dimension]
12+
pointset = PointSetType.New()
13+
14+
points = np.random.random((n_points, dimension)).astype(np.float32)
15+
pointset.SetPoints(itk.vector_container_from_array(points.ravel()))
16+
17+
point_data = np.random.random((n_points,)).astype(np.float32)
18+
pointset.SetPointData(itk.vector_container_from_array(point_data.ravel()))
19+
20+
itk_pointset_dict = itk.dict_from_pointset(pointset)
21+
# Bug, to be fixed by 5.3.0
22+
itk_pointset_dict.pop('dimension', None)
23+
itkwasm_pointset = PointSet(**itk_pointset_dict)
24+
itkwasm_pointset_dict = asdict(itkwasm_pointset)
25+
itk_pointset_roundtrip = itk.pointset_from_dict(itkwasm_pointset_dict)
26+
itk_pointset_roundtrip_dict = itk.dict_from_pointset(itk_pointset_roundtrip)
27+
28+
pointSetType = itk_pointset_dict["pointSetType"]
29+
pointSetType_roundtrip = itk_pointset_roundtrip_dict["pointSetType"]
30+
assert pointSetType["dimension"] == pointSetType_roundtrip["dimension"]
31+
32+
assert pointSetType["pointComponentType"] == pointSetType_roundtrip["pointComponentType"]
33+
assert pointSetType["pointPixelComponentType"] == pointSetType_roundtrip["pointPixelComponentType"]
34+
assert pointSetType["pointPixelType"] == pointSetType_roundtrip["pointPixelType"]
35+
assert pointSetType["pointPixelComponents"] == pointSetType_roundtrip["pointPixelComponents"]
36+
37+
assert itk_pointset_dict["name"] == itk_pointset_roundtrip_dict["name"]
38+
39+
assert itk_pointset_dict["numberOfPoints"] == itk_pointset_roundtrip_dict["numberOfPoints"]
40+
assert np.array_equal(itk_pointset_dict["points"], itk_pointset_roundtrip_dict["points"])
41+
42+
assert itk_pointset_dict["numberOfPointPixels"] == itk_pointset_roundtrip_dict["numberOfPointPixels"]
43+
assert np.array_equal(itk_pointset_dict["pointData"], itk_pointset_roundtrip_dict["pointData"])

0 commit comments

Comments
 (0)