From 80a8c29144efcdea502e59c90cdc1d56bfe20453 Mon Sep 17 00:00:00 2001 From: cignoni Date: Sun, 31 Oct 2010 13:03:36 +0000 Subject: [PATCH] Added function to normalize face/vertex quality value into a given range (usually 0..1) --- vcg/complex/trimesh/update/quality.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/vcg/complex/trimesh/update/quality.h b/vcg/complex/trimesh/update/quality.h index b83a620c..e950ba4c 100644 --- a/vcg/complex/trimesh/update/quality.h +++ b/vcg/complex/trimesh/update/quality.h @@ -189,6 +189,28 @@ static void VertexClamp(MeshType &m, float qmin, float qmax) (*vi).Q()=std::min(qmax, std::max(qmin,(*vi).Q())); } +/** Normalize the vertex quality so that it fits in the specified range. +*/ +static void VertexNormalize(MeshType &m, float qmin=0.0, float qmax=1.0) +{ + ScalarType deltaRange = qmax-qmin; + std::pair minmax = tri::Stat::ComputePerVertexQualityMinMax(m); + VertexIterator vi; + for(vi = m.vert.begin(); vi != m.vert.end(); ++vi) + (*vi).Q() = qmin+deltaRange*((*vi).Q() - minmax.first)/(minmax.second - minmax.first); +} + +/** Normalize the face quality so that it fits in the specified range. +*/ +static void FaceNormalize(MeshType &m, float qmin=0.0, float qmax=1.0) +{ + ScalarType deltaRange = qmax-qmin; + std::pair minmax = tri::Stat::ComputePerFaceQualityMinMax(m); + FaceIterator fi; + for(fi = m.face.begin(); fi != m.face.end(); ++fi) + (*fi).Q() = qmin+deltaRange*((*fi).Q() - minmax.first)/(minmax.second - minmax.first); +} + /** Assign to each face of the mesh a constant quality value. Useful for initialization. */ static void FaceConstant(MeshType &m, float q)