Skip to content

Commit 07c0ef6

Browse files
dmurdochcran-robot
authored andcommitted
version 0.104.16
1 parent 42a7577 commit 07c0ef6

File tree

173 files changed

+3398
-2384
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+3398
-2384
lines changed

DESCRIPTION

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
Package: rgl
2-
Version: 0.103.5
2+
Version: 0.104.16
33
Title: 3D Visualization Using OpenGL
44
Author: Daniel Adler <dadler@uni-goettingen.de>, Duncan Murdoch <murdoch.duncan@gmail.com>, and others (see README)
55
Maintainer: Duncan Murdoch <murdoch.duncan@gmail.com>
6-
Depends: R (>= 4.0.0)
6+
Depends: R (>= 3.2.0)
77
Suggests: MASS, rmarkdown, deldir, orientlib, lattice, misc3d,
88
rstudioapi, magick, plotrix (>= 3.7-3), tripack, interp,
99
alphashape3d, tcltk, js (>= 1.2), akima
1010
Imports: graphics, grDevices, stats, utils, htmlwidgets, htmltools,
1111
knitr, jsonlite (>= 0.9.20), shiny, magrittr, crosstalk,
12-
manipulateWidget (>= 0.9.0), mathjaxr
12+
manipulateWidget (>= 0.9.0)
1313
Description: Provides medium to high level functions for 3D interactive graphics, including
1414
functions modelled on base graphics (plot3d(), etc.) as well as functions for
1515
constructing representations of geometric objects (cube3d(), etc.). Output
@@ -18,14 +18,11 @@ Description: Provides medium to high level functions for 3D interactive graphics
1818
License: GPL
1919
URL: https://r-forge.r-project.org/projects/rgl/
2020
SystemRequirements: OpenGL, GLU Library, XQuartz (on OSX), zlib
21-
(optional on Unix, required on Windows), libpng (>=1.2.9,
22-
optional on Unix, required on Windows), FreeType (optional on
23-
Unix, required on Windows), pandoc (>=1.14, needed for
24-
vignettes)
21+
(optional), libpng (>=1.2.9, optional), FreeType (optional),
22+
pandoc (>=1.14, needed for vignettes)
2523
BugReports: https://r-forge.r-project.org/projects/rgl/
2624
VignetteBuilder: knitr
27-
RdMacros: mathjaxr
2825
NeedsCompilation: yes
29-
Packaged: 2020-11-19 00:52:36 UTC; murdoch
26+
Packaged: 2021-01-09 01:07:36 UTC; murdoch
3027
Repository: CRAN
31-
Date/Publication: 2020-11-23 15:00:02 UTC
28+
Date/Publication: 2021-01-10 17:10:13 UTC

MD5

+167-169
Large diffs are not rendered by default.

NAMESPACE

