Index: /trunk/FACT++/gui/BasicGlCamera.cc
===================================================================
--- /trunk/FACT++/gui/BasicGlCamera.cc	(revision 11900)
+++ /trunk/FACT++/gui/BasicGlCamera.cc	(revision 11901)
@@ -20,4 +20,29 @@
     {
         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;
@@ -108,9 +133,412 @@
         fcSlice = 0;
         fData.resize(1440);
+        for (int i=0;i<ACTUAL_NUM_PIXELS+2;i++)
+            fData[i] = (double)i;///1.44;//(double)(i)/(double)(ACTUAL_NUM_PIXELS);
+
+
+        setFont(QFont("Arial", 8));
+        int buttonShift=0;
+        scaleLabel = new QLabel("Scale", this);
+//        buttonShift += scaleLabel->height();
+
+        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<double> medianSet;
         for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
-            fData[i] = (double)i;///1.44;//(double)(i)/(double)(ACTUAL_NUM_PIXELS);
-    }
-    BasicGlCamera::~BasicGlCamera()
-    {
+        {
+            if (fData[i] < min)
+                min = fData[i];
+            if (fData[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<double>::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();
     }
 
@@ -125,5 +553,5 @@
         glEnable (GL_BLEND);
         glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-        glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
+        glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
 
     }
@@ -163,4 +591,38 @@
          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)
     {
@@ -369,4 +831,5 @@
         for (int i=2;i<MAX_NUM_PIXELS;i++)
         {
+ //           cout << "i " << i << endl;
             toSide = fromSide-1;
             if (toSide < 0)
Index: /trunk/FACT++/gui/BasicGlCamera.h
===================================================================
--- /trunk/FACT++/gui/BasicGlCamera.h	(revision 11900)
+++ /trunk/FACT++/gui/BasicGlCamera.h	(revision 11901)
@@ -12,4 +12,10 @@
 #include <QtGui/QMouseEvent>
 #include <vector>
+
+#include <QtGui/QRadioButton>
+#include <QtGui/QLabel>
+#include <QtGui/QButtonGroup>
+
+#include <set>
 
 using namespace std;
@@ -43,4 +49,54 @@
     ~BasicGlCamera();
 
+    int fWhite;
+    int fWhitePatch;
+
+    int64_t fMin;
+    int64_t fMax;
+
+    bool pixelColorUpToDate;
+
+    GLfloat patchColour[3];
+    GLfloat pixelContourColour[3];
+    GLfloat patchesCoulour[3];
+    GLfloat highlightedPatchesCoulour[3];
+    GLfloat highlightedPixelsCoulour[3];
+    GLfloat tooHighValueCoulour[3];
+    GLfloat tooLowValueCoulour[3];
+
+    string dataText;
+    string unitsText;
+    string titleText;
+
+    void setUnits(const string& units);
+    void setTitle(const string& title);
+    void SetWhite(int idx);
+    void SetMin(int64_t min);
+    void SetMax(int64_t max);
+
+    float ss[5];// = {0.00, 0.25, 0.5, 0.75, 1.00};
+    float rr[5];// = {0.15, 0.00, 0.00, 1.00, 0.85};
+    float gg[5];// = {0.15, 0.00, 1.00, 0.00, 0.85};
+    float bb[5];// = {0.15, 1.00, 0.00, 0.00, 0.85};
+
+public Q_SLOTS:
+        void linearScalePlease(bool);
+        void logScalePlease(bool);
+        void regularPalettePlease(bool);
+        void prettyPalettePlease(bool);
+        void greyScalePalettePlease(bool);
+        void glowingPalettePlease(bool);
+        void zeroRotationPlease(bool);
+        void plus90RotationPlease(bool);
+        void minus90RotationPlease(bool);
+
+Q_SIGNALS:
+         void signalCurrentPixel(int pixel);
+         void signalPixelMoveOver(int pixel);
+         void signalPixelDoubleClick(int pixel);
+         void colorPaletteHasChanged();
+
+
+
 protected:
     void initializeGL();
@@ -59,9 +115,8 @@
     vector<double>fData;
 
-    float ss[5];// = {0.00, 0.25, 0.5, 0.75, 1.00};
-    float rr[5];// = {0.15, 0.00, 0.00, 1.00, 0.85};
-    float gg[5];// = {0.15, 0.00, 1.00, 0.00, 0.85};
-    float bb[5];// = {0.15, 1.00, 0.00, 0.00, 0.85};
  //   bool recalcColorPlease;
+    GLfloat pixelsCoords[MAX_NUM_PIXELS][3];
+     PixelsNeighbors neighbors[MAX_NUM_PIXELS];
+     int hardwareMapping[NPIX];
     GLfloat pixelsColor[NPIX][3];
     GLfloat verticesList[NPIX*6][2];
@@ -74,19 +129,37 @@
     float shownSizey;
     float pixelSize;
+    void DrawCameraText();
+    void UpdateText();
+    void DrawScale();
+    void toggleInterfaceDisplay();
+    QRadioButton* linearButton;
+    QRadioButton* logButton;
+    QRadioButton* regularPaletteButton;
+    QRadioButton* prettyPaletteButton;
+    QRadioButton* greyScalePaletteButton;
+    QRadioButton* glowingPaletteButton;
+    QRadioButton* zeroRotationButton;
+    QRadioButton* minus90RotationButton;
+    QRadioButton* plus90Rotationbutton;
+    QLabel*       scaleLabel;
+    QLabel*       colorPaletteLabel;
+    QLabel*       rotationLabel;
+    QButtonGroup* scaleGroup;
+    QButtonGroup* colorGroup;
+    QButtonGroup* rotationGroup;
+
+
+    bool logScale;
+    int cameraRotation;
+    void buildVerticesList();
+    virtual void buildPatchesIndices();
+    void updateNeighbors(int currentPixel);
+    void calculatePixelsCoords();
 private:
-    void updateNeighbors(int currentPixel);
     void skipPixels(int start, int howMany);
-    void calculatePixelsCoords();
-    void buildVerticesList();
-    void buildPatchesIndices();
     float hexRadius;
     float hexTolerance;
     float viewSize;
-    GLfloat pixelsCoords[MAX_NUM_PIXELS][3];
-    PixelsNeighbors neighbors[MAX_NUM_PIXELS];
-
-
-    int hardwareMapping[NPIX];
-    int numVertices;
+     int numVertices;
 
 };
Index: /trunk/FACT++/gui/QCameraWidget.cc
===================================================================
--- /trunk/FACT++/gui/QCameraWidget.cc	(revision 11900)
+++ /trunk/FACT++/gui/QCameraWidget.cc	(revision 11901)
@@ -5,154 +5,11 @@
     QCameraWidget::QCameraWidget(QWidget *pparent) : BasicGlCamera(pparent)
     {
-        fWhite = -1;
-        fWhitePatch = -1;
         fBold.resize(1440);
         fEnable.resize(1440);
         fBold.assign(1440, false);
         fEnable.assign(1440, true);
-        fMin = -1;
-        fMax = -1;
         lastFace = -1;
-        unitsText = "";
-        titleText = "This is a title";
-        dataText = "";
-        logScale = false;
-        cameraRotation = 0;
-
-        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);
 
         CalculatePixelsColor();
-
-        setFont(QFont("Arial", 8));
-        int buttonShift=0;
-        scaleLabel = new QLabel("Scale", this);
-//        buttonShift += scaleLabel->height();
-
-        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(pparent);
-        colorGroup = new QButtonGroup(pparent);
-        rotationGroup = new QButtonGroup(pparent);
-        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)));
-
-
 
    }
@@ -262,58 +119,5 @@
         fBold.assign(1440, false);
     }
-    void QCameraWidget::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 QCameraWidget::repaintInterface()
-    {
-        return;
-        setFont(QFont("Arial", 10));
- //       glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-        linearButton->render(this);
-        logButton->render(this);
-        regularPaletteButton->render(this);
-        prettyPaletteButton->render(this);
-        greyScalePaletteButton->render(this);
-        glowingPaletteButton->render(this);
-        zeroRotationButton->render(this);
-        minus90RotationButton->render(this);
-        plus90Rotationbutton->render(this);
- //       scaleLabel->repaint();
-        colorPaletteLabel->render(this);
-        rotationLabel->render(this);
-
-        scaleLabel->render(this);
-  //       cout << scaleLabel->autoFillBackground() << endl;
-    }
+
     void QCameraWidget::mousePressEvent(QMouseEvent *cEvent)
     {
@@ -368,13 +172,5 @@
     }
 
-     void QCameraWidget::SetWhite(int idx)
-     {
-         fWhite = idx;
-         fWhitePatch = pixelsPatch[fWhite];
-         if (isVisible())
-             updateGL();
-//         CalculatePatchColor();
-     }
-     void QCameraWidget::SetEnable(int idx, bool b)
+    void QCameraWidget::SetEnable(int idx, bool b)
      {
          fEnable[idx] = b;
@@ -384,20 +180,4 @@
      {
          return fData[idx];
-     }
-     void QCameraWidget::SetMin(int64_t min)
-     {
- //        cout << "min: " << min << endl;
-         fMin = min;
-         pixelColorUpToDate = false;
-         if (isVisible())
-             updateGL();
-     }
-     void QCameraWidget::SetMax(int64_t max)
-     {
- //        cout << "max: " << max << endl;
-         fMax = max;
-         pixelColorUpToDate = false;
-         if (isVisible())
-             updateGL();
      }
      const char* QCameraWidget::GetName()
@@ -506,248 +286,6 @@
              updateGL();
      }
