Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-compute final color image and render only once #22

Closed
tyarkoni opened this issue Aug 6, 2015 · 3 comments
Closed

Pre-compute final color image and render only once #22

tyarkoni opened this issue Aug 6, 2015 · 3 comments

Comments

@tyarkoni
Copy link
Contributor

tyarkoni commented Aug 6, 2015

At the moment, all visible layers are independently painted to the canvas, which is hugely inefficient. Instead, we should loop once over all voxels, compute the final color image in memory, then blit to the canvas just once. This should take us from linear time in the number of layers to close to constant time, since profiling suggests that nearly all of the time is currently taken up by the painting operation.

@tyarkoni tyarkoni added this to the first official release milestone Aug 6, 2015
@njvack
Copy link
Contributor

njvack commented Aug 7, 2015

I think it might be saner, actually, to keep each layer in an offscreen canvas and then composite them at the end. Blitting canvases over each other is very fast.

One other optimization that might help would be to draw all the layers as individual pixels and then use the canvas transformation to scale the image when rendering. This would also let us get rid of the pixel overlap.

I looked into doing this a while ago; I need to see where I put my code experiments...

@tyarkoni
Copy link
Contributor Author

tyarkoni commented Aug 7, 2015

I actually have the alpha compositing 95% done now, and it's much faster (scrolls seamlessly through the brain with ~10 layers), so I'll probably stick with this approach. I also switched to ndarrays, and while performance is not noticeably better, the code is much cleaner--we can do nice matrix operations with ndarray-ops. I suspect using multiple canvases would be slower, because we'd still have the extra overhead of painting to off-screen canvases, even if that's much faster than to the on-screen canvas.

The scaling optimization is an interesting idea! Let's see where we are in a couple of days once I merge these changes.

@tyarkoni
Copy link
Contributor Author

tyarkoni commented Aug 8, 2015

Closed in #23.

@tyarkoni tyarkoni closed this as completed Aug 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants