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