]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EVE/Alieve/TPCSector2DGL.cxx
Minor changes in the local case based on the v4-04-Rev-14
[u/mrichter/AliRoot.git] / EVE / Alieve / TPCSector2DGL.cxx
index edf8a9de448f182ea2ad66dadff7d849ed3786d1..288fab11bc164677247e47a2055d424d1397f279 100644 (file)
@@ -4,17 +4,21 @@
 
 #include <Alieve/TPCData.h>
 
-#include <TStyle.h>
-#include <TColor.h>
-#include <TStopwatch.h>
-
-#include <GL/gl.h>
+#include <TGLRnrCtx.h>
+#include <TGLSelectRecord.h>
+#include <TGLIncludes.h>
 
 using namespace Reve;
 using namespace Alieve;
 using namespace std;
 
-  // This can be optimized to non-pow-2 values once everybody has GL 1.4.
+//______________________________________________________________________
+// TPCSector2DGL
+//
+
+ClassImp(TPCSector2DGL)
+
+// This can be optimized to non-pow-2 values once everybody has GL 1.4.
 
 const Int_t TPCSector2DGL::fgkTextureWidth    = 256;
 const Int_t TPCSector2DGL::fgkTextureHeight   = 128;
@@ -22,15 +26,16 @@ const Int_t TPCSector2DGL::fgkTextureByteSize = 4*256*128;
 
 /**************************************************************************/
 
