/* * ===================================================================================== * * Filename: main_cvpr_data.cpp * * Description: plays back depth mocap data for CVPR 2010 * Version: 1.0 * Created: 6/8/2010 4:12:38 PM * Author: Varun Ganapathi (varung@gmail.com), * ===================================================================================== */ #include #include #include #include // NOTE: you can change this to the standard GL headers if you don't have GLEW //#include #include #include //#include using namespace std; int paused = false; float amp_lo = 4000; float x_angle = 0, y_angle = 0; int cur_file=0; char *data_set_dir = NULL; extern float color_map[][3]; extern int color_map_size; float intrinsic[] = { 2.844376,0.000000,0.000000,0.000000, 0.000000,2.327216,0.000000,0.000000, 0.000000,0.000000,-1.000020,-1.000000, 0.000000,0.000000,-0.200002,0.000000 }; struct Frame { static const int R = 176; static const int C = 144; static const int N = R*C; static const int MAX_MARKERS = 64; int MAGIC_NUMBER; // 4 byte header to detect read failure int frame_number; // 4 bytes long long frame_timestamp; // 8 bytes float points[N][3]; // N * 4 bytes, points in TOF frame unsigned short dist[N], // N * 1 bytes, ~ depth amp[N], // N * 1 bytes, ~ intensity conf[N]; // N * 1 bytes, ~ confidence struct Marker { int id; int frame; float x, y, z; float cond; unsigned int flag; }; int nmarkers; Marker markers[MAX_MARKERS]; // constant size per frame void write_constant(ostream& os){ os.write( (char*)this, sizeof(*this)); } void read_constant(istream& os){ assert_sizes(); os.read( (char*)this, sizeof(*this)); if(!os) { //printf("error: read %d\n", os.gcount()); } assert(MAGIC_NUMBER==-1982 && "MAGIC NUMBER NOT FOUND"); } // asserts that byte sizes on this computer match dataset void assert_sizes() { assert(sizeof(int) == 4); assert(sizeof(long long) == 8); assert(sizeof(unsigned short) == 2 ); assert(sizeof(float) == 4); } Frame():MAGIC_NUMBER(-1982){} }; int win_h() { return glutGet(GLUT_WINDOW_HEIGHT); } int win_w() { return glutGet(GLUT_WINDOW_WIDTH); } void reshape( int w, int h ){ glutPostRedisplay(); } inline float clamp( float x, float lo, float hi){ if(x < lo) return lo; if(x > hi) return hi; return x; } Frame frame; ifstream seq_ifs; void draw( Frame& f ) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glLoadMatrixf(intrinsic); // draw sensor glEnable(GL_DEPTH_TEST); glPointSize(4.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0,0,-2); glRotatef(y_angle, 0, 1.0, 0); glRotatef(x_angle, 1.0, 0, 0); glTranslatef(0,0,2); glColor3f( .7, .3, .3 ); glBegin(GL_POINTS); for (int i=0; i1.0 ? 1.0 : a; a = a<0.0 ? 0.0 : a; //glColor3f( a, a, a ); int index = clamp(-(f.points[i][2] + 2.0), 0.0, 1.0 ) * (color_map_size-1); glColor3fv( color_map[ index ] ); glVertex3fv(p); } glEnd(); // draw markers glDisable(GL_DEPTH_TEST); for(int i=0; i