29e744fa
dmayerich
Added QT dialog b...
|
1
2
3
|
#ifndef DISTORTIONDIALOG_H
#define DISTORTIONDIALOG_H
|
887d4441
David Mayerich
updates from STIM...
|
4
|
#include <QtWidgets/QDialog>
|
29e744fa
dmayerich
Added QT dialog b...
|
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#include <QDragEnterEvent>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsPixmapItem>
#include <qfiledialog.h>
#include <qinputdialog.h>
#include "ui_distortiondialog.h"
#include "globals.h"
extern QGraphicsScene* distortionScene;
extern QGraphicsView* distortionWindow;
extern QGraphicsPixmapItem* pixmapItem;
class qtDistortionDialog : public QDialog
{
|
8ffb8373
dmayerich
Improved material...
|
20
|
Q_OBJECT
|
29e744fa
dmayerich
Added QT dialog b...
|
21
22
|
public:
|
887d4441
David Mayerich
updates from STIM...
|
23
|
qtDistortionDialog(QWidget *parent = 0, Qt::WindowFlags flags = 0);
|
8ffb8373
dmayerich
Improved material...
|
24
25
|
~qtDistortionDialog();
bool updating;
|
29e744fa
dmayerich
Added QT dialog b...
|
26
27
|
private:
|
8ffb8373
dmayerich
Improved material...
|
28
|
Ui::DistortionDialogClass ui;
|
29e744fa
dmayerich
Added QT dialog b...
|
29
30
|
public slots:
|
8ffb8373
dmayerich
Improved material...
|
31
|
void on_btnComputeDistortionMap_clicked() {
|
29e744fa
dmayerich
Added QT dialog b...
|
32
|
|
887d4441
David Mayerich
updates from STIM...
|
33
34
35
36
|
//get the filename
QString filename = QFileDialog::getSaveFileName(NULL, "Distortion File");
int steps = ui.spinSteps->value();
|
29e744fa
dmayerich
Added QT dialog b...
|
37
38
39
40
41
42
43
44
45
46
|
//delete the pixmap if one previously existed
if(pixmapItem != NULL)
delete(pixmapItem);
//create an image
QImage image(steps, steps, QImage::Format_RGB888);
QColor color(255, 255, 0);
|
887d4441
David Mayerich
updates from STIM...
|
47
48
49
50
51
52
|
double minIn, maxIn, minOut, maxOut;
minIn = ui.spinInStart->value();
maxIn = ui.spinInEnd->value();
minOut = ui.spinOutStart->value();
maxOut = ui.spinOutEnd->value();
|
29e744fa
dmayerich
Added QT dialog b...
|
53
|
|
887d4441
David Mayerich
updates from STIM...
|
54
|
//compute the distortion map (2D steps x steps image)
|
29e744fa
dmayerich
Added QT dialog b...
|
55
|
float* distortionMap = (float*)malloc(sizeof(float) * steps * steps);
|
887d4441
David Mayerich
updates from STIM...
|
56
|
DistortionMap(distortionMap, minIn, maxIn, minOut, maxOut, steps, filename.toUtf8().constData());
|
29e744fa
dmayerich
Added QT dialog b...
|
57
58
59
60
|
//compute the extrema
float minDistortion = 99999;
float maxDistortion = distortionMap[0];
|
8ffb8373
dmayerich
Improved material...
|
61
|
for(int i=1; i<steps*steps; i++) {
|
29e744fa
dmayerich
Added QT dialog b...
|
62
63
64
65
66
67
|
if(distortionMap[i] < minDistortion && distortionMap[i] > 0)
minDistortion = distortionMap[i];
if(distortionMap[i] > maxDistortion)
maxDistortion = distortionMap[i];
}
cout<<minDistortion<<"----------"<<maxDistortion<<endl;
|
887d4441
David Mayerich
updates from STIM...
|
68
69
70
|
FILE* outraw = fopen("out.raw", "wb");
fwrite(distortionMap, sizeof(float), steps * steps, outraw);
fclose(outraw);
|
29e744fa
dmayerich
Added QT dialog b...
|
71
72
73
74
75
76
|
//compute the distortion map image
int i, o;
float intensity;
float v;
for(i=0; i<steps; i++)
|
8ffb8373
dmayerich
Improved material...
|
77
|
for(o=0; o<steps; o++) {
|
29e744fa
dmayerich
Added QT dialog b...
|
78
79
80
|
v = distortionMap[o * steps + i];
intensity = (v - minDistortion) / (maxDistortion - minDistortion) * 255;
|
8ffb8373
dmayerich
Improved material...
|
81
|
if(intensity < 0) {
|
887d4441
David Mayerich
updates from STIM...
|
82
|
//cout<<"low intensity"<<endl;
|
8ffb8373
dmayerich
Improved material...
|
83
84
|
intensity = 0;
}
|
29e744fa
dmayerich
Added QT dialog b...
|
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
//QColor color(intensity, (float)o / (float)steps * 255, (float)i / (float)steps * 255);
QColor color(intensity, intensity, intensity);
image.setPixel(o, (steps-1-i), color.rgb());
}
pixmapItem = new QGraphicsPixmapItem(QPixmap::fromImage(image));
distortionScene->addItem(pixmapItem);
distortionWindow->show();
}
};
#endif
|