Easy3D 3.0.0
Loading...
Searching...
No Matches
Tutorial_101_PointCloud

Creating a point cloud from raw 3D points — the simplest possible Easy3D program.

Overview

This tutorial builds a PointCloud directly in memory from a set of coordinates, without loading a file and without opening a viewer. It is the "hello world" of Easy3D and shows the skeleton that almost every Easy3D program follows: initialize the library, create or load some data, do something with it, then release it.

The technique

A point cloud is an unordered collection of samples in 3D space. Each sample is just a position (x, y, z); there are no edges or faces connecting the points. Point clouds are the raw output of most 3D acquisition pipelines (LiDAR, depth cameras, photogrammetry), so they are the natural starting point for geometry processing. Here we synthesize a tiny cloud: 100 points laid out on a regular 10 x 10 grid that lies flat in the XY plane (z = 0). In Easy3D a point cloud stores its samples as vertices — but unlike a SurfaceMesh there is no connectivity between them.

Easy3D API

Running it

This example is console-only: it prints "point cloud has 100 points" and exits. No window appears because no Viewer is created. The cloud is a local object here, so it is destroyed automatically when main returns. (When a model is added to a Viewer instead, the Viewer takes ownership of it — see Tutorial_201_Viewer_default.)

1
27#include <easy3d/core/point_cloud.h>
28#include <easy3d/util/initializer.h>
29
72using namespace easy3d;
73
74int main(int argc, char **argv) {
75 // Bootstrap Easy3D (logging, resource directory, ...). Must come first.
76 initialize();
77
78 // Create an empty point cloud.
79 PointCloud cloud;
80
81 // Add some points. Here we add 100 points on a 10 x 10 grid in the XY plane.
82 for (int i = -5; i < 5; ++i) {
83 for (int j = -5; j < 5; ++j)
84 // add_vertex() appends one sample; vec3 is Easy3D's 3D position type.
85 cloud.add_vertex(
86 vec3(static_cast<float>(i), static_cast<float>(j), 0)); // z = 0: all points are on the XY plane
87 }
88
89 // n_vertices() is the number of points currently stored in the cloud.
90 std::cout << "point cloud has " << cloud.n_vertices() << " points" << std::endl;
91
92 return EXIT_SUCCESS;
93}
A data structure for point clouds.
Definition point_cloud.h:46
unsigned int n_vertices() const
Returns number of vertices in the cloud.
Definition point_cloud.h:423
Vertex add_vertex(const vec3 &p)
Add a new vertex with position p.
Definition point_cloud.cpp:169
Definition collider.cpp:182
See also
PointCloud, vec3, Tutorial_102_PointCloud_Property