hypertidy / quadmesh

raster grid as indexed quad mesh
https://hypertidy.github.io/quadmesh/
25 stars 2 forks source link

pure index mesh #8

Open mdsumner opened 6 years ago

mdsumner commented 6 years ago

To be more generally useable quadmesh should provide the index, and allow the triangulated version as an alternative. So a ncol*nrow grid of any kind has two index options: quads, triangles. The quads are implicit against the centres being offset half cell out, but the triangles are trivial.

Both are segment-modulo logic and readily vectorized.

This will simplify turning rectilinear axes and 2D grids of coordinates into meshes, with the obvious AREA vs. POINT distinction.

mdsumner commented 6 years ago

This turns out to be really simple, this creates rgl mesh just to demo but will work trivially with mesh_plot. Technically there's no need to actually use triangulation code, but I can't handle the index atm


  tri <- RTriangle::triangulate(RTriangle::pslg(P = cbind(raster::colFromCell(x, seq_len(raster::ncell(x))),
                                                          raster::rowFromCell(x, seq_len(raster::ncell(x))))))

  o <- structure(list(vb = t(cbind(coords, raster::values(x), 1)),
            it = t(tri$T),
            primitivetype = "triangle",
            material = list(),
            normals = NULL,
            texcoords = NULL), class = c("mesh3d", "shape3d"))

  rgl::open3d()
cols <- viridis::viridis(56)[scales::rescale(o$vb[3,o$it], c(1, 56))]

#print(str(cols))
  rgl::shade3d(o, col = cols)
  rgl::aspect3d(1, 1, .0001)  ## don't set z-exag to 0 ...
mdsumner commented 6 years ago

Worked example with quads and triangles in rgl and in grid here: http://rpubs.com/cyclemumner/421078

Use that to apply to stars