Equivalent of const vtkIdType *& in python?

I’m trying to use the GetFaceToAdjacentFaces method but I don’t know what argument I need to pass, I’ve read the docs and I should pass a ‘const vtkIdType *&’ but I don’t know how to do this in python.
Code:

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, )

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

# 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:

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

>>> 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.

1 Like

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

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?

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.