Title: | Voxel Rendering with Isometric Cubes |
---|---|
Description: | Visualising three-dimensional voxel data. |
Authors: | Mike Cheng [aut, cre, cph] |
Maintainer: | Mike Cheng <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.5.9009 |
Built: | 2024-11-29 06:32:23 UTC |
Source: | https://github.com/coolbutuseless/isocubes |
Calculate isocubes coordinates from a height matrix
coords_heightmap( mat, fill = NULL, scale = 1, flipx = FALSE, flipy = TRUE, ground = "xz", solid = TRUE, check_visibility = FALSE, verbose = FALSE )
coords_heightmap( mat, fill = NULL, scale = 1, flipx = FALSE, flipy = TRUE, ground = "xz", solid = TRUE, check_visibility = FALSE, verbose = FALSE )
mat |
integer matrix. The matrix will be interpreted as cubes flat on the page, with the value in the matrix interpreted as the height above the page. |
fill |
matrix of colours the same dimensions as the |
scale |
scale factor for values in matrix. Default = 1 |
flipx , flipy
|
Should the matrix be flipped in the horizontal/vertical directions (respectively)?
Default: Note: |
ground |
Orientation of the ground plane. Default: 'xz'. Possible values 'xz', 'xy' |
solid |
Should the heightmap be made 'solid' i.e. without holes? default: TRUE. This can be an expensive operation in terms of both memory and CPU, but should be OK for simple examples. Set to FALSE if things take too long. This operation works by extruding cubes down from the top of the height map to the floor to ensure gaps do not appear when the slope is too great. |
check_visibility |
Should non-visible cubes be removed? Default: FALSE. If you plan on rotating or manipulating the returned coordinates then this should definitely by FALSE. If TRUE, then non-visible voxels will be entirely removed from the returned coordinates i.e. they will be missing if you change the rendering viewpoint from the default. |
verbose |
Be verbose? default: FALSE |
data.frame of isocube coordinates
# Plot the standard volcano mat <- volcano mat[seq(nrow(mat)),] <- mat[rev(seq(nrow(mat))),] val <- as.vector(mat) val <- round(255 * (val - min(val)) / diff(range(val))) fill <- matrix("", nrow=nrow(mat), ncol=ncol(mat)) fill[] <- terrain.colors(256)[val + 1L] coords <- coords_heightmap(mat - min(mat), fill = fill, scale = 0.3) cubes <- isocubesGrob(coords, size = 2) grid::grid.draw(cubes)
# Plot the standard volcano mat <- volcano mat[seq(nrow(mat)),] <- mat[rev(seq(nrow(mat))),] val <- as.vector(mat) val <- round(255 * (val - min(val)) / diff(range(val))) fill <- matrix("", nrow=nrow(mat), ncol=ncol(mat)) fill[] <- terrain.colors(256)[val + 1L] coords <- coords_heightmap(mat - min(mat), fill = fill, scale = 0.3) cubes <- isocubesGrob(coords, size = 2) grid::grid.draw(cubes)
Create a grob of isocubes
isocubesGrob( coords, fill = NULL, fill_left = NULL, fill_right = NULL, intensity = c(1, 0.3, 0.7), size = 5, x = NULL, y = NULL, col = "black", default.units = "npc", default.units.cube = "mm", xyplane = "right", handedness = "left", verbosity = 0, ... )
isocubesGrob( coords, fill = NULL, fill_left = NULL, fill_right = NULL, intensity = c(1, 0.3, 0.7), size = 5, x = NULL, y = NULL, col = "black", default.units = "npc", default.units.cube = "mm", xyplane = "right", handedness = "left", verbosity = 0, ... )
coords |
data.frame of x,y,z coordinates for the cubes (integer coordinates) |
fill |
fill colour for the top face of cube. Default: NULL will attempt to use the 'fill' colour in the coords data.frame, otherwise 'grey50' |
fill_left , fill_right
|
fill colours for left and fight faces of cube. |
intensity |
c(1, 0.3, 0.6) Intensity shading for |
size |
dimensions of cube i.e. the length of the vertical edge of the cube. Default: 5mm |
x , y
|
the origin of the isometric coordinate system in 'snpc' coordinates.
These values should be given as vanilla floating point values.
Be default the origin is the middle bottom of the graphics device
i.e. |
col |
Stroke colour for outline of cube faces. Default: black. If |
default.units |
Default unit for (x,y) position is 'npc' |
default.units.cube |
Default unit for size of a cube is 'mm' |
xyplane |
How is the xyplane oriented with respect to the unit isometric cube?. "left", "right", "top" (or "flat"). Default: "right" |
handedness |
How is the z-axis positioned with respect to the xy-plane? I.e. is this a right-handed or left-handed coordinate system? Default: "left" |
verbosity |
Verbosity level. Default: 0 |
... |
other values passed to |
grid grob
object
coords <- sphere_coords fill <- rainbow(nrow(coords)) iso <- isocubesGrob(coords, fill = fill, size = 2) grid::grid.draw(iso) coords <- organic_coords iso <- isocubesGrob(coords, size = 2) grid::grid.newpage() grid::grid.draw(iso)
coords <- sphere_coords fill <- rainbow(nrow(coords)) iso <- isocubesGrob(coords, fill = fill, size = 2) grid::grid.draw(iso) coords <- organic_coords iso <- isocubesGrob(coords, size = 2) grid::grid.newpage() grid::grid.draw(iso)
Isometrix grid of lines
isolinesGrob( N = 50, size = 5, x = NULL, y = NULL, col = "black", default.units = "npc", default.units.cube = "mm", verbosity = 0, ... )
isolinesGrob( N = 50, size = 5, x = NULL, y = NULL, col = "black", default.units = "npc", default.units.cube = "mm", verbosity = 0, ... )
N |
extents |
size |
dimensions of cube i.e. the length of the vertical edge of the cube. Default: 5mm |
x , y
|
the origin of the isometric coordinate system in 'snpc' coordinates.
These values should be given as vanilla floating point values.
Be default the origin is the middle bottom of the graphics device
i.e. |
col |
Stroke colour for outline of cube faces. Default: black. If |
default.units |
Default unit for (x,y) position is 'npc' |
default.units.cube |
Default unit for size of a cube is 'mm' |
verbosity |
Verbosity level. Default: 0 |
... |
other values passed to |
isometric line grid
grid <- isolinesGrob() grid::grid.draw(grid)
grid <- isolinesGrob() grid::grid.draw(grid)
Isometric grid of points
isopointsGrob( N = 50, size = 5, x = NULL, y = NULL, col = "black", pch = ".", default.units = "npc", default.units.cube = "mm", verbosity = 0, ... )
isopointsGrob( N = 50, size = 5, x = NULL, y = NULL, col = "black", pch = ".", default.units = "npc", default.units.cube = "mm", verbosity = 0, ... )
N |
extents |
size |
dimensions of cube i.e. the length of the vertical edge of the cube. Default: 5mm |
x , y
|
the origin of the isometric coordinate system in 'snpc' coordinates.
These values should be given as vanilla floating point values.
Be default the origin is the middle bottom of the graphics device
i.e. |
col |
Stroke colour for outline of cube faces. Default: black. If |
pch |
plotting character. default '.' |
default.units |
Default unit for (x,y) position is 'npc' |
default.units.cube |
Default unit for size of a cube is 'mm' |
verbosity |
Verbosity level. Default: 0 |
... |
other values passed to |
isometric point grid
grid <- isopointsGrob() grid::grid.draw(grid)
grid <- isopointsGrob() grid::grid.draw(grid)
Voxel coordinates for an organic shape
organic_coords
organic_coords
An object of class tbl_df
(inherits from tbl
, data.frame
) with 14292 rows and 4 columns.
Other datasets:
r_coords
,
sphere_coords
head(organic_coords) cubes <- isocubesGrob(organic_coords, size = 2) grid::grid.newpage() grid::grid.draw(cubes)
head(organic_coords) cubes <- isocubesGrob(organic_coords, size = 2) grid::grid.newpage() grid::grid.draw(cubes)
Voxel coordinates for a sphere
r_coords
r_coords
An object of class data.frame
with 68 rows and 3 columns.
Other datasets:
organic_coords
,
sphere_coords
head(r_coords) cubes <- isocubesGrob(r_coords, size = 5, y = 0) grid::grid.newpage() grid::grid.draw(cubes)
head(r_coords) cubes <- isocubesGrob(r_coords, size = 5, y = 0) grid::grid.newpage() grid::grid.draw(cubes)
Voxel coordinates for a sphere
sphere_coords
sphere_coords
An object of class tbl_df
(inherits from tbl
, data.frame
) with 17071 rows and 3 columns.
Other datasets:
organic_coords
,
r_coords
head(sphere_coords) cubes <- isocubesGrob(sphere_coords, size = 2) grid::grid.newpage() grid::grid.draw(cubes)
head(sphere_coords) cubes <- isocubesGrob(sphere_coords, size = 2) grid::grid.newpage() grid::grid.draw(cubes)