Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

vertexControl

Set attributes of vertices


Description

This is a function to produce actions in a web display. A playwidget or Shiny input control (e.g. a sliderInput control) sets a value which controls attributes of a selection of vertices.

Usage

vertexControl(value = 0, values = NULL, vertices = 1, attributes,
              objid, param = seq_len(NROW(values)) - 1, interp = TRUE)

Arguments

value

The value to use for input (typically input$value in a Shiny app.) Not needed with playwidget.

values

A matrix of values, each row corresponding to an input value.

vertices

Which vertices are being controlled? Specify vertices as a number from 1 to the number of vertices in the objid.

attributes

A vector of attributes of a vertex, from c("x", "y", "z", "red", "green", "blue", "alpha", "nx", "ny", "nz", "radii", "ox", "oy", "oz", "ts", "tt", "offset"). See Details.

objid

A single RGL object id.

param

Parameter values corresponding to each row of values.

interp

Whether to interpolate between rows of values.

Details

This function modifies attributes of vertices in a single object. The attributes are properties of each vertex in a scene; not all are applicable to all objects. In order, they are: coordinates of the vertex "x", "y", "z", color of the vertex "red", "green", "blue", "alpha", normal at the vertex "nx", "ny", "nz", radius of a sphere at the vertex "radius", origin within a texture "ox", "oy" and perhaps "oz", texture coordinates "ts", "tt".

Planes are handled specially. The coefficients a, b, c in the planes3d or clipplanes3d specification are controlled using "nx", "ny", "nz", and d is handled as "offset". The vertices argument is interpreted as the indices of the planes when these attributes are set.

If only one attribute of one vertex is specified, values may be given as a vector and will be treated as a one-column matrix. Otherwise values must be given as a matrix with ncol(values) == max(length(vertices), length(attributes)). The vertices and attributes vectors will be recycled to the same length, and entries from column j of values will be applied to vertex vertices[j], attribute attributes[j].

The value argument is translated into a row (or two rows if interp = TRUE) of values by finding its location in param.

Value

A list of class "rglControl" of cleaned up parameter values, to be used in an RGL widget.

Author(s)

Duncan Murdoch

Examples

saveopts <- options(rgl.useNULL = TRUE)

  theta <- seq(0, 6*pi, len=100)
  xyz <- cbind(sin(theta), cos(theta), theta)
  plot3d(xyz, type="l")
  id <- spheres3d(xyz[1,,drop=FALSE], col="red")

  widget <- rglwidget(width=500, height=300) %>%
  playwidget(vertexControl(values=xyz,
                           attributes=c("x", "y", "z"),
                           objid = id, param=1:100),
             start = 1, stop = 100, rate=10)
  if (interactive() || in_pkgdown_example())
    widget
  options(saveopts)

rgl

3D Visualization Using OpenGL

v0.106.8
GPL
Authors
Duncan Murdoch [aut, cre], Daniel Adler [aut], Oleg Nenadic [ctb], Simon Urbanek [ctb], Ming Chen [ctb], Albrecht Gebhardt [ctb], Ben Bolker [ctb], Gabor Csardi [ctb], Adam Strzelecki [ctb], Alexander Senger [ctb], The R Core Team [ctb, cph], Dirk Eddelbuettel [ctb], The authors of Shiny [cph], The authors of knitr [cph], Jeroen Ooms [ctb], Yohann Demont [ctb], Joshua Ulrich [ctb], Xavier Fernandez i Marin [ctb], George Helffrich [ctb], Ivan Krylov [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.