Categories
Fade2D Examples

C++ Examples – Getting Started (0)

C++ examples of Fade2D

Fade2D contains a collection of small, self-contained C++ examples. Each example demonstrates step by step for a certain topic how to apply the library practically.

For example, the goal of this very first example is to show you how to compile C++ source code with Fade2D and how to create and draw a triangulation. Find the other examples here:

“Note: All described example source codes are contained in the download.”

Point clouds: 2D and 2.5D vs. 3D

Before we jump into the source code, here’s a short clarification about the dimensions:

  • Fade2D is a classic 2D Delaunay triangulation software for the xy-plane. It offers constraint edges, zones, boolean operations and more.
  • Fade2.5D is like Fade 2D a Delaunay triangulation but for lifted points. More precisely, the library has
    • all functions of Fade2D plus
    • a z-coordinate and
    • additional algorithms from the field of land surveying.
  • Fade3D is a Delaunay triangulation for 3D point clouds. But it is more precise to call it a 3D tetrahedralization because it creates tetrahedra, not triangles. If you want triangles instead you can use WOF to reconstruct the surface of a 3D point cloud.

“The difference between 2.5D and 3D is that a 2.5D point cloud describes a surface f(x,y), i.e. each coordinate pair (x,y) has only one z-coordinate. This is ideal for terrain data and other height fields, but a simple sphere is not 2.5D, for example.”

2D Constrained Delaunay triangulation, C++ example
2D Delaunay with constraint edges
2.5D Delaunay Triangulation of a point cloud (TIN, Triangulated Irregular Network)
2.5D Delaunay Triangulation (TIN, Triangulated Irregular Network) of a terrain point cloud
Use Fade3D or WOF for 3D point clouds

Example0: HelloTriangulation

The first C++ code example is equivalent to HelloWorld:

  • It creates a Fade_2D object and 4 points.
  • Then it inserts the points.
  • Afterwards it draws the resulting triangulation.
// An empty triangulation
Fade_2D dt;
// 4 points
Point2 p0(0.0,0.0);
Point2 p1(1.0,0.0);
Point2 p2(0.5,2.0);
Point2 p3(0.5,0.5);
// Insert the points
dt.insert(p0);
dt.insert(p1);
dt.insert(p2);
dt.insert(p3);
// Draw as postscript graphic
dt.show("example0.ps");
C++ Example of a 2D Delaunay triangulation
Example0: The code in ex0_hello_triangulation.cpp inserts 4 points and draws the resulting triangulation

If you want to use Fade2.5D it might be helpful to look at the 2D examples as well, because they cover the basics that also apply to Fade2.5D.

Compiling under Windows

  • Unzip and enter the examples_xx folder
  • Afterwards open the Visual Studio solution file (*.sln) for VS20xx and compile.
  • Then find the executable in the x64 (or Win32) folder and finally start it in a command line window.

“It is best to start the executables in a command line window. Hint: In a Windows Explorer window mark the address bar and type “cmd” to open a command line window at the same path.”

Compiling under MacOS and Linux

  • Make sure you have gmp installed. For instance (Debian):
    sudo apt-get install libgmp10
  • Afterwards enter the examples_xx directory
  • Then open the contained Makefile and uncomment only your OS version
# Choose a matching distribution below:
# DISTRO :=../lib_centos6.4_${ARCHITECTURE}
# DISTRO :=../lib_ubuntu14.04_${ARCHITECTURE}
# DISTRO :=../lib_fedora24_${ARCHITECTURE}
DISTRO :=../lib_ubuntu20.04_${ARCHITECTURE}
# DISTRO :=../lib_APPLE
# DISTRO :=../lib_raspberry_armv6l
# DISTRO :=../lib_raspberry_armv7l
  • Type make
  • Finally start the executable in the same directory

The next example benchmarks the performance of Fade on your computer.

Leave a Reply

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