Michael Friendly
2010-Dec-17 22:08 UTC
[R] rgl: coordinating and saving viewpoints, zoom, scale for multiple images
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") # 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) -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Street Web: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA
Dieter Menne
2010-Dec-17 22:39 UTC
[R] rgl: coordinating and saving viewpoints, zoom, scale for multiple images
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. > ... >It's late here, so I might be missing your point, but maybe this helps Dieter # ----------------- saveSettings ---------------------------------------------- saveSettings = function(){ if (rgl.cur()>0) { par3 = par3d(no.readonly=TRUE) save(par3,file=Pdata) } } ...... if (file.exists(Pdata)) load(Pdata,envir=.GlobalEnv) else cat(Pdata, "No settings file found; using defaults\n") -- View this message in context: http://r.789695.n4.nabble.com/rgl-coordinating-and-saving-viewpoints-zoom-scale-for-multiple-images-tp3093195p3093224.html Sent from the R help mailing list archive at Nabble.com.
Duncan Murdoch
2010-Dec-17 22:40 UTC
[R] rgl: coordinating and saving viewpoints, zoom, scale for multiple images
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> > > >
Reasonably Related Threads
- problem in applying function in data subset (with a level) - using plyr or other alternative are also welcome
- lmer and negative binomial family
- System GMM yields identical results for any weighting matrix
- System GMM yields identical results for any weighting matrix
- lme4_0.995-2/Matrix_0.995-4 upgrade introduces error messages (change management)