View source: R/plot-mesh-polygon.R
| plot_mesh_polygon | R Documentation |
Projects each triangular face onto a 2D plane using an orthographic camera,
shades it with a single color proportional to how directly it faces the
camera (Lambert), depth-sorts all faces across all meshes, and draws them
in a single polygon call.
Meshes without faces (point clouds) are substituted by a small sphere
(vcg_sphere) centered at each point and scaled by
cex; they then participate in the same rendering pipeline as ordinary
faced meshes.
A camera-facing clipping pass discards triangles whose outward normal
points along the camera ray (signed n \cdot z_{cam} > 1 - \mathrm{mesh\_clipping}),
peeling the front cap off the surface so the back wall (and any
interior meshes) become visible. Set mesh_clipping = 1 to disable
clipping. Point-cloud meshes (those rendered as substitute
vcg_sphere instances) are exempt from this clip so they
remain solid even when the enclosing surface is peeled.
Multiple meshes share a single depth space: all faces are projected, sorted, and drawn together so the painter's algorithm works correctly across meshes.
plot_mesh_polygon(
mesh,
eye = c(0, 0, 1000),
lookat = c(0, 0, 0),
up = c(0, 1, 0),
col = c("white", "gray30"),
cex = 1,
add = FALSE,
axes = FALSE,
asp = 1,
xlim = NULL,
ylim = NULL,
zoom = 1,
xlab = "",
ylab = "",
side = c("front", "back", "both"),
mesh_clipping = 1,
sphere_subdivision = 1L,
alpha = 1,
shadow_color = NULL,
light_intensity = 1,
ambient_intensity = 0.2,
clipping_plane = NULL,
clipping_plane_enabled = TRUE,
...
)
mesh |
a |
eye |
numeric vector of length 3 - camera position in world space. |
lookat |
numeric vector of length 3 - the world-space point the camera is looking at. |
up |
numeric vector of length 3 - world-space "up" direction; defaults
to |
col |
base color(s) per mesh. Same forms as
|
cex |
radius of the substitute sphere used for point-cloud meshes
(world units). Has no effect on meshes that already have faces. Default
|
add |
logical; if |
axes, asp, xlim, ylim, xlab, ylab |
passed to |
zoom |
positive numeric magnification applied to the auto-computed
axis limits when |
side |
which side of each triangle to render. One of |
mesh_clipping |
numeric in |
sphere_subdivision |
integer subdivision level forwarded to
|
alpha |
numeric in |
shadow_color |
color used for fully unlit (grazing/back) faces.
The Lambert shade linearly interpolates from |
light_intensity |
non-negative scalar controlling the brightness
of the (white) light source: at |
ambient_intensity |
scalar in |
clipping_plane |
optional list of world-space clipping planes used to
hide parts of the scene. Each plane is a numeric vector of length 5:
the first three entries are the plane normal |
clipping_plane_enabled |
logical vector, one entry per mesh
(recycled), controlling whether |
... |
additional graphical parameters forwarded to
|
Limitations of the base-R polygon path (no rgl):
Flat shading only - one color per triangle. No per-vertex color interpolation.
No depth buffer - faces are depth-sorted by centroid (painter's algorithm). Interpenetrating triangles can render in the wrong order.
Anti-aliasing seams can appear between adjacent triangles on
raster devices; Cairo-based devices (png(type = "cairo"),
svg(), pdf()) produce cleaner output than the default
quartz/X11 path.
Invisibly returns a list with components xlim and
ylim (the plot limits used).
The surface objects are converted to 'mesh3d' object before
applying further calculations.
When surface is a surface ieegio object, the returned
mesh3d$vb contains vertices that have been left-multiplied by
surface$geometry$transforms[[1]] (the first transform stored in the
geometry, typically the ScannerAnat or voxel-to-world transform).
Breaking change: Earlier versions (before 0.2.6) of ravetools
returned the raw surface$geometry$vertices without applying any
transform, so downstream code often multiplied by
surface$geometry$transforms[[1]] (or an equivalent) manually before
working in world space. Such code will now double
apply the transform and produce incorrect coordinates. If you previously
applied a transform from surface$geometry$transforms by hand after
calling a ravetools mesh function on an 'ieegio_surface',
remove that manual step.
Surfaces with an empty or missing geometry$transforms list (for
example, surfaces produced by ieegio's volume_to_surface,
which stores an identity transform) are unaffected.
If geometry$transforms contains multiple transforms targeting
different coordinate spaces, only the first one is used. Callers that need
a specific target space should select and apply that transform themselves
before calling ravetools mesh functions.
plot_mesh_dotcloud, vcg_isosurface
mesh <- vcg_isosurface(left_hippocampus_mask)
# Surface alone
plot_mesh_polygon(
mesh,
eye = c(150, 30, 0),
lookat = c(0, 0, 0),
up = c(0, 0, 1),
col = "steelblue"
)
# Surface + electrode point cloud (rendered as small icospheres)
n_elec <- 20
electrodes <- structure(
list(vb = matrix(rnorm(3 * n_elec, sd = 5), 3, n_elec) +
rowMeans(mesh$vb)[1:3]),
class = "mesh3d"
)
plot_mesh_polygon(
mesh = list(mesh, electrodes),
eye = c(150, -30, 0),
lookat = c(0, 0, 0),
up = c(0, 0, 1),
alpha = c(0.5, 1),
col = list("steelblue", "red"),
cex = 1.5
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.