Skip to content

Commit 12cf653

Browse files
dmurdochcran-robot
authored andcommitted
version 0.100.18
1 parent 2e2fe48 commit 12cf653

Some content is hidden

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

91 files changed

+4431
-2216
lines changed

DESCRIPTION

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
Package: rgl
2-
Version: 0.99.16
2+
Version: 0.100.18
33
Title: 3D Visualization Using OpenGL
44
Author: Daniel Adler <dadler@uni-goettingen.de>, Duncan Murdoch <murdoch@stats.uwo.ca>, and others (see README)
55
Maintainer: Duncan Murdoch <murdoch@stats.uwo.ca>
66
Depends: R (>= 3.2.0)
77
Suggests: MASS, rmarkdown, deldir, orientlib, lattice, misc3d,
8-
rstudioapi, magick
8+
rstudioapi, magick, plotrix (>= 3.7-3), tripack, interp,
9+
alphashape3d
910
Imports: graphics, grDevices, stats, utils, htmlwidgets, htmltools,
1011
knitr, jsonlite (>= 0.9.20), shiny, magrittr, crosstalk,
1112
manipulateWidget (>= 0.9.0)
@@ -22,6 +23,6 @@ SystemRequirements: OpenGL, GLU Library, XQuartz (on OSX), zlib
2223
BugReports: https://r-forge.r-project.org/projects/rgl/
2324
VignetteBuilder: knitr
2425
NeedsCompilation: yes
25-
Packaged: 2018-03-28 12:29:10 UTC; murdoch
26+
Packaged: 2019-03-05 21:02:05 UTC; murdoch
2627
Repository: CRAN
27-
Date/Publication: 2018-03-28 14:53:30 UTC
28+
Date/Publication: 2019-03-08 16:10:06 UTC

MD5

+90-80
Large diffs are not rendered by default.

NAMESPACE

