Skip to content

Lots of lights: Generating cities Data visualization with Qt 3D, OpenGL and C++

Sometimes data visualization might call for more than a graph – you need to visualize complex data, such as that generated by city lighting, in three dimensions to get the full effect.

KDAB decided to put together a showcase for the Qt World Summit that allowed us to demonstrate Qt 3D’s capabilities as a performant next-generation graphics engine, which can draw thousands of lights and objects simultaneously. This also enabled us to show what modern technologies like Qt 3D can achieve when paired with OpenGL, C++ and custom tooling.

What would show a huge amount of dynamic lighting in action better than a city at night?  We couldn’t answer that, so, to avoid the tedium of building a virtual 3D world to get us going, we imported data from the freely accessible OpenStreetMap service. OpenStreetMap is a great community and a source of free and open mapping information. Additionally, it allows for the export of street and building data to XML format which can be further post-processed.

Buildings

Our data was filtered according to OpenStreetMap keys, and building locations were extracted as polygonal shapes. From these shapes – according to specific rules – Houdini was used to generate a geometric three-dimensional object out of a single polygon per house. Along with that, texture coordinates were created automatically, too. Texture coordinates tell the graphics card how to map an image – commonly referred to as a “texture” – onto a geometric object much like a present is wrapped in paper.

The OpenStreetMap data contains a wealth of information, such as road surface type, speed limits and the number of floors per building. Our algorithm we used calculates the building’s height according to this data and produces an approximation. We used additional properties to provide rooftop variations and create random materials. To keep the performance high, we decided that all buildings should share the same, automatically generated texture atlas. This means that all images we used are combined into a single one so the graphics card has to load and hold just one image in memory for the whole scene.

Traffic

What would a city be without a little traffic? As a challenge, cars should roam the streets of our virtual city, we decided, and of course provide moving light sources. For that to work, we exported OpenStreetMap path data to a custom format and uploaded it to the GPU using a texture. Cars were then animated, instanced and drawn purely on the system’s graphics card.

 

Putting it together

Finally, we combined traffic, buildings and a massive amount of lights into a single scene using Qt 3D. In the final demo, a simple QML interface provides the ability to switch different features on and off as well as switch between a real-world city and a completely computer-generated one. Very little effort was necessary to connect the C++ logic to the interfaces, as QML makes those kind of data bindings very easy.

 

Make sure to see for yourself and visit our booth at the 2017 Qt World Summit!

Categories: Design / How to / KDAB Blogs / KDAB on Qt / OpenGL / Qt3D

Leave a Reply

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. More information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close