23#ifndef VCL_ALGORITHMS_MESH_UPDATE_QUALITY_H
24#define VCL_ALGORITHMS_MESH_UPDATE_QUALITY_H
26#include <vclib/algorithms/core/polygon.h>
27#include <vclib/algorithms/mesh/stat.h>
28#include <vclib/mesh/requirements.h>
43template<MeshConcept MeshType>
44void setPerVertexQuality(
46 typename MeshType::VertexType::QualityType s)
48 requirePerVertexQuality(m);
50 using VertexType = MeshType::VertexType;
68template<FaceMeshConcept MeshType>
69void setPerFaceQuality(MeshType& m,
typename MeshType::FaceType::QualityType s)
73 using FaceType = MeshType::FaceType;
75 for (FaceType& f : m.
faces()) {
92template<MeshConcept MeshType>
93void clampPerVertexQuality(
95 typename MeshType::VertexType::QualityType minS,
96 typename MeshType::VertexType::QualityType maxS)
98 requirePerVertexQuality(m);
100 using VertexType = MeshType::VertexType;
102 for (VertexType& v : m.
vertices()) {
103 v.quality() = std::min(maxS, std::max(minS, v.quality()));
119template<FaceMeshConcept MeshType>
120void clampPerFaceQuality(
122 typename MeshType::FaceType::QualityType minS,
123 typename MeshType::FaceType::QualityType maxS)
127 using FaceType = MeshType::FaceType;
129 for (FaceType& f : m.
faces()) {
130 f.quality() = std::min(maxS, std::max(minS, f.quality()));
147template<MeshConcept MeshType>
148void normalizePerVertexQuality(
150 typename MeshType::VertexType::QualityType minS = 0,
151 typename MeshType::VertexType::QualityType maxS = 1)
153 requirePerVertexQuality(m);
155 using VertexType = MeshType::VertexType;
156 using QualityType = VertexType::QualityType;
158 QualityType range = maxS - minS;
159 std::pair<QualityType, QualityType> p = vertexQualityMinMax(m);
161 for (VertexType& v : m.
vertices()) {
163 minS + range * ((v.quality() - p.first) / (p.second - p.first));
180template<FaceMeshConcept MeshType>
181void normalizePerFaceQuality(
183 typename MeshType::FaceType::QualityType minS = 0,
184 typename MeshType::FaceType::QualityType maxS = 1)
188 using FaceType = MeshType::FaceType;
189 using QualityType = FaceType::QualityType;
191 QualityType range = maxS - minS;
192 std::pair<QualityType, QualityType> p = faceQualityMinMax(m);
194 for (FaceType& f : m.
faces()) {
196 minS + range * ((f.quality() - p.first) / (p.second - p.first));
212template<FaceMeshConcept MeshType>
213void setPerVertexQualityFromVertexValence(MeshType& m)
215 requirePerVertexQuality(m);
217 using VertexType = MeshType::VertexType;
218 using FaceType = MeshType::FaceType;
220 setPerVertexQuality(m, 0);
222 for (FaceType& f : m.
faces()) {
223 for (VertexType* v : f.
vertices()) {
239template<FaceMeshConcept MeshType>
240void setPerFaceQualityFromFaceArea(MeshType& m)
244 using FaceType = MeshType::FaceType;
246 for (FaceType& f : m.
faces()) {
251template<MeshConcept MeshType>
252void setPerVertexQualityFromPrincipalCurvatureGaussian(MeshType& m)
254 requirePerVertexQuality(m);
255 requirePerVertexPrincipalCurvature(m);
257 using VertexType = MeshType::VertexType;
259 for (VertexType& v : m.
vertices()) {
260 v.quality() = v.principalCurvature().maxValue() *
261 v.principalCurvature().minValue();
265template<MeshConcept MeshType>
266void setPerVertexQualityFromPrincipalCurvatureMean(MeshType& m)
268 requirePerVertexQuality(m);
269 requirePerVertexPrincipalCurvature(m);
271 using VertexType = MeshType::VertexType;
273 for (VertexType& v : m.
vertices()) {
274 v.quality() = (v.principalCurvature().maxValue() +
275 v.principalCurvature().minValue()) /
280template<MeshConcept MeshType>
281void setPerVertexQualityFromPrincipalCurvatureMinValue(MeshType& m)
283 requirePerVertexQuality(m);
284 requirePerVertexPrincipalCurvature(m);
286 using VertexType = MeshType::VertexType;
288 for (VertexType& v : m.
vertices()) {
289 v.quality() = v.principalCurvature().minValue();
293template<MeshConcept MeshType>
294void setPerVertexQualityFromPrincipalCurvatureMaxValue(MeshType& m)
296 requirePerVertexQuality(m);
297 requirePerVertexPrincipalCurvature(m);
299 using VertexType = MeshType::VertexType;
301 for (VertexType& v : m.
vertices()) {
302 v.quality() = v.principalCurvature().maxValue();
317template<MeshConcept MeshType>
318void setPerVertexQualityFromPrincipalCurvatureShapeIndex(MeshType& m)
320 requirePerVertexQuality(m);
321 requirePerVertexPrincipalCurvature(m);
323 using VertexType = MeshType::VertexType;
324 using ScalarType = VertexType::PrincipalCurvatureType::ScalarType;
326 for (VertexType& v : m.
vertices()) {
327 ScalarType k1 = v.principalCurvature().maxValue();
328 ScalarType k2 = v.principalCurvature().minValue();
331 v.quality() = (2.0 / M_PI) * std::atan2(k1 + k2, k1 - k2);
346template<MeshConcept MeshType>
347void setPerVertexQualityFromPrincipalCurvatureCurvedness(MeshType& m)
349 requirePerVertexQuality(m);
350 requirePerVertexPrincipalCurvature(m);
352 using VertexType = MeshType::VertexType;
353 using ScalarType = VertexType::PrincipalCurvatureType::ScalarType;
355 for (VertexType& v : m.
vertices()) {
356 ScalarType k1 = v.principalCurvature().maxValue();
357 ScalarType k2 = v.principalCurvature().minValue();
359 v.quality() = std::sqrt((k1 * k1 + k2 * k2) / 2.0);
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 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 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