fury-gl / fury

FURY - Free Unified Rendering in pYthon.
https://fury.gl
Other
230 stars 163 forks source link

WIP: Update snapshot and record #742

Open skoudoro opened 1 year ago

skoudoro commented 1 year ago

This PR update snapshot and record function to allow ShowManager as input argument and deprecate Scene as an input arguments.

Many PR will follow-up to clean our tests and tutorial by forcing the use of ShowManager

196

Garyfallidis commented 1 year ago

It is not just that right? It should be also about resolving some memory management issues.

Garyfallidis commented 1 year ago

Or this is for the next PR?

skoudoro commented 1 year ago

Yes and No @Garyfallidis.

Yes -> it promotes good practice and avoid the memory leak. see below, no memory leak

    t = np.linspace(-10, 10, 100)
    bundle = []
    for i in np.linspace(3, 5, 1000):
        pts = np.vstack((np.cos(2 * t/np.pi), np.zeros(t.shape) + i*10, t )).T
        bundle.append(pts)

   # No memory when show manager outside the loop
    showm = window.ShowManager()
    for time in range(200):   

        ren.scene.clear()
        bundle_actor = actor.streamtube(bundle, window.colors.red, linewidth=0.01)
        showm.scene.add(bundle_actor)
        showm.scene.SetBackground(*window.colors.white)
        image_array = window.snapshot(
            showm, fname='images/file%02d.png' % time, size=(1000, 1000))

No -> the memory leak is from VTK, C++ based, so it will be always there until they fix it. the example below have a memory leak:

    t = np.linspace(-10, 10, 100)
    bundle = []
    for i in np.linspace(3, 5, 1000):
        pts = np.vstack((np.cos(2 * t/np.pi), np.zeros(t.shape) + i*10, t )).T
        bundle.append(pts)

    # ren = window.Scene()
    for time in range(200):  
        # Memory leak here, creation of multiple RenderWindow not well freed by vtk 
        ren = window.ShowManager()
        ren.scene.clear()
        bundle_actor = actor.streamtube(bundle, window.colors.red, linewidth=0.01)
        ren.scene.add(bundle_actor)
        ren.scene.SetBackground(*window.colors.white)
        image_array = window.snapshot(
            ren, fname='images/file%02d.png' % time, size=(1000, 1000))
skoudoro commented 1 year ago

This PR is ready to go @Garyfallidis.

2 PR will follow this PR: Update tests, then update tutorials

Garyfallidis commented 1 year ago

Unfortunately, there are some issues with viz_timer.py in Ubuntu. Happy to zoom. Hard to explain with words here.