Commit 2959aae640147468d99615d51d244b424ab6d58f
1 parent
5294a320
added support for large images
Showing
12 changed files
with
104 additions
and
78 deletions
Show diff stats
mainwindow.cpp
@@ -20,7 +20,7 @@ void MainWindow::loadImage(QString fileName){ | @@ -20,7 +20,7 @@ void MainWindow::loadImage(QString fileName){ | ||
20 | hsi.open(file, file + ".hdr"); | 20 | hsi.open(file, file + ".hdr"); |
21 | 21 | ||
22 | //initialize the size of the main window | 22 | //initialize the size of the main window |
23 | - resize(hsi.header.samples+2, hsi.header.lines + ui->menuBar->size().height()); | 23 | + //resize(hsi.header.samples+2, hsi.header.lines + ui->menuBar->size().height()); |
24 | 24 | ||
25 | //fill the x axis with wavelength numbers from the hsi | 25 | //fill the x axis with wavelength numbers from the hsi |
26 | x = QVector<double>::fromStdVector(hsi.header.wavelength); | 26 | x = QVector<double>::fromStdVector(hsi.header.wavelength); |
@@ -29,7 +29,7 @@ void MainWindow::loadImage(QString fileName){ | @@ -29,7 +29,7 @@ void MainWindow::loadImage(QString fileName){ | ||
29 | load_band(x.size()/2); | 29 | load_band(x.size()/2); |
30 | 30 | ||
31 | //set the pick position to the center of the image | 31 | //set the pick position to the center of the image |
32 | - p = QPoint((int)(image.width()/2), (int)(image.height()/2)); | 32 | + px = py = 0.5; |
33 | 33 | ||
34 | //create a graphics scene to store the image and any drawn UI elements | 34 | //create a graphics scene to store the image and any drawn UI elements |
35 | scene = new QGraphicsScene(this); | 35 | scene = new QGraphicsScene(this); |
@@ -45,6 +45,7 @@ void MainWindow::loadImage(QString fileName){ | @@ -45,6 +45,7 @@ void MainWindow::loadImage(QString fileName){ | ||
45 | draw_viewport(); | 45 | draw_viewport(); |
46 | } | 46 | } |
47 | 47 | ||
48 | + | ||
48 | /// Update the image viewing widget so that it always fills the main window | 49 | /// Update the image viewing widget so that it always fills the main window |
49 | void MainWindow::resizeEvent(QResizeEvent* event){ | 50 | void MainWindow::resizeEvent(QResizeEvent* event){ |
50 | 51 | ||
@@ -53,14 +54,32 @@ void MainWindow::resizeEvent(QResizeEvent* event){ | @@ -53,14 +54,32 @@ void MainWindow::resizeEvent(QResizeEvent* event){ | ||
53 | 54 | ||
54 | //get the current position of the QGraphicsView object | 55 | //get the current position of the QGraphicsView object |
55 | QPoint imagepos = ui->graphicsView->pos(); | 56 | QPoint imagepos = ui->graphicsView->pos(); |
56 | - | 57 | + |
58 | + //calculate the maximum allowable image width and height given the user's selected window size | ||
59 | + unsigned int maxwidth = winsize.width() - imagepos.x(); | ||
60 | + unsigned int maxheight = winsize.height() - imagepos.y(); | ||
61 | + | ||
62 | + //get the size of the image | ||
63 | + QSize imagesize = image.size(); | ||
64 | + | ||
65 | + //calculate the aspect ratio | ||
66 | + //float aspect = imagesize.width() / imagesize.height(); | ||
67 | + float width_ratio = imagesize.width() / maxwidth; | ||
68 | + float height_ratio = imagesize.height() / maxheight; | ||
69 | + | ||
70 | + //if the width requires the largest scaling | ||
71 | + if(width_ratio >= height_ratio) | ||
72 | + main_image = image.scaledToWidth(maxwidth); | ||
73 | + else | ||
74 | + main_image = image.scaledToHeight(maxheight); | ||
75 | + | ||
57 | //update the size of the QGraphicsView object | 76 | //update the size of the QGraphicsView object |
58 | // the QGraphicsView will be either the size of the image or | 77 | // the QGraphicsView will be either the size of the image or |
59 | // the size of the window (whichever is smaller) | 78 | // the size of the window (whichever is smaller) |
60 | - QSize viewsize = QSize( std::min(winsize.width() - imagepos.x(), image.width()+2), | ||
61 | - std::min(winsize.height() - imagepos.y(), image.height()+2) ); | 79 | + QSize viewsize = QSize( main_image.width()+2, main_image.height()+2 ); |
62 | ui->graphicsView->setFixedSize(viewsize.width(), viewsize.height()); | 80 | ui->graphicsView->setFixedSize(viewsize.width(), viewsize.height()); |
63 | 81 | ||
82 | + draw_viewport(); | ||
64 | } | 83 | } |
65 | 84 | ||
66 | /// Update everything associated with when the image is clicked | 85 | /// Update everything associated with when the image is clicked |
@@ -70,13 +89,20 @@ void MainWindow::mousePressEvent(QMouseEvent * event){ | @@ -70,13 +89,20 @@ void MainWindow::mousePressEvent(QMouseEvent * event){ | ||
70 | QPoint winp = event->pos(); | 89 | QPoint winp = event->pos(); |
71 | 90 | ||
72 | //get the position of the QGraphicsView object (upper left corner of the image) | 91 | //get the position of the QGraphicsView object (upper left corner of the image) |
73 | - QPoint imagep = ui->graphicsView->pos(); | 92 | + QPoint viewp = ui->graphicsView->pos(); |
74 | 93 | ||
75 | //get the size of the menu bar | 94 | //get the size of the menu bar |
76 | int menu_height = ui->menuBar->size().height(); | 95 | int menu_height = ui->menuBar->size().height(); |
77 | 96 | ||
78 | - //calculate the position of the click in the image | ||
79 | - p = winp - imagep - QPoint(0, menu_height); | 97 | + //calculate the position of the click in the graphics view |
98 | + QPoint imagep = winp - viewp - QPoint(0, menu_height); | ||
99 | + | ||
100 | + //get the size of the graphics view object | ||
101 | + QSize viewsize = ui->graphicsView->size(); | ||
102 | + | ||
103 | + //calculate the position of the point in the image space [0, 1] | ||
104 | + px = (float)imagep.x() / (float) viewsize.width(); | ||
105 | + py = (float)imagep.y() / (float) viewsize.height(); | ||
80 | 106 | ||
81 | //load the spectrum associated with p | 107 | //load the spectrum associated with p |
82 | load_spectrum(); | 108 | load_spectrum(); |
@@ -129,6 +155,16 @@ void MainWindow::load_band(unsigned int i){ | @@ -129,6 +155,16 @@ void MainWindow::load_band(unsigned int i){ | ||
129 | QImage::Format_RGB888 | 155 | QImage::Format_RGB888 |
130 | ) | 156 | ) |
131 | ); | 157 | ); |
158 | + | ||
159 | + //get the main image size | ||
160 | + QSize main_size = main_image.size(); | ||
161 | + | ||
162 | + //scale the band image | ||
163 | + main_image = image.scaledToHeight(main_size.height()); | ||
164 | + | ||
165 | + //free the buffer and band memory | ||
166 | + free(buffer); | ||
167 | + free(band); | ||
132 | } | 168 | } |
133 | 169 | ||
134 | void MainWindow::draw_viewport(){ | 170 | void MainWindow::draw_viewport(){ |
@@ -136,10 +172,10 @@ void MainWindow::draw_viewport(){ | @@ -136,10 +172,10 @@ void MainWindow::draw_viewport(){ | ||
136 | scene->clear(); | 172 | scene->clear(); |
137 | 173 | ||
138 | //add the image to the scene | 174 | //add the image to the scene |
139 | - scene->addPixmap(image); | 175 | + scene->addPixmap(main_image); |
140 | 176 | ||
141 | //I'm not sure what this does... | 177 | //I'm not sure what this does... |
142 | - scene->setSceneRect(image.rect()); | 178 | + scene->setSceneRect(main_image.rect()); |
143 | 179 | ||
144 | //draw the overlay indicating the selected pixel | 180 | //draw the overlay indicating the selected pixel |
145 | draw_overlay(); | 181 | draw_overlay(); |
@@ -154,8 +190,11 @@ void MainWindow::draw_overlay(){ | @@ -154,8 +190,11 @@ void MainWindow::draw_overlay(){ | ||
154 | //get the size of the QGraphicsView object | 190 | //get the size of the QGraphicsView object |
155 | QSize image_size = ui->graphicsView->size(); | 191 | QSize image_size = ui->graphicsView->size(); |
156 | 192 | ||
157 | - scene->addLine(0, p.y(), image_size.width(), p.y()); | ||
158 | - scene->addLine(p.x(), 0, p.x(), image_size.height()); | 193 | + //calculate the pixel position (index) into the main image |
194 | + QPoint pi = QPoint(px * image_size.width(), py * image_size.height()); | ||
195 | + | ||
196 | + scene->addLine(0, pi.y(), image_size.width(), pi.y()); | ||
197 | + scene->addLine(pi.x(), 0, pi.x(), image_size.height()); | ||
159 | } | 198 | } |
160 | 199 | ||
161 | /// Loads the spectrum from the picked point of the HSI and stores it in the member variable y | 200 | /// Loads the spectrum from the picked point of the HSI and stores it in the member variable y |
@@ -164,8 +203,11 @@ void MainWindow::load_spectrum(){ | @@ -164,8 +203,11 @@ void MainWindow::load_spectrum(){ | ||
164 | //allocate the appropriate amount of memory for the spectrum | 203 | //allocate the appropriate amount of memory for the spectrum |
165 | float* temp_y = (float*) malloc(x.size() * sizeof(float)); | 204 | float* temp_y = (float*) malloc(x.size() * sizeof(float)); |
166 | 205 | ||
206 | + //pixel position in the band image | ||
207 | + QPoint pi = QPoint(px * image.width(), py * image.height()); | ||
208 | + | ||
167 | //load the spectrum from the HSI | 209 | //load the spectrum from the HSI |
168 | - hsi.spectrum(temp_y, p.x(), p.y()); | 210 | + hsi.spectrum(temp_y, pi.x(), pi.y()); |
169 | 211 | ||
170 | //clear the previous spectrum | 212 | //clear the previous spectrum |
171 | y.clear(); | 213 | y.clear(); |
mainwindow.h
@@ -33,8 +33,12 @@ private slots: | @@ -33,8 +33,12 @@ private slots: | ||
33 | private: | 33 | private: |
34 | Ui::MainWindow *ui; | 34 | Ui::MainWindow *ui; |
35 | QGraphicsScene* scene; //scene containing the image and any drawn UI elements | 35 | QGraphicsScene* scene; //scene containing the image and any drawn UI elements |
36 | - QPixmap image; //stores the pixels for the displayed image | ||
37 | - QPoint p; //stores the picked position of the image | 36 | + QPixmap image; //stores the pixels for the current band |
37 | + QPixmap main_image; //stores the pixels for the image displayed in the main view (may be scaled) | ||
38 | + | ||
39 | + //coordinates of the picked position in image space [0, 1] | ||
40 | + double px; | ||
41 | + double py; | ||
38 | 42 | ||
39 | SpectrumWindow* s; //window displaying the spectrum of the selected pixel | 43 | SpectrumWindow* s; //window displaying the spectrum of the selected pixel |
40 | 44 |
mainwindow.ui
@@ -6,8 +6,8 @@ | @@ -6,8 +6,8 @@ | ||
6 | <rect> | 6 | <rect> |
7 | <x>0</x> | 7 | <x>0</x> |
8 | <y>0</y> | 8 | <y>0</y> |
9 | - <width>361</width> | ||
10 | - <height>377</height> | 9 | + <width>780</width> |
10 | + <height>733</height> | ||
11 | </rect> | 11 | </rect> |
12 | </property> | 12 | </property> |
13 | <property name="windowTitle"> | 13 | <property name="windowTitle"> |
@@ -19,8 +19,8 @@ | @@ -19,8 +19,8 @@ | ||
19 | <rect> | 19 | <rect> |
20 | <x>0</x> | 20 | <x>0</x> |
21 | <y>0</y> | 21 | <y>0</y> |
22 | - <width>361</width> | ||
23 | - <height>331</height> | 22 | + <width>781</width> |
23 | + <height>701</height> | ||
24 | </rect> | 24 | </rect> |
25 | </property> | 25 | </property> |
26 | <property name="alignment"> | 26 | <property name="alignment"> |
@@ -33,8 +33,8 @@ | @@ -33,8 +33,8 @@ | ||
33 | <rect> | 33 | <rect> |
34 | <x>0</x> | 34 | <x>0</x> |
35 | <y>0</y> | 35 | <y>0</y> |
36 | - <width>361</width> | ||
37 | - <height>21</height> | 36 | + <width>780</width> |
37 | + <height>31</height> | ||
38 | </rect> | 38 | </rect> |
39 | </property> | 39 | </property> |
40 | <widget class="QMenu" name="menuFile"> | 40 | <widget class="QMenu" name="menuFile"> |
spectrumplot.cpp deleted
spectrumplot.h deleted
1 | -/*#ifndef SPECTRUMPLOT_H | ||
2 | -#define SPECTRUMPLOT_H | ||
3 | - | ||
4 | -#include "qcustomplot.h" | ||
5 | - | ||
6 | -//stim libraries | ||
7 | -#include "stim/envi/envi.h" | ||
8 | - | ||
9 | -namespace Ui { | ||
10 | -class MainWindow; | ||
11 | -} | ||
12 | - | ||
13 | -class SpectrumPlot : public QCustomPlot | ||
14 | -{ | ||
15 | - Q_OBJECT | ||
16 | - | ||
17 | -public: | ||
18 | - //explicit MainWindow(QWidget *parent = 0); | ||
19 | - //~MainWindow(); | ||
20 | - | ||
21 | - //void mousePressEvent(QMouseEvent* event); //handles when the image is clicked | ||
22 | - //void resizeEvent(QResizeEvent* event); //handles when the window is resized | ||
23 | - | ||
24 | -private: | ||
25 | - //Ui::MainWindow *ui; | ||
26 | - //QGraphicsScene* scene; //scene containing the image and any drawn UI elements | ||
27 | - //QPixmap image; //stores the pixels for the displayed image | ||
28 | - //QPoint p; //stores the picked position of the image | ||
29 | - | ||
30 | - //SpectrumWindow* s; //window displaying the spectrum of the selected pixel | ||
31 | - | ||
32 | - //stim::envi hsi; //data structure storing the current hyperspectral image | ||
33 | - //QVector<double> x; //x values for the spectrum | ||
34 | - //QVector<double> y; //y values for the spectrum | ||
35 | - | ||
36 | - //void draw_overlay(); //draws an overlay showing the picked position | ||
37 | - //void draw_viewport(); //draws the viewport, including the image and overlay | ||
38 | - //void load_spectrum(); //loads a spectrum from the HSI and stores it in the global variable y | ||
39 | - //void draw_spectrum(); //sends a spectrum to the SpectrumWindow for plotting | ||
40 | - | ||
41 | -}; | ||
42 | - | ||
43 | -#endif // SPECTRUMPLOT_H*/ |
spectrumwindow.cpp
@@ -8,7 +8,16 @@ SpectrumWindow::SpectrumWindow(QWidget *parent) : | @@ -8,7 +8,16 @@ SpectrumWindow::SpectrumWindow(QWidget *parent) : | ||
8 | ui(new Ui::SpectrumWindow) | 8 | ui(new Ui::SpectrumWindow) |
9 | { | 9 | { |
10 | ui->setupUi(this); | 10 | ui->setupUi(this); |
11 | + | ||
12 | + //install an event filter to detect user clicks | ||
11 | ui->spectrumPlot->installEventFilter(this); | 13 | ui->spectrumPlot->installEventFilter(this); |
14 | + | ||
15 | + //create a line for the current band | ||
16 | + bandline = new QCPItemStraightLine(ui->spectrumPlot); | ||
17 | + ui->spectrumPlot->addItem(bandline); | ||
18 | + | ||
19 | + | ||
20 | + | ||
12 | } | 21 | } |
13 | 22 | ||
14 | SpectrumWindow::~SpectrumWindow() | 23 | SpectrumWindow::~SpectrumWindow() |
@@ -25,10 +34,15 @@ void SpectrumWindow::plotSpectrum(QVector<double> x, QVector<double> y){ | @@ -25,10 +34,15 @@ void SpectrumWindow::plotSpectrum(QVector<double> x, QVector<double> y){ | ||
25 | if(y[i] < y_min) y_min = y[i]; | 34 | if(y[i] < y_min) y_min = y[i]; |
26 | if(y[i] > y_max) y_max = y[i]; | 35 | if(y[i] > y_max) y_max = y[i]; |
27 | } | 36 | } |
37 | + | ||
38 | + //set the range of the y axis to the minimum and maximum spectrum values | ||
28 | ui->spectrumPlot->yAxis->setRange(y_min, y_max); | 39 | ui->spectrumPlot->yAxis->setRange(y_min, y_max); |
29 | 40 | ||
41 | + //add the graph to the plot | ||
30 | ui->spectrumPlot->addGraph(); | 42 | ui->spectrumPlot->addGraph(); |
31 | ui->spectrumPlot->graph(0)->setData(x, y); | 43 | ui->spectrumPlot->graph(0)->setData(x, y); |
44 | + | ||
45 | + //redraw the plot | ||
32 | ui->spectrumPlot->replot(); | 46 | ui->spectrumPlot->replot(); |
33 | } | 47 | } |
34 | 48 | ||
@@ -39,6 +53,15 @@ void SpectrumWindow::initPlot(double x_min, double x_max, double y_min, double y | @@ -39,6 +53,15 @@ void SpectrumWindow::initPlot(double x_min, double x_max, double y_min, double y | ||
39 | // set axes ranges, so we see all data: | 53 | // set axes ranges, so we see all data: |
40 | ui->spectrumPlot->xAxis->setRange(x_min, x_max); | 54 | ui->spectrumPlot->xAxis->setRange(x_min, x_max); |
41 | ui->spectrumPlot->yAxis->setRange(y_min, y_max); | 55 | ui->spectrumPlot->yAxis->setRange(y_min, y_max); |
56 | + | ||
57 | + //set the initial position of the band line | ||
58 | + double xmid = (x_max + x_min) / 2; | ||
59 | + std::cout<<"xmid: "<<xmid<<std::endl; | ||
60 | + bandline->point1->setCoords(xmid, 0); | ||
61 | + bandline->point2->setCoords(xmid, 1); | ||
62 | + bandline->setPen(QPen(Qt::red)); | ||
63 | + | ||
64 | + | ||
42 | ui->spectrumPlot->replot(); | 65 | ui->spectrumPlot->replot(); |
43 | } | 66 | } |
44 | 67 | ||
@@ -54,6 +77,7 @@ void SpectrumWindow::resizeEvent(QResizeEvent* event){ | @@ -54,6 +77,7 @@ void SpectrumWindow::resizeEvent(QResizeEvent* event){ | ||
54 | 77 | ||
55 | bool SpectrumWindow::eventFilter(QObject *target, QEvent *event) | 78 | bool SpectrumWindow::eventFilter(QObject *target, QEvent *event) |
56 | { | 79 | { |
80 | + | ||
57 | if(target == ui->spectrumPlot && event->type() == QEvent::MouseMove) | 81 | if(target == ui->spectrumPlot && event->type() == QEvent::MouseMove) |
58 | { | 82 | { |
59 | QMouseEvent *_mouseEvent = static_cast<QMouseEvent*>(event); | 83 | QMouseEvent *_mouseEvent = static_cast<QMouseEvent*>(event); |
@@ -65,6 +89,10 @@ bool SpectrumWindow::eventFilter(QObject *target, QEvent *event) | @@ -65,6 +89,10 @@ bool SpectrumWindow::eventFilter(QObject *target, QEvent *event) | ||
65 | //calculate the position of the click in the image | 89 | //calculate the position of the click in the image |
66 | double x = ui->spectrumPlot->xAxis->pixelToCoord(pixel.x()); | 90 | double x = ui->spectrumPlot->xAxis->pixelToCoord(pixel.x()); |
67 | double y = ui->spectrumPlot->yAxis->pixelToCoord(pixel.y()); | 91 | double y = ui->spectrumPlot->yAxis->pixelToCoord(pixel.y()); |
92 | + | ||
93 | + //set the position of the band line | ||
94 | + bandline->point1->setCoords(x, 0); | ||
95 | + bandline->point2->setCoords(x, 1); | ||
68 | } | 96 | } |
69 | else if(target == ui->spectrumPlot && event->type() == QEvent::MouseButtonPress) | 97 | else if(target == ui->spectrumPlot && event->type() == QEvent::MouseButtonPress) |
70 | { | 98 | { |
@@ -80,21 +108,13 @@ bool SpectrumWindow::eventFilter(QObject *target, QEvent *event) | @@ -80,21 +108,13 @@ bool SpectrumWindow::eventFilter(QObject *target, QEvent *event) | ||
80 | 108 | ||
81 | //tell the parent MainWindow that a point on the spectrum was selected | 109 | //tell the parent MainWindow that a point on the spectrum was selected |
82 | ((MainWindow*)parent())->mousePressSpectrum(x, y); | 110 | ((MainWindow*)parent())->mousePressSpectrum(x, y); |
111 | + | ||
112 | + //set the position of the band line | ||
113 | + bandline->point1->setCoords(x, 0); | ||
114 | + bandline->point2->setCoords(x, 1); | ||
83 | } | 115 | } |
84 | - return false; | ||
85 | -} | ||
86 | 116 | ||
87 | -/// Update everything associated with when the image is clicked | ||
88 | -void SpectrumWindow::mousePressEvent(QMouseEvent * event){ | ||
89 | 117 | ||
90 | - //get the window position of the click | ||
91 | - QPoint winp = event->pos(); | ||
92 | - | ||
93 | - | ||
94 | - //calculate the position of the click in the image | ||
95 | - QPoint p = winp; | ||
96 | - | ||
97 | - //output the image position | ||
98 | - std::cout<<p.x()<<" "<<p.y()<<std::endl; | ||
99 | 118 | ||
119 | + return false; | ||
100 | } | 120 | } |
spectrumwindow.h
@@ -4,6 +4,7 @@ | @@ -4,6 +4,7 @@ | ||
4 | #include <QDialog> | 4 | #include <QDialog> |
5 | #include <QVector> | 5 | #include <QVector> |
6 | #include <iostream> | 6 | #include <iostream> |
7 | +#include "qcustomplot.h" | ||
7 | 8 | ||
8 | namespace Ui { | 9 | namespace Ui { |
9 | class SpectrumWindow; | 10 | class SpectrumWindow; |
@@ -22,10 +23,12 @@ public: | @@ -22,10 +23,12 @@ public: | ||
22 | 23 | ||
23 | void resizeEvent(QResizeEvent* event); //handles when the window is resized | 24 | void resizeEvent(QResizeEvent* event); //handles when the window is resized |
24 | bool SpectrumWindow::eventFilter(QObject *target, QEvent *event); | 25 | bool SpectrumWindow::eventFilter(QObject *target, QEvent *event); |
25 | - void mousePressEvent(QMouseEvent* event); //handles when the image is clicked | ||
26 | 26 | ||
27 | private: | 27 | private: |
28 | Ui::SpectrumWindow *ui; | 28 | Ui::SpectrumWindow *ui; |
29 | + | ||
30 | + //line that displays the currently selected band | ||
31 | + QCPItemStraightLine* bandline; | ||
29 | }; | 32 | }; |
30 | 33 | ||
31 | #endif // SPECTRUMWINDOW_H | 34 | #endif // SPECTRUMWINDOW_H |
win32/Qt5Core.dll
No preview for this file type
win32/Qt5PrintSupport.dll
No preview for this file type
No preview for this file type
win32/hsiview.exe
No preview for this file type
win32/platforms/qwindows.dll
No preview for this file type