# ITK python itkMeshF3\_Pointer

**URL:** https://discourse.itk.org/t/itk-python-itkmeshf3-pointer/3061
**Category:** Beginner Questions
**Created:** [May 12, 2020, 9:13pm UTC](https://discourse.itk.org/t/itk-python-itkmeshf3-pointer/3061 "2020-05-12T21:13:07Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![cg2](https://discourse.itk.org/user_avatar/discourse.itk.org/cg2/32/1298_2.png) [@cg2](https://discourse.itk.org/u/cg2)
#### Post date: [May 12, 2020, 9:13pm UTC](https://discourse.itk.org/t/itk-python-itkmeshf3-pointer/3061/1 "2020-05-12T21:13:08Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [May 14, 2020, 2:20am UTC](https://discourse.itk.org/t/itk-python-itkmeshf3-pointer/3061/2 "2020-05-14T02:20:23Z")

</div>

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:

```auto
import itk
itk.MeshFileReader.GetTypes()

```

And the convenient way to load files in ITK 5.1.0 without type specification is:

```auto
mesh = itk.meshread('mesh_filename.off')

```

---

<div class="post-metadata">

### Author: ![cg2](https://discourse.itk.org/user_avatar/discourse.itk.org/cg2/32/1298_2.png) [@cg2](https://discourse.itk.org/u/cg2)
#### Post date: [May 14, 2020, 2:33pm UTC](https://discourse.itk.org/t/itk-python-itkmeshf3-pointer/3061/3 "2020-05-14T14:33:17Z")

</div>

@matt.mccormick Thanks for your help.

Here the result of `itk.MeshFileReader.GetTypes()` :

```auto
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:

```auto
>>> 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

```auto
mesh_ptr = itkMeshF3_Pointer(itk.meshread(fixed_filename))

```

given that my generated interface seems to expect itkMeshF3\_Pointer?

Thanks again,

Charles

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [May 14, 2020, 2:43pm UTC](https://discourse.itk.org/t/itk-python-itkmeshf3-pointer/3061/4 "2020-05-14T14:43:43Z")

</div>

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:

```auto
mesh = itk.meshread(fixed_filename, itk.F)

```

---

<div class="post-metadata">

### Author: ![cg2](https://discourse.itk.org/user_avatar/discourse.itk.org/cg2/32/1298_2.png) [@cg2](https://discourse.itk.org/u/cg2)
#### Post date: [May 14, 2020, 4:48pm UTC](https://discourse.itk.org/t/itk-python-itkmeshf3-pointer/3061/5 "2020-05-14T16:48:18Z")

</div>

> [@cg2](#):
>
> mesh\_ptr = itkMeshF3\_Pointer(itk.meshread(fixed\_filename))

This works, thanks. Though, I’m still not able to convert it to `itkMeshF3_Pointer` 😕

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [May 14, 2020, 5:26pm UTC](https://discourse.itk.org/t/itk-python-itkmeshf3-pointer/3061/6 "2020-05-14T17:26:05Z")

</div>

> [@cg2](#):
>
> `itkMeshF3_Pointer`

That is the equivalent of the result – pointers are not handled directly in Python.

---

<div class="post-metadata">

### Author: ![cg2](https://discourse.itk.org/user_avatar/discourse.itk.org/cg2/32/1298_2.png) [@cg2](https://discourse.itk.org/u/cg2)
#### Post date: [May 14, 2020, 5:43pm UTC](https://discourse.itk.org/t/itk-python-itkmeshf3-pointer/3061/7 "2020-05-14T17:43:07Z")

</div>

Indeed… Updating my interface to take pointer instead of smart pointer fixes the issue.

Thanks for your help!
