1 | #include "QCameraWidget.h"
|
---|
2 | #include <sstream>
|
---|
3 | #include <iostream>
|
---|
4 |
|
---|
5 | QCameraWidget::QCameraWidget(QWidget *pparent) : BasicGlCamera(pparent)
|
---|
6 | {
|
---|
7 | fWhite = 0;
|
---|
8 | fBold.resize(1440);
|
---|
9 | fEnable.resize(1440);
|
---|
10 | fBold.assign(1440, false);
|
---|
11 | fEnable.assign(1440, true);
|
---|
12 | fMin = -1;
|
---|
13 | fMax = -1;
|
---|
14 | CalculatePixelsColor();
|
---|
15 | }
|
---|
16 | void QCameraWidget::paintGL()
|
---|
17 | {
|
---|
18 | glClear(GL_COLOR_BUFFER_BIT);
|
---|
19 | glLoadIdentity();
|
---|
20 |
|
---|
21 | glTranslatef(0,-0.44,0);
|
---|
22 | glScalef(1.5, 1.5, 1.5);
|
---|
23 | drawCamera(true);
|
---|
24 | drawPatches();
|
---|
25 |
|
---|
26 | glLineWidth(1.0f);
|
---|
27 | glColor3f(1,1,1);
|
---|
28 | drawHexagon(fWhite, false);
|
---|
29 | }
|
---|
30 | void QCameraWidget::drawCamera(bool alsoWire)
|
---|
31 | {
|
---|
32 | glLineWidth(1.0);
|
---|
33 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
---|
34 | {
|
---|
35 | glColor3fv(pixelsColor[i]);
|
---|
36 | glLoadName(i);
|
---|
37 | drawHexagon(i,true);
|
---|
38 | }
|
---|
39 | if (!alsoWire)
|
---|
40 | return;
|
---|
41 | glColor3f(0.0f,0.0f,0.0f);
|
---|
42 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
---|
43 | {
|
---|
44 | drawHexagon(i, false);
|
---|
45 | }
|
---|
46 | }
|
---|
47 | void QCameraWidget::Reset()
|
---|
48 | {
|
---|
49 | fBold.assign(1440, false);
|
---|
50 | }
|
---|
51 | void QCameraWidget::mousePressEvent(QMouseEvent *cEvent)
|
---|
52 | {
|
---|
53 | int face = PixelAtPosition(cEvent->pos());
|
---|
54 | if (face != -1) {
|
---|
55 | fWhite = face;
|
---|
56 | emit signalCurrentPixel(face);
|
---|
57 | updateGL();
|
---|
58 | }
|
---|
59 | }
|
---|
60 | void QCameraWidget::mouseMoveEvent(QMouseEvent* cEvent)
|
---|
61 | {
|
---|
62 | int face = PixelAtPosition(cEvent->pos());
|
---|
63 | if (face != -1) {
|
---|
64 | emit signalPixelMoveOver(face);
|
---|
65 | }
|
---|
66 | }
|
---|
67 | void QCameraWidget::mouseDoubleClickEvent(QMouseEvent* cEvent)
|
---|
68 | {
|
---|
69 | int face = PixelAtPosition(cEvent->pos());
|
---|
70 | if (face != -1) {
|
---|
71 | fWhite = face;
|
---|
72 | emit signalPixelDoubleClick(face);
|
---|
73 | updateGL();
|
---|
74 | }
|
---|
75 | }
|
---|
76 | void QCameraWidget::SetBold(int idx)
|
---|
77 | {
|
---|
78 | //cout << "Boldness not taken into account yet" << endl;
|
---|
79 | }
|
---|
80 | void QCameraWidget::SetWhite(int idx)
|
---|
81 | {
|
---|
82 | fWhite = idx;
|
---|
83 | }
|
---|
84 | void QCameraWidget::SetEnable(int idx, bool b)
|
---|
85 | {
|
---|
86 | fEnable[idx] = b;
|
---|
87 | }
|
---|
88 | void QCameraWidget::Toggle(int idx)
|
---|
89 | {
|
---|
90 | }
|
---|
91 | double QCameraWidget::GetData(int idx)
|
---|
92 | {
|
---|
93 | return fData[idx];
|
---|
94 | }
|
---|
95 | void QCameraWidget::SetMin(int64_t min)
|
---|
96 | {
|
---|
97 | fMin = min;
|
---|
98 | CalculatePixelsColor();
|
---|
99 | }
|
---|
100 | void QCameraWidget::SetMax(int64_t max)
|
---|
101 | {
|
---|
102 | fMax = max;
|
---|
103 | CalculatePixelsColor();
|
---|
104 | }
|
---|
105 | const char* QCameraWidget::GetName()
|
---|
106 | {
|
---|
107 | return "QCameraWidget";
|
---|
108 | }
|
---|
109 | char *QCameraWidget::GetObjectInfo(int px, int py)
|
---|
110 | {
|
---|
111 |
|
---|
112 | static stringstream stream;
|
---|
113 | static string str;
|
---|
114 | const int pixel = this->PixelAtPosition(QPoint(px, py));
|
---|
115 | if (pixel >= 0)
|
---|
116 | {
|
---|
117 | stream << "Pixel=" << pixel << " Data=" << fData[pixel] << '\0';
|
---|
118 | }
|
---|
119 | str = stream.str();
|
---|
120 | return const_cast<char*>(str.c_str());
|
---|
121 | }
|
---|
122 | void QCameraWidget::CalculatePixelsColor()
|
---|
123 | {
|
---|
124 | double dmin = fData[0];
|
---|
125 | double dmax = fData[0];
|
---|
126 | for (int i=0;i<1440;i++)
|
---|
127 | {
|
---|
128 | if (!fEnable[i]) continue;
|
---|
129 | if (fData[i] > dmax) dmax = fData[i];
|
---|
130 | if (fData[i] < dmin) dmin = fData[i];
|
---|
131 | }
|
---|
132 | if (fMin >= 0) dmin = fMin;
|
---|
133 | if (fMax >= 0) dmax = fMax;
|
---|
134 | float color;
|
---|
135 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
---|
136 | {
|
---|
137 | color = float((fData[i]-dmin)/(dmax-dmin));
|
---|
138 | if (!fEnable[i])
|
---|
139 | color = 0;
|
---|
140 | int index = 0;
|
---|
141 | while (ss[index] < color)
|
---|
142 | index++;
|
---|
143 | index--;
|
---|
144 | if (index < 0) index = 0;
|
---|
145 | if (index > 3) index = 3;
|
---|
146 | float weight0 = (color-ss[index]) / (ss[index+1]-ss[index]);
|
---|
147 | if (weight0 > 1.0f) weight0 = 1.0f;
|
---|
148 | if (weight0 < 0.0f) weight0 = 0.0f;
|
---|
149 | float weight1 = 1.0f-weight0;
|
---|
150 | pixelsColor[i][0] = weight1*rr[index] + weight0*rr[index+1];
|
---|
151 | pixelsColor[i][1] = weight1*gg[index] + weight0*gg[index+1];
|
---|
152 | pixelsColor[i][2] = weight1*bb[index] + weight0*bb[index+1];
|
---|
153 | }
|
---|
154 | }
|
---|
155 | void QCameraWidget::SetData(const valarray<double> &ddata)
|
---|
156 | {
|
---|
157 | // fData = ddata;
|
---|
158 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
---|
159 | fData[i] = ddata[i];
|
---|
160 | CalculatePixelsColor();
|
---|
161 | updateGL();
|
---|
162 | }
|
---|