Jean-Romain / lidRviewer

An OpenGL point cloud viewer for R able to handle several millions of points

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Github licence

This is a point cloud viewer for R. The first goal of this package is to be an alternative backend to display point clouds in the lidR package in replacement of rgl. It is fully supported but one may consider that this package is under development (it works good enough to me but still have bugs).

rgl is an awesome package but has some difficulties displaying large point clouds. The lidRviewer package is able to display large point clouds consisting of several million points. So far I have tried it with over 30 million points and the display window remained fluid (smoothly pan, zoom and rotate).

Advantage of lidRviewer:

  • Can easily handle more than 20 million points while rgl can struggle displaying a tenth of that.
  • Is much more memory efficient. It allocates only a small amount of additional memory while rgl may require gigabytes of memory.

Drawbacks

  • Blocks the R session. If the viewer windows is open, you can't use R for anything else. You must close the viewer windows first.
  • Can only display point clouds. No other feature. This is only a point cloud displayer so not intended as a replacement for rgl

Installation

lidRviewer is based on the OpenGL and the SDL librairies. You must install both first.

GNU/Linux

sudo apt-get install libsdl-dev freeglut3-dev
devtools::install_github("Jean-Romain/lidRviewer")

Windows

We successfully installed the package on Windows machines. As always things are much harder on Windows but we wrote an automatic installation script that install the SDL and build the package.

  1. Make sure you have a C++ compiler. On Windows you must install Rtools.exe. You also need to install the remotes package to build this package.

  2. Run the following script by openning R (or Rstudio) as administrator. This script downloads the SDL library and installs it along with R (R belongs in a folder where only an adminitrator can write).

source("https://raw.githubusercontent.com/Jean-Romain/lidRviewer/master/sdl.R")
  1. Once it is done, install the lidRviewer package with remotes as usual:
remotes::install_github("Jean-Romain/lidRviewer")

MacOS

I don't know. Input from MacOS users will be appreciated.

Usage

library(lidR)
LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
las <- readLAS(LASfile)
plot(las, backend = "lidRviewer")
  • Rotate with left mouse button
  • Zoom with mouse wheel
  • Pan with right mouse button

How it works

Displaying huge point clouds in real time is a complex task. Advanced techniques often rely on Octrees to selectively display points within the camera field of view. These techniques are smart but not really appropriate for my low memory usage requirements. Considering how R stores data, constructing an Octree would require a full copy of the point cloud. This package uses some very naive optimization to render large point clouds in pseudo-real time:

  • When users rotate/pan/zoom it only displays a maximum of 2 million points, which allows for smooth, fluid movement of the display.
  • When the program finds a few milliseconds of free time between two events it progressively densifies the point cloud until the entire point cloud is displayed. This allows the user to rotate/pan/zoom again before the end of the rendering.
  • It uses a pointer to the R memory and does not create any copy. The memory allocated for the rendering is therefore reduced to a few megabytes independently of the point cloud size.

So far it works well on my tests and the package can display as many points as the user wants (I stopped my tests after 35 million points [~1GB]).

Benchmark

On a core i7 with 11 million points.

Package Time (s) Alloc mem Fluid
rgl 15-20 1.2 GB no
lidRviewer < 1 1.0 MB yes

'Time' is the time taken to open the Windows. 'Alloc mem' is the extra memory allocated by the call. 'Fluid' means you can rotate and zoom freely.

About

An OpenGL point cloud viewer for R able to handle several millions of points


Languages

Language:C++ 67.1%Language:R 31.5%Language:C 1.4%