// $Id$ // Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007 /************************************************************************** * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. * * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for * * full copyright notice. * **************************************************************************/ #include "AliEveTPCSector2DGL.h" #include #include #include #include using namespace std; //______________________________________________________________________ // AliEveTPCSector2DGL // ClassImp(AliEveTPCSector2DGL) // This can be optimized to non-pow-2 values once everybody has GL 1.4. const Int_t AliEveTPCSector2DGL::fgkTextureWidth = 256; const Int_t AliEveTPCSector2DGL::fgkTextureHeight = 128; const Int_t AliEveTPCSector2DGL::fgkTextureByteSize = 4*256*128; /**************************************************************************/ AliEveTPCSector2DGL::AliEveTPCSector2DGL() : TGLObject(), fSector (0), fSectorData (0), fImage (0), fTexture (0), fRTS (0) {} AliEveTPCSector2DGL::~AliEveTPCSector2DGL() { if(fImage) delete fImage; if(fTexture) glDeleteTextures(1, &fTexture); } /**************************************************************************/ Bool_t AliEveTPCSector2DGL::SetModel(TObject* obj, const Option_t* /*opt*/) { if(SetModelCheckClass(obj, AliEveTPCSector2D::Class())) { fSector = (AliEveTPCSector2D*) fExternalObj; return kTRUE; } return kFALSE; } void AliEveTPCSector2DGL::SetBBox() { SetAxisAlignedBBox(((AliEveTPCSector2D*)fExternalObj)->AssertBBox()); } /**************************************************************************/ void AliEveTPCSector2DGL::ProcessSelection(TGLRnrCtx & /*rnrCtx*/, TGLSelectRecord & rec) { if (rec.GetN() != 3) return; Int_t row = rec.GetItem(1); Int_t pad = rec.GetItem(2); if (row < 0 || row >= AliEveTPCSectorData::GetNAllRows()) return; if (pad < 0 || pad >= AliEveTPCSectorData::GetNPadsInRow(row)) return; fSector->PadSelected(row, pad); } /**************************************************************************/ void AliEveTPCSector2DGL::DirectDraw(TGLRnrCtx& rnrCtx) const { // Actual GL drawing. // printf("AliEveTPCSector2DGL::DirectDraw \n"); fSectorData = fSector->GetSectorData(); 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); glDisable(GL_LIGHTING); glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); glEnable(GL_COLOR_MATERIAL); glDisable(GL_CULL_FACE); // Display digits 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(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); 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(); } } glPopAttrib(); } /**************************************************************************/ // Data import /**************************************************************************/ void AliEveTPCSector2DGL::LoadPadrow(AliEveTPCSectorData::RowIterator& iter, Int_t row, Int_t col_off) const { Int_t padVal; Int_t time, val; 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()) { padVal = 0; while (iter.Next()) { time = iter.Time(); val = iter.Signal(); if(time < minTime || time > maxTime) continue; if(fSector->fShowMax) { if(val > padVal) { padVal = val; } } else { if(halfBorderTime && (time == minTime || time == maxTime)) padVal += val/2; else padVal += val; } } 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; } } /**************************************************************************/ void AliEveTPCSector2DGL::CreateTexture() const { if (fImage == 0 ) { fImage = new UChar_t[fgkTextureByteSize]; glGenTextures(1, &fTexture); } memset(fImage, 0, fgkTextureByteSize); Int_t rowOff[3], colOff[3]; Bool_t isOn[3]; rowOff[0] = 0; rowOff[1] = rowOff[2] = -AliEveTPCSectorData::GetSeg(1).GetFirstRow(); colOff[0] = colOff[2] = 0; colOff[1] = AliEveTPCSectorData::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 AliEveTPCSectorData::SegmentInfo& sInfo = AliEveTPCSectorData::GetSeg(sId); 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]); } } glBindTexture (GL_TEXTURE_2D, fTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_REPEAT); 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_REPLACE); glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, fgkTextureWidth, fgkTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, fImage); } /**************************************************************************/ // Data display /**************************************************************************/ void AliEveTPCSector2DGL::DisplayTexture(const AliEveTPCSectorData::SegmentInfo& seg, Int_t startCol, Int_t startRow) const { 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) seg.GetNMaxPads() / fgkTextureWidth; Float_t v2 = v1 + (Float_t) seg.GetNRows() / fgkTextureHeight; glBegin(GL_QUADS); 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 AliEveTPCSector2DGL::DisplayQuads(const AliEveTPCSectorData::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(); glBegin(GL_QUADS); for (Int_t row=0; rowfPickEmpty) { 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 /**************************************************************************/ void AliEveTPCSector2DGL::TraceStepsUp(const AliEveTPCSectorData::SegmentInfo& s) { 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=0; --i) { y = s.GetYStep(i); glVertex2f(x, y); x -= s.GetPadWidth(); glVertex2f(x, y); } y = s.GetRLow(); glVertex2f((0.5*s.GetNMaxPads() - s.GetNYSteps())*s.GetPadWidth(), y); } void AliEveTPCSector2DGL::DisplayFrame() const { UChar_t col[4]; TEveUtil::TEveUtil::ColorFromIdx(fSector->fFrameColor, col); glColor4ubv(col); if(fSector->fRnrInn) { glBegin(GL_POLYGON); TraceStepsUp (AliEveTPCSectorData::GetInnSeg()); TraceStepsDown(AliEveTPCSectorData::GetInnSeg()); glEnd(); } if(fSector->fRnrOut1) { glBegin(GL_POLYGON); TraceStepsUp (AliEveTPCSectorData::GetOut1Seg()); TraceStepsDown(AliEveTPCSectorData::GetOut1Seg()); glEnd(); } if(fSector->fRnrOut2) { glBegin(GL_POLYGON); TraceStepsUp (AliEveTPCSectorData::GetOut2Seg()); TraceStepsDown(AliEveTPCSectorData::GetOut2Seg()); glEnd(); } }