-
Notifications
You must be signed in to change notification settings - Fork 0
/
Visualixer.hpp
169 lines (130 loc) · 5.09 KB
/
Visualixer.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#ifndef _VISUALIXER_H
#define _VISUALIXER_H
#include "ColorRamp.hpp"
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#define GLM_FORCE_RADIANS
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/gtx/fast_trigonometry.hpp>
#include <glm/gtx/fast_exponential.hpp>
#include <glm/gtx/rotate_vector.hpp>
//#include <glm/transform.hpp>
#define DEFAULT_WIDTH 800
#define DEFAULT_HEIGHT 600
#define DEFAULT_CENTER_X 0
#define DEFAULT_CENTER_Y 0
#define VX_PI 3.14159265358979323846264338327950288
// this contains definitions for the openGL visualizer widget
//
// the visualizer should be able to:
// - visualize flow in 2d and 3d and move around in it
// - visualize the geometry in 2d and 3d and move around in it
// - visualize parametric or mesh CAD models and move around
// - visualize and interact with point clouds
//************** base visualixer class *********************
class visualixer{
public:
visualixer();
virtual ~visualixer();
// getters and setters
virtual std::string get_window_name() {return window_name;};
virtual void set_window_name(std::string w_name);
virtual void set_color_ramp(CRamp ramp_name);
//template <class T> void set_colorby(const T * color_by);
template <class T>
void set_colorby(T const * color_by){
if (color_by == NULL){
std::cout << "SHIT THE COLORBY INPUT IS NULL" << std::endl;
return;
}
if (colorby == NULL) colorby = new double[num_vertices];
for (unsigned int i=0; i<num_vertices; i++) colorby[i] = double(color_by[i]);
std::cout << "converted all to double" << std::endl;
// find the min of the incoming values
colorby_max = colorby[0]; colorby_min = colorby[0];
for (auto i=1; i<num_vertices; i++){
if (colorby[i] > colorby_max) colorby_max = colorby[i];
if (colorby[i] < colorby_min) colorby_min = colorby[i];
}
std::cout << "found the min and max" << std::endl;
// subtract out the min value
for (auto i=0; i<num_vertices; i++) colorby[i] = color_by[i]-colorby_min;
std::cout << "subtracted out the min value" << std::endl;
return;
}
//virtual void set_custom_colors(rgb * colors);
//void set_lock_rotation(bool lock_mode);
virtual void set_test_case();
// running the visualixer
virtual void run();
protected:
// model related data
GLFWwindow * window_ptr;
std::string window_name;
GLfloat * vertices;
GLuint * elements;
ColorRamp color_ramp;
double * colorby; // one per vertex
double colorby_max, colorby_min;
float model_centroid[3]; // from [model_min, model_max]
float xmin, xmax, ymin, ymax, zmin, zmax;
unsigned int num_vertices, num_per_vertex, num_vertex_points;
unsigned int num_elements, num_per_element; // number of triangles that may share vertices
// shaders and buffer objects
GLuint ebo, vbo, vao;
GLuint vertexShader, fragmentShader, shaderProgram;
GLint uniModel, uniView, uniProj;
// visualizer user viewing data
glm::mat4 model, view, proj;
glm::vec3 eye_vec, focus_vec, up_vec;
glm::vec3 new_eye, new_focus;
glm::vec3 camera_side, camera_up;
float rotdeg, zoom_level, zoom_scale, eyez_init;
// status data
bool left_mouse_engaged; // is the left mouse button clicked?
bool middle_mouse_engaged; // is the middle mouse button clicked?
bool right_mouse_engaged; // is the right mouse button clicked?
double x_upon_click, y_upon_click; // and and y positions of mouse upon click
bool visualixer_active; // is the window currently drawn?
bool rotation_lock; // lock mouse rotations?
bool pan_lock; // lock mouse panning
// base callbacks to interface with GLFW
virtual void onMouseClick(int button, int action, int modifiers);
virtual void onMouseWheel(double xoffset, double yoffset);
virtual void onKeyboard(int key, int scancode, int action, int modifiers);
virtual void onCursorPosition(double xpos, double ypos);
// derived callbacks defined by me
virtual void onMouseLeftDrag(double xpos, double ypos);
virtual void onMouseRightDrag(double xpos, double ypos);
virtual void onMouseMiddleDrag(double xpos, double ypos);
virtual void onKeyDown(unsigned char key, int x, int y);
virtual void onKeyUp(unsigned char key, int x, int y);
virtual void onReshape(int new_width, int new_height);
virtual void SetFullscreen(bool bFullscreen);
virtual void recalcCamera();
virtual void cycleColorRamp();
// functions related to the context creation and main loop rendering
virtual const GLchar * VertexShaderSource();
virtual const GLchar * FragmentShaderSource();
virtual void onInit();
virtual void onColors();
virtual void onRender();
virtual void onShaders();
virtual bool MainLoop();
virtual void onExit();
private:
// base callbacks for GLFW functions
static void sMouseClick(GLFWwindow * window, int button, int action, int modifiers);
static void sMouseWheel(GLFWwindow * window, double xoffset, double yoffset);
static void sKeyboard(GLFWwindow * window, int key, int scancode, int action, int modifiers);
static void sCursorPosition(GLFWwindow * window, double xpos, double ypos);
};
#endif