Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support shape by 3 for output mesh, polydata points #1008

Open
thewtex opened this issue Nov 29, 2023 · 0 comments
Open

support shape by 3 for output mesh, polydata points #1008

thewtex opened this issue Nov 29, 2023 · 0 comments

Comments

@thewtex
Copy link
Member

thewtex commented Nov 29, 2023

WIP patch:

diff --git a/packages/core/python/itkwasm/itkwasm/pipeline.py b/packages/core/python/itkwasm/itkwasm/pipeline.py
index 1424b68b..417a31a0 100644
--- a/packages/core/python/itkwasm/itkwasm/pipeline.py
+++ b/packages/core/python/itkwasm/itkwasm/pipeline.py
@@ -345,7 +345,7 @@ class Pipeline:
                     if mesh.numberOfPoints > 0:
                         data_ptr = ri.get_output_array_address(0, index, 0)
                         data_size = ri.get_output_array_size(0, index, 0)
-                        mesh.points = _to_numpy_array(mesh.meshType.pointComponentType, ri.wasmtime_lift(data_ptr, data_size))
+                        mesh.points = _to_numpy_array(mesh.meshType.pointComponentType, ri.wasmtime_lift(data_ptr, data_size)).reshape((-1, mesh.meshType.dimension))
                     else:
                         mesh.points =  _to_numpy_array(mesh.meshType.pointComponentType, bytes([]))
 
@@ -377,7 +377,7 @@ class Pipeline:
                     if polydata.numberOfPoints > 0:
                         data_ptr = ri.get_output_array_address(0, index, 0)
                         data_size = ri.get_output_array_size(0, index, 0)
-                        polydata.points = _to_numpy_array(FloatTypes.Float32, ri.wasmtime_lift(data_ptr, data_size))
+                        polydata.points = _to_numpy_array(FloatTypes.Float32, ri.wasmtime_lift(data_ptr, data_size)).reshape((-1, 3))
                     else:
                         polydata.points =  _to_numpy_array(FloatTypes.Float32, bytes([]))
 
diff --git a/packages/core/python/itkwasm/test/test_pipeline.py b/packages/core/python/itkwasm/test/test_pipeline.py
index 666ed5ef..e83e548f 100644
--- a/packages/core/python/itkwasm/test/test_pipeline.py
+++ b/packages/core/python/itkwasm/test/test_pipeline.py
@@ -167,6 +167,9 @@ def test_pipeline_write_read_mesh():
 
     outputs = pipeline.run(args, pipeline_outputs, pipeline_inputs)
 
+    print(outputs[0].data)
+    print(outputs[0].data.points.shape)
+
     out_mesh_dict = asdict(outputs[0].data)
     # Native ITK Python binaries require uint64
     out_mesh_dict['cells'] = out_mesh_dict['cells'].astype(np.uint64)

But the following needs to be addressed in itk Python:

test/test_pipeline.py:177:                                                                           
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/matt/bin/micromamba/envs/itk-wasm/lib/python3.11/site-packages/itk/support/extras.py:828: in me
sh_from_dict                                                                                         
    points = itk.vector_container_from_array(points)                                                 
/home/matt/bin/micromamba/envs/itk-wasm/lib/python3.11/site-packages/itk/support/extras.py:561: in ve
ctor_container_from_array                                                                            
    return itk.PyVectorContainer[keys[0]].vector_container_from_array(arr)                           
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _                                                                                                     
ndarr = array([[3.71636 , 2.34339 , 0.      ],                                                              [4.12656 , 0.642027, 0.      ],                                                               
       [3.45497 , 2.16988 , 0.      ],                                                               
 ...16 , 2.12093 , 1.17252 ],                                                                        
       [4.13317 , 2.17523 , 1.25932 ],                                                               
       [4.23234 , 1.90308 , 0.534362]], dtype=float32)                                               
                                                                                                     
    def vector_container_from_array(ndarr):                                                          
        """Get an itk.VectorContainer from a NumPy array.                                            
                                                                                                     
        This is a deep copy of the NumPy array buffer and is completely safe without potential       
        side effects.                                                                                
        """                                                                                          
                                                                                                     
>       assert ndarr.ndim == 1 , "Only arrays of 1 dimension are supported."                         
E       AssertionError: Only arrays of 1 dimension are supported.                                    
                                                                       
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant