39 template<
unsigned int Dim >
42 if ( sz==0 ) memset( _p , 0 ,
sizeof(_p) );
43 else if( sz==Dim ) memcpy( _p , values ,
sizeof(_p) );
44 else ERROR_OUT(
"Should never be called" );
47 template<
unsigned int Dim >
50 template<
unsigned int Dim >
53 template<
unsigned int Dim >
54 template<
typename ... Doubles >
57 static_assert(
sizeof...(values)==Dim ||
sizeof...(values)==0 ,
"[ERROR] Point< Dim >::Point: Invalid number of coefficients" );
58 const double _values[] = {
static_cast< double >( values )... };
59 _init( _values ,
sizeof...(values) );
62 template<
unsigned int Dim >
65 template<
unsigned int Dim >
68 template<
unsigned int Dim >
72 for(
int i=0 ; i<Dim ; i++ ) dot += _p[i] * q.
_p[i];
76 template<
unsigned int Dim >
79 template<
unsigned int Dim >
82 template<
unsigned int Dim >
86 for(
int i=0 ; i<Dim ; i++ ) p[i] = _p[i]*q.
_p[i];
90 template<
unsigned int Dim >
94 for(
int i=0 ; i<Dim ; i++ ) p[i] = _p[i]/q.
_p[i];
98 template<
unsigned int Dim >
101 template<
unsigned int Dim >
104 template<
unsigned int Dim >
105 template<
typename ... Points >
108 static_assert(
sizeof ... ( points )==Dim-1 ,
"[ERROR] Number of points in cross-product must be one less than the dimension" );
110 return CrossProduct( _points );
113 template<
unsigned int Dim >
116 template<
unsigned int Dim >
120 for(
int d=0 ; d<Dim ; d++ )
for(
int c=0 ; c<Dim-1 ; c++ ) M(d,c) = points[c][d];
122 for(
int d=0 ; d<Dim ; d++ ) p[d] = ( d&1 ) ? -M.subDeterminant( d , Dim-1 ) : M.subDeterminant( d , Dim-1 );
126 template<
unsigned int Dim >
129 for(
int i=0 ; i<Dim-1 ; i++ ) stream << p[i] <<
" ";
133 template<
unsigned int Dim >
136 for(
int i=0 ; i<Dim ; i++ ) stream >> p[i];
143 template<
unsigned int Rows ,
unsigned int Cols ,
typename MatrixType ,
typename MatrixTransposeType >
147 for(
int r=0 ; r<Rows ; r++ )
for(
int c=0 ; c<Cols ; c++ ) dot +=
operator()(r,c) * m(r,c);
151 template<
unsigned int Rows ,
unsigned int Cols ,
typename MatrixType ,
typename MatrixTransposeType >
154 template<
unsigned int Rows ,
unsigned int Cols ,
typename MatrixType ,
typename MatrixTransposeType >
157 template<
unsigned int Rows ,
unsigned int Cols ,
typename MatrixType ,
typename MatrixTransposeType >
160 template<
unsigned int Rows ,
unsigned int Cols ,
typename MatrixType ,
typename MatrixTransposeType >
163 MatrixTransposeType n;
164 for(
int r=0 ; r<Rows ; r++ )
for(
int c=0 ; c<Cols ; c++ ) n(c,r) = operator()(r,c);
168 template<
unsigned int Rows ,
unsigned int Cols ,
typename MatrixType ,
typename MatrixTransposeType >
172 for(
int r=0 ; r<Rows ; r++ )
for(
int c=0 ; c<Cols ; c++ ) q[r] +=
operator()(r,c) * p[c];
176 template<
unsigned int Rows ,
unsigned int Cols ,
typename MatrixType ,
typename MatrixTransposeType >
179 template<
unsigned int Rows ,
unsigned int Cols ,
typename MatrixType ,
typename MatrixTransposeType >
187 template<
unsigned int Rows ,
unsigned int Cols >
188 template<
unsigned int _Cols >
192 for(
int r=0 ; r<Rows ; r++ )
for(
int c=0 ; c<_Cols ; c++ )
for(
int i=0 ; i<Cols ; i++ ) n(r,c) += operator()(r,i) * m(i,c);
200 template<
unsigned int Dim >
203 template<
unsigned int Dim >
206 for(
int i=0 ; i<Dim-1 ; i++ )
for(
int j=0 ; j<Dim-1 ; j++ )
operator()(i,j) = n(i,j);
208 for(
int i=0 ; i<Dim-1 ; i++ )
operator()(i,Dim-1) = p[i];
211 template<
unsigned int Dim >
212 template<
unsigned int Cols >
216 for(
int r=0 ; r<Dim ; r++ )
for(
int c=0 ; c<Cols ; c++ )
for(
int i=0 ; i<Dim ; i++ ) n(r,c) += operator()(r,i) * m(i,c);
220 template<
unsigned int Dim >
224 int rr[Dim-1] , cc[Dim-1];
225 for(
int a=0 , _r=0 , _c=0 ; a<Dim ; a++ )
227 if( a!=r ) rr[_r++] = a;
228 if( a!=c ) cc[_c++] = a;
230 for(
int _c=0 ; _c<Dim-1 ; _c++ )
for(
int _r=0 ; _r<Dim-1 ; _r++ ) m(_r,_c) = operator()( rr[_r] , cc[_c] );
231 return m.determinant();
234 template<
unsigned int Dim >
238 for(
int d=0 ; d<Dim ; d++ )
239 if( d&1 ) det -= operator()(0,d) * subDeterminant( 0 , d );
240 else det += operator()(0,d) * subDeterminant( 0 , d );
248 operator()(0,0)*( operator()(1,1)*operator()(2,2) - operator()(1,2)*operator()(2,1) ) -
249 operator()(0,1)*(
operator()(1,0)*
operator()(2,2) -
operator()(1,2)*
operator()(2,0) ) +
250 operator()(0,2)*( operator()(1,0)*operator()(2,1) - operator()(1,1)*operator()(2,0) );
259 template<
unsigned int Dim >
263 for(
int i=0 ; i<Dim ; i++ ) tr +=
operator()(i,i);
266 template<
unsigned int Dim >
270 if( !setInverse( inv ) )
THROW(
" singular matrix" );
274 template<
unsigned int Dim >
277 double d = determinant();
278 if( !d )
return false;
279 for(
int i=0 ; i<Dim ; i++ )
for(
int j=0 ; j<Dim ; j++ )
280 if( (i+j)%2==0 ) inv(i,j) = subDeterminant( j , i ) / d;
281 else inv(i,j) = -subDeterminant( j , i ) / d;
288 double det = determinant();
289 if( !det )
return false;
290 inv(0,0) = ( operator()(1,1)*operator()(2,2) - operator()(1,2)*operator()(2,1) ) / det;
291 inv(0,1) = -( operator()(0,1)*operator()(2,2) - operator()(2,1)*operator()(0,2) ) / det;
292 inv(0,2) = ( operator()(0,1)*operator()(1,2) - operator()(0,2)*operator()(1,1) ) / det;
293 inv(1,0) = -( operator()(1,0)*operator()(2,2) - operator()(1,2)*operator()(2,0) ) / det;
294 inv(1,1) = ( operator()(0,0)*operator()(2,2) - operator()(0,2)*operator()(2,0) ) / det;
295 inv(1,2) = -( operator()(0,0)*operator()(1,2) - operator()(0,2)*operator()(1,0) ) / det;
296 inv(2,0) = ( operator()(1,0)*operator()(2,1) - operator()(1,1)*operator()(2,0) ) / det;
297 inv(2,1) = -( operator()(0,0)*operator()(2,1) - operator()(0,1)*operator()(2,0) ) / det;
298 inv(2,2) = ( operator()(0,0)*operator()(1,1) - operator()(0,1)*operator()(1,0) ) / det;
306 double det = determinant();
307 if( !det )
return false;
308 inv(0,0) = operator()(1,1) / det;
309 inv(1,1) = operator()(0,0) / det;
310 inv(1,0) = -operator()(1,0) / det;
311 inv(0,1) = -operator()(0,1) / det;
319 double det = operator()(0,0);
320 if( !det )
return false;
325 template<
unsigned int Dim >
329 for(
int i=0 ; i<Dim-1 ; i++ ) q[i] = p[i];
333 for(
int i=0 ; i<Dim-1 ; i++ ) _q[i] = q[i] / q[Dim-1];
337 template<
unsigned int Dim >
341 for(
int i=0 ; i<Dim ; i++ ) m(i,i) = 1;
345 template<
unsigned int Dim >
353 for(
int i=0 ; i<Dim ; i++ )
for(
int j=0 ; j<Dim ; j++ ) M(i,j) = operator()(i,j);
355 for(
int i=0 ; i<Dim ; i++ )
357 for(
int j=0 ; j<Dim ; j++ ) r1(j,i) = U(j,i) , r2(j,i) = Vt(j,i);
365 template<
unsigned int Dim >
371 while( (X*X-m).squareNorm()>eps*eps )
381 template<
unsigned int Dim >
387 while( (A-I).squareNorm()>0.25 )
389 A = SquareRoot( A , eps );
401 return X * ( -pow( 2.0 , (
double)k ) );
404 template<
unsigned int Dim >
407 template<
unsigned int Dim >
410 template<
unsigned int Rows ,
unsigned int Cols ,
typename MatrixType ,
typename MatrixTransposeType >
413 for(
unsigned int c=0 ; c<Cols ; c++ )
for(
unsigned int r=0 ; r<Rows ; r++ )
416 if( r!=Rows-1 || c!=Cols-1 ) stream <<
" ";
421 template<
unsigned int Rows ,
unsigned int Cols ,
typename MatrixType ,
typename MatrixTransposeType >
424 for(
unsigned int c=0 ; c<Cols ; c++ )
for(
unsigned int r=0 ; r<Rows ; r++ ) stream >> m(r,c);
431 template<
unsigned int Dim >
434 template<
unsigned int Dim >
441 template<
unsigned int Dim >
442 template<
typename ... Points >
445 static_assert(
sizeof ... ( points )==Dim ,
"[ERROR] Number of points in plane constructor must equal the dimension" );
447 (*this) =
Plane( _points );
450 template<
unsigned int Dim >
453 template<
unsigned int Dim >
457 for(
int i=1 ; i<Dim ; i++ ) _points[i-1] = points[i] - points[0];
462 template<
unsigned int Dim >
471 template<
unsigned int Dim >
474 template<
unsigned int Dim >
477 template<
unsigned int Dim >
480 template<
unsigned int Dim >
483 template<
unsigned int Dim >
486 template<
unsigned int Dim >
489 template<
unsigned int Dim >
492 template<
unsigned int Dim >
502 template<
unsigned int Dim >
505 template<
unsigned int Dim >
508 for(
int d=0 ; d<Dim ; d++ ) _p[0][d] = std::min< double >( p1[d] , p2[d] ) , _p[1][d] = std::max< double >( p1[d] , p2[d] );
511 template<
unsigned int Dim >
516 _p[0] = _p[1] = pList[0];
517 for(
int i=1 ; i<pSize ; i++ ) for( int j=0 ; j<Dim ; j++ ) _p[0][j] = std::min< double >( _p[0][j] , pList[i][j] ) , _p[1][j] = std::max< double >( _p[1][j] , pList[i][j] );
521 template<
unsigned int Dim >
524 template<
unsigned int Dim >
527 template<
unsigned int Dim >
533 if(
b.isEmpty() )
return *
this;
534 if( isEmpty() )
return b;
542 template<
unsigned int Dim >
545 template<
unsigned int Dim >
551 for(
int j=0 ; j<Dim ; j++ ) _b.
_p[0][j] = std::max< double >( _p[0][j] ,
b._p[0][j] ) , _b.
_p[1][j] = std::min< double >( _p[1][j] ,
b._p[1][j] );
556 template<
unsigned int Dim >
559 template<
unsigned int Dim >
563 for(
int idx=0 ; idx<(1<<Dim) ; idx++ )
566 for(
int d=0 ; d<Dim ; d++ ) p[d] =
b[(idx>>d)&1][d];
572 template<
unsigned int Dim >
575 for(
int d=0 ; d<Dim ; d++ )
if( p[d]<=_p[0][d] || p[d]>=_p[1][d] )
return false;
579 template<
unsigned int Dim >
582 for(
int d=0 ; d<Dim ; d++ )
if( _p[0][d]>=_p[1][d] )
return true;
586 template<
unsigned int Dim >
589 stream <<
"[ " <<
b[0] <<
" ] [ " <<
b[1] <<
" ]";
596 template<
unsigned int Dim >
599 template<
unsigned int Dim >
602 template<
unsigned int Dim >
606 for(
unsigned int i=0 ; i<Dim ; i++ )
608 _L[i] = ( Q(i,Dim) + Q(Dim,i) ) / 2.;
609 for(
unsigned int j=0 ; j<Dim ; j++ ) _Q(i,j) = ( Q(i,j) + Q(j,i) ) / 2.;
613 template<
unsigned int Dim >
618 for(
unsigned int i=0 ; i<Dim ; i++ )
620 Q(Dim,i) = Q(i,Dim) = _L[i];
621 for(
unsigned int j=0 ; j<Dim ; j++ ) Q(i,j) = _Q(i,j);
626 template<
unsigned int Dim >
629 template<
unsigned int Dim >
632 template<
unsigned int Dim >
635 template<
unsigned int Dim >
638 template<
unsigned int Dim >
641 template<
unsigned int Dim >
644 template<
unsigned int Dim >
647 template<
unsigned int Dim >
648 template<
unsigned int _Dim >
656 Q.
_L = T.transpose() * _L;
661 template<
unsigned int Dim >
674 template<
unsigned int Dim >
683 try{ extremum = -_Q.inverse() * _L; }
684 catch( std::exception & ){
return false; }
691 template<
unsigned int Dim >
694 template<
unsigned int Dim >
697 template<
unsigned int Dim >
700 template<
unsigned int Dim >
707 for(
unsigned int d=0 ; d<Dim ; d++ )
710 for(
unsigned int dd=0 ; dd<Dim ; dd++ )
if( dd!=d ) _boundaryInfo[d]._T(dd,idx++) = 1.;
711 _boundaryInfo[d]._Tt = _boundaryInfo[d]._T.
transpose();
712 _boundaryInfo[d]._set( Q * _boundaryInfo[d]._T );
713 _boundaryInfo[d]._Tt_Q = _boundaryInfo[d]._Tt * _Q;
717 template<
unsigned int Dim >
728 for(
unsigned int d=0 ; d<Dim ; d++ )
751 for(
unsigned int dd=0 ; dd<Dim ; dd++ )
if( dd!=d )
753 _bBox[0][idx] = bBox[0][dd];
754 _bBox[1][idx] = bBox[1][dd];
760 _Q.
_Q = _boundaryInfo[d]._Q;
762 Point< Dim-1 > _L = _boundaryInfo[d]._Tt * Q.
_L;
764 for(
unsigned int i=0 ; i<Dim-1 ; i++ ) _v[i] = _boundaryInfo[d]._Tt_Q(i,d);
766 for(
unsigned int o=0 ; o<2 ; o++ )
768 double v = bBox[o][d];
770 _Q._C = Q.
_C + v * v * Q.
_Q(d,d) + 2. * v * Q.
_L[d];
771 if( _boundaryInfo[d]._intersect( _Q , _bBox ) )
return true;
778 return bBox.
isInside( extremum ) && Q( extremum )<0;
790 if( Q(bBox[0])<0 || Q(bBox[1])<0 )
return true;
792 return extremum[0]>bBox[0][0] && extremum[0]<bBox[1][0] && Q(extremum)<0;
798 template<
typename RotationParameterType ,
typename ParameterType >
801 RotationParameterType p;
802 p.parameter = parameter * scale;
806 template<
typename RotationParameterType ,
typename ParameterType >
809 RotationParameterType _p;
810 _p.parameter = parameter + p.parameter;
817 template<
typename RotationParameterType >
826 template<
typename RotationParameterType >
835 template<
typename RotationParameterType >
838 template<
typename RotationParameterType >
841 for(
int i=0 ; i<3 ; i++ )
translation[i] = m(i,3);
844 template<
typename RotationParameterType >
847 for(
int i=0 ; i<3 ; i++ )
translation[i] = m(i,3);
850 template<
typename RotationParameterType >
853 return Matrix4D( rotationParameter() , translation );
434 template<
unsigned int Dim > {
…}
431 template<
unsigned int Dim > {
…}
416 if( r!=Rows-1 || c!=Cols-1 ) stream <<
" "; {
…}
413 for(
unsigned int c=0 ; c<Cols ; c++ )
for(
unsigned int r=0 ; r<Rows ; r++ ) {
…}
143 template<
unsigned int Rows ,
unsigned int Cols ,
typename MatrixType ,
typename MatrixTransposeType > {
…}
108 static_assert(
sizeof ... ( points )==Dim-1 ,
"[ERROR] Number of points in cross-product must be one less than the dimension" ); {
…}
105 template<
typename ... Points > {
…}
82 template<
unsigned int Dim > {
…}
79 template<
unsigned int Dim > {
…}
76 template<
unsigned int Dim > {
…}
57 static_assert(
sizeof...(values)==Dim ||
sizeof...(values)==0 ,
"[ERROR] Point< Dim >::Point: Invalid number of coefficients" ); {
…}
const GXMatrixMNTC< Coord > Identity(unsigned int cOrder)
void SVDMat(GXMatrixMNTC< REAL > &A, GXMatrixMNTC< REAL > &u, GXMatrixMNTC< REAL > &w, GXMatrixMNTC< REAL > &vt)
Definition SVDFit.inl:59
Definition MatrixMNTC.h:48
Definition geometry.h:126
Point< Rows > operator*(const Point< Cols > &p) const
Definition geometry.inl:169
double & operator()(int r, int c)
Definition geometry.inl:155
_BaseMatrix(void)
Definition geometry.inl:152
MatrixType operator+(const MatrixType &m) const
Definition geometry.inl:180
double dot(const _BaseMatrix &p) const
Definition geometry.inl:144
MatrixTransposeType transpose(void) const
Definition geometry.inl:161
double squareNorm(void) const
Definition algebra.h:117
Element unit(void) const
Definition algebra.h:123
static double Dot(const Point< Dim > &e1, const Point< Dim > &e2)
Definition algebra.h:102
Definition geometry.h:345
BoundingBox(void)
Definition geometry.inl:503
bool isEmpty(void) const
Definition geometry.inl:580
BoundingBox & operator^=(const BoundingBox &b)
Definition geometry.inl:557
BoundingBox & operator+=(const BoundingBox &b)
Definition geometry.inl:543
bool isInside(const Point< Dim > &p) const
Definition geometry.inl:573
BoundingBox operator+(const BoundingBox &b) const
Definition geometry.inl:528
Point< Dim > & operator[](int index)
Definition geometry.inl:522
BoundingBox operator^(const BoundingBox &b) const
Definition geometry.inl:546
Point< Dim > _p[2]
Definition geometry.h:350
Definition geometry.h:187
double trace(void) const
Definition geometry.inl:260
Matrix skewSymmetrize(void) const
Definition geometry.inl:408
double subDeterminant(int r, int c) const
Definition geometry.inl:221
static Matrix SquareRoot(const Matrix &m, double eps=0.000001)
Definition geometry.inl:366
Matrix(void)
Definition geometry.inl:199
Matrix symmetrize(void) const
Definition geometry.inl:405
void SVD(Matrix &r1, Matrix &diagonal, Matrix &r2) const
Definition geometry.inl:346
static Matrix Log(const Matrix &m, double eps=0.0001)
Definition geometry.inl:382
Matrix inverse(void) const
Definition geometry.inl:267
bool setInverse(Matrix &m) const
Definition geometry.inl:275
static Matrix Identity(void)
Definition geometry.inl:338
double determinant(void) const
Definition geometry.inl:235
Definition geometry.h:168
Matrix(void)
Definition geometry.inl:185
Definition geometry.h:269
Plane(void)
Definition geometry.inl:432
double operator()(const Point< Dim > &p) const
Definition geometry.inl:463
static Point CrossProduct(Points ... points)
double & operator[](int index)
Definition geometry.inl:77
Point(void)
Definition geometry.inl:48
void _init(const double *values, unsigned int sz)
Definition geometry.inl:40
double _p[Dim]
Definition geometry.h:54
Point operator+(const Point &p) const
Definition geometry.inl:66
double dot(const Point &p) const
Definition geometry.inl:69
Definition geometry.h:399
double getConstant(void) const
Definition geometry.inl:633
Quadric< _Dim > operator*(const Matrix< Dim, _Dim > &T) const
Definition geometry.inl:649
friend class Quadric
Definition geometry.h:405
Point< Dim > getLinear(void) const
Definition geometry.inl:630
Matrix< Dim+1, Dim+1 > operator()(void) const
Definition geometry.inl:614
void setQuadratic(Matrix< Dim, Dim > Q)
Definition geometry.inl:636
bool setExtremum(Point< Dim > &extremum) const
Definition geometry.inl:675
void setLinear(Point< Dim > L)
Definition geometry.inl:639
Matrix< Dim, Dim > _Q
Definition geometry.h:400
Matrix< Dim, Dim > getQuadratic(void) const
Definition geometry.inl:627
void setConstant(double C)
Definition geometry.inl:642
Point< Dim > _L
Definition geometry.h:401
Quadric< Dim > operator+(const Point< Dim > &t) const
Definition geometry.inl:662
double _C
Definition geometry.h:402
Definition geometry.h:299
Ray operator+(const Point< Dim > &p) const
Definition geometry.inl:481
Point< Dim > direction
Definition geometry.h:305
Ray(void)
Definition geometry.inl:472
Point< Dim > position
Definition geometry.h:302
Point< Dim > operator()(double t) const
Definition geometry.inl:478
Ray operator-(const Point< Dim > &p) const
Definition geometry.inl:487
Ray & operator+=(const Point< Dim > &p)
Definition geometry.inl:484
Ray & operator-=(const Point< Dim > &p)
Definition geometry.inl:490
RotationParameterType operator+(const RotationParameterType &p) const
Definition geometry.inl:807
RotationParameterType operator*(double scale) const
Definition geometry.inl:799
friend Point< Dim > & operator*=(Point< Dim > &e, double s)
Definition algebra.h:81
friend Point< Dim > operator*(double s, const Point< Dim > &e)
Definition algebra.h:90
friend Point< Dim > operator/(const Point< Dim > &e, double s)
Definition algebra.h:72
friend Point< Dim > & operator/=(Point< Dim > &e, double s)
Definition algebra.h:84
#define ERROR_OUT(...)
Definition exceptions.h:154
#define THROW(...)
Definition exceptions.h:151
long b
Definition jpegint.h:371
Matrix< 4, 4 > Matrix4D
Definition geometry.h:544
std::ostream & operator<<(std::ostream &stream, const Point< Dim > &p)
Definition geometry.inl:127
std::istream & operator>>(std::istream &stream, Point< Dim > &p)
Definition geometry.inl:134
Ray< Dim > operator*(const Matrix< Dim+1, Dim+1 > &m, const Ray< Dim > &ray)
Definition geometry.inl:493
Matrix< Dim, Dim > SquareMatrix
Definition geometry.h:532
Matrix< Dim, Dim > _Qinv
Definition geometry.h:476
Matrix< Dim, Dim > _Q
Definition geometry.h:476
bool _intersect(const Quadric< Dim > &Q, const BoundingBox< Dim > &bBox) const
Definition geometry.inl:718
friend struct QuadricBoundingBoxOverlap
Definition geometry.h:474
Quadric< Dim > _quadric
Definition geometry.h:475
bool operator()(const BoundingBox< Dim > &bBox) const
Definition geometry.inl:698
void _set(const Quadric< Dim > &Q)
Definition geometry.inl:701