diff --git a/README b/README index 040b46ac0f4081f87cf2e73db33fc94b64339be2..9032a9a125ad28faa498caca1baa9e1190ab7cd3 100644 --- a/README +++ b/README @@ -19,17 +19,24 @@ To build in GNU/Linux and Mac, simply run qmake and make. In Windows, it would be easier to go through QtCreator (of course, you can also use QtCreator on GNU/Linux and Mac). +By default, the interface lets the user choose, beyond our method, between +common projection methods. The compilation flag PANO_EXTENDED_CONTROLS can +be added to show controls for other state-of-the-art projection methods. + To configure, you can set in the file ~/.panorc the following options. shader_dir= image_file= image_dir= fov= max_fov= +If the program is compiled with the PANO_EXTENDED_CONTROLS flag, these +options are also available. + pd= zblambda= zbR= Lines in the file must start with option names, and no spaces should go between option names, equal signs and values. If no shader path is set, the default is ./shaders/. If no input file is set, or the file is missing, a file chooser will be shown at startup. The default value of max_fov and fov -are 60 degrees. zblambda and zbR are specified in floating-point, following -machine locales. +are 60 degrees. pd, zblambda and zbR are specified in floating-point, +following machine locales. diff --git a/extended_controls.ui b/extended_controls.ui index 99c0a6757cb5eb84af3e556bb7785b2e39d5c174..f9f7c7eddaf33872c86275ee94f9a624b3f759fa 100644 --- a/extended_controls.ui +++ b/extended_controls.ui @@ -96,6 +96,11 @@ Mercator + + + Pannini + + Zorin-Barr @@ -154,6 +159,9 @@ + + QFormLayout::AllNonFixedFieldsGrow + @@ -180,7 +188,7 @@ - + lambda @@ -212,12 +220,29 @@ - + R + + + + 400 + + + Qt::Horizontal + + + + + + + d + + + @@ -381,6 +406,7 @@ shrinkallbutton(bool) change_zb_lambda(int) change_zb_R(int) + change_p_d(int) @@ -658,5 +684,21 @@ + + changepd + sliderMoved(int) + GLCanvas + change_p_d(int) + + + 1166 + 209 + + + 563 + 345 + + + diff --git a/openglcanvas.cpp b/openglcanvas.cpp index 2ed81e843bef7f99a050f372b04e2e76ac2934c7..7e763189cd329389af2b6e36ecd2910fa43d5ec4 100644 --- a/openglcanvas.cpp +++ b/openglcanvas.cpp @@ -28,14 +28,17 @@ //#define CONST_PI_F (0x1.921fb6p+1f) //#define CONST_PI_2_F (0x1.921fb6p+0f) +#ifdef PANO_EXTENDED_CONTROLS // These definitions specify which attributes should be used to store some // parameters passed to the vertex shader. Nvidia hardware // only leaves attributes 1 and 7 unreserved; attributes 8 to 15 are // reserved for textures. // TODO: we use attributes 14 and 15, which work for Nvidia; we need to // test with other hardware. +#define PD_ATTR 13 #define ZBL_ATTR 14 #define ZBR_ATTR 15 +#endif // PANO_EXTENDED_CONTROLS OpenGLCanvas::OpenGLCanvas(QWidget *parent) : QGLWidget(parent) @@ -50,8 +53,11 @@ OpenGLCanvas::OpenGLCanvas(QWidget *parent) : visualization = "Moebius"; auto_fov_max=false; shrink_for_all=false; +#ifdef PANO_EXTENDED_CONTROLS + pd=0.f; // Pannini projection d zblambda=.1f; // Zorin-Barr transformation lambda zbR=1.f; // Zorin-Barr transformation R +#endif // PANO_EXTENDED_CONTROLS time_frames = 0; time_timer.setInterval(0); @@ -105,6 +111,14 @@ void OpenGLCanvas::change_fov_max(int new_fov_max){ updateGL(); } +#ifdef PANO_EXTENDED_CONTROLS +void OpenGLCanvas::change_p_d(int new_p_d){ + pd=(float)new_p_d/10; + fprintf(stderr,"p_d=%f\n",pd); + glVertexAttrib1f(PD_ATTR,pd); + updateGL(); +} + void OpenGLCanvas::change_zb_lambda(int new_zb_lambda){ zblambda=(float)new_zb_lambda/1000; fprintf(stderr,"zb_lambda=%f\n",zblambda); @@ -118,6 +132,7 @@ void OpenGLCanvas::change_zb_R(int new_zb_R){ glVertexAttrib1f(ZBR_ATTR,zbR); updateGL(); } +#endif // PANO_EXTENDED_CONTROLS //void OpenGLCanvas::change_scale(double s){ @@ -244,6 +259,14 @@ void OpenGLCanvas::read_config_file(){ auto_fov_max=atof(read_line); fprintf(stderr,"auto_max_fov=%d\n",auto_fov_max); } +#ifdef PANO_EXTENDED_CONTROLS + // check for the Pannini parameter, d + if(!strncmp(line,"pd=",3)){ + strcpy(read_line,line+3); + read_line[strlen(line)-4]='\0'; + pd=atof(read_line); + fprintf(stderr,"pd=%f\n",pd); + } // check for the Zorin-Barr transformation parameters, lambda and R if(!strncmp(line,"zblambda=",9)){ strcpy(read_line,line+9); @@ -257,6 +280,7 @@ void OpenGLCanvas::read_config_file(){ zbR=atof(read_line); fprintf(stderr,"zbR=%f\n",zbR); } +#endif // PANO_EXTENDED_CONTROLS } fclose(rcfile); } @@ -480,6 +504,21 @@ void OpenGLCanvas::vertex_transformation(float *positions, int m, int n, float c positions[3*(j+i*n)+1] = v/extent; positions[3*(j+i*n)+2] = z; } + else if (visualization=="Orthographic"){ + u=x; + v=y; + positions[3*(j+i*n)]=x/extent; + positions[3*(j+i*n)+1]=y/extent; + positions[3*(j+i*n)+2]=z; + } +#ifdef PANO_EXTENDED_CONTROLS + else if (visualization=="Pannini"){ + u = 2*x/(-z+pd); + v = 2*y/(-z+pd); + positions[3*(j+i*n)] = u/extent; + positions[3*(j+i*n)+1] = v/extent; + positions[3*(j+i*n)+2] = z; + } else if (visualization=="Zorin-Barr"){ // perspective u = x/(-z); @@ -497,13 +536,7 @@ void OpenGLCanvas::vertex_transformation(float *positions, int m, int n, float c positions[3*(j+i*n)+1] = v/extent; positions[3*(j+i*n)+2] = z; } - else if (visualization=="Orthographic"){ - u=x; - v=y; - positions[3*(j+i*n)]=x/extent; - positions[3*(j+i*n)+1]=y/extent; - positions[3*(j+i*n)+2]=z; - } +#endif // PANO_EXTENDED_CONTROLS } } } @@ -573,11 +606,6 @@ float OpenGLCanvas::calculate_extent(float fov_rads){ // Write now it's olny showing the entire panorama intead of // the corresponging FOV. } - else if (visualization=="Zorin-Barr"){ - // TODO: check whether this is correct - u=x/(-z); - v=y/(-z); - } else if (visualization=="Orthographic"){ if(z<0.f){ u=x; @@ -586,6 +614,17 @@ float OpenGLCanvas::calculate_extent(float fov_rads){ u=v=1.f; } } +#ifdef PANO_EXTENDED_CONTROLS + else if (visualization=="Pannini"){ + u=2.f*x/(pd-z); + v=2.f*y/(pd-z); + } + else if (visualization=="Zorin-Barr"){ + // TODO: check whether this is correct + u=x/(-z); + v=y/(-z); + } +#endif // PANO_EXTENDED_CONTROLS return u; } @@ -739,11 +778,15 @@ void OpenGLCanvas::setShaders() { GLuint p = glCreateProgram(); - // Bind attributes zblambda and zbR to the vertex shader. +#ifdef PANO_EXTENDED_CONTROLS + // Bind attributes pd, zblambda and zbR to the vertex shader. + glVertexAttrib1f(PD_ATTR,pd); + glBindAttribLocation(p,PD_ATTR,"pd"); glVertexAttrib1f(ZBL_ATTR,zblambda); glBindAttribLocation(p,ZBL_ATTR,"zblambda"); glVertexAttrib1f(ZBR_ATTR,zbR); glBindAttribLocation(p,ZBR_ATTR,"zbR"); +#endif // PANO_EXTENDED_CONTROLS glAttachShader(p,v); glAttachShader(p,f); @@ -796,9 +839,12 @@ void OpenGLCanvas::paintGL(){ else if (visualization=="3D Sphere") vis_mode=2.f; else if (visualization=="Equi-Rectangular") vis_mode=3.f; else if (visualization=="Stereographic") vis_mode=4.f; - else if (visualization=="Orthographic") vis_mode=4.5f; else if (visualization=="Mercator") vis_mode=5.f; + else if (visualization=="Orthographic") vis_mode=4.5f; +#ifdef PANO_EXTENDED_CONTROLS + else if (visualization=="Pannini") vis_mode=4.25f; else if (visualization=="Zorin-Barr") vis_mode=6.f; +#endif // PANO_EXTENDED_CONTROLS glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 2.0/extent, 0.0, 2.0/scale, 0.0, -2.0/vis_mode); diff --git a/openglcanvas.h b/openglcanvas.h index cf58a68f18bc62fd58b16942374be0e7604e28f8..97605b4811dd93c91e23965b2803f80c4f634525 100644 --- a/openglcanvas.h +++ b/openglcanvas.h @@ -53,8 +53,11 @@ public slots: void change_fov(double f); void change_fov(int new_fov); void change_fov_max(int new_fov_max); +#ifdef PANO_EXTENDED_CONTROLS + void change_p_d(int new_p_d); void change_zb_lambda(int new_zb_lambda); void change_zb_R(int new_zb_R); +#endif // PANO_EXTENDED_CONTROLS // void change_scale(double s); void change_center_lambda(double lambda); void change_center_phi(double phi); @@ -76,7 +79,10 @@ private: QString visualization; bool auto_fov_max; bool shrink_for_all; +#ifdef PANO_EXTENDED_CONTROLS + float pd; // parameter of the Pannini projection float zblambda,zbR; // parameters of the Zorin-Barr transformation +#endif // PANO_EXTENDED_CONTROLS Chronos time_time; QTimer time_timer; diff --git a/shaders/vertex_shader.vert b/shaders/vertex_shader.vert index cdc9b5c26f7d2b43c387ca5390091d34751127a3..673a5fadda06ca2ad1aca1020518969077b4cc74 100644 --- a/shaders/vertex_shader.vert +++ b/shaders/vertex_shader.vert @@ -6,7 +6,7 @@ float u, v, x, y, z; varying float r, theta, s; float lambda, phi; float extent, scale, vis_mode, center_lambda, center_phi; -attribute float zblambda,zbR; +attribute float zblambda,zbR,pd; void main(void){ @@ -71,8 +71,13 @@ void main(void){ else if (vis_mode==3.0) // Equi-Rectangular gl_Position = vec4(lambda,phi,z,1.0); else if (vis_mode==4.0) { // Stereographic - u = 2.0*x/(-z+1.0); - v = 2.0*y/(-z+1.0); + u = 2.0*x/(1.0-z); + v = 2.0*y/(1.0-z); + gl_Position = vec4(u/extent,v/extent,z,1.0); + } + else if (vis_mode==4.25) { // Pannini + u = 2.0*x/(pd-z); + v = 2.0*y/(pd-z); gl_Position = vec4(u/extent,v/extent,z,1.0); } else if (vis_mode==4.5){ // Orthographic