vtkSortDataArray sorts keys array


I’ve been using the following method to sort an array of values in the same order as my key array:

static void vtkSortDataArray::Sort(vtkAbstractArray* keys,vtkAbstractArray* values)

My “keys” array is not sorted and the values follow very well the keys values, which is why I find this method so powerful. What I noticed is, if I extract an array from my filter’s input and feed it as the “keys” array, that array also gets sorted and my input ends up being modified, which is not a good thing as of the pipeline paradigm. Here, I am forced to do a DeepCopy of my input array and apply vtkSortDataArray::Sort(…) onto that new array. Is this behaviour normal?

You are doing the right thing by deep copying the arrays. As the docs for the function say, it sorts the values and keys, so to prevent modification of the input, you indeed need to operate on a copy.

Thank you for clarifying, Cory.

Have a great day!

Patrick Laurin

1 Like