#include "QCameraWidget.h" #include #include #include using namespace std; QCameraWidget::QCameraWidget(QWidget *pparent) : BasicGlCamera(pparent) { fBold.resize(1440, false); fEnable.resize(1440, true); lastFace = -1; fShowPixelMoveOver = false; fShowPatchMoveOver = false; fDrawPatch = false; CalculatePixelsColor(); } void QCameraWidget::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(0,-0.44,0); glTranslatef(-0.1,0,0); glRotatef(cameraRotation, 0,0,-1); if (cameraRotation == 90) { glTranslatef(-0.45,-0.45,0); // cout << "correction" << endl; } if (cameraRotation == -90) { glTranslatef(0.45,-0.45,0); } glScalef(1.5, 1.5, 1.0); glTranslatef(0,0,-0.5); drawCamera(true); glTranslatef(0,0,0.1f); if (fDrawPatch) drawPatches(); glTranslatef(0,0,0.1f); glLineWidth(1.0f); glColor3fv(highlightedPixelsCoulour); for (vector::iterator it = highlightedPixels.begin(); it!= highlightedPixels.end(); it++) { drawHexagon(*it, false); } glLineWidth(1.0f); glTranslatef(0,0,0.1f); //glColor3f(1.f - pixelsColor[fWhite][0],1.f - pixelsColor[fWhite][1],1.f - pixelsColor[fWhite][2]); if (fWhite != -1) { glColor3f(1.f, 0.f, 0.f); drawHexagon(fWhite, false); } DrawCameraText(); DrawScale(); // if (linearButton->isVisible()) // repaintInterface(); } void QCameraWidget::drawCamera(bool alsoWire) { if (!pixelColorUpToDate) CalculatePixelsColor(); glLineWidth(1.0); for (int i=0;i 12) fontWidth--; if (fTextSize > 10) fontWidth--; if (fTextSize > 7) fontWidth--;//else fontWidth -=1; // if (fTextSize < 7) fontWidth++; for (int i=0;i<11;i++) { str.str(""); str << value; if (i==0 || i==10) str << ' ' << unitsText; str << ' '; int h = (value - min)*pixelSpan; if (logScale && h != 0) { float fh = h; float mult = (max - min)*pixelSpan; fh = log10(h*10.f/mult); fh *= mult; h = (int)fh; } h = height()-h; int w = width() - (width()/50) - fontWidth*str.str().size(); if (i==0 || i==10) w -= width()/50; if (i!=0 && i!=10) h -= fTextSize/2; renderText(w, h, QString(str.str().c_str())); value += (max - min)/10; } /* str.str(""); str << min << unitsText; int fontWidth = textSize; if (textSize > 12) fontWidth-=3; else fontWidth -= 2; //height of min ? int hmin = (min - min)*pixelSpan; hmin = height() - hmin; renderText(width() - (width()/25) - fontWidth*str.str().size(), hmin, QString(str.str().c_str())); str.str(""); str << max << unitsText; int hmax = (max - min)*pixelSpan; hmax = height() - hmax; renderText(width() - (width()/25) - fontWidth*str.str().size(), hmax, QString(str.str().c_str())); */ glPopMatrix(); // textSize = (int)(600*14/600); // setFont(QFont("Times", textSize)); } void QCameraWidget::drawPatches() { glLineWidth(3.0f); glColor3fv(patchesCoulour); glBegin(GL_LINES); for (int i=0;i::iterator it=highlightedPatches.begin(); it!= highlightedPatches.end(); it++) { for (unsigned int j=0;jpos().x() > width()-(width()/50.f)) { toggleInterfaceDisplay(); return; } int face = PixelAtPosition(cEvent->pos()); // cout << face << endl; if (face != -1) { fWhite = face; fWhitePatch = pixelsPatch[fWhite]; // CalculatePatchColor(); emit signalCurrentPixel(face); } else { fWhite = -1; fWhitePatch = -1; } updateGL(); } void QCameraWidget::mouseMoveEvent(QMouseEvent* cEvent) { int face = PixelAtPosition(cEvent->pos()); if (face != -1 && lastFace != face) { emit signalPixelMoveOver(face); } if (lastFace != face) { if (fShowPixelMoveOver) fWhite = face; if (fShowPatchMoveOver) fWhitePatch = face != -1 ? pixelsPatch[face] : -1; } if (fShowPixelMoveOver || fShowPatchMoveOver) if (lastFace != face && isVisible()) updateGL(); lastFace = face; } void QCameraWidget::mouseDoubleClickEvent(QMouseEvent* cEvent) { int face = PixelAtPosition(cEvent->pos()); if (face != -1) { // cout << "Event !" << endl; fWhite = face; fWhitePatch = pixelsPatch[fWhite]; // highlightPixel(face); // highlightPatch(fWhitePatch); // CalculatePatchColor(); emit signalPixelDoubleClick(face); } else { fWhite = -1; fWhitePatch = -1; // clearHighlightedPixels(); // clearHighlightedPatches(); } updateGL(); } void QCameraWidget::ShowPixelCursor(bool on) { fShowPixelMoveOver = on; if (isVisible() && autoRefresh) updateGL(); } void QCameraWidget::ShowPatchCursor(bool on) { fShowPatchMoveOver = on; if (isVisible() && autoRefresh) updateGL(); } void QCameraWidget::SetEnable(int idx, bool b) { fEnable[idx] = b; } double QCameraWidget::GetData(int idx) { return fData[idx]; } const char* QCameraWidget::GetName() { return "QCameraWidget"; } char *QCameraWidget::GetObjectInfo(int px, int py) { static stringstream stream; static string str; const int pixel = this->PixelAtPosition(QPoint(px, py)); if (pixel >= 0) { stream << "Pixel=" << pixel << " Data=" << fData[pixel] << '\0'; } str = stream.str(); return const_cast(str.c_str()); } void QCameraWidget::CalculatePixelsColor() { double dmin = fData[0]; double dmax = fData[0]; for (int ii=0;ii dmax) dmax = fData[i]; if (fData[i] < dmin) dmin = fData[i]; } } if (fMin > fScaleLimit) dmin = fMin; if (fMax > fScaleLimit) dmax = fMax; // cout << "min: " << dmin << " max: " << dmax << " fMin: " << fMin << " fMax: " << fMax << endl; float color; for (int i=0;i dmax) { pixelsColor[i][0] = tooHighValueCoulour[0]; pixelsColor[i][1] = tooHighValueCoulour[1]; pixelsColor[i][2] = tooHighValueCoulour[2]; continue; } color = float((fData[i]-dmin)/(dmax-dmin)); if (logScale) { color *= 9; color += 1; color = log10(color); } int index = 0; while (ss[index] < color && index < 4) index++; index--; if (index < 0) index = 0; float weight0 = (color-ss[index]) / (ss[index+1]-ss[index]); if (weight0 > 1.0f) weight0 = 1.0f; if (weight0 < 0.0f) weight0 = 0.0f; float weight1 = 1.0f-weight0; pixelsColor[i][0] = weight1*rr[index] + weight0*rr[index+1]; pixelsColor[i][1] = weight1*gg[index] + weight0*gg[index+1]; pixelsColor[i][2] = weight1*bb[index] + weight0*bb[index+1]; } CalculatePatchColor(); UpdateText(); pixelColorUpToDate = true; } void QCameraWidget::CalculatePatchColor() { return; //calculate the patch contour color. let's use the anti-colour of the pixels GLfloat averagePatchColour[3] = {0.0f,0.0f,0.0f}; for (int i=0;i<9;i++) for (int j=0;j<3;j++) averagePatchColour[j] += pixelsColor[softwareMapping[fWhitePatch*9+i]][j]; for (int j=0;j<3;j++) averagePatchColour[j] /= 9; for (int j=0;j<3;j++) patchColour[j] = 1.0f - averagePatchColour[j]; } void QCameraWidget::SetData(const valarray &ddata) { // fData = ddata; for (int i=0;i &ddata) { // fData = ddata; for (int i=0;i= ACTUAL_NUM_PIXELS) { cout << "Error: requested pixel highlight out of bounds" << endl; return; } const vector::iterator v = ::find(highlightedPixels.begin(), highlightedPixels.end(), idx); if (highlight) { if (v==highlightedPixels.end()) highlightedPixels.push_back(idx); } else { if (v!=highlightedPixels.end()) highlightedPixels.erase(v); } if (isVisible() && autoRefresh) updateGL(); } void QCameraWidget::highlightPatch(int idx, bool highlight) { if (idx < 0 || idx >= NTMARK) { cout << "Error: requested patch highlight out of bounds" << endl; return; } const vector::iterator v = ::find(highlightedPatches.begin(), highlightedPatches.end(), idx); if (highlight) { if (v==highlightedPatches.end()) highlightedPatches.push_back(idx); } else { if (v!=highlightedPatches.end()) highlightedPatches.erase(v); } if (isVisible() && autoRefresh) updateGL(); } void QCameraWidget::clearHighlightedPatches() { highlightedPatches.clear(); if (isVisible() && autoRefresh) updateGL(); } void QCameraWidget::clearHighlightedPixels() { highlightedPixels.clear(); if (isVisible() && autoRefresh) updateGL(); }