[vtkusers] Horrible performance partitioning an UnstructuredGrid into connected regions with vtkConnectivityFilter

scotsman60 doug at beachmailing.com
Wed Jun 20 08:14:44 EDT 2018


kenichiro yoshimi wrote
> Hi Doug,
> 
> It may be faster to use a SetExtractionModeToAllRegions method in
> vtkConnectivityFilter and then extract each region by vtkThreshold one
> by one.
> 
> -

Kenichiro,

Since my original post I had actually tried what you suggested and the
extraction time came down to 2.5 seconds per region. I got even better
performance using the selection method -  vtkSelection, vtkSelectionNode and
vtkExtactSelection brought it down to 0.6 seconds per extracted region. 

But with almost 5,000 regions to extract that's still too slow. So my latest
strategy is to use the vtkConnectivityFilter to find the regions - if you
use SetExtractionModeToAllRegionsusing this causes a Scalar array of
RegionIds to be added to the UG. I'm planning to use that array to process
the original cell data that I have in a series of numpy arrays (one per cell
type) so that I can simply create each region as a new UG and the throw away
the original UG. Basically I'm betting that numpy manipulation is faster
than extracting and copying using UG methods...... We'll see how that works
out.....

For reference, here's the code for the selection method. It took a little
while to understand how the classes work together, but in the end it works
quite well - jut too slow for my needs.....


    def extractConnectedRegions2(self):
        
        num_cell_arrays = self.mesh.GetCellData().GetNumberOfArrays()
        start = timer()
        connect = vtk.vtkConnectivityFilter() 
        connect.SetInputData(self.mesh)
        connect.SetExtractionModeToAllRegions()
        connect.ColorRegionsOn();
        connect.Update() 
        num_regions = connect.GetNumberOfExtractedRegions()
        end = timer()
        print("Extracted " + str(num_regions) + " regions in " +
str(end-start) + " seconds")

        start = timer()

        self.extractGrid = vtk.vtkUnstructuredGrid()
        self.extractGrid.DeepCopy(connect.GetOutput())      

        end = timer()
        print("Deep copied in " + str(end-start) + " seconds")
               
        selectionNode =vtk.vtkSelectionNode()
        selectionNode.SetFieldType(vtk.vtkSelectionNode.CELL)
        selectionNode.SetContentType(vtk.vtkSelectionNode.VALUES)
 
        selection = vtk.vtkSelection()
        selection.AddNode(selectionNode)
 
        extract_selection = vtk.vtkExtractSelection()
        extract_selection.SetInputData(0, self.extractGrid)        
        extract_selection.SetInputData(1, selection)        

        self.mb = vtk.vtkMultiBlockDataSet()

        for i in range(num_regions):
            start = timer()
            ids = vtk.vtkIntArray()
            ids.InsertNextValue(i)
            ids.SetName("RegionId")
            selectionNode.SetSelectionList(ids)
            val = ids.GetValue(0)
            
            extract_selection.Update()   
            leaf = vtk.vtkUnstructuredGrid()
            leaf.DeepCopy(extract_selection.GetOutput())     
            self.mb.SetBlock(i, leaf)
            end = timer()
            
            print("Processed region " + str(i) + " in " + str(end-start) + "
seconds")
            
       
        return num_regions 



Here's the timing info from the above

Deep copied in 0.46751967130063576 seconds
Processed region 0 in 0.7530222326956988 seconds
Processed region 1 in 0.6797586976174443 seconds
Processed region 2 in 0.6042322342475757 seconds
Processed region 3 in 0.6011810580749852 seconds
Processed region 4 in 0.5983285860557288 seconds
Processed region 5 in 0.604301616482914 seconds
Processed region 6 in 0.6362392036725879 seconds
Processed region 7 in 0.6126373378241681 seconds






--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html


More information about the vtkusers mailing list