camera+shot revamp: changed field names to something with more sense, cleaning of various functions, correction of minor bugs/incongruences, removal of the infamous reference in shot.
This commit is contained in:
parent
e0dc9fc1c7
commit
a344d59446
1207
vcg/math/camera.h
1207
vcg/math/camera.h
File diff suppressed because it is too large
Load Diff
211
vcg/math/shot.h
211
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 <vector>
|
||||
// #include <vcg/Matrix44.h>
|
||||
// #include <vcg/Box3.h>
|
||||
#include <vcg/space/point2.h>
|
||||
#include <vcg/space/point3.h>
|
||||
#include <vcg/math/similarity.h>
|
||||
|
@ -95,160 +95,179 @@ public:
|
|||
typedef Camera<S> CameraType;
|
||||
typedef S ScalarType;
|
||||
|
||||
protected:
|
||||
Camera<S> Intrinsics; // the camera that made the shot
|
||||
Similarity<S,vcg::Matrix44<S> > Extrinsics; // the position and orientation of the camera
|
||||
|
||||
enum {
|
||||
NOTVALID_BIT = 0x1,
|
||||
CREATED_EMPTY= 0x2
|
||||
};
|
||||
char flags;
|
||||
Camera<S> & camera; // the camera that shot
|
||||
vcg::Similarity<S,vcg::Matrix44<S> > similarity; // the position from where it did it
|
||||
|
||||
public:
|
||||
Shot(Camera<S> c)
|
||||
{
|
||||
Intrinsics = c;
|
||||
Extrinsics.SetIdentity();
|
||||
}
|
||||
|
||||
Shot( Camera<S> & c):camera(c){similarity.SetIdentity();flags=0;}
|
||||
Shot():camera(*new vcg::Camera<S>()){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<S> & Camera(){return camera;};
|
||||
|
||||
/// access to similarity
|
||||
vcg::Similarity<S,vcg::Matrix44<S> > & 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<S> Axis(const int & i)const;
|
||||
|
||||
/// take the viewpoint
|
||||
const vcg::Point3<S> ViewPoint()const;
|
||||
|
||||
/// set the viewpoint
|
||||
/// GET the viewpoint
|
||||
const vcg::Point3<S> GetViewPoint()const;
|
||||
/// SET the viewpoint
|
||||
void SetViewPoint(const vcg::Point3<S> & viewpoint);
|
||||
|
||||
/// look at
|
||||
/// look at (dir+up)
|
||||
void LookAt(const vcg::Point3<S> & z_dir,const vcg::Point3<S> & 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<S> & z_dir,const vcg::Point3<S> & up);
|
||||
|
||||
/// convert a 3d point in camera coordinates
|
||||
vcg::Point3<S> ConvertToCameraCoordinates(const vcg::Point3<S> & p) const;
|
||||
/// convert a 3d point from world to camera coordinates
|
||||
vcg::Point3<S> ConvertWorldToCameraCoordinates(const vcg::Point3<S> & p) const;
|
||||
|
||||
/// convert a 3d point in camera coordinates
|
||||
vcg::Point3<S> ConvertToWorldCoordinates(const vcg::Point3<S> & p) const;
|
||||
/// convert a 3d point from camera to world coordinates
|
||||
vcg::Point3<S> ConvertCameraToWorldCoordinates(const vcg::Point3<S> & p) const;
|
||||
|
||||
/// project onto the camera plane
|
||||
/// project a 3d point from world coordinates to 2d camera viewport (pixel)
|
||||
vcg::Point2<S> Project(const vcg::Point3<S> & 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<S> UnProject(const vcg::Point2<S> & 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<S> & p)const;
|
||||
|
||||
/// project a 3d point from 3D WORLD to 2D VIEWPORT
|
||||
vcg::Point2<S> ProjectWorldtoViewport(const vcg::Point3<S> & p) const;
|
||||
|
||||
|
||||
}; // end class definition
|
||||
|
||||
|
||||
|
||||
//---
|
||||
/// GET the viewpoint
|
||||
template <class S>
|
||||
const vcg::Point3<S> Shot<S>::ViewPoint() const {
|
||||
//Matrix44<S> m = similarity.Matrix();
|
||||
//return Point3<S>(m[0][3],m[1][3],m[2][3]);
|
||||
return -similarity.tra;
|
||||
const vcg::Point3<S> Shot<S>::GetViewPoint() const
|
||||
{
|
||||
return -Extrinsics.tra;
|
||||
}
|
||||
/// SET the viewpoint
|
||||
template <class S>
|
||||
void Shot<S>::SetViewPoint(const vcg::Point3<S> & viewpoint)
|
||||
{
|
||||
Extrinsics.tra = -viewpoint;
|
||||
}
|
||||
//---
|
||||
|
||||
/// GET the i-th axis of the coordinate system of the camera
|
||||
template <class S>
|
||||
vcg::Point3<S> Shot<S>::Axis(const int & i) const
|
||||
{
|
||||
vcg::Matrix44<S> m;
|
||||
Extrinsics.rot.ToMatrix(m);
|
||||
vcg::Point3<S> aa = m.GetRow3(i);
|
||||
return aa;
|
||||
}
|
||||
|
||||
/// look at (dir+up)
|
||||
template <class S>
|
||||
vcg::Point3<S> Shot<S>::Axis(const int & i) const {
|
||||
vcg::Matrix44<S> m;
|
||||
similarity.rot.ToMatrix(m);
|
||||
vcg::Point3<S> aa = m.GetRow3(i);
|
||||
return aa;
|
||||
}
|
||||
|
||||
template <class S>
|
||||
void Shot<S>::SetViewPoint(const vcg::Point3<S> & viewpoint){
|
||||
similarity.tra = -viewpoint;
|
||||
}
|
||||
|
||||
template <class S>
|
||||
void Shot<S>::LookAt(const vcg::Point3<S> & z_dir,const vcg::Point3<S> & up){
|
||||
void Shot<S>::LookAt(const vcg::Point3<S> & z_dir,const vcg::Point3<S> & up)
|
||||
{
|
||||
LookTowards(z_dir-ViewPoint(),up);
|
||||
}
|
||||
|
||||
/// look at (opengl-like)
|
||||
template <class S>
|
||||
void Shot<S>::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<S>::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<S>(eye_x,eye_y,eye_z));
|
||||
LookAt(Point3<S>(at_x,at_y,at_z),Point3<S>(up_x,up_y,up_z));
|
||||
}
|
||||
|
||||
|
||||
/// look towards
|
||||
template <class S>
|
||||
void Shot<S>::LookTowards(const vcg::Point3<S> & z_dir,const vcg::Point3<S> & up){
|
||||
vcg::Point3<S> x_dir = up ^-z_dir ;
|
||||
vcg::Point3<S> y_dir = -z_dir ^x_dir ;
|
||||
void Shot<S>::LookTowards(const vcg::Point3<S> & z_dir,const vcg::Point3<S> & up)
|
||||
{
|
||||
vcg::Point3<S> x_dir = up ^-z_dir;
|
||||
vcg::Point3<S> y_dir = -z_dir ^x_dir;
|
||||
|
||||
Matrix44<S> m;
|
||||
m.SetIdentity();
|
||||
*(vcg::Point3<S> *)&m[0][0] = x_dir/x_dir.Norm();
|
||||
*(vcg::Point3<S> *)&m[1][0] = y_dir/y_dir.Norm();
|
||||
*(vcg::Point3<S> *)&m[0][0] = x_dir/x_dir.Norm();
|
||||
*(vcg::Point3<S> *)&m[1][0] = y_dir/y_dir.Norm();
|
||||
*(vcg::Point3<S> *)&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 <class S>
|
||||
vcg::Point3<S> Shot<S>::ConvertToCameraCoordinates(const vcg::Point3<S> & p) const{
|
||||
vcg::Point3<S> Shot<S>::ConvertWorldToCameraCoordinates(const vcg::Point3<S> & p) const
|
||||
{
|
||||
Matrix44<S> rotM;
|
||||
similarity.rot.ToMatrix(rotM);
|
||||
vcg::Point3<S> cp = rotM * (p+similarity.tra);
|
||||
// note: the camera reference system is right handed
|
||||
cp[2]=-cp[2];
|
||||
Extrinsics.rot.ToMatrix(rotM);
|
||||
vcg::Point3<S> 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 <class S>
|
||||
vcg::Point3<S> Shot<S>::ConvertToWorldCoordinates(const vcg::Point3<S> & p) const{
|
||||
vcg::Point3<S> Shot<S>::ConvertCameraToWorldCoordinates(const vcg::Point3<S> & p) const
|
||||
{
|
||||
Matrix44<S> rotM;
|
||||
vcg::Point3<S> 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 <class S>
|
||||
vcg::Point2<S> Shot<S>::Project(const vcg::Point3<S> & p) const{
|
||||
return camera.Project(ConvertToCameraCoordinates(p));
|
||||
}
|
||||
template <class S>
|
||||
vcg::Point3<S> Shot<S>::UnProject(const vcg::Point2<S> & p, const S & d) const{
|
||||
Point2<S> tp = camera.ViewportToLocal(p);
|
||||
vcg::Point3<S> q = camera.UnProject(tp, d);
|
||||
return ConvertToWorldCoordinates(q);
|
||||
}
|
||||
template <class S>
|
||||
S Shot<S>::Depth(const vcg::Point3<S> & p)const {
|
||||
return ConvertToCameraCoordinates(p).Z();
|
||||
}
|
||||
|
||||
/// project a 3d point from world coordinates to 2d camera viewport (pixel)
|
||||
template <class S>
|
||||
vcg::Point2<S> Shot<S>::ProjectWorldtoViewport(const vcg::Point3<S> & p)const
|
||||
vcg::Point2<S> Shot<S>::Project(const vcg::Point3<S> & p) const
|
||||
{
|
||||
return camera.LocalToViewport( camera.Project( ConvertToCameraCoordinates(p) ) );
|
||||
Point3<S> cp = ConvertWorldToCameraCoordinates(p);
|
||||
Point2<S> pp = Intrinsics.Project(cp);
|
||||
Point2<S> vp = Intrinsics.LocalToViewportPx(pp);
|
||||
return vp;
|
||||
}
|
||||
|
||||
/// inverse projection from 2d camera viewport (pixel) + Zdepth to 3d world coordinates
|
||||
template <class S>
|
||||
vcg::Point3<S> Shot<S>::UnProject(const vcg::Point2<S> & p, const S & d) const
|
||||
{
|
||||
Point2<S> lp = Intrinsics.ViewportPxToLocal(p);
|
||||
Point3<S> cp = Intrinsics.UnProject(lp,d);
|
||||
Point3<S> wp = ConvertCameraToWorldCoordinates(cp);
|
||||
return wp;
|
||||
}
|
||||
|
||||
/// returns distance of point p from camera plane (z depth), used for unprojection
|
||||
template <class S>
|
||||
S Shot<S>::Depth(const vcg::Point3<S> & p)const
|
||||
{
|
||||
return ConvertWorldToCameraCoordinates(p).Z();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------
|
||||
|
||||
|
||||
//--- utility definitions
|
||||
class Shotf: public Shot<float>{};
|
||||
class Shotd: public Shot<double>{};
|
||||
//-----------------------
|
||||
|
||||
} // end name space
|
||||
|
||||
|
|
|
@ -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<ScalarType>
|
||||
MatrixGL(vcg::Camera<S> & cam, vcg::Matrix44<S> &m){
|
||||
MatrixGL(vcg::Camera<S> & cam, vcg::Matrix44<S> &m)
|
||||
{
|
||||
glPushAttrib(GL_TRANSFORM_BIT);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
|
@ -89,7 +95,8 @@ MatrixGL(vcg::Camera<S> & cam, vcg::Matrix44<S> &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<S> & 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<S> & 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<S> & camera, S farDist = -1 ) {
|
||||
/// set the OpenGL PROJECTION matrix to match the camera (intrinsics). requires near and far plane
|
||||
static void TransformGL(vcg::Camera<S> & 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<S> & 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<S> & camera, S &width, S &height) {
|
|||
height = tp-bt; //top - bottom = height
|
||||
};
|
||||
|
||||
|
||||
static void SetSubView(vcg::Camera<S> & camera,vcg::Point2<S> p0,vcg::Point2<S> p1){
|
||||
//typedef typename CameraType::ScalarType S;
|
||||
S sx,dx,bt,tp,nr,fr;
|
||||
|
@ -170,11 +176,12 @@ static void SetSubView(vcg::Camera<S> & camera,vcg::Point2<S> p0,vcg::Point2<S>
|
|||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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<typename ShotType::CameraType> GlCameraType;
|
||||
|
||||
static void MatrixGL(ShotType & shot,vcg::Matrix44<ScalarType> & 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<ScalarType> & m)
|
||||
{
|
||||
m = shot.Extrinsics.Matrix();
|
||||
}
|
||||
|
||||
static void TransformGL(vcg::Shot<ScalarType> & shot){
|
||||
/// set the OpenGL MODELVIEW matrix to match the shot (extrinsics)
|
||||
static void TransformGL(vcg::Shot<ScalarType> & shot)
|
||||
{
|
||||
vcg::Matrix44<ScalarType> m;
|
||||
MatrixGL(shot,m);
|
||||
glMultMatrix(m);
|
||||
}
|
||||
|
||||
static void SetView(vcg::Shot<ScalarType> & shot){
|
||||
/// set the OpenGL PROJECTION and MODELVIEW matrix to match camera+shot. requires near and far plane
|
||||
static void SetView(vcg::Shot<ScalarType> & 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<ScalarType> & shot){
|
|||
GlShot<ShotType>::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<ScalarType> & shot,
|
||||
vcg::Point2<ScalarType> p1,
|
||||
vcg::Point2<ScalarType> p2)
|
||||
|
@ -123,15 +144,7 @@ static void SetSubView(vcg::Shot<ScalarType> & shot,
|
|||
assert(glGetError() == 0);
|
||||
}
|
||||
|
||||
static void UnsetView()
|
||||
{
|
||||
glPushAttrib(GL_TRANSFORM_BIT);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glPopAttrib();
|
||||
}
|
||||
|
||||
|
||||
/**********************************
|
||||
DEFINE SHOT FROM TRACKBALL
|
||||
|
|
|
@ -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]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue