cg2
May 12, 2020, 9:13pm
1
Hi,
One of the module interface method I’m working on takes an itk::SmartPointer<itk::Mesh<float, 3>>
as parameter. In python, this translates to itkMeshF3_Pointer
. I tries to convert the output of itk.MeshFileReader
to itkMeshF3_Pointer
but the type seems unknown by default. Do I have to wrap it as part of my module?
Thanks for your help!
1 Like
Hi @cg2 ,
You may want to try the ITK 5.1.0 Python packages, which have support for both itk.Mesh.F3
and itk.Mesh.D3
– note that this can be found with:
import itk
itk.MeshFileReader.GetTypes()
And the convenient way to load files in ITK 5.1.0 without type specification is:
mesh = itk.meshread('mesh_filename.off')
1 Like
cg2
May 14, 2020, 2:33pm
3
@matt.mccormick Thanks for your help.
Here the result of itk.MeshFileReader.GetTypes()
:
6: [<itkCType double>, 2]
6: [<itkCType double>, 3]
6: [<itkCType float>, 2]
6: [<itkCType float>, 3]
6: [<itkCType signed short>, 2]
6: [<itkCType signed short>, 3]
6: [<itkCType unsigned char>, 2]
6: [<itkCType unsigned char>, 3]
When trying to read a mesh, I got the following error:
>>> mesh = itk.meshread(fixed_filename)
...
6: File "ITK-build/Wrapping/Generators/Python/itkExtras.py", line 767, in meshread
6: reader = TemplateReaderType.New(**kwargs)
6: File "ITK-build/Wrapping/Generators/Python/itkTemplate.py", line 473, in New
6: return self._NewMeshReader(itk.MeshFileReader, *args, **kwargs)
6: File "ITK-build/Wrapping/Generators/Python/itkTemplate.py", line 633, in _NewMeshReader
6: PixelType = itkTemplate._pixelTypeFromIO(pixel, component, numberOfComponents)
6: File "ITK-build/Wrapping/Generators/Python/itkTemplate.py", line 666, in _pixelTypeFromIO
6: raise RuntimeError("Unknown pixel type: %s." % pixel)
Even if I manage to get rid of this error, would I be able to do something like
mesh_ptr = itkMeshF3_Pointer(itk.meshread(fixed_filename))
given that my generated interface seems to expect itkMeshF3_Pointer?
Thanks again,
Charles
Hi Charles,
The detected type of the files may not be what is supported, so you can cast to a desired type, e.g. a float
type makes sense for many cases, like this:
mesh = itk.meshread(fixed_filename, itk.F)
cg2
May 14, 2020, 4:48pm
5
This works, thanks. Though, I’m still not able to convert it to itkMeshF3_Pointer
cg2:
itkMeshF3_Pointer
That is the equivalent of the result – pointers are not handled directly in Python.
1 Like
cg2
May 14, 2020, 5:43pm
7
Indeed… Updating my interface to take pointer instead of smart pointer fixes the issue.
Thanks for your help!
2 Likes