]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EVE/EveDet/AliEveTPCSector2DGL.cxx
fix for Savannah bug #81846
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveTPCSector2DGL.cxx
index 716152cf0c91ee7bb4096f98c3cf645650818c0d..3c5a02b8df2bad24b4db0474b373f76b6ae84d6a 100644 (file)
@@ -9,17 +9,15 @@
 
 #include "AliEveTPCSector2DGL.h"
 
-#include <EveDet/AliEveTPCData.h>
+#include <EveDet/AliEveTPCSector2D.h>
 
 #include <TGLRnrCtx.h>
 #include <TGLSelectRecord.h>
 #include <TGLIncludes.h>
 
-using namespace std;
-
 //______________________________________________________________________________
-// AliEveTPCSector2DGL
 //
+// GL renderer for AliEveTPCSector2D.
 
 ClassImp(AliEveTPCSector2DGL)
 
@@ -40,19 +38,26 @@ AliEveTPCSector2DGL::AliEveTPCSector2DGL() :
   fImage   (0),
   fTexture (0),
   fRTS     (0)
-{}
+{
+  // Constructor.
+}
 
 AliEveTPCSector2DGL::~AliEveTPCSector2DGL()
 {
-  if(fImage)   delete fImage;
-  if(fTexture) glDeleteTextures(1, &fTexture);
+  // Destructor.
+  // !!!! Should unregister texture via ContextIdentity!
+
+  if (fImage)   delete [] fImage;
+  if (fTexture) glDeleteTextures(1, &fTexture);
 }
 
 /******************************************************************************/
 
 Bool_t AliEveTPCSector2DGL::SetModel(TObject* obj, const Option_t* /*opt*/)
 {
-  if(SetModelCheckClass(obj, AliEveTPCSector2D::Class())) {
+  // Set model object.
+
+  if (SetModelCheckClass(obj, AliEveTPCSector2D::Class())) {
     fSector = (AliEveTPCSector2D*) fExternalObj;
     return kTRUE;
   }
@@ -61,14 +66,19 @@ Bool_t AliEveTPCSector2DGL::SetModel(TObject* obj, const Option_t* /*opt*/)
 
 void AliEveTPCSector2DGL::SetBBox()
 {
+  // Set bounding-box.
+
   SetAxisAlignedBBox(((AliEveTPCSector2D*)fExternalObj)->AssertBBox());
 }
 
 /******************************************************************************/
 
 void AliEveTPCSector2DGL::ProcessSelection(TGLRnrCtx       & /*rnrCtx*/,
-                                    TGLSelectRecord & rec)
+                                           TGLSelectRecord & rec)
 {
+  // Process selection record.
+  // Determine row and pad, call PadSelected() in model object.
+
   if (rec.GetN() != 3) return;
   Int_t row = rec.GetItem(1);
   Int_t pad = rec.GetItem(2);
@@ -87,44 +97,41 @@ void AliEveTPCSector2DGL::DirectDraw(TGLRnrCtx& rnrCtx) const
 
   fSectorData = fSector->GetSectorData();
 
-  if(fRTS < fSector->fRTS && fSectorData != 0) {
+  if (fRTS < fSector->fRTS && fSectorData != 0) {
     CreateTexture();
     fRTS = fSector->fRTS;
   }
 
-  glPushAttrib(GL_CURRENT_BIT      | GL_DEPTH_BUFFER_BIT |
-               GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT       | GL_POLYGON_BIT);
+  glPushAttrib(GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_POLYGON_BIT | GL_ENABLE_BIT);
 
   glDisable(GL_LIGHTING);
-  glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
-  glEnable(GL_COLOR_MATERIAL);
   glDisable(GL_CULL_FACE);
 
   // Display digits
-  if(fSectorData != 0) {
-
+  if (fSectorData != 0)
+  {
     const AliEveTPCSectorData::SegmentInfo&  iSeg = AliEveTPCSectorData::GetInnSeg();
     const AliEveTPCSectorData::SegmentInfo& o1Seg = AliEveTPCSectorData::GetOut1Seg();
     const AliEveTPCSectorData::SegmentInfo& o2Seg = AliEveTPCSectorData::GetOut2Seg();
 
-    if(rnrCtx.SecSelection()) {
+    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 {
-
-      if(fSector->fUseTexture) {
-       //texture
-       glEnable(GL_BLEND);
-       glDepthMask(GL_FALSE);
+    }
+    else
+    {
+      glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+      if (fSector->fUseTexture)
+      {
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+       glEnable(GL_BLEND);
 
-       glPolygonOffset(2,2);
-       glEnable(GL_POLYGON_OFFSET_FILL);
+       glAlphaFunc(GL_GREATER, 0.2);
+       glEnable(GL_ALPHA_TEST);
 
-       glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
        glBindTexture(GL_TEXTURE_2D, fTexture);
        glEnable(GL_TEXTURE_2D);
 
@@ -133,7 +140,9 @@ void AliEveTPCSector2DGL::DirectDraw(TGLRnrCtx& rnrCtx) const
        if(fSector->fRnrOut2) DisplayTexture(o2Seg, 0, o1Seg.GetNRows());
 
        glDisable(GL_TEXTURE_2D);
-      } else {
+      }
+      else
+      {
        if(fSector->fRnrInn)  DisplayQuads(iSeg, 0, 0);
        if(fSector->fRnrOut1) DisplayQuads(o1Seg, iSeg.GetNMaxPads(), 0);
        if(fSector->fRnrOut2) DisplayQuads(o2Seg, 0, o1Seg.GetNRows());
@@ -141,7 +150,6 @@ void AliEveTPCSector2DGL::DirectDraw(TGLRnrCtx& rnrCtx) const
       glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
       DisplayFrame();
     }
-
   }
 
   glPopAttrib();
@@ -152,8 +160,10 @@ void AliEveTPCSector2DGL::DirectDraw(TGLRnrCtx& rnrCtx) const
 /******************************************************************************/
 
 void AliEveTPCSector2DGL::LoadPadrow(AliEveTPCSectorData::RowIterator& iter,
-                              Int_t row, Int_t col_off) const
+                                     Int_t row, Int_t colOff) const
 {
+  // Load data for one pad-row into the texture.
+
   Int_t    padVal;
   Int_t    time, val;
 
@@ -161,7 +171,7 @@ void AliEveTPCSector2DGL::LoadPadrow(AliEveTPCSectorData::RowIterator& iter,
   Int_t    maxTime = fSector->fMaxTime;
   Bool_t   halfBorderTime = ((maxTime - minTime) % 2 == 0);
 
-  UChar_t* img_pos = GetRowCol(row, col_off);
+  UChar_t* imgPos = GetRowCol(row, colOff);
   while (iter.NextPad()) {
     padVal = 0;
 
@@ -184,13 +194,14 @@ void AliEveTPCSector2DGL::LoadPadrow(AliEveTPCSectorData::RowIterator& iter,
       }
     }
 
-    if(fSector->fShowMax == kFALSE && fSector->fAverage) {
+    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;
+    if (padVal > fSector->fThreshold) {
+      fSector->ColorFromArray(padVal, imgPos);
+    }
+    imgPos += 4;
   }
 }
 
@@ -198,7 +209,10 @@ void AliEveTPCSector2DGL::LoadPadrow(AliEveTPCSectorData::RowIterator& iter,
 
 void AliEveTPCSector2DGL::CreateTexture() const
 {
-  if (fImage == 0 ) {
+  // Create texture that holds pad data.
+
+  if (fImage == 0)
+  {
     fImage = new UChar_t[fgkTextureByteSize];
     glGenTextures(1, &fTexture);
   }
@@ -217,11 +231,13 @@ void AliEveTPCSector2DGL::CreateTexture() const
   fSector->SetupColorArray();
 
   // Loop over 3 main segments
-  for (Int_t sId = 0; sId <= 2; ++sId) {
-    if(isOn[sId] == kFALSE)
+  for (Int_t sId = 0; sId <= 2; ++sId)
+  {
+    if (isOn[sId] == kFALSE)
       continue;
     const AliEveTPCSectorData::SegmentInfo& sInfo = AliEveTPCSectorData::GetSeg(sId);
-    for (Int_t row=sInfo.GetFirstRow(); row<=sInfo.GetLastRow(); ++row) {
+    for (Int_t row = sInfo.GetFirstRow(); row <= sInfo.GetLastRow(); ++row)
+    {
       AliEveTPCSectorData::RowIterator i = fSectorData->MakeRowIterator(row);
       Int_t offset = (sInfo.GetNMaxPads() - AliEveTPCSectorData::GetNPadsInRow(row))/2;
       LoadPadrow(i, row + rowOff[sId], offset + colOff[sId]);
@@ -244,8 +260,10 @@ void AliEveTPCSector2DGL::CreateTexture() const
 /******************************************************************************/
 
 void AliEveTPCSector2DGL::DisplayTexture(const AliEveTPCSectorData::SegmentInfo& seg,
-                                   Int_t startCol, Int_t startRow) const
+                                         Int_t startCol, Int_t startRow) const
 {
+  // Display segment data via one textured rectangle.
+
   Float_t w  = seg.GetNMaxPads()*seg.GetPadWidth()/2;
   Float_t y1 = seg.GetRLow();
   Float_t y2 = y1 + seg.GetNRows()*seg.GetPadHeight();
@@ -266,30 +284,35 @@ void AliEveTPCSector2DGL::DisplayTexture(const AliEveTPCSectorData::SegmentInfo&
 /******************************************************************************/
 
 void AliEveTPCSector2DGL::DisplayQuads(const AliEveTPCSectorData::SegmentInfo& seg,
-                                 Int_t startCol, Int_t startRow) const
+                                       Int_t startCol, Int_t startRow) const
 {
-  Float_t y_d, y_u;
-  Float_t x_off, x;
+  // Display segment data by rendering one quad per pad.
+
+  Float_t yD, yU;
+  Float_t xOff, x;
   Float_t padW = seg.GetPadWidth();
   Float_t padH = seg.GetPadHeight();
 
   glBegin(GL_QUADS);
-  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;
+  for (Int_t row = 0; row < seg.GetNRows(); row++)
+  {
+    yD = seg.GetRLow() + row*padH;
+    yU = yD + padH;
+    xOff = -seg.GetNMaxPads()*padW/2;
     Int_t tpcRow = row + seg.GetFirstRow();
     Int_t deltaPad = (seg.GetNMaxPads() - AliEveTPCSectorData::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);
-        glVertex2f(x+padW, y_d);
-        glVertex2f(x,      y_d);
-        glVertex2f(x,      y_u);
-        glVertex2f(x+padW, y_u);
+    for (Int_t pad = deltaPad; pad < maxPad; pad++, pix+=4)
+    {
+      x = xOff + pad*padW;
+      if (pix[3] != 0)
+      {
+        TGLUtil::Color4ubv(pix);
+        glVertex2f(x+padW, yD);
+        glVertex2f(x,      yD);
+        glVertex2f(x,      yU);
+        glVertex2f(x+padW, yU);
       }
     }
   }
@@ -297,33 +320,39 @@ void AliEveTPCSector2DGL::DisplayQuads(const AliEveTPCSectorData::SegmentInfo& s
 }
 
 void AliEveTPCSector2DGL::DisplayNamedQuads(const AliEveTPCSectorData::SegmentInfo& seg,
-                                     Int_t startCol, Int_t startRow) const
+                                            Int_t startCol, Int_t startRow) const
 {
-  Float_t y_d, y_u;
-  Float_t x_off, x;
+  // Display segmen data as one quad per pad.
+  // Tag the rows and pads for selection.
+
+  Float_t yD, yU;
+  Float_t xOff, 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;
+  for (Int_t row = 0; row < seg.GetNRows(); row++)
+  {
+    yD = seg.GetRLow() + row*padH;
+    yU = yD + padH;
+    xOff = -seg.GetNMaxPads()*padW/2;
     Int_t tpcRow = row + seg.GetFirstRow();
     glLoadName(tpcRow);
     Int_t deltaPad = (seg.GetNMaxPads() - AliEveTPCSectorData::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) {
+    for (Int_t pad = deltaPad; pad < maxPad; pad++, pix+=4) 
+    {
+      x = xOff + 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);
+        glVertex2f(x+padW, yD);
+        glVertex2f(x,      yD);
+        glVertex2f(x,      yU);
+        glVertex2f(x+padW, yU);
        glEnd();
       }
     }
@@ -338,10 +367,13 @@ void AliEveTPCSector2DGL::DisplayNamedQuads(const AliEveTPCSectorData::SegmentIn
 
 void AliEveTPCSector2DGL::TraceStepsUp(const AliEveTPCSectorData::SegmentInfo& s)
 {
+  // Trace border of segment upwards.
+
   Float_t x = -(s.GetNMaxPads()*1.0/2 - s.GetNYSteps())*s.GetPadWidth();
   Float_t y  = s.GetRLow();
   glVertex2f(x, y);
-  for (Int_t i=0; i<s.GetNYSteps(); ++i) {
+  for (Int_t i = 0; i < s.GetNYSteps(); ++i)
+  {
     y = s.GetYStep(i);
     glVertex2f(x, y);
     x -= s.GetPadWidth();
@@ -353,10 +385,13 @@ void AliEveTPCSector2DGL::TraceStepsUp(const AliEveTPCSectorData::SegmentInfo& s
 
 void AliEveTPCSector2DGL::TraceStepsDown(const AliEveTPCSectorData::SegmentInfo& s)
 {
+  // Trace border of segment downwards.
+
   Float_t x = s.GetNMaxPads()*s.GetPadWidth()/2;
   Float_t y = s.GetRLow() + s.GetNRows()*s.GetPadHeight();
   glVertex2f(x, y);
-  for (Int_t i=s.GetNYSteps() - 1; i>=0; --i) {
+  for (Int_t i = s.GetNYSteps() - 1; i >= 0; --i)
+  {
     y =  s.GetYStep(i);
     glVertex2f(x, y);
     x -= s.GetPadWidth();
@@ -368,23 +403,27 @@ void AliEveTPCSector2DGL::TraceStepsDown(const AliEveTPCSectorData::SegmentInfo&
 
 void AliEveTPCSector2DGL::DisplayFrame() const
 {
-  UChar_t col[4];
-  TEveUtil::TEveUtil::ColorFromIdx(fSector->fFrameColor, col);
-  glColor4ubv(col);
+  // Display frame of the sector.
+  // Each segment's frame is drawn only if its data is drawn, too.
+
+  TGLUtil::Color(fSector->fFrameColor);
 
-  if(fSector->fRnrInn) {
+  if(fSector->fRnrInn)
+  {
     glBegin(GL_POLYGON);
     TraceStepsUp  (AliEveTPCSectorData::GetInnSeg());
     TraceStepsDown(AliEveTPCSectorData::GetInnSeg());
     glEnd();
   }
-  if(fSector->fRnrOut1) {
+  if(fSector->fRnrOut1)
+  {
     glBegin(GL_POLYGON);
     TraceStepsUp  (AliEveTPCSectorData::GetOut1Seg());
     TraceStepsDown(AliEveTPCSectorData::GetOut1Seg());
     glEnd();
   }
-  if(fSector->fRnrOut2) {
+  if(fSector->fRnrOut2)
+  {
     glBegin(GL_POLYGON);
     TraceStepsUp  (AliEveTPCSectorData::GetOut2Seg());
     TraceStepsDown(AliEveTPCSectorData::GetOut2Seg());