23#ifndef VCL_ALGORITHMS_MESH_UPDATE_QUALITY_H
24#define VCL_ALGORITHMS_MESH_UPDATE_QUALITY_H
26#include <vclib/algorithms/mesh/stat.h>
28#include <vclib/algorithms/core.h>
29#include <vclib/mesh.h>
44template<MeshConcept MeshType>
45void setPerVertexQuality(
47 typename MeshType::VertexType::QualityType s)
49 requirePerVertexQuality(m);
51 using VertexType = MeshType::VertexType;
69template<FaceMeshConcept MeshType>
70void setPerFaceQuality(MeshType& m,
typename MeshType::FaceType::QualityType s)
74 using FaceType = MeshType::FaceType;
76 for (FaceType& f : m.
faces()) {
93template<MeshConcept MeshType>
94void clampPerVertexQuality(
96 typename MeshType::VertexType::QualityType minS,
97 typename MeshType::VertexType::QualityType maxS)
99 requirePerVertexQuality(m);
101 using VertexType = MeshType::VertexType;
103 for (VertexType& v : m.
vertices()) {
104 v.quality() = std::min(maxS, std::max(minS, v.quality()));
120template<FaceMeshConcept MeshType>
121void clampPerFaceQuality(
123 typename MeshType::FaceType::QualityType minS,
124 typename MeshType::FaceType::QualityType maxS)
128 using FaceType = MeshType::FaceType;
130 for (FaceType& f : m.
faces()) {
131 f.quality() = std::min(maxS, std::max(minS, f.quality()));
148template<MeshConcept MeshType>
149void normalizePerVertexQuality(
151 typename MeshType::VertexType::QualityType minS = 0,
152 typename MeshType::VertexType::QualityType maxS = 1)
154 requirePerVertexQuality(m);
156 using VertexType = MeshType::VertexType;
157 using QualityType = VertexType::QualityType;
159 QualityType range = maxS - minS;
160 std::pair<QualityType, QualityType> p = vertexQualityMinMax(m);
162 for (VertexType& v : m.
vertices()) {
164 minS + range * ((v.quality() - p.first) / (p.second - p.first));
181template<FaceMeshConcept MeshType>
182void normalizePerFaceQuality(
184 typename MeshType::FaceType::QualityType minS = 0,
185 typename MeshType::FaceType::QualityType maxS = 1)
189 using FaceType = MeshType::FaceType;
190 using QualityType = FaceType::QualityType;
192 QualityType range = maxS - minS;
193 std::pair<QualityType, QualityType> p = faceQualityMinMax(m);
195 for (FaceType& f : m.
faces()) {
197 minS + range * ((f.quality() - p.first) / (p.second - p.first));
213template<FaceMeshConcept MeshType>
214void setPerVertexQualityFromVertexValence(MeshType& m)
216 requirePerVertexQuality(m);
218 using VertexType = MeshType::VertexType;
219 using FaceType = MeshType::FaceType;
221 setPerVertexQuality(m, 0);
223 for (FaceType& f : m.
faces()) {
224 for (VertexType* v : f.
vertices()) {
240template<FaceMeshConcept MeshType>
241void setPerFaceQualityFromFaceArea(MeshType& m)
245 using FaceType = MeshType::FaceType;
247 for (FaceType& f : m.
faces()) {
252template<MeshConcept MeshType>
253void setPerVertexQualityFromPrincipalCurvatureGaussian(MeshType& m)
255 requirePerVertexQuality(m);
256 requirePerVertexPrincipalCurvature(m);
258 using VertexType = MeshType::VertexType;
260 for (VertexType& v : m.
vertices()) {
261 v.quality() = v.principalCurvature().maxValue() *
262 v.principalCurvature().minValue();
266template<MeshConcept MeshType>
267void setPerVertexQualityFromPrincipalCurvatureMean(MeshType& m)
269 requirePerVertexQuality(m);
270 requirePerVertexPrincipalCurvature(m);
272 using VertexType = MeshType::VertexType;
274 for (VertexType& v : m.
vertices()) {
275 v.quality() = (v.principalCurvature().maxValue() +
276 v.principalCurvature().minValue()) /
281template<MeshConcept MeshType>
282void setPerVertexQualityFromPrincipalCurvatureMinValue(MeshType& m)
284 requirePerVertexQuality(m);
285 requirePerVertexPrincipalCurvature(m);
287 using VertexType = MeshType::VertexType;
289 for (VertexType& v : m.
vertices()) {
290 v.quality() = v.principalCurvature().minValue();
294template<MeshConcept MeshType>
295void setPerVertexQualityFromPrincipalCurvatureMaxValue(MeshType& m)
297 requirePerVertexQuality(m);
298 requirePerVertexPrincipalCurvature(m);
300 using VertexType = MeshType::VertexType;
302 for (VertexType& v : m.
vertices()) {
303 v.quality() = v.principalCurvature().maxValue();
318template<MeshConcept MeshType>
319void setPerVertexQualityFromPrincipalCurvatureShapeIndex(MeshType& m)
321 requirePerVertexQuality(m);
322 requirePerVertexPrincipalCurvature(m);
324 using VertexType = MeshType::VertexType;
325 using ScalarType = VertexType::PrincipalCurvatureType::ScalarType;
327 for (VertexType& v : m.
vertices()) {
328 ScalarType k1 = v.principalCurvature().maxValue();
329 ScalarType k2 = v.principalCurvature().minValue();
332 v.quality() = (2.0 / M_PI) * std::atan2(k1 + k2, k1 - k2);
347template<MeshConcept MeshType>
348void setPerVertexQualityFromPrincipalCurvatureCurvedness(MeshType& m)
350 requirePerVertexQuality(m);
351 requirePerVertexPrincipalCurvature(m);
353 using VertexType = MeshType::VertexType;
354 using ScalarType = VertexType::PrincipalCurvatureType::ScalarType;
356 for (VertexType& v : m.
vertices()) {
357 ScalarType k1 = v.principalCurvature().maxValue();
358 ScalarType k2 = v.principalCurvature().minValue();
360 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:108
void requirePerFaceQuality(const MeshType &m)
This function asserts that a Mesh has a FaceContainer, the Face has a Quality Component,...
Definition face_requirements.h:1137
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