23#ifndef VCL_ALGORITHMS_MESH_STAT_BARYCENTER_H
24#define VCL_ALGORITHMS_MESH_STAT_BARYCENTER_H
26#include <vclib/mesh.h>
41template<MeshConcept MeshType>
42auto barycenter(
const MeshType& m) -> MeshType::VertexType::PositionType
44 using VertexType = MeshType::VertexType;
45 using PositionType = VertexType::PositionType;
49 for (
const VertexType& v : m.
vertices()) {
53 return bar / m.vertexNumber();
70template<MeshConcept MeshType>
71auto weightedBarycenter(
const MeshType& m, Range
auto&& weights)
72 -> MeshType::VertexType::PositionType
74 using VertexType = MeshType::VertexType;
75 using PositionType = VertexType::PositionType;
76 using RType = std::ranges::range_value_t<
decltype(weights)>;
78 assert(std::ranges::size(weights) == m.vertexNumber());
81 RType weightedSum = 0;
83 for (
const auto& [v, w] : std::views::zip(m.
vertices(), weights)) {
84 bar += v.position() * w;
88 return bar / weightedSum;
106template<MeshConcept MeshType>
107auto qualityWeightedBarycenter(
const MeshType& m)
108 -> MeshType::VertexType::PositionType
110 requirePerVertexQuality(m);
112 return weightedBarycenter(m, m.vertices() | views::quality);
130template<FaceMeshConcept MeshType>
131auto shellBarycenter(
const MeshType& m) -> MeshType::VertexType::PositionType
133 using VertexType = MeshType::VertexType;
134 using FaceType = MeshType::FaceType;
135 using PositionType = VertexType::PositionType;
136 using ScalarType = PositionType::ScalarType;
140 ScalarType areaSum = 0;
142 for (
const FaceType& f : m.
faces()) {
148 return bar / areaSum;
auto faceArea(const FaceType &f)
Computes the area of a face. Works both for triangle and polygonal faces, and it is optimized in case...
Definition geometry.h:108
FaceType::VertexType::PositionType faceBarycenter(const FaceType &f)
Computes the barycenter of a face. Works both for triangle and polygonal faces, and it is optimized i...
Definition geometry.h:81
constexpr detail::FacesView faces
A view that allows to iterate overt the Face elements of an object.
Definition face.h:84
constexpr detail::VerticesView vertices
A view that allows to iterate over the Vertex elements of an object.
Definition vertex.h:92