| 1 | #include "QCameraWidget.h"
|
|---|
| 2 | #include <sstream>
|
|---|
| 3 | #include <iostream>
|
|---|
| 4 |
|
|---|
| 5 | QCameraWidget::QCameraWidget(QWidget *pparent) : BasicGlCamera(pparent)
|
|---|
| 6 | {
|
|---|
| 7 | fBold.resize(1440);
|
|---|
| 8 | fEnable.resize(1440);
|
|---|
| 9 | fBold.assign(1440, false);
|
|---|
| 10 | fEnable.assign(1440, true);
|
|---|
| 11 | lastFace = -1;
|
|---|
| 12 |
|
|---|
| 13 | CalculatePixelsColor();
|
|---|
| 14 |
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | void QCameraWidget::paintGL()
|
|---|
| 18 | {
|
|---|
| 19 | glClear(GL_COLOR_BUFFER_BIT);
|
|---|
| 20 | glLoadIdentity();
|
|---|
| 21 |
|
|---|
| 22 | glTranslatef(0,-0.44,0);
|
|---|
| 23 | glRotatef(cameraRotation, 0,0,-1);
|
|---|
| 24 | if (cameraRotation == 90)
|
|---|
| 25 | {
|
|---|
| 26 | glTranslatef(-0.45,-0.45,0);
|
|---|
| 27 | // cout << "correction" << endl;
|
|---|
| 28 | }
|
|---|
| 29 | if (cameraRotation == -90)
|
|---|
| 30 | {
|
|---|
| 31 | glTranslatef(0.45,-0.45,0);
|
|---|
| 32 | }
|
|---|
| 33 | glScalef(1.5, 1.5, 1.5);
|
|---|
| 34 | drawCamera(true);
|
|---|
| 35 |
|
|---|
| 36 | glLineWidth(1.0f);
|
|---|
| 37 | glColor3fv(highlightedPixelsCoulour);
|
|---|
| 38 | for (vector<int>::iterator it = highlightedPixels.begin(); it!= highlightedPixels.end(); it++)
|
|---|
| 39 | {
|
|---|
| 40 | drawHexagon(*it, false);
|
|---|
| 41 | }
|
|---|
| 42 | drawPatches();
|
|---|
| 43 |
|
|---|
| 44 | glLineWidth(1.0f);
|
|---|
| 45 |
|
|---|
| 46 | //glColor3f(1.f - pixelsColor[fWhite][0],1.f - pixelsColor[fWhite][1],1.f - pixelsColor[fWhite][2]);
|
|---|
| 47 | if (fWhite != -1)
|
|---|
| 48 | {
|
|---|
| 49 | glColor3f(1.f, 0.f, 0.f);
|
|---|
| 50 | drawHexagon(fWhite, false);
|
|---|
| 51 | }
|
|---|
| 52 | DrawCameraText();
|
|---|
| 53 |
|
|---|
| 54 | DrawScale();
|
|---|
| 55 |
|
|---|
| 56 | // if (linearButton->isVisible())
|
|---|
| 57 | // repaintInterface();
|
|---|
| 58 | }
|
|---|
| 59 | void QCameraWidget::drawCamera(bool alsoWire)
|
|---|
| 60 | {
|
|---|
| 61 | if (!pixelColorUpToDate)
|
|---|
| 62 | CalculatePixelsColor();
|
|---|
| 63 | glLineWidth(1.0);
|
|---|
| 64 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
|---|
| 65 | {
|
|---|
| 66 | glColor3fv(pixelsColor[i]);
|
|---|
| 67 | glLoadName(i);
|
|---|
| 68 | drawHexagon(i,true);
|
|---|
| 69 | }
|
|---|
| 70 | if (!alsoWire)
|
|---|
| 71 | return;
|
|---|
| 72 | glColor3fv(pixelContourColour);//0.0f,0.0f,0.0f);
|
|---|
| 73 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
|---|
| 74 | {
|
|---|
| 75 | drawHexagon(i, false);
|
|---|
| 76 | }
|
|---|
| 77 | }
|
|---|
| 78 | void QCameraWidget::drawPatches()
|
|---|
| 79 | {
|
|---|
| 80 | glLineWidth(2.0f);
|
|---|
| 81 | glColor3fv(patchesCoulour);
|
|---|
| 82 | glBegin(GL_LINES);
|
|---|
| 83 | for (int i=0;i<NTMARK;i++)
|
|---|
| 84 | {
|
|---|
| 85 | for (unsigned int j=0;j<patchesIndices[i].size();j++)
|
|---|
| 86 | {
|
|---|
| 87 | glVertex2fv(verticesList[patchesIndices[i][j].first]);
|
|---|
| 88 | glVertex2fv(verticesList[patchesIndices[i][j].second]);
|
|---|
| 89 | }
|
|---|
| 90 | }
|
|---|
| 91 | glEnd();
|
|---|
| 92 |
|
|---|
| 93 | glColor3fv(highlightedPatchesCoulour);
|
|---|
| 94 | glBegin(GL_LINES);
|
|---|
| 95 | for (vector<int>::iterator it=highlightedPatches.begin(); it!= highlightedPatches.end(); it++)
|
|---|
| 96 | {
|
|---|
| 97 | for (unsigned int j=0;j<patchesIndices[*it].size();j++)
|
|---|
| 98 | {
|
|---|
| 99 | glVertex2fv(verticesList[patchesIndices[*it][j].first]);
|
|---|
| 100 | glVertex2fv(verticesList[patchesIndices[*it][j].second]);
|
|---|
| 101 | }
|
|---|
| 102 | }
|
|---|
| 103 | glEnd();
|
|---|
| 104 | if (fWhitePatch != -1)
|
|---|
| 105 | {
|
|---|
| 106 | glColor3f(1.f, 0.5f, 0.f);//patchColour);//[0],patchColour[1],patchColour[2]);//0.5f, 0.5f, 0.3f);
|
|---|
| 107 | glBegin(GL_LINES);
|
|---|
| 108 | for (unsigned int j=0;j<patchesIndices[fWhitePatch].size();j++)
|
|---|
| 109 | {
|
|---|
| 110 | glVertex2fv(verticesList[patchesIndices[fWhitePatch][j].first]);
|
|---|
| 111 | glVertex2fv(verticesList[patchesIndices[fWhitePatch][j].second]);
|
|---|
| 112 | }
|
|---|
| 113 | glEnd();
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | }
|
|---|
| 117 | void QCameraWidget::Reset()
|
|---|
| 118 | {
|
|---|
| 119 | fBold.assign(1440, false);
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | void QCameraWidget::mousePressEvent(QMouseEvent *cEvent)
|
|---|
| 123 | {
|
|---|
| 124 | if (cEvent->pos().x() > width()-(width()/50.f))
|
|---|
| 125 | {
|
|---|
| 126 | toggleInterfaceDisplay();
|
|---|
| 127 | return;
|
|---|
| 128 | }
|
|---|
| 129 | int face = PixelAtPosition(cEvent->pos());
|
|---|
| 130 | if (face != -1) {
|
|---|
| 131 | fWhite = face;
|
|---|
| 132 | fWhitePatch = pixelsPatch[fWhite];
|
|---|
| 133 | // CalculatePatchColor();
|
|---|
| 134 | emit signalCurrentPixel(face);
|
|---|
| 135 | }
|
|---|
| 136 | else
|
|---|
| 137 | {
|
|---|
| 138 | fWhite = -1;
|
|---|
| 139 | fWhitePatch = -1;
|
|---|
| 140 | }
|
|---|
| 141 | updateGL();
|
|---|
| 142 | }
|
|---|
| 143 | void QCameraWidget::mouseMoveEvent(QMouseEvent* cEvent)
|
|---|
| 144 | {
|
|---|
| 145 | int face = PixelAtPosition(cEvent->pos());
|
|---|
| 146 | if (face != -1 && lastFace != face) {
|
|---|
| 147 | emit signalPixelMoveOver(face);
|
|---|
| 148 | }
|
|---|
| 149 | lastFace = face;
|
|---|
| 150 | }
|
|---|
| 151 | void QCameraWidget::mouseDoubleClickEvent(QMouseEvent* cEvent)
|
|---|
| 152 | {
|
|---|
| 153 | int face = PixelAtPosition(cEvent->pos());
|
|---|
| 154 | if (face != -1) {
|
|---|
| 155 | // cout << "Event !" << endl;
|
|---|
| 156 | fWhite = face;
|
|---|
| 157 | fWhitePatch = pixelsPatch[fWhite];
|
|---|
| 158 | highlightPixel(face);
|
|---|
| 159 | highlightPatch(fWhitePatch);
|
|---|
| 160 | // CalculatePatchColor();
|
|---|
| 161 | emit signalPixelDoubleClick(face);
|
|---|
| 162 | }
|
|---|
| 163 | else
|
|---|
| 164 | {
|
|---|
| 165 | fWhite = -1;
|
|---|
| 166 | fWhitePatch = -1;
|
|---|
| 167 | clearHighlightedPixels();
|
|---|
| 168 | clearHighlightedPatches();
|
|---|
| 169 | }
|
|---|
| 170 | updateGL();
|
|---|
| 171 |
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | void QCameraWidget::SetEnable(int idx, bool b)
|
|---|
| 175 | {
|
|---|
| 176 | fEnable[idx] = b;
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | double QCameraWidget::GetData(int idx)
|
|---|
| 180 | {
|
|---|
| 181 | return fData[idx];
|
|---|
| 182 | }
|
|---|
| 183 | const char* QCameraWidget::GetName()
|
|---|
| 184 | {
|
|---|
| 185 | return "QCameraWidget";
|
|---|
| 186 | }
|
|---|
| 187 | char *QCameraWidget::GetObjectInfo(int px, int py)
|
|---|
| 188 | {
|
|---|
| 189 |
|
|---|
| 190 | static stringstream stream;
|
|---|
| 191 | static string str;
|
|---|
| 192 | const int pixel = this->PixelAtPosition(QPoint(px, py));
|
|---|
| 193 | if (pixel >= 0)
|
|---|
| 194 | {
|
|---|
| 195 | stream << "Pixel=" << pixel << " Data=" << fData[pixel] << '\0';
|
|---|
| 196 | }
|
|---|
| 197 | str = stream.str();
|
|---|
| 198 | return const_cast<char*>(str.c_str());
|
|---|
| 199 | }
|
|---|
| 200 | void QCameraWidget::CalculatePixelsColor()
|
|---|
| 201 | {
|
|---|
| 202 | double dmin = fData[0];
|
|---|
| 203 | double dmax = fData[0];
|
|---|
| 204 | if (fMin < 0 || fMax < 0)
|
|---|
| 205 | {
|
|---|
| 206 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
|---|
| 207 | {
|
|---|
| 208 | if (!fEnable[i]) continue;
|
|---|
| 209 | if (fData[i] > dmax) dmax = fData[i];
|
|---|
| 210 | if (fData[i] < dmin) dmin = fData[i];
|
|---|
| 211 | }
|
|---|
| 212 | }
|
|---|
| 213 | if (fMin >= 0) dmin = fMin;
|
|---|
| 214 | if (fMax >= 0) dmax = fMax;
|
|---|
| 215 | // cout << "min: " << dmin << " max: " << dmax << " fMin: " << fMin << " fMax: " << fMax << endl;
|
|---|
| 216 | float color;
|
|---|
| 217 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
|---|
| 218 | {
|
|---|
| 219 | if (!fEnable[i])
|
|---|
| 220 | {
|
|---|
| 221 | // cout << "not enabled !" << i << endl;
|
|---|
| 222 | pixelsColor[i][0] = 0.1f;
|
|---|
| 223 | pixelsColor[i][1] = 0.1f;
|
|---|
| 224 | pixelsColor[i][2] = 0.15f;
|
|---|
| 225 | continue;
|
|---|
| 226 | }
|
|---|
| 227 | if (fData[i] < dmin)
|
|---|
| 228 | {
|
|---|
| 229 | pixelsColor[i][0] = tooLowValueCoulour[0];
|
|---|
| 230 | pixelsColor[i][1] = tooLowValueCoulour[1];
|
|---|
| 231 | pixelsColor[i][2] = tooLowValueCoulour[2];
|
|---|
| 232 | continue;
|
|---|
| 233 | }
|
|---|
| 234 | if (fData[i] > dmax)
|
|---|
| 235 | {
|
|---|
| 236 | pixelsColor[i][0] = tooHighValueCoulour[0];
|
|---|
| 237 | pixelsColor[i][1] = tooHighValueCoulour[1];
|
|---|
| 238 | pixelsColor[i][2] = tooHighValueCoulour[2];
|
|---|
| 239 | continue;
|
|---|
| 240 | }
|
|---|
| 241 | color = float((fData[i]-dmin)/(dmax-dmin));
|
|---|
| 242 | if (logScale)
|
|---|
| 243 | {
|
|---|
| 244 | color *= 9;
|
|---|
| 245 | color += 1;
|
|---|
| 246 | color = log10(color);
|
|---|
| 247 | }
|
|---|
| 248 |
|
|---|
| 249 | int index = 0;
|
|---|
| 250 | while (ss[index] < color && index < 4)
|
|---|
| 251 | index++;
|
|---|
| 252 | index--;
|
|---|
| 253 | if (index < 0) index = 0;
|
|---|
| 254 | float weight0 = (color-ss[index]) / (ss[index+1]-ss[index]);
|
|---|
| 255 | if (weight0 > 1.0f) weight0 = 1.0f;
|
|---|
| 256 | if (weight0 < 0.0f) weight0 = 0.0f;
|
|---|
| 257 | float weight1 = 1.0f-weight0;
|
|---|
| 258 | pixelsColor[i][0] = weight1*rr[index] + weight0*rr[index+1];
|
|---|
| 259 | pixelsColor[i][1] = weight1*gg[index] + weight0*gg[index+1];
|
|---|
| 260 | pixelsColor[i][2] = weight1*bb[index] + weight0*bb[index+1];
|
|---|
| 261 | }
|
|---|
| 262 | CalculatePatchColor();
|
|---|
| 263 | UpdateText();
|
|---|
| 264 | pixelColorUpToDate = true;
|
|---|
| 265 | }
|
|---|
| 266 | void QCameraWidget::CalculatePatchColor()
|
|---|
| 267 | {
|
|---|
| 268 | return;
|
|---|
| 269 | //calculate the patch contour color. let's use the anti-colour of the pixels
|
|---|
| 270 | GLfloat averagePatchColour[3] = {0.0f,0.0f,0.0f};
|
|---|
| 271 | for (int i=0;i<9;i++)
|
|---|
| 272 | for (int j=0;j<3;j++)
|
|---|
| 273 | averagePatchColour[j] += pixelsColor[softwareMapping[patches[fWhitePatch][i]]][j];
|
|---|
| 274 | for (int j=0;j<3;j++)
|
|---|
| 275 | averagePatchColour[j] /= 9;
|
|---|
| 276 | for (int j=0;j<3;j++)
|
|---|
| 277 | patchColour[j] = 1.0f - averagePatchColour[j];
|
|---|
| 278 | }
|
|---|
| 279 | void QCameraWidget::SetData(const valarray<double> &ddata)
|
|---|
| 280 | {
|
|---|
| 281 | // fData = ddata;
|
|---|
| 282 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
|---|
| 283 | fData[i] = ddata[i];
|
|---|
| 284 | pixelColorUpToDate = false;
|
|---|
| 285 | if (isVisible())
|
|---|
| 286 | updateGL();
|
|---|
| 287 | }
|
|---|
| 288 |
|
|---|
| 289 |
|
|---|
| 290 | void QCameraWidget::highlightPixel(int idx, bool highlight)
|
|---|
| 291 | {
|
|---|
| 292 | if (idx < 0 || idx > ACTUAL_NUM_PIXELS)
|
|---|
| 293 | {
|
|---|
| 294 | cout << "Error: requested pixel highlight out of bounds" << endl;
|
|---|
| 295 | return;
|
|---|
| 296 | }
|
|---|
| 297 |
|
|---|
| 298 | const vector<int>::iterator v = ::find(highlightedPixels.begin(), highlightedPixels.end(), idx);
|
|---|
| 299 | if (highlight)
|
|---|
| 300 | {
|
|---|
| 301 | if (v==highlightedPixels.end())
|
|---|
| 302 | highlightedPixels.push_back(idx);
|
|---|
| 303 | }
|
|---|
| 304 | else
|
|---|
| 305 | {
|
|---|
| 306 | if (v!=highlightedPixels.end())
|
|---|
| 307 | highlightedPixels.erase(v);
|
|---|
| 308 | }
|
|---|
| 309 |
|
|---|
| 310 | if (isVisible())
|
|---|
| 311 | updateGL();
|
|---|
| 312 | }
|
|---|
| 313 | void QCameraWidget::highlightPatch(int idx, bool highlight)
|
|---|
| 314 | {
|
|---|
| 315 | if (idx < 0 || idx > NTMARK)
|
|---|
| 316 | {
|
|---|
| 317 | cout << "Error: requested patch highlight out of bounds" << endl;
|
|---|
| 318 | return;
|
|---|
| 319 | }
|
|---|
| 320 |
|
|---|
| 321 | const vector<int>::iterator v = ::find(highlightedPatches.begin(), highlightedPatches.end(), idx);
|
|---|
| 322 | if (highlight)
|
|---|
| 323 | {
|
|---|
| 324 | if (v==highlightedPatches.end())
|
|---|
| 325 | highlightedPatches.push_back(idx);
|
|---|
| 326 | }
|
|---|
| 327 | else
|
|---|
| 328 | {
|
|---|
| 329 | if (v!=highlightedPatches.end())
|
|---|
| 330 | highlightedPatches.erase(v);
|
|---|
| 331 | }
|
|---|
| 332 |
|
|---|
| 333 | if (isVisible())
|
|---|
| 334 | updateGL();
|
|---|
| 335 |
|
|---|
| 336 | }
|
|---|
| 337 | void QCameraWidget::clearHighlightedPatches()
|
|---|
| 338 | {
|
|---|
| 339 | highlightedPatches.clear();
|
|---|
| 340 | if (isVisible())
|
|---|
| 341 | updateGL();
|
|---|
| 342 | }
|
|---|
| 343 | void QCameraWidget::clearHighlightedPixels()
|
|---|
| 344 | {
|
|---|
| 345 | highlightedPixels.clear();
|
|---|
| 346 | if (isVisible())
|
|---|
| 347 | updateGL();
|
|---|
| 348 | }
|
|---|
| 349 |
|
|---|
| 350 |
|
|---|
| 351 |
|
|---|
| 352 |
|
|---|