+7-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ export(.check3d,
3030
rgl.viewpoint, rgl.window2user,
3131
rglFonts, rglId, rglMouse, rglShared, rglToLattice, rglToBase,
3232
r3dDefaults, rotate3d, rotationMatrix,
33-
scale3d, scaleMatrix, scene3d, segments3d, select3d, selectpoints3d,
33+
scale3d, scaleMatrix, scene3d, segments3d,
34+
select3d, selectionFunction3d, selectpoints3d,
3435
rgl.setMouseCallbacks, rgl.setWheelCallback, set3d,
3536
setGraphicsDelay, setupKnitr, setUserShaders, shade3d,
36-
shapelist3d, shinyGetPar3d, shinySetPar3d, show2d, snapshot3d,
37+
shapelist3d, shinyGetPar3d, shinySetPar3d, shinyResetBrush,
38+
show2d, snapshot3d,
3739
spheres3d, spin3d, sprites3d, subdivision3d,
3840
subsceneInfo, subsceneList, subsetSetter, subsetSlider, Sweave.snapshot,
3941
surface3d, terrain3d,
@@ -116,10 +118,13 @@ export(.check3d,
116118
S3method(print, rglsubscene)
117119
S3method(print, indexedSetter)
118120
S3method(print, rglId)
121+
S3method(print, rglOpen3d)
119122
S3method(print, mesh3d)
120123
S3method(print, shapelist3d)
124+
S3method(print, rglMouseSelection)
121125

122126
S3method(knit_print, rglId)
127+
S3method(knit_print, rglOpen3d)
123128

124129
S3method(summary, rglscene)
125130
S3method(summary, rglsubscene)

R/Sweave_knitr.R

+27-16
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ rgl.Sweave <- function(name, width, height, options, ...) {
2424
}
2525

2626
snapshotDone <- FALSE
27-
27+
28+
# stayOpen is used below in rgl.Sweave.off
2829
stayOpen <- isTRUE(options$stayopen)
2930

3031
type <- options$outputtype
@@ -217,7 +218,7 @@ withPrivateSeed <- local({
217218
# Need to call this to make sure that the value of .Random.seed gets put
218219
# into R's internal RNG state. (Issue #1763)
219220

220-
# httpuv::getRNGState()
221+
# httpuv::getRNGState() # nolint
221222
})
222223

223224
expr
@@ -287,6 +288,14 @@ fns <- local({
287288
}
288289
}
289290

291+
knit_print.rglOpen3d <- function(x, options, ...) {
292+
print(x, ...)
293+
if (getOption("rgl.printRglwidget", FALSE)) {
294+
plotnum <<- plotnum + 1
295+
}
296+
invisible(x)
297+
}
298+
290299
knit_print.rglId <- function(x, options, ...) {
291300
if (getOption("rgl.printRglwidget", FALSE)) {
292301
scene <- scene3d()
@@ -312,16 +321,16 @@ fns <- local({
312321
}, logical(1))
313322

314323
# move plots before source code
315-
fig_before_code = function(x) {
316-
s = vapply(x, evaluate::is.source, logical(1))
324+
fig_before_code <- function(x) {
325+
s <- vapply(x, evaluate::is.source, logical(1))
317326
if (length(s) == 0 || !any(s)) return(x)
318-
s = which(s)
319-
f = which(find_figs(x))
320-
f = f[f >= min(s)] # only move those plots after the first code block
327+
s <- which(s)
328+
f <- which(find_figs(x))
329+
f <- f[f >= min(s)] # only move those plots after the first code block
321330
for (i in f) {
322-
j = max(s[s < i])
323-
tmp = x[i]; x[[i]] = NULL; x = append(x, tmp, j - 1)
324-
s = which(vapply(x, evaluate::is.source, logical(1)))
331+
j <- max(s[s < i])
332+
tmp <- x[i]; x[[i]] <- NULL; x <- append(x, tmp, j - 1)
333+
s <- which(vapply(x, evaluate::is.source, logical(1)))
325334
}
326335
x
327336
}
@@ -439,8 +448,8 @@ fns <- local({
439448
# These functions are closely based on code from knitr:
440449

441450
# compare two recorded plots
442-
is_low_change = function(p1, p2) {
443-
p1 = p1[[1]]; p2 = p2[[1]] # real plot info is in [[1]],
451+
is_low_change <- function(p1, p2) {
452+
p1 <- p1[[1]]; p2 <- p2[[1]] # real plot info is in [[1]],
444453
# as is plotnum
445454
if (length(p2) < (n1 <- length(p1))) return(FALSE) # length must increase
446455
identical(p1[1:n1], p2[1:n1])
@@ -452,9 +461,9 @@ fns <- local({
452461
i1 <- idx[1]; i2 <- idx[2] # compare plots sequentially
453462
for (i in 1:(n - 1)) {
454463
# remove the previous plot and move its index to the next plot
455-
if (is_low_change(x[[i1]], x[[i2]])) m = c(m, i1)
456-
i1 = idx[i + 1]
457-
i2 = idx[i + 2]
464+
if (is_low_change(x[[i1]], x[[i2]])) m <- c(m, i1)
465+
i1 <- idx[i + 1]
466+
i2 <- idx[i + 2]
458467
}
459468
if (is.null(m)) x else x[-m]
460469
}
@@ -464,7 +473,8 @@ fns <- local({
464473
hook_figkeep = hook_figkeep,
465474
hook_figshow = hook_figshow,
466475
hook_figbeforecode = hook_figbeforecode,
467-
knit_print.rglId = knit_print.rglId)
476+
knit_print.rglId = knit_print.rglId,
477+
knit_print.rglOpen3d = knit_print.rglOpen3d)
468478
})
469479

470480
setupKnitr <- fns[["setupKnitr"]]
@@ -473,6 +483,7 @@ hook_figkeep <- fns[["hook_figkeep"]]
473483
hook_figshow <- fns[["hook_figshow"]]
474484
hook_figbeforecode <- fns[["hook_figbeforecode"]]
475485
knit_print.rglId <- fns[["knit_print.rglId"]]
486+
knit_print.rglOpen3d <- fns[["knit_print.rglOpen3d"]]
476487
rm(fns)
477488

478489
figWidth <- function()

R/addNormals.mesh3d.R

+41-28
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,53 @@
11
addNormals <- function(x, ...) UseMethod("addNormals")
22

3-
addNormals.mesh3d <- function(x, ...) {
3+
addNormals.mesh3d <- function(x, angleWeighted = TRUE, ...) {
44
v <- x$vb
55

66
# Make sure v is homogeneous with unit w
77
if (nrow(v) == 3) v <- rbind(v, 1)
88
else v <- t( t(v)/v[4,] )
99

10-
normals <- v*0
1110
v <- v[1:3,]
11+
normals <- v*0
1212

13-
if (length(x$it)) {
14-
it <- x$it
15-
for (i in 1:ncol(it)) {
16-
normal <- normalize(xprod( v[, it[1, i]] - v[, it[3, i]],
17-
v[, it[2, i]] - v[, it[1, i]]))
18-
if (!any(is.na(normal)))
19-
for (j in 1:3) {
20-
if (sum(normals[1:3, it[j,i]]*normal) < 0)
21-
normals[, it[j,i]] <- normals[, it[j,i]] + c(-normal, 1)
22-
else
23-
normals[, it[j,i]] <- normals[, it[j,i]] + c(normal, 1)
24-
}
25-
}
26-
}
13+
if (is.na(angleWeighted)) {
14+
reproduceBug <- TRUE
15+
angleWeighted <- FALSE
16+
} else
17+
reproduceBug <- FALSE
2718

28-
if (length(x$ib)) {
29-
it <- x$ib
30-
for (i in 1:ncol(it)) {
31-
normal <- normalize(xprod( v[, it[1, i]] - v[, it[4, i]],
32-
v[, it[2, i]] - v[, it[1, i]]))
33-
if (!any(is.na(normal)))
34-
for (j in 1:4) {
35-
if (sum(normals[1:3, it[j,i]]*normal) < 0)
36-
normals[, it[j,i]] <- normals[, it[j,i]] + c(-normal, 1)
37-
else
38-
normals[, it[j,i]] <- normals[, it[j,i]] + c(normal, 1)
19+
dopolys <- function(it, normals) {
20+
n <- nrow(it)
21+
for (i in seq_len(ncol(it))) {
22+
normal <- xprod( v[, it[1, i]] - v[, it[3, i]],
23+
v[, it[2, i]] - v[, it[1, i]])
24+
if (reproduceBug)
25+
normal <- normalize(normal)
26+
if (!any(is.na(normal))) {
27+
if (angleWeighted)
28+
normal <- normalize(normal)
29+
30+
for (j in seq_len(n)) {
31+
if (angleWeighted) {
32+
jm1 <- (j + n - 2) %% n + 1
33+
jp1 <- j %% n + 1
34+
weight <- angle(v[, it[jm1, i]] - v[, it[j, i]],
35+
v[, it[jp1, i]] - v[, it[j, i]])
36+
} else
37+
weight <- 1
38+
normals[, it[j,i]] <- normals[, it[j,i]] + normal*weight
3939
}
40+
}
4041
}
42+
normals
4143
}
42-
normals <- t( t(normals)/normals[4,] )
44+
45+
if (length(x$it))
46+
normals <- dopolys(x$it, normals)
47+
48+
if (length(x$ib))
49+
normals <- dopolys(x$ib, normals)
50+
normals <- rbind(apply(normals, 2, function(n) n/veclen(n)), 1)
4351
x$normals <- normals
4452
x
4553
}
@@ -51,3 +59,8 @@ normalize <- function(v) v/veclen(v)
5159
xprod <- function(v, w) c( v[2]*w[3] - v[3]*w[2],
5260
v[3]*w[1] - v[1]*w[3],
5361
v[1]*w[2] - v[2]*w[1] )
62+
63+
angle <- function(a,b) {
64+
dot <- sum(a*b)
65+
acos(dot/veclen(a)/veclen(b))
66+
}

R/animate.R

+2-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ toRotmatrix <- function(x) {
3131

3232
par3dinterp <- function(times=NULL, userMatrix, scale, zoom, FOV, method=c("spline", "linear"),
3333
extrapolate = c("oscillate","cycle","constant", "natural"),
34-
dev = cur3d(), subscene = par3d("listeners", dev = dev)) {
34+
dev = cur3d(), subscene = par3d("listeners", dev = dev)) {
3535
force(dev)
3636
force(subscene)
3737

@@ -197,7 +197,7 @@ movie3d <- function(f, duration, dev = cur3d(), ..., fps=10,
197197
rgl.snapshot(filename=filename, fmt="png", top=top)
198198
}
199199
cat("\n")
200-
if (.Platform$OS.type == "windows") system <- shell
200+
if (.Platform$OS.type == "windows") system <- shell # nolint
201201
if (is.null(convert) && requireNamespace("magick")) {
202202
m <- NULL
203203
for (i in round(startTime*fps):(duration*fps)) {
@@ -249,4 +249,3 @@ movie3d <- function(f, duration, dev = cur3d(), ..., fps=10,
249249
}
250250
invisible(convert)
251251
}
252-

R/arrow3d.R

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ arrow3d <- function(p0=c(1,1,1), p1=c(0,0,0), barblen, s=1/3, theta=pi/12,
88
width = 1/3,
99
thickness = 0.618*width,
1010
spriteOrigin = NULL,
11-
plot = TRUE, ...){
11+
plot = TRUE, ...) {
1212
## p0: start point
1313
## p1: end point
1414
## barblen: length of barb
@@ -56,8 +56,7 @@ arrow3d <- function(p0=c(1,1,1), p1=c(0,0,0), barblen, s=1/3, theta=pi/12,
5656
r <- gs[2,]
5757

5858
## now compute the barb end points and draw:
59-
pts = list()
60-
for(i in 1:length(phi)){
59+
for(i in seq_along(phi)) {
6160
ptb <- rotate3d(r,phi[i],(p1-p0)[1],(p1-p0)[2],(p1-p0)[3])
6261
xyz <- rbind(xyz, p1, cpt + barblen*sin(theta)*ptb)
6362
}

R/ashape3d.R

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ reOrient <- function(vertices) {
2020
}
2121
polys <- ncol(vertices)
2222
verts <- nrow(vertices)
23-
cols <- col(vertices)
2423
fixed <- 0L
2524
for (i in seq_len(polys - 1)) {
2625
fixed <- max(i, fixed)

R/asy.R

+4-5
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ ticklabel RGLScale(real s)
6060
}
6161

6262
# simulate rgl.attrib
63-
get.attrib <- function(id, attrib) {
63+
get.attrib <- function(id, attrib) {
6464
obj <- scene$objects[[as.character(id)]]
6565
obj[[attrib]]
6666
}
@@ -144,7 +144,7 @@ ticklabel RGLScale(real s)
144144

145145
writePoly <- function(vertices) {
146146
if (any(!is.finite(vertices)))
147-
return();
147+
return()
148148
setPen(apply(vertices[, rgba], 2, mean))
149149
v <- vertices[1, 1:3]
150150
result <<- c(result, subst('draw(surface((%x%, %y%, %z%)', x=v[1], y=v[2], z=v[3]))
@@ -246,7 +246,6 @@ ticklabel RGLScale(real s)
246246
setPen(size = getmaterial(id)$lwd)
247247
vertices <- getVertices(id)
248248
n <- nrow(vertices)
249-
inds <- seq_len(n)
250249
open <- FALSE
251250
for (i in seq_len(n)) {
252251
if (open) {
@@ -261,7 +260,7 @@ ticklabel RGLScale(real s)
261260
setPen(vertices[i, rgba])
262261
result <<- c(result, subst('draw((%x%, %y%, %z%)',
263262
x = vertices[i, 1], y = vertices[i, 2], z = vertices[i, 3]))
264-
open = TRUE
263+
open <- TRUE
265264
}
266265
}
267266
if (open)
@@ -445,7 +444,7 @@ ticklabel RGLScale(real s)
445444
text = writeText(ids[i]),
446445
background = writeBackground(ids[i]),
447446
bboxdeco = writeBBox(ids[i]),
448-
light = {}
447+
light = {} # nolint
449448
)
450449
}
451450
if (outtype %in% c("latex", "pdflatex")) {

0 commit comments

Comments
 (0)