#include "BasicGlCamera.h" #include #include #include #include #include #include "src/tools.h" //Coordinates of an hexagon of radius 1 and center 0 GLfloat hexcoords[6][2] = {{-1./sqrt(3.), 1}, { 1./sqrt(3.), 1}, { 2./sqrt(3.), 0}, { 1./sqrt(3.), -1}, {-1./sqrt(3.), -1}, {-2./sqrt(3.), 0}}; BasicGlCamera::BasicGlCamera(QWidget* cParent) : QGLWidget(cParent) { setFormat(QGLFormat(QGL::DoubleBuffer));// | QGL::DepthBuffer)); fWhite = -1; fWhitePatch = -1; fMin = -1; fMax = -1; logScale = false; cameraRotation = 0; unitsText = ""; titleText = ""; dataText = ""; pixelContourColour[0] = 0.1f; pixelContourColour[1] = 0.1f; pixelContourColour[2] = 0.1f; patchesCoulour[0] = 0.1f; patchesCoulour[1] = 0.1f; patchesCoulour[2] = 0.1f; highlightedPatchesCoulour[0] = 0.6f; highlightedPatchesCoulour[1] = 0.6f; highlightedPatchesCoulour[2] = 0.6f; highlightedPixelsCoulour[0] = 0.8f; highlightedPixelsCoulour[1] = 0.8f; highlightedPixelsCoulour[2] = 0.8f; regularPalettePlease(true); hexRadius = 0.015f; hexTolerance = hexRadius/100.0f; viewSize = 1.0f; calculatePixelsCoords(); ifstream fin2("MasterList-v3.txt"); if (!fin2.is_open()) { cout << "Error: file \"MasterList-v3\" missing. aborting." << endl; exit(-1); } int l = 0; string buf; while (getline(fin2, buf, '\n')) { buf = Tools::Trim(buf); if (buf[0]=='#') continue; unsigned int softid, hardid, dummy; stringstream str(buf); str >> softid; str >> dummy; str >> hardid; if (softid>=1440) continue; hardwareMapping[softid] = hardid; softwareMapping[hardid] = softid; l++; } // GLfloat tempPixelsCoords[MAX_NUM_PIXELS][3]; // for (int i=0;i<1440;i++) // for (int j=0;j<3;j++) // tempPixelsCoords[hardwareMapping[i]][j] = pixelsCoords[i][j]; // for (int i=0;i<1440;i++) // for (int j=0;j<3;j++) // pixelsCoords[i][j] = tempPixelsCoords[i][j]; buildVerticesList(); ifstream fin1("Trigger-Patches.txt"); if (!fin1.is_open()) { cout << "Error: file \"Trigger-Patches.txt\" missing. Aborting." << endl; exit(-1); } l=0; while (getline(fin1, buf, '\n')) { buf = Tools::Trim(buf); if (buf[0]=='#') continue; stringstream str(buf); for (int i=0; i<9; i++) { unsigned int n; str >> n; if (n>=1440) continue; patches[l][i] = hardwareMapping[n]; } l++; } //now construct the correspondance between pixels and patches for (int i=0;iheight(); linearButton = new QRadioButton("Linear", this); linearButton->move(scaleLabel->width(), buttonShift); buttonShift += linearButton->height(); logButton = new QRadioButton("Log", this); logButton->move(scaleLabel->width(), buttonShift); buttonShift += logButton->height()*1.1f; colorPaletteLabel = new QLabel("Colour\nPalette", this); colorPaletteLabel->move(0, buttonShift); // buttonShift += colorPaletteLabel->height(); regularPaletteButton = new QRadioButton("Regular", this); regularPaletteButton->move(colorPaletteLabel->width(), buttonShift); buttonShift += regularPaletteButton->height(); prettyPaletteButton = new QRadioButton("Pretty", this); prettyPaletteButton->move(colorPaletteLabel->width(), buttonShift); buttonShift += prettyPaletteButton->height(); greyScalePaletteButton = new QRadioButton("Grey Scale", this); greyScalePaletteButton->move(colorPaletteLabel->width(), buttonShift); buttonShift += greyScalePaletteButton->height(); glowingPaletteButton = new QRadioButton("Glowing", this); glowingPaletteButton->move(colorPaletteLabel->width(), buttonShift); buttonShift += glowingPaletteButton->height()*1.1f; rotationLabel = new QLabel("Camera\nRotation", this); rotationLabel->move(0, buttonShift); // buttonShift += rotationLabel->height(); unsigned short utf16Array; utf16Array = 0x00b0; QString degreeSymbol(QString::fromUtf16(&utf16Array, 1)); QString zerostr("0" + degreeSymbol); zeroRotationButton = new QRadioButton(zerostr, this); zeroRotationButton->move(rotationLabel->width(), buttonShift); buttonShift += zeroRotationButton->height(); QString minus90str("-90" + degreeSymbol); minus90RotationButton = new QRadioButton(minus90str, this); minus90RotationButton->move(rotationLabel->width(), buttonShift); buttonShift += minus90RotationButton->height(); QString plus90str("+90"+degreeSymbol); plus90Rotationbutton = new QRadioButton(plus90str, this); plus90Rotationbutton->move(rotationLabel->width(), buttonShift); scaleGroup = new QButtonGroup(this); colorGroup = new QButtonGroup(this); rotationGroup = new QButtonGroup(this); scaleGroup->addButton(linearButton); scaleGroup->addButton(logButton); colorGroup->addButton(regularPaletteButton); colorGroup->addButton(prettyPaletteButton); colorGroup->addButton(greyScalePaletteButton); colorGroup->addButton(glowingPaletteButton); rotationGroup->addButton(zeroRotationButton); rotationGroup->addButton(minus90RotationButton); rotationGroup->addButton(plus90Rotationbutton); linearButton->setChecked(true); regularPaletteButton->setChecked(true); zeroRotationButton->setChecked(true); // linearButton->palette.setColor(); linearButton->setAutoFillBackground(true); logButton->setAutoFillBackground(true); regularPaletteButton->setAutoFillBackground(true); prettyPaletteButton->setAutoFillBackground(true); greyScalePaletteButton->setAutoFillBackground(true); glowingPaletteButton->setAutoFillBackground(true); zeroRotationButton->setAutoFillBackground(true); minus90RotationButton->setAutoFillBackground(true); plus90Rotationbutton->setAutoFillBackground(true); scaleLabel->setAutoFillBackground(true); colorPaletteLabel->setAutoFillBackground(true); rotationLabel->setAutoFillBackground(true); linearButton->hide(); logButton->hide(); regularPaletteButton->hide(); prettyPaletteButton->hide(); greyScalePaletteButton->hide(); glowingPaletteButton->hide(); zeroRotationButton->hide(); minus90RotationButton->hide(); plus90Rotationbutton->hide(); scaleLabel->hide(); colorPaletteLabel->hide(); rotationLabel->hide(); connect(linearButton, SIGNAL(toggled(bool)), this, SLOT(linearScalePlease(bool))); connect(logButton, SIGNAL(toggled(bool)), this, SLOT(logScalePlease(bool))); connect(regularPaletteButton, SIGNAL(toggled(bool)), this, SLOT(regularPalettePlease(bool))); connect(prettyPaletteButton, SIGNAL(toggled(bool)), this, SLOT(prettyPalettePlease(bool))); connect(greyScalePaletteButton, SIGNAL(toggled(bool)), this, SLOT(greyScalePalettePlease(bool))); connect(glowingPaletteButton, SIGNAL(toggled(bool)), this, SLOT(glowingPalettePlease(bool))); connect(zeroRotationButton, SIGNAL(toggled(bool)), this, SLOT(zeroRotationPlease(bool))); connect(minus90RotationButton, SIGNAL(toggled(bool)), this, SLOT(plus90RotationPlease(bool))); connect(plus90Rotationbutton, SIGNAL(toggled(bool)), this, SLOT(minus90RotationPlease(bool))); } BasicGlCamera::~BasicGlCamera() { } void BasicGlCamera::setUnits(const string& units) { unitsText = units; pixelColorUpToDate = false; if (isVisible()) updateGL(); } void BasicGlCamera::setTitle(const string& title) { titleText = title; pixelColorUpToDate = false; if (isVisible()) updateGL(); } void BasicGlCamera::SetWhite(int idx) { fWhite = idx; fWhitePatch = pixelsPatch[fWhite]; if (isVisible()) updateGL(); // CalculatePatchColor(); } void BasicGlCamera::SetMin(int64_t min) { // cout << "min: " << min << endl; fMin = min; pixelColorUpToDate = false; if (isVisible()) updateGL(); } void BasicGlCamera::SetMax(int64_t max) { // cout << "max: " << max << endl; fMax = max; pixelColorUpToDate = false; if (isVisible()) updateGL(); } void BasicGlCamera::linearScalePlease(bool checked) { if (!checked) return; logScale = false; pixelColorUpToDate = false; emit colorPaletteHasChanged(); if (isVisible()) updateGL(); } void BasicGlCamera::UpdateText() { ostringstream str; float min, max, mean, rms, median; min = max = fData[0]; mean = 0; rms = 0; median = 0; multiset medianSet; for (int i=0;i max) max = fData[i]; mean += fData[i]; rms += fData[i]*fData[i]; medianSet.insert(fData[i]); } mean /= ACTUAL_NUM_PIXELS; rms /= ACTUAL_NUM_PIXELS; rms = sqrt(rms); // cout << "Size of the set: " << medianSet.size() << endl; multiset::iterator it = medianSet.begin(); for (int i=0;i<(ACTUAL_NUM_PIXELS/2)-1;i++) it++; median = *it; it++; median += *it; median /= 2; str << "Min: " << min << " Max: " << max << " Mean: " << mean << " RMS: " << rms << " Median: " << median; str << " Units: " << unitsText; dataText = str.str(); } void BasicGlCamera::DrawCameraText() { glPushMatrix(); glLoadIdentity(); // cout << width() << " " << height() << endl; int textSize = (int)(height()*14/600); setFont(QFont("Times", textSize)); qglColor(QColor(255,223,127)); float shiftx = 0.01f;//0.55f; float shifty = 0.01f;//0.65f; renderText(-shownSizex/2.f + shiftx, -shownSizey/2.f + shifty, 0.f, QString(dataText.c_str())); int textLength = titleText.size(); renderText(-shownSizex/2.f + shiftx, shownSizey/2.f - textSize*pixelSize - shifty, 0.f, QString(titleText.c_str())); glPopMatrix(); } void BasicGlCamera::DrawScale() { glPushMatrix(); glLoadIdentity(); glPushAttrib(GL_POLYGON_BIT); glShadeModel(GL_SMOOTH); glBegin(GL_QUADS); float oneX = shownSizex/2.f - shownSizex/50.f; float twoX = shownSizex/2.f; float oneY = -shownSizey/2.f; float twoY = -shownSizey/4.f; float threeY = 0; float fourY = shownSizey/4.f; float fiveY = shownSizey/2.f; glColor3f(rr[0], gg[0], bb[0]); glVertex2f(oneX, oneY); glVertex2f(twoX, oneY); glColor3f(rr[1], gg[1], bb[1]); glVertex2f(twoX, twoY); glVertex2f(oneX, twoY); glVertex2f(oneX, twoY); glVertex2f(twoX, twoY); glColor3f(rr[2], gg[2], bb[2]); glVertex2f(twoX, threeY); glVertex2f(oneX, threeY); glVertex2f(oneX, threeY); glVertex2f(twoX, threeY); glColor3f(rr[3], gg[3], bb[3]); glVertex2f(twoX, fourY); glVertex2f(oneX, fourY); glVertex2f(oneX, fourY); glVertex2f(twoX, fourY); glColor3f(rr[4], gg[4], bb[4]); glVertex2f(twoX, fiveY); glVertex2f(oneX, fiveY); float zeroX = oneX - shownSizex/50.f; float zeroY = fiveY - shownSizey/50.f; glColor3fv(tooHighValueCoulour); glVertex2f(zeroX, fiveY); glVertex2f(oneX, fiveY); glVertex2f(oneX, zeroY); glVertex2f(zeroX, zeroY); glColor3fv(tooLowValueCoulour); glVertex2f(zeroX, -fiveY); glVertex2f(oneX, -fiveY); glVertex2f(oneX, -zeroY); glVertex2f(zeroX, -zeroY); glEnd(); //draw linear/log tick marks glColor3f(0.f,0.f,0.f); glBegin(GL_LINES); float value; for (int i=1;i<10;i++) { if (logScale) value = log10(i); else value = (float)(i)/10.f; float y = -shownSizey/2.f + value*shownSizey; glVertex2f(oneX, y); glVertex2f(twoX, y); } glEnd(); glPopAttrib(); glPopMatrix(); } void BasicGlCamera::logScalePlease(bool checked) { if (!checked) return; logScale = true; pixelColorUpToDate = false; emit colorPaletteHasChanged(); if (isVisible()) updateGL(); } void BasicGlCamera::regularPalettePlease(bool checked) { if (!checked) return; ss[0] = 0; ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f; rr[0] = 0.15; rr[1] = 0; rr[2] = 0; rr[3] = 1.0f; rr[4] = 0.85f; gg[0] = 0.15; gg[1] = 0; gg[2] = 1; gg[3] = 0; gg[4] = 0.85f; bb[0] = 0.15; bb[1] = 1; bb[2] = 0; bb[3] = 0; bb[4] = 0.85f; tooHighValueCoulour[0] = 1.f; tooHighValueCoulour[1] = 1.f; tooHighValueCoulour[2] = 0.f; tooLowValueCoulour[0] = 0.f; tooLowValueCoulour[1] = 1.f; tooLowValueCoulour[2] = 1.f; pixelColorUpToDate = false; emit colorPaletteHasChanged(); if (isVisible()) updateGL(); } void BasicGlCamera::prettyPalettePlease(bool checked) { if (!checked) return; ss[0] = 0.f; ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f; rr[0] = 0.f; rr[1] = 0.35f; rr[2] = 0.85f; rr[3] = 1.0f; rr[4] = 1.f; gg[0] = 0.f; gg[1] = 0.10f; gg[2] = 0.20f; gg[3] = 0.73f; gg[4] = 1.f; bb[0] = 0.f; bb[1] = 0.03f; bb[2] = 0.06f; bb[3] = 0.00f; bb[4] = 1.f; tooHighValueCoulour[0] = 0.f; tooHighValueCoulour[1] = 1.f; tooHighValueCoulour[2] = 0.f; tooLowValueCoulour[0] = 0.f; tooLowValueCoulour[1] = 0.f; tooLowValueCoulour[2] = 1.f; pixelColorUpToDate = false; emit colorPaletteHasChanged(); if (isVisible()) updateGL(); } void BasicGlCamera::greyScalePalettePlease(bool checked) { if (!checked) return; ss[0] = 0; ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f; rr[0] = 0; rr[1] = 0.25f; rr[2] = 0.5f; rr[3] = 0.75f; rr[4] = 1.0f; gg[0] = 0; gg[1] = 0.25f; gg[2] = 0.5f; gg[3] = 0.75f; gg[4] = 1.0f; bb[0] = 0; bb[1] = 0.25f; bb[2] = 0.5f; bb[3] = 0.75f; bb[4] = 1.0f; tooHighValueCoulour[0] = 0.f; tooHighValueCoulour[1] = 1.f; tooHighValueCoulour[2] = 0.f; tooLowValueCoulour[0] = 0.f; tooLowValueCoulour[1] = 0.f; tooLowValueCoulour[2] = 1.f; pixelColorUpToDate = false; emit colorPaletteHasChanged(); if (isVisible()) updateGL(); } void BasicGlCamera::glowingPalettePlease(bool checked) { if (!checked) return; ss[0] = 0; ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f; rr[0] = 0.15; rr[1] = 0.5; rr[2] = 1.f; rr[3] = 0.0f; rr[4] = 1.f; gg[0] = 0.15; gg[1] = 0.5; gg[2] = 1.f; gg[3] = 0.5f; gg[4] = 0.5f; bb[0] = 0.15; bb[1] = 0.5; bb[2] = 1; bb[3] = 1.f; bb[4] = 0.f; tooHighValueCoulour[0] = 1.f; tooHighValueCoulour[1] = 0.f; tooHighValueCoulour[2] = 0.f; tooLowValueCoulour[0] = 0.f; tooLowValueCoulour[1] = 1.f; tooLowValueCoulour[2] = 0.f; pixelColorUpToDate = false; emit colorPaletteHasChanged(); if (isVisible()) updateGL(); } void BasicGlCamera::zeroRotationPlease(bool checked) { if (!checked) return; cameraRotation = 0; pixelColorUpToDate = false; if (isVisible()) updateGL(); } void BasicGlCamera::plus90RotationPlease(bool checked) { if (!checked) return; cameraRotation = 90; pixelColorUpToDate = false; if (isVisible()) updateGL(); } void BasicGlCamera::minus90RotationPlease(bool checked) { if (!checked) return; cameraRotation = -90; pixelColorUpToDate = false; if (isVisible()) updateGL(); } void BasicGlCamera::initializeGL() { qglClearColor(QColor(25,25,38)); glShadeModel(GL_FLAT); glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glEnable (GL_LINE_SMOOTH); glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); } void BasicGlCamera::resizeGL(int cWidth, int cHeight) { glViewport(0, 0, cWidth, cHeight); glMatrixMode(GL_PROJECTION); glLoadIdentity(); GLfloat windowRatio = (float)cWidth/(float)cHeight; if (windowRatio < 1) { windowRatio = 1.0f/windowRatio; gluOrtho2D(-viewSize, viewSize, -viewSize*windowRatio, viewSize*windowRatio); pixelSize = 2*viewSize/(float)cWidth; shownSizex = 2*viewSize; shownSizey = 2*viewSize*windowRatio; } else { gluOrtho2D(-viewSize*windowRatio, viewSize*windowRatio, -viewSize, viewSize); pixelSize = 2*viewSize/(float)cHeight; shownSizex = 2*viewSize*windowRatio; shownSizey = 2*viewSize; } glMatrixMode(GL_MODELVIEW); } void BasicGlCamera::paintGL() { glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glTranslatef(0,-0.44,0); glScalef(1.5, 1.5, 1.5); drawCamera(true); drawPatches(); } void BasicGlCamera::toggleInterfaceDisplay() { if (linearButton->isVisible()) { linearButton->hide(); logButton->hide(); regularPaletteButton->hide(); prettyPaletteButton->hide(); greyScalePaletteButton->hide(); glowingPaletteButton->hide(); zeroRotationButton->hide(); minus90RotationButton->hide(); plus90Rotationbutton->hide(); scaleLabel->hide(); colorPaletteLabel->hide(); rotationLabel->hide(); } else { linearButton->show(); logButton->show(); regularPaletteButton->show(); prettyPaletteButton->show(); greyScalePaletteButton->show(); glowingPaletteButton->show(); zeroRotationButton->show(); minus90RotationButton->show(); plus90Rotationbutton->show(); scaleLabel->show(); colorPaletteLabel->show(); rotationLabel->show(); } } void BasicGlCamera::mousePressEvent(QMouseEvent *cEvent) { } void BasicGlCamera::mouseMoveEvent(QMouseEvent *cEvent) { } void BasicGlCamera::mouseDoubleClickEvent(QMouseEvent *cEvent) { } void BasicGlCamera::drawCamera(bool alsoWire) { cout << "Super PaintGL" << endl; glColor3f(0.5,0.5,0.5); glLineWidth(1.0); float color; for (int i=0;i pixelsCoords[currentPixel][1]){//bottom neighbors[i][3] = currentPixel; neighbors[currentPixel][0] = i; continue;} if (pixelsCoords[i][0] > pixelsCoords[currentPixel][0] && pixelsCoords[i][1] > pixelsCoords[currentPixel][1]){//top right neighbors[i][4] = currentPixel; neighbors[currentPixel][1] = i; continue;} if (pixelsCoords[i][0] > pixelsCoords[currentPixel][0] && pixelsCoords[i][1] < pixelsCoords[currentPixel][1]){//bottom right neighbors[i][5] = currentPixel; neighbors[currentPixel][2] = i; continue;} if (pixelsCoords[i][0] < pixelsCoords[currentPixel][0] && pixelsCoords[i][1] > pixelsCoords[currentPixel][1]){//top left neighbors[i][2] = currentPixel; neighbors[currentPixel][5] = i; continue;} if (pixelsCoords[i][0] < pixelsCoords[currentPixel][0] && pixelsCoords[i][1] < pixelsCoords[currentPixel][1]){//bottom left neighbors[i][1] = currentPixel; neighbors[currentPixel][4] = i; continue;} } } } void BasicGlCamera::skipPixels(int start, int howMany) { for (int i=start;i= 0) { toSide--; if (toSide < 0) toSide = 5; } fromSide = toSide + 3; if (fromSide > 5) fromSide -= 6; //ok. now we now in which direction we're heading pixelsCoords[i][0] = pixelsCoords[i-1][0]; pixelsCoords[i][1] = pixelsCoords[i-1][1]; pixelsCoords[i][2] = pixelsCoords[i-1][2]; switch (toSide) { case 0: pixelsCoords[i][1] += 2*hexRadius; break; case 1: pixelsCoords[i][0] += (2*hexRadius)*sin(M_PI/3.0); pixelsCoords[i][1] += (2*hexRadius)*cos(M_PI/3.0); break; case 2: pixelsCoords[i][0] += (2*hexRadius)*sin(M_PI/3.0); pixelsCoords[i][1] -= (2*hexRadius)*cos(M_PI/3.0); break; case 3: pixelsCoords[i][1] -= 2*hexRadius; break; case 4: pixelsCoords[i][0] -= (2*hexRadius)*sin(M_PI/3.0); pixelsCoords[i][1] -= (2*hexRadius)*cos(M_PI/3.0); break; case 5: pixelsCoords[i][0] -= (2*hexRadius)*sin(M_PI/3.0); pixelsCoords[i][1] += (2*hexRadius)*cos(M_PI/3.0); break; }; updateNeighbors(i); } //Ok. So now we've circled around all the way to MAX_NUM_PIXELS //do the required shifts so that it matches the fact camera up to ACTUAL_NUM_PIXELS pixels skipPixels(1200, 1); skipPixels(1218, 3); skipPixels(1236, 1); skipPixels(1256, 1); skipPixels(1274, 3); skipPixels(1292, 3); skipPixels(1309, 6); skipPixels(1323, 7); skipPixels(1337, 6); skipPixels(1354, 6); skipPixels(1368, 7); skipPixels(1382, 9); skipPixels(1394, 12); skipPixels(1402, 15); skipPixels(1410, 12); skipPixels(1422, 12); skipPixels(1430, 15); } void BasicGlCamera::buildVerticesList() { numVertices = 0; GLfloat cVertex[2]; for (int i=0;i::iterator it; bool erased = false; // patchesIndices.resize(NTMARK); for (int i=0;i= ACTUAL_NUM_PIXELS) continue; for (int k=0;k<6;k++)//for all sides of the current cell { int first = k-1; int second = k; if (first < 0) first = 5; erased = false; for (it=(patchesIndices[i]).begin(); it != (patchesIndices[i]).end(); it++)//check if this side is here already or not { if (((*it).first == verticesIndices[softwareMapping[patches[i][j]]][first] && (*it).second == verticesIndices[softwareMapping[patches[i][j]]][second]) || ((*it).first == verticesIndices[softwareMapping[patches[i][j]]][second] && (*it).second == verticesIndices[softwareMapping[patches[i][j]]][first])) { patchesIndices[i].erase(it); erased = true; break; } } if (!erased) { edge temp; temp.first = verticesIndices[softwareMapping[patches[i][j]]][first]; temp.second = verticesIndices[softwareMapping[patches[i][j]]][second]; patchesIndices[i].push_back(temp); } } } } // for (int i=0;i 3013) // cout << patchesIndices[i][j].first << " and " << patchesIndices[i][j].second << " and " << j << endl; // } // } }