fixed const correctness for Inertia and some Stat functions + code cleaning
This commit is contained in:
parent
bd1b1a937b
commit
95f5550951
|
|
@ -188,20 +188,21 @@ void CompFaceIntegrals(const FaceType &f)
|
||||||
It requires a watertight mesh with per face normals.
|
It requires a watertight mesh with per face normals.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
void Compute(MeshType &m)
|
void Compute(const MeshType &m)
|
||||||
{
|
{
|
||||||
tri::UpdateNormal<MeshType>::PerFaceNormalized(m);
|
|
||||||
double nx, ny, nz;
|
double nx, ny, nz;
|
||||||
|
|
||||||
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;
|
||||||
for (auto fi=m.face.begin(); fi!=m.face.end();++fi) if(!(*fi).IsD() && vcg::DoubleArea(*fi)>std::numeric_limits<float>::min()) {
|
for (auto fi=m.face.begin(); fi!=m.face.end();++fi) if(!(*fi).IsD() && vcg::DoubleArea(*fi)>std::numeric_limits<float>::min())
|
||||||
|
{
|
||||||
const FaceType &f=(*fi);
|
const FaceType &f=(*fi);
|
||||||
|
const auto fn = vcg::NormalizedTriangleNormal(f);
|
||||||
|
|
||||||
nx = fabs(f.N()[0]);
|
nx = fabs(fn[0]);
|
||||||
ny = fabs(f.N()[1]);
|
ny = fabs(fn[1]);
|
||||||
nz = fabs(f.N()[2]);
|
nz = fabs(fn[2]);
|
||||||
if (nx > ny && nx > nz) C = X;
|
if (nx > ny && nx > nz) C = X;
|
||||||
else C = (ny > nz) ? Y : Z;
|
else C = (ny > nz) ? Y : Z;
|
||||||
A = (C + 1) % 3;
|
A = (C + 1) % 3;
|
||||||
|
|
@ -209,17 +210,17 @@ void Compute(MeshType &m)
|
||||||
|
|
||||||
CompFaceIntegrals(f);
|
CompFaceIntegrals(f);
|
||||||
|
|
||||||
T0 += f.N()[X] * ((A == X) ? Fa : ((B == X) ? Fb : Fc));
|
T0 += fn[X] * ((A == X) ? Fa : ((B == X) ? Fb : Fc));
|
||||||
|
|
||||||
T1[A] += f.N()[A] * Faa;
|
T1[A] += fn[A] * Faa;
|
||||||
T1[B] += f.N()[B] * Fbb;
|
T1[B] += fn[B] * Fbb;
|
||||||
T1[C] += f.N()[C] * Fcc;
|
T1[C] += fn[C] * Fcc;
|
||||||
T2[A] += f.N()[A] * Faaa;
|
T2[A] += fn[A] * Faaa;
|
||||||
T2[B] += f.N()[B] * Fbbb;
|
T2[B] += fn[B] * Fbbb;
|
||||||
T2[C] += f.N()[C] * Fccc;
|
T2[C] += fn[C] * Fccc;
|
||||||
TP[A] += f.N()[A] * Faab;
|
TP[A] += fn[A] * Faab;
|
||||||
TP[B] += f.N()[B] * Fbbc;
|
TP[B] += fn[B] * Fbbc;
|
||||||
TP[C] += f.N()[C] * Fcca;
|
TP[C] += fn[C] * Fcca;
|
||||||
}
|
}
|
||||||
|
|
||||||
T1[X] /= 2; T1[Y] /= 2; T1[Z] /= 2;
|
T1[X] /= 2; T1[Y] /= 2; T1[Z] /= 2;
|
||||||
|
|
@ -231,7 +232,7 @@ void Compute(MeshType &m)
|
||||||
|
|
||||||
Meaningful only if the mesh is watertight.
|
Meaningful only if the mesh is watertight.
|
||||||
*/
|
*/
|
||||||
ScalarType Mass()
|
ScalarType Mass(void) const
|
||||||
{
|
{
|
||||||
return static_cast<ScalarType>(T0);
|
return static_cast<ScalarType>(T0);
|
||||||
}
|
}
|
||||||
|
|
@ -240,7 +241,7 @@ ScalarType Mass()
|
||||||
|
|
||||||
Meaningful only if the mesh is watertight.
|
Meaningful only if the mesh is watertight.
|
||||||
*/
|
*/
|
||||||
Point3<ScalarType> CenterOfMass()
|
Point3<ScalarType> CenterOfMass(void) const
|
||||||
{
|
{
|
||||||
Point3<ScalarType> r;
|
Point3<ScalarType> r;
|
||||||
r[X] = T1[X] / T0;
|
r[X] = T1[X] / T0;
|
||||||
|
|
@ -248,7 +249,9 @@ Point3<ScalarType> CenterOfMass()
|
||||||
r[Z] = T1[Z] / T0;
|
r[Z] = T1[Z] / T0;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
void InertiaTensor(Matrix33<ScalarType> &J ){
|
|
||||||
|
void InertiaTensor(Matrix33<ScalarType> &J) const
|
||||||
|
{
|
||||||
Point3<ScalarType> r;
|
Point3<ScalarType> r;
|
||||||
r[X] = T1[X] / T0;
|
r[X] = T1[X] / T0;
|
||||||
r[Y] = T1[Y] / T0;
|
r[Y] = T1[Y] / T0;
|
||||||
|
|
@ -270,7 +273,7 @@ void InertiaTensor(Matrix33<ScalarType> &J ){
|
||||||
}
|
}
|
||||||
|
|
||||||
//void InertiaTensor(Matrix44<ScalarType> &J )
|
//void InertiaTensor(Matrix44<ScalarType> &J )
|
||||||
void InertiaTensor(Eigen::Matrix3d &J )
|
void InertiaTensor(Eigen::Matrix3d &J) const
|
||||||
{
|
{
|
||||||
J=Eigen::Matrix3d::Identity();
|
J=Eigen::Matrix3d::Identity();
|
||||||
Point3d r;
|
Point3d r;
|
||||||
|
|
@ -299,7 +302,7 @@ void InertiaTensor(Eigen::Matrix3d &J )
|
||||||
|
|
||||||
The result is factored as eigenvalues and eigenvectors (as ROWS).
|
The result is factored as eigenvalues and eigenvectors (as ROWS).
|
||||||
*/
|
*/
|
||||||
void InertiaTensorEigen(Matrix33<ScalarType> &EV, Point3<ScalarType> &ev )
|
void InertiaTensorEigen(Matrix33<ScalarType> &EV, Point3<ScalarType> &ev) const
|
||||||
{
|
{
|
||||||
Eigen::Matrix3d it;
|
Eigen::Matrix3d it;
|
||||||
InertiaTensor(it);
|
InertiaTensor(it);
|
||||||
|
|
|
||||||
|
|
@ -239,18 +239,18 @@ public:
|
||||||
return barycenter/areaSum;
|
return barycenter/areaSum;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ScalarType ComputeTetraMeshVolume(MeshType & m)
|
static ScalarType ComputeTetraMeshVolume(const MeshType & m)
|
||||||
{
|
{
|
||||||
ScalarType V = 0;
|
ScalarType V = 0;
|
||||||
|
|
||||||
ForEachTetra(m, [&V] (TetraType & t) {
|
ForEachTetra(m, [&V] (const TetraType & t) {
|
||||||
V += Tetra::ComputeVolume(t);
|
V += Tetra::ComputeVolume(t);
|
||||||
});
|
});
|
||||||
|
|
||||||
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();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue