r-lidar / lidR

Airborne LiDAR data manipulation and visualisation for forestry application
https://CRAN.R-project.org/package=lidR
GNU General Public License v3.0
587 stars 132 forks source link

plot las file zoomed in instead of overview #681

Closed wiesehahn closed 1 year ago

wiesehahn commented 1 year ago

To inspect las data visually sometimes we want to plot an overview of the LASfile, plot(las) will do this by default. But sometimes its also necessary to inspect the point cloud in full detail at some point. Of course we can interactively zoom in the plotted point cloud, but this is a little tedious for large files.

Would it be possible to implement something like lidR::plot(las, zoom=TRUE) to plot the las files zoomed in at the center with a certain "resolution" (maybe based on point density)? Or something like lidR::plot(las, zoom=c(x,y,z)) to start with a view at a certain location?

Jean-Romain commented 1 year ago

This is a too specific feature. I won't implement it unless I find broader use cases. However I can make you a prototype function. It needs some refinement but it works

plot_las = function(las, zoom = 1, at = "auto", ...)
{
  if (is.character(at) && at == "auto")
    at =  c(0.5, 0.5) %*% matrix(rgl::par3d("bbox"), 2, 3) 

  plot(las, clear_artifacts = FALSE, ...)
  center <- c(0.5, 0.5) %*% matrix(rgl::par3d("bbox"), 2, 3) 
  trans <- center - at
  userMatrix <- rgl::par3d()$userMatrix
  userMatrix <- userMatrix %*% t(rgl::translationMatrix(trans[1], trans[2], trans[3]))
  rgl::view3d(zoom = zoom, userMatrix = userMatrix)
}

at = as.numeric(sf::st_coordinates(las[26360])) 
plot_las(las, zoom = 0.25, at = at)
wiesehahn commented 1 year ago

ok, strangely zoom=1 is zoomed out quite far in my case, but a value of 0.00001 results in a zoomed view with your function.

But

plot(las)
rgl::view3d(zoom=0.2)

also does the trick of zooming in without scolling forever. Thats more or less what I was looking for.

Jean-Romain commented 1 year ago

My function also center on the point of interest. that's why it is more complex than using only rgl::view3d(zoom=0.2)