adeae3a0
David Mayerich
Initial commit, s...
|
1
2
3
4
5
6
7
8
9
10
|
#include "spectrumwindow.h"
#include "ui_spectrumwindow.h"
#include "mainwindow.h"
SpectrumWindow::SpectrumWindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::SpectrumWindow)
{
ui->setupUi(this);
|
2959aae6
David Mayerich
added support for...
|
11
12
|
//install an event filter to detect user clicks
|
adeae3a0
David Mayerich
Initial commit, s...
|
13
|
ui->spectrumPlot->installEventFilter(this);
|
2959aae6
David Mayerich
added support for...
|
14
15
16
17
|
//create a line for the current band
bandline = new QCPItemStraightLine(ui->spectrumPlot);
ui->spectrumPlot->addItem(bandline);
|
adeae3a0
David Mayerich
Initial commit, s...
|
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
}
SpectrumWindow::~SpectrumWindow()
{
delete ui;
}
void SpectrumWindow::plotSpectrum(QVector<double> x, QVector<double> y){
//find the maximum and minimum values
double y_min = y[0];
double y_max = y[0];
for(int i=1; i<y.size(); i++){
if(y[i] < y_min) y_min = y[i];
if(y[i] > y_max) y_max = y[i];
}
|
2959aae6
David Mayerich
added support for...
|
34
35
|
//set the range of the y axis to the minimum and maximum spectrum values
|
adeae3a0
David Mayerich
Initial commit, s...
|
36
37
|
ui->spectrumPlot->yAxis->setRange(y_min, y_max);
|
2959aae6
David Mayerich
added support for...
|
38
|
//add the graph to the plot
|
adeae3a0
David Mayerich
Initial commit, s...
|
39
|
ui->spectrumPlot->graph(0)->setData(x, y);
|
2959aae6
David Mayerich
added support for...
|
40
41
|
//redraw the plot
|
adeae3a0
David Mayerich
Initial commit, s...
|
42
|
ui->spectrumPlot->replot();
|
4d6d4d8b
David Mayerich
fixed an error in...
|
43
44
45
|
std::cout<<"Items in the plot: "<<ui->spectrumPlot->itemCount()<<std::endl;
std::cout<<bandline->point1->coords().x()<<", "<<bandline->point1->coords().y()<<std::endl;
|
adeae3a0
David Mayerich
Initial commit, s...
|
46
47
48
49
50
51
52
53
54
|
}
void SpectrumWindow::initPlot(double x_min, double x_max, double y_min, double y_max, QString x_title, QString y_title){
// give the axes some labels:
ui->spectrumPlot->xAxis->setLabel(x_title);
ui->spectrumPlot->yAxis->setLabel(y_title);
// set axes ranges, so we see all data:
ui->spectrumPlot->xAxis->setRange(x_min, x_max);
ui->spectrumPlot->yAxis->setRange(y_min, y_max);
|
2959aae6
David Mayerich
added support for...
|
55
|
|
4d6d4d8b
David Mayerich
fixed an error in...
|
56
57
58
|
//add a graph to the plot
ui->spectrumPlot->addGraph();
|
2959aae6
David Mayerich
added support for...
|
59
60
61
62
63
64
65
66
|
//set the initial position of the band line
double xmid = (x_max + x_min) / 2;
std::cout<<"xmid: "<<xmid<<std::endl;
bandline->point1->setCoords(xmid, 0);
bandline->point2->setCoords(xmid, 1);
bandline->setPen(QPen(Qt::red));
|
adeae3a0
David Mayerich
Initial commit, s...
|
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
ui->spectrumPlot->replot();
}
/// Update the image viewing widget so that it always fills the main window
void SpectrumWindow::resizeEvent(QResizeEvent* event){
//get the current window size
QSize winsize = event->size();
//match the plot to the window
ui->spectrumPlot->setFixedSize(winsize.width(), winsize.height());
}
bool SpectrumWindow::eventFilter(QObject *target, QEvent *event)
{
|
2959aae6
David Mayerich
added support for...
|
82
|
|
4d6d4d8b
David Mayerich
fixed an error in...
|
83
|
/*if(target == ui->spectrumPlot && event->type() == QEvent::MouseMove)
|
adeae3a0
David Mayerich
Initial commit, s...
|
84
85
86
87
88
89
90
91
92
93
|
{
QMouseEvent *_mouseEvent = static_cast<QMouseEvent*>(event);
//get the window position of the click
QPoint pixel = _mouseEvent->pos();
//calculate the position of the click in the image
double x = ui->spectrumPlot->xAxis->pixelToCoord(pixel.x());
double y = ui->spectrumPlot->yAxis->pixelToCoord(pixel.y());
|
2959aae6
David Mayerich
added support for...
|
94
95
96
97
|
//set the position of the band line
bandline->point1->setCoords(x, 0);
bandline->point2->setCoords(x, 1);
|
4d6d4d8b
David Mayerich
fixed an error in...
|
98
|
std::cout<<"coords set to: "<<x<<std::endl;
|
adeae3a0
David Mayerich
Initial commit, s...
|
99
|
}
|
4d6d4d8b
David Mayerich
fixed an error in...
|
100
101
|
else */
if(target == ui->spectrumPlot && event->type() == QEvent::MouseButtonPress)
|
adeae3a0
David Mayerich
Initial commit, s...
|
102
103
104
105
106
107
108
109
110
111
112
113
114
|
{
QMouseEvent *_mouseEvent = static_cast<QMouseEvent*>(event);
//get the window position of the click
QPoint pixel = _mouseEvent->pos();
//calculate the position of the click in the image
double x = ui->spectrumPlot->xAxis->pixelToCoord(pixel.x());
double y = ui->spectrumPlot->yAxis->pixelToCoord(pixel.y());
//tell the parent MainWindow that a point on the spectrum was selected
((MainWindow*)parent())->mousePressSpectrum(x, y);
|
2959aae6
David Mayerich
added support for...
|
115
116
117
118
|
//set the position of the band line
bandline->point1->setCoords(x, 0);
bandline->point2->setCoords(x, 1);
|
4d6d4d8b
David Mayerich
fixed an error in...
|
119
120
121
122
|
std::cout<<"coords set to: "<<x<<std::endl;
//replot the spectrum with the new band line position
ui->spectrumPlot->replot();
|
adeae3a0
David Mayerich
Initial commit, s...
|
123
|
}
|
adeae3a0
David Mayerich
Initial commit, s...
|
124
|
|
adeae3a0
David Mayerich
Initial commit, s...
|
125
|
|
adeae3a0
David Mayerich
Initial commit, s...
|
126
|
|
2959aae6
David Mayerich
added support for...
|
127
|
return false;
|
adeae3a0
David Mayerich
Initial commit, s...
|
128
|
}
|