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

selectpoints3d

Select points from a scene


Description

This function uses the select3d function to allow the user to choose a point or region in the scene, then reports on all the vertices in or near that selection.

Usage

selectpoints3d(objects = ids3d()$id, value = TRUE, closest = TRUE, 
               multiple = FALSE, ...)

Arguments

objects

A vector of object id values to use for the search.

value

If TRUE, return the coordinates of the points; otherwise, return their indices.

closest

If TRUE, return the points closest to the selection of no points are exactly within it.

multiple

If TRUE or a function, do multiple selections. See the Details below.

...

Other parameters to pass to select3d.

Details

The multiple argument may be a logical value or a function. If logical, it controls whether multiple selections will be performed. If multiple is FALSE, a single selection will be performed; it might contain multiple points. If TRUE, multiple selections will occur and the results will be combined into a single matrix.

If multiple is a function, it should take a single argument. This function will be called with the argument set to a matrix containing newly added rows to the value, i.e. it will contain coordinates of the newly selected points (if value = TRUE), or the indices of the points (if value = FALSE). It should return a logical value, TRUE to indicate that selection should continue, FALSE to indicate that it should stop.

In either case, if multiple selections are being performed, the ESC key will stop the process.

Value

If value is TRUE, a 3-column matrix giving the coordinates of the selected points. All rows in the matrix will be unique even if multiple vertices have the same coordinates.

If value is FALSE, a 2-column matrix containing columns:

id

The object id containing the point.

index

The index of the point within rgl.attrib(id, "vertices"). If multiple points have the same coordinates, all indices will be returned.

Author(s)

Duncan Murdoch

See Also

select3d to return a selection function.

Examples

xyz <- cbind(rnorm(20), rnorm(20), rnorm(20))
ids <- plot3d( xyz )

if (interactive()) {
  # Click near a point to select it and put a sphere there.
  # Press ESC to quit...

  # This version returns coordinates
  selectpoints3d(ids["data"], 
     multiple = function(x) {
        spheres3d(x, color = "red", alpha = 0.3, radius = 0.2)
        TRUE
     })

  # This one returns indices
  selectpoints3d(ids["data"], value = FALSE,
     multiple = function(ids) {
        spheres3d(xyz[ids[, "index"], , drop = FALSE], color = "blue", 
                  alpha = 0.3, radius = 0.2)
        TRUE
     })
}

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.