forked from foxsi/foxsigse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainHistogram.cxx
executable file
·224 lines (185 loc) · 5.76 KB
/
mainHistogram.cxx
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#include "mainHistogram.h"
#include "gui.h"
#include <math.h>
#define XSTRIPS 128
#define YSTRIPS 128
#define TICKLENGTH 3
#define YNUMTICKS 10
#define XTICKINTERVAL 5
#define XTICKINTERVALM 10
#define NUM_DETECTORS 7
#define XMIN 1
#define MAX_CHANNEL 1024
int HistogramFunction[MAX_CHANNEL];
extern double displayHistogram[MAX_CHANNEL];
int chosenHistPixel;
int mouseHistPixel;
int low_threshold = 0;
int mainHistogram_binsize = 25;
float FLHistcursorX[2], FLHistcursorY[2];
float YTICKINTERVAL;
float YTICKINTERVALM;
extern Gui *gui;
mainHistogram::mainHistogram(int x,int y,int w,int h,const char *l)
: Fl_Gl_Window(x,y,w,h,l)
{
ymax = 1024;
ymin = 0;
xmax = MAX_CHANNEL;
xmin = 0;
/* initialize random seed: */
//srand ( time(NULL) );
//initialize the histogram
for(int i=0; i < MAX_CHANNEL; i++)
{
HistogramFunction[i] = i*1;
displayHistogram[i] = HistogramFunction[i];
}
FLHistcursorX[0] = 500;
mouseHistPixel = FLHistcursorX[0];
}
void mainHistogram::draw()
{
// the drawing method: draws the histFunc into the window
int y = 0;
int k = 0;
ymax = maximumValue(displayHistogram, MAX_CHANNEL/mainHistogram_binsize);
xmax = MAX_CHANNEL/mainHistogram_binsize;
YTICKINTERVALM = (ymax-ymin)/YNUMTICKS;
YTICKINTERVAL = YTICKINTERVALM/2;
if (!valid()) {
make_current();
}
//The following line causes the display to not refresh after being moved
//gui->mainChartWindow->bounds(0.0, ymax);
//float FL_Yconv = (float) (MAX_CHANNEL)/(ymax - ymin);
//float FL_Xconv = (float) (MAX_CHANNEL)/(MAX_CHANNEL*mainHistogram_binsize- 0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0,0,w(),h());
gluOrtho2D(0,MAX_CHANNEL/mainHistogram_binsize, 0, ymax);
glMatrixMode(GL_MODELVIEW);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPushMatrix();
glLoadIdentity();
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
//draw the graph
glBegin(GL_LINES);
glColor3f(1.0, 0.0, 0.0);
// recalculate the displayed histogram (rebinned)
for(int i = 0; i < MAX_CHANNEL; i+=mainHistogram_binsize)
{
y = 0;
for (int j = 0; j < mainHistogram_binsize; j++) {
y += HistogramFunction[i+j];}
displayHistogram[k] = y;
k++;
}
for(int i = 0; i < MAX_CHANNEL/mainHistogram_binsize; i++)
{
glVertex2f(i, displayHistogram[i]);
glVertex2f(i+1, displayHistogram[i]);
glVertex2f(i+0.5, displayHistogram[i] - sqrt(displayHistogram[i]));
glVertex2f(i+0.5, displayHistogram[i] + sqrt(displayHistogram[i]));
}
//glVertex2f(MAX_CHANNEL+XBORDER, YBORDER);
//glVertex2f(XBORDER, YBORDER);
glEnd();
// draw vertival select line from mouse click
glBegin(GL_LINES);
glColor3f(0.0, 1.0, 0.0);
glVertex2f(FLHistcursorX[0]+0.5, 0);
glVertex2f(FLHistcursorX[0]+0.5, ymax);
glEnd();
// draw the line showing the low energy cutoff
glColor4f(0.0, 0.0, 1.0, 0.5);
glRectf(0, 0, (int) low_threshold/mainHistogram_binsize, ymax);
glBegin(GL_LINES);
glColor3f(0.0, 0.0, 1.0);
glVertex2f((int) low_threshold/mainHistogram_binsize, 0);
glVertex2f((int) low_threshold/mainHistogram_binsize, ymax);
glEnd();
glPopMatrix();
glFinish();
//update the axis labels
gui->mainHistogramYlabelmax->value(ymax);
gui->mainHistogramYlabelmid->value(ymax/2.0);
gui->histCounts->value(displayHistogram[mouseHistPixel]);
//Should not make this update everytime
//gui->mainHistogramXlabelmid->value(xmid);
//gui->mainHistogramXlabelmax->value(xmax);
//if(gui->mainHistogramLockbut->value() == 0)
// {
// //now update the text box with the current chosen pixel
// sprintf( text, "%d", mouseHistPixel);
// gui->histEnergy->value(text);
//
// sprintf( text, "%d", HistogramFunction[mouseHistPixel]);
// gui->histCounts->value(text);
// } else
// {
// sprintf( text, "%d", HistogramFunction[chosenHistPixel]);
// gui->histCounts->value(text);
// }
}
int mainHistogram::handle(int eventType)
{
char text[8];
int button;
button=Fl::event_button();
if(eventType == FL_PUSH)
{
//convert between fltk coordinates and opengl coordinates
FLHistcursorX[0] = floor(Fl::event_x()*(xmax)/w());
FLHistcursorY[0] = floor((h()-Fl::event_y())*(ymax)/h());
mouseHistPixel = FLHistcursorX[0];
}
// now update the value displayed
gui->histEnergy->value(mouseHistPixel);
gui->histCounts->value(displayHistogram[mouseHistPixel]);
redraw();
//if((eventType==FL_PUSH)&&(button==1))
//{
// // FLHistcursorX[1]=FLHistcursorX[0];
// // FLHistcursorY[1]=FLHistcursorY[0];
// // gui->mainHistogramLockbut->set();
// //}
// //if((eventType==FL_PUSH)&&(button==2))
// //{
// // FLHistcursorX[1]=0;
// // FLHistcursorY[1]=0;
// //}
//
// //if(gui->mainHistogramLockbut->value() == 0){chosenHistPixel = FLHistcursorX[1] - XBORDER;}
//
// //if(gui->mainHistogramLockbut->value() == 0){gui->mainHistogramWindow->redraw();}
// //redraw();
//
return(1);
}
//void mainHistogram::glPrint(float x, float y, char *string )
//{
// int len, i;
// glRasterPos2f(x, y);
// //find the length of the string
// len = (int) strlen(string);
// //print each character individually
// for ( i = 0; i < len; i++){ glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, string[i]);
// }
//}
float mainHistogram::maximumValue(double *array, int size)
{
//float length = sizeof(array)/sizeof(array[0]); // establish size of array
//cout << "size of array " << length << endl;
//do not consider below xmin
float max = array[0]; // start with max = first element
for(int i = 1; i < size; i++)
{
if(array[i] > max){
max = array[i];}
}
return max; // return highest value in array
}