-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHist3d.pde
123 lines (102 loc) · 2.18 KB
/
Hist3d.pde
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
import peasy.*;
public class Hist3d extends Frame {
private Hist3dApplet histApp;
private Frame hist3dFrame;
private PImage img;
private boolean autorotate = true;
private PeasyCam cam;
public Hist3d() {
hist3dFrame = this;
setBounds(screen.width/2,100,512,512);
histApp = new Hist3dApplet();
add(histApp);
histApp.init();
show();
setResizable(false);
setTitle("Hist3d");
}
void setImage(PImage i) {
img = i;
}
void setAutorotate(boolean b) {
autorotate = b;
}
boolean getAutorotate() {
return autorotate;
}
class Hist3dApplet extends PApplet {
public void setup() {
size(512, 512, P3D);
PFont myFont = createFont(PFont.list()[0], 64);
textFont(myFont);
textSize(18);
cam = new PeasyCam(this, 500);
cam.setMinimumDistance(200);
cam.setMaximumDistance(700);
cam.rotateX(PI);
cam.rotateY(.5);
cam.setState(cam.getState());
}
public void draw() {
if(autorotate)
cam.rotateY(.002);
background(255);
smooth();
noFill();
stroke(128);
box(256);
translate(-128,-128,-128);
noSmooth();
drawAxes();
drawAxes();
drawPoints(img);
}
// draw 3D RGB histogram with Points
void drawPoints(PImage img) {
if(img != null && img.pixels != null)
for(color c : img.pixels) {
stroke(c);
point(red(c), green(c), blue(c));
}
}
void drawAxes() {
float[] rot = cam.getRotations();
pushMatrix();
translate(-10,-10,-10);
rotateX(rot[0]);
rotateY(rot[1]);
rotateZ(rot[2]);
fill(0);
textAlign(CENTER);
text("O",0,0,0);
popMatrix();
pushMatrix();
translate(265,-10,-10);
rotateX(rot[0]);
rotateY(rot[1]);
rotateZ(rot[2]);
fill(255,0,0);
textAlign(CENTER);
text("R",0,0,0);
popMatrix();
pushMatrix();
translate(-10,265,-10);
rotateX(rot[0]);
rotateY(rot[1]);
rotateZ(rot[2]);
fill(0,255,0);
textAlign(CENTER);
text("G",0,0,0);
popMatrix();
pushMatrix();
translate(-10,-10,265);
rotateX(rot[0]);
rotateY(rot[1]);
rotateZ(rot[2]);
fill(0,0,255);
textAlign(CENTER);
text("B",0,0,0);
popMatrix();
}
}
}