C++Game DevelopmentLanguage FeatureLearn C++

Learn to Visualize Topographic 3D Data in C++ Builder

Do you want to learn how to visualize topographic data? How we can view a 3D function? Can we display specific functions in 3D like activation functions in AI ? How can we create a 3D map in C++?

Topographic Data are data sets about the elevation of the a surface, generally surface of the Earth. Two such data types are commonly used, the first is the Digital Topographic Data that represent the information typically found on a topographic quadrangle map, and the second is the Dgitial Evelation Models (DEM) composed with grids of data. The first data model, typically found on a topographic quadrangle map, such as contour lines, roads, streams, railroads, towns, etc. For simplicity, this first category of data will be referred to as digital topographic map data. The second are Digital Elevation Models or DEMs, composed with grids of data, for which each cell in the grid represents the elevation at a certain point on the Earth.

C++ Builder is easy to build this kind of simple visualizations. C++ is a fast programming language that allows you to develop fully native applications which run at the full speed of the machine. You can use OpenGL or Direct3D libraries or some other 3rd party 3D Engines. In C++ IDE, you can directly create your own 3D objects, you can animate them on runtime. Viewport3D (TViewportd3D) component in C++ Builder FireMonkey projects is good to display many basic 3D Objects like Plane, Cube, Sphere, Cone, Plane, Ellipse3D etc. Please see this post about Working With 3D In Modern Windows C++ Development for creating these 3D objects. You can also easily load your 3D objects into Viewport3D by using Model3D (TModel3D).

To create a 3D object to be used in Viewport3D we need to use TMesh classes.  TMesh is a custom 3D shape that can be customized by drawing 3D shapes.  It is a class publishes a set of properties from its ancestor, TCustomMesh, in order to let you design new 3D shapes at design time from within the IDE, through the Object Inspector. Use the Data property to specify the points, normals and textures for each point, and the order in which the resulting triangles are drawn. The designed shape is filled with the material specified through MaterialSource property. If no material is specified, then the shape is filled with red color.

Viewport3D

Viewport3D (TViewport3D) is a 3Dcomponent to display 3D objects in its space. TViewport3D implements IViewport3D methods to describe how a 3D object is seen. It is really simple and nice to develop some small 3D games or adding some 3D features in your applications. Viewport3D is a component that shows the view port of the camera or default view. You can arrange it’s position, Width and Height on any place of your form or you can use it in client view to do full screen. We can use viewport3D without a 3D Camera, it is using its own design camera view. If you want to use camera and want to see view from the view of that camera you must set its UseDesignCamera property to false from its properties or as below;

You can update any objects in Viewport3D with BeginUpdate(), EndUpdate() methods as given below;

This will update full 3D matrix of Viewport3D in one time. You can also change background color of this Viewport3D component like this;

What does TPlane do?

The TPlane is used in Viewport3D component, it is a class implements a 2D plane that can be placed on a 3D FireMonkey form, it represents a 2D plane that can be employed in a 3D form. Planes support 3D rotation and alignment. TPlane is a visual object that can be added from the Tool Palette.

We can use TPlane to display each parts of faces. But using TMesh is much more simple and easy to setup 4 corner nodes.

How does TMesh help us with visualizations?

Use TMesh to display 3D topographic data. 3D faces, 3D Functions, 3D ground shapes and any other data can be displayed by using TPlane and its 4 coordinates.

 TMesh represents a 3D shape that can be customized. The TMesh class publishes a set of properties from its ancestor, TCustomMesh, in order to let you design new 3D shapes at design time from within the IDE, through the Object Inspector.

Use the Data property to specify the points, normals and textures for each point, and the order in which the resulting triangles are drawn. The designed shape is filled with the material specified through MaterialSource property. If no material is specified, then the shape is filled with red color.

How To Generate Topographic Data in C++

In our example we will used TMesh to display surfaces and we will use Digital Elevation Model (DEM) . We will create our own data with x and y coordinates and its z elevation. Let’s define our 100×100 grid data and a TMesh object first.

Now let’s generate a data. We can generate a random data as remmed below or we can use a 3D function as given below.

Generating Topographic 3D Mesh from the Data

We can generate each planes of the Mesh with 4 points from the grid data, each point will have x,y,z and we can scale this to have better visualization. See how it works below,

Full Example to Topographic 3D Mesh

Here is the screenshot of the fully maximized C++ Builder FMX example. Here we have 100×100 grid and a functional elevation.

Learn to Visualize Topographic 3D Data in C++ Builder full example of 3D mesh

If we randomly generate data by using remmed lines of generate_topographic_data() above, we can see this.

Whole codes of this example is listed below,

As given here, you can generate your own 3D topography, you can add texture on to this mesh, you can also create different textured meshes for the rivers and mountains etc. You can create color textures and you can show the elevation in colors. You can use this method to display your functions i.e. Activation Functions in Artificial Intelligence. You can develop 3D games which has random or well designed topographical maps as given example above. Note that there are a lot of topographic data in internet. For example you can get these kinds of data from https://opentopography.org/

C++ Builder is really great, there no limit to do your dreams ! Just dream and code for it !

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Introduction to C++Learn C++

Learn Copy Constructors in C++ Classes

C++C++11C++14C++17Introduction to C++Learn C++Syntax

Learn How To Use Types Of Destructors In C++?

C++C++11C++14Learn C++Syntax

How To Convert u32string To A wstring In C++

C++C++11C++14C++17C++20Introduction to C++Learn C++

How To Learn The Move Constructors In Modern C++?