Closed riccardomarin closed 4 years ago
Hi Riccardo,
Not in the present code. But this could be an interesting option. I am just finishing v0.11 so it needs to wait for v0.12 - in the meantime: how would you use it? training input to some ML shadow estimator?
& 3. Use NpOptiX instead of TkOptiX class, and set callback to launch code when accumulation is finished. This should work:
import numpy as np
from plotoptix import NpOptiX
def save_image(rt: NpOptiX) -> None:
rt.save_image("out.png")
print("job done")
n = 10000
xyz = 3 * (np.random.random((n, 3)) - 0.5)
r = 0.2 * np.random.random(n) + 0.002
rt = NpOptiX(on_rt_accum_done=save_image, width=600, height=600)
rt.set_param(min_accumulation_step=50, max_accumulation_frames=50)
rt.set_ambient(0.9);
rt.set_data("plot", xyz, r=r, c=0.9)
rt.start()
min_accumulation_step==max_accumulation_frames
is a good idea in this case since any postprocessing will be done only once.
Rendering is running in a background thread, so you may need to write some synchronization. If you are making a series of images with the modified scene (like for an animation) then all can be done with callbacks. Have a look at these examples.
Thanks for your reply:
I need to render models with shadow and a white background to crop it easily and to include them into documents. It is common in scientific papers to avoid clutters, to make the size smaller possible, and to have a coherence with the document background.
Awesome for the NpOptiX and the callback: they solved my other issues :D
OK, now I understand. That kind of plane will just need another material shader - much more simple than I thought at the beginning.
So, I have this kind of effect with two lights and a little of blue ambient light. White plane that receives shadows is made of the new material that I'll add to the next release:
Hi, The new release finally is ready on PyPI. There is also a short sample code that configures the new material. Enjoy and thanks for the idea!
Hi @robertsulej ,
first of all: Great project and I see a lot of potential, especially in scientific visualization!
Is there some example code that shows how to do this:
Rendering is running in a background thread, so you may need to write some synchronization.
Specifically, I'm asking for a way to close/stop the NpOptiX instance after the accumulation is finished. I don't necessarily want to exit the script, but resume execution and possibly use the rendered result after that. Essentially something like this (note, I'm not using notebooks but this should be part of a larger script):
def accum_done(rt):
# TODO: Code that contributes to synchronization (?)
optix = NpOptiX(on_rt_accum_done=accum_done)
optix.start()
# TODO: Synchronize here!
optix.close()
# Use optix._img_rgba here
Changing any captured variables in accum_done
doesn't seem to have an effect globally (I assume because of the threads) and I cannot call rt.close()
directly. Any suggestion? Am I missing something?
Hi @mworchel ,
I'll post a sample code (~Saturday). Everything is in place, just need a moment to prepare a clear example :)
That would be awesome! Thank you so much in advance. I'm curious to see the solution.
Hi Markus,
The example is here.
Variables in class params
are visible from the callback and from the main()
function. Events are probably the easiest way to signal between threads. I'll also add a similar sample but with an animation to show code using more callbacks.
Hi Robert,
thank you so much! So it basically just required built-in synchronization structures (I wasn't very familiar with these).
I think it's going to be super helpful!
Hi, I have three questions:
1) I was wondering if at the moment there is a way to have a Shadow catcher surface, i.e. a plane that shows only the shadows but fully transparent to have infinite scenes. 2) There is a way to do not show the rendering window, i.e. to do the image rendering in "background"? 3) There is a way to save the figure when the "max_accumulation_frames" has been reached? I tried to set the min_accumulation_step == max_accumulation_frames, but it does not work (it saves a black image). The only trick I was able to figure out was an infinite while loop that wait for no more changes in the rendering process:
Thanks!