Skip to contents

Convenience helper for vignettes and reports: renders a surface with view_surface() onto an off-screen rgl device and saves a PNG. When rgl.useNULL() is TRUE (headless builds), a proper snapshot requires the webshot2 package; otherwise a blank image is likely and an empty path is returned.

Usage

snapshot_surface(surfgeom, file = NULL, width = 1200, height = 900, ...)

Arguments

surfgeom

A SurfaceGeometry object.

file

Output path for the PNG. Defaults to the current knitr figure path when knitting, otherwise a temporary file.

width, height

Device size in pixels (controls render resolution).

...

Additional arguments passed to view_surface.

Value

The file path (invisibly). Callers can use knitr::include_graphics() or read the image via png::readPNG(). In headless mode without webshot2, an empty character vector is returned.

Examples

# \donttest{
fs <- load_fsaverage_std8("inflated")
#> loading /private/var/folders/9h/nkjq6vss7mqdl4ck7q1hd8ph0000gp/T/RtmpFhvBlN/temp_libpathff9947c5f204/neurosurf/extdata/std.8_lh.inflated.asc
#> loading /private/var/folders/9h/nkjq6vss7mqdl4ck7q1hd8ph0000gp/T/RtmpFhvBlN/temp_libpathff9947c5f204/neurosurf/extdata/std.8_rh.inflated.asc
img <- snapshot_surface(fs$lh, viewpoint = "lateral", specular = "black")
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: rgl.useNULL=TRUE and webshot2 not installed; snapshot unavailable in headless builds.
# }