-     void QCameraWidget::UpdateText()
-     {
-         ostringstream str;
-         float min, max, mean, rms, median;
-         min = max = fData[0];
-         mean = 0;
-         rms = 0;
-         median = 0;
-         multiset<double> medianSet;
-         for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
-         {
-             if (fData[i] < min)
-                 min = fData[i];
-             if (fData[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<double>::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 QCameraWidget::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 QCameraWidget::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 QCameraWidget::setUnits(const string& units)
-     {
-         unitsText = units;
-         pixelColorUpToDate = false;
-         if (isVisible())
-             updateGL();
-     }
-     void QCameraWidget::setTitle(const string& title)
-     {
-         titleText = title;
-         pixelColorUpToDate = false;
-         if (isVisible())
-             updateGL();
-     }
-     void QCameraWidget::linearScalePlease(bool checked)
-     {
-         if (!checked) return;
-         logScale = false;
-         pixelColorUpToDate = false;
-         if (isVisible())
-             updateGL();
-     }
-     void QCameraWidget::logScalePlease(bool checked)
-     {
-         if (!checked) return;
-         logScale = true;
-         pixelColorUpToDate = false;
-         if (isVisible())
-             updateGL();
-     }
-     void QCameraWidget::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;
-         if (isVisible())
-             updateGL();
-     }
-     void QCameraWidget::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;
-         if (isVisible())
-             updateGL();
-     }
-     void QCameraWidget::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;
-         if (isVisible())
-             updateGL();
-     }
-     void QCameraWidget::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;
-         if (isVisible())
-             updateGL();
-     }
-     void QCameraWidget::zeroRotationPlease(bool checked)
-     {
-         if (!checked) return;
-         cameraRotation = 0;
-         pixelColorUpToDate = false;
-         if (isVisible())
-             updateGL();
-     }
-     void QCameraWidget::plus90RotationPlease(bool checked)
-     {
-         if (!checked) return;
-         cameraRotation = 90;
-         pixelColorUpToDate = false;
-         if (isVisible())
-             updateGL();
-     }
-     void QCameraWidget::minus90RotationPlease(bool checked)
-     {
-         if (!checked) return;
-         cameraRotation = -90;
-         pixelColorUpToDate = false;
-         if (isVisible())
-             updateGL();
-     }
+
+
      void QCameraWidget::highlightPixel(int idx)
      {
Index: /trunk/FACT++/gui/QCameraWidget.h
===================================================================
--- /trunk/FACT++/gui/QCameraWidget.h	(revision 11900)
+++ /trunk/FACT++/gui/QCameraWidget.h	(revision 11901)
@@ -6,7 +6,4 @@
 #include <set>
 
-#include <QtGui/QRadioButton>
-#include <QtGui/QLabel>
-#include <QtGui/QButtonGroup>
 
 using namespace std;
@@ -27,25 +24,7 @@
     vector<int> highlightedPixels;
 
-    int fWhite;
-    int fWhitePatch;
-
-    int64_t fMin;
-    int64_t fMax;
 
     int lastFace;
 
-    bool pixelColorUpToDate;
-
-    GLfloat patchColour[3];
-    GLfloat pixelContourColour[3];
-    GLfloat patchesCoulour[3];
-    GLfloat highlightedPatchesCoulour[3];
-    GLfloat highlightedPixelsCoulour[3];
-    GLfloat tooHighValueCoulour[3];
-    GLfloat tooLowValueCoulour[3];
-
-    string dataText;
-    string unitsText;
-    string titleText;
 
 public:
@@ -54,6 +33,4 @@
     void clearHighlightedPatches();
     void clearHighlightedPixels();
-    void setUnits(const string& units);
-    void setTitle(const string& title);
     QCameraWidget(QWidget *pparent = 0);
     void paintGL();
@@ -64,10 +41,7 @@
     void drawCamera(bool alsoWire);
     void drawPatches();
-     void SetWhite(int idx);
      void SetEnable(int idx, bool b);
      double GetData(int idx);
-     void SetMin(int64_t min);
-     void SetMax(int64_t max);
-     const char *GetName();
+    const char *GetName();
 
      int GetIdx(float px, float py);
@@ -76,46 +50,9 @@
      void SetData(const valarray<double> &ddata);
 
-public Q_SLOTS:
-        void linearScalePlease(bool);
-        void logScalePlease(bool);
-        void regularPalettePlease(bool);
-        void prettyPalettePlease(bool);
-        void greyScalePalettePlease(bool);
-        void glowingPalettePlease(bool);
-        void zeroRotationPlease(bool);
-        void plus90RotationPlease(bool);
-        void minus90RotationPlease(bool);
-
-Q_SIGNALS:
-         void signalCurrentPixel(int pixel);
-         void signalPixelMoveOver(int pixel);
-         void signalPixelDoubleClick(int pixel);
 
 private:
      void CalculatePixelsColor();
      void CalculatePatchColor();
-     void DrawCameraText();
-     void UpdateText();
-     void DrawScale();
-     void toggleInterfaceDisplay();
-     void repaintInterface();
-     QRadioButton* linearButton;
-     QRadioButton* logButton;
-     QRadioButton* regularPaletteButton;
-     QRadioButton* prettyPaletteButton;
-     QRadioButton* greyScalePaletteButton;
-     QRadioButton* glowingPaletteButton;
-     QRadioButton* zeroRotationButton;
-     QRadioButton* minus90RotationButton;
-     QRadioButton* plus90Rotationbutton;
-     QLabel*       scaleLabel;
-     QLabel*       colorPaletteLabel;
-     QLabel*       rotationLabel;
-     QButtonGroup* scaleGroup;
-     QButtonGroup* colorGroup;
-     QButtonGroup* rotationGroup;
 
-     bool logScale;
-     int cameraRotation;
 };
 
Index: /trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.cc
===================================================================
--- /trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.cc	(revision 11900)
+++ /trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.cc	(revision 11901)
@@ -25,11 +25,8 @@
 #include "src/Configuration.h"
 
-//Coordinates of an hexagon of radius 1 and center 0
-GLfloat hexcoords[6][2] = {{-0.577367206,  1},
-                           { 0.577367206,  1},
-                           { 1.154734411,  0},
-                           { 0.577367206, -1},
-                           {-0.577367206, -1},
-                           {-1.154734411,  0}};
+//#include "../BasicGlCamera.cc"
+
+#undef ACTUAL_NUM_PIXELS
+#define ACTUAL_NUM_PIXELS 1440
 
 //bounding box for diplaying the impulse curve
