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.
reader = vtk.vtkXMLUnstructuredGridReader()
output = reader.GetOutput()
for i in range(output.GetNumberOfCells()):
cell = output.GetCell(i) # hexaedron
for face_index in range(cell.GetNumberOfFaces()):
const vtkIdType *&’ is handled with the vtk-python
# create a tuple reference
faces = vtk.reference(())
# call the method
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)
Compare this to the
vtkCellArray.GetCell() method, which does have wrapper hints:
>>> a = vtk.vtkCellArray()
>>> a.InsertNextCell(3, (0,1,2))
>>> n = vtk.reference(0) # create an int reference
>>> t = vtk.reference(()) # create a tuple reference
>>> a.GetCell(0, n, t)
vtkmodules.vtkCommonCore.tuple_reference((0, 1, 2))
So to make a long story short, the
GetFaceToAdjacentFaces() method is unusable from Python.
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])
(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
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.