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

kenichiro yoshimi rccm.kyoshimi at gmail.com
Wed Jun 20 06:37:57 EDT 2018


Hi Doug,

It may be faster to use a SetExtractionModeToAllRegions method in
vtkConnectivityFilter and then extract each region by vtkThreshold one
by one.

-----
    connect.SetExtractionModeToAllRegions()
    ...

    threshold = vtk.vtkThreshold()
    threshold.SetInputConnection(connect.GetOutputPort())
    threshold.SetInputArrayToProcess(0, 0, 0,
vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS, 'RegionId')

    i = 0
    while True:
        start = timer()
        extractGrid = vtk.vtkUnstructuredGrid()
        threshold.ThresholdBetween(i, i)
        threshold.Update()
        extractGrid.DeepCopy(threshold.GetOutput())
        if extractGrid.GetNumberOfCells() <= 0:
            break
        print(i, extractGrid.GetNumberOfCells())
        mb.SetBlock(i, extractGrid)
        end = timer()
        print("Processed region " + str(i) + " in " + str(end-start) +
"seconds")
        i += 1
-----

Best

2018-06-17 18:44 GMT+09:00 scotsman60 <doug at beachmailing.com>:
> Hello!!!
>
> I am partitioning a single large vtkUnstructuredGrid with around 15 million
> Points and Cells into contiguous cell regions using the
> vtkConnectivityFilter.
>
> I'm using VTK 7.1 with Python 3.6.2
>
> The filter finds around 4,700 regions quite quickly - in about 10 seconds.
>
> But then it takes almost the same amount of time to extract each region into
> it's own grid and add to a MultiBlockDataSet - this is my end goal at the
> moment.
>
> Here is the code,
>
>     def extractConnectedRegions(self):
>         start = timer()
>         connect = vtk.vtkConnectivityFilter()
>         connect.SetInputData(self.mesh)
>         connect.SetExtractionModeToSpecifiedRegions()
>         connect.ColorRegionsOn();
>         connect.Update()
>         num_regions = connect.GetNumberOfExtractedRegions()
>         end = timer()
>         print("Extracted " + str(num_regions) + " regions in " +
> str(end-start) + " seconds")
>
>         self.mb = vtk.vtkMultiBlockDataSet()
>
>         i=0
>         while True:
>             start = timer()
>             extractGrid = vtk.vtkUnstructuredGrid()
>             connect.AddSpecifiedRegion(i)
>             connect.Update()
>             extractGrid.DeepCopy(connect.GetOutput())
>             if extractGrid.GetNumberOfCells() <= 0:
>                 break
>             print(i,extractGrid.GetNumberOfCells())
>             self.mb.SetBlock(i, extractGrid)
>             connect.DeleteSpecifiedRegion(i)
>             end = timer()
>             print("Processed region " + str(i) + " in " + str(end-start) + "
> seconds")
>             i+=1
>
>         return num_regions
>
>
> The output from this fragment is shown below,
>
> Time to add 15811239 points to vtkUnstructuredGrid - 0.19109638981581245
> seconds
> Time to size array for 15685372 elements is 8.62148243552241e-06 seconds
> Time to create connectivity array for 15685372 elements is
> 0.6341917319162356 seconds
> Time to populate vtkUnstructuredGrid with 15685372 cells is
> 1.5787703795422896 seconds
> Extracted 4739 regions in 10.1558246735332 seconds
> 0 1
> Processed region 0 in 7.074993349142119 seconds
> 1 1
> Processed region 1 in 7.067869541369976 seconds
> 2 1
> Processed region 2 in 6.956592478126069 seconds
> 3 1
> Processed region 3 in 6.968502850836856 seconds
>
>
> I have to believe that there's a more efficient way to do this than the one
> I'm using, but I haven't been able to find one.
>
> Any suggestions, hints or solutions will be gratefully appreciated.
>
> Doug
>
>
>
>
>
> --
> Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://public.kitware.com/mailman/listinfo/vtkusers


More information about the vtkusers mailing list