41 ClassImp(TEveCaloLegoOverlay);
46 TEveCaloLegoOverlay::TEveCaloLegoOverlay() :
52 fScaleColor(-1), fScaleTransparency(0),
53 fScaleCoordX(0.85), fScaleCoordY(0.65),
54 fScaleW(0), fScaleH(0),
55 fCellX(-1), fCellY(-1),
57 fFrameColor(-1), fFrameLineTransp(70), fFrameBgTransp(90),
59 fMouseX(0), fMouseY(0),
62 fHeaderSelected(kFALSE),
64 fPlaneAxis(0), fAxisPlaneColor(kGray),
74 fActiveID(-1), fActiveCol(kRed-4)
76 fPlaneAxis =
new TAxis();
83 Bool_t TEveCaloLegoOverlay::SetSliderVal(Event_t* event, TGLRnrCtx &rnrCtx)
87 TGLRect& wprt = rnrCtx.RefCamera().RefViewport();
88 fSliderVal = (1 -
event->fY*1./wprt.Height() -fSliderPosY)/fSliderH;
92 else if (fSliderVal > 1)
95 fCalo->SetHPlaneVal(fSliderVal);
104 Bool_t TEveCaloLegoOverlay::Handle(TGLRnrCtx & rnrCtx,
105 TGLOvlSelectRecord & selRec,
108 if (selRec.GetN() < 2)
return kFALSE;
111 if (rnrCtx.RefCamera().IsOrthographic())
113 switch (event->fType)
130 const TGLRect& vp = rnrCtx.RefCamera().RefViewport();
131 fScaleCoordX += (Float_t)(event->fX - fMouseX) / vp.Width();
132 fScaleCoordY -= (Float_t)(event->fY - fMouseY) / vp.Height();
136 if (fScaleCoordX < 0)
138 else if (fScaleCoordX + fScaleW > 1.0f)
139 fScaleCoordX = 1.0f - fScaleW;
140 if (fScaleCoordY < 0)
142 else if (fScaleCoordY + fScaleH > 1.0f)
143 fScaleCoordY = 1.0f - fScaleH;
154 switch (event->fType)
158 Int_t item = selRec.GetN() < 2 ? -1 : (Int_t)selRec.GetItem(1);
159 if (fActiveID != item) {
163 if (fActiveID == 2 && event->fState == 256)
164 return SetSliderVal(event, rnrCtx);
172 if (event->fCode != kButton1) {
175 switch (selRec.GetItem(1))
178 fShowSlider = !fShowSlider;
179 fCalo->SetDrawHPlane(fShowSlider);
182 return SetSliderVal(event, rnrCtx);
184 fHeaderSelected = !fHeaderSelected;
200 Bool_t TEveCaloLegoOverlay::MouseEnter(TGLOvlSelectRecord& )
208 void TEveCaloLegoOverlay::MouseLeave()
216 void TEveCaloLegoOverlay::SetScaleColorTransparency(Color_t colIdx, Char_t transp)
218 fScaleColor = colIdx;
219 fScaleTransparency = transp;
225 void TEveCaloLegoOverlay::SetScalePosition(Double_t x, Double_t y)
234 void TEveCaloLegoOverlay:: SetFrameAttribs(Color_t frameColor, Char_t lineTransp, Char_t bgTransp)
236 fFrameColor = frameColor;
237 fFrameLineTransp = lineTransp;
238 fFrameBgTransp = bgTransp;
242 void TEveCaloLegoOverlay::RenderHeader(TGLRnrCtx& rnrCtx)
246 TGLRect &vp = rnrCtx.GetCamera()->RefViewport();
249 Int_t fs = TMath::Max(TMath::Nint(vp.Height()*0.035), 12);
250 rnrCtx.RegisterFontNoScale(fs,
"arial", TGLFont::kPixmap, font);
252 Float_t off = fs*0.2;
254 font.BBox(fHeaderTxt.Data(), bb[0], bb[1], bb[2], bb[3], bb[4], bb[5]);
255 Float_t x = vp.Width() -bb[3] -off;
256 Float_t y = vp.Height() -bb[4] -off;
257 if (rnrCtx.Selection())
262 glVertex2f(x/vp.Width(), y/ vp.Height());
263 glVertex2f(1, y/ vp.Height());
265 glVertex2f(x/vp.Width(), 1);
271 TGLUtil::Color(fHeaderSelected ? fActiveCol : fCalo->GetFontColor());
273 glBitmap(0, 0, 0, 0, x, y, 0);
274 font.Render(fHeaderTxt.Data());
282 void TEveCaloLegoOverlay::RenderPlaneInterface(TGLRnrCtx &rnrCtx)
284 glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT | GL_LINE_BIT | GL_POINT_BIT);
285 glEnable(GL_POINT_SMOOTH);
286 glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
287 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
288 glEnable(GL_POLYGON_OFFSET_FILL);
289 glPolygonOffset(0.1, 1);
290 glDisable(GL_CULL_FACE);
292 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
295 Double_t maxVal = fCalo->GetMaxVal();
299 glTranslatef(1 -fMenuW, (1-fButtonW )*fMenuW*0.8, 0);
304 (fActiveID == 1) ? TGLUtil::Color(fActiveCol):TGLUtil::Color4f(0, 1, 0, a);
305 Float_t bw = fButtonW*fMenuW*0.5;
306 Float_t bwt = bw*0.8;
307 Float_t bh = fButtonW*fMenuW;
311 glVertex2f( bwt, bh);
312 glVertex2f(-bwt, bh);
316 TGLUtil::LineWidth(1);
319 glVertex2f(0, 0); glVertex2f(0, bh);
320 glVertex2f((bw+bwt)*0.5, bh*0.5); glVertex2f(-(bw+bwt)*0.5, bh*0.5);
323 TGLUtil::LineWidth(2);
324 glBegin(GL_LINE_LOOP);
327 glVertex2f( bwt, bh);
328 glVertex2f(-bwt, bh);
330 TGLUtil::LineWidth(1);
332 glTranslatef(0, fSliderPosY, 0.5);
337 if (rnrCtx.Selection())
340 Float_t w = fButtonW*fMenuW*0.5f;
344 glVertex2f( w, fSliderH);
345 glVertex2f(-w, fSliderH);
350 fAxisPainter->SetLabelPixelFontSize(TMath::CeilNint(rnrCtx.GetCamera()->RefViewport().Height()*GetAttAxis()->GetLabelSize()));
351 fAxisPainter->RefDir().Set(0, 1, 0);
352 fAxisPainter->RefTMOff(0).Set(1, 0, 0);
353 fAxisPainter->SetLabelAlign(TGLFont::kLeft, TGLFont::kCenterV);
354 fPlaneAxis->SetRangeUser(0, maxVal);
355 fPlaneAxis->SetLimits(0, maxVal);
356 fPlaneAxis->SetNdivisions(710);
357 fPlaneAxis->SetTickLength(0.02*maxVal);
358 fPlaneAxis->SetLabelOffset(0.02*maxVal);
359 fPlaneAxis->SetLabelSize(0.05);
362 glScalef(fSliderH/(maxVal), fSliderH/maxVal, 1.);
363 fAxisPainter->PaintAxis(rnrCtx, fPlaneAxis);
367 TGLUtil::Color((fActiveID == 2) ? fActiveCol : 3);
368 TGLUtil::PointSize(8);
370 glVertex3f(0, fSliderVal*fSliderH, -0.1);
380 void TEveCaloLegoOverlay::RenderLogaritmicScales(TGLRnrCtx& rnrCtx)
384 TGLRect &vp = rnrCtx.GetCamera()->RefViewport();
386 Double_t maxVal = fCalo->GetMaxVal();
387 Int_t maxe = TMath::CeilNint(TMath::Log10(maxVal+1));
388 Double_t sqv = TMath::Power(10, maxe)+1;
389 Double_t fc = TMath::Log10(sqv)/TMath::Log10(fCalo->GetMaxVal()+1);
390 Double_t cellX = fCellX*fc;
391 Double_t cellY = fCellY*fc;
393 Double_t scaleStepY = 0.1;
394 Double_t scaleStepX = scaleStepY*vp.Height()/vp.Width();
396 Double_t frameOff = 0.01;
399 while(cellY > scaleStepY)
401 fc = TMath::Log10(TMath::Power(10, maxe-1)+1)/TMath::Log10(TMath::Power(10, maxe)+1);
407 sqv = TMath::Power(10, maxe)+1;
409 glTranslatef(fScaleCoordX + 0.5*scaleStepX + frameOff, fScaleCoordY + 0.5*scaleStepY + frameOff, 0);
411 glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT | GL_LINE_BIT | GL_POINT_BIT);
413 glDisable(GL_CULL_FACE);
414 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
415 glEnable(GL_POLYGON_OFFSET_FILL);
416 glPolygonOffset(0.1, 1);
422 Color_t color = fScaleColor > -1 ? fScaleColor : rnrCtx.ColorSet().Markup().GetColorIndex();
423 TGLUtil::ColorTransparency(color, fScaleTransparency);
428 for (Int_t i=0; i < ne; ++i)
430 Float_t valFac = TMath::Log10(TMath::Power(10, maxe-i)+1)/TMath::Log10(sqv);
431 dx = 0.5* cellX * valFac;
432 dy = 0.5* cellY * valFac;
434 glVertex2f( - dx, pos - dy);
435 glVertex2f( - dx, pos + dy);
436 glVertex2f( + dx, pos + dy);
437 glVertex2f( + dx, pos - dy);
443 for (Int_t i=0; i < ne; ++i)
444 glVertex2f(0, i* scaleStepY);
449 Int_t fsb = TMath::Max(TMath::Nint(vp.Height()*0.03), 12);
450 rnrCtx.RegisterFontNoScale(fsb,
"arial", TGLFont::kPixmap, fontB);
452 Int_t fsE = TMath::Max(TMath::Nint(vp.Height()*0.01), 8);
453 rnrCtx.RegisterFontNoScale(fsE,
"arial", TGLFont::kPixmap, fontE);
455 Float_t llx, lly, llz, urx, ury, urz;
456 fontB.BBox(
"10", llx, lly, llz, urx, ury, urz);
457 Float_t expX = urx/vp.Width();
458 Float_t expY = (ury-lly)*0.5/vp.Height();
463 glTranslatef(0.5*scaleStepX, 0, 0.1);
464 for (Int_t i = 0; i < ne; ++i)
468 fontB.Render(
"1", 0, i*scaleStepY, 0, TGLFont::kLeft, TGLFont::kCenterV);
470 else if ( i == (maxe -1))
472 fontB.Render(
"10", 0, i*scaleStepY, 0, TGLFont::kLeft, TGLFont::kCenterV);
476 fontB.Render(
"10", 0, i*scaleStepY, 0, TGLFont::kLeft, TGLFont::kCenterV);
477 fontB.BBox(Form(
"%d", maxe-i), llx, lly, llz, urx, ury, urz);
478 if (expOff > urx/vp.Width()) expOff = urx/vp.Width();
479 fontE.Render(Form(
"%d", maxe-i), expX , i*scaleStepY+expY, 0, TGLFont::kLeft, TGLFont::kCenterV);
485 if (expOff < 1) expX += expOff;
490 fScaleW = scaleStepX + expX+ frameOff*2;
491 fScaleH = scaleStepY * ne + frameOff*2;
492 Double_t x0 = fScaleCoordX;
493 Double_t x1 = x0 + fScaleW;
494 Double_t y0 = fScaleCoordY;
495 Double_t y1 = y0 + fScaleH;
498 color = fFrameColor > -1 ? fFrameColor : rnrCtx.ColorSet().Markup().GetColorIndex();
499 TGLUtil::ColorTransparency(color, fFrameLineTransp);
501 glBegin(GL_LINE_LOOP);
502 glVertex3f(x0, y0, zf); glVertex3f(x1, y0, zf);
503 glVertex3f(x1, y1, zf); glVertex3f(x0, y1, zf);
506 TGLUtil::ColorTransparency(color, fFrameBgTransp);
508 glVertex2f(x0, y0); glVertex2f(x1, y0);
509 glVertex2f(x1, y1); glVertex2f(x0, y1);
519 void TEveCaloLegoOverlay::RenderPaletteScales(TGLRnrCtx& rnrCtx)
523 glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT | GL_LINE_BIT);
525 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
526 glEnable(GL_POLYGON_OFFSET_FILL);
527 glPolygonOffset(0.1, 1);
529 TGLRect& vp = rnrCtx.RefCamera().RefViewport();
530 Double_t maxVal = fCalo->GetMaxVal();
533 Double_t bl = 0, bh = 0;
534 THLimitsFinder::Optimize(0, maxVal, 10, bl, bh, bn, bw);
535 bn = TMath::CeilNint(maxVal/bw) + 1;
538 fScaleW = fScaleH*1.5/(bn*vp.Aspect());
539 Float_t h = 0.5 * bw ;
540 Float_t w = h * 1.5/ vp.Aspect();
543 glTranslatef(fScaleCoordX + fScaleW*0.5, fScaleCoordY + fScaleH/bn*0.5, 0);
544 glScalef(fScaleH/(bn*bw), fScaleH/(bn*bw), 1.);
548 TGLAxisPainter::LabVec_t &labVec = fAxisPainter->RefLabVec();
551 for (Int_t l= 0; l<bn; l++) {
552 labVec.push_back( TGLAxisPainter::Lab_t(val, val));
556 TGLUtil::Color(rnrCtx.ColorSet().Markup().GetColorIndex());
557 fAxisPainter->RefDir().Set(0, 1, 0);
558 Int_t fs = TMath::CeilNint(rnrCtx.GetCamera()->RefViewport().Height()*0.02);
559 fAxisPainter->SetLabelFont(rnrCtx,
"arial", fs);
560 fAxisPainter->SetTextFormat(0, maxVal, bw);
561 fAxisPainter->SetLabelAlign(TGLFont::kCenterH, TGLFont::kCenterV);
563 fAxisPainter->SetAttAxis(&att);
564 fAxisPainter->RnrLabels();
570 for (TGLAxisPainter::LabVec_t::iterator it = labVec.begin(); it != labVec.end(); ++it)
572 fCalo->GetPalette()->ColorFromValue((Int_t)((*it).first), c);
573 glColor4ub( c[0], c[1], c[2], c[3]);
576 glVertex3f( -w, y - h, zf); glVertex3f( +w, y - h, zf);
577 glVertex3f( +w, y + h, zf); glVertex3f( -w, y + h, zf);
581 TGLUtil::Color(rnrCtx.ColorSet().Markup().GetColorIndex());
582 glBegin(GL_LINE_LOOP);
583 for (TGLAxisPainter::LabVec_t::iterator it = labVec.begin(); it != labVec.end(); ++it)
586 glVertex3f( -w, y - h, zf); glVertex3f( +w, y - h, zf);
587 glVertex3f( +w, y + h, zf); glVertex3f( -w, y + h, zf);
598 void TEveCaloLegoOverlay::Render(TGLRnrCtx& rnrCtx)
602 if ( fCalo == 0 || fCalo->GetData()->Empty())
return;
604 Float_t old_depth_range[2];
605 glGetFloatv(GL_DEPTH_RANGE, old_depth_range);
606 glDepthRange(0, 0.001);
608 glMatrixMode(GL_PROJECTION);
611 if (rnrCtx.Selection())
613 TGLRect rect(*rnrCtx.GetPickRectangle());
614 rnrCtx.GetCamera()->WindowToViewport(rect);
615 gluPickMatrix(rect.X(), rect.Y(), rect.Width(), rect.Height(),
616 (Int_t*) rnrCtx.GetCamera()->RefViewport().CArr());
618 glMatrixMode(GL_MODELVIEW);
622 glTranslatef(-1, -1, 0);
626 TGLCapabilitySwitch lights_off(GL_LIGHTING, kFALSE);
627 TGLCamera& cam = rnrCtx.RefCamera();
628 Bool_t drawOverlayAxis = kTRUE;
630 if (cam.IsOrthographic())
634 TGLVector3 rng(fCalo->GetEtaRng(), fCalo->GetPhiRng(), 0);
636 TGLVector3 res = cam.WorldDeltaToViewport(p, rng);
638 TEveCaloLegoGL* lgl =
dynamic_cast<TEveCaloLegoGL*
>(rnrCtx.RefViewer().FindLogicalInScenes(fCalo));
639 if (fShowScales && lgl)
644 if (lgl->fBinStep == 1)
646 TEveCaloData::CellData_t cellData;
647 for ( TEveCaloData::vCellId_t::iterator i = fCalo->fCellList.begin(); i != fCalo->fCellList.end(); ++i)
649 fCalo->fData->GetCellData(*i, cellData);
650 if (sq > cellData.EtaDelta()) sq = cellData.EtaDelta();
651 if (sq > cellData.PhiDelta()) sq = cellData.PhiDelta();
658 a = fCalo->GetData()->GetEtaBins();
660 for (Int_t i=1 ; i<=nb; i++)
662 if (sq > a->GetBinWidth(i)) sq = a->GetBinWidth(i);
665 a = fCalo->GetData()->GetPhiBins();
667 for (Int_t i=1 ; i<=nb; i++)
669 if (sq > a->GetBinWidth(i)) sq = a->GetBinWidth(i);
674 fCellX = (res.X()*sq)/(fCalo->GetEtaRng()*1.*cam.RefViewport().Width());
675 fCellY = (res.Y()*sq)/(fCalo->GetPhiRng()*1.*cam.RefViewport().Height());
677 if (fCalo->Get2DMode() == TEveCaloLego::kValSize)
678 RenderLogaritmicScales(rnrCtx);
679 else if (fCalo->GetPalette())
680 RenderPaletteScales(rnrCtx);
685 if ( fCalo->GetEtaMin() > fFrustum[0] && fCalo->GetEtaMax() < fFrustum[2]
686 && fCalo->GetPhiMin() > fFrustum[1] && fCalo->GetPhiMax() < fFrustum[3])
687 drawOverlayAxis = kFALSE;
690 if (cam.IsPerspective() && fShowPlane)
692 RenderPlaneInterface(rnrCtx);
696 if (fHeaderTxt.Length())
698 RenderHeader(rnrCtx);
702 glMatrixMode(GL_PROJECTION);
704 glMatrixMode(GL_MODELVIEW);
706 glDepthRange(old_depth_range[0], old_depth_range[1]);
708 if (drawOverlayAxis) TGLCameraOverlay::Render(rnrCtx);