Blame view

qtDistortionDialog.h 2.32 KB
29e744fa   dmayerich   Added QT dialog b...
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
  #ifndef DISTORTIONDIALOG_H
  #define DISTORTIONDIALOG_H
  
  #include <QtGui/QDialog>
  #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
  {
  	Q_OBJECT
  
  public:
  	qtDistortionDialog(QWidget *parent = 0, Qt::WFlags flags = 0);
  	~qtDistortionDialog();
  	bool updating;
  
  private:
  	Ui::DistortionDialogClass ui;
  
  public slots:
      void on_btnComputeDistortionMap_clicked(){
  
          int steps = 100;
  
          //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);
  
  
          //compute the distortion map
          float* distortionMap = (float*)malloc(sizeof(float) * steps * steps);
          DistortionMap(distortionMap, steps);
  
          //compute the extrema
          float minDistortion = 99999;
          float maxDistortion = distortionMap[0];
          for(int i=1; i<steps*steps; i++){
              if(distortionMap[i] < minDistortion && distortionMap[i] > 0)
                  minDistortion = distortionMap[i];
              if(distortionMap[i] > maxDistortion)
                  maxDistortion = distortionMap[i];
          }
          cout<<minDistortion<<"----------"<<maxDistortion<<endl;
  
          //compute the distortion map image
          int i, o;
          float intensity;
          float v;
          for(i=0; i<steps; i++)
              for(o=0; o<steps; o++){
                  v = distortionMap[o * steps + i];
                  intensity = (v - minDistortion) / (maxDistortion - minDistortion) * 255;
  
                  if(intensity < 0) {cout<<"low intensity"<<endl; intensity = 0;}
  
                  //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