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

4
#include "glincludes.h"
Luis Penaranda's avatar
Luis Penaranda committed
5 6
#include <QGLWidget>
#include <QTimer>
7
#include <QFile>
8
#include <QFileDialog>
Luis Penaranda's avatar
Luis Penaranda committed
9
#include <fcntl.h>
Luis Peñaranda's avatar
Luis Peñaranda committed
10

11
#include "chronos.h"
Luis Penaranda's avatar
Luis Penaranda committed
12

13
#include "image_read.h"
Luis Penaranda's avatar
Luis Penaranda committed
14

15 16 17
class OpenGLCanvas:
        public QGLWidget,
        public FileRead
Luis Peñaranda's avatar
Luis Peñaranda committed
18 19 20 21 22 23
{
    Q_OBJECT
public:
    explicit OpenGLCanvas(QWidget *parent = 0);

protected:
24
    void read_config_file();
25
    void load_image(const char *new_image);
Luis Peñaranda's avatar
Luis Peñaranda committed
26 27 28 29 30 31 32 33
    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);
34

35 36 37
private:
    int compute_auto_fov_max(int);

Luis Peñaranda's avatar
Luis Peñaranda committed
38
    char *textFileRead(char *fn);
39
    void setShaders();
Luis Peñaranda's avatar
Luis Peñaranda committed
40 41
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
42
    void wheelEvent(QWheelEvent *event);
Luis Peñaranda's avatar
Luis Peñaranda committed
43 44 45

signals:
    void fps(QString newFPS);
46
    void fov_changed(int new_fov);
47
    void max_fov_changed(int new_max_fov);
Luis Peñaranda's avatar
Luis Peñaranda committed
48 49

public slots:
50
    void automaxbutton(bool);
Luis Peñaranda's avatar
Luis Peñaranda committed
51
    void change_fov(double f);
52 53
    void change_fov(int new_fov);
    void change_fov_max(int new_fov_max);
Luis Peñaranda's avatar
Luis Peñaranda committed
54 55 56
//    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
57
    void re_center();
Luis Peñaranda's avatar
Luis Peñaranda committed
58 59
    void change_fov_scale_relation(QString name);
    void change_visualization(QString name);
60
    void change_input_image();
Luis Peñaranda's avatar
Luis Peñaranda committed
61 62 63
    void slotTimer();

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

Luis Peñaranda's avatar
Luis Peñaranda committed
66
    double fov;
Luis Peñaranda's avatar
Luis Peñaranda committed
67
    double fov_max; // the \phi_{max} on the technote
Luis Peñaranda's avatar
Luis Peñaranda committed
68 69 70 71 72
    double scale;
    double center_lambda;
    double center_phi;
    QString fov_scale_relation;
    QString visualization;
73
    bool auto_fov_max;
74
    float zblambda,zbR; // parameters of the Zorin-Barr transformation
Luis Peñaranda's avatar
Luis Peñaranda committed
75 76 77 78 79 80 81 82 83 84 85

    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;
86 87
    //float windowWidth;
    //float windowHeight;
88 89 90

    char* shader_dir;
    char* input_image_file;
91
    char* input_image_dir;
Luis Peñaranda's avatar
Luis Peñaranda committed
92

93
    // input image size
Luis Peñaranda's avatar
Luis Peñaranda committed
94 95 96 97
    int image_size_x;
    int image_size_y;

    QPoint lastPos; // mouse click position
Luis Peñaranda's avatar
Luis Peñaranda committed
98 99 100
};

#endif // OPENGLCANVAS_H