random const correctness

This commit is contained in:
alemuntoni 2021-01-28 21:30:24 +01:00
parent 4bc6e679d2
commit de8569a483
3 changed files with 33 additions and 30 deletions

View File

@ -91,7 +91,7 @@ public:
Inertia(MeshType &m) {Compute(m);} Inertia(MeshType &m) {Compute(m);}
/* compute various integrations over projection of face */ /* compute various integrations over projection of face */
void compProjectionIntegrals(FaceType &f) void compProjectionIntegrals(const FaceType &f)
{ {
double a0, a1, da; double a0, a1, da;
double b0, b1, db; double b0, b1, db;
@ -148,7 +148,7 @@ public:
} }
void CompFaceIntegrals(FaceType &f) void CompFaceIntegrals(const FaceType &f)
{ {
Point3<ScalarType> n; Point3<ScalarType> n;
ScalarType w; ScalarType w;
@ -196,9 +196,8 @@ void Compute(MeshType &m)
T0 = T1[X] = T1[Y] = T1[Z] T0 = T1[X] = T1[Y] = T1[Z]
= T2[X] = T2[Y] = T2[Z] = T2[X] = T2[Y] = T2[Z]
= TP[X] = TP[Y] = TP[Z] = 0; = TP[X] = TP[Y] = TP[Z] = 0;
FaceIterator fi; for (auto fi=m.face.begin(); fi!=m.face.end();++fi) if(!(*fi).IsD() && vcg::DoubleArea(*fi)>std::numeric_limits<float>::min()) {
for (fi=m.face.begin(); fi!=m.face.end();++fi) if(!(*fi).IsD() && vcg::DoubleArea(*fi)>std::numeric_limits<float>::min()) { const FaceType &f=(*fi);
FaceType &f=(*fi);
nx = fabs(f.N()[0]); nx = fabs(f.N()[0]);
ny = fabs(f.N()[1]); ny = fabs(f.N()[1]);

View File

@ -192,28 +192,27 @@ public:
\short compute the pointcloud barycenter. \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 E.g. it assume each vertex has a mass. If useQualityAsWeight is true, vertex quality is the mass of the vertices
*/ */
static Point3<ScalarType> ComputeCloudBarycenter(MeshType & m, bool useQualityAsWeight=false) static Point3<ScalarType> ComputeCloudBarycenter(const MeshType & m, bool useQualityAsWeight=false)
{ {
if (useQualityAsWeight) if (useQualityAsWeight)
tri::RequirePerVertexQuality(m); tri::RequirePerVertexQuality(m);
Point3<ScalarType> barycenter(0, 0, 0); Point3<ScalarType> barycenter(0, 0, 0);
Point3d accumulator(0.0, 0.0, 0.0); Point3d accumulator(0.0, 0.0, 0.0);
double weightSum = 0; double weightSum = 0;
VertexIterator vi; for (auto vi = m.vert.begin(); vi != m.vert.end(); ++vi) {
for (vi = m.vert.begin(); vi != m.vert.end(); ++vi) if (!(*vi).IsD()) {
if (!(*vi).IsD()) ScalarType weight = useQualityAsWeight ? (*vi).Q() : 1.0f;
{ accumulator[0] += (double)((*vi).P()[0] * weight);
ScalarType weight = useQualityAsWeight ? (*vi).Q() : 1.0f; accumulator[1] += (double)((*vi).P()[1] * weight);
accumulator[0] += (double)((*vi).P()[0] * weight); accumulator[2] += (double)((*vi).P()[2] * weight);
accumulator[1] += (double)((*vi).P()[1] * weight); weightSum += weight;
accumulator[2] += (double)((*vi).P()[2] * weight); }
weightSum += weight; }
} barycenter[0] = (ScalarType)(accumulator[0] / weightSum);
barycenter[0] = (ScalarType)(accumulator[0] / weightSum); barycenter[1] = (ScalarType)(accumulator[1] / weightSum);
barycenter[1] = (ScalarType)(accumulator[1] / weightSum); barycenter[2] = (ScalarType)(accumulator[2] / weightSum);
barycenter[2] = (ScalarType)(accumulator[2] / weightSum); return barycenter;
return barycenter;
} }
/** /**
@ -248,17 +247,17 @@ public:
return V; return V;
} }
static ScalarType ComputeMeshVolume(MeshType & m) static ScalarType ComputeMeshVolume(const MeshType & m)
{ {
Inertia<MeshType> I(m); Inertia<MeshType> I(m);
return I.Mass(); return I.Mass();
} }
static ScalarType ComputeMeshArea(MeshType & m) static ScalarType ComputeMeshArea(const MeshType & m)
{ {
ScalarType area=0; 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()) if(!(*fi).IsD())
area += DoubleArea(*fi); area += DoubleArea(*fi);

View File

@ -174,6 +174,7 @@ public:
typedef typename T::VertexType::ScalarType ScalarType; 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 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 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() ) 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 * & 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 * & 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 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 * 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 * cV1( const int j ) const { return cV((j+1)%3);}
inline typename T::VertexType * cV2( const int j ) const { return cV((j+2)%3);} inline typename T::VertexType * cV2( const int j ) const { return cV((j+2)%3);}
@ -214,6 +218,7 @@ template <class A, class T> class NormalAbs: public T {
public: public:
typedef A NormalType; typedef A NormalType;
inline NormalType &N() { return _norm; } inline NormalType &N() { return _norm; }
inline const NormalType &N() const { return _norm; }
inline NormalType cN() const { return _norm; } inline NormalType cN() const { return _norm; }
template <class RightValueType> template <class RightValueType>
void ImportData(const RightValueType & rightF) void ImportData(const RightValueType & rightF)