openglcanvas.h 3.47 KB
Newer Older
Luis Peñaranda's avatar
Luis Peñaranda committed
1
2
3
#ifndef OPENGLCANVAS_H
#define OPENGLCANVAS_H

Luis Peñaranda's avatar
Luis Peñaranda committed
4
5
6
7
// GLew might not be needed on mac, or if a recent version of OpenGL is present
#ifndef __APPLE__
  #include <GL/glew.h>
  #if (!defined GLEW_VERSION_1_5) || (!defined GL_VERSION_3_1)
Luis Penaranda's avatar
Luis Penaranda committed
8
    #error GLEW 1.5.2 is required
Luis Peñaranda's avatar
Luis Peñaranda committed
9
  #endif
10
11
#endif

Luis Peñaranda's avatar
Luis Peñaranda committed
12
#define GL_GLEXT_PROTOTYPES 1
13
14
15
16
17
18
#ifdef __APPLE__
  #include<OpenGL/gl.h>
  #include<OpenGL/glu.h>
  #include<Glut/glut.h>
  #include<OpenGL/glext.h>
#else
19
20
  //#include <GL/gl.h>
  //#include <GL/glu.h>
21
  #include <GL/glut.h>
22
23
  // is glext really needed?
  //#include <GL/glext.h>
24
25
#endif

Luis Penaranda's avatar
Luis Penaranda committed
26
27
#include <QGLWidget>
#include <QTimer>
28
#include <QFile>
29
#include <QFileDialog>
Luis Penaranda's avatar
Luis Penaranda committed
30
#include <fcntl.h>
31
32
33
34
35
#ifdef _WIN32
  #include <io.h>
#else
  #include <unistd.h>   // for getcwd, getpwuid, getuid
#endif
Luis Penaranda's avatar
Luis Penaranda committed
36
37
38
39
40
41
42
#include "chronos.h"

extern "C" {
#include <ppm.h>
#include <pm.h>
#include <pam.h>
}
Luis Peñaranda's avatar
Luis Peñaranda committed
43

Luis Penaranda's avatar
Luis Penaranda committed
44
45
46
47
48
49
50
51
#include <jpeglib.h>

enum FileType{
    PNM,
    JPEG,
    UNKNOWN
};

Luis Peñaranda's avatar
Luis Peñaranda committed
52
53
54
55
56
57
58
class OpenGLCanvas : public QGLWidget
{
    Q_OBJECT
public:
    explicit OpenGLCanvas(QWidget *parent = 0);

protected:
59
    void read_config_file();
60
    void load_image(const char *new_image);
Luis Peñaranda's avatar
Luis Peñaranda committed
61
62
63
64
65
66
67
68
    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);
Luis Penaranda's avatar
Luis Penaranda committed
69
70
71
72
    int pnmGetTextureSize(const char *const progname, const char *texturePath);
    void pnmReadTextureBytes(const char *const progname, const char *texturePath,unsigned char *textureBytes,int *outImageWidth,int *outImageHeight);
    int jpgGetTextureSize(const char *texturePath);
    void jpgReadTextureBytes(const char *texturePath,unsigned char *textureBytes,int *outImageWidth,int *outImageHeight);
Luis Peñaranda's avatar
Luis Peñaranda committed
73
    char *textFileRead(char *fn);
74
    void setShaders();
Luis Peñaranda's avatar
Luis Peñaranda committed
75
76
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
77
    void wheelEvent(QWheelEvent *event);
Luis Peñaranda's avatar
Luis Peñaranda committed
78
79
80

signals:
    void fps(QString newFPS);
81
    void fov_changed(int new_fov);
82
    void max_fov_changed(int new_max_fov);
Luis Peñaranda's avatar
Luis Peñaranda committed
83
84
85

public slots:
    void change_fov(double f);
86
87
    void change_fov(int new_fov);
    void change_fov_max(int new_fov_max);
Luis Peñaranda's avatar
Luis Peñaranda committed
88
89
90
//    void change_scale(double s);
    void change_center_lambda(double lambda);
    void change_center_phi(double phi);
Luis Peñaranda's avatar
Luis Peñaranda committed
91
    void re_center();
Luis Peñaranda's avatar
Luis Peñaranda committed
92
93
    void change_fov_scale_relation(QString name);
    void change_visualization(QString name);
94
    void change_input_image();
Luis Peñaranda's avatar
Luis Peñaranda committed
95
96
97
    void slotTimer();

private:
Luis Penaranda's avatar
Luis Penaranda committed
98
99
    enum FileType get_file_type(const char*);

Luis Peñaranda's avatar
Luis Peñaranda committed
100
    double fov;
Luis Peñaranda's avatar
Luis Peñaranda committed
101
    double fov_max; // the \phi_{max} on the technote
Luis Peñaranda's avatar
Luis Peñaranda committed
102
103
104
105
106
    double scale;
    double center_lambda;
    double center_phi;
    QString fov_scale_relation;
    QString visualization;
107
    bool auto_fov_max;
Luis Peñaranda's avatar
Luis Peñaranda committed
108
109
110
111
112
113
114
115
116
117
118

    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;
119
120
    //float windowWidth;
    //float windowHeight;
121
122
123

    char* shader_dir;
    char* input_image_file;
Luis Peñaranda's avatar
Luis Peñaranda committed
124
125
126
127
128
129

    // input image size (determined automatically)
    int image_size_x;
    int image_size_y;

    QPoint lastPos; // mouse click position
Luis Peñaranda's avatar
Luis Peñaranda committed
130
131
132
};

#endif // OPENGLCANVAS_H