Code-style consistency improvement:

Apply clang-format-all.sh using the _clang-format file through all the cpp/.h files.
make sure not to apply it to certain serialization structures, since some parser expects the * as part of the name, instead of type.
This commit contains no other changes aside from adding and applying clang-format-all.sh
This commit is contained in:
erwincoumans
2018-09-23 14:17:31 -07:00
parent b73b05e9fb
commit ab8f16961e
1773 changed files with 1081087 additions and 474249 deletions

View File

@@ -52,369 +52,358 @@
namespace BestFit
{
class Vec3
{
public:
Vec3(void) { };
Vec3(float _x,float _y,float _z) { x = _x; y = _y; z = _z; };
Vec3(void){};
Vec3(float _x, float _y, float _z)
{
x = _x;
y = _y;
z = _z;
};
float dot(const Vec3 &v)
{
return x * v.x + y * v.y + z * v.z; // the dot product
}
float dot(const Vec3 &v)
{
return x*v.x + y*v.y + z*v.z; // the dot product
}
float x;
float y;
float z;
float x;
float y;
float z;
};
class Eigen
{
public:
void DecrSortEigenStuff(void)
{
Tridiagonal(); //diagonalize the matrix.
QLAlgorithm(); //
DecreasingSort();
GuaranteeRotation();
}
void Tridiagonal(void)
{
float fM00 = mElement[0][0];
float fM01 = mElement[0][1];
float fM02 = mElement[0][2];
float fM11 = mElement[1][1];
float fM12 = mElement[1][2];
float fM22 = mElement[2][2];
void DecrSortEigenStuff(void)
{
Tridiagonal(); //diagonalize the matrix.
QLAlgorithm(); //
DecreasingSort();
GuaranteeRotation();
}
m_afDiag[0] = fM00;
m_afSubd[2] = 0;
if (fM02 != (float)0.0)
{
float fLength = sqrtf(fM01 * fM01 + fM02 * fM02);
float fInvLength = ((float)1.0) / fLength;
fM01 *= fInvLength;
fM02 *= fInvLength;
float fQ = ((float)2.0) * fM01 * fM12 + fM02 * (fM22 - fM11);
m_afDiag[1] = fM11 + fM02 * fQ;
m_afDiag[2] = fM22 - fM02 * fQ;
m_afSubd[0] = fLength;
m_afSubd[1] = fM12 - fM01 * fQ;
mElement[0][0] = (float)1.0;
mElement[0][1] = (float)0.0;
mElement[0][2] = (float)0.0;
mElement[1][0] = (float)0.0;
mElement[1][1] = fM01;
mElement[1][2] = fM02;
mElement[2][0] = (float)0.0;
mElement[2][1] = fM02;
mElement[2][2] = -fM01;
m_bIsRotation = false;
}
else
{
m_afDiag[1] = fM11;
m_afDiag[2] = fM22;
m_afSubd[0] = fM01;
m_afSubd[1] = fM12;
mElement[0][0] = (float)1.0;
mElement[0][1] = (float)0.0;
mElement[0][2] = (float)0.0;
mElement[1][0] = (float)0.0;
mElement[1][1] = (float)1.0;
mElement[1][2] = (float)0.0;
mElement[2][0] = (float)0.0;
mElement[2][1] = (float)0.0;
mElement[2][2] = (float)1.0;
m_bIsRotation = true;
}
}
void Tridiagonal(void)
{
float fM00 = mElement[0][0];
float fM01 = mElement[0][1];
float fM02 = mElement[0][2];
float fM11 = mElement[1][1];
float fM12 = mElement[1][2];
float fM22 = mElement[2][2];
bool QLAlgorithm(void)
{
const int iMaxIter = 32;
m_afDiag[0] = fM00;
m_afSubd[2] = 0;
if (fM02 != (float)0.0)
{
float fLength = sqrtf(fM01*fM01+fM02*fM02);
float fInvLength = ((float)1.0)/fLength;
fM01 *= fInvLength;
fM02 *= fInvLength;
float fQ = ((float)2.0)*fM01*fM12+fM02*(fM22-fM11);
m_afDiag[1] = fM11+fM02*fQ;
m_afDiag[2] = fM22-fM02*fQ;
m_afSubd[0] = fLength;
m_afSubd[1] = fM12-fM01*fQ;
mElement[0][0] = (float)1.0;
mElement[0][1] = (float)0.0;
mElement[0][2] = (float)0.0;
mElement[1][0] = (float)0.0;
mElement[1][1] = fM01;
mElement[1][2] = fM02;
mElement[2][0] = (float)0.0;
mElement[2][1] = fM02;
mElement[2][2] = -fM01;
m_bIsRotation = false;
}
else
{
m_afDiag[1] = fM11;
m_afDiag[2] = fM22;
m_afSubd[0] = fM01;
m_afSubd[1] = fM12;
mElement[0][0] = (float)1.0;
mElement[0][1] = (float)0.0;
mElement[0][2] = (float)0.0;
mElement[1][0] = (float)0.0;
mElement[1][1] = (float)1.0;
mElement[1][2] = (float)0.0;
mElement[2][0] = (float)0.0;
mElement[2][1] = (float)0.0;
mElement[2][2] = (float)1.0;
m_bIsRotation = true;
}
}
for (int i0 = 0; i0 < 3; i0++)
{
int i1;
for (i1 = 0; i1 < iMaxIter; i1++)
{
int i2;
for (i2 = i0; i2 <= (3 - 2); i2++)
{
float fTmp = fabsf(m_afDiag[i2]) + fabsf(m_afDiag[i2 + 1]);
if (fabsf(m_afSubd[i2]) + fTmp == fTmp)
break;
}
if (i2 == i0)
{
break;
}
bool QLAlgorithm(void)
{
const int iMaxIter = 32;
float fG = (m_afDiag[i0 + 1] - m_afDiag[i0]) / (((float)2.0) * m_afSubd[i0]);
float fR = sqrtf(fG * fG + (float)1.0);
if (fG < (float)0.0)
{
fG = m_afDiag[i2] - m_afDiag[i0] + m_afSubd[i0] / (fG - fR);
}
else
{
fG = m_afDiag[i2] - m_afDiag[i0] + m_afSubd[i0] / (fG + fR);
}
float fSin = (float)1.0, fCos = (float)1.0, fP = (float)0.0;
for (int i3 = i2 - 1; i3 >= i0; i3--)
{
float fF = fSin * m_afSubd[i3];
float fB = fCos * m_afSubd[i3];
if (fabsf(fF) >= fabsf(fG))
{
fCos = fG / fF;
fR = sqrtf(fCos * fCos + (float)1.0);
m_afSubd[i3 + 1] = fF * fR;
fSin = ((float)1.0) / fR;
fCos *= fSin;
}
else
{
fSin = fF / fG;
fR = sqrtf(fSin * fSin + (float)1.0);
m_afSubd[i3 + 1] = fG * fR;
fCos = ((float)1.0) / fR;
fSin *= fCos;
}
fG = m_afDiag[i3 + 1] - fP;
fR = (m_afDiag[i3] - fG) * fSin + ((float)2.0) * fB * fCos;
fP = fSin * fR;
m_afDiag[i3 + 1] = fG + fP;
fG = fCos * fR - fB;
for (int i4 = 0; i4 < 3; i4++)
{
fF = mElement[i4][i3 + 1];
mElement[i4][i3 + 1] = fSin * mElement[i4][i3] + fCos * fF;
mElement[i4][i3] = fCos * mElement[i4][i3] - fSin * fF;
}
}
m_afDiag[i0] -= fP;
m_afSubd[i0] = fG;
m_afSubd[i2] = (float)0.0;
}
if (i1 == iMaxIter)
{
return false;
}
}
return true;
}
for (int i0 = 0; i0 <3; i0++)
{
int i1;
for (i1 = 0; i1 < iMaxIter; i1++)
{
int i2;
for (i2 = i0; i2 <= (3-2); i2++)
{
float fTmp = fabsf(m_afDiag[i2]) + fabsf(m_afDiag[i2+1]);
if ( fabsf(m_afSubd[i2]) + fTmp == fTmp )
break;
}
if (i2 == i0)
{
break;
}
void DecreasingSort(void)
{
//sort eigenvalues in decreasing order, e[0] >= ... >= e[iSize-1]
for (int i0 = 0, i1; i0 <= 3 - 2; i0++)
{
// locate maximum eigenvalue
i1 = i0;
float fMax = m_afDiag[i1];
int i2;
for (i2 = i0 + 1; i2 < 3; i2++)
{
if (m_afDiag[i2] > fMax)
{
i1 = i2;
fMax = m_afDiag[i1];
}
}
float fG = (m_afDiag[i0+1] - m_afDiag[i0])/(((float)2.0) * m_afSubd[i0]);
float fR = sqrtf(fG*fG+(float)1.0);
if (fG < (float)0.0)
{
fG = m_afDiag[i2]-m_afDiag[i0]+m_afSubd[i0]/(fG-fR);
}
else
{
fG = m_afDiag[i2]-m_afDiag[i0]+m_afSubd[i0]/(fG+fR);
}
float fSin = (float)1.0, fCos = (float)1.0, fP = (float)0.0;
for (int i3 = i2-1; i3 >= i0; i3--)
{
float fF = fSin*m_afSubd[i3];
float fB = fCos*m_afSubd[i3];
if (fabsf(fF) >= fabsf(fG))
{
fCos = fG/fF;
fR = sqrtf(fCos*fCos+(float)1.0);
m_afSubd[i3+1] = fF*fR;
fSin = ((float)1.0)/fR;
fCos *= fSin;
}
else
{
fSin = fF/fG;
fR = sqrtf(fSin*fSin+(float)1.0);
m_afSubd[i3+1] = fG*fR;
fCos = ((float)1.0)/fR;
fSin *= fCos;
}
fG = m_afDiag[i3+1]-fP;
fR = (m_afDiag[i3]-fG)*fSin+((float)2.0)*fB*fCos;
fP = fSin*fR;
m_afDiag[i3+1] = fG+fP;
fG = fCos*fR-fB;
for (int i4 = 0; i4 < 3; i4++)
{
fF = mElement[i4][i3+1];
mElement[i4][i3+1] = fSin*mElement[i4][i3]+fCos*fF;
mElement[i4][i3] = fCos*mElement[i4][i3]-fSin*fF;
}
}
m_afDiag[i0] -= fP;
m_afSubd[i0] = fG;
m_afSubd[i2] = (float)0.0;
}
if (i1 == iMaxIter)
{
return false;
}
}
return true;
}
if (i1 != i0)
{
// swap eigenvalues
m_afDiag[i1] = m_afDiag[i0];
m_afDiag[i0] = fMax;
// swap eigenvectors
for (i2 = 0; i2 < 3; i2++)
{
float fTmp = mElement[i2][i0];
mElement[i2][i0] = mElement[i2][i1];
mElement[i2][i1] = fTmp;
m_bIsRotation = !m_bIsRotation;
}
}
}
}
void DecreasingSort(void)
{
//sort eigenvalues in decreasing order, e[0] >= ... >= e[iSize-1]
for (int i0 = 0, i1; i0 <= 3-2; i0++)
{
// locate maximum eigenvalue
i1 = i0;
float fMax = m_afDiag[i1];
int i2;
for (i2 = i0+1; i2 < 3; i2++)
{
if (m_afDiag[i2] > fMax)
{
i1 = i2;
fMax = m_afDiag[i1];
}
}
void GuaranteeRotation(void)
{
if (!m_bIsRotation)
{
// change sign on the first column
for (int iRow = 0; iRow < 3; iRow++)
{
mElement[iRow][0] = -mElement[iRow][0];
}
}
}
if (i1 != i0)
{
// swap eigenvalues
m_afDiag[i1] = m_afDiag[i0];
m_afDiag[i0] = fMax;
// swap eigenvectors
for (i2 = 0; i2 < 3; i2++)
{
float fTmp = mElement[i2][i0];
mElement[i2][i0] = mElement[i2][i1];
mElement[i2][i1] = fTmp;
m_bIsRotation = !m_bIsRotation;
}
}
}
}
void GuaranteeRotation(void)
{
if (!m_bIsRotation)
{
// change sign on the first column
for (int iRow = 0; iRow <3; iRow++)
{
mElement[iRow][0] = -mElement[iRow][0];
}
}
}
float mElement[3][3];
float m_afDiag[3];
float m_afSubd[3];
bool m_bIsRotation;
float mElement[3][3];
float m_afDiag[3];
float m_afSubd[3];
bool m_bIsRotation;
};
}
} // namespace BestFit
using namespace BestFit;
bool getBestFitPlane(unsigned int vcount,
const float *points,
unsigned int vstride,
const float *weights,
unsigned int wstride,
float *plane)
const float *points,
unsigned int vstride,
const float *weights,
unsigned int wstride,
float *plane)
{
bool ret = false;
bool ret = false;
Vec3 kOrigin(0,0,0);
Vec3 kOrigin(0, 0, 0);
float wtotal = 0;
float wtotal = 0;
if ( 1 )
{
const char *source = (const char *) points;
const char *wsource = (const char *) weights;
if (1)
{
const char *source = (const char *)points;
const char *wsource = (const char *)weights;
for (unsigned int i=0; i<vcount; i++)
{
for (unsigned int i = 0; i < vcount; i++)
{
const float *p = (const float *)source;
const float *p = (const float *) source;
float w = 1;
float w = 1;
if (wsource)
{
const float *ws = (const float *)wsource;
w = *ws; //
wsource += wstride;
}
if ( wsource )
{
const float *ws = (const float *) wsource;
w = *ws; //
wsource+=wstride;
}
kOrigin.x += p[0] * w;
kOrigin.y += p[1] * w;
kOrigin.z += p[2] * w;
kOrigin.x+=p[0]*w;
kOrigin.y+=p[1]*w;
kOrigin.z+=p[2]*w;
wtotal += w;
wtotal+=w;
source += vstride;
}
}
source+=vstride;
}
}
float recip = 1.0f / wtotal; // reciprocol of total weighting
float recip = 1.0f / wtotal; // reciprocol of total weighting
kOrigin.x *= recip;
kOrigin.y *= recip;
kOrigin.z *= recip;
kOrigin.x*=recip;
kOrigin.y*=recip;
kOrigin.z*=recip;
float fSumXX = 0;
float fSumXY = 0;
float fSumXZ = 0;
float fSumYY = 0;
float fSumYZ = 0;
float fSumZZ = 0;
float fSumXX=0;
float fSumXY=0;
float fSumXZ=0;
if (1)
{
const char *source = (const char *)points;
const char *wsource = (const char *)weights;
float fSumYY=0;
float fSumYZ=0;
float fSumZZ=0;
for (unsigned int i = 0; i < vcount; i++)
{
const float *p = (const float *)source;
float w = 1;
if ( 1 )
{
const char *source = (const char *) points;
const char *wsource = (const char *) weights;
if (wsource)
{
const float *ws = (const float *)wsource;
w = *ws; //
wsource += wstride;
}
for (unsigned int i=0; i<vcount; i++)
{
Vec3 kDiff;
const float *p = (const float *) source;
kDiff.x = w * (p[0] - kOrigin.x); // apply vertex weighting!
kDiff.y = w * (p[1] - kOrigin.y);
kDiff.z = w * (p[2] - kOrigin.z);
float w = 1;
fSumXX += kDiff.x * kDiff.x; // sume of the squares of the differences.
fSumXY += kDiff.x * kDiff.y; // sume of the squares of the differences.
fSumXZ += kDiff.x * kDiff.z; // sume of the squares of the differences.
if ( wsource )
{
const float *ws = (const float *) wsource;
w = *ws; //
wsource+=wstride;
}
fSumYY += kDiff.y * kDiff.y;
fSumYZ += kDiff.y * kDiff.z;
fSumZZ += kDiff.z * kDiff.z;
Vec3 kDiff;
source += vstride;
}
}
kDiff.x = w*(p[0] - kOrigin.x); // apply vertex weighting!
kDiff.y = w*(p[1] - kOrigin.y);
kDiff.z = w*(p[2] - kOrigin.z);
fSumXX *= recip;
fSumXY *= recip;
fSumXZ *= recip;
fSumYY *= recip;
fSumYZ *= recip;
fSumZZ *= recip;
fSumXX+= kDiff.x * kDiff.x; // sume of the squares of the differences.
fSumXY+= kDiff.x * kDiff.y; // sume of the squares of the differences.
fSumXZ+= kDiff.x * kDiff.z; // sume of the squares of the differences.
// setup the eigensolver
Eigen kES;
fSumYY+= kDiff.y * kDiff.y;
fSumYZ+= kDiff.y * kDiff.z;
fSumZZ+= kDiff.z * kDiff.z;
kES.mElement[0][0] = fSumXX;
kES.mElement[0][1] = fSumXY;
kES.mElement[0][2] = fSumXZ;
kES.mElement[1][0] = fSumXY;
kES.mElement[1][1] = fSumYY;
kES.mElement[1][2] = fSumYZ;
source+=vstride;
}
}
kES.mElement[2][0] = fSumXZ;
kES.mElement[2][1] = fSumYZ;
kES.mElement[2][2] = fSumZZ;
fSumXX *= recip;
fSumXY *= recip;
fSumXZ *= recip;
fSumYY *= recip;
fSumYZ *= recip;
fSumZZ *= recip;
// compute eigenstuff, smallest eigenvalue is in last position
kES.DecrSortEigenStuff();
// setup the eigensolver
Eigen kES;
Vec3 kNormal;
kES.mElement[0][0] = fSumXX;
kES.mElement[0][1] = fSumXY;
kES.mElement[0][2] = fSumXZ;
kNormal.x = kES.mElement[0][2];
kNormal.y = kES.mElement[1][2];
kNormal.z = kES.mElement[2][2];
kES.mElement[1][0] = fSumXY;
kES.mElement[1][1] = fSumYY;
kES.mElement[1][2] = fSumYZ;
// the minimum energy
plane[0] = kNormal.x;
plane[1] = kNormal.y;
plane[2] = kNormal.z;
kES.mElement[2][0] = fSumXZ;
kES.mElement[2][1] = fSumYZ;
kES.mElement[2][2] = fSumZZ;
plane[3] = 0 - kNormal.dot(kOrigin);
// compute eigenstuff, smallest eigenvalue is in last position
kES.DecrSortEigenStuff();
Vec3 kNormal;
kNormal.x = kES.mElement[0][2];
kNormal.y = kES.mElement[1][2];
kNormal.z = kES.mElement[2][2];
// the minimum energy
plane[0] = kNormal.x;
plane[1] = kNormal.y;
plane[2] = kNormal.z;
plane[3] = 0 - kNormal.dot(kOrigin);
return ret;
return ret;
}
float getBoundingRegion(unsigned int vcount,const float *points,unsigned int pstride,float *bmin,float *bmax) // returns the diagonal distance
float getBoundingRegion(unsigned int vcount, const float *points, unsigned int pstride, float *bmin, float *bmax) // returns the diagonal distance
{
const unsigned char *source = (const unsigned char *) points;
const unsigned char *source = (const unsigned char *)points;
bmin[0] = points[0];
bmin[1] = points[1];
@@ -424,43 +413,36 @@ float getBoundingRegion(unsigned int vcount,const float *points,unsigned int pst
bmax[1] = points[1];
bmax[2] = points[2];
for (unsigned int i = 1; i < vcount; i++)
{
source += pstride;
const float *p = (const float *)source;
for (unsigned int i=1; i<vcount; i++)
{
source+=pstride;
const float *p = (const float *) source;
if (p[0] < bmin[0]) bmin[0] = p[0];
if (p[1] < bmin[1]) bmin[1] = p[1];
if (p[2] < bmin[2]) bmin[2] = p[2];
if ( p[0] < bmin[0] ) bmin[0] = p[0];
if ( p[1] < bmin[1] ) bmin[1] = p[1];
if ( p[2] < bmin[2] ) bmin[2] = p[2];
if (p[0] > bmax[0]) bmax[0] = p[0];
if (p[1] > bmax[1]) bmax[1] = p[1];
if (p[2] > bmax[2]) bmax[2] = p[2];
}
if ( p[0] > bmax[0] ) bmax[0] = p[0];
if ( p[1] > bmax[1] ) bmax[1] = p[1];
if ( p[2] > bmax[2] ) bmax[2] = p[2];
}
float dx = bmax[0] - bmin[0];
float dy = bmax[1] - bmin[1];
float dz = bmax[2] - bmin[2];
return sqrtf( dx*dx + dy*dy + dz*dz );
float dx = bmax[0] - bmin[0];
float dy = bmax[1] - bmin[1];
float dz = bmax[2] - bmin[2];
return sqrtf(dx * dx + dy * dy + dz * dz);
}
bool overlapAABB(const float *bmin1,const float *bmax1,const float *bmin2,const float *bmax2) // return true if the two AABB's overlap.
bool overlapAABB(const float *bmin1, const float *bmax1, const float *bmin2, const float *bmax2) // return true if the two AABB's overlap.
{
if ( bmax2[0] < bmin1[0] ) return false; // if the maximum is less than our minimum on any axis
if ( bmax2[1] < bmin1[1] ) return false;
if ( bmax2[2] < bmin1[2] ) return false;
if (bmax2[0] < bmin1[0]) return false; // if the maximum is less than our minimum on any axis
if (bmax2[1] < bmin1[1]) return false;
if (bmax2[2] < bmin1[2]) return false;
if ( bmin2[0] > bmax1[0] ) return false; // if the minimum is greater than our maximum on any axis
if ( bmin2[1] > bmax1[1] ) return false; // if the minimum is greater than our maximum on any axis
if ( bmin2[2] > bmax1[2] ) return false; // if the minimum is greater than our maximum on any axis
if (bmin2[0] > bmax1[0]) return false; // if the minimum is greater than our maximum on any axis
if (bmin2[1] > bmax1[1]) return false; // if the minimum is greater than our maximum on any axis
if (bmin2[2] > bmax1[2]) return false; // if the minimum is greater than our maximum on any axis
return true; // the extents overlap
return true; // the extents overlap
}