[vtk-developers] vtkSortDataArray

Will Schroeder will.schroeder at kitware.com
Mon Jan 4 12:57:39 EST 2016


A quick note on a potentially powerful but likely overlooked capability
relative to sorting data in VTK. This is available from a recent merge.

vtkSortDataArray has been revamped, a lot of what you'd expect: removed a
static variable so it's thread-safe, significant code cleanup; new tests;
uses std::sort instead of older C-based homegrown stuff; uses
vtkSMPTools::Sort(),  so when the build is configured appropriately you'll
see faster performance, etc.

The interesting bit is that sorting has been broken out into separate
steps. An initial sort creates a permutation / sort index of vtkIdType that
indicates where the data ends up (after the sort). This sorting index can
then be used to shuffle any associated data around, or the sort index can
be queried to perform additional analysis on the data.

Practically this means you can use any component of a tuple in a data array
to generate a sort index. So for example, if you want to find the top N
points with lowest/greatest scalar value; or the cells with largest
z-velocity component; etc. it is quite easy to do. Look at
Common/Core/Testing/Cxx/TestSortDataArray.cxx. I also thought about
creating an extraction filter to sort, extract, and/or reorder cells/points
based on data value; this is down on my todo list....

There is also a new, related class vtkSortFieldData that enables you to
simultaneously sort all the arrays contained in subclasses of vtkFieldData
(e.g., vtkPointData and vtkCellData).

Have fun and as always let me know if there are issues, concerns, or
improvements to be made.

Best,
W
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20160104/5ea24c5e/attachment.html>


More information about the vtk-developers mailing list