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

select3d

Select a rectangle in an RGL scene


Description

This function allows the user to use the mouse to select a region in an RGL scene.

Usage

rgl.select3d(button = c("left", "middle", "right"),
             dev = cur3d(), subscene = currentSubscene3d(dev))
select3d(...)
selectionFunction3d(proj, region = proj$region)

Arguments

button

Which button to use for selection.

dev, subscene

The RGL device and subscene to work with

...

Button argument to pass to rgl.select3d

proj

An object returned from rgl.projection containing details of the current projection.

region

Corners of a rectangular region in the display.

Details

select3d and rgl.select3d select 3-dimensional regions by allowing the user to use a mouse to draw a rectangle showing the projection of the region onto the screen. They return a function which tests points for inclusion in the selected region.

selectionFunction3d constructs such a test function given coordinates and current transformation matrices.

If the scene is later moved or rotated, the selected region will remain the same, though no longer corresponding to a rectangle on the screen.

Value

All of these return a function f(x, y, z) which tests whether each of the points (x, y, z) is in the selected region, returning a logical vector. This function accepts input in a wide variety of formats as it uses xyz.coords to interpret its parameters.

Author(s)

Ming Chen / Duncan Murdoch

See Also

Examples

# Allow the user to select some points, and then redraw them
# in a different color

if (interactive()) {
 x <- rnorm(1000)
 y <- rnorm(1000)
 z <- rnorm(1000)
 open3d()
 points3d(x, y, z)
 f <- select3d()
 if (!is.null(f)) {
   keep <- f(x, y, z)
   pop3d()
   points3d(x[keep], y[keep], z[keep], color = 'red')
   points3d(x[!keep], y[!keep], z[!keep])
 }
}

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.