@@ -37,211 +34,425 @@
 float bboxMax[2] = {0.8,-0.3};
 /************************************************************
- * UPDATE NEIGHBORS recalculate the neighbors of the current pixels.
- * Only takes the previous pixels into account (and updates them, too)
- ************************************************************/
-void RawDataViewer::updateNeighbors(int currentPixel)
-{
-    float squaredDistance = 0;
-    for (int i=0;i<currentPixel;i++)
-    {
-        squaredDistance = (pixelsCoords[i][0] - pixelsCoords[currentPixel][0])*
-                          (pixelsCoords[i][0] - pixelsCoords[currentPixel][0]) +
-                          (pixelsCoords[i][1] - pixelsCoords[currentPixel][1])*
-                          (pixelsCoords[i][1] - pixelsCoords[currentPixel][1]);
-        if (squaredDistance < 4*hexRadius*hexRadius*(1.0f+hexTolerance))//neighbor !
-        {//ok, but which one ?
-            if (fabs(pixelsCoords[i][0] - pixelsCoords[currentPixel][0]) < hexTolerance &&
-                pixelsCoords[i][1] < pixelsCoords[currentPixel][1]){//top
-                neighbors[i][0] = currentPixel;
-                neighbors[currentPixel][3] = i;
-                continue;}
-            if (fabs(pixelsCoords[i][0] - pixelsCoords[currentPixel][0]) < hexTolerance &&
-                pixelsCoords[i][1] > 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;}
-        }
-    }
-}
-/************************************************************
- * SKIP PIXELS skips a given number of pixels.
- * Only update the pixel coordinates. i.e. update neighbors must
- * called again afterwards.
- ************************************************************/
-void RawDataViewer::skipPixels(int start, int howMany)
-{
-    for (int i=start;i<MAX_NUM_PIXELS-howMany;i++)
-    {
-        pixelsCoords[i][0] = pixelsCoords[i+howMany][0];
-        pixelsCoords[i][1] = pixelsCoords[i+howMany][1];
-    }
-}
-/************************************************************
- * CALCULATE PIXELS COORDS as the name suggests
- ************************************************************/
-void RawDataViewer::calculatePixelsCoords()
-{
-    pixelsCoords[0][0] = 0;
-    pixelsCoords[0][1] = 0.3;
-    pixelsCoords[0][2] = 0;
-    pixelsCoords[1][0] = 0;
-    pixelsCoords[1][1] = 0.3+2*hexRadius;
-    pixelsCoords[1][2] = 0;
-    neighbors[0][0] = 1;
-    neighbors[1][3] = 0;
-    //from which side of the previous hexagon are we coming from ?
-    int fromSide = 3;
-    //to which side are we heading to ?
-    int toSide = 0;
-    for (int i=2;i<MAX_NUM_PIXELS;i++)
-    {
-        toSide = fromSide-1;
-        if (toSide < 0)
-            toSide =5;
-        while (neighbors[i-1][toSide] >= 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;
-        };
-
+ * CALC BLUR COLOR if in blur display mode, calculate the interpolated
+ * colour for a given vertex
+ ************************************************************/
+void RawDataViewer::calcBlurColor(int pixel,  int vertex)
+{
+    GLfloat color[3];
+    int first, second;
+    first = vertex-1;
+    second = vertex;
+    if (first < 0)
+        first = 5;
+    first = neighbors[pixel][first];
+    second = neighbors[pixel][second];
+    for (int i=0;i<3;i++)
+        color[i] = pixelsColor[pixel][i];
+    float divide = 1;
+    if (first != -1)
+    {
+        divide++;
+        for (int i=0;i<3;i++)
+            color[i] += pixelsColor[first][i];
+    }
+    if (second != -1)
+    {
+        divide++;
+        for (int i=0;i<3;i++)
+            color[i] += pixelsColor[second][i];
+    }
+    for (int i=0;i<3;i++)
+        color[i] /= divide;
+    glColor3fv(color);
+}
+/************************************************************
+ * DRAW BLURRY HEXAGON. draws a solid hexagon, with interpolated colours
+ ************************************************************/
+void RawDataViewer::drawBlurryHexagon(int index)
+{
+    GLfloat color[3];
+    for (int i=0;i<3;i++)
+        color[i] = pixelsColor[index][i];
+    glBegin(GL_TRIANGLES);
+    calcBlurColor(index, 0);
+    glVertex2fv(verticesList[verticesIndices[index][0]]);
+    glColor3fv(color);
+    glVertex2fv(pixelsCoords[index]);
+    calcBlurColor(index, 1);
+    glVertex2fv(verticesList[verticesIndices[index][1]]);
+
+    glVertex2fv(verticesList[verticesIndices[index][1]]);
+    glColor3fv(color);
+    glVertex2fv(pixelsCoords[index]);
+    calcBlurColor(index, 2);
+    glVertex2fv(verticesList[verticesIndices[index][2]]);
+
+    glVertex2fv(verticesList[verticesIndices[index][2]]);
+    glColor3fv(color);
+    glVertex2fv(pixelsCoords[index]);
+    calcBlurColor(index, 3);
+    glVertex2fv(verticesList[verticesIndices[index][3]]);
+
+    glVertex2fv(verticesList[verticesIndices[index][3]]);
+    glColor3fv(color);
+    glVertex2fv(pixelsCoords[index]);
+    calcBlurColor(index, 4);
+    glVertex2fv(verticesList[verticesIndices[index][4]]);
+
+    glVertex2fv(verticesList[verticesIndices[index][4]]);
+    glColor3fv(color);
+    glVertex2fv(pixelsCoords[index]);
+    calcBlurColor(index, 5);
+    glVertex2fv(verticesList[verticesIndices[index][5]]);
+
+    glVertex2fv(verticesList[verticesIndices[index][5]]);
+    glColor3fv(color);
+    glVertex2fv(pixelsCoords[index]);
+    calcBlurColor(index, 0);
+    glVertex2fv(verticesList[verticesIndices[index][0]]);
+    glEnd();
+
+    return;
+}
+
+/************************************************************
+ * DRAW CAMERA draws all the camera pixels
+ ************************************************************/
+void RawDataViewer::drawCamera(bool alsoWire)
+{
+    glLoadIdentity();
+    if (!drawImpulse)
+    {
+        glTranslatef(0,-0.44,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);
+    }
+    else
+    {
+        glRotatef(cameraRotation, 0,0,-1);
+          if (cameraRotation == 90)
+        {
+            glTranslatef(-0.45/1.5,-0.45/1.5,0);
+ //           cout << "correction" << endl;
+        }
+        if (cameraRotation == -90)
+        {
+            glTranslatef(0.45/1.5,-0.45/1.5,0);
+        }
+  }
+    glColor3f(0.5,0.5,0.5);
+    glLineWidth(1.0);
+    float color;
+//cout << "Actual num pixels: " << ACTUAL_NUM_PIXELS << endl;
+    for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
+    {
+        if (!nRoi)
+          color = (float)(i)/(float)(ACTUAL_NUM_PIXELS);
+        else
+#ifdef LOAD_RAW
+        color = float(eventsData[eventNum][i][whichSlice]+(VALUES_SPAN/2))/(float)(VALUES_SPAN-1);
+#else
+        color = float(eventData[nRoi*i + whichSlice]+(VALUES_SPAN/2))/(float)(VALUES_SPAN-1);
+        if (logScale)
+        {
+            color *= 9;
+            color += 1;
+            color = log10(color);
+        }
+#endif
+        if (color < 0)
+        {
+            pixelsColor[i][0] = tooLowValueCoulour[0];
+            pixelsColor[i][1] = tooLowValueCoulour[1];
+            pixelsColor[i][2] = tooLowValueCoulour[2];
+            continue;
+        }
+        if (color > 1)
+        {
+            pixelsColor[i][0] = tooHighValueCoulour[0];
+            pixelsColor[i][1] = tooHighValueCoulour[1];
+            pixelsColor[i][2] = tooHighValueCoulour[2];
+            continue;
+        }
+        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];
+    }
+
+    for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
+    {
+        if (i == 690 ||
+            i == 70)
+            continue;
+        glColor3fv(pixelsColor[i]);
+        glLoadName(i);
+if (drawBlur)
+    drawBlurryHexagon(i);
+else
+    drawHexagon(i,true);
+
+    }
+    if (!alsoWire)
+        return;
+    glColor3f(0.0f,0.0f,0.0f);
+    for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
+    {
+        if (i == 690 ||
+            i == 70)
+            continue;
+        drawHexagon(i, false);
+    }
+
+}
+
+/************************************************************
+ * TRIM. FIXME this should not be here but taken from an existing class (somewhere)
+ ***********************************************************
+string Trim(const string &str)
+{
+    // Trim Both leading and trailing spaces
+    const size_t start = str.find_first_not_of(' '); // Find the first character position after excluding leading blank spaces
+    const size_t end   = str.find_last_not_of(' ');  // Find the first character position from reverse af
+
+    // if all spaces or empty return an empty string
+    if (string::npos==start || string::npos==end)
+        return string();
+
+    return str.substr(start, end-start+1);
+}*/
+/************************************************************
+ * DRAW PIXEL CURVE. draws the raw impulse curve of the currently selected pixel
+ ************************************************************/
+void RawDataViewer::drawPixelCurve()
+{
+    if (!nRoi)
+        return;
+
+    float xZoom, yZoom;
+    xZoom = yZoom = 1.0f;
+
+    glBegin(GL_LINES);
+    glLineWidth(1.0f);
+    glColor3f(0.5,0.5,0.5);
+    glVertex2f(bboxMin[0], bboxMin[1]);
+    glVertex2f(bboxMax[0], bboxMin[1]);
+    glVertex2f(bboxMin[0], bboxMin[1]);
+    glVertex2f(bboxMin[0], bboxMax[1]);
+    glVertex2f(bboxMin[0], (bboxMin[1]+bboxMax[1])/2.0f);
+    glVertex2f(bboxMax[0], (bboxMin[1]+bboxMax[1])/2.0f);
+    float xRange = bboxMax[0] - bboxMin[0];
+    float yRange = bboxMax[1] - bboxMin[1];
+    glColor3f(1.0,1.0,1.0);
+    float divideMe = (float)(VALUES_SPAN-1);
+    float plusMe = VALUES_SPAN/2;
+    if (drawCalibrationLoaded)
+        plusMe += 0;//VALUES_SPAN/2;
+    if (drawCalibrationLoaded && calibrationLoaded)
+    {
+        divideMe /=2;
+        plusMe /=2;
+    }
+    for (int i=0;i<nRoi-1;i++)
+    {
+#ifdef LOAD_RAW
+        glVertex2f(bboxMin[0] + xRange*i/(float)nRoi,
+                   bboxMin[1] + yRange*(eventsData[eventNum][selectedPixel][i]+plusMe) /divideMe);
+        glVertex2f(bboxMin[0] + xRange*(i+1)/(float)nRoi,
+                   bboxMin[1] + yRange*(eventsData[eventNum][selectedPixel][i+1]+plusMe) /divideMe);
+#else
+
+        glVertex2f(bboxMin[0] + xRange*i/(float)nRoi,
+                   bboxMin[1] + yRange*(eventData[nRoi*selectedPixel + i]+plusMe) /divideMe);
+        glVertex2f(bboxMin[0] + xRange*(i+1)/(float)nRoi,
+                   bboxMin[1] + yRange*(eventData[nRoi*selectedPixel + i+1]+plusMe) /divideMe);
+#endif
+    }
+    glColor3f(1.0,0.0,0.0);
+    glVertex2f(bboxMin[0] + xRange*whichSlice/(float)nRoi,
+               bboxMin[1]);
+    glVertex2f(bboxMin[0] + xRange*whichSlice/(float)nRoi,
+               bboxMax[1]);
+    glEnd();
+    glEnable(GL_MULTISAMPLE);
+    setFont(QFont("Times", 12));
+    qglColor(QColor(255,223,127));
+    float xShift = 0.10f;
+    float yShift = 0.01f;
+    renderText(bboxMin[0]-xShift/2.0f, bboxMax[1]+3*yShift, 0, QString("Volts"));
+    if (drawCalibrationLoaded)
+    {
+        renderText(bboxMin[0]-xShift, bboxMax[1]-yShift,0,QString("+2.10"));
+        renderText(bboxMin[0]-xShift,  ((bboxMin[1]+bboxMax[1])/2.0f) - yShift, 0, QString("+1.05"));//((bboxMin[1]+bboxMax[1])/2.0f)
+        renderText(bboxMin[0]-xShift, bboxMin[1]-yShift, 0, QString("0.00"));
+    }
+    else
+    {
+        renderText(bboxMin[0]-xShift, bboxMax[1]-yShift,0,QString("+1.05"));
+        renderText(bboxMin[0]-xShift,  ((bboxMin[1]+bboxMax[1])/2.0f) - yShift, 0, QString("+0.00"));//((bboxMin[1]+bboxMax[1])/2.0f)
+        renderText(bboxMin[0]-xShift, bboxMin[1]-yShift, 0, QString("-1.05"));
+    }
+    renderText(bboxMax[0]+xShift/2.0f, bboxMin[1]-4*yShift, 0, QString("Slices"));
+    renderText(bboxMin[0]-yShift/2.0f, bboxMin[1]-4*yShift, 0, QString("0"));
+    ostringstream str;
+    str << nRoi/2;
+    renderText(((bboxMin[0]+bboxMax[0])/2.0f)-xShift/2.0f, bboxMin[1]-4*yShift, 0, QString(str.str().c_str()));
+    str.str("");
+    str << nRoi;
+    renderText(bboxMax[0]-xShift/2.0f, bboxMin[1]-4*yShift, 0, QString(str.str().c_str()));
+
+}
+/************************************************************
+ * CONSTRUCTOR.
+ ************************************************************/
+RawDataViewer::RawDataViewer(QWidget *cParent) : BasicGlCamera(cParent)
+{
+ //   setFormat(QGLFormat(QGL::DoubleBuffer));// | QGL::DepthBuffer));
+    whichSlice = 0;
+#ifdef LOAD_RAW
+    nRoi = 1024;
+#else
+    nRoi = 0;
+#endif
+    eventNum = 0;
+    rowNum = -1;
+    eventStep = 1;
+    selectedPixel = 393;
+    inputFile = NULL;
+    eventData = NULL;
+    drawPatch = true;
+    drawImpulse = false;
+    drawBlur = false;
+    loopCurrentEvent = false;
+#ifdef LOAD_RAW
+    loadEvents("/scratch/00000043.001_T.bin");
+#endif
+//    cout << "avant" << endl;
+//    calculatePixelsCoords();
+//    cout << "apres" << endl;
+/*
+    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 = 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];
+
+    for (int i=0;i<1440;i++)
+    updateNeighbors(i);
+    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 = 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++;
+    }*/
+
+    buildPatchesIndices();
+    float color[3];
+    for (int i=0;i<160;i++)
+    {
+        color[0] = 0.5; color[1] = 0.5; color[2] = 0.3;
+        for (int j=0;j<3;j++)
+            patchesColor[i][j] = color[j];
+    }
+
+    for (int i=0;i<1440;i++)
         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);
-}
-/************************************************************
- * BUILD VERTICES LIST. from the coordinates of the camera pixels,
- * calculate the list and coordinates of the vertices required to draw the
- * entire camera.
- ************************************************************/
-void RawDataViewer::buildVerticesList()
-{
-    numVertices = 0;
-    GLfloat cVertex[2];
-    for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
-    {
-        for (int j=0;j<6;j++)
-        {
-            for (int k=0;k<2;k++)
-                cVertex[k] = hexcoords[j][k]*hexRadius + pixelsCoords[i][k];
-            bool found = false;
-            for (int k=0;k<numVertices;k++)
-            {
-                if ((cVertex[0] - verticesList[k][0])*
-                    (cVertex[0] - verticesList[k][0]) +
-                    (cVertex[1] - verticesList[k][1])*
-                    (cVertex[1] - verticesList[k][1]) < hexTolerance*hexTolerance)
-                    {
-                        found = true;
-                        break;
-                    }
-            }
-            if (!found)
-            {
-                for (int k=0;k<2;k++)
-                    verticesList[numVertices][k] = cVertex[k];
-                numVertices++;
-            }
-        }
-    }
-    for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
-    {
-        for (int j=0;j<6;j++)
-        {
-            for (int k=0;k<2;k++)
-                cVertex[k] = hexcoords[j][k]*hexRadius + pixelsCoords[i][k];
-            for (int k=0;k<numVertices;k++)
-            {
-                if ((cVertex[0] - verticesList[k][0])*
-                     (cVertex[0] - verticesList[k][0]) +
-                     (cVertex[1] - verticesList[k][1])*
-                     (cVertex[1] - verticesList[k][1]) < hexTolerance*hexTolerance)
-                     {
-                        verticesIndices[i][j] = k;
-                        break;
-                     }
-            }
-        }
-    }
-}
-/************************************************************
- * BUILD PATCHES INDICES. from the list of patches, crawls through
- * the list of camera pixels and build the list of edges that should be kept
- * in order to display the patches' contours.
- ************************************************************/
+
+    calibrationLoaded = false;
+    drawCalibrationLoaded = false;
+
+}
+/************************************************************
+ *  DESTRUCTOR
+ ************************************************************/
+RawDataViewer::~RawDataViewer()
+{
+    if (inputFile != NULL)
+    {
+        inputFile->close();
+        delete inputFile;
+    }
+    if (eventData != NULL) {
+        delete[] eventData;
+        delete[] rawEventData;
+    }
+}
+
 void RawDataViewer::buildPatchesIndices()
 {
     vector<edge>::iterator it;
     bool erased = false;
+//        patchesIndices.resize(NTMARK);
     for (int i=0;i<NTMARK;i++)//for all patches
     {
@@ -283,449 +494,4 @@
 }
 /************************************************************
- * CALC BLUR COLOR if in blur display mode, calculate the interpolated
- * colour for a given vertex
- ************************************************************/
-void RawDataViewer::calcBlurColor(int pixel,  int vertex)
-{
-    GLfloat color[3];
-    int first, second;
-    first = vertex-1;
-    second = vertex;
-    if (first < 0)
-        first = 5;
-    first = neighbors[pixel][first];
-    second = neighbors[pixel][second];
-    for (int i=0;i<3;i++)
-        color[i] = pixelsColor[pixel][i];
-    float divide = 1;
-    if (first != -1)
-    {
-        divide++;
-        for (int i=0;i<3;i++)
-            color[i] += pixelsColor[first][i];
-    }
-    if (second != -1)
-    {
-        divide++;
-        for (int i=0;i<3;i++)
-            color[i] += pixelsColor[second][i];
-    }
-    for (int i=0;i<3;i++)
-        color[i] /= divide;
-    glColor3fv(color);
-}
-/************************************************************
- * DRAW BLURRY HEXAGON. draws a solid hexagon, with interpolated colours
- ************************************************************/
-void RawDataViewer::drawBlurryHexagon(int index)
-{
-    GLfloat color[3];
-    for (int i=0;i<3;i++)
-        color[i] = pixelsColor[index][i];
-    glBegin(GL_TRIANGLES);
-    calcBlurColor(index, 0);
-    glVertex2fv(verticesList[verticesIndices[index][0]]);
-    glColor3fv(color);
-    glVertex2fv(pixelsCoords[index]);
-    calcBlurColor(index, 1);
-    glVertex2fv(verticesList[verticesIndices[index][1]]);
-
-    glVertex2fv(verticesList[verticesIndices[index][1]]);
-    glColor3fv(color);
-    glVertex2fv(pixelsCoords[index]);
-    calcBlurColor(index, 2);
-    glVertex2fv(verticesList[verticesIndices[index][2]]);
-
-    glVertex2fv(verticesList[verticesIndices[index][2]]);
-    glColor3fv(color);
-    glVertex2fv(pixelsCoords[index]);
-    calcBlurColor(index, 3);
-    glVertex2fv(verticesList[verticesIndices[index][3]]);
-
-    glVertex2fv(verticesList[verticesIndices[index][3]]);
-    glColor3fv(color);
-    glVertex2fv(pixelsCoords[index]);
-    calcBlurColor(index, 4);
-    glVertex2fv(verticesList[verticesIndices[index][4]]);
-
-    glVertex2fv(verticesList[verticesIndices[index][4]]);
-    glColor3fv(color);
-    glVertex2fv(pixelsCoords[index]);
-    calcBlurColor(index, 5);
-    glVertex2fv(verticesList[verticesIndices[index][5]]);
-
-    glVertex2fv(verticesList[verticesIndices[index][5]]);
-    glColor3fv(color);
-    glVertex2fv(pixelsCoords[index]);
-    calcBlurColor(index, 0);
-    glVertex2fv(verticesList[verticesIndices[index][0]]);
-    glEnd();
-
-    return;
-}
-/************************************************************
- * DRAW HEXAGON. draws a single hexagon.
- ************************************************************/
-void RawDataViewer::drawHexagon(int index, bool solid)
-{
-    if (solid)
-        glBegin(GL_POLYGON);
-    else
-        glBegin(GL_LINE_LOOP);
-
-    glVertex2fv(verticesList[verticesIndices[index][0]]);
-    glVertex2fv(verticesList[verticesIndices[index][1]]);
-    glVertex2fv(verticesList[verticesIndices[index][2]]);
-    glVertex2fv(verticesList[verticesIndices[index][3]]);
-    glVertex2fv(verticesList[verticesIndices[index][4]]);
-    glVertex2fv(verticesList[verticesIndices[index][5]]);
-    if (solid)
-        glVertex2fv(verticesList[verticesIndices[index][0]]);
-
-    glEnd();
-
-    return;
-}
-
-
-float ss[5] = {0.00, 0.25, 0.5, 0.75, 1.00};
-float rr[5] = {0.15, 0.00, 0.00, 1.00, 0.85};
-float gg[5] = {0.15, 0.00, 1.00, 0.00, 0.85};
-float bb[5] = {0.15, 1.00, 0.00, 0.00, 0.85};
-/*
-float ss[5] = {0., 0.47, 0.475, 0.48, 1.00};
-float rr[5] = {0., 0.35, 0.85, 1.00, 1.00};
-float gg[5] = {0., 0.10, 0.20, 0.73, 1.00};
-float bb[5] = {0., 0.03, 0.06, 0.00, 1.00};
-*/
-/************************************************************
- * DRAW PATCHES. draws the clustering patches
- ************************************************************/
-void RawDataViewer::drawPatches()
-{
-    glLineWidth(2.0f);
-    float backupRadius = hexRadius;
-    hexRadius *= 0.95;
-    glBegin(GL_LINES);
-    for (int i=0;i<NTMARK;i++)
-    {
-        glColor3fv(patchesColor[i]);
-        for (unsigned int j=0;j<patchesIndices[i].size();j++)
-        {
-            glVertex2fv(verticesList[patchesIndices[i][j].first]);
-            glVertex2fv(verticesList[patchesIndices[i][j].second]);
-        }
-    }
-    glEnd();
-    hexRadius = backupRadius;
-}
-/************************************************************
- * DRAW CAMERA draws all the camera pixels
- ************************************************************/
-void RawDataViewer::drawCamera(bool alsoWire)
-{
-    glColor3f(0.5,0.5,0.5);
-    glLineWidth(1.0);
-    float color;
-
-    for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
-    {
-        if (!nRoi)
-          color = (float)(i)/(float)(ACTUAL_NUM_PIXELS);
-        else
-#ifdef LOAD_RAW
-        color = float(eventsData[eventNum][i][whichSlice]+(VALUES_SPAN/2))/(float)(VALUES_SPAN-1);
-#else
-        color = float(eventData[nRoi*i + whichSlice]+(VALUES_SPAN/2))/(float)(VALUES_SPAN-1);
-#endif
-        int index = 0;
-        while (ss[index] < color)
-            index++;
-        index--;
-        float weight0 = (color-ss[index]) / (ss[index+1]-ss[index]);
-        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];
-    }
-
-    for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
-    {
-        if (i == 690 ||
-            i == 70)
-            continue;
-        glColor3fv(pixelsColor[i]);
-        glLoadName(i);
-if (drawBlur)
-    drawBlurryHexagon(i);
-else
-    drawHexagon(i,true);
-
-    }
-    if (!alsoWire)
-        return;
-    glColor3f(0.0f,0.0f,0.0f);
-    for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
-    {
-        if (i == 690 ||
-            i == 70)
-            continue;
-        drawHexagon(i, false);
-    }
-
-}
-
-/************************************************************
- * TRIM. FIXME this should not be here but taken from an existing class (somewhere)
- ************************************************************/
-string Trim(const string &str)
-{
-    // Trim Both leading and trailing spaces
-    const size_t start = str.find_first_not_of(' '); // Find the first character position after excluding leading blank spaces
-    const size_t end   = str.find_last_not_of(' ');  // Find the first character position from reverse af
-
-    // if all spaces or empty return an empty string
-    if (string::npos==start || string::npos==end)
-        return string();
-
-    return str.substr(start, end-start+1);
-}
-/************************************************************
- * DRAW PIXEL CURVE. draws the raw impulse curve of the currently selected pixel
- ************************************************************/
-void RawDataViewer::drawPixelCurve()
-{
-    if (!nRoi)
-        return;
-
-    float xZoom, yZoom;
-    xZoom = yZoom = 1.0f;
-
-    glBegin(GL_LINES);
-    glLineWidth(1.0f);
-    glColor3f(0.5,0.5,0.5);
-    glVertex2f(bboxMin[0], bboxMin[1]);
-    glVertex2f(bboxMax[0], bboxMin[1]);
-    glVertex2f(bboxMin[0], bboxMin[1]);
-    glVertex2f(bboxMin[0], bboxMax[1]);
-    glVertex2f(bboxMin[0], (bboxMin[1]+bboxMax[1])/2.0f);
-    glVertex2f(bboxMax[0], (bboxMin[1]+bboxMax[1])/2.0f);
-    float xRange = bboxMax[0] - bboxMin[0];
-    float yRange = bboxMax[1] - bboxMin[1];
-    glColor3f(1.0,1.0,1.0);
-    float divideMe = (float)(VALUES_SPAN-1);
-    float plusMe = VALUES_SPAN/2;
-    if (drawCalibrationLoaded && calibrationLoaded)
-    {
-        divideMe /=2;
-        plusMe /=2;
-    }
-    for (int i=0;i<nRoi-1;i++)
-    {
-#ifdef LOAD_RAW
-        glVertex2f(bboxMin[0] + xRange*i/(float)nRoi,
-                   bboxMin[1] + yRange*(eventsData[eventNum][selectedPixel][i]+plusMe) /divideMe);
-        glVertex2f(bboxMin[0] + xRange*(i+1)/(float)nRoi,
-                   bboxMin[1] + yRange*(eventsData[eventNum][selectedPixel][i+1]+plusMe) /divideMe);
-#else
-
-        glVertex2f(bboxMin[0] + xRange*i/(float)nRoi,
-                   bboxMin[1] + yRange*(eventData[nRoi*selectedPixel + i]+plusMe) /divideMe);
-        glVertex2f(bboxMin[0] + xRange*(i+1)/(float)nRoi,
-                   bboxMin[1] + yRange*(eventData[nRoi*selectedPixel + i+1]+plusMe) /divideMe);
-#endif
-    }
-    glColor3f(1.0,0.0,0.0);
-    glVertex2f(bboxMin[0] + xRange*whichSlice/(float)nRoi,
-               bboxMin[1]);
-    glVertex2f(bboxMin[0] + xRange*whichSlice/(float)nRoi,
-               bboxMax[1]);
-    glEnd();
-    glEnable(GL_MULTISAMPLE);
-    setFont(QFont("Times", 12));
-    qglColor(QColor(255,223,127));
-    float xShift = 0.10f;
-    float yShift = 0.01f;
-    renderText(bboxMin[0]-xShift/2.0f, bboxMax[1]+3*yShift, 0, QString("Volts"));
-    renderText(bboxMin[0]-xShift, bboxMax[1]-yShift,0,QString("+1.05"));
-    renderText(bboxMin[0]-xShift,  ((bboxMin[1]+bboxMax[1])/2.0f) - yShift, 0, QString("+0.00"));//((bboxMin[1]+bboxMax[1])/2.0f)
-    renderText(bboxMin[0]-xShift, bboxMin[1]-yShift, 0, QString("-1.05"));
-
-    renderText(bboxMax[0]+xShift/2.0f, bboxMin[1]-4*yShift, 0, QString("Slices"));
-    renderText(bboxMin[0]-yShift/2.0f, bboxMin[1]-4*yShift, 0, QString("0"));
-    ostringstream str;
-    str << nRoi/2;
-    renderText(((bboxMin[0]+bboxMax[0])/2.0f)-xShift/2.0f, bboxMin[1]-4*yShift, 0, QString(str.str().c_str()));
-    str.str("");
-    str << nRoi;
-    renderText(bboxMax[0]-xShift/2.0f, bboxMin[1]-4*yShift, 0, QString(str.str().c_str()));
-
-}
-/************************************************************
- * CONSTRUCTOR.
- ************************************************************/
-RawDataViewer::RawDataViewer(QWidget *cParent) : QGLWidget(cParent)
-{
-    setFormat(QGLFormat(QGL::DoubleBuffer));// | QGL::DepthBuffer));
-    hexRadius = 0.015f;
-    hexTolerance = hexRadius/100.0f;
-    viewSize = 1.0f;
-    whichSlice = 0;
-#ifdef LOAD_RAW
-    nRoi = 1024;
-#else
-    nRoi = 0;
-#endif
-    eventNum = 0;
-    rowNum = -1;
-    eventStep = 1;
-    selectedPixel = 393;
-    inputFile = NULL;
-    eventData = NULL;
-    drawPatch = true;
-    drawImpulse = false;
-    drawBlur = false;
-    loopCurrentEvent = false;
-#ifdef LOAD_RAW
-    loadEvents("/scratch/00000043.001_T.bin");
-#endif
-    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 = 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 = 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++;
-    }
-    buildPatchesIndices();
-    float color[3];
-    for (int i=0;i<160;i++)
-    {
-        color[0] = 0.5; color[1] = 0.5; color[2] = 0.3;
-        for (int j=0;j<3;j++)
-            patchesColor[i][j] = color[j];
-    }
-
-    for (int i=0;i<1440;i++)
-        updateNeighbors(i);
-
-    calibrationLoaded = false;
-    drawCalibrationLoaded = false;
-
-}
-/************************************************************
- *  DESTRUCTOR
- ************************************************************/
-RawDataViewer::~RawDataViewer()
-{
-    if (inputFile != NULL)
-    {
-        inputFile->close();
-        delete inputFile;
-    }
-    if (eventData != NULL) {
-        delete[] eventData;
-        delete[] rawEventData;
-    }
-}
-/************************************************************
- * INITIALIZE GL. does not do much.
- ************************************************************/
-void RawDataViewer::initializeGL()
-{
-    qglClearColor(QColor(25,25,38));
-    glShadeModel(GL_FLAT);
-    glDisable(GL_DEPTH_TEST);
-    glDisable(GL_CULL_FACE);
-//    glEnable(GL_LINE_SMOOTH);
-//    glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
-}
-
-/************************************************************
- * RESIZE GL. reshapes the ortho projection to match the current window size
- ************************************************************/
-void RawDataViewer::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);
-}
-
-/************************************************************
  * PAINT GL. main drawing function.
  ************************************************************/
