diff --git a/vcg/math/camera.h b/vcg/math/camera.h index 107cfe4f..2a3f9220 100644 --- a/vcg/math/camera.h +++ b/vcg/math/camera.h @@ -23,6 +23,9 @@ /**************************************************************************** History $Log: not supported by cvs2svn $ +Revision 1.25 2005/12/12 16:52:55 callieri +Added Unproject, from 2D local space + Zdepth to 3D camera space. Added ViewportToLocal, inverse of LocalToViewport + Revision 1.24 2005/12/01 01:03:37 cignoni Removed excess ';' from end of template functions, for gcc compiling @@ -118,11 +121,10 @@ creation namespace vcg{ enum { - - PERSPECTIVE = 0, - ORTHO = 1, - ISOMETRIC = 2, - CAVALIERI = 3 + PERSPECTIVE = 0, + ORTHO = 1, + ISOMETRIC = 2, + CAVALIERI = 3 }; @@ -131,228 +133,219 @@ class Camera { public: typedef S ScalarType; + Camera(): - f(0.f),s(vcg::Point2(0.0,0.0)), - c(vcg::Point2(0.0,0.0)), - viewport(vcg::Point2(0,0)), - viewportM(1),_flags(0), cameraType(0) + FocalMm(0.f),PixelSizeMm(vcg::Point2(0.0,0.0)), + CenterPx(vcg::Point2(0.0,0.0)), + DistorCenterPx(vcg::Point2(0.0,0.0)), + ViewportPx(vcg::Point2(0,0)), + cameraType(0) {} - S f; // Focal Distance (cioe' la distanza del piano immagine dal centro di proiezione - S farend; // farend end of frustum (it doesn influence the projection ) - vcg::Point2 s; // Scale factor of the image (nei casi in cui a senso) - vcg::Point2 c; // pin-hole position + //------ camera intrinsics + ScalarType FocalMm; /// Focal Distance: the distance between focal center and image plane. Expressed in mm + Point2 ViewportPx; /// Dimension of the Image Plane (in pixels) + Point2 PixelSizeMm; /// Dimension in mm of a single pixel + Point2 CenterPx; /// Position of the projection of the focal center on the image plane. Expressed in pixels - vcg::Point2 viewport; // Size viewport (in pixels) - vcg::Point2 p; // principal point (between -1 and 1) for distortion - S k[4]; // 1st & 2nd order radial lens distortion coefficient + Point2 DistorCenterPx; /// Position of the radial distortion center on the image plane in pixels + S k[4]; /// 1st & 2nd order radial lens distortion coefficient (only the first 2 terms are used) + //------------------------ - S viewportM; // ratio between viewport in pixel and size (useful to avoid chancing s or viewport when - // zooming a ortho camera (for a perspective camera it is 1) + int cameraType; /// Type of camera: PERSPECTIVE,ORTHO,ISOMETRIC,CAVALIERI - /*enum{ - ORTHO_BIT = 0x01 // true if the camera is orthogonal - };*/ - - - - char _flags; - - int cameraType; - //bool IsOrtho(){ return (_flags & ORTHO_BIT);} - - - - /*void SetOrtho(bool v, S dist ) + void SetOrtho(S dist) { - if(v) - { - _flags |= ORTHO_BIT; - viewportM = ( ((viewport[0] * s[0]) * (viewport[1] * s[1])) / f ) * dist; - } - else _flags &= ~ORTHO_BIT; - - };*/ - - char & UberFlags() {return _flags;} - - void SetOrtho(S dist ) - { - - cameraType = ORTHO; - viewportM = ( ((viewport[0] * s[0]) * (viewport[1] * s[1])) / f ) * dist; - - + cameraType = ORTHO; + ViewportPx = ( ((ViewportPx[0] * PixelSizeMm[0]) * (ViewportPx[1] * PixelSizeMm[1])) / f ) * dist; }; - bool IsOrtho() { return ( cameraType == ORTHO ); } + + bool IsOrtho() const + { + return ( cameraType == ORTHO ); + } + + //--- Set-up methods /// set the camera specifying the perspecive view - inline void SetPerspective(S angle, S ratio, S nearend, S farend,vcg::Point2 viewport=vcg::Point2(500,-1) ); - + inline void SetPerspective(S AngleDeg, S AspectRatio, S Focal, vcg::Point2 Viewport); /// set the camera specifying the cavalieri view - inline void SetCavalieri(S sx, S dx, S bt, S tp, S nearend, S farend, vcg::Point2 viewport=vcg::Point2(500,-1) ); - + inline void SetCavalieri(S sx, S dx, S bt, S tp, S Focal, vcg::Point2 Viewport); /// set the camera specifying the isometric view - inline void SetIsometric(S sx, S dx, S bt, S tp, S nearend, S farend, vcg::Point2 viewport=vcg::Point2(500,-1) ); + inline void SetIsometric(S sx, S dx, S bt, S tp, S Focal, vcg::Point2 Viewport); - /// set the camera specifying the frustum view - inline void SetFrustum(S dx, S sx, S bt, S tp, S nearend, S farend,vcg::Point2 viewport=vcg::Point2(500,-1)); + /// set the camera specifying the frustum view + inline void SetFrustum(S dx, S sx, S bt, S tp, S Focal, vcg::Point2 Viewport); + //------------------ - /// get the camera frustum view - inline void GetFrustum(S & sx,S & dx,S & bt,S & tp, S & f ,S & fr); + /// returns the frustum + inline void GetFrustum(S & sx, S & dx, S & bt, S & tp, S & nr); - /// project a point from space 3d (in the reference system of the camera) to the camera's plane - /// the result is in absolute coordinates - inline vcg::Point2 Project(const vcg::Point3 & p); - inline vcg::Point3 UnProject(const vcg::Point2 & p, const S & d); - inline vcg::Point2 LocalToViewport(const vcg::Point2 & p); - inline vcg::Point2 ViewportToLocal(const vcg::Point2 & p); - inline vcg::Point2 LocalTo_0_1(const vcg::Point2 & p); - inline vcg::Point2 LocalTo_neg1_1(const vcg::Point2 & p); + //--- Space transformation methods + + /// project a point from 3d CAMERA space to the camera local plane + inline vcg::Point2 Project(const vcg::Point3 & p) const; + + /// unproject a point from the camera local plane (plus depth) to 3d CAMERA space + inline vcg::Point3 UnProject(const vcg::Point2 & p, const S & d) const; + + /// transforms local plane coords to vieport (pixel) coords + inline vcg::Point2 LocalToViewportPx(const vcg::Point2 & p) const; + + /// transforms vieport (pixel) coords to local plane coords + inline vcg::Point2 ViewportPxToLocal(const vcg::Point2 & p) const; + + /// transforms local plane coords to [0 1] coords + inline vcg::Point2 LocalTo_0_1(const vcg::Point2 & p) const; + + /// transforms local plane coords to [-1 1] coords + inline vcg::Point2 LocalTo_neg1_1(const vcg::Point2 & p) const; + //-------------------------------- }; -/// project a point in the camera plane (in space [-1,-1]x[1,1] ) + + +/// project a point from 3d CAMERA space to the camera's plane] template -vcg::Point2 Camera::Project(const vcg::Point3 & p){ - vcg::Point2 q = Point2( p[0],p[1]); - // nota: per le camere ortogonali viewportM vale 1 - if(!IsOrtho()) - { - q[0] *= f/p.Z(); - q[1] *= f/p.Z(); - } +vcg::Point2 Camera::Project(const vcg::Point3 & p) const +{ + vcg::Point2 q = Point2(p[0],p[1]); + + if(!IsOrtho()) + { + q[0] *= FocalMm/p.Z(); + q[1] *= FocalMm/p.Z(); + } + return q; } -/// project back a 2D point on LOCAL plane + Zdepth to 3D camera space coord +/// unproject a point from the camera 2d plane [-1,-1]x[1,1] (plus depth) to 3d CAMERA space template -vcg::Point3 Camera::UnProject(const vcg::Point2 & p, const S & d) +vcg::Point3 Camera::UnProject(const vcg::Point2 & p, const S & d) const { vcg::Point3 np = Point3(p[0], p[1], d); if(!IsOrtho()) { - np[0] /= f/d; - np[1] /= f/d; + np[0] /= FocalMm/d; + np[1] /= FocalMm/d; } return np; } +/// transforms local plane coords to vieport (pixel) coords template -vcg::Point2 Camera::LocalToViewport(const vcg::Point2 & p){ - vcg::Point2 ps; - ps[0] = p[0]/s.X()+c.X(); - ps[1] = p[1]/s.Y()+c.Y(); - return ps; -} - -template -vcg::Point2 Camera::ViewportToLocal(const vcg::Point2 & p){ - vcg::Point2 ps; - ps[0] = (p[0]-c.X()) * s.X(); - ps[1] = (p[1]-c.Y()) * s.Y(); - return ps; -} - -template -vcg::Point2 Camera::LocalTo_0_1(const vcg::Point2 & p){ - vcg::Point2 ps; - ps[0] = ( p[0]/s.X() + c.X() ) / (ScalarType) viewport[0]; - ps[1] = ( p[1]/s.Y() + c.Y() ) / (ScalarType) viewport[1]; - return ps; -} - -template -vcg::Point2 Camera::LocalTo_neg1_1(const vcg::Point2 & p){ - vcg::Point2 ps; - ps[0] = 2 * p[0] / ( s.X() * viewport[0] ); - ps[1] = 2 * p[1] / ( s.Y() * viewport[1] ); - return ps; -} - -/// set the camera specifying the cavalieri view -template -void Camera::SetCavalieri(S sx, S dx, S bt, S tp, S nearend, S farend, vcg::Point2 viewport) +vcg::Point2 Camera::LocalToViewportPx(const vcg::Point2 & p) const { - cameraType = CAVALIERI; - SetFrustum(sx, dx, bt, tp, nearend,farend,viewport); + vcg::Point2 np; + + np[0] = (p[0] / PixelSizeMm.X()) + CenterPx.X(); + np[1] = (p[1] / PixelSizeMm.Y()) + CenterPx.Y(); + + return np; } -/// set the camera specifying the isometric view +/// transforms vieport (pixel) coords to local plane coords template -void Camera::SetIsometric(S sx, S dx, S bt, S tp, S nearend, S farend, vcg::Point2 viewport ) +vcg::Point2 Camera::ViewportPxToLocal(const vcg::Point2 & p) const { - cameraType = ISOMETRIC; - SetFrustum(sx, dx, bt, tp, nearend,farend,viewport); + vcg::Point2 ps; + ps[0] = (p[0]-CenterPx.X()) * PixelSizeMm.X(); + ps[1] = (p[1]-CenterPx.Y()) * PixelSizeMm.Y(); + return ps; } +/// transforms local plane coords to [0-1] coords +template +vcg::Point2 Camera::LocalTo_0_1(const vcg::Point2 & p) const +{ + vcg::Point2 ps; + ps[0] = ( p[0]/PixelSizeMm.X() + CenterPx.X() ) / (S)ViewportPx[0]; + ps[1] = ( p[1]/PixelSizeMm.Y() + CenterPx.Y() ) / (S)ViewportPx[1]; + return ps; +} + +/// transforms local plane coords to [-1 1] coords +template +vcg::Point2 Camera::LocalTo_neg1_1(const vcg::Point2 & p) const +{ + vcg::Point2 ps; + ps[0] = 2.0f * p[0] / ( PixelSizeMm.X() * (S)ViewportPx[0] ); + ps[1] = 2.0f * p[1] / ( PixelSizeMm.Y() * (S)ViewportPx[1] ); + return ps; +} + +//--- basic camera setup (GL-like) /// set the camera specifying the perspective view template - void Camera::SetPerspective( S angle, - S ratio, - S near_thr, - S far_thr, - vcg::Point2 vp) +void Camera::SetPerspective( S AngleDeg, S AspectRatio, S Focal, vcg::Point2 Viewport) { - cameraType = PERSPECTIVE; - S halfsize[2]; - halfsize[1] = tan(math::ToRad(angle/2)) * near_thr; - halfsize[0] = halfsize[1]*ratio; - SetFrustum(-halfsize[0],halfsize[0],-halfsize[1],halfsize[1],near_thr,far_thr,vp); + cameraType = PERSPECTIVE; + S halfsize[2]; + + halfsize[1] = tan(math::ToRad(AngleDeg/2.0f)) * Focal; + halfsize[0] = halfsize[1]*AspectRatio; + + SetFrustum(-halfsize[0],halfsize[0],-halfsize[1],halfsize[1],Focal,Viewport); } - - /// set the camera specifying the frustum view template - void Camera::SetFrustum( S sx, - S dx, - S bt, - S tp, - S near_thr, - S far_thr, - vcg::Point2 vp ) +void Camera::SetFrustum( S sx, S dx, S bt, S tp, S Focal, vcg::Point2 Viewport) { S vpt[2]; vpt[0] = dx-sx; vpt[1] = tp-bt; - viewport[0] = vp[0]; + ViewportPx[0] = vp[0]; if(vp[1] != -1) - viewport[1] = vp[1];// the user specified the viewport + ViewportPx[1] = vp[1]; // the user specified the viewport else - viewport[1] = viewport[0];// default viewport + ViewportPx[1] = ViewportPx[0]; // default viewport - s[0] = vpt[0]/(S) viewport[0]; - s[1] = vpt[1]/(S) viewport[1]; + PixelSizeMm[0] = vpt[0] / (S)Viewport[0]; + PixelSizeMm[1] = vpt[1] / (S)Viewport[1]; - c[0] = -sx/vpt[0] * viewport[0]; - c[1] = -bt/vpt[1] * viewport[1]; + CenterPx[0] = -sx/vpt[0] * (S)Viewport[0]; + CenterPx[1] = -bt/vpt[1] * (S)Viewport[1]; - f =near_thr; - farend = far_thr; + FocalMm =Focal; } +//--- special cameras setup + +/// set the camera specifying the cavalieri view template - void Camera:: GetFrustum( S & sx, - S & dx, - S & bt, - S & tp, - S & nr , - S & fr ) +void Camera::SetCavalieri(S sx, S dx, S bt, S tp, S Focal, vcg::Point2 Viewport) { - dx = c.X()*s.X(); //scaled center - sx = -( viewport.X() - c.X() ) * s.X(); + cameraType = CAVALIERI; + SetFrustum(sx, dx, bt, tp, Focal,Viewport); +} - bt = -c.Y()*s.Y(); - tp = ( viewport.Y() - c.Y() ) * s.Y(); +/// set the camera specifying the isometric view +template +void Camera::SetIsometric(S sx, S dx, S bt, S tp, S Focal, vcg::Point2 Viewport) +{ + cameraType = ISOMETRIC; + SetFrustum(sx, dx, bt, tp, Focal,Viewport); +} - nr = f; - fr = farend; +/// returns the frustum +template +void Camera:: GetFrustum( S & sx, S & dx, S & bt, S & tp, S & nr) +{ + dx = CenterPx.X()* PixelSizeMm.X(); //scaled center + sx = -( (S)ViewportPx.X() - CenterPx.X() ) * PixelSizeMm.X(); + + bt = -CenterPx.Y()* PixelSizeMm.Y(); + tp = ( (S)ViewportPx.Y() - CenterPx.Y() ) * PixelSizeMm.Y(); + + nr = FocalMm; } } @@ -361,895 +354,3 @@ template - - -//private: -// -// static inline S SQRT( S x) { return sqrt(fabs(x)); } -// static inline S CBRT ( S x ) -// { -// if (x == 0) return 0; -// else if (x > 0) return pow (x, 1.0 / 3.0); -// else return -pow (-x, 1.0 / 3.0); -// } -// static inline void SINCOS( S x, S & s, S & c) -// { -// s=sin(x); -// c=cos(x); -// } -// static inline void SINCOSd( double x, double & s, double & c) -// { -// s=sin(x); -// c=cos(x); -// } -// static inline S CUB( S x ) { return x*x*x; } -// static inline S SQR( S x ) { return x*x; } -// -//public: -// void undistorted_to_distorted_sensor_coord (S Xu, S Yu, S & Xd, S & Yd) const -// { -// const S SQRT3 = S(1.732050807568877293527446341505872366943); -// S Ru,Rd,lambda,c,d,Q,R,D,S,T,sinT,cosT; -// -// if((Xu==0 && Yu==0) || k[0] == 0) -// { -// Xd = Xu; -// Yd = Yu; -// return; -// } -// -// Ru = hypot (Xu, Yu); /* SQRT(Xu*Xu+Yu*Yu) */ -// c = 1 / k[0]; -// d = -c * Ru; -// -// Q = c / 3; -// R = -d / 2; -// D = CUB (Q) + SQR (R); -// -// if (D >= 0) /* one real root */ -// { -// D = SQRT (D); -// S = CBRT (R + D); -// T = CBRT (R - D); -// Rd = S + T; -// -// if (Rd < 0) -// Rd = SQRT (-1 / (3 * k[0])); -// } -// else /* three real roots */ -// { -// D = SQRT (-D); -// S = CBRT (hypot (R, D)); -// T = atan2 (D, R) / 3; -// SINCOS (T, sinT, cosT); -// -// /* the larger positive root is 2*S*cos(T) */ -// /* the smaller positive root is -S*cos(T) + SQRT(3)*S*sin(T) */ -// /* the negative root is -S*cos(T) - SQRT(3)*S*sin(T) */ -// Rd = -S * cosT + SQRT3 * S * sinT; /* use the smaller positive root */ -// } -// -// lambda = Rd / Ru; -// -// Xd = Xu * lambda; -// Yd = Yu * lambda; -// } -// -// -//void correction(double k, float i, float j, float &disi, float &disj) -//{ -// // (i,j) punto nell'immagine distorta -// // (disi,disj) punto nell'immagine corretta (undistorted) -// float hyp; -// float I,J,ni,nj; -// float ratio = 1; -// -// ni = i-viewport[0]/2; -// nj = j-viewport[1]/2; -// hyp = ni*ni + nj*nj; -// -// I = ni * (1+ k * hyp); -// J = nj * (1+ k * hyp); -// -// disi = (I*ratio+viewport[0]/2); -// disj = (J*ratio+viewport[1]/2); -//} -// -// -// -//void distorsion( float k ,float i, float j,double & disi, double &disj) -//{ -// // (i,j) punto nell'immagine corretta (undistorted) -// // (disi,disj) punto nell'immagine distorta -// float hyp; -// int _I,_J; -// float I,J,ni,nj; -// I = i-viewport[0]/2; -// J = j-viewport[1]/2; -// hyp = sqrt(I*I + J*J); -// if((k==0.0) || (hyp <0.001)) -// { -// disi = i; -// disj = j; -// } -// else -// { -// undistorted_to_distorted_sensor_coord (I, J, disi, disj); -// disi += viewport[0]/2; -// disj += viewport[1]/2; -// -// -//// hyp = (viewport[0]*viewport[0] + viewport[1]*viewport[1])/4; -//// ni = SX/2 + SX/2 * cam.k[0] * hyp; -///// nj = SY/2 + SY/2 * cam.k[0] * hyp; -//// float ratio = sqrt(hyp/(ni*ni + nj*nj)); -// float ratio=1; -// -// -// -// //----------- Maple -// // float t0,t1,t2,sol; -// -// //t0 = 1/k*pow((108.0*hyp+12.0*sqrt(3.0)*sqrt((4.0+27.0*hyp*hyp*k)/k))*k*k,0.3333333333333333)/6.0-2.0/pow((108.0*hyp+12.0*sqrt(3.0)*sqrt((4.0+27.0*hyp*hyp*k)/k))*k*k,0.3333333333333333); -// -// -// //t1 = -1/k*pow((108.0*hyp+12.0*sqrt(3.0)*sqrt((4.0+27.0*hyp*hyp*k)/k))*k*k,0.3333333333333333)/12.0+1/pow((108.0*hyp+12.0*sqrt(3.0)*sqrt((4.0+27.0*hyp* -// //hyp*k)/k))*k*k,0.3333333333333333)+sqrt(-1.0)*sqrt(3.0)*(1/k*pow((108.0*hyp+ -// //12.0*sqrt(3.0)*sqrt((4.0+27.0*hyp*hyp*k)/k))*k*k,0.3333333333333333)/6.0+2.0/ -// //pow((108.0*hyp+12.0*sqrt(3.0)*sqrt((4.0+27.0*hyp*hyp*k)/k))*k*k, -// //0.3333333333333333))/2.0; -// -// //t2 = -1/k*pow((108.0*hyp+12.0*sqrt(3.0)*sqrt((4.0+27.0*hyp*hyp*k)/k))*k*k,0.3333333333333333)/12.0+1/pow((108.0*hyp+12.0*sqrt(3.0)*sqrt((4.0+27.0*hyp* -// //hyp*k)/k))*k*k,0.3333333333333333)-sqrt(-1.0)*sqrt(3.0)*(1/k*pow((108.0*hyp+ -// //12.0*sqrt(3.0)*sqrt((4.0+27.0*hyp*hyp*k)/k))*k*k,0.3333333333333333)/6.0+2.0/ -// //pow((108.0*hyp+12.0*sqrt(3.0)*sqrt((4.0+27.0*hyp*hyp*k)/k))*k*k, -// //0.3333333333333333))/2.0; -// -// //sol = (t0>t1)?t0:t1; -// //sol = (sol (i/(double)(si-1),j/(double)(sj-1)); -// { -// double disi,disj; -// distorsion( k[0] ,(i/(double)(si-1))*viewport[0], (j/(double)(sj-1))*viewport[1],disi,disj); -// gridMap[i][j] = Point2 (disi/viewport[0],disj/viewport[1]); -// } -// } -// -// inline Camera() -// { -// k[0]=k[1]=k[2]=k[3]=0.0; -// valid = false; -// ortho = false; -// ResizeGridMap(100,100);// da spostare altrove -// } -// -// inline bool IsValid() -// { -// return valid; -// } -// -// inline bool IsOrtho() const -// { -// return ortho; -// } -// -// inline void SetInvalid() -// { -// valid = false; -// } -// -// inline void SetOrtho(bool isOrtho=true) -// { -// ortho = isOrtho; -// } -// -// // Genera una camera standard -// void Standard() -// { -// valid = true; -// ortho = false; -// view_p = vectorial(0,0,0); -// x_axis = vectorial(1,0,0); -// y_axis = vectorial(0,1,0); -// z_axis = vectorial(0,0,1); -// f = 25.75; -// s = Point2(0.0074,0.0074); -// c = Point2(320,240); -// viewport[0] = 640; -// viewport[1] = 480; -// k[0] = 0; -// k[1] = 0; -// k[2] = 0; -// k[3] = 0; -// } -// -// // Trasla la camera (world coordinate) -// inline void Translate( const vectorial & t ) -// { -// view_p += t; -// } -// -// // Trasla la camera (camera coordinate) -// inline void Move( const vectorial & t ) -// { -// view_p+= x_axis * t[0]+y_axis * t[1] + z_axis * t[2]; -// } -// -// // scala la camera -// inline void Scale(const scalar & sc){ -// view_p *=sc; -// s[0]*=sc; -// s[1]*=sc; -// f*=sc; -// //printf("sc\n"); -// } -// -// -// -// // NOTA funziona solo se l'ultima colonna di m e' 0,0,0,1 -// void Apply( const Matrix44 & m ) -// { -// // Passo 1: calcolo pseudo inversa di m -// S s11,s12,s13; -// S s21,s22,s23; -// S s31,s32,s33; -// S s41,s42,s43; -// -// { -// S t4 = m[0][0]*m[1][1]; -// S t6 = m[0][0]*m[2][1]; -// S t8 = m[1][0]*m[0][1]; -// S t10 = m[1][0]*m[2][1]; -// S t12 = m[2][0]*m[0][1]; -// S t14 = m[2][0]*m[1][1]; -// S t17 = 1/(t4*m[2][2]-t6*m[1][2]-t8*m[2][2]+t10*m[0][2]+t12*m[1][2]-t14*m[0][2]); -// S t27 = m[1][0]*m[2][2]; -// S t28 = m[2][0]*m[1][2]; -// S t31 = m[0][0]*m[2][2]; -// S t32 = m[2][0]*m[0][2]; -// S t35 = m[0][0]*m[1][2]; -// S t36 = m[1][0]*m[0][2]; -// S t49 = m[3][0]*m[1][1]; -// S t51 = m[3][0]*m[2][1]; -// S t59 = m[3][0]*m[0][1]; -// s11 = -(-m[1][1]*m[2][2]+m[2][1]*m[1][2])*t17; -// s12 = -( m[0][1]*m[2][2]-m[2][1]*m[0][2])*t17; -// s13 = ( m[0][1]*m[1][2]-m[1][1]*m[0][2])*t17; -// s21 = (-t27+t28)*t17; -// s22 = -(-t31+t32)*t17; -// s23 = -( t35-t36)*t17; -// s31 = -(-t10+t14)*t17; -// s32 = (-t6 +t12)*t17; -// s33 = ( t4 -t8 )*t17; -// s41 = -(t10*m[3][2]-t27*m[3][1]-t14*m[3][2]+t28*m[3][1]+t49*m[2][2]-t51*m[1][2])*t17; -// s42 = -(-t6*m[3][2]+t31*m[3][1]+t12*m[3][2]-t32*m[3][1]-t59*m[2][2]+t51*m[0][2])*t17; -// s43 = (-t4*m[3][2]+t35*m[3][1]+t8 *m[3][2]-t36*m[3][1]-t59*m[1][2]+t49*m[0][2])*t17; -// 1.0; -// } -// -// //Matrix44 t2 = tt*m; -// //print(t2); -// // Fase 2: Calcolo nuovo punto di vista -// { -// S t1 = view_p[2]*s31; -// S t3 = view_p[2]*s21; -// S t5 = s43*s21; -// S t7 = s43*s31; -// S t9 = view_p[1]*s31; -// S t11 = view_p[1]*s21; -// S t13 = s42*s31; -// S t15 = s42*s21; -// S t17 = view_p[0]*s32; -// S t19 = view_p[0]*s22; -// S t21 = s41*s32; -// S t23 = s41*s22; -// S t25 = -t1*s22+t3*s32-t5*s32+t7*s22+t9*s23-t11*s33-t13*s23+t15*s33-t17*s23+t19*s33+t21*s23-t23*s33; -// S t39 = 1/(s11*s22*s33-s11*s32*s23-s21*s12*s33+s21*s32*s13+s31*s12*s23-s31*s22*s13); -// S t41 = view_p[0]*s12; -// S t45 = s41*s12; -// S t47 = view_p[2]*s11; -// S t50 = s43*s11; -// S t53 = view_p[1]*s11; -// S t56 = s42*s11; -// S t59 = t41*s33-t17*s13+t21*s13-t45*s33+t47*s32-t1*s12-t50*s32+t7*s12-t53*s33+t9*s13+t56*s33-t13*s13; -// S t73 = t15*s13-t56*s23+t19*s13-t41*s23-t23*s13+t45*s23-t11*s13+t53*s23+t3*s12-t47*s22-t5*s12+t50*s22; -// -// view_p[0] = t25*t39; -// view_p[1] = -t59*t39; -// view_p[2] = -t73*t39; -// } -// -// // Fase 3: Calcol nuovo sistema di riferimento -// { -// S A00 = s11*x_axis[0]+s12*x_axis[1]+s13*x_axis[2]; -// S A01 = s11*y_axis[0]+s12*y_axis[1]+s13*y_axis[2]; -// S A02 = s11*z_axis[0]+s12*z_axis[1]+s13*z_axis[2]; -// // S A03 = 0.0; -// S A10 = s21*x_axis[0]+s22*x_axis[1]+s23*x_axis[2]; -// S A11 = s21*y_axis[0]+s22*y_axis[1]+s23*y_axis[2]; -// S A12 = s21*z_axis[0]+s22*z_axis[1]+s23*z_axis[2]; -// // S A13 = 0.0; -// S A20 = s31*x_axis[0]+s32*x_axis[1]+s33*x_axis[2]; -// S A21 = s31*y_axis[0]+s32*y_axis[1]+s33*y_axis[2]; -// S A22 = s31*z_axis[0]+s32*z_axis[1]+s33*z_axis[2]; -// -// x_axis[0] = A00; x_axis[1] = A10; x_axis[2] = A20; -// y_axis[0] = A01; y_axis[1] = A11; y_axis[2] = A21; -// z_axis[0] = A02; z_axis[1] = A12; z_axis[2] = A22; -// // S A1[2][3] = 0.0; -// // S A1[3][0] = 0.0; -// // S A1[3][1] = 0.0; -// // S A1[3][2] = 0.0; -// // S A1[3][3] = 1.0; -// } -// } -// -// /* -// // Applica una trasformazione -// void Apply( const Matrix44 & m ) -// { -// Point3 tx = view_p+x_axis; -// Point3 ty = view_p+y_axis; -// Point3 tz = view_p+z_axis; -// -// view_p = m.Apply(view_p); -// -// x_axis = m.Apply(tx) - view_p; -// y_axis = m.Apply(ty) - view_p; -// z_axis = m.Apply(tz) - view_p; -// } -// -// // Applica una trasformazione ma bene! -// void Stable_Apply( const Matrix44 & m ) -// { -// Point3 tx = view_p+x_axis; -// Point3 ty = view_p+y_axis; -// Point3 tz = view_p+z_axis; -// -// view_p = m.Stable_Apply(view_p); -// -// x_axis = m.Stable_Apply(tx) - view_p; -// y_axis = m.Stable_Apply(ty) - view_p; -// z_axis = m.Stable_Apply(tz) - view_p; -// } -// -// */ -// -// void Project( const vectorial & p, Point2 & q ) const -// { -// vectorial dp = p - view_p; -// S dx = dp*x_axis; -// S dy = dp*y_axis; -// S dz = dp*z_axis; -// -// S tx = dx; -// S ty = -dy; -// S qx,qy; -// -// // nota: per le camere ortogonali viewportM vale 1 -// if(!IsOrtho()) -// { -// tx *= f/dz; -// ty *= f/dz; -// -// undistorted_to_distorted_sensor_coord(tx,ty,qx,qy); -// -// q[0] = qx/s[0]+c[0]; -// q[1] = qy/s[1]+c[1]; -// } -// else -// { -// q[0] = tx/(s[0]*viewportM)+c[0]; -// q[1] = ty/(s[1]*viewportM)+c[1]; -// } -// } -// -//#if 1 -// void Show( FILE * fp ) -// { -// if(valid) -// fprintf(fp, -// "posiz.: %g %g %g\n" -// "x axis: %g %g %g\n" -// "y axis: %g %g %g\n" -// "z axis: %g %g %g\n" -// "focal : %g scale: %g %g center: %g %g\n" -// "viewp.: %d %d distorsion: %g %g %g %g\n" -// ,view_p[0],view_p[1],view_p[2] -// ,x_axis[0],x_axis[1],x_axis[2] -// ,y_axis[0],y_axis[1],y_axis[2] -// ,z_axis[0],z_axis[1],z_axis[2] -// ,f,s[0],s[1],c[0],c[1] -// ,viewport[0],viewport[1],k[0],k[1],k[2],k[3] -// ); -// else -// fprintf(fp,"Invalid\n"); -// } -//#endif -// -// // Legge una camera in descrizione tsai binario -// static void load_tsai_bin (FILE *fp, tsai_camera_parameters *cp, tsai_calibration_constants *cc) -// { -// double sa, -// ca, -// sb, -// cb, -// sg, -// cg; -// -// fread(&(cp->Ncx),sizeof(double),1,fp); -// fread(&(cp->Nfx),sizeof(double),1,fp); -// fread(&(cp->dx),sizeof(double),1,fp); -// fread(&(cp->dy),sizeof(double),1,fp); -// fread(&(cp->dpx),sizeof(double),1,fp); -// fread(&(cp->dpy),sizeof(double),1,fp); -// fread(&(cp->Cx),sizeof(double),1,fp); -// fread(&(cp->Cy),sizeof(double),1,fp); -// fread(&(cp->sx),sizeof(double),1,fp); -// -// fread(&(cc->f),sizeof(double),1,fp); -// fread(&(cc->kappa1),sizeof(double),1,fp); -// fread(&(cc->Tx),sizeof(double),1,fp); -// fread(&(cc->Ty),sizeof(double),1,fp); -// fread(&(cc->Tz),sizeof(double),1,fp); -// fread(&(cc->Rx),sizeof(double),1,fp); -// fread(&(cc->Ry),sizeof(double),1,fp); -// fread(&(cc->Rz),sizeof(double),1,fp); -// -// -// SINCOSd (cc->Rx, sa, ca); -// SINCOSd (cc->Ry, sb, cb); -// SINCOSd (cc->Rz, sg, cg); -// -// cc->r1 = cb * cg; -// cc->r2 = cg * sa * sb - ca * sg; -// cc->r3 = sa * sg + ca * cg * sb; -// cc->r4 = cb * sg; -// cc->r5 = sa * sb * sg + ca * cg; -// cc->r6 = ca * sb * sg - cg * sa; -// cc->r7 = -sb; -// cc->r8 = cb * sa; -// cc->r9 = ca * cb; -// -// fread(&(cc->p1),sizeof(double),1,fp); -// fread(&(cc->p2),sizeof(double),1,fp); -// } -// -// void load_tsai (FILE *fp, tsai_camera_parameters *cp, tsai_calibration_constants *cc) -// { -// double sa, -// ca, -// sb, -// cb, -// sg, -// cg; -// -// fscanf (fp, "%lf", &(cp->Ncx)); -// fscanf (fp, "%lf", &(cp->Nfx)); -// fscanf (fp, "%lf", &(cp->dx)); -// fscanf (fp, "%lf", &(cp->dy)); -// fscanf (fp, "%lf", &(cp->dpx)); -// fscanf (fp, "%lf", &(cp->dpy)); -// fscanf (fp, "%lf", &(cp->Cx)); -// fscanf (fp, "%lf", &(cp->Cy)); -// fscanf (fp, "%lf", &(cp->sx)); -// -// fscanf (fp, "%lf", &(cc->f)); -// fscanf (fp, "%lf", &(cc->kappa1)); -// fscanf (fp, "%lf", &(cc->Tx)); -// fscanf (fp, "%lf", &(cc->Ty)); -// fscanf (fp, "%lf", &(cc->Tz)); -// fscanf (fp, "%lf", &(cc->Rx)); -// fscanf (fp, "%lf", &(cc->Ry)); -// fscanf (fp, "%lf", &(cc->Rz)); -// -// SINCOSd (cc->Rx, sa, ca); -// SINCOSd (cc->Ry, sb, cb); -// SINCOSd (cc->Rz, sg, cg); -// -// cc->r1 = cb * cg; -// cc->r2 = cg * sa * sb - ca * sg; -// cc->r3 = sa * sg + ca * cg * sb; -// cc->r4 = cb * sg; -// cc->r5 = sa * sb * sg + ca * cg; -// cc->r6 = ca * sb * sg - cg * sa; -// cc->r7 = -sb; -// cc->r8 = cb * sa; -// cc->r9 = ca * cb; -// -// fscanf (fp, "%lf", &(cc->p1)); -// fscanf (fp, "%lf", &(cc->p2)); -// } -// -// // Importa una camera dal formato tsai -// void import( const tsai_camera_parameters & cp, -// const tsai_calibration_constants & cc, -// const int image_viewport[2] -// ) -// { -// assert(!IsOrtho()); -// valid = true; -// x_axis[0] = cc.r1; x_axis[1] = cc.r2; x_axis[2] = cc.r3; -// y_axis[0] = cc.r4; y_axis[1] = cc.r5; y_axis[2] = cc.r6; -// z_axis[0] = cc.r7; z_axis[1] = cc.r8; z_axis[2] = cc.r9; -// -// view_p[0] = - (cc.Tx * x_axis[0] + cc.Ty * y_axis[0] + cc.Tz * z_axis[0]); -// view_p[1] = - (cc.Tx * x_axis[1] + cc.Ty * y_axis[1] + cc.Tz * z_axis[1]); -// view_p[2] = - (cc.Tx * x_axis[2] + cc.Ty * y_axis[2] + cc.Tz * z_axis[2]); -// -// s[0] = cp.dpx/cp.sx; -// s[1] = cp.dpy; -// c[0] = cp.Cx; -// c[1] = cp.Cy; -// -// f = cc.f; -// viewport[0] = image_viewport[0]; -// viewport[1] = image_viewport[1]; -// -// k[0] = cc.kappa1; -// k[1] = cc.kappa1; -// k[2] = 0; -// k[2] = 0; -// } -// -// // Esporta una camera in formato tsai -// void export( tsai_camera_parameters & cp, -// tsai_calibration_constants & cc, -// int image_viewport[2] -// ) -// { -// assert(!IsOrtho()); -// cc.r1 = x_axis[0]; cc.r2 = x_axis[1]; cc.r3= x_axis[2] ; -// cc.r4 = y_axis[0]; cc.r5 = y_axis[1]; cc.r6= y_axis[2] ; -// cc.r7 = z_axis[0]; cc.r8 = z_axis[1]; cc.r9= z_axis[2] ; -// -// cc.Tx = - (view_p[0] * x_axis[0] + view_p[1] * x_axis[1] + view_p[2] * x_axis[2]); -// cc.Ty = - (view_p[0] * y_axis[0] + view_p[1] * y_axis[1] + view_p[2] * y_axis[2]); -// cc.Tz = - (view_p[0] * z_axis[0] + view_p[1] * z_axis[1] + view_p[2] * z_axis[2]); -// -// cp.dpx = s[0]; -// cp.dpy = s[1]; -// -// cp.Cx= c[0] ; -// cp.Cy= c[1] ; -// cp.sx= 1; -// -// cc.f= f ; -// -// image_viewport[0] = viewport[0]; -// image_viewport[1] = viewport[1]; -// -// cc.kappa1= k[0] ; -// cc.kappa1= k[1] ; -// } -// -// -// void Save(FILE * out) -// { -// fprintf(out,"VIEW_POINT %f %f %f\n", view_p[0],view_p[1],view_p[2]); -// fprintf(out,"X_AXIS %f %f %f\n", x_axis[0],x_axis[1],x_axis[2]); -// fprintf(out,"Y_AXIS %f %f %f\n", y_axis[0],y_axis[1],y_axis[2]); -// fprintf(out,"Z_AXIS %f %f %f\n", z_axis[0],z_axis[1],z_axis[2]); -// fprintf(out,"FOCUS_LENGHT %f \n", f); -// fprintf(out,"SCALE %f %f \n", s[0], s[1]); -// fprintf(out,"VIEWPORT %d %d \n", viewport[0], viewport[1]); -// fprintf(out,"VIEWPORTM %f\n", viewportM); -// fprintf(out,"RADIAL_DISTORSION %.10g %.10g \n", k[0],k[1]); -// fprintf(out,"CENTER %f %f \n", c[0], c[1]); -// fprintf(out,"IS_VALID %d\n", IsValid()); -// fprintf(out,"END_CAMERA\n"); -// } -// -// void Load(FILE * in) -// { -// char row[255]; -// Standard(); -// while(!feof(in)) -// { -// fscanf(in,"%s",row); -// if(strcmp(row,"VIEW_POINT")==0) -// fscanf(in,"%lg %lg %lg",&view_p[0],&view_p[1],&view_p[2]); -// else -// if(strcmp(row,"X_AXIS")==0) -// fscanf(in,"%lg %lg %lg",& x_axis[0],&x_axis[1],&x_axis[2]); -// else -// if(strcmp(row,"Y_AXIS")==0) -// fscanf(in,"%lg %lg %lg",& y_axis[0],&y_axis[1],&y_axis[2]); -// else -// if(strcmp(row,"Z_AXIS")==0) -// fscanf(in,"%lg %lg %lg",& z_axis[0],&z_axis[1],&z_axis[2]); -// else -// if(strcmp(row,"FOCUS_LENGHT")==0) -// fscanf(in,"%lg",&f); -// else -// if(strcmp(row,"SCALE")==0) -// fscanf(in,"%lg %lg",&s[0],&s[1]); -// else -// if(strcmp(row,"VIEWPORT")==0) -// fscanf(in,"%d %d", &viewport[0],&viewport[1]); -// else -// if(strcmp(row,"VIEWPORTM")==0) -// fscanf(in,"%f", &viewportM); -// else -// if(strcmp(row,"CENTER")==0) -// fscanf(in,"%lg %lg", &c[0],&c[1]); -// else -// if(strcmp(row,"RADIAL_DISTORSION")==0) -// fscanf(in,"%lg %lg", &k[0],&k[1]); -// else -// if(strcmp(row,"IS_VALID")==0) -// fscanf(in,"%d",&valid); -// if(strcmp(row,"END_CAMERA")==0) -// break; -// } -// } -// -//#ifdef __GL_H__ -// -//// Prende in ingresso il bounding box dell'oggetto da inquadrare e setta projection e modelmatrix -//// in modo da matchare il piu' possibile quelle della camera. Ovviamente (?) si ignora le distorsioni radiali. -//// Nota che bb viene utilizzato solo per settare i near e farend plane in maniera sensata. -//void SetGL(const Box3 &bb,scalar subx0=0, scalar subx1=1,scalar suby0=0,scalar suby1=1) -//{ -// scalar _,__; -// SetGL(_,__,bb,subx0, subx1, suby0, suby1); -// -//} -// -//void SetGL(scalar &znear, scalar &zfar,const Box3 &bb,scalar subx0=0, -// scalar subx1=1,scalar suby0=0,scalar suby1=1) -//{ -// glMatrixMode(GL_PROJECTION); -// glLoadIdentity(); -// scalar left,right; -// scalar bottom, top; -// scalar w,h; -// -// // La lunghezza focale e' la distanza del piano immagine dal centro di proiezione. -// // il che mappa direttamente nella chiamata glFrustum che prende in ingresso -// // le coordinate del piano immagine posto a znear. -// -// float imleft =-c[0]*s[0]; -// float imright =(viewport[0]-c[0])*s[0]; -// float imbottom =-c[1]*s[1]; -// float imtop =(viewport[1]-c[1])*s[1]; -// znear = Distance(view_p, bb.Center())-bb.Diag(); -// zfar = Distance(view_p, bb.Center())+bb.Diag(); -// -// w=imright-imleft; -// h=imtop-imbottom; -// -// // Quindi il frustum giusto sarebbe questo, -// // glFrustum(imleft, imright, imbottom, imtop, f, zfar); -// // ma per amor di opengl conviene spostare il near plane fino ad essere vicino all'oggetto da inquadrare. -// // Cambiare f significa amplificare in maniera proporzionale anche i left right ecc. -// -// // 8/5/02 Nota che il near plane va spostato verso l'oggetto solo se quello calcolato sopra e' maggiore di 'f' -// // nota che potrebbe anche succedere che znear <0 (viewpoint vicino ad un oggetto con il bb allungato); -// if(znear c, scalar RadAngle) -//{ -// Point3 rnd(1.0 - 2.0*scalar(rand())/RAND_MAX, -// 1.0 - 2.0*scalar(rand())/RAND_MAX, -// 1.0 - 2.0*scalar(rand())/RAND_MAX); -// rnd.Normalize(); -// Matrix44 m,t0,t1,tr; -// Point3 axis = rnd ^ (view_p-c).Normalize(); -// scalar RadRandAngle=RadAngle*(1.0 - 2.0*scalar(rand())/RAND_MAX); -// t0.Translate(c); -// t1.Translate(-c); -// m.Rotate(ToDeg(RadRandAngle),axis); -// tr=t1*m*t0; -// Apply(tr); -//} -// -// -// -// -//void glTexGen(int offx =0, // angolo basso sinistra della -// int offy=0, // subtexture per la quale si vogliono settare le coordinate -// int sx=1, // Dimensioni in Texel -// int sy=1, -// int Tx=1, // Dimensioni della texture -// int Ty=1) -//{ -// // prendi la rototraslazione che -// // trasforma la coordinata nel -// // sistema di coordinate della camera -// Matrix44d M; -// M[0][0] = x_axis[0]; -// M[0][1] = x_axis[1]; -// M[0][2] = x_axis[2]; -// M[0][3] = -view_p* x_axis ; -// -// M[1][0] = y_axis[0]; -// M[1][1] = y_axis[1]; -// M[1][2] = y_axis[2]; -// M[1][3] = -view_p* y_axis; -// -// M[2][0] = z_axis[0]; -// M[2][1] = z_axis[1]; -// M[2][2] = z_axis[2]; -// M[2][3] = -view_p* z_axis; -// -// M[3][0] = 0.0; -// M[3][1] = 0.0; -// M[3][2] = 0.0; -// M[3][3] = 1.0; -// -// // prendi la matrice di proiezione -// Matrix44d P; -// P.Zero(); -// -// if(!IsOrtho())// prospettica -// { -// -// P[0][0] = sx/(s[0]*viewport[0]*Tx); -// P[0][2] = (1/f)*(offx+0.5*sx)/Tx; -// -// P[1][1] = sy/(s[1]* viewport[1]*Ty); -// P[1][2] = (1/f)*(offy+0.5*sy)/Ty; -// -// P[2][2] = 1; -// P[3][2] = 1/f; -// } -// else // ortogonale -// { -// P[0][0] = sx/(s[0]*viewport[0]*viewportM*Tx); -// P[0][3] = (offx+0.5*sx)/Tx; // l'effetto e' una traslazione di +1/2 -// -// P[1][1] = sy/(s[1]* viewport[1]*viewportM*Ty); -// P[1][3] = (offy+0.5*sy)/Ty; // l'effetto e' una traslazione di +1/2 -// -// P[2][2] = 1; -// P[3][3] = 1; -// } -// // componi -// Matrix44d PM = P*M; -// -// glTexGend(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); -// glTexGend(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); -// glTexGend(GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); -// -// glTexGendv(GL_S,GL_OBJECT_PLANE,&PM[0][0]); -// glTexGendv(GL_T,GL_OBJECT_PLANE,&PM[1][0]); -// glTexGendv(GL_Q,GL_OBJECT_PLANE,&PM[3][0]); -// -// glEnable(GL_TEXTURE_GEN_S); -// glEnable(GL_TEXTURE_GEN_T); -// glDisable(GL_TEXTURE_GEN_R); -// glEnable(GL_TEXTURE_GEN_Q); -//} -// -//// versione per le texture rettangolare NV_TEXTURE_RECTANGLE -//// la differenza da glTexGen e' che il mapping e' in [0..sx]X[0..sy] -//void glTexGen_NV(int sx, // Texture Size -// int sy) -//{ -// // prendi la rototraslazione che -// // trasforma la coordinata nel -// // sistema di coordinate della camera -// Matrix44d M; -// M[0][0] = x_axis[0]; -// M[0][1] = x_axis[1]; -// M[0][2] = x_axis[2]; -// M[0][3] = -view_p* x_axis ; -// -// M[1][0] = y_axis[0]; -// M[1][1] = y_axis[1]; -// M[1][2] = y_axis[2]; -// M[1][3] = -view_p* y_axis; -// -// M[2][0] = z_axis[0]; -// M[2][1] = z_axis[1]; -// M[2][2] = z_axis[2]; -// M[2][3] = -view_p* z_axis; -// -// M[3][0] = 0.0; -// M[3][1] = 0.0; -// M[3][2] = 0.0; -// M[3][3] = 1.0; -// -// // prendi la matrice di proiezione -// Matrix44d P; -// P.Zero(); -// -// if(!IsOrtho())// prospettica -// { -// -// P[0][0] = sx/(s[0]*viewport[0]); -// P[0][2] = sx*(1/f)*( 0.5); -// -// P[1][1] = sy/(s[1]* viewport[1] ); -// P[1][2] = sy*(1/f)*( 0.5); -// -// P[2][2] = 1; -// P[3][2] = 1/f; -// } -// else // ortogonale -// { -// P[0][0] = sx/(s[0]*viewport[0]*viewportM); -// P[0][3] = sx* 0.5 ; // l'effetto e' una traslazione di +1/2 -// -// P[1][1] = sy/(s[1]* viewport[1]*viewportM); -// P[1][3] = sy* 0.5 ; // l'effetto e' una traslazione di +1/2 -// -// P[2][2] = 1; -// P[3][3] = 1; -// } -// // componi -// Matrix44d PM = P*M; -// -// glTexGend(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); -// glTexGend(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); -// glTexGend(GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); -// -// glTexGendv(GL_S,GL_OBJECT_PLANE,&PM[0][0]); -// glTexGendv(GL_T,GL_OBJECT_PLANE,&PM[1][0]); -// glTexGendv(GL_Q,GL_OBJECT_PLANE,&PM[3][0]); -// -// glEnable(GL_TEXTURE_GEN_S); -// glEnable(GL_TEXTURE_GEN_T); -// glDisable(GL_TEXTURE_GEN_R); -// glEnable(GL_TEXTURE_GEN_Q); -//// glDisable(GL_TEXTURE_GEN_Q); -// -//} -//#endif // __GL_H__ -// -//}; -//} // End namespace vcg diff --git a/vcg/math/shot.h b/vcg/math/shot.h index c3e5a1e5..a6031253 100644 --- a/vcg/math/shot.h +++ b/vcg/math/shot.h @@ -23,6 +23,9 @@ /**************************************************************************** History $Log: not supported by cvs2svn $ +Revision 1.19 2006/01/22 17:01:40 cignoni +Corrected intialization of flag, must be zero. + Revision 1.18 2005/12/12 16:53:43 callieri corrected UnProject, it's necessary also a ZDepth value to perform inverse projection @@ -79,9 +82,6 @@ creation #ifndef __VCGLIB_SHOT #define __VCGLIB_SHOT -// #include -// #include -// #include #include #include #include @@ -95,160 +95,179 @@ public: typedef Camera CameraType; typedef S ScalarType; -protected: + Camera Intrinsics; // the camera that made the shot + Similarity > Extrinsics; // the position and orientation of the camera - enum { - NOTVALID_BIT = 0x1, - CREATED_EMPTY= 0x2 - }; - char flags; - Camera & camera; // the camera that shot - vcg::Similarity > similarity; // the position from where it did it -public: + Shot(Camera c) + { + Intrinsics = c; + Extrinsics.SetIdentity(); + } - Shot( Camera & c):camera(c){similarity.SetIdentity();flags=0;} - Shot():camera(*new vcg::Camera()){similarity.SetIdentity();flags|=CREATED_EMPTY;} - ~Shot(){if(flags&CREATED_EMPTY) delete &camera;} + Shot() + { + Extrinsics.SetIdentity(); + } - bool IsValid(){ return (flags& NOTVALID_BIT)==0;} - void SetValid(bool v){ if(!v) flags|=NOTVALID_BIT; else flags&=~NOTVALID_BIT;} - Camera & Camera(){return camera;}; - - /// access to similarity - vcg::Similarity > & Similarity(){return similarity;} - - /// take the i-th axis of the coordinate system of the camera + /// GET the i-th axis of the coordinate system of the camera vcg::Point3 Axis(const int & i)const; - /// take the viewpoint - const vcg::Point3 ViewPoint()const; - - /// set the viewpoint + /// GET the viewpoint + const vcg::Point3 GetViewPoint()const; + /// SET the viewpoint void SetViewPoint(const vcg::Point3 & viewpoint); - /// look at + /// look at (dir+up) void LookAt(const vcg::Point3 & z_dir,const vcg::Point3 & up); - /// look at (same as opengl) - void LookAt(const S & eye_x,const S & eye_y,const S & eye_z,const S & at_x,const S & at_y,const S & at_z, - const S & up_x,const S & up_y,const S & up_z); + /// look at (opengl-like) + void LookAt(const S & eye_x,const S & eye_y,const S & eye_z, + const S & at_x,const S & at_y,const S & at_z, + const S & up_x,const S & up_y,const S & up_z); /// look towards void LookTowards(const vcg::Point3 & z_dir,const vcg::Point3 & up); - /// convert a 3d point in camera coordinates - vcg::Point3 ConvertToCameraCoordinates(const vcg::Point3 & p) const; + /// convert a 3d point from world to camera coordinates + vcg::Point3 ConvertWorldToCameraCoordinates(const vcg::Point3 & p) const; - /// convert a 3d point in camera coordinates - vcg::Point3 ConvertToWorldCoordinates(const vcg::Point3 & p) const; + /// convert a 3d point from camera to world coordinates + vcg::Point3 ConvertCameraToWorldCoordinates(const vcg::Point3 & p) const; - /// project onto the camera plane + /// project a 3d point from world coordinates to 2d camera viewport (pixel) vcg::Point2 Project(const vcg::Point3 & p) const; - /// inverse projection from camera plane + Zdepth to original 3D + /// inverse projection from 2d camera viewport (pixel) + Zdepth to 3d world coordinates vcg::Point3 UnProject(const vcg::Point2 & p, const S & d) const; - /// take the distance from the point p and the plane parallel to the camera plane and passing through the view - /// point. The would be z depth + /// returns distance of point p from camera plane (z depth), used for unprojection S Depth(const vcg::Point3 & p)const; - /// project a 3d point from 3D WORLD to 2D VIEWPORT - vcg::Point2 ProjectWorldtoViewport(const vcg::Point3 & p) const; - - }; // end class definition + + +//--- +/// GET the viewpoint template -const vcg::Point3 Shot::ViewPoint() const { - //Matrix44 m = similarity.Matrix(); - //return Point3(m[0][3],m[1][3],m[2][3]); - return -similarity.tra; +const vcg::Point3 Shot::GetViewPoint() const +{ + return -Extrinsics.tra; +} +/// SET the viewpoint +template +void Shot::SetViewPoint(const vcg::Point3 & viewpoint) +{ + Extrinsics.tra = -viewpoint; +} +//--- + +/// GET the i-th axis of the coordinate system of the camera +template +vcg::Point3 Shot::Axis(const int & i) const +{ + vcg::Matrix44 m; + Extrinsics.rot.ToMatrix(m); + vcg::Point3 aa = m.GetRow3(i); + return aa; } +/// look at (dir+up) template - vcg::Point3 Shot::Axis(const int & i) const { - vcg::Matrix44 m; - similarity.rot.ToMatrix(m); - vcg::Point3 aa = m.GetRow3(i); - return aa; - } - -template -void Shot::SetViewPoint(const vcg::Point3 & viewpoint){ - similarity.tra = -viewpoint; -} - -template -void Shot::LookAt(const vcg::Point3 & z_dir,const vcg::Point3 & up){ +void Shot::LookAt(const vcg::Point3 & z_dir,const vcg::Point3 & up) +{ LookTowards(z_dir-ViewPoint(),up); } +/// look at (opengl-like) template -void Shot::LookAt(const S & eye_x,const S & eye_y,const S & eye_z,const S & at_x,const S & at_y,const S & at_z, - const S & up_x,const S & up_y,const S & up_z){ +void Shot::LookAt(const S & eye_x, const S & eye_y, const S & eye_z, + const S & at_x, const S & at_y, const S & at_z, + const S & up_x,const S & up_y,const S & up_z) +{ SetViewPoint(Point3(eye_x,eye_y,eye_z)); LookAt(Point3(at_x,at_y,at_z),Point3(up_x,up_y,up_z)); } - +/// look towards template -void Shot::LookTowards(const vcg::Point3 & z_dir,const vcg::Point3 & up){ - vcg::Point3 x_dir = up ^-z_dir ; - vcg::Point3 y_dir = -z_dir ^x_dir ; +void Shot::LookTowards(const vcg::Point3 & z_dir,const vcg::Point3 & up) +{ + vcg::Point3 x_dir = up ^-z_dir; + vcg::Point3 y_dir = -z_dir ^x_dir; Matrix44 m; m.SetIdentity(); - *(vcg::Point3 *)&m[0][0] = x_dir/x_dir.Norm(); - *(vcg::Point3 *)&m[1][0] = y_dir/y_dir.Norm(); + *(vcg::Point3 *)&m[0][0] = x_dir/x_dir.Norm(); + *(vcg::Point3 *)&m[1][0] = y_dir/y_dir.Norm(); *(vcg::Point3 *)&m[2][0] = -z_dir/z_dir.Norm(); - similarity.rot.FromMatrix(m); + Extrinsics.rot.FromMatrix(m); } +//--- Space transformation methods + +/// convert a 3d point from world to camera coordinates template -vcg::Point3 Shot::ConvertToCameraCoordinates(const vcg::Point3 & p) const{ +vcg::Point3 Shot::ConvertWorldToCameraCoordinates(const vcg::Point3 & p) const +{ Matrix44 rotM; - similarity.rot.ToMatrix(rotM); - vcg::Point3 cp = rotM * (p+similarity.tra); - // note: the camera reference system is right handed - cp[2]=-cp[2]; + Extrinsics.rot.ToMatrix(rotM); + vcg::Point3 cp = rotM * (p + Extrinsics.tra); + cp[2]=-cp[2]; // note: camera reference system is right handed return cp; } + +/// convert a 3d point from camera to world coordinates template -vcg::Point3 Shot::ConvertToWorldCoordinates(const vcg::Point3 & p) const{ +vcg::Point3 Shot::ConvertCameraToWorldCoordinates(const vcg::Point3 & p) const +{ Matrix44 rotM; vcg::Point3 cp = p; - // note: the World reference system is left handed - cp[2]=-cp[2]; - similarity.rot.ToMatrix(rotM); - cp = Inverse(rotM) * cp-similarity.tra; + cp[2]=-cp[2]; // note: World reference system is left handed + Extrinsics.rot.ToMatrix(rotM); + cp = Inverse(rotM) * cp-Extrinsics.tra; return cp; } -template -vcg::Point2 Shot::Project(const vcg::Point3 & p) const{ - return camera.Project(ConvertToCameraCoordinates(p)); - } -template -vcg::Point3 Shot::UnProject(const vcg::Point2 & p, const S & d) const{ - Point2 tp = camera.ViewportToLocal(p); - vcg::Point3 q = camera.UnProject(tp, d); - return ConvertToWorldCoordinates(q); -} -template -S Shot::Depth(const vcg::Point3 & p)const { - return ConvertToCameraCoordinates(p).Z(); -} +/// project a 3d point from world coordinates to 2d camera viewport (pixel) template -vcg::Point2 Shot::ProjectWorldtoViewport(const vcg::Point3 & p)const +vcg::Point2 Shot::Project(const vcg::Point3 & p) const { - return camera.LocalToViewport( camera.Project( ConvertToCameraCoordinates(p) ) ); + Point3 cp = ConvertWorldToCameraCoordinates(p); + Point2 pp = Intrinsics.Project(cp); + Point2 vp = Intrinsics.LocalToViewportPx(pp); + return vp; } +/// inverse projection from 2d camera viewport (pixel) + Zdepth to 3d world coordinates +template +vcg::Point3 Shot::UnProject(const vcg::Point2 & p, const S & d) const +{ + Point2 lp = Intrinsics.ViewportPxToLocal(p); + Point3 cp = Intrinsics.UnProject(lp,d); + Point3 wp = ConvertCameraToWorldCoordinates(cp); + return wp; +} + +/// returns distance of point p from camera plane (z depth), used for unprojection +template +S Shot::Depth(const vcg::Point3 & p)const +{ + return ConvertWorldToCameraCoordinates(p).Z(); +} + + + +//-------------------------------- + + +//--- utility definitions class Shotf: public Shot{}; class Shotd: public Shot{}; +//----------------------- } // end name space diff --git a/wrap/gl/camera.h b/wrap/gl/camera.h index e0ca7ded..726a6fae 100644 --- a/wrap/gl/camera.h +++ b/wrap/gl/camera.h @@ -23,6 +23,9 @@ /**************************************************************************** History $Log: not supported by cvs2svn $ +Revision 1.11 2006/01/10 12:22:34 spinelli +add namespace vcg:: + Revision 1.10 2005/10/24 14:42:57 spinelli add namespace vcg:: to GetFrustum(...) @@ -76,8 +79,11 @@ struct GlCamera{ typedef typename CameraType::ScalarType ScalarType; typedef typename CameraType::ScalarType S; + +/// returns the OpenGL 4x4 PROJECTION matrix that describes the camera (intrinsics) static vcg::Matrix44 -MatrixGL(vcg::Camera & cam, vcg::Matrix44 &m){ +MatrixGL(vcg::Camera & cam, vcg::Matrix44 &m) +{ glPushAttrib(GL_TRANSFORM_BIT); glMatrixMode(GL_PROJECTION); glPushMatrix(); @@ -89,7 +95,8 @@ MatrixGL(vcg::Camera & cam, vcg::Matrix44 &m){ return m; } -static void CavalieriProj(float x1, float x2, float y1, float y2, float z1, float z2) +/// set the OpenGL PROJECTION matrix for the Cavalieri projection +static void SetGLCavalieriProj(float x1, float x2, float y1, float y2, float z1, float z2) { GLfloat cavalieri[16]; @@ -103,10 +110,10 @@ static void CavalieriProj(float x1, float x2, float y1, float y2, float z1, floa cavalieri[11] = 0; cavalieri[15] = 1.0f; glLoadMatrixf(cavalieri); - } -static void IsometricProj(float x1, float x2, float y1, float y2, float z1, float z2) +/// set the OpenGL PROJECTION matrix for the Isometric projection +static void SetGLIsometricProj(float x1, float x2, float y1, float y2, float z1, float z2) { GLfloat isometric[16]; @@ -122,34 +129,32 @@ static void IsometricProj(float x1, float x2, float y1, float y2, float z1, floa glLoadMatrixf(isometric); } -static void GetFrustum(vcg::Camera & camera, S & sx,S & dx,S & bt,S & tp,S & f ,S & fr) +/// get OpenGL-like frustum from a vcg camera (intrinsics) +static void GetFrustum(vcg::Camera & intrinsics, S & sx,S & dx,S & bt,S & tp,S & f) { - camera.GetFrustum(sx,dx,bt,tp,f,fr); + intrinsics.GetFrustum(sx,dx,bt,tp,f); } - -static void TransformGL(vcg::Camera & camera, S farDist = -1 ) { +/// set the OpenGL PROJECTION matrix to match the camera (intrinsics). requires near and far plane +static void TransformGL(vcg::Camera & camera, S nearDist, S farDist ) +{ S sx,dx,bt,tp,nr,fr; - GetFrustum(camera,sx,dx,bt,tp,nr,fr); + camera.GetFrustum(sx,dx,bt,tp,nr); + assert(glGetError()==0); - switch(camera.cameraType) { - case vcg::PERSPECTIVE: glFrustum(sx,dx,bt,tp,nr,(farDist == -1)?fr:farDist); break; - case vcg::ORTHO: glOrtho(sx*camera.viewportM,dx*camera.viewportM,bt*camera.viewportM,tp*camera.viewportM,nr,(farDist == -1)?fr:farDist); break; - case vcg::ISOMETRIC: IsometricProj(sx,dx,bt,tp,nr,(farDist == -1)?fr:farDist); break; - case vcg::CAVALIERI: CavalieriProj(sx,dx,bt,tp,nr,(farDist == -1)?fr:farDist); break; - } -/* if(!camera.IsOrtho()) + switch(camera.cameraType) { - //glFrustum(sx,dx,bt,tp,nr,(farDist == -1)?fr:farDist); - IsometricProj(sx,dx,bt,tp,nr,(farDist == -1)?fr:farDist); + case vcg::PERSPECTIVE: glFrustum(sx,dx,bt,tp,nearDist,farDist); break; + case vcg::ORTHO: glOrtho(sx,dx,bt,tp,nearDist,farDist); break; + case vcg::ISOMETRIC: SetGLIsometricProj(sx,dx,bt,tp,nearDist,farDist); break; + case vcg::CAVALIERI: SetGLCavalieriProj(sx,dx,bt,tp,nearDist,farDist); break; } - else glOrtho(sx*camera.viewportM,dx*camera.viewportM,bt*camera.viewportM,tp*camera.viewportM,nr,(farDist == -1)?fr:farDist); -*/ - + assert(glGetError()==0); }; + static void GetViewSize(vcg::Camera & camera, S &width, S &height) { S sx,dx,bt,tp,nr,fr; GetFrustum(camera,sx,dx,bt,tp,nr,fr); @@ -157,6 +162,7 @@ static void GetViewSize(vcg::Camera & camera, S &width, S &height) { height = tp-bt; //top - bottom = height }; + static void SetSubView(vcg::Camera & camera,vcg::Point2 p0,vcg::Point2 p1){ //typedef typename CameraType::ScalarType S; S sx,dx,bt,tp,nr,fr; @@ -170,11 +176,12 @@ static void SetSubView(vcg::Camera & camera,vcg::Point2 p0,vcg::Point2 - switch(camera.cameraType) { - case vcg::PERSPECTIVE: glFrustum( width* p0[0]+ sx, width* p1[0]+ sx, height* p0[1]+ bt, height* p1[1]+ bt,nr,fr); break; - case vcg::ORTHO: glOrtho((width* p0[0]+sx)*camera.viewportM, (width* p1[0]+sx)*camera.viewportM, (height* p0[1]+ bt)*camera.viewportM, (height* p1[1]+bt)*camera.viewportM,nr,fr); break; - case vcg::ISOMETRIC: IsometricProj(dx-width* p1[0], dx-width* p0[0], tp-height* p1[1], tp-height* p0[1],nr,fr); break; - case vcg::CAVALIERI: CavalieriProj(dx-width* p1[0], dx-width* p0[0], tp-height* p1[1], tp-height* p0[1],nr,fr); break; + switch(camera.cameraType) + { + case vcg::PERSPECTIVE: glFrustum( width* p0[0]+ sx, width* p1[0]+ sx, height* p0[1]+ bt, height* p1[1]+ bt,nr,fr); break; + case vcg::ORTHO: glOrtho((width* p0[0]+sx)*camera.viewportM, (width* p1[0]+sx)*camera.viewportM, (height* p0[1]+ bt)*camera.viewportM, (height* p1[1]+bt)*camera.viewportM,nr,fr); break; + case vcg::ISOMETRIC: IsometricProj(dx-width* p1[0], dx-width* p0[0], tp-height* p1[1], tp-height* p0[1],nr,fr); break; + case vcg::CAVALIERI: CavalieriProj(dx-width* p1[0], dx-width* p0[0], tp-height* p1[1], tp-height* p0[1],nr,fr); break; } diff --git a/wrap/gl/shot.h b/wrap/gl/shot.h index 2a2b22e7..ee867517 100644 --- a/wrap/gl/shot.h +++ b/wrap/gl/shot.h @@ -23,6 +23,9 @@ /**************************************************************************** History $Log: not supported by cvs2svn $ +Revision 1.8 2006/01/11 16:06:25 matteodelle +*** empty log message *** + Revision 1.8 2005/01/11 17:06:30 dellepiane FromTrackball() coorected (similarity->Similarity() @@ -79,24 +82,30 @@ struct GlShot { typedef typename ShotType::ScalarType ScalarType; typedef typename GlCamera GlCameraType; -static void MatrixGL(ShotType & shot,vcg::Matrix44 & m) { - m = shot.Similarity().Matrix(); +/// returns the OpenGL 4x4 MODELVIEW matrix that describes the shot position and orientation (extrinsics) +static void MatrixGL(ShotType & shot,vcg::Matrix44 & m) +{ + m = shot.Extrinsics.Matrix(); } -static void TransformGL(vcg::Shot & shot){ +/// set the OpenGL MODELVIEW matrix to match the shot (extrinsics) +static void TransformGL(vcg::Shot & shot) +{ vcg::Matrix44 m; MatrixGL(shot,m); glMultMatrix(m); } -static void SetView(vcg::Shot & shot){ +/// set the OpenGL PROJECTION and MODELVIEW matrix to match camera+shot. requires near and far plane +static void SetView(vcg::Shot & shot, ScalarType nearDist, ScalarType farDist) +{ assert(glGetError() == 0); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); assert(glGetError() == 0); - GlCameraType::TransformGL(shot.Camera()); // apply camera/modelview transformation + GlCameraType::TransformGL(shot.Intrinsics, nearDist, farDist); // apply camera/projection transformation assert(glGetError() == 0); glMatrixMode(GL_MODELVIEW); @@ -106,6 +115,18 @@ static void SetView(vcg::Shot & shot){ GlShot::TransformGL(shot); // apply similarity/modelview transformation assert(glGetError() == 0); } + +/// restore the previous OpenGL modelview and projection state. to be called AFTER a SetView +static void UnsetView() +{ + glPushAttrib(GL_TRANSFORM_BIT); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glPopAttrib(); +} + static void SetSubView(vcg::Shot & shot, vcg::Point2 p1, vcg::Point2 p2) @@ -123,15 +144,7 @@ static void SetSubView(vcg::Shot & shot, assert(glGetError() == 0); } -static void UnsetView() -{ - glPushAttrib(GL_TRANSFORM_BIT); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glPopAttrib(); -} + /********************************** DEFINE SHOT FROM TRACKBALL diff --git a/wrap/io_trimesh/export_ply.h b/wrap/io_trimesh/export_ply.h index 48354816..44f20664 100644 --- a/wrap/io_trimesh/export_ply.h +++ b/wrap/io_trimesh/export_ply.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.17 2006/11/30 22:49:32 cignoni +Added save with (unused) callback + Revision 1.16 2006/10/14 00:39:22 cignoni Added a comment on an assert @@ -178,7 +181,7 @@ static int Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo &p if(m.textures.size()>1 && (m.HasPerWedgeTexture() || m.HasPerVertexTexture())) multit = true; } - if( (pi.mask & Mask::IOM_CAMERA) && m.shot.IsValid()) + if((pi.mask & Mask::IOM_CAMERA)) { fprintf(fpout, "element camera 1\n" @@ -300,65 +303,65 @@ static int Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo &p fprintf(fpout, "end_header\n" ); // Salvataggio camera - if( (pi.mask & Mask::IOM_CAMERA) && m.shot.IsValid() ) + if((pi.mask & Mask::IOM_CAMERA)) { if(binary) { float t[17]; - t[ 0] = (float) -m.shot.Similarity().tra[0]; - t[ 1] = (float)-m.shot.Similarity().tra[1]; - t[ 2] = (float)-m.shot.Similarity().tra[2]; - t[ 3] = (float)m.shot.Similarity().rot[0][0]; - t[ 4] = (float)m.shot.Similarity().rot[0][1]; - t[ 5] = (float)m.shot.Similarity().rot[0][2]; - t[ 6] = (float)m.shot.Similarity().rot[1][0]; - t[ 7] = (float)m.shot.Similarity().rot[1][1]; - t[ 8] = (float)m.shot.Similarity().rot[1][2]; - t[ 9] = (float)m.shot.Similarity().rot[2][0]; - t[10] = (float)m.shot.Similarity().rot[2][1]; - t[11] = (float)m.shot.Similarity().rot[2][2]; - t[12] = (float)m.shot.Camera().f; - t[13] = (float)m.shot.Camera().s[0]; - t[14] = (float) m.shot.Camera().s[1]; - t[15] = (float)m.shot.Camera().c[0]; - t[16] = (float)m.shot.Camera().c[1]; + t[ 0] = (float)-m.shot.Extrinsics.tra[0]; + t[ 1] = (float)-m.shot.Extrinsics.tra[1]; + t[ 2] = (float)-m.shot.Extrinsics.tra[2]; + t[ 3] = (float)m.shot.Extrinsics.rot[0][0]; + t[ 4] = (float)m.shot.Extrinsics.rot[0][1]; + t[ 5] = (float)m.shot.Extrinsics.rot[0][2]; + t[ 6] = (float)m.shot.Extrinsics.rot[1][0]; + t[ 7] = (float)m.shot.Extrinsics.rot[1][1]; + t[ 8] = (float)m.shot.Extrinsics.rot[1][2]; + t[ 9] = (float)m.shot.Extrinsics.rot[2][0]; + t[10] = (float)m.shot.Extrinsics.rot[2][1]; + t[11] = (float)m.shot.Extrinsics.rot[2][2]; + t[12] = (float)m.shot.Intrinsics.FocalMm; + t[13] = (float)m.shot.Intrinsics.PixelSizeMm[0]; + t[14] = (float)m.shot.Intrinsics.PixelSizeMm[1]; + t[15] = (float)m.shot.Intrinsics.CenterPx[0]; + t[16] = (float)m.shot.Intrinsics.CenterPx[1]; fwrite(t,sizeof(float),17,fpout); - fwrite( &m.shot.Camera().viewport[0],sizeof(int),2,fpout ); + fwrite( &m.shot.Intrinsics.ViewportPx[0],sizeof(int),2,fpout ); - t[ 0] = (float)m.shot.Camera().k[0]; - t[ 1] = (float)m.shot.Camera().k[1]; - t[ 2] = (float)m.shot.Camera().k[2]; - t[ 3] = (float)m.shot.Camera().k[3]; + t[ 0] = (float)m.shot.Intrinsics.k[0]; + t[ 1] = (float)m.shot.Intrinsics.k[1]; + t[ 2] = (float)m.shot.Intrinsics.k[2]; + t[ 3] = (float)m.shot.Intrinsics.k[3]; fwrite(t,sizeof(float),4,fpout); } else { fprintf(fpout,"%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %d %d %g %g %g %g\n" - ,-m.shot.Similarity().tra[0] - ,-m.shot.Similarity().tra[1] - ,-m.shot.Similarity().tra[2] - ,m.shot.Similarity().rot[0][0] - ,m.shot.Similarity().rot[0][1] - ,m.shot.Similarity().rot[0][2] - ,m.shot.Similarity().rot[1][0] - ,m.shot.Similarity().rot[1][1] - ,m.shot.Similarity().rot[1][2] - ,m.shot.Similarity().rot[2][0] - ,m.shot.Similarity().rot[2][1] - ,m.shot.Similarity().rot[2][2] - ,m.shot.Camera().f - ,m.shot.Camera().s[0] - ,m.shot.Camera().s[1] - ,m.shot.Camera().c[0] - ,m.shot.Camera().c[1] - ,m.shot.Camera().viewport[0] - ,m.shot.Camera().viewport[1] - ,m.shot.Camera().k[0] - ,m.shot.Camera().k[1] - ,m.shot.Camera().k[2] - ,m.shot.Camera().k[3] + ,-m.shot.Extrinsics.tra[0] + ,-m.shot.Extrinsics.tra[1] + ,-m.shot.Extrinsics.tra[2] + ,m.shot.Extrinsics.rot[0][0] + ,m.shot.Extrinsics.rot[0][1] + ,m.shot.Extrinsics.rot[0][2] + ,m.shot.Extrinsics.rot[1][0] + ,m.shot.Extrinsics.rot[1][1] + ,m.shot.Extrinsics.rot[1][2] + ,m.shot.Extrinsics.rot[2][0] + ,m.shot.Extrinsics.rot[2][1] + ,m.shot.Extrinsics.rot[2][2] + ,m.shot.Intrinsics.FocalMm + ,m.shot.Intrinsics.PixelSizeMm[0] + ,m.shot.Intrinsics.PixelSizeMm[1] + ,m.shot.Intrinsics.CenterPx[0] + ,m.shot.Intrinsics.CenterPx[1] + ,m.shot.Intrinsics.ViewportPx[0] + ,m.shot.Intrinsics.ViewportPx[1] + ,m.shot.Intrinsics.k[0] + ,m.shot.Intrinsics.k[1] + ,m.shot.Intrinsics.k[2] + ,m.shot.Intrinsics.k[3] ); } } diff --git a/wrap/io_trimesh/import_ply.h b/wrap/io_trimesh/import_ply.h index 0b5fa65a..59abc235 100644 --- a/wrap/io_trimesh/import_ply.h +++ b/wrap/io_trimesh/import_ply.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.30 2006/11/27 10:36:13 cignoni +Removed flags initialization. no more necessary + Revision 1.29 2006/10/14 00:18:42 cignoni Allowed the correct loading of meshes with 0 faces @@ -562,37 +565,37 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi ) //camera.valid = true; // extrinsic - m.shot.Similarity().SetIdentity(); + m.shot.Extrinsics.SetIdentity(); // view point - m.shot.Similarity().tra[0] = -ca.view_px; - m.shot.Similarity().tra[1] = -ca.view_py; - m.shot.Similarity().tra[2] = -ca.view_pz; + m.shot.Extrinsics.tra[0] = -ca.view_px; + m.shot.Extrinsics.tra[1] = -ca.view_py; + m.shot.Extrinsics.tra[2] = -ca.view_pz; // axis (i.e. rotation). - m.shot.Similarity().rot[0][0] = ca.x_axisx; - m.shot.Similarity().rot[0][1] = ca.x_axisy; - m.shot.Similarity().rot[0][2] = ca.x_axisz; + m.shot.Extrinsics.rot[0][0] = ca.x_axisx; + m.shot.Extrinsics.rot[0][1] = ca.x_axisy; + m.shot.Extrinsics.rot[0][2] = ca.x_axisz; - m.shot.Similarity().rot[1][0] = ca.y_axisx; - m.shot.Similarity().rot[1][1] = ca.y_axisy; - m.shot.Similarity().rot[1][2] = ca.y_axisz; + m.shot.Extrinsics.rot[1][0] = ca.y_axisx; + m.shot.Extrinsics.rot[1][1] = ca.y_axisy; + m.shot.Extrinsics.rot[1][2] = ca.y_axisz; - m.shot.Similarity().rot[2][0] = ca.z_axisx; - m.shot.Similarity().rot[2][1] = ca.z_axisy; - m.shot.Similarity().rot[2][2] = ca.z_axisz; + m.shot.Extrinsics.rot[2][0] = ca.z_axisx; + m.shot.Extrinsics.rot[2][1] = ca.z_axisy; + m.shot.Extrinsics.rot[2][2] = ca.z_axisz; //intrinsic - m.shot.Camera().f = ca.focal; - m.shot.Camera().s[0] = ca.scalex; - m.shot.Camera().s[1] = ca.scaley; - m.shot.Camera().c[0] = ca.centerx; - m.shot.Camera().c[1] = ca.centery; - m.shot.Camera().viewport[0] = ca.viewportx; - m.shot.Camera().viewport[1] = ca.viewporty; - m.shot.Camera().k[0] = ca.k1; - m.shot.Camera().k[1] = ca.k2; - m.shot.Camera().k[2] = ca.k3; - m.shot.Camera().k[3] = ca.k4; + m.shot.Intrinsics.FocalMm = ca.focal; + m.shot.Intrinsics.PixelSizeMm[0] = ca.scalex; + m.shot.Intrinsics.PixelSizeMm[1] = ca.scaley; + m.shot.Intrinsics.CenterPx[0] = ca.centerx; + m.shot.Intrinsics.CenterPx[1] = ca.centery; + m.shot.Intrinsics.ViewportPx[0] = ca.viewportx; + m.shot.Intrinsics.ViewportPx[1] = ca.viewporty; + m.shot.Intrinsics.k[0] = ca.k1; + m.shot.Intrinsics.k[1] = ca.k2; + m.shot.Intrinsics.k[2] = ca.k3; + m.shot.Intrinsics.k[3] = ca.k4; } }