This example shows how to add per-point properties to a point cloud and access its properties.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include <easy3d/core/point_cloud.h>
28#include <easy3d/core/random.h>
29#include <easy3d/util/initializer.h>
30
35
37
38
39int main(int argc, char** argv) {
40
42
43
44 srand(0);
45
46
48
49
50 for (int i=-5; i<5; ++i) {
51 for (int j = -5; j < 5; ++j)
52 cloud->add_vertex(
vec3(
static_cast<float>(i),
static_cast<float>(j), 0));
53 }
54 std::cout <<
"point cloud has " << cloud->
n_vertices() <<
" points" << std::endl;
55
56
57
58
59
60
61
62
63
64
65
66 auto colors = cloud->add_vertex_property<
vec3>(
"v:color");
67 for (auto v : cloud->vertices())
69
70
71
72
73
74
75 auto points = cloud->get_vertex_property<
vec3>(
"v:point");
76 for (auto v : cloud->vertices())
77 std::cout << "index: " << v.idx() << ", xyz: " << points[v] << ", color: " << colors[v] << std::endl;
78
79
80 delete cloud;
81
82 return EXIT_SUCCESS;
83}
84
A data structure for point clouds.
Definition point_cloud.h:45
unsigned int n_vertices() const
Returns number of vertices in the cloud.
Definition point_cloud.h:422
Definition collider.cpp:182
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition types.h:44
void initialize(bool info_to_stdout, bool use_log_file, bool use_setting_file, const std::string &resource_dir)
Initialization of Easy3D.
Definition initializer.cpp:39
vec3 random_color(bool allow_dark=false)
Generates a random color. The parameter allow_dark controls if too dark colors are allowed.
Definition random.h:49