[R] rgl: coordinating and saving viewpoints, zoom, scale for multiple images

Duncan Murdoch murdoch.duncan at gmail.com
Fri Dec 17 23:40:59 CET 2010


On 17/12/2010 5:08 PM, Michael Friendly wrote:
> Context: I have two or more rgl-based views of a given data set, perhaps
> fitting different
> models, or showing different things across views.  I want to be able to
> hand-rotate, zoom, scale
> one view to something I like, and then show the other views with
> matching viewpoints and scaling.
> so that one could flip back/forth among graphs and see only the relevant
> differences.
>
> In 2D, all this usually requires is setting the same xlim, ylim and
> other constant aspects across
> multiple graphs.
>
> In 3D with rgl, I can do one graph, rotate, zoom, etc.  by hand
> and capture the viewpoint with par3d("userMatrix"),
> but I can't figure out how to save the zoom and scale values to
> reproduce that viewpoint in another
> graph, in a way I could feed to view3d or rgl.viewpoint and get an
> equivalent view of the new data/model.
>
> An example follows, but I don't know how to capture in code what I did
> manually to get graph 1 in the orientation,
> zoom and scaling to re-create in another session or another graph....
> Which is why I'm asking for R-help.
>
> library(vcdExtra)
> HEC<- HairEyeColor[,c(1,3,4,2),]
> # graph 1
> mosaic3d(HEC)
>
> # hand rotate, scale, then save orientation; make sure rgl window is not
> hidden
> #snapshot3d("HEC3D-1a.png", top=TRUE)
> M1a<- par3d("userMatrix")

Also save "zoom", and possibly "FOV".  (Those are the three 
characteristics set by the default buttons.)

M1a <- par3d(c("userMatrix", "zoom", "FOV"))

>
> # try to make this reproducible, across sessions
> #>  dput(M1a)
> #structure(c(0.890118718147278, 0.105095967650414, -0.44344499707222,
> #0, -0.454265862703323, 0.282511830329895, -0.84488445520401,
> #0, 0.0364845432341099, 0.953489363193512, 0.299210667610168,
> #0, 0, 0, 0, 1), .Dim = c(4L, 4L))
> #>
> M1a<-
> structure(c(0.890118718147278, 0.105095967650414, -0.44344499707222,
> 0, -0.454265862703323, 0.282511830329895, -0.84488445520401,
> 0, 0.0364845432341099, 0.953489363193512, 0.299210667610168,
> 0, 0, 0, 0, 1), .Dim = c(4L, 4L))
>
> # graph 2
> mosaic3d(HEC, type="expected")
> # present this in the same orientation
> par3d(userMatrix=M1a)

To restore everything in the list of attributes, just use par3d(M1a).

Duncan Murdoch

>
>
>
>



More information about the R-help mailing list