Run OpenGL 2D graphics in R to quickly display a bitmap using qtpaint (qt) or rdyncall (SDL / OpenGL) packages?

In the Mandelbrot interactive viewer that I did in real time, I did in R and Rcpp + OpenMP and Shiny. I'm in search of a powerful way to display 1920x1080 matrices as bitmaps in the hope that you can achieve approx. 5-10 fps (the calculation of the Mandelbrot images themselves reaches 20-30 frames per second at moderate scales , and, of course, scrolling should go quickly). Using image() with the option useRaster=TRUE , plot.raster or even grid.raster() still doesn't quite shorten it, so I'm looking for a more efficient option, ideally using OpenGL acceleration.

I noticed that there are qt packages of the qtutils and qtpaint http://finzi.psych.upenn.edu/R/library/qtutils/html/sceneDevice.html where you can set the argument opengl=TRUE and http: //finzi.psych .upenn.edu / R / library / qtpaint / html / qplotView.html again with the argument opengl=TRUE and http://finzi.psych.upenn.edu/R/library/qtpaint/html/painting.html .

And I also noticed that you need to be able to call the SDL and GL / OpenGL functions using the rdyncall package (install from https://cran.r-project.org/src/contrib/Archive/rdyncall/ and SDL from https: // www.libsdl.org/download-1.2.php ) `, demos are available at http://hg.dyncall.org/pub/dyncall/bindings/file/87fd9f34eaa0/R/rdyncall/demo/00Index , e.g. http: // hg.dyncall.org/pub/dyncall/bindings/file/87fd9f34eaa0/R/rdyncall/demo/randomfield.R ).

I am correcting that with these packages you should be able to display a 2D raster image using opengl acceleration? If so, does anyone have thoughts on how to do this (I ask because I'm not an expert in qt or SDL / OpenGL )?

Some timings of parameters other than OpenGL that are too slow for my application:

 # some example data & desired colour mapping of [0-1] ranged data matrix library(RColorBrewer) ncol=1080 cols=colorRampPalette(RColorBrewer::brewer.pal(11, "RdYlBu"))(ncol) colfun=colorRamp(RColorBrewer::brewer.pal(11, "RdYlBu")) col = rgb(colfun(seq(0,1, length.out = ncol)), max = 255) mat=matrix(seq(1:1080)/1080,nrow=1920,ncol=1080,byrow=TRUE) mat2rast = function(mat, col) { idx = findInterval(mat, seq(0, 1, length.out = length(col))) colors = col[idx] rastmat = t(matrix(colors, ncol = ncol(mat), nrow = nrow(mat), byrow = TRUE)) class(rastmat) = "raster" return(rastmat) } system.time(mat2rast(mat, col)) # 0.24s # plot.raster method - one of the best? par(mar=c(0, 0, 0, 0)) system.time(plot(mat2rast(mat, col), asp=NA)) # 0.26s # grid graphics - tie with plot.raster? library(grid) system.time(grid.raster(mat2rast(mat, col),interpolate=FALSE)) # 0.28s # base R image() par(mar=c(0, 0, 0, 0)) system.time(image(mat,axes=FALSE,useRaster=TRUE,col=cols)) # 0.74s # note Y is flipped to compared to 2 options above - but not so important as I can fill matrix the way I want # magick - browser viewer, so no good.... # library(magick) # image_read(mat2rast(mat, col)) # imager - doesn't plot in base R graphics device, so this one won't work together with Shiny # If you wouldn't have to press ESC to return control to R this # might have some potential though... library(imager) display(as.cimg(mat2rast(mat, col))) # ggplot2 - just for the record... df=expand.grid(y=1:1080,x=1:1920) df$z=seq(1,1080)/1080 library(ggplot2) system.time({q <- qplot(data=df,x=x,y=y,fill=z,geom="raster") + scale_x_continuous(expand = c(0,0)) + scale_y_continuous(expand = c(0,0)) + scale_fill_gradientn(colours = cols) + theme_void() + theme(legend.position="none"); print(q)}) # 11s 
+8
r qt graphics sdl opengl
source share

No one has answered this question yet.

See similar questions:

4
Multithreaded and SIMD-vectorized Mandelbrot in R using Rcpp & OpenMP

or similar:

31
Why are SDL and OpenGL related?
27
Display SVG in OpenGL without an intermediate raster
2
OpenGL window with SDL not displaying
2
Some thoughts on SDL + Qt + OpenGL for the game engine
one
OpenGL SDL Problem
one
Using SDL, OpenGL, and Qt Together
0
Problem with openGL SDL, no openGL drawing
0
SDL Software Rendering VS. OpenGL: compatibility and performance
0
Properly disabling SDL with OpenGL
0
Problem with displaying OpenGL SDL texture

All Articles