82 Vec3(
double _x,
double _y,
double _z) {
x = _x;
y = _y;
z = _z; };
87 return x*v.
x +
y*v.
y +
z*v.
z;
111 double fM00 = mElement[0][0];
112 double fM01 = mElement[0][1];
113 double fM02 = mElement[0][2];
114 double fM11 = mElement[1][1];
115 double fM12 = mElement[1][2];
116 double fM22 = mElement[2][2];
120 if (fM02 != (
double)0.0)
122 double fLength = sqrt(fM01*fM01+fM02*fM02);
123 double fInvLength = ((double)1.0)/fLength;
126 double fQ = ((double)2.0)*fM01*fM12+fM02*(fM22-fM11);
127 m_afDiag[1] = fM11+fM02*fQ;
128 m_afDiag[2] = fM22-fM02*fQ;
129 m_afSubd[0] = fLength;
130 m_afSubd[1] = fM12-fM01*fQ;
131 mElement[0][0] = (double)1.0;
132 mElement[0][1] = (double)0.0;
133 mElement[0][2] = (double)0.0;
134 mElement[1][0] = (double)0.0;
135 mElement[1][1] = fM01;
136 mElement[1][2] = fM02;
137 mElement[2][0] = (double)0.0;
138 mElement[2][1] = fM02;
139 mElement[2][2] = -fM01;
140 m_bIsRotation =
false;
148 mElement[0][0] = (double)1.0;
149 mElement[0][1] = (double)0.0;
150 mElement[0][2] = (double)0.0;
151 mElement[1][0] = (double)0.0;
152 mElement[1][1] = (double)1.0;
153 mElement[1][2] = (double)0.0;
154 mElement[2][0] = (double)0.0;
155 mElement[2][1] = (double)0.0;
156 mElement[2][2] = (double)1.0;
157 m_bIsRotation =
true;
163 const int iMaxIter = 32;
165 for (
int i0 = 0; i0 <3; i0++)
168 for (i1 = 0; i1 < iMaxIter; i1++)
171 for (i2 = i0; i2 <= (3-2); i2++)
173 double fTmp = fabs(m_afDiag[i2]) + fabs(m_afDiag[i2+1]);
174 if ( fabs(m_afSubd[i2]) + fTmp == fTmp )
182 double fG = (m_afDiag[i0+1] - m_afDiag[i0])/(((
double)2.0) * m_afSubd[i0]);
183 double fR = sqrt(fG*fG+(
double)1.0);
184 if (fG < (
double)0.0)
186 fG = m_afDiag[i2]-m_afDiag[i0]+m_afSubd[i0]/(fG-fR);
190 fG = m_afDiag[i2]-m_afDiag[i0]+m_afSubd[i0]/(fG+fR);
192 double fSin = (double)1.0, fCos = (
double)1.0, fP = (double)0.0;
193 for (
int i3 = i2-1; i3 >= i0; i3--)
195 double fF = fSin*m_afSubd[i3];
196 double fB = fCos*m_afSubd[i3];
197 if (fabs(fF) >= fabs(fG))
200 fR = sqrt(fCos*fCos+(
double)1.0);
201 m_afSubd[i3+1] = fF*fR;
202 fSin = ((double)1.0)/fR;
208 fR = sqrt(fSin*fSin+(
double)1.0);
209 m_afSubd[i3+1] = fG*fR;
210 fCos = ((double)1.0)/fR;
213 fG = m_afDiag[i3+1]-fP;
214 fR = (m_afDiag[i3]-fG)*fSin+((
double)2.0)*fB*fCos;
216 m_afDiag[i3+1] = fG+fP;
218 for (
int i4 = 0; i4 < 3; i4++)
220 fF = mElement[i4][i3+1];
221 mElement[i4][i3+1] = fSin*mElement[i4][i3]+fCos*fF;
222 mElement[i4][i3] = fCos*mElement[i4][i3]-fSin*fF;
227 m_afSubd[i2] = (double)0.0;
240 for (
int i0 = 0, i1; i0 <= 3-2; i0++)
244 double fMax = m_afDiag[i1];
246 for (i2 = i0+1; i2 < 3; i2++)
248 if (m_afDiag[i2] > fMax)
258 m_afDiag[i1] = m_afDiag[i0];
261 for (i2 = 0; i2 < 3; i2++)
263 double fTmp = mElement[i2][i0];
264 mElement[i2][i0] = mElement[i2][i1];
265 mElement[i2][i1] = fTmp;
266 m_bIsRotation = !m_bIsRotation;
278 for (
int iRow = 0; iRow <3; iRow++)
280 mElement[iRow][0] = -mElement[iRow][0];
285 double mElement[3][3];
293 const double *points,
294 unsigned int vstride,
295 const double *weights,
296 unsigned int wstride,
307 const char *source = (
const char *) points;
308 const char *wsource = (
const char *) weights;
310 for (
unsigned int i=0; i<vcount; i++)
313 const double *p = (
const double *) source;
319 const double *ws = (
const double *) wsource;
334 double recip = 1.0f / wtotal;
352 const char *source = (
const char *) points;
353 const char *wsource = (
const char *) weights;
355 for (
unsigned int i=0; i<vcount; i++)
358 const double *p = (
const double *) source;
364 const double *ws = (
const double *) wsource;
371 kDiff.
x = w*(p[0] - kOrigin.
x);
372 kDiff.
y = w*(p[1] - kOrigin.
y);
373 kDiff.
z = w*(p[2] - kOrigin.
z);
375 fSumXX+= kDiff.
x * kDiff.
x;
376 fSumXY+= kDiff.
x * kDiff.
y;
377 fSumXZ+= kDiff.
x * kDiff.
z;
379 fSumYY+= kDiff.
y * kDiff.
y;
380 fSumYZ+= kDiff.
y * kDiff.
z;
381 fSumZZ+= kDiff.
z * kDiff.
z;
420 plane[0] = kNormal.
x;
421 plane[1] = kNormal.
y;
422 plane[2] = kNormal.
z;
424 plane[3] = 0 - kNormal.
dot(kOrigin);
431 double getBoundingRegion(
unsigned int vcount,
const double *points,
unsigned int pstride,
double *bmin,
double *bmax)
434 const unsigned char *source = (
const unsigned char *) points;
445 for (
unsigned int i=1; i<vcount; i++)
448 const double *p = (
const double *) source;
450 if ( p[0] < bmin[0] ) bmin[0] = p[0];
451 if ( p[1] < bmin[1] ) bmin[1] = p[1];
452 if ( p[2] < bmin[2] ) bmin[2] = p[2];
454 if ( p[0] > bmax[0] ) bmax[0] = p[0];
455 if ( p[1] > bmax[1] ) bmax[1] = p[1];
456 if ( p[2] > bmax[2] ) bmax[2] = p[2];
460 double dx = bmax[0] - bmin[0];
461 double dy = bmax[1] - bmin[1];
462 double dz = bmax[2] - bmin[2];
464 return sqrt( dx*dx + dy*dy + dz*dz );
469 bool overlapAABB(
const double *bmin1,
const double *bmax1,
const double *bmin2,
const double *bmax2)
471 if ( bmax2[0] < bmin1[0] )
return false;
472 if ( bmax2[1] < bmin1[1] )
return false;
473 if ( bmax2[2] < bmin1[2] )
return false;
475 if ( bmin2[0] > bmax1[0] )
return false;
476 if ( bmin2[1] > bmax1[1] )
return false;
477 if ( bmin2[2] > bmax1[2] )
return false;
double dot(const Vec3 &v)
void GuaranteeRotation(void)
double getBoundingRegion(unsigned int vcount, const double *points, unsigned int pstride, double *bmin, double *bmax)
void DecreasingSort(void)
bool overlapAABB(const double *bmin1, const double *bmax1, const double *bmin2, const double *bmax2)
Vec3(double _x, double _y, double _z)
void DecrSortEigenStuff(void)
bool getBestFitPlane(unsigned int vcount, const double *points, unsigned int vstride, const double *weights, unsigned int wstride, double *plane)