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
|
#ifndef VORONOISPLAT_H
#define VORONOISPLAT_H
#include <memory>
#include <armadillo>
#include <glad/gl.h>
#include <nod.hpp>
#include "colorscale.h"
#include "geometry.h"
#include "scale.h"
#include "shader.h"
class VoronoiSplat
{
public:
VoronoiSplat();
~VoronoiSplat();
// Renderer *createRenderer() const;
void update();
void draw();
const std::vector<vec2> &sites() const { return m_sites; }
const std::vector<float> &values() const { return m_values; }
const std::vector<float> &colorScale() const { return m_cmap; }
LinearScale<float> scaleX() const { return m_sx; }
LinearScale<float> scaleY() const { return m_sy; }
float alpha() const { return m_alpha; }
float beta() const { return m_beta; }
size_t width() const { return m_width; }
size_t height() const { return m_height; }
GLuint texture() { return m_outTex; }
void setSitesChanged(bool sitesChanged) {
m_sitesChanged = sitesChanged;
}
void setValuesChanged(bool valuesChanged) {
m_valuesChanged = valuesChanged;
}
void setColorScaleChanged(bool colorScaleChanged) {
m_colorScaleChanged = colorScaleChanged;
}
nod::signal<void(const arma::mat &)> sitesChanged;
nod::signal<void(const arma::vec &)> valuesChanged;
nod::signal<void(GLuint)> colormapChanged;
nod::signal<void(const LinearScale<float> &, const LinearScale<float> &)> scaleChanged;
nod::signal<void(float)> alphaChanged, betaChanged;
void setSize(size_t width, size_t height);
// 'points' should be a 2D points matrix (each point in a row)
void setSites(const arma::mat &points);
// Set the value to be colorScaleped in each site
void setValues(const arma::vec &values);
// Set colormap texture used for color lookup in rendering
void setColormap(GLuint texture);
void setScale(const LinearScale<float> &sx,
const LinearScale<float> &sy);
// Shepard blur radius
void setAlpha(float alpha);
// Maximum blur radius
void setBeta(float beta);
void setupShaders();
void setupVAOs();
void setupTextures();
void resizeTextures();
void updateSites();
void updateValues();
void updateColormap();
void updateTransform();
private:
std::unique_ptr<Shader> m_program1, m_program2, m_programVoronoi;
GLuint m_dtVAO, m_sitesVAO, m_2ndPassVAO, m_voronoiVAO;
GLfloat m_transform[4][4];
GLuint m_FBO, m_voronoiFBO, m_preFBO;
GLuint m_VBOs[3], m_dtVBO;
GLuint m_textures[2], m_colormapTex, m_voronoiDepthTex, m_outTex;
float m_alpha, m_beta;
size_t m_width, m_height;
std::vector<vec2> m_sites;
std::vector<float> m_values, m_cmap;
LinearScale<float> m_sx, m_sy;
bool m_sitesChanged, m_valuesChanged, m_colorScaleChanged, m_redraw;
};
#endif // VORONOISPLAT_H
|