-
Notifications
You must be signed in to change notification settings - Fork 0
/
RTriangleExample.R
46 lines (36 loc) · 1.56 KB
/
RTriangleExample.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
pquads1 <- function(x, texture = NULL, texcoords = NULL, subset = NULL, ...) {
if (is.null(texcoords)) texcoords <- t(x$vb[1:2,x$ib])
if (!is.null(subset)) x$ib <- x$ib[,subset]
rgl.quads(x$vb[1,x$ib], x$vb[2,x$ib], x$vb[3,x$ib], texcoords = texcoords, texture = texture, ...)
}
allcoords <- function(x) {
coordinates(as(as(x, "SpatialLines"), "SpatialPoints"))
}
library(gris) ## devtools::install_github("mdsumner/gris)
library(RTriangle) ## install.packages("RTriangle")
library(maptools)
data(wrld_simpl)
library(rworldmap)
data(countriesLow)
o <- gris(countriesLow)
#for (i in seq(nrow(countriesLow))) {
#while(TRUE) {
# i <- sample(1:nrow(countriesLow), 10)
# i <- c(188L, 204L, 68L, 77L, 236L, 129L, 133L, 15L, 165L, 31L)
#o <- gris(countriesLow[i,])
#o <- gris(wrld_simpl) ##subset(wrld_simpl, NAME %in% c("Australia", "Indonesia", "United States")))
##o <- gris:::normalizeVerts(o1, c("x", "y"))
p <- pslg(P = o$v %>% dplyr::select(x, y) %>% as.matrix(),
S = do.call(rbind, lapply(split(o$bXv$.vx0, o$bXv$.br0), prs1)))
plot(p)
tr <- RTriangle::triangulate(p, a = 2)
#plot(p)
#plot(tr, cex = 0.2)
library(rgl)
library(rglgris) ## devtools::install_github("mdsumner/rglgris)
tri <- tetrahedron3d()
tri$vb <- t(cbind(llh2xyz(cbind(tr$P, 0)),1))
tri$it <- t(tr$T)
wimg <- setExtent(brick("world.topo.bathy.200411.3x5400x2700.png"), extent(-180, 180, -90, 90))
tcoords <- xyFromCell(setExtent(wimg, extent(0, 1, 0, 1)), cellFromXY(wimg, tr$P))
shade3d(tri, col = "white", texture = "world.topo.bathy.200411.3x5400x2700.png", texcoords = tcoords[tri$it, ])