How do you pick point in a point cloud?

Sorry if this is obvious but how do you pick points in a point-cloud using Cesium.

Specifically I would like to cast a ray through the full point-cloud and return all the points within some distance (d) of the ray. Ideally want to do this fast by raycasting against the octree first and then only consider points in the intersecting octree leaves.

Welcome to the Cesium forum Nicholas!

CesiumJS has a built-in picking system for doing this kind of thing efficiently (by capturing the depth buffer and extracting the coordinates from there). As a consequence, the picked position is the visual position which may be slightly off from the stored coordinate (if the points have attenuation for example). You can read more about this issue here: https://github.com/CesiumGS/cesium/issues/7953

I think you may be able to use scene.pick to get the tile that was clicked on, and then read all the point information inside that tile. CesiumJS doesn’t keep the point coordinates on the CPU once they’ve been uploaded to the GPU as a buffer, so you may need to do additional work there to retrieve that.

Omar 's absolutely right.
Here’s a sample implement it.

Point Cloud Picking Sample

Just adding some notes that picking on a pointcloud is not straight forward, mainly two things;

  1. Picking a point accurately is very dependant on how disperse your cloud is. You’ll find you’ll often fall through the cracks, hitting points further down but most likely on the globe itself. (To fix this you need to create a scatter picker yourself, use some statistics to pick three or more points around a point, find the average, discard the outliners, convert to Carto for height, etc.)

  2. Using something like pickPosition() picks very differently to other picking methods, so you might use pick() to find you’re on top of a pointcloud, but then pickPosition() on the same coordinate might easily fall through to the globe (or other things).

  3. You don’t have access to the profile of the pointcloud through the normal API. I haven’t dug too far into the terrain pickers too much, but again I think it’s mostly about surface picking, not profiling. A way around this would be to create a clipping plane (I’d shape it as a tube), and pick accurately along it. You probably could also look into colorising pointclouds where you can control the visibility of the points (and colorise them) to certain properties, and pull the information out that way, but again the docos are a bit sparse on this.

Cheers,

Alex

1 Like