-TPCSector2DGL::TPCSector2DGL() : TGLObject()
-{
-  fSector     = 0;
-  fSectorData = 0;
+TPCSector2DGL::TPCSector2DGL() :
+  TGLObject(),
+  
+  fSector     (0),
+  fSectorData (0),
 
-  fImage   = 0;
-  fTexture = 0;
-  fRTS     = 0;
-}
+  fImage   (0),
+  fTexture (0),
+  fRTS     (0)
+{}
 
 TPCSector2DGL::~TPCSector2DGL()
 {
@@ -40,54 +45,42 @@ TPCSector2DGL::~TPCSector2DGL()
 
 /**************************************************************************/
 
-Bool_t TPCSector2DGL::SetModel(TObject* obj)
+Bool_t TPCSector2DGL::SetModel(TObject* obj, const Option_t* /*opt*/)
 {
-  if (set_model(obj, "Alieve::TPCSector2D")) {
+  if(SetModelCheckClass(obj, Alieve::TPCSector2D::Class())) {
     fSector = (TPCSector2D*) fExternalObj;
-    return true;
+    return kTRUE;
   }
-  return false;
+  return kFALSE;
 }
 
 void TPCSector2DGL::SetBBox()
 {
-  set_axis_aligned_bbox(((TPCSector2D*)fExternalObj)->AssertBBox());
+  SetAxisAlignedBBox(((TPCSector2D*)fExternalObj)->AssertBBox());
 }
 
 /**************************************************************************/
 
-void TPCSector2DGL::SetCol(Float_t z, UChar_t* pixel) const
+void TPCSector2DGL::ProcessSelection(TGLRnrCtx       & /*rnrCtx*/,
+                                    TGLSelectRecord & rec)
 {
-  Int_t n_col = gStyle->GetNumberOfColors();
-
-  Int_t ci = gStyle->GetColorPalette
-    (TMath::Min(n_col - 1,
-                Int_t((n_col*(z - fSector->fthreshold))/(fSector->fMaxVal - fSector->fthreshold))));
-
-  TColor* c = gROOT->GetColor(ci);
-
-  if(c) {
-    //    UChar_t *x = (UChar_t*) &c;
-    pixel[0] = (UChar_t)(255*c->GetRed());
-    pixel[1] = (UChar_t)(255*c->GetGreen());
-    pixel[2] = (UChar_t)(255*c->GetBlue());
-    pixel[3] = 255;
-  }
+  if (rec.GetN() != 3) return;
+  Int_t row = rec.GetItem(1);
+  Int_t pad = rec.GetItem(2);
+  if (row < 0 || row >= TPCSectorData::GetNAllRows())      return;
+  if (pad < 0 || pad >= TPCSectorData::GetNPadsInRow(row)) return;
+  fSector->PadSelected(row, pad);
 }
 
 /**************************************************************************/
 
-void TPCSector2DGL::DirectDraw(const TGLDrawFlags& /*flags*/) const
+void TPCSector2DGL::DirectDraw(TGLRnrCtx& rnrCtx) const
 {
   // Actual GL drawing.
 
   // printf("TPCSector2DGL::DirectDraw \n");
 
-  if(fSector->fTPCData == 0)
-    fSectorData = 0;
-  else
-    fSectorData = fSector->fTPCData->GetSectorData(fSector->fSectorID);
+  fSectorData = fSector->GetSectorData();
 
   if(fRTS < fSector->fRTS && fSectorData != 0) {
     CreateTexture();
@@ -109,49 +102,42 @@ void TPCSector2DGL::DirectDraw(const TGLDrawFlags& /*flags*/) const
     const TPCSectorData::SegmentInfo& o1Seg = TPCSectorData::GetOut1Seg();
     const TPCSectorData::SegmentInfo& o2Seg = TPCSectorData::GetOut2Seg();
 
-    if(fSector->fUseTexture) {
-      //texture
-      glEnable(GL_BLEND);
-      glDepthMask(GL_FALSE);
-      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-      glShadeModel(GL_FLAT);
-
-      glBindTexture  (GL_TEXTURE_2D, fTexture);
-
-      glPolygonOffset(2,2);
-      glEnable(GL_POLYGON_OFFSET_FILL);
-
-      glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-      glBindTexture(GL_TEXTURE_2D, fTexture);
-      glEnable(GL_TEXTURE_2D);
-
-      DisplayTexture(iSeg.GetPadWidth(),  iSeg.GetPadHeight(),  iSeg.GetRLow(),
-                    iSeg.GetNMaxPads(),  iSeg.GetNRows(),
-                    0,                   0);
-      DisplayTexture(o1Seg.GetPadWidth(), o1Seg.GetPadHeight(), o1Seg.GetRLow(),
-                    o1Seg.GetNMaxPads(), o1Seg.GetNRows(),
-                    iSeg.GetNMaxPads(),  0);
-      DisplayTexture(o2Seg.GetPadWidth(), o2Seg.GetPadHeight(), o2Seg.GetRLow(),
-                    o2Seg.GetNMaxPads(), o2Seg.GetNRows(),
-                    0,                   o1Seg.GetNRows());
-
-      glDisable(GL_TEXTURE_2D);
+    if(rnrCtx.SecSelection()) {
+
+      if(fSector->fRnrInn)  DisplayNamedQuads(iSeg, 0, 0);
+      if(fSector->fRnrOut1) DisplayNamedQuads(o1Seg, iSeg.GetNMaxPads(), 0);
+      if(fSector->fRnrOut2) DisplayNamedQuads(o2Seg, 0, o1Seg.GetNRows());
+
     } else {
-      DisplayQuads(iSeg.GetPadWidth(),  iSeg.GetPadHeight(),  iSeg.GetRLow(),
-                  iSeg.GetNMaxPads(),  iSeg.GetNRows(),
-                  0,                   0);
-      DisplayQuads(o1Seg.GetPadWidth(), o1Seg.GetPadHeight(), o1Seg.GetRLow(),
-                  o1Seg.GetNMaxPads(), o1Seg.GetNRows(),
-                  iSeg.GetNMaxPads(),    0);
-      DisplayQuads(o2Seg.GetPadWidth(), o2Seg.GetPadHeight(), o2Seg.GetRLow(),
-                  o2Seg.GetNMaxPads(), o2Seg.GetNRows(),
-                  0,                   o1Seg.GetNRows());
+
+      if(fSector->fUseTexture) {
+       //texture
+       glEnable(GL_BLEND);
+       glDepthMask(GL_FALSE);
+       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+       glPolygonOffset(2,2);
+       glEnable(GL_POLYGON_OFFSET_FILL);
+
+       glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+       glBindTexture(GL_TEXTURE_2D, fTexture);
+       glEnable(GL_TEXTURE_2D);
+
+       if(fSector->fRnrInn)  DisplayTexture(iSeg, 0, 0);
+       if(fSector->fRnrOut1) DisplayTexture(o1Seg, iSeg.GetNMaxPads(), 0);
+       if(fSector->fRnrOut2) DisplayTexture(o2Seg, 0, o1Seg.GetNRows());
+
+       glDisable(GL_TEXTURE_2D);
+      } else {
+       if(fSector->fRnrInn)  DisplayQuads(iSeg, 0, 0);
+       if(fSector->fRnrOut1) DisplayQuads(o1Seg, iSeg.GetNMaxPads(), 0);
+       if(fSector->fRnrOut2) DisplayQuads(o2Seg, 0, o1Seg.GetNRows());
+      }
+      glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+      DisplayFrame();
     }
-  }
 
-  // Display frame
-  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-  DisplayFrame();
+  }
 
   glPopAttrib();
 }
@@ -163,39 +149,42 @@ void TPCSector2DGL::DirectDraw(const TGLDrawFlags& /*flags*/) const
 void TPCSector2DGL::LoadPadrow(TPCSectorData::RowIterator& iter,
                               Int_t row, Int_t col_off) const
 {
-  Int_t    pad_var;
+  Int_t    padVal;
   Int_t    time, val;   
 
-  Int_t    min_time = fSector->fMinTime;
-  Int_t    max_time = fSector->fMaxTime;
-  Bool_t   half_border_time = ((fSector->fMaxTime - fSector->fMinTime) % 2 == 0);
+  Int_t    minTime = fSector->fMinTime;
+  Int_t    maxTime = fSector->fMaxTime;
+  Bool_t   halfBorderTime = ((maxTime - minTime) % 2 == 0);
 
   UChar_t* img_pos = GetRowCol(row, col_off);
   while (iter.NextPad()) {
-    pad_var = 0; 
+    padVal = 0; 
 
     while (iter.Next()) {
       time = iter.Time();
       val  = iter.Signal();
 
+      if(time < minTime || time > maxTime)
+       continue;
+
       if(fSector->fShowMax) {
-        if(val > pad_var) {
-          pad_var = val;
+        if(val > padVal) {
+          padVal = val;
         }
       } else {
-        // Integrate int max_val.
-        if(time >= min_time && time <= max_time) {
-          if(half_border_time && (time == min_time || time == max_time))
-            pad_var += val/2;
-          else
-            pad_var += val;
-        }
+       if(halfBorderTime && (time == minTime || time == maxTime))
+         padVal += val/2;
+       else
+         padVal += val;
       }
     }
 
-    pad_var = TMath::Min(pad_var, fSector->fMaxVal);
-    if(pad_var > fSector->fthreshold)
-      SetCol(pad_var, img_pos);
+    if(fSector->fShowMax == kFALSE && fSector->fAverage) {
+      padVal = (Int_t)((Float_t)padVal / (maxTime - minTime));
+    }
+    padVal = TMath::Min(padVal, fSector->fMaxVal);
+    if(padVal > fSector->fThreshold)
+      fSector->ColorFromArray(padVal, img_pos);
     img_pos += 4;
   }
 }
@@ -211,11 +200,21 @@ void TPCSector2DGL::CreateTexture() const
   memset(fImage, 0, fgkTextureByteSize);
 
   Int_t rowOff[3], colOff[3];
-  rowOff[0] = 0; rowOff[1] = rowOff[2] = -TPCSectorData::GetSeg(1).GetFirstRow();
-  colOff[0] = colOff[2] = 0; colOff[1] =  TPCSectorData::GetSeg(0).GetNMaxPads();
+  Bool_t isOn[3];
+  rowOff[0] = 0;
+  rowOff[1] = rowOff[2] = -TPCSectorData::GetSeg(1).GetFirstRow();
+  colOff[0] = colOff[2] = 0;
+  colOff[1] = TPCSectorData::GetSeg(0).GetNMaxPads();
+  isOn[0] = fSector->fRnrInn;
+  isOn[1] = fSector->fRnrOut1;
+  isOn[2] = fSector->fRnrOut2;
+
+  fSector->SetupColorArray();
 
   // Loop over 3 main segments
   for (Int_t sId = 0; sId <= 2; ++sId) {
+    if(isOn[sId] == kFALSE)
+      continue;
     const TPCSectorData::SegmentInfo& sInfo = TPCSectorData::GetSeg(sId);
     for (Int_t row=sInfo.GetFirstRow(); row<=sInfo.GetLastRow(); ++row) {
       TPCSectorData::RowIterator i = fSectorData->MakeRowIterator(row);
@@ -229,7 +228,7 @@ void TPCSector2DGL::CreateTexture() const
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_REPEAT);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-  // glTexEnvf      (GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,   GL_MODULATE); // Lightning is off anyway.
+  glTexEnvf      (GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,   GL_REPLACE);
   glTexImage2D   (GL_TEXTURE_2D, 0, GL_RGBA, fgkTextureWidth, fgkTextureHeight,
                   0, GL_RGBA, GL_UNSIGNED_BYTE, fImage);
 
@@ -239,41 +238,46 @@ void TPCSector2DGL::CreateTexture() const
 // Data display
 /**************************************************************************/
 
-void TPCSector2DGL::DisplayTexture(Float_t padW,     Float_t padH, Float_t startR,
-                                   Int_t numMaxPads, Int_t numRows, 
-                                   Int_t startCol,   Int_t startRow) const
+void TPCSector2DGL::DisplayTexture(const TPCSectorData::SegmentInfo& seg,
+                                   Int_t startCol, Int_t startRow) const
 {
-  Float_t w  = numMaxPads*padW/2;
+  Float_t w  = seg.GetNMaxPads()*seg.GetPadWidth()/2;
+  Float_t y1 = seg.GetRLow();
+  Float_t y2 = y1 + seg.GetNRows()*seg.GetPadHeight();
+
   Float_t u1 = (Float_t) startCol / fgkTextureWidth;
   Float_t v1 = (Float_t) startRow / fgkTextureHeight;
-  Float_t u2 = u1 + (Float_t) numMaxPads / fgkTextureWidth;
-  Float_t v2 = v1 + (Float_t) numRows    / fgkTextureHeight;
+  Float_t u2 = u1 + (Float_t) seg.GetNMaxPads() / fgkTextureWidth;
+  Float_t v2 = v1 + (Float_t) seg.GetNRows()    / fgkTextureHeight;
 
   glBegin(GL_QUADS);  
-  glTexCoord2f(u1, v1);  glVertex2f(-w, startR);
-  glTexCoord2f(u1, v2);  glVertex2f(-w, startR + numRows*padH);
-  glTexCoord2f(u2, v2);  glVertex2f( w, startR + numRows*padH);
-  glTexCoord2f(u2, v1);  glVertex2f( w, startR);
+  glTexCoord2f(u1, v1);  glVertex2f(-w, y1);
+  glTexCoord2f(u1, v2);  glVertex2f(-w, y2);
+  glTexCoord2f(u2, v2);  glVertex2f( w, y2);
+  glTexCoord2f(u2, v1);  glVertex2f( w, y1);
   glEnd();
 }
 
 /**************************************************************************/
 
-void TPCSector2DGL::DisplayQuads(Float_t padW,     Float_t padH, Float_t startR,
-                                 Int_t numMaxPads, Int_t numRows, 
-                                 Int_t startCol,   Int_t startRow) const
+void TPCSector2DGL::DisplayQuads(const TPCSectorData::SegmentInfo& seg,
+                                 Int_t startCol, Int_t startRow) const
 {
-  UChar_t *pix;
   Float_t y_d, y_u;
   Float_t x_off, x;
+  Float_t padW = seg.GetPadWidth();
+  Float_t padH = seg.GetPadHeight();
 
   glBegin(GL_QUADS);
-  for (Int_t row=0; row<numRows; row++) {
-    y_d = startR + row*padH;
+  for (Int_t row=0; row<seg.GetNRows(); row++) {
+    y_d = seg.GetRLow() + row*padH;
     y_u = y_d + padH;
-    x_off = -numMaxPads*padW/2;
-    pix = GetRowCol(row + startRow, startCol);
-    for (Int_t pad=0; pad<numMaxPads; pad++, pix+=4) {
+    x_off = -seg.GetNMaxPads()*padW/2;
+    Int_t tpcRow = row + seg.GetFirstRow();
+    Int_t deltaPad = (seg.GetNMaxPads() - TPCSectorData::GetNPadsInRow(tpcRow))/2;
+    Int_t   maxPad = seg.GetNMaxPads() - deltaPad;
+    UChar_t   *pix = GetRowCol(row + startRow, startCol + deltaPad);
+    for (Int_t pad=deltaPad; pad<maxPad; pad++, pix+=4) {
       x = x_off + pad*padW;
       if (pix[3] != 0) {
         glColor4ubv(pix);
@@ -287,6 +291,42 @@ void TPCSector2DGL::DisplayQuads(Float_t padW,     Float_t padH, Float_t startR,
   glEnd();
 }
 
+void TPCSector2DGL::DisplayNamedQuads(const TPCSectorData::SegmentInfo& seg,
+                                     Int_t startCol, Int_t startRow) const
+{
+  Float_t y_d, y_u;
+  Float_t x_off, x;
+  Float_t padW = seg.GetPadWidth();
+  Float_t padH = seg.GetPadHeight();
+
+  glPushName(0);
+  for (Int_t row=0; row<seg.GetNRows(); row++) {
+    y_d = seg.GetRLow() + row*padH;
+    y_u = y_d + padH;
+    x_off = -seg.GetNMaxPads()*padW/2;
+    Int_t tpcRow = row + seg.GetFirstRow();
+    glLoadName(tpcRow);
+    Int_t deltaPad = (seg.GetNMaxPads() - TPCSectorData::GetNPadsInRow(tpcRow))/2;
+    Int_t   maxPad = seg.GetNMaxPads() - deltaPad;
+    UChar_t   *pix = GetRowCol(row + startRow, startCol + deltaPad);
+    glPushName(0);
+    for (Int_t pad=deltaPad; pad<maxPad; pad++, pix+=4) {
+      x = x_off + pad*padW;
+      if (pix[3] != 0 || fSector->fPickEmpty) {
+       glLoadName(pad - deltaPad);
+       glBegin(GL_QUADS);
+        glVertex2f(x+padW, y_d);
+        glVertex2f(x,      y_d);
+        glVertex2f(x,      y_u);
+        glVertex2f(x+padW, y_u);
+       glEnd();
+      }
+    }
+    glPopName();
+  }
+  glPopName();
+}
+
 /**************************************************************************/
 // Frame drawing
 /**************************************************************************/
@@ -323,28 +363,26 @@ void TPCSector2DGL::TraceStepsDown(const TPCSectorData::SegmentInfo& s)
 
 void TPCSector2DGL::DisplayFrame() const
 {
-  TColor* c = gROOT->GetColor(fSector->fFrameCol);
-  if(c == 0) return; 
-
-  // x[0] = (UChar_t)(255*c->GetRed());  x[1] = (UChar_t)(255*c->GetGreen());
-  // x[2] = (UChar_t)(255*c->GetBlue()); x[3] = 255;
-
-  glColor3ub((UChar_t)(255*c->GetRed()), 
-             (UChar_t)(255*c->GetGreen()),
-             (UChar_t)(255*c->GetBlue()));
-
-  glBegin(GL_LINE_LOOP);
-  TraceStepsUp  (TPCSectorData::GetInnSeg());
-  TraceStepsDown(TPCSectorData::GetInnSeg());
-  glEnd();
-
-  glBegin(GL_LINE_LOOP);
-  TraceStepsUp  (TPCSectorData::GetOut1Seg());
-  TraceStepsDown(TPCSectorData::GetOut1Seg());
-  glEnd();
-
-  glBegin(GL_LINE_STRIP);
-  TraceStepsUp  (TPCSectorData::GetOut2Seg());
-  TraceStepsDown(TPCSectorData::GetOut2Seg());
-  glEnd();
+  UChar_t col[4];
+  ColorFromIdx(fSector->fFrameColor, col);
+  glColor4ubv(col);
+
+  if(fSector->fRnrInn) {
+    glBegin(GL_POLYGON);
+    TraceStepsUp  (TPCSectorData::GetInnSeg());
+    TraceStepsDown(TPCSectorData::GetInnSeg());
+    glEnd();
+  }
+  if(fSector->fRnrOut1) {
+    glBegin(GL_POLYGON);
+    TraceStepsUp  (TPCSectorData::GetOut1Seg());
+    TraceStepsDown(TPCSectorData::GetOut1Seg());
+    glEnd();
+  }
+  if(fSector->fRnrOut2) {
+    glBegin(GL_POLYGON);
+    TraceStepsUp  (TPCSectorData::GetOut2Seg());
+    TraceStepsDown(TPCSectorData::GetOut2Seg());
+    glEnd();
+  }
 }