Blame view

qtDistortionDialog.h 2.39 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
  #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
  {
8ffb8373   dmayerich   Improved material...
20
      Q_OBJECT
29e744fa   dmayerich   Added QT dialog b...
21
22
  
  public:
8ffb8373   dmayerich   Improved material...
23
24
25
      qtDistortionDialog(QWidget *parent = 0, Qt::WFlags flags = 0);
      ~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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  
          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];
8ffb8373   dmayerich   Improved material...
52
          for(int i=1; i<steps*steps; i++) {
29e744fa   dmayerich   Added QT dialog b...
53
54
55
56
57
58
59
60
61
62
63
64
              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++)
8ffb8373   dmayerich   Improved material...
65
              for(o=0; o<steps; o++) {
29e744fa   dmayerich   Added QT dialog b...
66
67
68
                  v = distortionMap[o * steps + i];
                  intensity = (v - minDistortion) / (maxDistortion - minDistortion) * 255;
  
8ffb8373   dmayerich   Improved material...
69
70
71
72
                  if(intensity < 0) {
                      cout<<"low intensity"<<endl;
                      intensity = 0;
                  }
29e744fa   dmayerich   Added QT dialog b...
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
  
                  //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