Let's start
We can first declare a new Triangle Mesh and load a ply file:
#include <vclib/meshes.h>
#include <vclib/load_save.h>
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
void load(MeshType &m, const std::string &filename, MeshInfo &loadedInfo, LogType &log=nullLogger, const LoadSettings &settings=LoadSettings())
Loads a mesh from a file with the given filename and stores it in the given mesh object....
Definition load.h:63
Or:
The TriMesh data structure has containers of Vertices and Faces, plus some other info like Bounding Box, Transform Matrix, ...
We can, for example, print some statistics and update the bounding box component of the mesh after has been loaded:
#include <vclib/algorithms.h>
std::cout << "Min bb: " << myTriMesh.boundingBox().min() << "; "
<< "Max bb: " << myTriMesh.boundingBox().max() << "\n";
std::cout << "Vertex number: " << myTriMesh.vertexNumber() "; "
<< "Face number: "<< myTriMesh.faceNumber() "\n";
void updateBoundingBox(MeshType &m)
Updates the bounding box of the mesh.
Definition bounding_box.h:41
We can iterate over Vertices and over Faces of the mesh:
bar.setZero();
for (const vcl::TriMesh::Vertex& v : myTriMesh.vertices()) {
bar += v.coord();
}
bar /= myTriMesh.vertexNumber();
for (const vcl::TriMesh::Face& f : myTriMesh.faces()) {
bool up = true;
for (const vcl::TriMesh::Vertex* v : f.vertices()) {
if (v->coord().y() < bar.
y())
up = false;
}
if (up) {
std::cout << myTriMesh.index(f) << " is above the y barycenter\n";
}
}
The Point class represents an N-dimensional point containing N scalar values.
Definition point.h:58
ScalarType & y()
Returns a reference to the y-component of the Point object.
Definition point.h:153
Note that iterating over the vertices of the faces of the Mesh returns the vertices/faces/elements objects by reference, while iterating over the vertices of the face (or, in general, adjacencies of a specific element) returns the pointer to an element that is stored inside the same Mesh. Note also that this pointer may be nullptr
: in this small example we assume that the mesh is consistent meaning that this cannot happen.
Add, set and delete Elements
We can create from scratch a mesh:
mesh.addVertices(2);
mesh.addVertices(p0, p1, p2, p3, p4);
mesh.addFace(0, 1, 2);
uint fid = mesh.addFace();
mesh.face(fid).setVertices(&mesh.vertex(2), &mesh.vertex(1), &mesh.vertex(3));
Point3< double > Point3d
A convenience alias for a 3-dimensional Point with double-precision floating-point components.
Definition point.h:804