From de8569a483c25ef3f5044adc1a92376f6dfa408f Mon Sep 17 00:00:00 2001 From: alemuntoni Date: Thu, 28 Jan 2021 21:30:24 +0100 Subject: [PATCH] random const correctness --- vcg/complex/algorithms/inertia.h | 9 +++--- vcg/complex/algorithms/stat.h | 49 ++++++++++++++++---------------- vcg/simplex/face/component.h | 5 ++++ 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/vcg/complex/algorithms/inertia.h b/vcg/complex/algorithms/inertia.h index d3449fc3..14d92b2a 100644 --- a/vcg/complex/algorithms/inertia.h +++ b/vcg/complex/algorithms/inertia.h @@ -91,7 +91,7 @@ public: Inertia(MeshType &m) {Compute(m);} /* compute various integrations over projection of face */ - void compProjectionIntegrals(FaceType &f) + void compProjectionIntegrals(const FaceType &f) { double a0, a1, da; double b0, b1, db; @@ -148,7 +148,7 @@ public: } -void CompFaceIntegrals(FaceType &f) +void CompFaceIntegrals(const FaceType &f) { Point3 n; ScalarType w; @@ -196,9 +196,8 @@ void Compute(MeshType &m) T0 = T1[X] = T1[Y] = T1[Z] = T2[X] = T2[Y] = T2[Z] = TP[X] = TP[Y] = TP[Z] = 0; - FaceIterator fi; - for (fi=m.face.begin(); fi!=m.face.end();++fi) if(!(*fi).IsD() && vcg::DoubleArea(*fi)>std::numeric_limits::min()) { - FaceType &f=(*fi); + for (auto fi=m.face.begin(); fi!=m.face.end();++fi) if(!(*fi).IsD() && vcg::DoubleArea(*fi)>std::numeric_limits::min()) { + const FaceType &f=(*fi); nx = fabs(f.N()[0]); ny = fabs(f.N()[1]); diff --git a/vcg/complex/algorithms/stat.h b/vcg/complex/algorithms/stat.h index 3ba9db9b..fb2f18b5 100644 --- a/vcg/complex/algorithms/stat.h +++ b/vcg/complex/algorithms/stat.h @@ -192,28 +192,27 @@ public: \short compute the pointcloud barycenter. E.g. it assume each vertex has a mass. If useQualityAsWeight is true, vertex quality is the mass of the vertices */ - static Point3 ComputeCloudBarycenter(MeshType & m, bool useQualityAsWeight=false) - { - if (useQualityAsWeight) - tri::RequirePerVertexQuality(m); - - Point3 barycenter(0, 0, 0); - Point3d accumulator(0.0, 0.0, 0.0); - double weightSum = 0; - VertexIterator vi; - for (vi = m.vert.begin(); vi != m.vert.end(); ++vi) - if (!(*vi).IsD()) - { - ScalarType weight = useQualityAsWeight ? (*vi).Q() : 1.0f; - accumulator[0] += (double)((*vi).P()[0] * weight); - accumulator[1] += (double)((*vi).P()[1] * weight); - accumulator[2] += (double)((*vi).P()[2] * weight); - weightSum += weight; - } - barycenter[0] = (ScalarType)(accumulator[0] / weightSum); - barycenter[1] = (ScalarType)(accumulator[1] / weightSum); - barycenter[2] = (ScalarType)(accumulator[2] / weightSum); - return barycenter; + static Point3 ComputeCloudBarycenter(const MeshType & m, bool useQualityAsWeight=false) + { + if (useQualityAsWeight) + tri::RequirePerVertexQuality(m); + + Point3 barycenter(0, 0, 0); + Point3d accumulator(0.0, 0.0, 0.0); + double weightSum = 0; + for (auto vi = m.vert.begin(); vi != m.vert.end(); ++vi) { + if (!(*vi).IsD()) { + ScalarType weight = useQualityAsWeight ? (*vi).Q() : 1.0f; + accumulator[0] += (double)((*vi).P()[0] * weight); + accumulator[1] += (double)((*vi).P()[1] * weight); + accumulator[2] += (double)((*vi).P()[2] * weight); + weightSum += weight; + } + } + barycenter[0] = (ScalarType)(accumulator[0] / weightSum); + barycenter[1] = (ScalarType)(accumulator[1] / weightSum); + barycenter[2] = (ScalarType)(accumulator[2] / weightSum); + return barycenter; } /** @@ -248,17 +247,17 @@ public: return V; } - static ScalarType ComputeMeshVolume(MeshType & m) + static ScalarType ComputeMeshVolume(const MeshType & m) { Inertia I(m); return I.Mass(); } - static ScalarType ComputeMeshArea(MeshType & m) + static ScalarType ComputeMeshArea(const MeshType & m) { ScalarType area=0; - for(FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) + for(auto fi = m.face.begin(); fi != m.face.end(); ++fi) if(!(*fi).IsD()) area += DoubleArea(*fi); diff --git a/vcg/simplex/face/component.h b/vcg/simplex/face/component.h index da731066..8134eac6 100644 --- a/vcg/simplex/face/component.h +++ b/vcg/simplex/face/component.h @@ -174,6 +174,7 @@ public: typedef typename T::VertexType::ScalarType ScalarType; inline typename T::VertexType * &V( const int j ) { assert(j>=0 && j<3); return v[j]; } /// \brief The pointer to the i-th vertex + inline const typename T::VertexType * V (const int j) const { assert(j>=0 && j<3); return v[j]; } inline typename T::VertexType * cV( const int j ) const { assert(j>=0 && j<3); return v[j]; } inline CoordType &P( const int j ) { assert(j>=0 && j<3); return v[j]->P(); } /// \brief Shortcut: the position of the i-th vertex (equivalent to \c V(i)->P() ) @@ -182,6 +183,9 @@ public: inline typename T::VertexType * & V0( const int j ) { return V(j);} /** \brief Return the pointer to the j-th vertex of the face. */ inline typename T::VertexType * & V1( const int j ) { return V((j+1)%3);} /** \brief Return the pointer to the ((j+1)%3)-th vertex of the face. */ inline typename T::VertexType * & V2( const int j ) { return V((j+2)%3);} /** \brief Return the pointer to the ((j+2)%3)-th vertex of the face. */ + inline const typename T::VertexType * V0( const int j ) const { return V(j);} /** \brief Return the pointer to the j-th vertex of the face. */ + inline const typename T::VertexType * V1( const int j ) const { return V((j+1)%3);} /** \brief Return the pointer to the ((j+1)%3)-th vertex of the face. */ + inline const typename T::VertexType * V2( const int j ) const { return V((j+2)%3);} /** \brief Return the pointer to the ((j+2)%3)-th vertex of the face. */ inline typename T::VertexType * cV0( const int j ) const { return cV(j);} inline typename T::VertexType * cV1( const int j ) const { return cV((j+1)%3);} inline typename T::VertexType * cV2( const int j ) const { return cV((j+2)%3);} @@ -214,6 +218,7 @@ template class NormalAbs: public T { public: typedef A NormalType; inline NormalType &N() { return _norm; } + inline const NormalType &N() const { return _norm; } inline NormalType cN() const { return _norm; } template void ImportData(const RightValueType & rightF)