39 ClassImp(TGLHistPainter);
203 TGLHistPainter::TGLHistPainter(TH1 *hist)
204 : fDefaultPainter(TVirtualHistPainter::HistPainter(hist)),
209 fPlotType(kGLDefaultPlot)
216 TGLHistPainter::TGLHistPainter(TGLParametricEquation *equation)
221 fPlotType(kGLParametricPlot)
223 fGLPainter.reset(
new TGLParametricPlot(equation, &fCamera));
229 TGLHistPainter::TGLHistPainter(TGL5DDataSet *data)
236 fGLPainter.reset(
new TGL5DPainter(data, &fCamera, &fCoord));
242 TGLHistPainter::TGLHistPainter(TGLTH3Composition *data)
247 fPlotType(kGLTH3Composition)
249 fGLPainter.reset(
new TGLTH3CompositionPainter(data, &fCamera, &fCoord));
256 Int_t TGLHistPainter::DistancetoPrimitive(Int_t px, Int_t py)
261 if (fPlotType == kGLDefaultPlot)
262 return fDefaultPainter.get() ? fDefaultPainter->DistancetoPrimitive(px, py) : 9999;
269 py = gPad->GetWh() - py;
273 const Int_t glContext = gPad->GetGLDevice();
275 if (glContext != -1) {
277 PadToViewport(kTRUE);
279 if (!gGLManager->PlotSelected(fGLPainter.get(), px, py))
280 gPad->SetSelected(gPad);
282 Error(
"DistancetoPrimitive",
283 "Attempt to use TGLHistPainter, while the current pad (gPad) does not support gl");
284 gPad->SetSelected(gPad);
297 void TGLHistPainter::DrawPanel()
299 if (fDefaultPainter.get())
300 fDefaultPainter->DrawPanel();
314 void TGLHistPainter::ExecuteEvent(Int_t event, Int_t px, Int_t py)
316 if (fPlotType == kGLDefaultPlot) {
317 if(fDefaultPainter.get()) {
318 fDefaultPainter->ExecuteEvent(event, px, py);
323 const Int_t glContext = gPad->GetGLDevice();
325 if (glContext == -1) {
326 Error(
"ExecuteEvent",
327 "Attempt to use TGLHistPainter, while the current pad (gPad) does not support gl");
336 if (event != kKeyPress) {
340 py -= Int_t((1 - gPad->GetHNDC() - gPad->GetYlowNDC()) * gPad->GetWh());
341 px -= Int_t(gPad->GetXlowNDC() * gPad->GetWw());
344 TGLUtil::InitializeIfNeeded();
345 const Float_t scale = TGLUtil::GetScreenScalingFactor();
355 fGLPainter->ProcessEvent(event, px, py);
359 if (!fGLPainter->CutAxisSelected())
360 fCamera.StartRotation(px, py);
362 fGLPainter->StartPan(px, py);
370 fGLPainter->InvalidateSelection();
371 if (fGLPainter->CutAxisSelected())
372 gGLManager->PanObject(fGLPainter.get(), px, py);
374 fCamera.RotateCamera(px, py);
381 gGLManager->MarkForDirectCopy(glContext, kFALSE);
384 gPad->SetCursor(kRotate);
393 fGLPainter->StartPan(px, py);
394 gGLManager->MarkForDirectCopy(glContext, kTRUE);
397 gGLManager->PanObject(fGLPainter.get(), px, py);
408 gGLManager->MarkForDirectCopy(glContext, kTRUE);
409 if (event == 6 || py == kKey_J || py == kKey_j) {
411 fGLPainter->InvalidateSelection();
414 }
else if (event == 5 || py == kKey_K || py == kKey_k) {
416 fGLPainter->InvalidateSelection();
419 }
else if (py == kKey_p || py == kKey_P || py == kKey_S || py == kKey_s
420 || py == kKey_c || py == kKey_C || py == kKey_x || py == kKey_X
421 || py == kKey_y || py == kKey_Y || py == kKey_z || py == kKey_Z
422 || py == kKey_w || py == kKey_W || py == kKey_l || py == kKey_L
425 fGLPainter->ProcessEvent(event, px, py);
429 gGLManager->MarkForDirectCopy(glContext, kFALSE);
440 TList *TGLHistPainter::GetContourList(Double_t contour)
const
442 return fDefaultPainter.get() ? fDefaultPainter->GetContourList(contour) : 0;
453 char *TGLHistPainter::GetObjectInfo(Int_t px, Int_t py)
const
455 static char errMsg[] = {
"TGLHistPainter::GetObjectInfo: Error in a hist painter\n" };
456 if (fPlotType == kGLDefaultPlot)
457 return fDefaultPainter.get() ? fDefaultPainter->GetObjectInfo(px, py)
460 TGLUtil::InitializeIfNeeded();
461 const Float_t scale = TGLUtil::GetScreenScalingFactor();
467 return gGLManager->GetPlotInfo(fGLPainter.get(), px, py);
474 TList *TGLHistPainter::GetStack()
const
483 Bool_t TGLHistPainter::IsInside(Int_t x, Int_t y)
485 if (fPlotType == kGLDefaultPlot)
486 return fDefaultPainter.get() ? fDefaultPainter->IsInside(x, y) : kFALSE;
495 Bool_t TGLHistPainter::IsInside(Double_t x, Double_t y)
497 if (fPlotType == kGLDefaultPlot)
498 return fDefaultPainter.get() ? fDefaultPainter->IsInside(x, y) : kFALSE;
507 void TGLHistPainter::PaintStat(Int_t dostat, TF1 *fit)
509 if (fDefaultPainter.get())
510 fDefaultPainter->PaintStat(dostat, fit);
516 void TGLHistPainter::ProcessMessage(
const char *m,
const TObject *o)
518 if (!std::strcmp(m,
"SetF3"))
521 if (fDefaultPainter.get())
522 fDefaultPainter->ProcessMessage(m, o);
528 void TGLHistPainter::SetHighlight()
530 if (fDefaultPainter.get())
531 fDefaultPainter->SetHighlight();
537 void TGLHistPainter::SetHistogram(TH1 *h)
541 if (fDefaultPainter.get())
542 fDefaultPainter->SetHistogram(h);
548 void TGLHistPainter::SetStack(TList *s)
552 if (fDefaultPainter.get())
553 fDefaultPainter->SetStack(s);
559 Int_t TGLHistPainter::MakeCuts(
char *o)
561 if (fPlotType == kGLDefaultPlot && fDefaultPainter.get())
562 return fDefaultPainter->MakeCuts(o);
567 struct TGLHistPainter::PlotOption_t {
568 EGLPlotType fPlotType;
569 EGLCoordType fCoordType;
581 void TGLHistPainter::Paint(Option_t *o)
586 const Ssiz_t glPos = option.Index(
"gl");
588 option.Remove(glPos, 2);
589 else if (fPlotType != kGLParametricPlot && fPlotType != kGL5D && fPlotType != kGLTH3Composition) {
590 gPad->SetCopyGLDevice(kFALSE);
591 if (fDefaultPainter.get())
592 fDefaultPainter->Paint(o);
596 if (fPlotType != kGLParametricPlot && fPlotType != kGL5D && fPlotType != kGLTH3Composition)
597 CreatePainter(ParsePaintOption(option), option);
599 if (fPlotType == kGLDefaultPlot) {
607 if (fDefaultPainter.get())
608 fDefaultPainter->Paint(option.Data());
610 Int_t glContext = gPad->GetGLDevice();
612 if (glContext != -1) {
623 if (gPad->GetFrameFillColor() != kWhite)
624 fGLPainter->SetFrameColor(gROOT->GetColor(gPad->GetFrameFillColor()));
625 fGLPainter->SetPadColor(gROOT->GetColor(gPad->GetFillColor()));
626 if (fGLPainter->InitGeometry())
627 gGLManager->PaintSingleObject(fGLPainter.get());
634 Bool_t FindAndRemoveOption(TString &options,
const char *toFind)
636 const UInt_t len = std::strlen(toFind);
637 const Ssiz_t index = options.Index(toFind);
639 if (index != kNPOS) {
640 options.Remove(index, len);
653 TGLHistPainter::PlotOption_t
654 TGLHistPainter::ParsePaintOption(
const TString &o)
const
658 PlotOption_t parsedOption = {kGLDefaultPlot, kGLCartesian,
660 Bool_t(gPad->GetLogx()), Bool_t(gPad->GetLogy()),
661 Bool_t(gPad->GetLogz())};
664 if (FindAndRemoveOption(options,
"pol"))
665 parsedOption.fCoordType = kGLPolar;
666 if (FindAndRemoveOption(options,
"cyl"))
667 parsedOption.fCoordType = kGLCylindrical;
668 if (FindAndRemoveOption(options,
"sph"))
669 parsedOption.fCoordType = kGLSpherical;
672 if (FindAndRemoveOption(options,
"lego"))
673 fStack ? parsedOption.fPlotType = kGLStackPlot : parsedOption.fPlotType = kGLLegoPlot;
674 if (FindAndRemoveOption(options,
"surf"))
675 parsedOption.fPlotType = kGLSurfacePlot;
676 if (FindAndRemoveOption(options,
"tf3"))
677 parsedOption.fPlotType = kGLTF3Plot;
678 if (FindAndRemoveOption(options,
"box"))
679 parsedOption.fPlotType = kGLBoxPlot;
680 if (FindAndRemoveOption(options,
"iso"))
681 parsedOption.fPlotType = kGLIsoPlot;
682 if (FindAndRemoveOption(options,
"col"))
683 parsedOption.fPlotType = kGLVoxel;
686 if (FindAndRemoveOption(options,
"bb"))
687 parsedOption.fBackBox = kFALSE;
688 if (FindAndRemoveOption(options,
"fb"))
689 parsedOption.fFrontBox = kFALSE;
692 if (FindAndRemoveOption(options,
"a"))
693 parsedOption.fDrawAxes = kFALSE;
701 void TGLHistPainter::CreatePainter(
const PlotOption_t &option,
const TString &addOption)
703 if (option.fPlotType != fPlotType) {
704 fCoord.ResetModified();
708 if (option.fPlotType == kGLLegoPlot) {
709 if (!fGLPainter.get()) {
710 if (dynamic_cast<TH2Poly*>(fHist))
711 fGLPainter.reset(
new TGLH2PolyPainter(fHist, &fCamera, &fCoord));
713 fGLPainter.reset(
new TGLLegoPainter(fHist, &fCamera, &fCoord));
715 }
else if (option.fPlotType == kGLSurfacePlot) {
716 if (!fGLPainter.get())
717 fGLPainter.reset(
new TGLSurfacePainter(fHist, &fCamera, &fCoord));
718 }
else if (option.fPlotType == kGLBoxPlot) {
719 if (!fGLPainter.get())
720 fGLPainter.reset(
new TGLBoxPainter(fHist, &fCamera, &fCoord));
721 }
else if (option.fPlotType == kGLTF3Plot) {
722 if (!fGLPainter.get())
723 fGLPainter.reset(
new TGLTF3Painter(fF3, fHist, &fCamera, &fCoord));
724 }
else if (option.fPlotType == kGLIsoPlot) {
725 if (!fGLPainter.get())
726 fGLPainter.reset(
new TGLIsoPainter(fHist, &fCamera, &fCoord));
727 }
else if (option.fPlotType == kGLVoxel) {
728 if (!fGLPainter.get())
729 fGLPainter.reset(
new TGLVoxelPainter(fHist, &fCamera, &fCoord));
732 if (fGLPainter.get()) {
733 fPlotType = option.fPlotType;
734 fCoord.SetXLog(gPad->GetLogx());
735 fCoord.SetYLog(gPad->GetLogy());
736 fCoord.SetZLog(gPad->GetLogz());
737 fCoord.SetCoordType(option.fCoordType);
738 fGLPainter->AddOption(addOption);
740 fGLPainter->SetDrawFrontBox(option.fFrontBox);
741 fGLPainter->SetDrawBackBox(option.fBackBox);
742 fGLPainter->SetDrawAxes(option.fDrawAxes);
744 fPlotType = kGLDefaultPlot;
750 void TGLHistPainter::SetShowProjection(
const char *option, Int_t nbins)
752 if (fDefaultPainter.get()) fDefaultPainter->SetShowProjection(option, nbins);
757 void TGLHistPainter::PadToViewport(Bool_t )
759 if (!fGLPainter.get())
763 vp.Width() = Int_t(gPad->GetAbsWNDC() * gPad->GetWw());
764 vp.Height() = Int_t(gPad->GetAbsHNDC() * gPad->GetWh());
766 vp.X() = Int_t(gPad->XtoAbsPixel(gPad->GetX1()));
767 vp.Y() = Int_t((gPad->GetWh() - gPad->YtoAbsPixel(gPad->GetY1())));
769 TGLUtil::InitializeIfNeeded();
770 const Float_t scale = TGLUtil::GetScreenScalingFactor();
773 vp.X() = Int_t(vp.X() * scale);
774 vp.Y() = Int_t(vp.Y() * scale);
776 vp.Width() = Int_t(vp.Width() * scale);
777 vp.Height() = Int_t(vp.Height() * scale);
780 fCamera.SetViewport(vp);
781 if (fCamera.ViewportChanged() && fGLPainter.get())
782 fGLPainter->InvalidateSelection();