From 8e1fbd14f35c4d56f6a72ef7e8c91c38091cf2e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Pe=C3=B1aranda?= Date: Mon, 12 Aug 2013 15:48:14 -0300 Subject: [PATCH] added the Zorin-Barr transformation --- openglcanvas.cpp | 39 +++++++++++++++++++++++++++++++++ openglcanvas.h | 1 + pano_interface_1.pro | 4 ++++ panowindow1.ui | 5 +++++ shaders/test_vertex_shader.vert | 27 ++++++++++++++++++----- 5 files changed, 71 insertions(+), 5 deletions(-) diff --git a/openglcanvas.cpp b/openglcanvas.cpp index af7298e..2288d04 100644 --- a/openglcanvas.cpp +++ b/openglcanvas.cpp @@ -40,6 +40,8 @@ OpenGLCanvas::OpenGLCanvas(QWidget *parent) : fov_scale_relation = "Naive"; visualization = "Moebius"; auto_fov_max=false; + zblambda=.1f; // Zorin-Barr transformation lambda + zbR=1.f; // Zorin-Barr transformation R time_frames = 0; time_timer.setInterval(0); @@ -248,6 +250,19 @@ void OpenGLCanvas::read_config_file(){ auto_fov_max=atof(read_line); fprintf(stderr,"auto_max_fov=%d\n",auto_fov_max); } + // check for the Zorin-Barr transformation parameters, lambda and R + if(!strncmp(line,"zblambda=",9)){ + strcpy(read_line,line+9); + read_line[strlen(line)-10]='\0'; + zblambda=atof(read_line); + fprintf(stderr,"zblambda=%f\n",zblambda); + } + if(!strncmp(line,"zbR=",4)){ + strcpy(read_line,line+4); + read_line[strlen(line)-5]='\0'; + zbR=atof(read_line); + fprintf(stderr,"zbR=%f\n",zbR); + } } fclose(rcfile); } @@ -475,6 +490,24 @@ void OpenGLCanvas::vertex_transformation(float *positions, int m, int n, float c positions[3*(j+i*n)+2] = z; } + // perspective + if (visualization=="Zorin-Barr"){ + // perspective + u = x/(-z); + v = y/(-z); + // apply Z-B transformation to (u,v) + float lambda=.1f; + float R=1.f; + float alpha=atanf(v/u); + float r=hypotf(u,v); + float rhoprime=(lambda*r/R)+(1.f-lambda)*(R*(sqrtf(r*r+1.f)-1.f))/(r*(sqrtf(R*R+1.f)-1.f)); + u=rhoprime*cosf(alpha); + v=rhoprime*sinf(alpha); + // + positions[3*(j+i*n)] = u/extent; + positions[3*(j+i*n)+1] = v/extent; + positions[3*(j+i*n)+2] = z; + } } } @@ -546,6 +579,11 @@ float OpenGLCanvas::calculate_extent(float fov_rads){ // Write now it's olny showing the entire panorama intead of // the corresponging FOV. } + if (visualization=="Zorin-Barr"){ + // TODO: check whether this is correct + u = x/(-z); + v = y/(-z); + } return u; } @@ -724,6 +762,7 @@ void OpenGLCanvas::paintGL(){ else if (visualization=="Equi-Rectangular") vis_mode=3.0; else if (visualization=="Stereographic") vis_mode=4.0; else if (visualization=="Mercator") vis_mode=5.0; + else if (visualization=="Zorin-Barr") vis_mode=6.0; 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 e614574..064ba3b 100644 --- a/openglcanvas.h +++ b/openglcanvas.h @@ -71,6 +71,7 @@ private: QString fov_scale_relation; QString visualization; bool auto_fov_max; + float zblambda,zbR; // parameters of the Zorin-Barr transformation Chronos time_time; QTimer time_timer; diff --git a/pano_interface_1.pro b/pano_interface_1.pro index d229edd..be14f9f 100644 --- a/pano_interface_1.pro +++ b/pano_interface_1.pro @@ -76,3 +76,7 @@ HEADERS += panowindow1.h \ files.h FORMS += panowindow1.ui + +OTHER_FILES += \ + shaders/fragment_shader.frag \ + shaders/test_vertex_shader.vert diff --git a/panowindow1.ui b/panowindow1.ui index f6880c3..aec84ac 100644 --- a/panowindow1.ui +++ b/panowindow1.ui @@ -202,6 +202,11 @@ Mercator + + + Zorin-Barr + + diff --git a/shaders/test_vertex_shader.vert b/shaders/test_vertex_shader.vert index 7107ae7..b5f5399 100644 --- a/shaders/test_vertex_shader.vert +++ b/shaders/test_vertex_shader.vert @@ -4,6 +4,7 @@ float u, v, x, y, z; varying float r, theta, s; float lambda, phi; float extent, scale, vis_mode, center_lambda, center_phi; +varying float zbu,zbv,zblambda,zbr,zbR,zbalpha,zbrho; void main(void){ @@ -58,23 +59,39 @@ void main(void){ phi = asin(y)/1.5708; // Visualize using specified visualization (remove for timings in the paper! Use only "Perspective" in the paper!) - if (vis_mode==1.0) { + if (vis_mode==1.0) { // Moebius u = x/(-z); v = y/(-z); gl_Position = vec4(u/extent,v/extent,z,1.0); } - else if (vis_mode==2.0) gl_Position = vec4(0.9*x,0.9*y,z,1.0); - else if (vis_mode==3.0) gl_Position = vec4(lambda,phi,z,1.0); - else if (vis_mode==4.0) { + else if (vis_mode==2.0) // 3D Sphere + gl_Position = vec4(0.9*x,0.9*y,z,1.0); + 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.f*x/(-z+1); v = 2.f*y/(-z+1); gl_Position = vec4(u/extent,v/extent,z,1.0); } - else if (vis_mode==5.0) { + else if (vis_mode==5.0) { // Mercator u = lambda; v = log((1.0/cos(phi)) + tan(phi)); gl_Position = vec4(u,v,z,1.0); } + else if (vis_mode==6.0) { // Zorin-Barr + // perspective projection + zbu = x/(-z); + zbv = y/(-z); + // Z-B transformation + zblambda=0.1; + zbR=1.0; + zbalpha=atan(zbv,zbu); + zbr=sqrt(zbu*zbu+zbv*zbv); + zbrho=(zblambda*zbr/zbR)+(1.0-zblambda)*(zbR*(sqrt(zbr*zbr+1.0)-1.0))/(zbr*(sqrt(zbR*zbR+1.0)-1.0)); + u=zbrho*cos(zbalpha); + v=zbrho*sin(zbalpha); + gl_Position = vec4(u/extent,v/extent,z,1.0); + } // gl_Position = vec4(u/2.0,v/2.0,z,1.0); -- GitLab