+20-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export(.check3d,
2-
abclines3d, addNormals, addToSubscene3d,
2+
abclines3d, addNormals, addToSubscene3d, arc3d,
33
arrow3d, as.mesh3d, asRow,
44
ageSetter, asEuclidean, asHomogeneous, aspect3d, axes3d, axis3d, box3d,
55
bbox3d, bg3d, bgplot3d,
@@ -31,12 +31,12 @@ export(.check3d,
3131
scale3d, scaleMatrix, scene3d, segments3d, select3d, selectpoints3d,
3232
rgl.setMouseCallbacks, rgl.setWheelCallback, setupKnitr,
3333
setUserShaders, shade3d,
34-
shapelist3d, show2d, snapshot3d,
34+
shapelist3d, shinyGetPar3d, shinySetPar3d, show2d, snapshot3d,
3535
spheres3d, spin3d, sprites3d, subdivision3d,
3636
subsceneInfo, subsceneList, subsetSetter, subsetSlider, Sweave.snapshot,
3737
surface3d, terrain3d,
38-
tetrahedron3d, text3d,
39-
texts3d, title3d, toggleButton, toggleWidget, triangulate,
38+
tetrahedron3d, text3d, texts3d,
39+
thigmophobe3d, title3d, toggleButton, toggleWidget, triangulate,
4040
tmesh3d, transform3d, translate3d, translationMatrix, triangles3d,
4141
turn3d, useSubscene3d, vertexSetter, view3d, wire3d,
4242
writeASY, writeOBJ, writePLY, writeSTL, writeWebGL)
@@ -62,6 +62,9 @@ export(.check3d,
6262
S3method(plot3d, mesh3d)
6363

6464
S3method(as.mesh3d, deldir)
65+
S3method(as.mesh3d, tri)
66+
S3method(as.mesh3d, triSht)
67+
S3method(as.mesh3d, ashape3d)
6568

6669
S3method(translate3d, default)
6770
S3method(rotate3d, default)
@@ -76,6 +79,10 @@ export(.check3d,
7679
S3method(persp3d, default)
7780
S3method(persp3d, "function")
7881
S3method(persp3d, deldir)
82+
S3method(persp3d, tri)
83+
S3method(persp3d, triSht)
84+
S3method(persp3d, ashape3d)
85+
S3method(persp3d, formula)
7986

8087
S3method(plot3d, rglscene)
8188
S3method(plot3d, rglobject)
@@ -84,12 +91,19 @@ export(.check3d,
8491
S3method(plot3d, rglsubscene)
8592
S3method(plot3d, "function")
8693
S3method(plot3d, deldir)
94+
S3method(plot3d, tri)
95+
S3method(plot3d, triSht)
96+
S3method(plot3d, ashape3d)
97+
S3method(plot3d, formula)
98+
S3method(plot3d, lm)
8799

88100
S3method(print, rglscene)
89101
S3method(print, rglobject)
90102
S3method(print, rglsubscene)
91103
S3method(print, indexedSetter)
92104
S3method(print, rglId)
105+
S3method(print, mesh3d)
106+
S3method(print, shapelist3d)
93107

94108
S3method(knit_print, rglId)
95109

@@ -122,7 +136,8 @@ importFrom(htmltools, HTML, includeScript, tags, tagAppendAttributes,
122136
tagHasAttribute, tagList, browsable, resolveDependencies)
123137
importFrom(jsonlite, toJSON)
124138
importFrom(knitr, fig_path, hook_plot_custom, image_uri, knit_hooks, knit_print, opts_current, opts_knit)
125-
importFrom(shiny, getDefaultReactiveDomain, markRenderFunction)
139+
importFrom(shiny, getDefaultReactiveDomain, markRenderFunction, registerInputHandler)
126140
importFrom(magrittr, "%>%")
127141
importFrom(manipulateWidget, combineWidgets)
142+
importFrom(stats, coef, predict, residuals)
128143

R/arc3d.R

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
arc3d <- function(from, to, center, radius, n, circle = 50, base = 0, plot = TRUE, ...) {
2+
fixarg <- function(arg) {
3+
if (is.matrix(arg))
4+
arg[, 1:3, drop = FALSE]
5+
else
6+
matrix(arg, 1, 3)
7+
}
8+
normalize <- function(v)
9+
v / veclen(v)
10+
getrow <- function(arg, i) {
11+
arg[1 + (i - 1) %% nrow(arg),]
12+
}
13+
from <- fixarg(from)
14+
to <- fixarg(to)
15+
center <- fixarg(center)
16+
17+
m <- max(nrow(from), nrow(to), nrow(center), length(base))
18+
base <- rep_len(base, m)
19+
20+
result <- matrix(NA_real_, nrow = 1, ncol = 3)
21+
22+
for (j in seq_len(m)) {
23+
from1 <- getrow(from, j)
24+
to1 <- getrow(to, j)
25+
center1 <- getrow(center, j)
26+
base1 <- base[j]
27+
logr1 <- log(veclen(from1 - center1))
28+
logr2 <- log(veclen(to1 - center1))
29+
A <- normalize(from1 - center1)
30+
B <- normalize(to1 - center1)
31+
steps <- if (base1 <= 0) 4*abs(base1) + 1 else 4*base1 - 1
32+
for (k in seq_len(steps)) {
33+
if (k %% 2) {
34+
A1 <- A * (-1)^(k %/% 2)
35+
B1 <- B * (-1)^(k %/% 2 + (base1 > 0))
36+
} else {
37+
A1 <- B * (-1)^(k %/% 2 + (base1 <= 0))
38+
B1 <- A * (-1)^(k %/% 2)
39+
}
40+
theta <- acos(sum(A1*B1))
41+
if (isTRUE(all.equal(theta, pi)))
42+
warning("Arc ", j, " points are opposite each other! Arc is not well defined.")
43+
if (missing(n))
44+
n1 <- ceiling(circle*theta/(2*pi))
45+
else
46+
n1 <- n
47+
48+
if (missing(radius)) {
49+
pretheta <- (k %/% 2)*pi - (k %% 2 == 0)*theta
50+
if (k == 1)
51+
totaltheta <- (steps %/% 2)*pi - (steps %% 2 == 0)*theta + theta
52+
p1 <- pretheta/totaltheta
53+
p2 <- (pretheta + theta)/totaltheta
54+
radius1 <- exp(seq(from = (1 - p1)*logr1 + p1*logr2,
55+
to = (1 - p2)*logr1 + p2*logr2,
56+
length.out = n1 + 1))
57+
} else
58+
radius1 <- rep_len(radius, n1)
59+
arc <- matrix(NA_real_, nrow = n1 + 1, ncol = 3)
60+
p <- seq(0, 1, length.out = n1 + 1)
61+
arc[1,] <- center1 + radius1[1]*A1
62+
arc[n1 + 1,] <- center1 + radius1[n1 + 1]*B1
63+
AB <- veclen(A1 - B1)
64+
for (i in seq_len(n1)[-1]) {
65+
ptheta <- p[i]*theta
66+
phi <- pi/2 + (0.5 - p[i])*theta
67+
q <- (sin(ptheta) / sin(phi))/AB
68+
D <- (1-q)*A1 + q*B1
69+
arc[i,] <- center1 + radius1[i] * normalize(D)
70+
}
71+
if (k == 1)
72+
result <- rbind(result, arc)
73+
else
74+
result <- rbind(result[-nrow(result), ,drop = FALSE], arc)
75+
}
76+
result <- rbind(result, result[1,])
77+
}
78+
if (plot)
79+
lines3d(result[c(-1, -nrow(result)), , drop = FALSE], ...)
80+
else
81+
result[c(-1, -nrow(result)), , drop = FALSE]
82+
}

R/ashape3d.R

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Support for objects from alphashape3d package
2+
3+
persp3d.ashape3d <- function(x, ..., add = FALSE) {
4+
plot3d(as.mesh3d(x, ...), add = add, ...)
5+
}
6+
7+
plot3d.ashape3d <- function(x, ...) persp3d(x, ...)
8+
9+
reOrient <- function(vertices) {
10+
warned <- FALSE
11+
12+
# Count how many other triangles touch each edge of this one, in order 2-3, 1-3, 1-2:
13+
edgeCounts <- function(index) {
14+
triangle <- vertices[,index]
15+
result <- integer(3)
16+
for (i in 1:3) {
17+
result[i] <- sum(apply(vertices, 2, function(col) all(triangle[-i] %in% col)))
18+
}
19+
result - 1
20+
}
21+
polys <- ncol(vertices)
22+
verts <- nrow(vertices)
23+
cols <- col(vertices)
24+
fixed <- 0L
25+
for (i in seq_len(polys - 1)) {
26+
fixed <- max(i, fixed)
27+
# Get all polygons touching polygon i
28+
thistriangle <- vertices[,i]
29+
if (any(is.na(thistriangle))) next
30+
touches <- which(matrix(vertices %in% thistriangle,nrow=3), arr.ind = TRUE)
31+
if (!nrow(touches)) next
32+
counts <- table(touches[,2L])
33+
# Get col number of all polygons sharing an edge with i
34+
shared <- as.numeric(names(counts)[counts > 1L])
35+
shared <- shared[shared != i]
36+
if (!length(shared)) next
37+
otherverts <- vertices[, shared, drop=FALSE]
38+
39+
# FIXME: otherverts may include multiple triangles sharing the
40+
# same edge, because ashape3d sometimes embeds
41+
# tetrahedrons (or larger polyhedra?) in the surfaces
42+
# it produces. It doesn't appear to be safe to just
43+
# delete these
44+
45+
if (!warned && length(shared) > 1L && any( edgeCounts(i) > 1)) {
46+
warning("Surface may not be simple; smoothing may not be possible.")
47+
warned <- TRUE
48+
}
49+
50+
shared <- shared[shared > fixed]
51+
if (!length(shared)) next
52+
53+
otherverts <- vertices[, shared, drop=FALSE]
54+
55+
for (m in seq_len(ncol(otherverts))) { # m is intersection number
56+
# For each vertex in i, see if it is in the shared one, and
57+
# if they have opposite orientations as we need
58+
for (j in seq_len(verts)) {
59+
# Where is j in the others?
60+
jother <- which(otherverts[,m] == vertices[j,i])
61+
if (!length(jother)) next
62+
k <- j %% verts + 1L # k follows j
63+
kother <- jother %% verts + 1L # kother is entry following jother
64+
if (vertices[k, i] == otherverts[kother, m]) {
65+
otherverts[, m] <- rev(otherverts[, m])
66+
break
67+
}
68+
}
69+
}
70+
# Now move all of shared to the front
71+
unshared <- (fixed+1L):max(shared)
72+
unshared <- unshared[!(unshared %in% shared)]
73+
if (length(unshared))
74+
vertices[, (fixed+length(shared)+1L):max(shared)] <- vertices[,unshared]
75+
vertices[, fixed + seq_along(shared)] <- otherverts
76+
fixed <- fixed + length(shared)
77+
}
78+
vertices
79+
}
80+
81+
as.mesh3d.ashape3d <- function(x, alpha = x$alpha[1],
82+
col = "gray", smooth = FALSE,
83+
normals = NULL, texcoords = NULL,
84+
...) {
85+
whichAlpha <- which(alpha == x$alpha)[1]
86+
if (!length(whichAlpha))
87+
stop("'alpha = ", alpha, "' not found in ", deparse(substitute(x)))
88+
triangles <- x$triang
89+
keep <- triangles[,8 + whichAlpha] > 1
90+
triangs <- t(triangles[keep, 1:3])
91+
points <- t(x$x)
92+
if (!is.null(texcoords))
93+
texcoords <- texcoords[triangs, ]
94+
material <- .getMaterialArgs(...)
95+
material$color <- col
96+
result <- tmesh3d(points, triangs, homogeneous = FALSE,
97+
normals = normals, texcoords = texcoords,
98+
material = material)
99+
if (smooth) {
100+
if (is.null(normals)) {
101+
result$it <- reOrient(result$it)
102+
result <- addNormals(result)
103+
} else
104+
warning("smoothing ignored when 'normals' specified")
105+
}
106+
result
107+
}

R/callbacks.R

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
rgl.setMouseCallbacks <- function(button, begin=NULL, update=NULL, end=NULL) {
2-
invisible(.Call(rgl_setMouseCallbacks, as.integer(button), begin, update, end))
1+
rgl.setMouseCallbacks <- function(button, begin=NULL, update=NULL, end=NULL, dev = rgl.cur(), subscene = currentSubscene3d(dev)) {
2+
invisible(.Call(rgl_setMouseCallbacks, as.integer(button), begin, update, end,
3+
as.integer(dev), as.integer(subscene)))
34
}
45

5-
rgl.getMouseCallbacks <- function(button)
6-
.Call(rgl_getMouseCallbacks, as.integer(button))
6+
rgl.getMouseCallbacks <- function(button, dev = rgl.cur(), subscene = currentSubscene3d(dev))
7+
.Call(rgl_getMouseCallbacks, as.integer(button), as.integer(dev), as.integer(subscene))
78

8-
rgl.setWheelCallback <- function(rotate=NULL) {
9-
invisible(.Call(rgl_setWheelCallback, rotate))
9+
rgl.setWheelCallback <- function(rotate=NULL, dev = rgl.cur(), subscene = currentSubscene3d(dev)) {
10+
invisible(.Call(rgl_setWheelCallback, rotate, as.integer(dev), as.integer(subscene)))
1011
}
1112

12-
rgl.getWheelCallback <- function()
13-
.Call(rgl_getWheelCallback)
13+
rgl.getWheelCallback <- function(dev = rgl.cur(), subscene = currentSubscene3d(dev))
14+
.Call(rgl_getWheelCallback, as.integer(dev), as.integer(subscene))

R/convertScene.R

+5-2
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,17 @@ convertScene <- function(x = scene3d(), width = NULL, height = NULL, reuse = NUL
130130

131131
result["is_smooth"] <- mat$smooth && type %in% c("triangles", "quads", "surface", "planes",
132132
"spheres")
133+
134+
result["sprites_3d"] <- sprites_3d <- type == "sprites" && length(obj$ids)
133135

134-
result["has_texture"] <- has_texture <- !is.null(mat$texture) && !is.null(obj$texcoords)
136+
result["has_texture"] <- has_texture <- !is.null(mat$texture) &&
137+
(!is.null(obj$texcoords)
138+
|| (type == "sprites" && !sprites_3d))
135139

136140
result["is_transparent"] <- is_transparent <- (has_texture && mat$isTransparent) || any(obj$colors[,"a"] < 1)
137141

138142
result["depth_sort"] <- depth_sort <- is_transparent && type %in% c("triangles", "quads", "surface",
139143
"spheres", "sprites", "text")
140-
result["sprites_3d"] <- sprites_3d <- type == "sprites" && length(obj$ids)
141144

142145
result["fixed_quads"] <- type %in% c("text", "sprites") && !sprites_3d
143146
result["is_lines"] <- type %in% c("lines", "linestrip", "abclines")

R/enum.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ rgl.enum.attribtype <- function (attrib)
3131
rgl.enum( attrib, vertices=1, normals=2, colors=3, texcoords=4, dim=5,
3232
texts=6, cex=7, adj=8, radii=9, centers=10, ids=11,
3333
usermatrix=12, types=13, flags=14, offsets=15,
34-
family=16, font=17)
34+
family=16, font=17, pos=18)
3535

3636
rgl.enum.pixfmt <- function (fmt)
3737
rgl.enum( fmt, png=0 )

R/getscene.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ scene3d <- function() {
2222
attribs <- c("vertices", "normals", "colors", "texcoords", "dim",
2323
"texts", "cex", "adj", "radii", "ids",
2424
"usermatrix", "types", "offsets", "centers",
25-
"family", "font")
25+
"family", "font", "pos")
2626
for (a in attribs)
2727
if (rgl.attrib.count(id, a))
2828
result[[a]] <- rgl.attrib(id, a)

R/grid3d.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ grid3d <- function (side, at = NULL, col="gray",
2424
at[[coord]] <- NULL
2525
}
2626

27-
result <- c()
27+
result <- integer()
2828

2929
for (cside in sides) {
3030
range <- ranges[[cside]]
@@ -53,8 +53,8 @@ grid3d <- function (side, at = NULL, col="gray",
5353
mpos1 <- temp1
5454
mpos2 <- temp2
5555
}
56-
57-
result[sidenames[cside]] <- segments3d(x=c(rbind(mpos1[,1],mpos2[,1])),
56+
if (nrow(mpos1) + nrow(mpos2) > 0)
57+
result[sidenames[cside]] <- segments3d(x=c(rbind(mpos1[,1],mpos2[,1])),
5858
y=c(rbind(mpos1[,2],mpos2[,2])),
5959
z=c(rbind(mpos1[,3],mpos2[,3])),
6060
lwd=lwd,color=col)

0 commit comments

Comments
 (0)