-
Notifications
You must be signed in to change notification settings - Fork 245
Tutotrial_02: Add and access properties of a point cloud
Liangliang Nan edited this page Dec 10, 2018
·
1 revision
In Easy3D, all actual 3D data are stored as per-element (e.g., vertex, edge, and face) properties. A model can have multiple properties and the properties can be accessed by their names. So it is important to give each property a unique name. Easy3D will pop up a warning if you attempt to create a property with an already used name.
// Assume you have a point cloud (loaded from a file or created by your algorithm).
PointCloud* cloud = ...
// Let's add a random color to each point.
// We give this property a name "v:color". Here "v:" is optional and it just indicates
// that this property
// is defined on the vertices. You will later see properties defined one edges (use
// "e:") and faces (use "f:") for surface meshes.
PointCloud::Vertex_property<vec3> colors = cloud->add_vertex_property<vec3>("v:color");
for (auto v : cloud->vertices()) // iterate over all vertices
colors[v] = random_color(); // assign a random color to point 'v'
// You can use the get_vertex_property() function to access the named properties.
// Below I show you how to access the xyz coordinates and color of each point.
// Here we simply print the coordinates and colors.
// The point coordinates are stored as a per-point property 'v:point'.
PointCloud::Vertex_property<vec3> points = cloud->get_vertex_property<vec3>("v:point");
for (auto v : cloud->vertices())
std::cout << v.idx() << ", xyz: " << points[v] << ", color: " << colors[v] << std::endl;