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>
29#include <vclib/space/complex/mesh_inertia.h>
30#include <vclib/space/core/matrix.h>
41template<FaceMeshConcept MeshType>
42double volume(
const MeshType& m)
44 MeshInertia<MeshType> i(m);
55template<FaceMeshConcept MeshType>
56double surfaceArea(
const MeshType& m)
58 using FaceType = MeshType::FaceType;
61 for (
const FaceType& f : m.
faces()) {
74template<FaceMeshConcept MeshType>
75double borderLength(
const MeshType& m)
77 using FaceType = MeshType::FaceType;
80 for (
const FaceType& f : m.
faces()) {
81 for (uint i = 0; i < f.vertexNumber(); ++i) {
82 if (f.adjFace(i) ==
nullptr) {
83 l += f.vertex(i)->coord().dist(f.vertexMod(i + 1)->coord());
100template<MeshConcept MeshType>
101auto covarianceMatrixOfPointCloud(
const MeshType& m)
103 using VertexType = MeshType::VertexType;
104 using ScalarType = VertexType::CoordType::ScalarType;
106 auto bar = barycenter(m);
108 Matrix33<ScalarType> mm;
111 for (
const VertexType& v : m.
vertices()) {
112 auto e = v.coord() - bar;
113 m += e.outerProduct(e);
126template<FaceMeshConcept MeshType>
127auto covarianceMatrixOfMesh(
const MeshType& m)
129 using VertexType = MeshType::VertexType;
130 using FaceType = MeshType::FaceType;
131 using CoordType = VertexType::CoordType;
132 using ScalarType = CoordType::ScalarType;
134 CoordType bar = shellBarycenter(m);
135 Matrix33<ScalarType> C;
137 Matrix33<ScalarType> C0;
139 C0(0, 0) = C0(1, 1) = 2.0;
140 C0(0, 1) = C0(1, 0) = 1.0;
143 Eigen::Vector3<ScalarType> x;
144 x << 1 / 6.0, 1 / 6.0, 0;
145 Matrix33<ScalarType> A;
146 Matrix33<ScalarType> DC;
148 for (
const FaceType& f : m.
faces()) {
149 const CoordType& p0 = f.vertex(0)->coord();
150 const CoordType& p1 = f.vertex(1)->coord();
151 const CoordType& p2 = f.vertex(2)->coord();
152 CoordType n = (p1 - p0).cross(p2 - p0);
153 double da = n.norm();
156 CoordType tmpp = p1 - p0;
157 for (uint j = 0; j < 3; j++)
160 for (uint j = 0; j < 3; j++)
162 for (uint j = 0; j < 3; j++)
164 Eigen::Vector3<ScalarType> delta;
166 for (uint j = 0; j < 3; j++)
172 DC += A * C0 * A.transpose();
173 Matrix33<ScalarType> tmp = (A * x) * delta.transpose();
174 DC += tmp + tmp.transpose();
176 tmp = delta * delta.transpose();
198template<MeshConcept MeshType,
typename ScalarType>
199std::vector<ScalarType> vertexRadiusFromWeights(
201 const std::vector<ScalarType>& weights,
203 double radiusVariance,
206 using VertexType = MeshType::VertexType;
208 std::vector<ScalarType> radius(m.vertexContainerSize());
209 auto minmax = std::minmax_element(weights.begin(), weights.end());
211 float minRad = diskRadius;
212 float maxRad = diskRadius * radiusVariance;
213 float deltaQ = *minmax.second - *minmax.first;
214 float deltaRad = maxRad - minRad;
215 for (
const VertexType& v : m.
vertices()) {
216 ScalarType w = weights[m.index(v)];
220 ((invert ? *minmax.second - w : w - *minmax.first) / deltaQ);
241template<FaceMeshConcept MeshType>
242std::vector<std::pair<uint, uint>> creaseFaceEdges(
246 bool alsoBorderEdges =
false)
250 std::vector<std::pair<uint, uint>> creaseEdges;
252 for (
const auto& f : m.
faces()) {
253 for (uint i = 0; i < f.vertexNumber(); ++i) {
254 if (f.adjFace(i) ==
nullptr) {
256 if (alsoBorderEdges) {
257 creaseEdges.push_back({f.index(), i});
262 double angle = faceDihedralAngleOnEdge(f, i);
263 if (angle < angleRadNeg || angle > angleRadPos) {
264 creaseEdges.push_back({f.index(), i});
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:101
void requirePerFaceAdjacentFaces(const MeshType &m)
This function asserts that a Mesh has a FaceContainer, the Face has a AdjacentFaces Component,...
Definition face_requirements.h:698
constexpr detail::FacesView faces
A view that allows to iterate overt the Face elements of an object.
Definition face.h:52
constexpr detail::VerticesView vertices
A view that allows to iterate over the Vertex elements of an object.
Definition vertex.h:60