UnstructuredGrid::GetCellLinks() get null value after I upgrade from 8.2 to 9.4

As described in the title, I am upgrading from 8.2 to 9.4, all works fine in the codebase of 8.2, which I have the following:

mesh is type of vtkPointSet *, which is argument in the method.

vtkUnstructuredGrid * grid = vtkUnstructuredGrid::SafeDownCast(mesh);
vtkCellLinks * links = nullptr;
if (grid != nullptr)
{
    links = vtkCellLinks::SafeDownCast(grid->GetCellLinks());
}

in 8.2, links get the real contents.
but in 9.4, links get null.

I have read the document that GetCellLinks() is deprecated. So I changed to GetLinks() directly.

vtkAbstractCellLinks *links = grid->GetLinks();

This has the real address value. But when I downcast to vtkCellLinks, it still returns null value.

What is possible cause of this issue? Thanks.

Hello,

From what I understand from the docs, in VTK 9.4 you, first, use GetLinks()‘s returned vtkAbstractCellLinks’ (do not downcast) GetType() method to query its concrete data type (the six constants below are defined in vtkAbstractCellLinks::CellLinksTypes enum VTK: vtkAbstractCellLinks Class Reference):

  • LINKS_NOT_DEFINED (0): is a nullptr;
  • CELL_LINKS (1): is a vtkCellLinks;
  • STATIC_CELL_LINKS_USHORT (2): is a vtkStaticCellLinksTemplate<VTK_UNSIGNED_SHORT>;
  • STATIC_CELL_LINKS_UINT (3): is a vtkStaticCellLinksTemplate<VTK_UNSIGNED_INT>;
  • STATIC_CELL_LINKS_IDTYPE (4): is a vtkStaticCellLinksTemplate<VTK_ID_TYPE>;
  • STATIC_CELL_LINKS_SPECIALIZED (5): dunno what this is (docs are unclear, likely to be a vtkStaticCellLinks);

Reference: VTK: vtkUnstructuredGrid Class Reference

Then you can use, for instance, a switch(){} structure to use the appropriate downcast.

best,

PC

Thanks Paulo.

That’s right. Previously in 8.2, I can directly use GetCellLinks() and get the Link internal type inside it, then query the cell size and the cell list.

Now after the upgrade, I need check which type of the link it is. And now I have used the type condition check to get the correct value.

I just wonder why in previous 8.2, I get the links data with the type of CellLinks, while on the contrary the links changed to be the type of Static Cell Links in 9.4 version. I have not delved into the code changes in 9.4. The value of Links type is changed, is that caused by the design change of data storage? Maybe I need to debug into the implementation of new vtk codes.

You still have the original vtkCellLinks as one of the available options. The reason for the new design is in the docs (VTK: vtkStaticCellLinksTemplate< TIds > Class Template Reference):

This class is a faster implementation of vtkCellLinks. However, it cannot be incrementally constructed; it is meant to be constructed once (statically) and must be rebuilt if the cells change.

This is a templated implementation for vtkStaticCellLinks. The reason for the templating is to gain performance and reduce memory by using smaller integral types to represent ids. For example, if the maximum id can be represented by an int (as compared to a vtkIdType), it is possible to reduce memory requirements by half and increase performance. This templated class can be used directly; alternatively the non-templated class vtkStaticCellLinks can be used for convenience; although it uses vtkIdType and so will lose some speed and memory advantages.

best,

PC

Yes. got it.

Thanks.