vtkExtractSelection evolutions between VTK 8.90 and 9.3

Good morning,

My organization recently upgraded from Paraview 5.8 to Paraview 5.12 and it appears that some Python scripts require adaptations.

One of these scripts uses the vtkExtractSelection filter and shows different behavior with the latest version of Paraview/VTK.

Here is an example showing this difference:

# -*- coding: utf-8 -*-

import vtk
print(f"VTK : {vtk.VTK_VERSION}")

path_in = r"testcase.vtk"

# Read test data
vf = vtk.vtkUnstructuredGridReader()
vf.SetFileName(path_in)
vf.Update()
obj_src = vf.GetOutput()

# define a selection to select all cells : select None and inverse selection
selectionNode = vtk.vtkSelectionNode()
selectionNode.SetFieldType(selectionNode.CELL)
selectionNode.SetContentType(selectionNode.INDICES)
ids = vtk.vtkIdTypeArray()
ids.SetNumberOfComponents(1)
selectionNode.SetSelectionList(ids)
selectionNode.GetProperties().Set(vtk.vtkSelectionNode.INVERSE(), 1)

selection = vtk.vtkSelection()
selection.AddNode(selectionNode)

# Extract selection
extractSelection = vtk.vtkExtractSelection()
extractSelection.SetInputDataObject(obj_src)
extractSelection.SetInputData(1, selection)
extractSelection.Update()

obj_res = extractSelection.GetOutput()

# print debug info

def strdbg(obj):
    """get debug short debug info"""
    pData = obj.GetPointData()
    pArr = [] if pData is None else [ pData.GetArrayName(ii) for ii in range(pData.GetNumberOfArrays()) ]

    cData = obj.GetCellData()
    cArr = [] if cData is None else [ cData.GetArrayName(ii) for ii in range(cData.GetNumberOfArrays()) ]    

    return f"{obj.__class__.__name__}({obj.GetNumberOfPoints()} node : {pArr}, {obj.GetNumberOfCells()} cell: {cArr})"

print("obj_src", strdbg(obj_src))
print("obj_res", strdbg(obj_res))

This script aims to select all the points attached to a cell.

Here is content of the testcase.vtk file used in the example:

# vtk DataFile Version 2.0
Simple test case
ASCII
DATASET UNSTRUCTURED_GRID

POINTS 11 float
-2  -2  0
-1   0  0
-3   0  0
-2   2  0
 1   0  0
 0   2  0
 2  -2  0
 2   2  0
 3   0  0
 0  -2  0
 0   4  0

CELLS 7 28
3 0 1 2
3 2 1 3
3 3 1 5
3 5 1 4
3 5 4 7
3 7 4 8
3 8 4 6

CELL_TYPES 7
5
5
5
5
5
5
5

POINT_DATA 11

SCALARS NData float 1
LOOKUP_TABLE default
0
0
1
1
0
1
0
1
1
-1
3

In this example file, there are two points that are not attached to any cells and should not be selected.

With Paraview 5.8.1, I get the following results:

VTK: 8.90.0
obj_src vtkUnstructuredGrid (11 nodes: ['NData'], 7 cells: [])
obj_res vtkUnstructuredGrid (9 nodes: ['NData', 'vtkOriginalPointIds'], 7 cells: ['vtkOriginalCellIds'])

With Paraview 5.12.1:

VTK: 9.3.20231030
obj_src vtkUnstructuredGrid (11 nodes: ['NData', 'vtkOriginalPointIds'], 7 cells: ['vtkOriginalCellIds'])
obj_res vtkUnstructuredGrid (11 nodes: ['NData', 'vtkOriginalPointIds'], 7 cells: ['vtkOriginalCellIds'])

With the latest version of Paraview, obj_res contains 11 points instead of 9.

It seems that there have been changes in VTK regarding how to select entities between vtk 8.90 and 9.3.

Does anyone know how to adapt this script to select only points attached to a cell and get the old behavior back?

Regards,