-
Notifications
You must be signed in to change notification settings - Fork 10
/
profile_widget.cpp
442 lines (384 loc) · 14.7 KB
/
profile_widget.cpp
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
#include "profile_widget.h"
#include "settings.h"
/* #define QDEBUG */
profile_widget::profile_widget(frameWorker *fw, image_t image_type, QWidget *parent) :
QWidget(parent)
{
/*! \brief Establishes a plot for a specified image type.
* \param image_type Determines the type of graph that will be output by profile_widget
* \author Jackie Ryan
* \author Noah Levy */
itype = image_type;
qcp = NULL;
this->fw = fw;
options = fw->getStartupOptions();
ceiling = fw->base_ceiling;
floor = 0;
frHeight = fw->getFrameHeight();
frWidth = fw->getFrameWidth();
x_coord = -1;
y_coord = -1;
qcp = new QCustomPlot(this);
qcp->addLayer("Plot Layer");
qcp->setCurrentLayer("Plot Layer");
qcp->setNotAntialiasedElement(QCP::aeAll);
qcp->plotLayout()->insertRow(0);
plotTitle = new QCPPlotTitle(qcp);
qcp->plotLayout()->addElement(0, 0, plotTitle);
qcp->addGraph();
// Vertical LH Overlay:
qcp->addGraph();
qcp->graph(1)->setPen(QPen(Qt::green));
// Vertical RH Overlay:
qcp->addGraph();
qcp->graph(2)->setPen(QPen(Qt::red));
if (itype == VERTICAL_MEAN || itype == VERTICAL_CROSS || itype == VERT_OVERLAY) {
xAxisMax = frHeight;
qcp->xAxis->setLabel("Y index");
} else if (itype == HORIZONTAL_MEAN || itype == HORIZONTAL_CROSS) {
xAxisMax = frWidth;
qcp->xAxis->setLabel("X index");
}
x = QVector<double>(xAxisMax);
for (int i = 0; i < xAxisMax; i++)
x[i] = double(i);
y = QVector<double>(xAxisMax);
y_lh = QVector<double>(xAxisMax);
y_rh = QVector<double>(xAxisMax);
qcp->xAxis->setRange(QCPRange(0, xAxisMax));
qcp->addLayer("Box Layer", qcp->currentLayer());
qcp->setCurrentLayer("Box Layer");
callout = new QCPItemText(qcp);
qcp->addItem(callout);
callout->position->setCoords(xAxisMax / 2, ceiling - 1000);
callout->setFont(QFont(font().family(), 16));
callout->setPen(QPen(Qt::black));
callout->setBrush(Qt::white);
qcp->setSelectionTolerance(100);
callout->setSelectedBrush(Qt::white);
callout->setSelectedFont(QFont(font().family(), 16));
callout->setSelectedPen(QPen(Qt::black));
callout->setSelectedColor(Qt::black);
callout->setText("Double click\nto set point.");
callout->setVisible(false);
qcp->addLayer("Arrow Layer", qcp->currentLayer(), QCustomPlot::limBelow);
qcp->setCurrentLayer("Arrow Layer");
arrow = new QCPItemLine(qcp);
qcp->addItem(arrow);
arrow->start->setParentAnchor(callout->bottom);
arrow->setHead(QCPLineEnding::esSpikeArrow);
arrow->setSelectable(false);
arrow->setVisible(false);
qcp->setInteractions(QCP::iRangeZoom | QCP::iSelectItems | QCP::iRangeDrag);
qcp->yAxis->setLabel("Pixel Magnitude [DN]");
qcp->yAxis->setRange(QCPRange(0, fw->base_ceiling)); //From 0 to 2^16
qcp->graph(0)->setData(x, y);
showCalloutCheck = new QCheckBox("Display Callout");
showCalloutCheck->setChecked(false);
zoomX_enable_Check = new QCheckBox("Enable X-Zoom");
zoomX_enable_Check->setChecked(true);
zoomY_enable_Check = new QCheckBox("Enable Y-Zoom");
zoomY_enable_Check->setChecked(true);
spacer = new QSpacerItem(50,1,QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
spacer->setAlignment(Qt::AlignRight);
reset_zoom_btn = new QPushButton("Reset Zoom");
reset_zoom_btn->setToolTip("Reset the X-axis to full-frame, and the y-axis to full-scale.\n If displaying dark-subtracted data, the y-axis goes to +/- 200 DN.");
if(itype==VERT_OVERLAY)
{
overlay_img = new frameview_widget(fw, DSF, this);
// Grid layout
// Right side plot and check box:
op_vert.addWidget(qcp,1);
// op_vert.addWidget(showCalloutCheck, 2);
// Assemble Left and Right together:
// qgl.addWidget(qcp, 1,2,1,1); // profile plot
// qgl.addWidget(showCalloutCheck, 2,2,1,1); // "Show Callout"
horiz_layout.addSpacerItem(spacer);
horiz_layout.addWidget(showCalloutCheck,0);
horiz_layout.addWidget(zoomX_enable_Check,0);
horiz_layout.addWidget(zoomY_enable_Check,0);
horiz_layout.addWidget(reset_zoom_btn,0);
op_vert.addLayout(&horiz_layout,1);
// Place vertical layout on right side:
qgl.addLayout(&op_vert, 0,2, Qt::AlignBaseline);
// Left side frame view image:
qgl.addWidget(overlay_img, 0,1,1,1); // frame view, dark subtracted
//TODO: Zoom-X, Zoom-Y toggles for plot
this->setLayout(&qgl);
} else {
// VBox layout
qvbl.addWidget(qcp);
horiz_layout.addWidget(showCalloutCheck,0);
horiz_layout.addWidget(zoomX_enable_Check,0);
horiz_layout.addWidget(zoomY_enable_Check,0);
horiz_layout.addWidget(reset_zoom_btn,0);
horiz_layout.addSpacerItem(spacer);
qvbl.addLayout(&horiz_layout, 1);
qvbl.addWidget(showCalloutCheck);
this->setLayout(&qvbl);
}
connect(reset_zoom_btn, SIGNAL(released()), this, SLOT(defaultZoom())); // disconnect?
connect(qcp, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(moveCallout(QMouseEvent*)));
connect(qcp, SIGNAL(mouseDoubleClick(QMouseEvent*)), this, SLOT(setCallout(QMouseEvent*)));
connect(qcp->xAxis, SIGNAL(rangeChanged(QCPRange)), this, SLOT(profileScrolledX(QCPRange)));
connect(qcp->yAxis, SIGNAL(rangeChanged(QCPRange)), this, SLOT(profileScrolledY(QCPRange)));
connect(showCalloutCheck, SIGNAL(clicked()), this, SLOT(hideCallout()));
connect(&rendertimer, SIGNAL(timeout()), this, SLOT(handleNewFrame()));
if(!options.headless) {
rendertimer.start(FRAME_DISPLAY_PERIOD_MSECS);
}
}
profile_widget::~profile_widget()
{
if(overlay_img)
{
usleep(1000);
delete overlay_img;
}
}
// public functions
double profile_widget::getFloor()
{
/*! \brief Return the value of the floor for this widget as a double */
return floor;
}
double profile_widget::getCeiling()
{
/*! \brief Return the value of the ceiling for this widget as a double */
return ceiling;
}
// public slots
void profile_widget::handleNewFrame()
{
/*! \brief Plots a specific dimension profile.
* \paragraph
* The switch statement is a bit silly here, I only use it to differentiate the plot title and the type of profile array to use.
* The y-axis data is reversed in these images.
* \author Jackie Ryan
*/
float *local_image_ptr;
bool isMeanProfile = itype == VERTICAL_MEAN || itype == HORIZONTAL_MEAN;
if (!this->isHidden() && fw->curFrame != NULL && ((fw->crosshair_x != -1 && fw->crosshair_y != -1) || isMeanProfile)) {
allow_callouts = true;
switch (itype)
{
case VERTICAL_CROSS:
// same as mean:
case VERTICAL_MEAN:
local_image_ptr = fw->curFrame->vertical_mean_profile; // vertical profiles
for (int r = 0; r < frHeight; r++)
{
y[r] = double(local_image_ptr[r]);
}
break;
case VERT_OVERLAY:
local_image_ptr = fw->curFrame->vertical_mean_profile; // vertical profiles
for (int r = 0; r < frHeight; r++)
{
y[r] = double(local_image_ptr[r]);
y_lh[r] = double(fw->curFrame->vertical_mean_profile_lh[r]);
y_rh[r] = double(fw->curFrame->vertical_mean_profile_rh[r]);
}
// display overlay
qcp->graph(1)->setData(x, y_lh);
qcp->graph(2)->setData(x, y_rh);
break;
case HORIZONTAL_CROSS:
// same as mean:
case HORIZONTAL_MEAN:
local_image_ptr = fw->curFrame->horizontal_mean_profile; // horizontal profiles
for (int c = 0; c < frWidth; c++)
y[c] = double(local_image_ptr[c]);
break;
default:
// do nothing
break;
}
// display x and y:
qcp->graph(0)->setData(x, y);
qcp->replot();
if (callout->visible())
updateCalloutValue();
switch (itype) {
case HORIZONTAL_MEAN: plotTitle->setText(QString("Horizontal Mean Profile")); break;
case HORIZONTAL_CROSS: plotTitle->setText(QString("Horizontal Profile centered @ y = %1").arg(fw->crosshair_y)); break;
case VERTICAL_MEAN: plotTitle->setText(QString("Vertical Mean Profile")); break;
case VERTICAL_CROSS: plotTitle->setText(QString("Vertical Profile centered @ x = %1").arg(fw->crosshair_x)); break;
case VERT_OVERLAY: plotTitle->setText(QString("Vertical Overlay")); break; // TODO: Add useful things here
default: break;
}
} else {
plotTitle->setText("No Crosshair designated");
allow_callouts = false;
qcp->graph(0)->clearData();
qcp->replot();
}
boundedRange_y = qcp->yAxis->range();
boundedRange_x = qcp->xAxis->range();
}
void profile_widget::updateCeiling(int c)
{
/*! \brief Change the value of the ceiling for this widget to the input parameter and replot the color scale. */
ceiling = (double)c;
this->blockSignals(true);
rescaleRange();
this->blockSignals(false);
}
void profile_widget::updateFloor(int f)
{
/*! \brief Change the value of the floor for this widget to the input parameter and replot the color scale. */
floor = (double)f;
this->blockSignals(true);
rescaleRange();
this->blockSignals(false);
}
void profile_widget::rescaleRange()
{
/*! \brief Set the color scale of the display to the last used values for this widget */
qcp->yAxis->setRange(QCPRange(floor, ceiling));
}
void profile_widget::profileScrolledX(const QCPRange &newRange)
{
/*! \brief Controls the behavior of zooming the plot.
* \param newRange Unused.
* Profiles must not allow the user to zoom in the x direction.
*/
if(zoomX_enable_Check->isChecked())
{
// Compute intelligent zoom parameters
// Q_UNUSED(newRange);
QCPRange boundedRange = newRange;
// LIL_MIN, BIG_MIN, these are based on pixel amplitude range, not frame geometry.
double lowerRangeBound = 0;
double upperRangeBound = xAxisMax;
if (boundedRange.size() > upperRangeBound - lowerRangeBound) {
boundedRange = QCPRange(lowerRangeBound, upperRangeBound);
} else {
double oldSize = boundedRange.size();
if (boundedRange.lower < lowerRangeBound) {
boundedRange.lower = lowerRangeBound;
boundedRange.upper = lowerRangeBound + oldSize;
}
if (boundedRange.upper > upperRangeBound) {
boundedRange.lower = upperRangeBound - oldSize;
boundedRange.upper = upperRangeBound;
}
}
// floor = boundedRange.lower;
// ceiling = boundedRange.upper;
// old:
// qcp->xAxis->setRange(0, xAxisMax);
qcp->xAxis->setRange(boundedRange);
boundedRange_x = boundedRange;
} else {
qcp->xAxis->setRange(boundedRange_x);
}
}
void profile_widget::profileScrolledY(const QCPRange &newRange)
{
/*! \brief Controls the behavior of zooming the plot.
* \param newRange Mouse wheel scrolled range.
* Profiles must not allow the user to zoom past the dimensions of the frame.
*/
if(zoomY_enable_Check->isChecked())
{
QCPRange boundedRange = newRange;
double lowerRangeBound = slider_low_inc ? LIL_MIN : BIG_MIN;
double upperRangeBound = slider_low_inc ? LIL_MAX : BIG_MAX;
if (boundedRange.size() > upperRangeBound - lowerRangeBound) {
boundedRange = QCPRange(lowerRangeBound, upperRangeBound);
} else {
double oldSize = boundedRange.size();
if (boundedRange.lower < lowerRangeBound) {
boundedRange.lower = lowerRangeBound;
boundedRange.upper = lowerRangeBound + oldSize;
}
if (boundedRange.upper > upperRangeBound) {
boundedRange.lower = upperRangeBound - oldSize;
boundedRange.upper = upperRangeBound;
}
}
floor = boundedRange.lower;
ceiling = boundedRange.upper;
qcp->yAxis->setRange(boundedRange);
boundedRange_y = boundedRange;
emit haveNewRangeFC(floor, ceiling);
} else {
qcp->yAxis->setRange(boundedRange_y);
}
}
void profile_widget::defaultZoom()
{
// Set default zoom ("zoom reset" button)
QCPRange boundedRange_vert;
// if(dark_sub_enabled)
if(fw->usingDSF())
{
boundedRange_vert.lower = -200;
boundedRange_vert.upper = 200;
} else {
boundedRange_vert.lower = 0;
boundedRange_vert.upper = 65535;
}
QCPRange boundedRange_horiz;
boundedRange_horiz.lower = 0;
boundedRange_horiz.upper = xAxisMax;
qcp->yAxis->setRange(boundedRange_vert);
qcp->xAxis->setRange(boundedRange_horiz);
//TODO: update slider
}
void profile_widget::setCallout(QMouseEvent *e)
{
x_coord = qcp->xAxis->pixelToCoord(e->pos().x());
x_coord = x_coord < 0 ? 0 : x_coord;
x_coord = x_coord > xAxisMax ? xAxisMax : x_coord;
y_coord = y[x_coord];
if (callout->position->coords().y() > ceiling || callout->position->coords().y() < floor)
callout->position->setCoords(callout->position->coords().x(), (ceiling - floor) * 0.9 + floor);
callout->setText(QString(" x: %1 \n y: %2 ").arg(x_coord).arg(y_coord));
if(allow_callouts) {
arrow->end->setCoords(x_coord, y_coord);
callout->setVisible(true);
arrow->setVisible(true);
}
showCalloutCheck->setChecked(callout->visible());
}
void profile_widget::moveCallout(QMouseEvent *e)
{
// Note, e->posF() was used for previous QT Library versions.
if ((callout->selectTest(e->pos(), true) < (0.99 * qcp->selectionTolerance())) && (e->buttons() & Qt::LeftButton)) {
callout->position->setPixelPoint(e->pos());
} else {
return;
}
}
void profile_widget::setPenWidth(int penWidth) {
QPen myPen;
for(int i=0; i < qcp->graphCount(); i++) {
myPen = qcp->graph(i)->pen();
myPen.setWidth(penWidth);
qcp->graph(i)->setPen(myPen);
}
}
void profile_widget::hideCallout()
{
if (callout->visible() || !allow_callouts) {
callout->setVisible(false);
arrow->setVisible(false);
} else {
if( (y.size()-1 < x_coord) || (x_coord <0))
return;
callout->setVisible(true);
arrow->setVisible(true);
}
showCalloutCheck->setChecked(callout->visible());
}
// private slots
void profile_widget::updateCalloutValue()
{
if( (y.size()-1 < x_coord) || (x_coord <0))
return;
y_coord = y[x_coord];
arrow->end->setCoords(x_coord, y_coord);
callout->setText(QString(" x: %1 \n y: %2 ").arg(x_coord).arg(y_coord));
}