# Equivalent of const vtkIdType \*& in python?

**URL:** https://discourse.vtk.org/t/equivalent-of-const-vtkidtype-in-python/9298
**Category:** Support
**Tags:** python
**Created:** [September 8, 2022, 7:29pm UTC](https://discourse.vtk.org/t/equivalent-of-const-vtkidtype-in-python/9298 "2022-09-08T19:29:14Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Unique](https://discourse.vtk.org/user_avatar/discourse.vtk.org/unique/32/5745_2.png) [@Unique](https://discourse.vtk.org/u/Unique)
#### Post date: [September 8, 2022, 7:29pm UTC](https://discourse.vtk.org/t/equivalent-of-const-vtkidtype-in-python/9298/1 "2022-09-08T19:29:14Z")

</div>

I’m trying to use the GetFaceToAdjacentFaces method but I don’t know what argument I need to pass, I’ve read the [docs](https://vtk.org/doc/nightly/html/classvtkCell3D.html#a8a0c338524621fdb8411ed53b770fa9d) and I should pass a ‘const vtkIdType \*&’ but I don’t know how to do this in python.  
**Code:**

```auto
reader = vtk.vtkXMLUnstructuredGridReader()
reader.SetFileName(file_name)
reader.Update()
output = reader.GetOutput()

for i in range(output.GetNumberOfCells()):
    cell = output.GetCell(i) # hexaedron
    for face_index in range(cell.GetNumberOfFaces()):
        cell.GetFaceToAdjacentFaces(face_index, )

```

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [September 9, 2022, 5:02pm UTC](https://discourse.vtk.org/t/equivalent-of-const-vtkidtype-in-python/9298/2 "2022-09-09T17:02:09Z")

</div>

Usually ‘`const vtkIdType *&`’ is handled with the vtk-python `reference` type.

```python
# create a tuple reference
faces = vtk.reference(())
# call the method
cell.GetFaceToAdjacentFaces(face_index, faces)

```

However, in order for the wrappers to properly deal with ‘`const vtkIdType *&`’, they also need a wrapper hint that specifies the size of the tuple. Since the `GetFaceToAdjacentFaces()` method has no wrapper hint, it always gives an empty tuple:

```python
>>> faces = vtk.reference(())
>>> cell.GetFaceToAdjacentFaces(0, faces)
4
>>> faces
vtkmodules.vtkCommonCore.tuple_reference(())

```

Compare this to the `vtkCellArray.GetCell()` method, which does have wrapper hints:

```python
>>> a = vtk.vtkCellArray()
>>> a.InsertNextCell(3, (0,1,2))
0
>>> n = vtk.reference(0) # create an int reference
>>> t = vtk.reference(()) # create a tuple reference
>>> a.GetCell(0, n, t)
>>> n
vtkmodules.vtkCommonCore.number_reference(3)
>>> t
vtkmodules.vtkCommonCore.tuple_reference((0, 1, 2))

```

So to make a long story short, the `GetFaceToAdjacentFaces()` method is unusable from Python.

---

<div class="post-metadata">

### Author: ![Unique](https://discourse.vtk.org/user_avatar/discourse.vtk.org/unique/32/5745_2.png) [@Unique](https://discourse.vtk.org/u/Unique)
#### Post date: [September 9, 2022, 6:46pm UTC](https://discourse.vtk.org/t/equivalent-of-const-vtkidtype-in-python/9298/3 "2022-09-09T18:46:10Z")

</div>

Thanks for your precise answer, anyway I have a doubt, I noticed that if I write something like

```auto
faces = vtk.reference([0,0,0,0,0,0])
cell.GetFaceToAdjacentFaces(0,faces)
print(faces)

```

It print: `(4, 2, 5, 3, 4, 3)`. Aren’t these numbers the ids of the adjacent faces or they are just pseudo-random? What these numbers mean?

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [September 9, 2022, 8:17pm UTC](https://discourse.vtk.org/t/equivalent-of-const-vtkidtype-in-python/9298/4 "2022-09-09T20:17:50Z")

</div>

Some of the numbers will be correct. For example, if `cell.GetFaceToAdjacentFaces(0,faces)` returns `4`, then the first 4 values will be accurate and the rest will be whatever was at the memory locations beyond those 4 values. In the worst case you might see a segfault if it goes past the end of an allocated memory block.

That’s why we ideally want a hint, to make sure that the wrappers will always copy the correct number of values from C++ to Python.
