Commit 29e744fadfbb7445f8c7f05a252b5ca63265feb1
1 parent
39a7d6e9
Added QT dialog box files for distortion maps.
Showing
3 changed files
with
128 additions
and
0 deletions
Show diff stats
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<ui version="4.0"> | ||
3 | + <class>DistortionDialogClass</class> | ||
4 | + <widget class="QDialog" name="DistortionDialogClass"> | ||
5 | + <property name="geometry"> | ||
6 | + <rect> | ||
7 | + <x>0</x> | ||
8 | + <y>0</y> | ||
9 | + <width>400</width> | ||
10 | + <height>300</height> | ||
11 | + </rect> | ||
12 | + </property> | ||
13 | + <property name="windowTitle"> | ||
14 | + <string>Distortion Map</string> | ||
15 | + </property> | ||
16 | + <widget class="QPushButton" name="btnComputeDistortionMap"> | ||
17 | + <property name="geometry"> | ||
18 | + <rect> | ||
19 | + <x>300</x> | ||
20 | + <y>250</y> | ||
21 | + <width>87</width> | ||
22 | + <height>27</height> | ||
23 | + </rect> | ||
24 | + </property> | ||
25 | + <property name="text"> | ||
26 | + <string>Compute</string> | ||
27 | + </property> | ||
28 | + </widget> | ||
29 | + </widget> | ||
30 | + <resources/> | ||
31 | + <connections/> | ||
32 | +</ui> |
1 | +#ifndef DISTORTIONDIALOG_H | ||
2 | +#define DISTORTIONDIALOG_H | ||
3 | + | ||
4 | +#include <QtGui/QDialog> | ||
5 | +#include <QDragEnterEvent> | ||
6 | +#include <QGraphicsScene> | ||
7 | +#include <QGraphicsView> | ||
8 | +#include <QGraphicsPixmapItem> | ||
9 | +#include <qfiledialog.h> | ||
10 | +#include <qinputdialog.h> | ||
11 | +#include "ui_distortiondialog.h" | ||
12 | +#include "globals.h" | ||
13 | + | ||
14 | +extern QGraphicsScene* distortionScene; | ||
15 | +extern QGraphicsView* distortionWindow; | ||
16 | +extern QGraphicsPixmapItem* pixmapItem; | ||
17 | + | ||
18 | +class qtDistortionDialog : public QDialog | ||
19 | +{ | ||
20 | + Q_OBJECT | ||
21 | + | ||
22 | +public: | ||
23 | + qtDistortionDialog(QWidget *parent = 0, Qt::WFlags flags = 0); | ||
24 | + ~qtDistortionDialog(); | ||
25 | + bool updating; | ||
26 | + | ||
27 | +private: | ||
28 | + Ui::DistortionDialogClass ui; | ||
29 | + | ||
30 | +public slots: | ||
31 | + void on_btnComputeDistortionMap_clicked(){ | ||
32 | + | ||
33 | + int steps = 100; | ||
34 | + | ||
35 | + //delete the pixmap if one previously existed | ||
36 | + if(pixmapItem != NULL) | ||
37 | + delete(pixmapItem); | ||
38 | + | ||
39 | + //create an image | ||
40 | + QImage image(steps, steps, QImage::Format_RGB888); | ||
41 | + | ||
42 | + QColor color(255, 255, 0); | ||
43 | + | ||
44 | + | ||
45 | + //compute the distortion map | ||
46 | + float* distortionMap = (float*)malloc(sizeof(float) * steps * steps); | ||
47 | + DistortionMap(distortionMap, steps); | ||
48 | + | ||
49 | + //compute the extrema | ||
50 | + float minDistortion = 99999; | ||
51 | + float maxDistortion = distortionMap[0]; | ||
52 | + for(int i=1; i<steps*steps; i++){ | ||
53 | + if(distortionMap[i] < minDistortion && distortionMap[i] > 0) | ||
54 | + minDistortion = distortionMap[i]; | ||
55 | + if(distortionMap[i] > maxDistortion) | ||
56 | + maxDistortion = distortionMap[i]; | ||
57 | + } | ||
58 | + cout<<minDistortion<<"----------"<<maxDistortion<<endl; | ||
59 | + | ||
60 | + //compute the distortion map image | ||
61 | + int i, o; | ||
62 | + float intensity; | ||
63 | + float v; | ||
64 | + for(i=0; i<steps; i++) | ||
65 | + for(o=0; o<steps; o++){ | ||
66 | + v = distortionMap[o * steps + i]; | ||
67 | + intensity = (v - minDistortion) / (maxDistortion - minDistortion) * 255; | ||
68 | + | ||
69 | + if(intensity < 0) {cout<<"low intensity"<<endl; intensity = 0;} | ||
70 | + | ||
71 | + //QColor color(intensity, (float)o / (float)steps * 255, (float)i / (float)steps * 255); | ||
72 | + QColor color(intensity, intensity, intensity); | ||
73 | + image.setPixel(o, (steps-1-i), color.rgb()); | ||
74 | + } | ||
75 | + | ||
76 | + pixmapItem = new QGraphicsPixmapItem(QPixmap::fromImage(image)); | ||
77 | + distortionScene->addItem(pixmapItem); | ||
78 | + distortionWindow->show(); | ||
79 | + | ||
80 | + | ||
81 | + } | ||
82 | +}; | ||
83 | + | ||
84 | +#endif |