Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Luis Penaranda
panoramic
Commits
b102f57b
Commit
b102f57b
authored
Jan 25, 2013
by
Luis Peñaranda
Browse files
some numerical stability
parent
e6fa883b
Changes
1
Hide whitespace changes
Inline
Side-by-side
openglcanvas.cpp
View file @
b102f57b
...
...
@@ -22,6 +22,11 @@
#define VERT_SHADER_FILE "test_vertex_shader.vert"
#define FRAG_SHADER_FILE "fragment_shader.frag"
#define CONST_PI 3.141592653589793238462
#define CONST_PI_2 1.57079632679489661923
#define CONST_PI_F 3.14159265358979f
#define CONST_PI_2_F 1.570796326794897f // TODO: check this one
OpenGLCanvas
::
OpenGLCanvas
(
QWidget
*
parent
)
:
QGLWidget
(
parent
)
{
...
...
@@ -50,8 +55,8 @@ void OpenGLCanvas::change_fov(double f){
fov
=
f
;
if
(
fov
<=
fov_max
)
scale
=
1.
f
;
else
if
(
fov
>
295.
f
)
scale
=
0.02
f
;
// TODO: check this value wrt fov_max
//
else if (fov>295.f)
//
scale = 0.02f; // TODO: check this value wrt fov_max
else
{
if
(
fov_scale_relation
==
"Naive"
)
scale
=
fov_max
/
fov
;
...
...
@@ -69,7 +74,7 @@ void OpenGLCanvas::change_fov(double f){
// scale = 0.3f;
fprintf
(
stderr
,
"change fov=%f, fov_max=%f
\n
"
,
fov
,
fov_max
);
fprintf
(
stderr
,
"change
fov,
fov=%f, fov_max=%f
, scale=%f
\n
"
,
fov
,
fov_max
,
scale
);
emit
fov_changed
((
int
)
fov
);
updateGL
();
...
...
@@ -77,15 +82,17 @@ void OpenGLCanvas::change_fov(double f){
}
void
OpenGLCanvas
::
change_fov
(
int
new_fov
){
change_fov
((
double
)
new_fov
);
if
(
new_fov
<=
360
&&
new_fov
>=
1
)
change_fov
((
double
)
new_fov
);
}
void
OpenGLCanvas
::
change_fov_max
(
int
new_fov_max
){
fov_max
=
(
double
)
new_fov_max
;
if
(
new_fov_max
<=
360
&&
new_fov_max
>=
0
)
fov_max
=
(
double
)
new_fov_max
;
if
(
fov
<=
fov_max
)
scale
=
1.
f
;
else
if
(
fov
>
295.
f
)
scale
=
0.02
f
;
// TODO: check this value wrt fov_max
//
else if (fov>295.f)
//
scale = 0.02f; // TODO: check this value wrt fov_max
else
{
if
(
fov_scale_relation
==
"Naive"
)
scale
=
fov_max
/
fov
;
...
...
@@ -100,7 +107,7 @@ void OpenGLCanvas::change_fov_max(int new_fov_max){
else
if
(
fov_scale_relation
==
"Logarithm"
)
scale
=
log
(
exp
(
1.
f
)
+
(
1.
f
-
exp
(
1.
f
))
*
(
fov
-
fov_max
)
/
(
360.
-
2
*
fov_max
));
}
fprintf
(
stderr
,
"change fov_max=%f, new scale=%f
\n
"
,
fov_max
,
scale
);
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
);
updateGL
();
}
...
...
@@ -114,7 +121,7 @@ void OpenGLCanvas::change_fov_max(int new_fov_max){
void
OpenGLCanvas
::
change_center_lambda
(
double
lambda
){
if
(
center_lambda
!=
lambda
&&
lambda
>=-
3.14
f
&&
lambda
<=
3.14
f
)
{
if
(
center_lambda
!=
lambda
&&
lambda
>=-
CONST_PI
&&
lambda
<=
CONST_PI
)
{
center_lambda
=
lambda
;
updateGL
();
}
...
...
@@ -123,7 +130,7 @@ void OpenGLCanvas::change_center_lambda(double lambda){
void
OpenGLCanvas
::
change_center_phi
(
double
phi
){
if
(
center_phi
!=
phi
&&
phi
>=-
1.57
f
&&
phi
<=
1.57
f
)
{
if
(
center_phi
!=
phi
&&
phi
>=-
CONST_PI_2
&&
phi
<=
CONST_PI_2
)
{
center_phi
=
phi
;
updateGL
();
}
...
...
@@ -139,8 +146,8 @@ void OpenGLCanvas::re_center(){
void
OpenGLCanvas
::
change_fov_scale_relation
(
QString
name
){
fov_scale_relation
=
name
;
if
(
fov
<
60.
f
)
scale
=
1.
f
;
else
if
(
fov
>
295.
f
)
scale
=
0.01
f
;
if
(
fov
<
fov_max
)
scale
=
1.
f
;
//
else if (fov>295.f) scale = 0.01f;
else
{
if
(
fov_scale_relation
==
"Naive"
)
scale
=
fov_max
/
fov
;
...
...
@@ -278,7 +285,7 @@ void OpenGLCanvas::initializeGL(){
if
(
texCoord
==
NULL
){
printf
(
"problem allocating memory for texture coordinates
\n
"
);
}
define_texture_coordinates
(
texCoord
,
m
,
n
,
-
1.57
f
,
1.57
f
,
-
3.14
f
,
3.14
f
);
define_texture_coordinates
(
texCoord
,
m
,
n
,
-
CONST_PI_2_F
,
CONST_PI_2_F
,
-
CONST_PI_F
,
CONST_PI_F
);
//defining positions of the sphere vertices
int
meshNumVertices
=
m
*
n
;
...
...
@@ -311,8 +318,8 @@ void OpenGLCanvas::define_texture_coordinates(float *texCoord, int m, int n, flo
for
(
int
i
=
0
;
i
<
m
;
i
++
){
for
(
int
j
=
0
;
j
<
n
;
j
++
){
texCoord
[
2
*
(
j
+
i
*
n
)]
=
(
min_lambda
+
delta_lambda
*
j
)
/
(
6.2832
)
+
0.5
;
texCoord
[
2
*
(
j
+
i
*
n
)
+
1
]
=
(
min_phi
+
delta_phi
*
i
)
/
(
3.1416
)
+
0.5
;
texCoord
[
2
*
(
j
+
i
*
n
)]
=
(
min_lambda
+
delta_lambda
*
j
)
/
(
2
*
CONST_PI_F
)
+
0.5
;
texCoord
[
2
*
(
j
+
i
*
n
)
+
1
]
=
(
min_phi
+
delta_phi
*
i
)
/
(
CONST_PI_F
)
+
0.5
;
}
}
...
...
@@ -320,10 +327,10 @@ void OpenGLCanvas::define_texture_coordinates(float *texCoord, int m, int n, flo
void
OpenGLCanvas
::
vertex_transformation
(
float
*
positions
,
int
m
,
int
n
,
float
center_lambda
,
float
center_phi
,
float
fov_rads
,
float
scale
){
float
min_lambda
=
-
3.1415
f
;
float
max_lambda
=
3.1415
f
;
float
min_phi
=
-
1.5708
f
;
float
max_phi
=
1.5708
f
;
float
min_lambda
=
-
CONST_PI_F
;
float
max_lambda
=
CONST_PI_F
;
float
min_phi
=
-
CONST_PI_2_F
;
float
max_phi
=
CONST_PI_2_F
;
float
delta_lambda
=
(
max_lambda
-
min_lambda
)
/
(
1.0
*
(
n
-
1
));
float
delta_phi
=
(
max_phi
-
min_phi
)
/
(
1.0
*
(
m
-
1
));
...
...
@@ -391,8 +398,8 @@ void OpenGLCanvas::vertex_transformation(float *positions, int m, int n, float c
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
)
/
3.1415
;
phi
=
asin
(
y
)
/
1.5708
;
lambda
=
atan2
(
x
,
-
z
)
/
CONST_PI_F
;
phi
=
asin
(
y
)
/
CONST_PI_2_F
;
u
=
x
/
(
-
z
);
v
=
y
/
(
-
z
);
...
...
@@ -422,10 +429,10 @@ void OpenGLCanvas::vertex_transformation(float *positions, int m, int n, float c
void
OpenGLCanvas
::
load_sphere_mesh
(
float
*
positions
,
int
m
,
int
n
){
float
min_lambda
=
-
3.1415
f
;
float
max_lambda
=
3.1415
f
;
float
min_phi
=
-
1.5708
f
;
float
max_phi
=
1.5708
f
;
float
min_lambda
=
-
CONST_PI_F
;
float
max_lambda
=
CONST_PI_F
;
float
min_phi
=
-
CONST_PI_2_F
;
float
max_phi
=
CONST_PI_2_F
;
float
delta_lambda
=
(
max_lambda
-
min_lambda
)
/
(
1.0
*
(
n
-
1
));
float
delta_phi
=
(
max_phi
-
min_phi
)
/
(
1.0
*
(
m
-
1
));
...
...
@@ -454,24 +461,24 @@ void OpenGLCanvas::load_sphere_mesh(float *positions, int m, int n){
float
OpenGLCanvas
::
calculate_extent
(
float
fov_rads
){
float
lambda
,
phi
,
x
,
y
,
z
,
u
,
v
,
r
,
theta
;
double
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
;
phi
=
0.
;
// 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
);
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.
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.
*
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.
);
u
=
x
/
(
-
z
);
v
=
y
/
(
-
z
);
return
u
;
...
...
@@ -670,8 +677,8 @@ void OpenGLCanvas::mouseMoveEvent(QMouseEvent *event){
// scroll with the left button
if
(
event
->
buttons
()
==
Qt
::
LeftButton
){
// compute the delta and move the image
center_lambda
+=
(
event
->
x
()
-
lastPos
.
x
())
*
3.1415926
f
/
image_size_x
;
center_phi
+=
(
event
->
y
()
-
lastPos
.
y
())
*
3.1415926
f
/
image_size_y
;
center_lambda
+=
(
event
->
x
()
-
lastPos
.
x
())
*
CONST_PI_F
/
image_size_x
;
center_phi
+=
(
event
->
y
()
-
lastPos
.
y
())
*
CONST_PI_F
/
image_size_y
;
lastPos
=
event
->
pos
();
updateGL
();
}
...
...
@@ -689,7 +696,7 @@ void OpenGLCanvas::wheelEvent(QWheelEvent *event){
void
OpenGLCanvas
::
paintGL
(){
float
fov_rads
=
(
fov
/
18
0.
f
)
*
1.5708
f
;
float
fov_rads
=
(
fov
/
36
0.
)
*
CONST_PI
;
// // changing scale to generate the figures for the paper (remove it after)
// scale = 0.8;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment