From e165cc4e45f8691ded3131e06a3fc5a5039ae8ba Mon Sep 17 00:00:00 2001 From: alemuntoni Date: Mon, 26 Apr 2021 14:31:04 +0200 Subject: [PATCH] complex/algorithms/stat.h const correctness --- vcg/complex/algorithms/stat.h | 83 ++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/vcg/complex/algorithms/stat.h b/vcg/complex/algorithms/stat.h index fb2f18b5..f0e8502e 100644 --- a/vcg/complex/algorithms/stat.h +++ b/vcg/complex/algorithms/stat.h @@ -41,64 +41,67 @@ class Stat { public: typedef StatMeshType MeshType; - typedef typename MeshType::ScalarType ScalarType; - typedef typename MeshType::VertexType VertexType; - typedef typename MeshType::VertexPointer VertexPointer; - typedef typename MeshType::VertexIterator VertexIterator; + typedef typename MeshType::ScalarType ScalarType; + typedef typename MeshType::VertexType VertexType; + typedef typename MeshType::VertexPointer VertexPointer; + typedef typename MeshType::VertexIterator VertexIterator; typedef typename MeshType::ConstVertexIterator ConstVertexIterator; - typedef typename MeshType::EdgeType EdgeType; - typedef typename MeshType::EdgeIterator EdgeIterator; - typedef typename MeshType::FaceType FaceType; - typedef typename MeshType::FacePointer FacePointer; - typedef typename MeshType::FaceIterator FaceIterator; - typedef typename MeshType::FaceContainer FaceContainer; - typedef typename MeshType::TetraType TetraType; - typedef typename MeshType::TetraPointer TetraPointer; - typedef typename MeshType::TetraIterator TetraIterator; - typedef typename MeshType::TetraContainer TetraContainer; - typedef typename vcg::Box3 Box3Type; + typedef typename MeshType::EdgeType EdgeType; + typedef typename MeshType::EdgeIterator EdgeIterator; + typedef typename MeshType::FaceType FaceType; + typedef typename MeshType::FacePointer FacePointer; + typedef typename MeshType::FaceIterator FaceIterator; + typedef typename MeshType::ConstFaceIterator ConstFaceIterator; + typedef typename MeshType::FaceContainer FaceContainer; + typedef typename MeshType::TetraType TetraType; + typedef typename MeshType::TetraPointer TetraPointer; + typedef typename MeshType::TetraIterator TetraIterator; + typedef typename MeshType::TetraContainer TetraContainer; + typedef typename vcg::Box3 Box3Type; - static void ComputePerVertexQualityMinMax(MeshType & m, ScalarType &minV, ScalarType &maxV) + static void ComputePerVertexQualityMinMax(const MeshType & m, ScalarType &minV, ScalarType &maxV) { std::pair pp = ComputePerVertexQualityMinMax(m); minV=pp.first; maxV=pp.second; } - static std::pair ComputePerVertexQualityMinMax(MeshType & m) + static std::pair ComputePerVertexQualityMinMax(const MeshType & m) { // assert(0); tri::RequirePerVertexQuality(m); - typename MeshType::template PerMeshAttributeHandle < std::pair > mmqH; - mmqH = tri::Allocator::template GetPerMeshAttribute >(m,"minmaxQ"); + /** Please if you need to create an attribute called minmaxQ, implement an + explicit function that does it. This function should take a const Mesh. **/ + //typename MeshType::template PerMeshAttributeHandle < std::pair > mmqH; + //mmqH = tri::Allocator::template GetPerMeshAttribute >(m,"minmaxQ"); std::pair minmax = std::make_pair(std::numeric_limits::max(), -std::numeric_limits::max()); - for(VertexIterator vi = m.vert.begin(); vi != m.vert.end(); ++vi) + for(ConstVertexIterator vi = m.vert.begin(); vi != m.vert.end(); ++vi) if(!(*vi).IsD()) { if( (*vi).Q() < minmax.first) minmax.first = (*vi).Q(); if( (*vi).Q() > minmax.second) minmax.second = (*vi).Q(); } - mmqH() = minmax; + //mmqH() = minmax; return minmax; } - static void ComputePerFaceQualityMinMax(MeshType & m, ScalarType &minV, ScalarType &maxV) + static void ComputePerFaceQualityMinMax(const MeshType & m, ScalarType &minV, ScalarType &maxV) { std::pair pp = ComputePerFaceQualityMinMax(m); minV=pp.first; maxV=pp.second; } - static std::pair ComputePerFaceQualityMinMax( MeshType & m) + static std::pair ComputePerFaceQualityMinMax( const MeshType & m) { tri::RequirePerFaceQuality(m); std::pair minmax = std::make_pair(std::numeric_limits::max(),-std::numeric_limits::max()); - FaceIterator fi; + ConstFaceIterator fi; for(fi = m.face.begin(); fi != m.face.end(); ++fi) if(!(*fi).IsD()) { @@ -141,12 +144,12 @@ public: return avgQ /= (ScalarType) m.TN(); } - static ScalarType ComputePerFaceQualityAvg(MeshType & m) + static ScalarType ComputePerFaceQualityAvg(const MeshType & m) { tri::RequirePerFaceQuality(m); ScalarType AvgQ = 0; - FaceIterator fi; + ConstFaceIterator fi; size_t num=0; for(fi = m.face.begin(); fi != m.face.end(); ++fi) { @@ -221,11 +224,11 @@ public: Works for any triangulated model (no problem with open, nonmanifold selfintersecting models). Useful for computing the barycenter of 2D planar figures. */ - static Point3 ComputeShellBarycenter(MeshType & m) + static Point3 ComputeShellBarycenter(const MeshType & m) { Point3 barycenter(0,0,0); ScalarType areaSum=0; - FaceIterator fi; + ConstFaceIterator fi; for(fi = m.face.begin(); fi != m.face.end(); ++fi) if(!(*fi).IsD()) { @@ -264,11 +267,11 @@ public: return area/ScalarType(2.0); } - static ScalarType ComputePolyMeshArea(MeshType & m) + static ScalarType ComputePolyMeshArea(const MeshType & m) { ScalarType area=0; - for(FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) + for(ConstFaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) if(!(*fi).IsD()) area += PolyArea(*fi); @@ -293,10 +296,10 @@ public: return sum; } - static void ComputePerVertexQualityDistribution(MeshType & m, Distribution & h, bool selectionOnly = false) // V1.0 + static void ComputePerVertexQualityDistribution(const MeshType & m, Distribution & h, bool selectionOnly = false) // V1.0 { tri::RequirePerVertexQuality(m); - for(VertexIterator vi = m.vert.begin(); vi != m.vert.end(); ++vi) + for(ConstVertexIterator vi = m.vert.begin(); vi != m.vert.end(); ++vi) if(!(*vi).IsD() && ((!selectionOnly) || (*vi).IsS()) ) { assert(!math::IsNAN((*vi).Q()) && "You should never try to compute Histogram with Invalid Floating points numbers (NaN)"); @@ -304,11 +307,11 @@ public: } } - static void ComputePerFaceQualityDistribution( MeshType & m, Distribution &h, + static void ComputePerFaceQualityDistribution( const MeshType & m, Distribution &h, bool selectionOnly = false) // V1.0 { tri::RequirePerFaceQuality(m); - for(FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) + for(ConstFaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) if(!(*fi).IsD() && ((!selectionOnly) || (*fi).IsS()) ) { assert(!math::IsNAN((*fi).Q()) && "You should never try to compute Histogram with Invalid Floating points numbers (NaN)"); @@ -345,27 +348,27 @@ public: }); } - static void ComputePerFaceQualityHistogram( MeshType & m, Histogram &h, bool selectionOnly=false,int HistSize=10000 ) + static void ComputePerFaceQualityHistogram( const MeshType & m, Histogram &h, bool selectionOnly=false,int HistSize=10000 ) { tri::RequirePerFaceQuality(m); std::pair minmax = tri::Stat::ComputePerFaceQualityMinMax(m); h.Clear(); h.SetRange( minmax.first,minmax.second, HistSize ); - for(FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) + for(ConstFaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) if(!(*fi).IsD() && ((!selectionOnly) || (*fi).IsS()) ){ assert(!math::IsNAN((*fi).Q()) && "You should never try to compute Histogram with Invalid Floating points numbers (NaN)"); h.Add((*fi).Q()); } } - static void ComputePerVertexQualityHistogram( MeshType & m, Histogram &h, bool selectionOnly = false, int HistSize=10000 ) // V1.0 + static void ComputePerVertexQualityHistogram( const MeshType & m, Histogram &h, bool selectionOnly = false, int HistSize=10000 ) // V1.0 { tri::RequirePerVertexQuality(m); std::pair minmax = ComputePerVertexQualityMinMax(m); h.Clear(); h.SetRange( minmax.first,minmax.second, HistSize); - for(VertexIterator vi = m.vert.begin(); vi != m.vert.end(); ++vi) + for(ConstVertexIterator vi = m.vert.begin(); vi != m.vert.end(); ++vi) if(!(*vi).IsD() && ((!selectionOnly) || (*vi).IsS()) ) { assert(!math::IsNAN((*vi).Q()) && "You should never try to compute Histogram with Invalid Floating points numbers (NaN)"); @@ -381,7 +384,7 @@ public: { std::vector QV; QV.reserve(m.vn); - for(VertexIterator vi = m.vert.begin(); vi != m.vert.end(); ++vi) + for(ConstVertexIterator vi = m.vert.begin(); vi != m.vert.end(); ++vi) if(!(*vi).IsD()) QV.push_back((*vi).Q()); std::nth_element(QV.begin(),QV.begin()+m.vn/100,QV.end()); @@ -391,7 +394,7 @@ public: h.Clear(); h.SetRange(newmin, newmax, HistSize*50); - for(VertexIterator vi = m.vert.begin(); vi != m.vert.end(); ++vi) + for(ConstVertexIterator vi = m.vert.begin(); vi != m.vert.end(); ++vi) if(!(*vi).IsD() && ((!selectionOnly) || (*vi).IsS()) ) h.Add((*vi).Q()); }