使用无头显示的rgl

时间:2016-05-30 08:42:21

标签: r shell xvfb rgl

我安装了Xfvb并实例化了一个显示实例:

$ Xvfb :2 -screen 0 1280x960x24 &

然后我分别从源代码安装了R 3.2.5和rgl 0.95.1441,并在端口2上打开了与DISPLAY的连接。然后我尝试使用一些基本的rgl例程运行测试rgl会话:

$ DISPLAY=:2 /usr/local/bin/R
R version 3.2.5 (2016-04-14) -- "Very, Very Secure Dishes"
...
> library(rgl)
> open3d()
> x <- sort(rnorm(1000))
> y <- rnorm(1000)
> z <- rnorm(1000) + atan2(x,y)
glX
 1
> plot3d(x, y, z, col=rainbow(1000))
> rgl.postscript("foo.pdf", fmt="pdf")
> sessionInfo()

这里的rgl.postscript()命令应该打印出一个PDF文件,其中包含传递给plot3d()的数据点的呈现。但是,生成的PDF文件为空白。

是否存在配置问题,如何安装或实例化Xvfb和/或R,这会导致显示问题?

以下是典型运行会话的日志:

R version 3.2.5 (2016-04-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Fedora release 14 (Laughlin)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  base

other attached packages:
[1] rgl_0.95.1441  optparse_1.3.2

loaded via a namespace (and not attached):
[1] getopt_1.20.0 methods_3.2.5

5 XSELINUXs still allocated at reset
SCREEN: 0 objects of 136 bytes = 0 total bytes 0 private allocs
DEVICE: 4 objects of 32 bytes = 128 total bytes 0 private allocs
CLIENT: 0 objects of 160 bytes = 0 total bytes 0 private allocs
WINDOW: 0 objects of 48 bytes = 0 total bytes 0 private allocs
PIXMAP: 1 objects of 16 bytes = 16 total bytes 0 private allocs
GC: 0 objects of 56 bytes = 0 total bytes 0 private allocs
CURSOR: 0 objects of 8 bytes = 0 total bytes 0 private allocs
CURSOR_BITS: 0 objects of 8 bytes = 0 total bytes 0 private allocs
DBE_WINDOW: 0 objects of 24 bytes = 0 total bytes 0 private allocs
TOTAL: 5 objects, 144 bytes, 0 allocs
4 DEVICEs still allocated at reset
DEVICE: 4 objects of 32 bytes = 128 total bytes 0 private allocs
CLIENT: 0 objects of 160 bytes = 0 total bytes 0 private allocs
WINDOW: 0 objects of 48 bytes = 0 total bytes 0 private allocs
PIXMAP: 1 objects of 16 bytes = 16 total bytes 0 private allocs
GC: 0 objects of 56 bytes = 0 total bytes 0 private allocs
CURSOR: 0 objects of 8 bytes = 0 total bytes 0 private allocs
CURSOR_BITS: 0 objects of 8 bytes = 0 total bytes 0 private allocs
DBE_WINDOW: 0 objects of 24 bytes = 0 total bytes 0 private allocs
TOTAL: 5 objects, 144 bytes, 0 allocs
1 PIXMAPs still allocated at reset
PIXMAP: 1 objects of 16 bytes = 16 total bytes 0 private allocs
GC: 0 objects of 56 bytes = 0 total bytes 0 private allocs
CURSOR: 0 objects of 8 bytes = 0 total bytes 0 private allocs
CURSOR_BITS: 0 objects of 8 bytes = 0 total bytes 0 private allocs
DBE_WINDOW: 0 objects of 24 bytes = 0 total bytes 0 private allocs
TOTAL: 1 objects, 16 bytes, 0 allocs

除了Fedora 14之外,我还在CentOS Linux版本7.2.1511下测试了相同版本的Rrgl

在Fedora 14上,我正在运行:

xorg-x11-server-Xvfb.x86_64   v1.9.5-2.fc14

在CentOS 7上,我正在运行:

xorg-x11-server-Xvfb.x86_64   v1.17.2-10.el7

在两个测试服务器下,当我运行我的测试R脚本时,我会从rgl.postscript()获取一个白色的空PDF,并从rgl.snapshot()获得一个黑色的空PNG(以及相同的{ {1}}日志语句)。

我应该强调,我希望创建一个包含渲染场景的PDF文件,该场景采用基于矢量的格式。虽然Xvfb可能有助于解决问题的原因,但该调用会返回PNG位图,而不是矢量格式的PDF。就我的目的而言,位图不是最终产品。

除了在传递rgl.snapshot()变量设置的情况下运行R之外,我还使用了DISPLAY

export

或者:

$ DISPLAY=:2 /usr/local/bin/R

任何一种方法都会产生相同的结果。

如果有其他细节可供使用,请随时发表评论并详细说明,我会尽我所能跟进。

Fedora 14和CentOS 7盒都不应该有专有的libgl驱动程序。据我所知,这些是独立的无头服务器。 Fedora 14盒子实际上是一个虚拟机。如果有具体的确认方式,请告诉我。

我在Fedora 14无头服务器下安装了以下$ export DISPLAY=":2" $ /usr/local/bin/R ... 软件包:

Xdummy

在CentOS 7机器上:

xorg-x11-drv-dummy.x86_64   v0.3.4-1.fc14

在CentOS 7服务器上,我运行Xdummy脚本在xorg-x11-drv-dummy.x86_64 v0.3.6-21.el7 上创建显示:

:10

在另一个shell中,我运行R和测试rgl例程:

$ sudo ./Xdummy -debug :10 -depth 16 -geom 1024x768

$ DISPLAY=":10" /usr/local/bin/R ... > library(rgl) > open3d() > x <- sort(rnorm(1000)) > y <- rnorm(1000) > z <- rnorm(1000) + atan2(x,y) > plot3d(x, y, z, col=rainbow(1000)) > rgl.postscript("foo.pdf", fmt="pdf") 一样,生成的PDF文件是一个空白文档,不包含任何数据点。

1 个答案:

答案 0 :(得分:2)

这似乎与rgl包密切相关。假设我们向Xvfb和朋友投掷赞成Cairo并将plot3D替换为rgl

library(Cairo)
library(plot3D)
CairoPDF()
x <- sort(rnorm(1000))
y <- rnorm(1000)
z <- rnorm(1000) + atan2(x, y)
scatter3D(x, y, z)
dev.off()

这仍然需要在X11(即xterm)下运行,但是避免显示X11窗口并在Rplots.pdf中留下PDF图(你可以控制文件名,当然还有很多其他细节)情节。)

enter image description here

(转换为JPEG以便在此处插入,但它确实是PDF。)