@@ -735,9 +501,5 @@
     glLoadIdentity();
 
-    if (!drawImpulse)
-    {
-        glTranslatef(0,-0.44,0);
-        glScalef(1.5,1.5,1);
-    }
+
     if (drawBlur)
     {
@@ -749,9 +511,4 @@
         glShadeModel(GL_FLAT);
         drawCamera(true);
-    }
-    if (drawImpulse)
-    {
-        glLineWidth(2.0);
-        drawPixelCurve();
     }
     if (drawPatch)
@@ -764,4 +521,13 @@
         drawHexagon(selectedPixel, false);
    }
+   if (drawImpulse)
+   {
+    //   glRotatef(cameraRotation, 0,0,1);
+       glLoadIdentity();
+       glLineWidth(2.0);
+       drawPixelCurve();
+   }
+
+   DrawScale();
 }
 
@@ -771,4 +537,9 @@
 void RawDataViewer::mousePressEvent(QMouseEvent *cEvent)
 {
+    if (cEvent->pos().x() > width()-(width()/50.f))
+    {
+        toggleInterfaceDisplay();
+        return;
+    }
     lastPos = cEvent->pos();
     setCorrectSlice(cEvent);
@@ -822,53 +593,4 @@
 }
 
-/************************************************************
- * PIXEL AT POSITION. figures out which camera pixel was clicked.
- ************************************************************/
-int RawDataViewer::PixelAtPosition(const QPoint &cPos)
-{
-    const int MaxSize = 512;
-    GLuint buffer[MaxSize];
-    GLint viewport[4];
-
-    makeCurrent();
-
-    glGetIntegerv(GL_VIEWPORT, viewport);
-    glSelectBuffer(MaxSize, buffer);
-    glRenderMode(GL_SELECT);
-
-    glInitNames();
-    glPushName(0);
-
-    glMatrixMode(GL_PROJECTION);
-    glPushMatrix();
-    glLoadIdentity();
-    GLfloat windowRatio = GLfloat(width()) / GLfloat(height());
-    gluPickMatrix(GLdouble(cPos.x()), GLdouble(viewport[3] - cPos.y()),
-            1.0, 1.0, viewport);
-
-    if (windowRatio < 1)
-     {
-         windowRatio = 1.0f/windowRatio;
-         gluOrtho2D(-viewSize, viewSize, -viewSize*windowRatio, viewSize*windowRatio);
-     }
-     else
-     {
-         gluOrtho2D(-viewSize*windowRatio, viewSize*windowRatio, -viewSize, viewSize);
-     }
-
-    glMatrixMode(GL_MODELVIEW);
-    drawCamera(false);
-    glMatrixMode(GL_PROJECTION);
-    glPopMatrix();
-
-    //for some reason that I cannot understand, the push/pop matrix doesn't do the trick here... bizarre
-    //ok, so re-do the resizeGL thing.
-    resizeGL(width(), height());
-
-    if (!glRenderMode(GL_RENDER))
-        return -1;
-
-    return buffer[3];
-}
 /************************************************************
  * OPEN FILE. opens a new fits file
@@ -1006,7 +728,7 @@
     calibInputFile->GetNextRow();
 
-    for (int i=0;i<1024;i++)
-        cout << gainMean[i] << " ";
-    cout << endl << endl;
+ //   for (int i=0;i<1024;i++)
+ //       cout << gainMean[i] << " ";
+ //   cout << endl << endl;
 
     delete calibInputFile;
@@ -1066,7 +788,8 @@
             for (int j=0;j<nRoi;j++)
             {
+                int realj = (j+startPix[j])%1024;
                 eventData[i*1024+j] *= 2000.f/4096.f;
-                eventData[i*1024+j] -= (baseLineMean[i*1024+j]+triggerOffsetMean[i*1024+j]);
-                eventData[i*1024+j] /= gainMean[i*1024+j];
+                eventData[i*1024+j] -= (baseLineMean[i*1024+realj]+triggerOffsetMean[i*1024+realj]);
+                eventData[i*1024+j] /= gainMean[i*1024+realj];
                 eventData[i*1024+j] *= (50000.f/65536.f) * 2500.f;
             }
@@ -1150,7 +873,8 @@
 //                    cout << "start value: " << viewer->eventData[i*1024+j] << " baseline: " << viewer->baseLineMean[i*1024+j];
 //                    cout << " triggerOffset: " << viewer->triggerOffsetMean[i*1024+j] << " gain: " << viewer->gainMean[i*1024+j];
+                    int realj = (j+viewer->startPix[j])%1024;
                     viewer->eventData[i*1024+j] *= 2000.f/4096.f;
-                    viewer->eventData[i*1024+j] -= (viewer->baseLineMean[i*1024+j]+viewer->triggerOffsetMean[i*1024+j]);
-                    viewer->eventData[i*1024+j] /= viewer->gainMean[i*1024+j];
+                    viewer->eventData[i*1024+j] -= (viewer->baseLineMean[i*1024+realj]+viewer->triggerOffsetMean[i*1024+realj]);
+                    viewer->eventData[i*1024+j] /= viewer->gainMean[i*1024+realj];
                     viewer->eventData[i*1024+j] *= (50000.f/65536.f) * 2500.f;
 //                    cout << " end value: " << viewer->eventData[i*1024+j] << endl;
@@ -1171,8 +895,8 @@
                 for (int j=0;j<viewer->nRoi;j++)
                 {
-
+                    int realj = (j+viewer->startPix[j])%1024;
                     viewer->eventData[i*1024+j] /= (50000.f/65536.f) * 2500.f;
-                    viewer->eventData[i*1024+j] *= viewer->gainMean[i*1024+j];
-                    viewer->eventData[i*1024+j] += (viewer->baseLineMean[i*1024+j]+viewer->triggerOffsetMean[i*1024+j]);
+                    viewer->eventData[i*1024+j] *= viewer->gainMean[i*1024+realj];
+                    viewer->eventData[i*1024+j] += (viewer->baseLineMean[i*1024+realj]+viewer->triggerOffsetMean[i*1024+realj]);
                     viewer->eventData[i*1024+j] /= 2000.f/4096.f;
                }
@@ -1181,4 +905,5 @@
 
     }
+     autoScalePressed();
 
 }
@@ -1249,5 +974,5 @@
 void UIConnector::rangeChanged0(double value)
 {
-    ss[0] = (float)value;
+    viewer->ss[0] = (float)value;
     viewer->updateGL();
 }
@@ -1257,5 +982,5 @@
 void UIConnector::rangeChanged1(double value)
 {
-    ss[1] = (float)value;
+    viewer->ss[1] = (float)value;
     viewer->updateGL();
 }
@@ -1265,5 +990,5 @@
 void UIConnector::rangeChanged2(double value)
 {
-    ss[2] = (float)value;
+    viewer->ss[2] = (float)value;
     viewer->updateGL();
 }
@@ -1273,5 +998,5 @@
 void UIConnector::rangeChanged3(double value)
 {
-    ss[3] = (float)value;
+    viewer->ss[3] = (float)value;
     viewer->updateGL();
 }
@@ -1281,5 +1006,5 @@
 void UIConnector::rangeChanged4(double value)
 {
-    ss[4] = (float)value;
+    viewer->ss[4] = (float)value;
     viewer->updateGL();
 }
@@ -1289,5 +1014,5 @@
 void UIConnector::redChanged0(double value)
 {
-    rr[0] = (float)value;
+    viewer->rr[0] = (float)value;
     viewer->updateGL();
 }
@@ -1297,5 +1022,5 @@
 void UIConnector::redChanged1(double value)
 {
-    rr[1] = (float)value;
+    viewer->rr[1] = (float)value;
     viewer->updateGL();
 }
@@ -1305,5 +1030,5 @@
 void UIConnector::redChanged2(double value)
 {
-    rr[2] = (float)value;
+    viewer->rr[2] = (float)value;
     viewer->updateGL();
 }
@@ -1313,5 +1038,5 @@
 void UIConnector::redChanged3(double value)
 {
-    rr[3] = (float)value;
+    viewer->rr[3] = (float)value;
     viewer->updateGL();
 }
@@ -1321,5 +1046,5 @@
 void UIConnector::redChanged4(double value)
 {
-    rr[4] = (float)value;
+    viewer->rr[4] = (float)value;
     viewer->updateGL();
 }
@@ -1329,5 +1054,5 @@
 void UIConnector::greenChanged0(double value)
 {
-    gg[0] = (float)value;
+    viewer->gg[0] = (float)value;
     viewer->updateGL();
 }
@@ -1337,5 +1062,5 @@
 void UIConnector::greenChanged1(double value)
 {
-    gg[1] = (float)value;
+    viewer->gg[1] = (float)value;
     viewer->updateGL();
 }
@@ -1345,5 +1070,5 @@
 void UIConnector::greenChanged2(double value)
 {
-    gg[2] = (float)value;
+    viewer->gg[2] = (float)value;
     viewer->updateGL();
 }
@@ -1353,5 +1078,5 @@
 void UIConnector::greenChanged3(double value)
 {
-    gg[3] = (float)value;
+    viewer->gg[3] = (float)value;
     viewer->updateGL();
 }
@@ -1361,5 +1086,5 @@
 void UIConnector::greenChanged4(double value)
 {
-    gg[4] = (float)value;
+    viewer->gg[4] = (float)value;
     viewer->updateGL();
 }
@@ -1369,5 +1094,5 @@
 void UIConnector::blueChanged0(double value)
 {
-    bb[0] = (float)value;
+    viewer->bb[0] = (float)value;
     viewer->updateGL();
 }
@@ -1377,5 +1102,5 @@
 void UIConnector::blueChanged1(double value)
 {
-    bb[1] = (float)value;
+    viewer->bb[1] = (float)value;
     viewer->updateGL();
 }
@@ -1385,5 +1110,5 @@
 void UIConnector::blueChanged2(double value)
 {
-    bb[2] = (float)value;
+    viewer->bb[2] = (float)value;
     viewer->updateGL();
 }
@@ -1393,5 +1118,5 @@
 void UIConnector::blueChanged3(double value)
 {
-    bb[3] = (float)value;
+    viewer->bb[3] = (float)value;
     viewer->updateGL();
 }
@@ -1401,5 +1126,5 @@
 void UIConnector::blueChanged4(double value)
 {
-    bb[4] = (float)value;
+    viewer->bb[4] = (float)value;
     viewer->updateGL();
 }
@@ -1544,4 +1269,7 @@
     emit updateCurrentPixelSliceValue(qstr);
 
+    if (autoScaleColor->isChecked())
+        emit viewer->colorPaletteHasChanged();//autoScalePressed();
+
     boardsTimeList->clear();
     startPixelsList->clear();
@@ -1896,4 +1624,6 @@
         return;
 
+    if (hwID == pixel)
+        return;
     for (int i=0;i<viewer->nRoi;i++)
     {
@@ -1918,12 +1648,39 @@
     hwID = pixel;
     swID = viewer->softwareMapping[pixel];
-    crateID = (pixel/4)/10;
-    boardID = (pixel/4)%10;
-    patchID = pixel%4;
-    HwIDBox->setValue(hwID);
-    SwIDBox->setValue(swID);
-    crateIDBox->setValue(crateID);
-    boardIDBox->setValue(boardID);
-    patchIDBox->setValue(patchID);
+//    cout << "here" << endl;
+/*    int channel = hwID%360;
+    channel = channel%36;
+    channel = channel%9;
+    int inter = (pixel-channel)%360;
+     inter = inter%36;
+    patchID = inter/9;
+    inter = pixel - channel - patchID*9;
+    inter = inter%360;
+    boardID = inter/36;
+    inter = pixel - channel - patchID*9 - boardID*36;
+    crateID = inter/360;
+*/
+    crateID = pixel/360;
+    boardID = (pixel - crateID*360)/36;
+    patchID = (pixel - crateID*360 - boardID*36)/9;
+//    cout << "Value: " << hwID << " " << swID;
+//    cout << " " << crateID  << " " << boardID;
+//   cout << " " << patchID  << endl;
+//    cout << "there " << crateID << " " << boardID << " " << patchID << endl;
+//    crateID = (pixel/4)/10;
+ //   boardID = (pixel/4)%10;
+//    patchID = pixel%4;
+//    cout << "there2 " << crateID << " " << boardID << " " << patchID << endl;
+
+    if (HwIDBox->value() != hwID)
+        HwIDBox->setValue(hwID);
+    if (SwIDBox->value() != swID)
+        SwIDBox->setValue(swID);
+    if (crateIDBox->value() != crateID)
+        crateIDBox->setValue(crateID);
+    if (boardIDBox->value() != boardID)
+        boardIDBox->setValue(boardID);
+    if (patchIDBox->value() != patchID)
+        patchIDBox->setValue(patchID);
 
     ostringstream str;
