Commit 562c84c4 authored by Luis Peñaranda's avatar Luis Peñaranda

use float arithmetic functions for floats

parent dade31c1
......@@ -65,15 +65,15 @@ void OpenGLCanvas::change_fov(double f){
if (fov_scale_relation == "Naive")
scale=fov_max/fov;
else if (fov_scale_relation == "Square Root")
scale=sqrt((360.f-fov_max-fov)/(360.-2*fov_max));
scale=sqrtf((360.f-fov_max-fov)/(360.-2*fov_max));
else if (fov_scale_relation == "Linear")
scale=(360.f-fov_max-fov)/(360.-2*fov_max);
scale=(360.f-fov_max-fov)/(360.f-2.f*fov_max);
else if (fov_scale_relation == "Square Power")
scale=powf((360.f-fov_max-fov)/(360.-2*fov_max),2);
scale=powf((360.f-fov_max-fov)/(360.f-2.f*fov_max),2.f);
else if (fov_scale_relation == "Cubic Power")
scale=powf((360.f-fov_max-fov)/(360.-2*fov_max),3);
scale=powf((360.f-fov_max-fov)/(360.f-2.f*fov_max),3.f);
else if (fov_scale_relation == "Logarithm")
scale=log(exp(1.f)+(1.f-exp(1.f))*(fov-fov_max)/(360.-2*fov_max));
scale=logf(expf(1.f)+(1.f-expf(1.f))*(fov-fov_max)/(360.f-2.f*fov_max));
}
// scale = 0.3f;
......@@ -99,7 +99,7 @@ void OpenGLCanvas::change_fov(int new_fov){
}
void OpenGLCanvas::change_fov_max(int new_fov_max){
if(new_fov_max<=360&&new_fov_max>=1)
if(new_fov_max<=360.f&&new_fov_max>=1)
fov_max=(double)new_fov_max;
if (fov<=fov_max)
scale=1.f;
......@@ -109,15 +109,15 @@ void OpenGLCanvas::change_fov_max(int new_fov_max){
if (fov_scale_relation == "Naive")
scale=fov_max/fov;
else if (fov_scale_relation == "Square Root")
scale=sqrt((360.f-fov_max-fov)/(360.-2*fov_max));
scale=sqrtf((360.f-fov_max-fov)/(360.f-2.f*fov_max));
else if (fov_scale_relation == "Linear")
scale=(360.f-fov_max-fov)/(360.-2*fov_max);
scale=(360.f-fov_max-fov)/(360.f-2.f*fov_max);
else if (fov_scale_relation == "Square Power")
scale=powf((360.f-fov_max-fov)/(360.-2*fov_max),2);
scale=powf((360.f-fov_max-fov)/(360.f-2.f*fov_max),2.f);
else if (fov_scale_relation == "Cubic Power")
scale=powf((360.f-fov_max-fov)/(360.-2*fov_max),3);
scale=powf((360.f-fov_max-fov)/(360.f-2.f*fov_max),3.f);
else if (fov_scale_relation == "Logarithm")
scale=log(exp(1.f)+(1.f-exp(1.f))*(fov-fov_max)/(360.-2*fov_max));
scale=logf(expf(1.f)+(1.f-expf(1.f))*(fov-fov_max)/(360.f-2.f*fov_max));
}
fprintf(stderr,"change fov_max, fov=%f, fov_max=%f, new scale=%f\n",fov,fov_max,scale);
emit max_fov_changed((int)fov_max);
......@@ -133,7 +133,7 @@ void OpenGLCanvas::change_fov_max(int new_fov_max){
void OpenGLCanvas::change_center_lambda(double lambda){
if (center_lambda!=lambda && lambda>=-CONST_PI && lambda<=CONST_PI) {
if (center_lambda!=lambda && lambda>=-CONST_PI_F && lambda<=CONST_PI_F) {
center_lambda = lambda;
updateGL();
}
......@@ -142,7 +142,7 @@ void OpenGLCanvas::change_center_lambda(double lambda){
void OpenGLCanvas::change_center_phi(double phi){
if (center_phi!=phi && phi>=-CONST_PI_2 && phi<=CONST_PI_2) {
if (center_phi!=phi && phi>=-CONST_PI_2_F && phi<=CONST_PI_2_F) {
center_phi = phi;
updateGL();
}
......@@ -164,15 +164,15 @@ void OpenGLCanvas::change_fov_scale_relation(QString name){
if (fov_scale_relation == "Naive")
scale=fov_max/fov;
else if (fov_scale_relation == "Square Root")
scale=sqrt((360.f-fov_max-fov)/(360.-2*fov_max));
scale=sqrtf((360.f-fov_max-fov)/(360.f-2.f*fov_max));
else if (fov_scale_relation == "Linear")
scale=(360.f-fov_max-fov)/(360.-2*fov_max);
scale=(360.f-fov_max-fov)/(360.f-2.f*fov_max);
else if (fov_scale_relation == "Square Power")
scale=powf((360.f-fov_max-fov)/(360.-2*fov_max),2);
scale=powf((360.f-fov_max-fov)/(360.f-2.f*fov_max),2.f);
else if (fov_scale_relation == "Cubic Power")
scale=powf((360.f-fov_max-fov)/(360.-2*fov_max),3);
scale=powf((360.f-fov_max-fov)/(360.f-2.f*fov_max),3.f);
else if (fov_scale_relation == "Logarithm")
scale=log(exp(1.f)+(1.f-exp(1.f))*(fov-fov_max)/(360.-2*fov_max));
scale=logf(expf(1.f)+(1.f-expf(1.f))*(fov-fov_max)/(360.f-2.f*fov_max));
}
fprintf(stderr,"changed scale relation, scale=%f, fov_max=%f\n",scale,fov_max);
updateGL();
......@@ -393,6 +393,7 @@ void OpenGLCanvas::define_texture_coordinates(float *texCoord, int m, int n, flo
}
// This function makes the same computation GLSL does. It is never called.
void OpenGLCanvas::vertex_transformation(float *positions, int m, int n, float center_lambda, float center_phi, float fov_rads, float scale){
float min_lambda = -CONST_PI_F;
......@@ -406,68 +407,67 @@ void OpenGLCanvas::vertex_transformation(float *positions, int m, int n, float c
float lambda, phi, x, y, z, u, v, r, theta;
//calculating the extent of the projection for the given FOV
lambda = fov_rads;
phi = 0.f;
lambda=fov_rads;
phi=0.f;
// OpenGL: x is the vertical axes pointg downwards, and y is horizontal axes
y = sin(phi);
x = -sin(lambda)*cos(phi);
z = -cos(lambda)*cos(phi);
u = 2.f*x/(-z+1.f);
v = 2.f*y/(-z+1.f);
r = sqrt(u*u+v*v);
theta = atan2(u,v);
r *= scale;
u = -r*sin(theta);
v = r*cos(theta);
x = (4.f*u)/(u*u+v*v+4.f);
y = (4.f*v)/(u*u+v*v+4.f);
z = (u*u+v*v-4.f)/(u*u+v*v+4.f);
u = x/(-z);
v = y/(-z);
float extent = u;
y=sinf(phi);
x=-sinf(lambda)*cosf(phi);
z = -cosf(lambda)*cosf(phi);
u=2.f*x/(1.f-z);
v=2.f*y/(1.f-z);
r=hypotf(u,v);
theta=atan2f(u,v);
r*=scale;
u=-r*sinf(theta);
v=r*cosf(theta);
x=(4.f*u)/(u*u+v*v+4.f);
y=(4.f*v)/(u*u+v*v+4.f);
z=(u*u+v*v-4.f)/(u*u+v*v+4.f);
u=x/(-z);
v=y/(-z);
float extent=u;
for (int i = 0; i<m; i++){
for (int j = 0; j<n; j++){
lambda = (min_lambda+delta_lambda*j);
phi = (min_phi+delta_phi*i);
lambda=(min_lambda+delta_lambda*j);
phi=(min_phi+delta_phi*i);
// OpenGL: x is the vertical axes pointg downwards, and y is horizontal axes
y = sin(phi);
x = -sin(lambda)*cos(phi);
z = -cos(lambda)*cos(phi);
y=sinf(phi);
x=-sinf(lambda)*cosf(phi);
z=-cosf(lambda)*cosf(phi);
//Rotation 1: (-center_lambda)-rotation on the xz-plane
float x_copy = x;
x = cos(-center_lambda)*x - sin(-center_lambda)*z;
y = 1.f*y;
z = sin(-center_lambda)*x_copy + cos(-center_lambda)*z;
float x_copy=x;
x=cosf(-center_lambda)*x-sinf(-center_lambda)*z;
//y=1.f*y;
z=sinf(-center_lambda)*x_copy+cosf(-center_lambda)*z;
//Rotation 2: (-center_phi)-rotation on the yz-plane
float y_copy = y;
x = 1.f*x;
y = cos(-center_phi)*y - sin(-center_phi)*z;
z = sin(-center_phi)*y_copy + cos(-center_phi)*z;
float y_copy=y;
//x = 1.f*x;
y=cosf(-center_phi)*y-sinf(-center_phi)*z;
z=sinf(-center_phi)*y_copy+cosf(-center_phi)*z;
u=2.f*x/(1.f-z);
v=2.f*y/(1.f-z);
u = 2.f*x/(-z+1.f);
v = 2.f*y/(-z+1.f);
r = sqrt(u*u+v*v);
theta = atan2(u,v);
r=hypotf(u,v);
theta=atan2f(u,v);
// scaling the complex plane according to scale specified in the interface (relate it to FOV)
r *= scale;
r*=scale;
u = -r*sin(theta);
v = r*cos(theta);
u=-r*sinf(theta);
v=r*cosf(theta);
x = (4.f*u)/(u*u+v*v+4.f);
y = (4.f*v)/(u*u+v*v+4.f);
z = (u*u+v*v-4.f)/(u*u+v*v+4.f);
x=(4.f*u)/(u*u+v*v+4.f);
y=(4.f*v)/(u*u+v*v+4.f);
z=(u*u+v*v-4.f)/(u*u+v*v+4.f);
lambda = atan2(x,-z)/CONST_PI_F;
phi = asin(y)/CONST_PI_2_F;
lambda=atan2f(x,-z)/CONST_PI_F;
phi=asinf(y)/CONST_PI_2_F;
if (visualization=="Moebius"){
u = x/(-z);
......@@ -476,36 +476,31 @@ 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;
}
if (visualization=="3D Sphere"){
else if (visualization=="3D Sphere"){
positions[3*(j+i*n)] = 0.9f*x;
positions[3*(j+i*n)+1] = 0.9f*y;
positions[3*(j+i*n)+2] = z;
}
if (visualization=="Equi-Rectangular"){
else if (visualization=="Equi-Rectangular"){
positions[3*(j+i*n)] = lambda;
positions[3*(j+i*n)+1] = phi;
positions[3*(j+i*n)+2] = z;
}
if (visualization=="Stereographic"){
else if (visualization=="Stereographic"){
u = 2*x/(-z+1);
v = 2*y/(-z+1);
positions[3*(j+i*n)] = u/extent;
positions[3*(j+i*n)+1] = v/extent;
positions[3*(j+i*n)+2] = z;
}
if (visualization=="Mercator"){
u = lambda;
v = log((1.0/cos(phi)) + tan(phi));
else if (visualization=="Mercator"){
u=lambda;
v=logf((1.0/cosf(phi))+tanf(phi));
positions[3*(j+i*n)] = u/extent;
positions[3*(j+i*n)+1] = v/extent;
positions[3*(j+i*n)+2] = z;
}
if (visualization=="Zorin-Barr"){
else if (visualization=="Zorin-Barr"){
// perspective
u = x/(-z);
v = y/(-z);
......@@ -522,18 +517,15 @@ 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;
}
if (visualization=="Orthographic"){
u = x;
v = y;
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=="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;
}
}
}
}
void OpenGLCanvas::load_sphere_mesh(float *positions, int m, int n){
......@@ -551,13 +543,13 @@ void OpenGLCanvas::load_sphere_mesh(float *positions, int m, int n){
for (int i = 0; i<m; i++){
for (int j = 0; j<n; j++){
lambda = (min_lambda+delta_lambda*j);
phi = (min_phi+delta_phi*i);
lambda=(min_lambda+delta_lambda*j);
phi=(min_phi+delta_phi*i);
// OpenGL: x is the vertical axes pointg downwards, and y is horizontal axes
y = sin(phi);
x = -sin(lambda)*cos(phi);
z = -cos(lambda)*cos(phi);
y=sinf(phi);
x=-sinf(lambda)*cosf(phi);
z=-cosf(lambda)*cosf(phi);
positions[3*(j+i*n)] = x;
positions[3*(j+i*n)+1] = y;
......@@ -569,46 +561,45 @@ void OpenGLCanvas::load_sphere_mesh(float *positions, int m, int n){
}
float OpenGLCanvas::calculate_extent(float fov_rads){
double lambda, phi, x, y, z, u, v, r, theta;
float lambda, phi, x, y, z, u, v, r, theta;
//calculating the extent of the projection for the given FOV
lambda = fov_rads;
phi = 0.;
lambda=fov_rads;
phi=0.f;
// OpenGL: x is the vertical axes pointg downwards, and y is horizontal axes
y = sin(phi);
x = -sin(lambda)*cos(phi);
z = -cos(lambda)*cos(phi);
u = 2.*x/(-z+1.);
v = 2.*y/(-z+1.);
r = sqrt(u*u+v*v);
theta = atan2(u,v);
r *= scale;
u = -r*sin(theta);
v = r*cos(theta);
x = (4.*u)/(u*u+v*v+4.);
y = (4.*v)/(u*u+v*v+4.);
z = (u*u+v*v-4.)/(u*u+v*v+4.);
y=sinf(phi);
x=-sinf(lambda)*cosf(phi);
z=-cosf(lambda)*cosf(phi);
u=2.f*x/(1.f-z);
v=2.f*y/(1.f-z);
r=hypotf(u,v);//sqrt(u*u+v*v);
theta=atan2f(u,v);
r*=scale;
u=-r*sinf(theta);
v=r*cosf(theta);
x=(4.f*u)/(u*u+v*v+4.f);
y=(4.f*v)/(u*u+v*v+4.f);
z=(u*u+v*v-4.f)/(u*u+v*v+4.f);
if (visualization=="Moebius"){
u = x/(-z);
v = y/(-z);
u=x/(-z);
v=y/(-z);
}
else if (visualization=="Stereographic"){
u = 2*x/(-z+1);
v = 2*y/(-z+1);
u=2.f*x/(1.f-z);
v=2.f*y/(1.f-z);
}
else if (visualization=="Mercator"){
u = fov_rads;
u=fov_rads;
// Warning: this extent calculation is wrong.
// 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);
u=x/(-z);
v=y/(-z);
}
if (visualization=="Orthographic"){
if(z<0.){
if(z<0.f){
u=x;
v=y;
}else{
......@@ -791,22 +782,21 @@ void OpenGLCanvas::wheelEvent(QWheelEvent *event){
void OpenGLCanvas::paintGL(){
float fov_rads = (fov/360.)*CONST_PI;
float fov_rads = (fov/360.f)*CONST_PI_F;
// // changing scale to generate the figures for the paper (remove it after)
// scale = 0.8;
// defining transformation parameters (that will be passed to the vertex shader)
float extent = calculate_extent(fov_rads);
float vis_mode=.0;
if (visualization=="Moebius") vis_mode=1.0;
else if (visualization=="3D Sphere") vis_mode=2.0;
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;
else if (visualization=="Orthographic") vis_mode=7.0;
float extent=calculate_extent(fov_rads);
float vis_mode=.0f;
if (visualization=="Moebius") vis_mode=1.f;
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=="Mercator") vis_mode=5.f;
else if (visualization=="Zorin-Barr") vis_mode=6.f;
else if (visualization=="Orthographic") vis_mode=7.f;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 2.0/extent, 0.0, 2.0/scale, 0.0, -2.0/vis_mode);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment