question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

render new volume on same plot

See original GitHub issue

Hi all,

I would like to use vedo for volumetric rendering, but I would like to update the plot with a new volume render based off a slider value input. So, as the slider is moved, a new volume is rendered and displayed. Idea looks like this:

from vedo.pyplot import plot, histogram, show
from vedo import Volume, buildLUT, Plotter
import numpy as np
import nibabel as nib
import vtk
from vtk.util.numpy_support import vtk_to_numpy
import time
import vedo
import torch

# create slider
def slider1(widget, event):
    
    # get slider value
    value = widget.GetRepresentation().GetValue()
    value = value/100

    # linear interpolate between the two coords
    z = z_0*value + z_1*(1-value)

    # run interpolation
    moved = decodeZ(z, moving, model)

    # create the volume 
    vol = Volume(moved, c=bodyColors,  mapper='fixed')
    vol.mapper().SetClippingPlanes(planes)

    # plot
    plt.show(vol, interactive=False, camera=cam2, bg='black')

# initialize volume
vol = Volume(img, c=bodyColors,  mapper='fixed')
vol.mapper().SetClippingPlanes(planes)

# add slider
plt.addSlider2D(slider1, 0, 100, value=0,
            pos="bottom-right", title="Interpolate", c='blue')

plt.show(vol, interactive=True, camera=cam2, bg='black')

However, when the slider is moved, this gives the following error:

Traceback (most recent call last):
  File "volMotion.py", line 138, in slider1
    plt.show(vol, interactive=False, camera=cam2, bg='black')
  File "/home/savjani/anaconda3/lib/python3.8/site-packages/vedo/plotter.py", line 2354, in show
    self.allowInteraction()
  File "/home/savjani/anaconda3/lib/python3.8/site-packages/vedo/plotter.py", line 778, in allowInteraction
    self.interactor.DestroyTimer(self._repeatingtimer_id)
TypeError: DestroyTimer argument 1: an integer is required (got type NoneType)

There is likely a better way to update the plt with the new rendered volume, right? Thanks!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
marcomusycommented, Sep 21, 2021

From the next release you’ll be able to do simply:

plt.addSlider2D(slider1, 0, 10, value=5, title="Interpolate", c='blue7', delayed=True)
1reaction
rsavjanimdphdcommented, Sep 21, 2021

@marcomusy - amazing, thank you so much! This is exactly what I was looking for.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Volume rendering - 3D Slicer documentation - Read the Docs
Render different volumes in two views¶ · Go to Volume Rendering module · Open the “Inputs” section · Select the first volume ·...
Read more >
Render two volumes simultaneously by blending them using ...
My goal is to blend two different scalar volumes of same size and spacing and display them using image plane widget. I have...
Read more >
Visit-tutorial-Volume-Rendering - VisItusers.org
The Volume plot uses a visualization technique known as volume-rendering, which assigns color and opacity values to a range of data values.
Read more >
3d volume plots in Python - Plotly
A volume plot with go.Volume shows several partially transparent isosurfaces for volume rendering. The API of go.Volume is close to the one of...
Read more >
Volume rendering Feature - AtomicusChart©
Volume rendering is a set of data visualization techniques used for viewing and analyzing computer graphics and scientific data. Generally, volume rendering ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found