@@ -1945,7 +1702,11 @@
     hwID = hwid;
     swID = viewer->softwareMapping[hwid];
-    crateID = (hwid/4)/10;
-    boardID = (hwid/4)%10;
-    patchID = hwid%4;
+    crateID = hwID/360;
+    boardID = (hwID - crateID*360)/36;
+    patchID = (hwID - crateID*360 - boardID*36)/9;
+
+//    crateID = (hwid/4)/10;
+//    boardID = (hwid/4)%10;
+//    patchID = hwid%4;
     HwIDBox->setValue(hwID);
     SwIDBox->setValue(swID);
@@ -1963,7 +1724,11 @@
     swID = swid;
     hwID = viewer->hardwareMapping[swid];
-    crateID = (hwID/4)/10;
-    boardID = (hwID/4)%10;
-    patchID = hwID%4;
+    crateID = hwID/360;
+    boardID = (hwID - crateID*360)/36;
+    patchID = (hwID - crateID*360 - boardID*36)/9;
+
+//    crateID = (hwID/4)/10;
+//    boardID = (hwID/4)%10;
+//    patchID = hwID%4;
     HwIDBox->setValue(hwID);
     SwIDBox->setValue(swID);
@@ -1978,6 +1743,7 @@
 void UIConnector::crateIDChanged(int cid)
 {
+    hwID -= 360*crateID;
     crateID = cid;
-    hwID = 40*crateID + 4*boardID + patchID;
+    hwID += 360*crateID;
     swID = viewer->softwareMapping[hwID];
     HwIDBox->setValue(hwID);
@@ -1989,6 +1755,7 @@
 void UIConnector::boardIDChanged(int bid)
 {
+    hwID -= 36*boardID;
     boardID = bid;
-    hwID = 40*crateID + 4*boardID + patchID;
+    hwID += 36*boardID;
     swID = viewer->softwareMapping[hwID];
     HwIDBox->setValue(hwID);
@@ -2000,6 +1767,7 @@
 void UIConnector::patchIDChanged(int pid)
 {
+    hwID -= 9*patchID;
     patchID = pid;
-    hwID = 40*crateID + 4*boardID + patchID;
+    hwID += 9*patchID;
     swID = viewer->softwareMapping[hwID];
     HwIDBox->setValue(hwID);
@@ -2011,4 +1779,6 @@
 void UIConnector::autoScalePressed()
 {
+    if (!autoScaleColor->isChecked())
+        return;
     if (!viewer->nRoi)
         return;
@@ -2047,14 +1817,27 @@
     double maxRange = (double)(max+(VALUES_SPAN/2))/(double)VALUES_SPAN;
     double midRange = (double)(average+(VALUES_SPAN/2))/(double)VALUES_SPAN;
-    ss[0] = minRange;
-    range0->setValue(ss[0]);
-    ss[4] = maxRange;
-    range4->setValue(ss[4]);
-    ss[2] = midRange;
-    range2->setValue(ss[2]);
-    ss[1] = (minRange+midRange)/2;
-    range1->setValue(ss[1]);
-    ss[3] = (maxRange+midRange)/2;
-    range3->setValue(ss[3]);
+    if (viewer->logScale)
+    {
+        minRange *= 9;
+        maxRange *= 9;
+//        midRange *= 9;
+        minRange += 1;
+        maxRange += 1;
+//        midRange += 1;
+        minRange = log10(minRange);
+        maxRange = log10(maxRange);
+//        midRange = (minRange + maxRange)/2.f;
+        midRange = log10(midRange);
+    }
+    viewer->ss[0] = minRange;
+    range0->setValue(viewer->ss[0]);
+    viewer->ss[4] = maxRange;
+    range4->setValue(viewer->ss[4]);
+    viewer->ss[2] = midRange;
+    range2->setValue(viewer->ss[2]);
+    viewer->ss[1] = (minRange+midRange)/2;
+    range1->setValue(viewer->ss[1]);
+    viewer->ss[3] = (maxRange+midRange)/2;
+    range3->setValue(viewer->ss[3]);
 
 
@@ -2118,4 +1901,20 @@
 int main(int argc, char *argv[])
 {
+    QApplication app(argc, argv);
+
+    if (!QGLFormat::hasOpenGL()) {
+        std::cerr << "This system has no OpenGL support" << std::endl;
+        return 1;
+    }
+
+   QMainWindow mainWindow;
+
+    Ui_MainWindow myUi;
+    myUi.setupUi(&mainWindow);
+
+    UIConnector connector;
+
+    RawDataViewer *canvas = myUi.GLWindow;
+
     Configuration conf(argv[0]);
     conf.SetPrintUsage(PrintHelp);
@@ -2133,5 +1932,5 @@
         }
         for (int i=0;i<5;i++)
-            ss[i] = value[i];
+            canvas->ss[i] = value[i];
     }
 
@@ -2145,5 +1944,5 @@
         }
         for (int i=0;i<5;i++)
-            rr[i] = value[i];
+            canvas->rr[i] = value[i];
     }
 
@@ -2157,5 +1956,5 @@
         }
         for (int i=0;i<5;i++)
