Memory continuously increasing when using IntersectWithLine from any vtkAbstractCellLocator implementation in a loop inside a python filter plugin


I am trying to use one of the vtkAbstractCellLocator implementation, especially vtkModifiedBSPTree since it appears much faster than others, to do some kind of raytracing in a python plugin.

The main idea is basically shadow computation, so following a point object and using two inputs, one for my ground mesh (vtkUnstructuredGrid) and another one for my buildings (vtkPolyData) and do some statistics with this (so no need to handle timesteps and also no need to know the intersection point).

The plugin work nicely (and the python plugin interface is really nice by the way and much better than programmableFilter I used to use !) but I am having an issue with memory usage.

Here is an simple example reproducing (at least on my computer) my problem. I simplified to one input and two simple loop reproducing my script (i loop for point object, k loop for mesh points)

from paraview.util.vtkAlgorithm import *
import vtk
import paraview.benchmark as bm

@smproperty.input(name="InputSurfaces", port_index=0)
@smdomain.datatype(dataTypes=["vtkPolyData"], composite_data_supported=False)
class TestFilter(VTKPythonAlgorithmBase):
    def __init__(self):
        VTKPythonAlgorithmBase.__init__(self, nInputPorts=1, nOutputPorts=1, outputType="vtkPolyData")
    def FillInputPortInformation(self, port, info):
        if port == 0:
            info.Set(self.INPUT_REQUIRED_DATA_TYPE(), "vtkPolyData")
    def RequestData(self, request, inInfoVec, outInfoVec):
        from vtkmodules.vtkCommonDataModel import vtkUnstructuredGrid, vtkPolyData
        input0 = vtkPolyData.GetData(inInfoVec[0], 0)
        output = vtkPolyData.GetData(outInfoVec, 0)

surface = vtk.vtkDataSetSurfaceFilter()

bspTree = vtk.vtkModifiedBSPTree()

tol = 0.1
t = vtk.reference(0.0)
x = [0.0,0.0,0.0]
pcoords = [0.0,0.0,0.0]
subId = vtk.reference(0)

for i in range(0,100):
    print i, bm.logbase.get_memuse()
    ray = [1.0,1.0,1.0]
    for k in range(0,1000000):
      pstart = [0.0,0.0,0.0]
      pend = (pstart[0]+ray[0]*100000,pstart[1]+ray[1]*100000,pstart[2]+ray[2]*100000)
      hit = 1 - bspTree.IntersectWithLine(pstart,pend,tol,t,x,pcoords,subId)

return 1

I can clearly see memory consumption increasing steadily inside the i loop (via logbase or my system manager) whereas in my mind it should not.

I am kind of lost about the Python wrapper stuff and the implication it might have so I was wondering if someone would have any idea as to why this is happening.

Am I doing something wrong or maybe vtkModifiedBSPTree (or other vtkAbstractCellLocator implementations) is storing some informations each time I call IntersectWithLine ? If so, is there any way to avoid this ?

I am using the ParaView-5.6.0-MPI-Linux-64bit (Nov 7) binaries available on paraview website.

My OS is openSUSE Leap 42.3

Thanks !

1 Like