Learn R Programming

quadmesh (version 0.5.5)

triangmesh: Create a triangle-type mesh for use in rgl.

Description

Convert an object to a mesh3d (of rgl package) triangle mesh, with methods for raster::raster() and matrix.

Usage

triangmesh(
  x,
  z = x,
  na.rm = FALSE,
  ...,
  texture = NULL,
  texture_filename = NULL
)

# S3 method for matrix triangmesh( x, z = x, na.rm = FALSE, ..., texture = NULL, texture_filename = NULL )

# S3 method for BasicRaster triangmesh( x, z = x, na.rm = FALSE, ..., texture = NULL, texture_filename = NULL )

dtriangmesh( x, z = x, na.rm = FALSE, ..., texture = NULL, texture_filename = NULL )

# S3 method for default dtriangmesh( x, z = x, na.rm = FALSE, ..., texture = NULL, texture_filename = NULL )

Value

mesh3d (primitivetype triangle)

Arguments

x

raster object for mesh structure

z

raster object for height values

na.rm

remove quads where missing values?

...

ignored

texture

optional input RGB raster, 3-layers

texture_filename

optional input file path for PNG texture

Details

triangmesh() generates the point-based interpretation of a raster (POINT) with the obvious continuous interpretation. dtriangmesh splits the mesh so that each primitive is independent. This is more coherent than the analogous distinction for quadmesh, though both will appear the same on creation.

The output is described as a mesh because it is a dense representation of a continuous shape, in this case plane-filling triangles defined by index of three of the available vertices.

The z argument defaults to the input x argument, though may be set to NULL, a constant numeric value, or another raster. If the coordinate system of z and x don't match the z values are queried by reprojection.

Any raster RGB object (3-layers, ranging in 0-255) may be used as a texture on the resulting mesh3d object. It is not possible to provide rgl with an object of data for texture, it must be a PNG file and so the in-memory texture argument is written out to PNG file (with a message). The location of the file may be set explicitly with texture_filename. Currently it's not possible to not use the texture object in-memory.

Examples

Run this code
library(raster)
r <- setExtent(raster(volcano), extent(0, nrow(volcano), 0, ncol(volcano)))
tm <- triangmesh(r)

## jitter the mesh just enough to show that they are distinct in the discrete case
a <- dtriangmesh(r)
a$vb[3L, ] <- jitter(a$vb[3L, ], factor = 10)

Run the code above in your browser using DataLab