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