图像未显示 - rgl

问题描述 投票:0回答:1

一年前,以下代码用于显示输出,但事实并非如此。也没有显示错误。我正在阅读软件包更改,但无法确定原因。

library(rgl)

x1 <- seq(0, 2, len = 20)
x2 <- seq(0, 2, len = 20)
y <- outer(x1,x2, function(x1,x2) 1 + x1*2 + x2) 

persp3d(x=x1, y=x2, z=y, theta = 30, phi = 30, expand = 1, col = "green")
surface3d(x=x1, y=x2, z=y, back = "lines")
surface3d(x=x1, y=x2, z=y, front = "lines")
bgplot3d({
  plot.new()
  title(main = 'y = 1 + 2*x1 + x2', line = 3)
})
r rgl
1个回答
1
投票

我尝试重现您的问题,但我自己也遇到了同样的问题。这里的问题是

rgl
默认使用“空”设备......当我试图明确停止它时,

open3d(useNULL=F)
# Error in open3d(useNULL = F) : OpenGL is not available in this build

这让我知道了这次它是如何安装的,我在安装日志(在R控制台上)中找到了:

install.packages("rgl") # Installing package into ‘/home/r2/R/x86_64-pc-linux-gnu-library/4.2’ # (as ‘lib’ is unspecified) # trying URL 'https://packagemanager.posit.co/cran/latest/src/contrib/rgl_1.2.1.tar.gz' # Content type 'binary/octet-stream' length 2558042 bytes (2.4 MB) # ================================================== # downloaded 2.4 MB # * installing *source* package ‘rgl’ ... # ** package ‘rgl’ successfully unpacked and MD5 sums checked # ** using staged installation # checking for gcc... gcc # ... # configure: using libpng-config # configure: using libpng dynamic linkage # checking for X... no # configure: WARNING: X11 not found, continuing without OpenGL support. # configure: compiling without OpenGL support # configure: creating ./config.status
特别是

compiling without OpenGL support

部分。 (如果重要的话,我正在使用 wayland 运行 ubuntu-23.04。)

查看

安装说明,它提到了操作系统软件包libgl1-mesa-dev

libglu1-mesa-dev
,你瞧,它们没有安装在我的系统上。在 shell(不是 R)提示符下,我用以下命令确认了这一缺失:

$ dpkg -l libgl1-mesa-dev libglu1-mesa-dev dpkg-query: no packages found matching libgl1-mesa-dev dpkg-query: no packages found matching libglu1-mesa-dev
安装后:

$ sudo apt install -y libgl1-mesa-dev libglu1-mesa-dev
(输出很多),然后我卸载了 R 包

rgl

并从头开始重新编译。

remove.packages("rgl") install.packages("rgl") # Installing package into ‘/home/r2/R/x86_64-pc-linux-gnu-library/4.2’ # (as ‘lib’ is unspecified) # trying URL 'https://packagemanager.posit.co/cran/latest/src/contrib/rgl_1.2.1.tar.gz' # Content type 'binary/octet-stream' length 2558042 bytes (2.4 MB) # ================================================== # downloaded 2.4 MB # * installing *source* package ‘rgl’ ... # ** package ‘rgl’ successfully unpacked and MD5 sums checked # ** using staged installation # checking for gcc... gcc # ... # checking for libpng-config... yes # configure: using libpng-config # configure: using libpng dynamic linkage # checking for X... libraries , headers <--- BETTER! # checking for XAllocClassHint... yes # checking for GL/gl.h... yes <--- another good sign # checking for GL/glu.h... yes # ... # configure: creating ./config.status
主观上注意到它花费了更长的时间,因为它有更多的文件需要编译和链接。完成后

我重新启动了R(我认为这是必要的),

library(rgl) open3d() # Warning in par3d(userMatrix = c(1, 0, 0, 0, 0, 0.342020143325668, -0.939692620785909, : # font family "sans" not found, using "bitmap" # glX # 1 x1 <- seq(0, 2, len = 20) x2 <- seq(0, 2, len = 20) y <- outer(x1,x2, function(x1,x2) 1 + x1*2 + x2) persp3d(x=x1, y=x2, z=y, theta = 30, phi = 30, expand = 1, col = "green") surface3d(x=x1, y=x2, z=y, back = "lines") surface3d(x=x1, y=x2, z=y, front = "lines") bgplot3d({ plot.new() title(main = 'y = 1 + 2*x1 + x2', line = 3) })
制作了一个情节:

© www.soinside.com 2019 - 2024. All rights reserved.