23#ifndef VCL_ALGORITHMS_MESH_STAT_QUALITY_H
24#define VCL_ALGORITHMS_MESH_STAT_QUALITY_H
26#include <vclib/mesh.h>
44template<u
int ELEM_ID, MeshConcept MeshType>
45auto elementQualityMinMax(
const MeshType& m)
47 requirePerElementComponent<ELEM_ID, CompId::QUALITY>(m);
50 std::ranges::minmax(m.template elements<ELEM_ID>() | views::quality);
52 return std::pair {
min,
max};
65template<u
int ELEM_ID, MeshConcept MeshType>
66auto elementQualityAverage(
const MeshType& m)
68 requirePerElementComponent<ELEM_ID, CompId::QUALITY>(m);
70 auto eq = m.template elements<ELEM_ID>() | views::quality;
71 return std::accumulate(std::ranges::begin(eq), std::ranges::end(eq), 0.0) /
72 m.template number<ELEM_ID>();
75template<u
int ELEM_ID, MeshConcept MeshType>
76auto elementQualityHistogram(
78 bool selectionOnly =
false,
79 uint histSize = 10000)
82 typename MeshType::template ElementType<ELEM_ID>::QualityType;
84 requirePerElementComponent<ELEM_ID, CompId::QUALITY>(m);
86 auto minmax = elementQualityMinMax<ELEM_ID>(m);
88 Histogram<QualityType> h(minmax.first, minmax.second, histSize);
89 for (
const auto& e : m.template elements<ELEM_ID>()) {
90 if (!selectionOnly || e.selected()) {
92 h.addValue(e.quality());
111template<MeshConcept MeshType>
112auto vertexQualityMinMax(
const MeshType& m)
114 return elementQualityMinMax<ElemId::VERTEX>(m);
130template<FaceMeshConcept MeshType>
131auto faceQualityMinMax(
const MeshType& m)
133 return elementQualityMinMax<ElemId::FACE>(m);
147template<MeshConcept MeshType>
148auto vertexQualityAverage(
const MeshType& m)
150 return elementQualityAverage<ElemId::VERTEX>(m);
164template<FaceMeshConcept MeshType>
165auto faceQualityAverage(
const MeshType& m)
167 return elementQualityAverage<ElemId::FACE>(m);
183template<MeshConcept MeshType>
184std::vector<typename MeshType::VertexType::QualityType> vertexRadiusFromQuality(
187 double radiusVariance,
190 requirePerVertexQuality(m);
192 using VertexType = MeshType::VertexType;
193 using QualityType = VertexType::QualityType;
195 std::vector<QualityType> radius(m.vertexContainerSize());
196 std::pair<QualityType, QualityType> minmax = vertexQualityMinMax(m);
198 float minRad = diskRadius;
199 float maxRad = diskRadius * radiusVariance;
200 float deltaQ = minmax.second - minmax.first;
201 float deltaRad = maxRad - minRad;
202 for (
const VertexType& v : m.
vertices()) {
204 minRad + deltaRad * ((invert ? minmax.second - v.quality() :
205 v.quality() - minmax.first) /
212template<MeshConcept MeshType,
typename HScalar =
double>
213Histogram<HScalar> vertexQualityHistogram(
215 bool selectionOnly =
false,
216 uint histSize = 10000)
218 return elementQualityHistogram<ElemId::VERTEX>(m, selectionOnly, histSize);
221template<FaceMeshConcept MeshType,
typename HScalar =
double>
222Histogram<HScalar> faceQualityHistogram(
224 bool selectionOnly =
false,
225 uint histSize = 10000)
227 return elementQualityHistogram<ElemId::FACE>(m, selectionOnly, histSize);
constexpr auto max(const T &p1, const T &p2)
Returns the maximum between the two parameters.
Definition min_max.h:81
bool isDegenerate(Scalar number)
Checks if a floating point number is degenerate.
Definition math.h:43
constexpr auto min(const T &p1, const T &p2)
Returns the minimum between the two parameters.
Definition min_max.h:40
constexpr detail::VerticesView vertices
A view that allows to iterate over the Vertex elements of an object.
Definition vertex.h:92