What is the most efficient way to find out what primitives are visible


   I am using a large collection of PointPrimitive (currently in master). I am trying to show label on them when there is a small number of them in the current view. I can have up to 300K points so I am trying to find what would be the most efficient solution. Some areas will have very high point density so using the camera distance will not work well...



I looked at the thread above, however I did not see any closure as to whether that approach was good. Matt had the comment below but I did not see a follow up answer.

Matt wrote:

"Cesium does not actually know what billboards are visible. It only knows if any single billboard in a collection is visible and then everything else is done on the GPU and none of that information is retrievable.

Attempting to detect what visualisation is on the screen after the fact is almost always the wrong way to go about whatever problem you are encountering. (View based visualisation where you retrieve data or only create data for the visible view is a different story, i.e. streaming terrain/imagery/large vector data sets).

If you can explain your exact use case, I’d be happy to suggest some possible solutions; what feature/behaviour are you trying to implement?"



You can use the labels translucencyByDistance property to have labels only become visible when you get close to then, You can see this in action with the KML example: http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=KML.html&label=DataSources

Matt, Thanks for the reply… I don’t
think that will work for me. I am trying to limit the number of
labels I have to crete as I have close to 300K points. I was
hoping to use a pool of labels that i can attach to points that are
visible when there is a small number in view. I was able to
attach a label to a point when the mouse is over it and that worked
well. I was hoping I could use something similar if I could detect
when 20 or so points are in view. I noticed you guys just added
camera movement events I can use as trigger to check what points are
currently in view. I am trying to figure out what would be the most
efficient way to detect which point primitives are currently visible.



The technically correct way to do what you want is to only render visible points and labels using a quadtree, similar to how terrain and imagery are loaded. Cesium has an internal QuadTreePrimitive, but it’s not part of the public API. You can search the forums and find others using it, but in the longer term we will probably replace it with something different (but similar) and there’s no guarantee of release to release backwards compatibility. This approach is kind of the opposite what you asked for, Cesium tells you what part of the earth is in view and then you render the points/labels in that tile.

A poor-mans way to do what you want would be to listen to the viewChanged event and then get the 4 corner points of the screen and convert them to cartographic. Then iterate all of the points and make a label for the ones inside the rectangle. This will work as long as you have the entire earth on the screen, but it will not work for horizon views because you can’t produce the rectangle (and it’s a bad approach for horizon view anyway because the rectangle would be enormous).

Sorry there’s no easy answer here yet; we are planning on making this kind of thing trivial in the coming months.

Thanks Matt, I will try those approaches and report back…