Commit 57233cc4 authored by Luis Peñaranda's avatar Luis Peñaranda

initial commit

parents
This diff is collapsed.
This diff is collapsed.
#ifdef _WIN32
#include <windows.h>
#else
#include <ctime>
#include <sys/time.h>
#endif
#include "chronos.h"
Chronos::
Chronos() {
reset();
}
void
Chronos::
reset(void) {
m_reset = time();
}
double
Chronos::
elapsed(void) {
return time() - m_reset;
}
double
Chronos::time(void) {
#ifdef _WIN32
LARGE_INTEGER counter, freq;
QueryPerformanceCounter(&counter);
QueryPerformanceFrequency(&freq);
return (1.0*counter.QuadPart)/(1.0*freq.QuadPart);
#else
struct timeval v;
gettimeofday(&v, (struct timezone *) NULL);
return v.tv_sec + v.tv_usec/1.0e6;
#endif
}
#ifndef CHRONOS_H
#define CHRONOS_H
class Chronos {
public:
Chronos();
void reset(void);
double elapsed(void);
double time(void);
private:
double m_reset;
};
#endif // CHRONOS_H
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#include <QtGui/QApplication>
#include "panowindow1.h"
#include "openglcanvas.h"
#include <QMainWindow>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
PanoWindow1 w;
OpenGLCanvas canvas;
// QObject::connect(&canvas, SIGNAL(fps(QString)), w.statusBar(), SLOT(showMessage(QString)));
w.show();
return a.exec();
}
This diff is collapsed.
#ifndef OPENGLCANVAS_H
#define OPENGLCANVAS_H
#include <QGLWidget>
#include <fcntl.h>
#include <unistd.h>
#include "chronos.h"
#include <QTimer>
extern "C" {
#include <ppm.h>
#include <pm.h>
#include <pam.h>
}
#define GL_GLEXT_PROTOTYPES 1
#include<OpenGL/gl.h>
#include<OpenGL/glu.h>
#include<Glut/glut.h>
#include<OpenGL/glext.h>
class OpenGLCanvas : public QGLWidget
{
Q_OBJECT
public:
explicit OpenGLCanvas(QWidget *parent = 0);
protected:
void initializeGL();
void resizeGL(int w, int h);
void paintGL();
void define_texture_coordinates(float *texCoord, int m, int n, float min_phi, float max_phi, float min_lambda, float max_lambda);
void vertex_transformation(float *positions, int m, int n, float center_lambda, float center_phi, float fov_rads, float scale);
void load_sphere_mesh(float *positions, int m, int n);
float calculate_extent(float fov_rads);
void define_triangle_indices(unsigned int * indices, int m, int n);
int getTextureSize(const char * const progname, const char * texturePath);
void readTextureBytes(const char * const progname, const char * texturePath,unsigned char * textureBytes,int * outImageWidth, int * outImageHeight);
char *textFileRead(char *fn);
void setShaders(void);
signals:
void fps(QString newFPS);
public slots:
void change_fov(double f);
// void change_scale(double s);
void change_center_lambda(double lambda);
void change_center_phi(double phi);
void change_fov_scale_relation(QString name);
void change_visualization(QString name);
void slotTimer();
private:
double fov;
double scale;
double center_lambda;
double center_phi;
QString fov_scale_relation;
QString visualization;
Chronos time_time;
QTimer time_timer;
int time_frames;
double time_start;
double time_fps;
unsigned int numberOfIndices;
unsigned int * triangleIndices;
float * verticesPositions;
float * textureCoordinates;
float windowWidth;
float windowHeight;
};
#endif // OPENGLCANVAS_H
#-------------------------------------------------
#
# Project created by QtCreator 2012-06-06T09:22:08
#
#-------------------------------------------------
QT += core gui opengl
#mac-os {
LIBS += -L/opt/local/lib
LIBS += -lpng -lpnm
LIBS += -framework Carbon -framework OpenGL -framework GLUT
INCLUDEPATH += /opt/local/include/netpbm/ \
/opt/local/include/
#}
#linux-g++-64 {
#LIBS += -lm -lpng -lpetsc -lglut -lGL -lnetpbm
#SOURCES += GLee.c
#HEADERS += GLee.h
#DEFINES += NEEDGLEE
#}
TARGET = pano_interface_1
TEMPLATE = app
SOURCES += main.cpp\
panowindow1.cpp \
openglcanvas.cpp \
chronos.cpp
HEADERS += panowindow1.h \
openglcanvas.h \
chronos.h
FORMS += panowindow1.ui
This diff is collapsed.
#include "panowindow1.h"
#include "ui_panowindow1.h"
PanoWindow1::PanoWindow1(QWidget *parent) :
QWidget(parent),
ui(new Ui::PanoWindow1)
{
ui->setupUi(this);
}
PanoWindow1::~PanoWindow1()
{
delete ui;
}
#ifndef PANOWINDOW1_H
#define PANOWINDOW1_H
#include <QWidget>
namespace Ui {
class PanoWindow1;
}
class PanoWindow1 : public QWidget
{
Q_OBJECT
public:
explicit PanoWindow1(QWidget *parent = 0);
~PanoWindow1();
private:
Ui::PanoWindow1 *ui;
};
#endif // PANOWINDOW1_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PanoWindow1</class>
<widget class="QWidget" name="PanoWindow1">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>650</width>
<height>500</height>
</rect>
</property>
<property name="windowTitle">
<string>PanoWindow1</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" rowspan="10">
<widget class="OpenGLCanvas" name="GLCanvas" native="true"/>
</item>
<item row="0" column="1" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>FOV-Scale Relation</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="comboBox">
<property name="editable">
<bool>false</bool>
</property>
<property name="modelColumn">
<number>0</number>
</property>
<item>
<property name="text">
<string>Square Root</string>
</property>
</item>
<item>
<property name="text">
<string>Linear</string>
</property>
</item>
<item>
<property name="text">
<string>Square Power</string>
</property>
</item>
<item>
<property name="text">
<string>Cubic Power</string>
</property>
</item>
<item>
<property name="text">
<string>Logarithm</string>
</property>
</item>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Visualization</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="QComboBox" name="comboBox_2">
<item>
<property name="text">
<string>Perspective</string>
</property>
</item>
<item>
<property name="text">
<string>3D Sphere</string>
</property>
</item>
<item>
<property name="text">
<string>Equi-Rectangular</string>
</property>
</item>
</widget>
</item>
<item row="4" column="1" colspan="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Field of View</string>
</property>
</widget>
</item>
<item row="5" column="1" colspan="2">
<widget class="QDoubleSpinBox" name="doubleSpinBox">
<property name="minimum">
<double>1.000000000000000</double>
</property>
<property name="maximum">
<double>360.000000000000000</double>
</property>
<property name="singleStep">
<double>2.000000000000000</double>
</property>
<property name="value">
<double>60.000000000000000</double>
</property>
</widget>
</item>
<item row="6" column="1" colspan="2">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Center Point</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBox_3">
<property name="maximumSize">
<size>
<width>61</width>
<height>25</height>
</size>
</property>
<property name="minimum">
<double>-3.140000000000000</double>
</property>
<property name="maximum">
<double>3.140000000000000</double>
</property>
<property name="singleStep">
<double>0.010000000000000</double>
</property>
</widget>
</item>
<item row="7" column="2">
<widget class="QDoubleSpinBox" name="doubleSpinBox_4">
<property name="maximumSize">
<size>
<width>61</width>
<height>25</height>
</size>
</property>
<property name="minimum">
<double>-1.570000000000000</double>
</property>
<property name="maximum">
<double>1.570000000000000</double>
</property>
<property name="singleStep">
<double>0.010000000000000</double>
</property>
</widget>
</item>
<item row="8" column="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>145</height>
</size>
</property>
</spacer>
</item>
<item row="9" column="1" colspan="2">
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>OpenGLCanvas</class>
<extends>QWidget</extends>
<header>openglcanvas.h</header>
<container>1</container>
<slots>
<slot>change_fov(double)</slot>
<slot>change_scale(double)</slot>
<slot>change_center_lambda(double)</slot>
<slot>change_center_phi(double)</slot>
<slot>change_fov_scale_relation(QString)</slot>
<slot>change_visualization(QString)</slot>
</slots>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>pushButton</sender>
<signal>clicked()</signal>
<receiver>PanoWindow1</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>596</x>
<y>409</y>
</hint>
<hint type="destinationlabel">
<x>629</x>
<y>364</y>
</hint>
</hints>
</connection>
<connection>
<sender>doubleSpinBox</sender>
<signal>valueChanged(double)</signal>
<receiver>GLCanvas</receiver>
<slot>change_fov(double)</slot>
<hints>
<hint type="sourcelabel">
<x>592</x>
<y>174</y>
</hint>
<hint type="destinationlabel">
<x>507</x>
<y>252</y>
</hint>
</hints>
</connection>
<connection>
<sender>doubleSpinBox_3</sender>
<signal>valueChanged(double)</signal>
<receiver>GLCanvas</receiver>
<slot>change_center_lambda(double)</slot>
<hints>
<hint type="sourcelabel">
<x>536</x>
<y>230</y>
</hint>
<hint type="destinationlabel">
<x>506</x>
<y>297</y>
</hint>
</hints>
</connection>
<connection>
<sender>doubleSpinBox_4</sender>
<signal>valueChanged(double)</signal>
<receiver>GLCanvas</receiver>
<slot>change_center_phi(double)</slot>
<hints>
<hint type="sourcelabel">
<x>605</x>
<y>227</y>
</hint>
<hint type="destinationlabel">
<x>506</x>
<y>320</y>
</hint>
</hints>
</connection>
<connection>
<sender>comboBox</sender>
<signal>activated(QString)</signal>
<receiver>GLCanvas</receiver>
<slot>change_fov_scale_relation(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>603</x>
<y>50</y>
</hint>
<hint type="destinationlabel">
<x>492</x>
<y>77</y>
</hint>
</hints>
</connection>
<connection>
<sender>comboBox_2</sender>
<signal>activated(QString)</signal>
<receiver>GLCanvas</receiver>
<slot>change_visualization(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>554</x>
<y>106</y>
</hint>
<hint type="destinationlabel">
<x>496</x>
<y>123</y>
</hint>
</hints>
</connection>
</connections>
</ui>
uniform sampler2D diffuse_texture;
varying vec2 texcoord0;
varying vec4 K_color;
varying float r, theta, s;
void main() {
gl_FragColor = texture2D(diffuse_texture, texcoord0);
// gl_FragColor = 0.1*texture2D(diffuse_texture, texcoord0) + s;
// gl_FragColor = 0.1*texture2D(diffuse_texture, texcoord0) + theta/6.28+0.5;
}
varying vec2 texcoord0;
vec4 pos;
float u, v, x, y, z;
varying float r, theta, s;
float lambda, phi;
float extent, scale, vis_mode, center_lambda, center_phi;
void main(void){
texcoord0 = vec2(gl_MultiTexCoord0);
pos = gl_Vertex;
// getting paramters from the interface
extent = gl_ProjectionMatrix[0].x;
scale = gl_ProjectionMatrix[1].y;
vis_mode = gl_ProjectionMatrix[2].z;
center_lambda = gl_ModelViewMatrix[0].x;
center_phi = gl_ModelViewMatrix[1].y;
x = pos.x;
y = pos.y;
z = pos.z;
//Rotation 1: (-center_lambda)-rotation on the xz-plane
float x_copy = x;
x = cos(-center_lambda)*x - sin(-center_lambda)*z;
y = 1.0*y;
z = sin(-center_lambda)*x_copy + cos(-center_lambda)*z;
//Rotation 2: (-center_phi)-rotation on the yz-plane
float y_copy = y;
x = 1.0*x;
y = cos(-center_phi)*y - sin(-center_phi)*z;
z = sin(-center_phi)*y_copy + cos(-center_phi)*z;
// stereographic projection
u = 2.0*x/(-z+1.0);
v = 2.0*y/(-z+1.0);
// from cartesian to polar coordinates
r = sqrt(u*u+v*v);
theta = atan(u,v);
// scaling the complex plane according to scale specified in the interface
r *= scale;
// mapping from polar coordinates to cartesian coordinates
u = -r*sin(theta);
v = r*cos(theta);
// mapping back from the complex plane to the unit sphere
x = (4.0*u)/(u*u+v*v+4.0);
y = (4.0*v)/(u*u+v*v+4.0);
z = (u*u+v*v-4.0)/(u*u+v*v+4.0);
// mapping back to the equirectangular domain
lambda = atan(x,-z)/3.1415;
phi = asin(y)/1.5708;
// perspective projection
u = x/(-z);
v = y/(-z);
// Visualize using specified visualization (remove for timings in the paper! Use only "Perspective" in the paper!)
if (vis_mode==1.0) 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);
// gl_Position = vec4(u/2.0,v/2.0,z,1.0);
}
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