hypertidy / quadmesh

@@ -29,12 +29,10 @@
Loading
29 29
#' library(raster)
30 30
#' r <- setExtent(raster(volcano), extent(0, nrow(volcano), 0, ncol(volcano)))
31 31
#' tm <- triangmesh(r)
32 -
#' #rgl::shade3d(tm)
33 32
#'
34 33
#' ## jitter the mesh just enough to show that they are distinct in the discrete case
35 34
#' a <- dtriangmesh(r)
36 35
#' a$vb[3L, ] <- jitter(a$vb[3L, ], factor = 10)
37 -
#' ##rgl.clear(); rgl::shade3d(a, col = "grey"); aspect3d(1, 1, 0.2); rglwidget()
38 36
triangmesh <- function (x, z = x, na.rm = FALSE, ..., texture = NULL, texture_filename = NULL) {
39 37
  UseMethod("triangmesh")
40 38
}

@@ -47,44 +47,3 @@
Loading
47 47
                 na.rm = TRUE)
48 48
}
49 49
50 -
51 -
as_mesh3d_matrix <- function(x,...) {
52 -
  v <- vxy(x)
53 -
  exy <- edges_xy(x)
54 -
55 -
  dm <- dim(x)
56 -
  ## this was developed against raster, so nc is nr ;)
57 -
  nc <- dm[1L]
58 -
  nr <- dm[2L]
59 -
  nc1 <- nc + 1
60 -
  aa <- t(prs(seq_len(nc1)))
61 -
  ind <- matrix(c(rbind(aa, aa[2:1, ])) + c(0, 0, nc1, nc1), 4)
62 -
  ind0 <- as.integer(as.vector(ind) +
63 -
                       rep(seq(0, length = nr, by = nc1), each = 4 * nc))
64 -
  ind1 <- matrix(ind0, nrow = 4)
65 -
  ## for a matrix, we are done
66 -
  ## for raster, we have to apply the extent transformation
67 -
  cols <- viridis::viridis(100)
68 -
  rgl::qmesh3d(rbind(t(exy), v, 1),
69 -
               ind1,
70 -
               material = list(color = cols[scales::rescale(v, to = c(1, 100))])
71 -
  )
72 -
}
73 -
74 -
as_mesh3d_raster <- function(x, ...) {
75 -
  v <- vxy_raster(x)
76 -
  exy <- edgesXY(x)
77 -
  nc <- x@ncols
78 -
  nc1 <- nc + 1
79 -
  aa <- t(prs(seq(nc1)))
80 -
  ind <- matrix(c(rbind(aa, aa[2:1, ])) + c(0, 0, nc1, nc1), 4)
81 -
  ind0 <- as.integer(as.vector(ind) +
82 -
                       rep(seq(0, length = nrow(x), by = ncol(x) + 1), each = 4 * dim(x)[2L]))
83 -
  ind1 <- matrix(ind0, nrow = 4)
84 -
85 -
  cols <- viridis::viridis(100)
86 -
  rgl::qmesh3d(rbind(t(exy),  v, 1),
87 -
               ind1,
88 -
               material = list(color = cols[scales::rescale(v, to = c(1, 100))])
89 -
               )
90 -
}

@@ -6,6 +6,9 @@
Loading
6 6
#' using the 'col' argument, and controlled with 'zlim' and 'breaks' in the usual
7 7
#' [graphics::image()] way.
8 8
#' @name mesh_plot
9 +
#' @param prefer_quad set to `TRUE` by default, if but may be `FALSE` to assume use of triangle rather than quad primitives -
10 +
#' this covers the case for when a mesh3d object may have quads *and* triangles in the same mesh
11 +
#' @param breaks argument passed along to [palr::image_pal()]
9 12
#' @export
10 13
mesh_plot.mesh3d <-
11 14
  function (x,

@@ -4,14 +4,11 @@
Loading
4 4
#' a raw rendition of the cube is returned as six quad primitives in a `mesh3d` object.
5 5
#'
6 6
#' It's not clear if this is useful.
7 -
#' @references \url{https://github.com/OSGeo/proj.4/wiki/Qsc}
8 7
#' @return mesh3d
9 8
#' @export
10 9
#'
11 10
#' @examples
12 -
#' library(rgl); #rgl.clear()
13 -
#' wire3d(qsc())
14 -
#' if ( rgl::rgl.useNULL()) rglwidget()
11 +
#' str(qsc())
15 12
qsc <- function() {
16 13
 radius <- 6378137
17 14
 xy <- rbind(c(-radius, -radius, radius, radius),

@@ -64,7 +64,10 @@
Loading
64 64
  if (!is.null(crs)) use_crs(crs) else use_crs(raster::projection(x))
65 65
66 66
  qm <- quadmesh::quadmesh(x, na.rm = FALSE)
67 -
67 +
  if (!is.null(coords) && is.na(qm$crs)) {
68 +
    ## we need this otherwise no reprojection is done in the case where coords and crs are both given
69 +
    qm$crs <- "+proj=longlat +datum=WGS84"  ## assume
70 +
  }
68 71
  if (is.null(col)) col <- hcl.colors(12, "YlOrRd",
69 72
                                      rev = TRUE)
70 73
  ib <- qm$ib
@@ -79,7 +82,9 @@
Loading
79 82
    if (!crs_wasnull && !.ok_ll(xy)) warning("'coords' do not look like longlat, so 'crs' arg won't work\n please see Details in '?quadmesh'")
80 83
81 84
  }
85 +
82 86
  if (!is.na(use_crs()) && !is.na(qm$crs)) {
87 +
83 88
   xy <- reproj::reproj(xy, target = use_crs(), source = qm$crs)
84 89
  }
85 90
  ## as this affects the entire thing

@@ -29,7 +29,7 @@
Loading
29 29
30 30
#' Create a quad-type mesh for use in rgl.
31 31
#'
32 -
#' Convert an object to a `mesh3d` ([rgl::qmesh3d()]) quadrangle mesh,
32 +
#' Convert an object to a `mesh3d` quadrangle mesh,
33 33
#' with methods for [raster::raster()] and `matrix`.
34 34
#'
35 35
#' `quadmesh()` generates the cell-based interpretation of a raster (AREA) but applies a continuous
Files Coverage
R 44.34%
Project Totals (13 files) 44.34%
1
comment: false
2

3
coverage:
4
  status:
5
    project:
6
      default:
7
        target: auto
8
        threshold: 1%
9
    patch:
10
      default:
11
        target: auto
12
        threshold: 1%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading