23#ifndef VCL_ALGORITHMS_MESH_STAT_QUALITY_H
24#define VCL_ALGORITHMS_MESH_STAT_QUALITY_H
26#include <vclib/math/base.h>
27#include <vclib/math/histogram.h>
28#include <vclib/mesh/requirements.h>
29#include <vclib/views/mesh.h>
46template<MeshConcept MeshType>
47auto vertexQualityMinMax(
const MeshType& m)
49 requirePerVertexQuality(m);
51 auto [
min,
max] = std::ranges::minmax(m.vertices() | views::quality);
52 return std::make_pair(
min,
max);
68template<FaceMeshConcept MeshType>
69auto faceQualityMinMax(
const MeshType& m)
73 auto [
min,
max] = std::ranges::minmax(m.faces() | views::quality);
75 return std::make_pair(
min,
max);
89template<MeshConcept MeshType>
90auto vertexQualityAverage(
const MeshType& m)
92 requirePerVertexQuality(m);
94 using VertexType = MeshType::VertexType;
95 using QualityType = VertexType::QualityType;
99 for (
const VertexType& v : m.
vertices())
102 return avg / m.vertexNumber();
116template<FaceMeshConcept MeshType>
117auto faceQualityAverage(
const MeshType& m)
121 using FaceType = MeshType::FaceType;
122 using QualityType = FaceType::QualityType;
126 for (
const FaceType& f : m.
faces())
129 return avg / m.faceNumber();
145template<MeshConcept MeshType>
146std::vector<typename MeshType::VertexType::QualityType> vertexRadiusFromQuality(
149 double radiusVariance,
152 requirePerVertexQuality(m);
154 using VertexType = MeshType::VertexType;
155 using QualityType = VertexType::QualityType;
157 std::vector<QualityType> radius(m.vertexContainerSize());
158 std::pair<QualityType, QualityType> minmax = vertexQualityMinMax(m);
160 float minRad = diskRadius;
161 float maxRad = diskRadius * radiusVariance;
162 float deltaQ = minmax.second - minmax.first;
163 float deltaRad = maxRad - minRad;
164 for (
const VertexType& v : m.
vertices()) {
166 minRad + deltaRad * ((invert ? minmax.second - v.quality() :
167 v.quality() - minmax.first) /
174template<MeshConcept MeshType,
typename HScalar =
double>
175Histogram<HScalar> vertexQualityHistogram(
177 bool selectionOnly =
false,
178 uint histSize = 10000)
180 requirePerVertexQuality(m);
182 using VertexType = MeshType::VertexType;
184 auto minmax = vertexQualityMinMax(m);
186 Histogram<HScalar> h(minmax.first, minmax.second, histSize);
187 for (
const VertexType& v : m.
vertices()) {
188 if (!selectionOnly || v.selected()) {
190 h.addValue(v.quality());
196template<FaceMeshConcept MeshType,
typename HScalar =
double>
197Histogram<HScalar> faceQualityHistogram(
199 bool selectionOnly =
false,
200 uint histSize = 10000)
204 using FaceType = MeshType::FaceType;
206 auto minmax = vertexQualityMinMax(m);
208 Histogram<HScalar> h(minmax.first, minmax.second, histSize);
209 for (
const FaceType& f : m.
faces()) {
210 if (!selectionOnly || f.selected()) {
212 h.addValue(f.quality());
void requirePerFaceQuality(const MeshType &m)
This function asserts that a Mesh has a FaceContainer, the Face has a Quality Component,...
Definition face_requirements.h:875
constexpr auto max(const T &p1, const T &p2)
Returns the maximum between the two parameters.
Definition min_max.h:83
bool isDegenerate(Scalar number)
Checks if a floating point number is degenerate.
Definition base.h:45
constexpr auto min(const T &p1, const T &p2)
Returns the minimum between the two parameters.
Definition min_max.h:42
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