File CentroidSampler.cpp
File List > algos > mesh_to_pointcloud > CentroidSampler.cpp
Go to the documentation of this file
#include "mesh_to_pointcloud/CentroidSampler.h"
namespace Argos {
PointCloud CentroidSampler::sample(const Mesh& mesh)
{
PointCloud cloud;
const auto& faces = mesh.getFaces();
const auto& vertices = mesh.getVertices();
for (const Face& face : faces)
{
const auto& indices = face.getIndices();
if (indices.size() < 3)
continue;
// Triangulation fan
for (std::size_t i = 1; i < indices.size() - 1; ++i)
{
const auto& A = vertices[indices[0]];
const auto& B = vertices[indices[i]];
const auto& C = vertices[indices[i + 1]];
auto P = (A + B + C) / 3.0; // point centroid
cloud.addPoint(P);
}
}
return cloud;
}
}