dmurdoch/rgl

selection styling does not apply to all points

gitdemont opened this issue · 6 comments

Hi,

Running a slightly modified version of rglshared example, you can see that selecting points does not induce text label to appear despite being well selected in javascript. See attached screen shot, 2 points are selected but only one text appears
rglshared

In addition, the first time I ran this example I got a warning saying Combining widgets requires the 'manipulateWidget' package.
But the execution of rglShared example is not conditioned on manipulateWidget package (it is conditioned on crosstalk)

The manipulateWidget package is used to place the button below the plot: those are the widgets being "conbined". Regarding the labels, I'd need some reproducible code to diagnose the issue.

Sorry @dmurdoch for the poor reproducibility of the screenshot, here is the code that allows to see the problem

library(rgl)

save <- options(rgl.useNULL = TRUE)
tryCatch({
  n = 400
  set.seed(42)
  
  open3d()
  x <- sort(rnorm(n))
  y <- rnorm(n)
  z <- rnorm(n) + atan2(x, y)
  ids <- plot3d(x, y, z, col = "black")
  sharedData <- rglShared(ids["data"])
  sharedLabel <- rglShared(text3d(x, y, z, text = 1:n, adj = -0.5),
                           group = sharedData$groupName(),
                           deselectedFade = 0,
                           selectedIgnoreNone = FALSE) 
  str(par3d(), vec.len = 100)
  if(interactive())  rglMouse(rglwidget(shared = list(sharedLabel)))
}, finally = {
  options(save)
  print(sessionInfo())
})

str(par3d(), vec.len = 100) gives

List of 24
 $ antialias     : int 8
 $ FOV           : num 30
 $ ignoreExtent  : logi FALSE
 $ listeners     : int 7
 $ mouseMode     : Named chr [1:5] "none" "trackball" "zoom" "fov" "pull"
  ..- attr(*, "names")= chr [1:5] "none" "left" "right" "middle" "wheel"
 $ observer      : num [1:3] 0 0 32.5
 $ modelMatrix   : num [1:4, 1:4] 1.345 0 0 0 0 0.42 -1.153 0 0 0.704 0.256 0 0.196 -0.166 -32.398 1
 $ projMatrix    : num [1:4, 1:4] 3.73 0 0 0 0 3.73 0 0 0 0 -3.86 -1 0 0 -117.07 0
 $ skipRedraw    : logi FALSE
 $ userMatrix    : num [1:4, 1:4] 1 0 0 0 0 0.342 -0.94 0 0 0.94 0.342 0 0 0 0 1
 $ userProjection: num [1:4, 1:4] 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
 $ scale         : num [1:3] 1.345 1.227 0.749
 $ viewport      : Named int [1:4] 0 0 256 256
  ..- attr(*, "names")= chr [1:4] "x" "y" "width" "height"
 $ zoom          : num 1
 $ bbox          : num [1:6] -2.99 2.7 -3.02 3.23 -4.94 5.29
 $ windowRect    : int [1:4] 0 0 256 256
 $ family        : chr "sans"
 $ font          : int 1
 $ cex           : num 1
 $ useFreeType   : logi FALSE
 $ fontname      : chr "NULL"
 $ maxClipPlanes : int 2147483647
 $ glVersion     : num NA
 $ activeSubscene: int 0

sessionInfo()

R version 4.1.3 (2022-03-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rgl_0.109.16

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.9              rstudioapi_0.13         knitr_1.39             
 [4] magrittr_2.0.3          xtable_1.8-4            R6_2.5.1               
 [7] rlang_1.0.4             fastmap_1.1.0           tools_4.1.3            
[10] xfun_0.32               miniUI_0.1.1.1          cli_3.2.0              
[13] htmltools_0.5.3         crosstalk_1.2.0         ellipsis_0.3.2         
[16] digest_0.6.29           lifecycle_1.0.1         shiny_1.7.1.9003       
[19] later_1.3.0             base64enc_0.1-3         htmlwidgets_1.5.4      
[22] promises_1.2.0.1        manipulateWidget_0.11.1 evaluate_0.16          
[25] mime_0.12               rmarkdown_2.10          compiler_4.1.3         
[28] jsonlite_1.8.0          httpuv_1.6.5     

However, I did not find an easy way to extract vertices of the selecting rectangle so as to programatically create it for a fully reproducible example. So one still have to make the selection manually here (according to the screenshot). If you have some directions about how to do this, I would be very pleased to learn it, though.

Concerning the manipulateWidget part, what I meant is don't you think that rglShared example execution should be conditionned on its presence with something like ?

if (requireNamespace("crosstalk", quietly = TRUE) && requireNamespace("manipulateWidget", quietly = TRUE)) { # so on, ...

Thanks for the clarification. I think you're right on both issues.

What I believe is happening with the missing label is that it is being culled because it is computed to be outside the viewable area. If you set deselectedFade = 0.5 you won't see the label on that point whether it is selected or not. From the looks of it, this is wrong: so I'll need to try to figure out where the miscalculation happens. It's a problem with text3d(adj = -0.5, ...) rather than with selection.

I tried to track where it could come from so I installed various version of rgl and tested the example
But I think the following will introduce even more confusion:

remotes::install_version("rgl", "0.107.14", dependencies = FALSE, INSTALL_opts = "--no-multiarch") # OK v0.107.14
# remotes::install_github("dmurdoch/rgl", "980963beaef91f7b6d3bff4dfb451ca5859ecc62", dependencies = FALSE, INSTALL_opts = "--no-multiarch") # Not OK v0.107.13
# remotes::install_github("dmurdoch/rgl", "016098b39c36961b15841a1b634042c2ff081687", dependencies = FALSE, INSTALL_opts = "--no-multiarch") # Not OK v0.107.15
# remotes::install_version("rgl", "0.108.3", dependencies = FALSE, INSTALL_opts = "--no-multiarch") # Not OK v 0.108.3

On CRAN, the last version that did work is 0.107.14 (2021-08-21 17:20) then next CRAN release 0.108.3 (2021-11-21 18:40) does not

However, I was not able to find 0.107.14 on this date on github, but we have:
-0.107.13 commit 2021-07-28 which is surprisingly not working (surprisingly, because I would have expect that a version earlier than 0.107.14 would work)
-0.107.15 commit 2021-08-21 which is also not working

Maybe I did an error somewhere or forgot to restart R session 🙄

The bug arrived when 3D adj values were added, back in July 2021. The intention was that a value of 0.5 should indicate that the text label has the same coordinate value as the point. This is properly implemented for X and Y offsets, but for Z it appears that somewhere along the way, a value of 0 became needed to specify the same Z value as the point, while the default is 0.5.

That means labels default to a different depth than the point. Apparently for the point that didn't get a label, the depth was so great that the point was culled.

A temporary workaround is to set adj = c(-0.5, 0.5, 0) in the text3d() call. Then all labels should appear.

There are two possible fixes here: I could change the documentation and the default value to 0 , so the temporary workaround would continue to work. Or I could track down where the error entered and fix it. I'm inclined to fixing the error, but I might go the other way.

From what you mentionned, it looks related to commit

Is it good to play with ?

gl.uniform3f( obj.textScaleLoc, 0.75/this.vp.width, 0.75/this.vp.height, 1.0);

gl.uniform3f( obj.textScaleLoc, 0.75/this.vp.width, 0.75/this.vp.height, 0.75);