-            gg[i] = value[i];
+            canvas->gg[i] = value[i];
     }
 
@@ -2169,20 +1968,8 @@
         }
         for (int i=0;i<5;i++)
-            bb[i] = value[i];
-    }
-
-    QApplication app(argc, argv);
-
-    if (!QGLFormat::hasOpenGL()) {
-        std::cerr << "This system has no OpenGL support" << std::endl;
-        return 1;
-    }
-
-    QMainWindow mainWindow;
-
-    Ui_MainWindow myUi;
-    myUi.setupUi(&mainWindow);
-
-    RawDataViewer *canvas = myUi.GLWindow;
+            canvas->bb[i] = value[i];
+    }
+
+
 
     QObject::connect(myUi.eventsMinusButton, SIGNAL(clicked()),
@@ -2192,26 +1979,25 @@
     QObject::connect(myUi.eventsStepBox, SIGNAL(valueChanged(int)),
                      canvas, SLOT(setEventStep(int)));
-    myUi.colorRange0->setValue(ss[0]);
-    myUi.colorRange1->setValue(ss[1]);
-    myUi.colorRange2->setValue(ss[2]);
-    myUi.colorRange3->setValue(ss[3]);
-    myUi.colorRange4->setValue(ss[4]);
-    myUi.redValue0->setValue(rr[0]);
-    myUi.redValue1->setValue(rr[1]);
-    myUi.redValue2->setValue(rr[2]);
-    myUi.redValue3->setValue(rr[3]);
-    myUi.redValue4->setValue(rr[4]);
-    myUi.greenValue0->setValue(gg[0]);
-    myUi.greenValue1->setValue(gg[1]);
-    myUi.greenValue2->setValue(gg[2]);
-    myUi.greenValue3->setValue(gg[3]);
-    myUi.greenValue4->setValue(gg[4]);
-    myUi.blueValue0->setValue(bb[0]);
-    myUi.blueValue1->setValue(bb[1]);
-    myUi.blueValue2->setValue(bb[2]);
-    myUi.blueValue3->setValue(bb[3]);
-    myUi.blueValue4->setValue(bb[4]);
-
-    UIConnector connector;
+    myUi.colorRange0->setValue(canvas->ss[0]);
+    myUi.colorRange1->setValue(canvas->ss[1]);
+    myUi.colorRange2->setValue(canvas->ss[2]);
+    myUi.colorRange3->setValue(canvas->ss[3]);
+    myUi.colorRange4->setValue(canvas->ss[4]);
+    myUi.redValue0->setValue(canvas->rr[0]);
+    myUi.redValue1->setValue(canvas->rr[1]);
+    myUi.redValue2->setValue(canvas->rr[2]);
+    myUi.redValue3->setValue(canvas->rr[3]);
+    myUi.redValue4->setValue(canvas->rr[4]);
+    myUi.greenValue0->setValue(canvas->gg[0]);
+    myUi.greenValue1->setValue(canvas->gg[1]);
+    myUi.greenValue2->setValue(canvas->gg[2]);
+    myUi.greenValue3->setValue(canvas->gg[3]);
+    myUi.greenValue4->setValue(canvas->gg[4]);
+    myUi.blueValue0->setValue(canvas->bb[0]);
+    myUi.blueValue1->setValue(canvas->bb[1]);
+    myUi.blueValue2->setValue(canvas->bb[2]);
+    myUi.blueValue3->setValue(canvas->bb[3]);
+    myUi.blueValue4->setValue(canvas->bb[4]);
+
     connector.setViewer(canvas);
     connector.boardsTimeList = myUi.boardsTimeList;
@@ -2223,4 +2009,5 @@
     connector.triggerDelayHisto = myUi.triggerDelayHisto;
     connector.triggerDelayList = myUi.triggerDelayList;
+    connector.autoScaleColor = myUi.autoScaleColor;
 
     connector.startTimeMarksList = myUi.startTimeMarksList;
@@ -2260,4 +2047,7 @@
     QObject::connect(myUi.autoScaleColor, SIGNAL(clicked()),
                      &connector, SLOT(autoScalePressed()));
+    QObject::connect(canvas, SIGNAL(colorPaletteHasChanged()),
+                     &connector, SLOT(autoScalePressed()));
+
     QObject::connect(myUi.currentPixelScale, SIGNAL(toggled(bool)),
                      &connector, SLOT(currentPixelChanged(bool)));
Index: /trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.h
===================================================================
--- /trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.h	(revision 11900)
+++ /trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.h	(revision 11901)
@@ -20,5 +20,9 @@
 #include <QtGui/QListWidget>
 #include <QtGui/QMainWindow>
-#include <QtOpenGL/QGLWidget>
+#include <QtGui/QPushButton>
+
+//#include <QtOpenGL/QGLWidget>
+#include "../BasicGlCamera.h"
+
 #include <QtGui/QMouseEvent>
 #include <QtGui/QColorDialog>
@@ -42,34 +46,8 @@
 #include "externals/fits.h"
 
-using namespace std;
-
-#define NUM_STORED_EVENTS 5
-#define MAX_NUM_PIXELS 1600
-#define ACTUAL_NUM_PIXELS 1440
-
-///structure for storing edges of hexagons (for blurry display)
-struct edge
-{
-    int first;
-    int second;
-};
-
-///structure for storing neighbors of pixels. For camera position calculation and blurry display
-struct PixelsNeighbors
-{
-    //neighbors. clockwise, starting from top
-    int neighbors[6];
-    PixelsNeighbors()
-    {
-        for (int i=0;i<6;i++)
-            neighbors[i] = -1;
-    }
-    int& operator[](int index){return neighbors[index];}
-};
-
 /*************************************************
  * Class Raw Data Viewer. FACT raw data diplayer
  *************************************************/
-class RawDataViewer : public QGLWidget
+class RawDataViewer : public BasicGlCamera//QGLWidget
 {
     Q_OBJECT
@@ -82,4 +60,6 @@
     void openCalibFile(string& file);
 
+
+
 public Q_SLOTS:
     void plusEvent();
@@ -94,8 +74,9 @@
     void newFileLoaded();
     void signalCurrentPixel(int pixel);
+    void signalAutoScaleNeeded();
 
 protected:
-    void initializeGL();
-    void resizeGL(int width, int height);
+//    void initializeGL();
+//    void resizeGL(int width, int height);
     void paintGL();
     void mousePressEvent(QMouseEvent *event);
@@ -103,7 +84,7 @@
     void mouseDoubleClickEvent(QMouseEvent *event);
     void drawCamera(bool alsoWire);
-    void drawPatches();
-    int PixelAtPosition(const QPoint &pos);
-    void drawHexagon(int index, bool solid);
+//    void drawPatches();
+//    int PixelAtPosition(const QPoint &pos);
+//    void drawHexagon(int index, bool solid);
     int selectedPixel;
     float *eventData;
@@ -112,20 +93,16 @@
 private:
     void drawPixelCurve();
-    void updateNeighbors(int currentPixel);
-    void skipPixels(int start, int howMany);
-    void calculatePixelsCoords();
+//    void updateNeighbors(int currentPixel);
+//    void skipPixels(int start, int howMany);
+//    void calculatePixelsCoords();
     void setCorrectSlice(QMouseEvent* event);
     void eventStepping(bool plus);
-    void buildVerticesList();
+//    void buildVerticesList();
     void buildPatchesIndices();
     void calcBlurColor(int pixel, int vertex);
     void drawBlurryHexagon(int index);
-    float hexRadius;
-    float hexTolerance;
-    float viewSize;
     int whichSlice;
-    float pixelSize;
-    float shownSizex;
-    float shownSizey;
+ //   float shownSizex;
+ //   float shownSizey;
     bool drawPatch;
     bool drawImpulse;
@@ -165,9 +142,9 @@
     int eventStep;
 
-    int hardwareMapping[1440];
-    int softwareMapping[1440];
-    int patches[160][9];
+//    int hardwareMapping[1440];
+//    int softwareMapping[1440];
+////    int patches[160][9];
     GLfloat patchesColor[160][3];
-    vector<edge> patchesIndices[160];
+//    vector<edge> patchesIndices[160];
     fits* inputFile;
     fits* calibInputFile;
@@ -180,50 +157,12 @@
     QPoint lastPos;
 
-    GLfloat pixelsCoords[MAX_NUM_PIXELS][3];
-    PixelsNeighbors neighbors[MAX_NUM_PIXELS];
-    GLfloat pixelsColor[ACTUAL_NUM_PIXELS][3];
-    GLfloat verticesList[ACTUAL_NUM_PIXELS*6][2];
-    int verticesIndices[ACTUAL_NUM_PIXELS][6];
-    int numVertices;
+//    GLfloat pixelsCoords[MAX_NUM_PIXELS][3];
+//    PixelsNeighbors neighbors[MAX_NUM_PIXELS];
+ //   GLfloat pixelsColor[ACTUAL_NUM_PIXELS][3];
+//    GLfloat verticesList[ACTUAL_NUM_PIXELS*6][2];
+//    int verticesIndices[ACTUAL_NUM_PIXELS][6];
+//    int numVertices;
 };
 
-class Camera : public RawDataViewer
-{
-    Q_OBJECT
-
-    typedef pair<double, double> Position;
-    typedef vector<Position> Positions;
-
-    Positions fGeom;
-
-    valarray<double> fData;
-    vector<bool> fBold;
-    vector<bool> fEnable;
-
-    int fWhite;
-
-    int64_t fMin;
-    int64_t fMax;
-
-public:
-    Camera(QWidget *pparent = 0);
-    void Reset();
-     void SetBold(int idx);
-     void SetWhite(int idx);
-     void SetEnable(int idx, bool b);
-     void Toggle(int idx);
-     double GetData(int idx);
-     void SetMin(int64_t min);
-     void SetMax(int64_t max);
-     const char *GetName();
-
-     void Paint();
-
-     int GetIdx(float px, float py);
-     char *GetObjectInfo(int px, int py);
-
-     void SetData(const valarray<double> &ddata);
-
-};
 /*************************************************
  * Class UIConnector. used to connect the interface to the raw data displayer
@@ -335,4 +274,7 @@
     QwtPlotCurve triggerDelayHistoItem;
     QwtPlotZoomer* triggerDelayHistoZoom;
+
+    QPushButton* autoScaleColor;
+
     QListWidget* triggerDelayList;
 
Index: /trunk/FACT++/gui/RawEventsViewer/viewer.ui
===================================================================
--- /trunk/FACT++/gui/RawEventsViewer/viewer.ui	(revision 11900)
+++ /trunk/FACT++/gui/RawEventsViewer/viewer.ui	(revision 11901)
@@ -339,8 +339,8 @@
              <widget class="QSpinBox" name="crateIDBox">
               <property name="maximum">
-               <number>39</number>
+               <number>99</number>
               </property>
               <property name="value">
-               <number>9</number>
+               <number>0</number>
               </property>
              </widget>
@@ -349,8 +349,8 @@
              <widget class="QSpinBox" name="boardIDBox">
               <property name="maximum">
-               <number>9</number>
+               <number>99</number>
               </property>
               <property name="value">
-               <number>8</number>
+               <number>0</number>
               </property>
              </widget>
@@ -359,8 +359,8 @@
              <widget class="QSpinBox" name="patchIDBox">
               <property name="maximum">
-               <number>3</number>
+               <number>99</number>
               </property>
               <property name="value">
-               <number>1</number>
+               <number>0</number>
               </property>
              </widget>
@@ -775,5 +775,8 @@
         </property>
         <property name="text">
-         <string>AutoScale !</string>
+         <string>AutoScale</string>
+        </property>
+        <property name="checkable">
+         <bool>true</bool>
         </property>
        </widget>
