23#ifndef VCL_ALGORITHMS_MESH_STAT_GEOMETRY_H
24#define VCL_ALGORITHMS_MESH_STAT_GEOMETRY_H
26#include "barycenter.h"
28#include <vclib/algorithms/mesh/face_topology.h>
30#include <vclib/space/complex.h>
31#include <vclib/space/core.h>
42template<FaceMeshConcept MeshType>
43double volume(
const MeshType& m)
45 MeshInertia<MeshType> i(m);
56template<FaceMeshConcept MeshType>
57double surfaceArea(
const MeshType& m)
59 using FaceType = MeshType::FaceType;
62 for (
const FaceType& f : m.
faces()) {
79template<FaceMeshConcept MeshType>
80double borderLength(
const MeshType& m)
82 using FaceType = MeshType::FaceType;
87 for (
const FaceType& f : m.
faces()) {
88 for (uint i = 0; i < f.vertexNumber(); ++i) {
89 if (f.adjFace(i) ==
nullptr) {
90 l += f.vertex(i)->position().dist(
91 f.vertexMod(i + 1)->position());
108template<MeshConcept MeshType>
109auto covarianceMatrixOfPointCloud(
const MeshType& m)
111 using VertexType = MeshType::VertexType;
112 using PositionType = VertexType::PositionType;
113 using ScalarType = PositionType::ScalarType;
115 PositionType bar = barycenter(m);
117 Matrix33<ScalarType> mm;
120 for (
const VertexType& v : m.
vertices()) {
121 PositionType e = v.position() - bar;
122 mm += e.outerProduct(e);
135template<FaceMeshConcept MeshType>
136auto covarianceMatrixOfMesh(
const MeshType& m)
138 using VertexType = MeshType::VertexType;
139 using FaceType = MeshType::FaceType;
140 using PositionType = VertexType::PositionType;
141 using ScalarType = PositionType::ScalarType;
143 PositionType bar = shellBarycenter(m);
144 Matrix33<ScalarType> C;
146 Matrix33<ScalarType> C0;
148 C0(0, 0) = C0(1, 1) = 2.0;
149 C0(0, 1) = C0(1, 0) = 1.0;
152 Eigen::Vector3<ScalarType> x;
153 x << 1 / 6.0, 1 / 6.0, 0;
154 Matrix33<ScalarType> A;
155 Matrix33<ScalarType> DC;
157 for (
const FaceType& f : m.
faces()) {
158 const PositionType& p0 = f.vertex(0)->position();
159 const PositionType& p1 = f.vertex(1)->position();
160 const PositionType& p2 = f.vertex(2)->position();
161 PositionType n = (p1 - p0).cross(p2 - p0);
162 double da = n.norm();
165 PositionType tmpp = p1 - p0;
166 for (uint j = 0; j < 3; j++)
169 for (uint j = 0; j < 3; j++)
171 for (uint j = 0; j < 3; j++)
173 Eigen::Vector3<ScalarType> delta;
175 for (uint j = 0; j < 3; j++)
181 DC += A * C0 * A.transpose();
182 Matrix33<ScalarType> tmp = (A * x) * delta.transpose();
183 DC += tmp + tmp.transpose();
185 tmp = delta * delta.transpose();
207template<
typename ScalarType, MeshConcept MeshType>
208std::vector<ScalarType> vertexRadiusFromWeights(
210 Range
auto&& weights,
212 double radiusVariance,
215 using VertexType = MeshType::VertexType;
217 assert(std::ranges::size(weights) == m.vertexNumber());
219 std::vector<ScalarType> radius(m.vertexContainerSize());
220 const auto [
min,
max] = std::ranges::minmax_element(weights);
222 double minRad = diskRadius;
223 double maxRad = diskRadius * radiusVariance;
224 double deltaQ = *
max - *
min;
225 double deltaRad = maxRad - minRad;
226 for (
const auto& [v, w] : std::views::zip(m.
vertices(), weights)) {
227 double num = invert ? (*
max - w) : (w - *
min);
228 radius[m.index(v)] = minRad + deltaRad * (num / deltaQ);
249template<FaceMeshConcept MeshType>
250std::vector<std::pair<uint, uint>> creaseFaceEdges(
254 bool alsoBorderEdges =
false)
258 std::vector<std::pair<uint, uint>> creaseEdges;
260 for (
const auto& f : m.
faces()) {
261 for (uint i = 0; i < f.vertexNumber(); ++i) {
262 if (f.adjFace(i) ==
nullptr) {
264 if (alsoBorderEdges) {
265 creaseEdges.push_back({f.index(), i});
270 double angle = faceDihedralAngleOnEdge(f, i);
271 if (angle < angleRadNeg || angle > angleRadPos) {
272 creaseEdges.push_back({f.index(), i});
constexpr auto max(const T &p1, const T &p2)
Returns the maximum between the two parameters.
Definition min_max.h:81
constexpr auto min(const T &p1, const T &p2)
Returns the minimum between the two parameters.
Definition min_max.h:40
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
void requirePerFaceAdjacentFaces(const MeshType &m)
This function asserts that a Mesh has a FaceContainer, the Face has a AdjacentFaces Component,...
Definition face_requirements.h:960
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