00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <stdexcept>
00013 #include <cstring>
00014
00015 #include "TVirtualGL.h"
00016 #include "KeySymbols.h"
00017 #include "Buttons.h"
00018 #include "TH2Poly.h"
00019 #include "TClass.h"
00020 #include "TROOT.h"
00021 #include "TGL5D.h"
00022 #include "TMath.h"
00023 #include "TPad.h"
00024 #include "TH3.h"
00025 #include "TF3.h"
00026
00027 #include "TGLSurfacePainter.h"
00028 #include "TGLTH3Composition.h"
00029 #include "TGLH2PolyPainter.h"
00030 #include "TGLHistPainter.h"
00031 #include "TGLLegoPainter.h"
00032 #include "TGLBoxPainter.h"
00033 #include "TGLTF3Painter.h"
00034 #include "TGLParametric.h"
00035 #include "TGL5DPainter.h"
00036
00037 ClassImp(TGLHistPainter)
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196 TGLHistPainter::TGLHistPainter(TH1 *hist)
00197 : fDefaultPainter(TVirtualHistPainter::HistPainter(hist)),
00198 fEq(0),
00199 fHist(hist),
00200 fF3(0),
00201 fStack(0),
00202 fPlotType(kGLDefaultPlot)
00203 {
00204
00205
00206 }
00207
00208
00209 TGLHistPainter::TGLHistPainter(TGLParametricEquation *equation)
00210 : fEq(equation),
00211 fHist(0),
00212 fF3(0),
00213 fStack(0),
00214 fPlotType(kGLParametricPlot)
00215 {
00216
00217 fGLPainter.reset(new TGLParametricPlot(equation, &fCamera));
00218 }
00219
00220
00221 TGLHistPainter::TGLHistPainter(TGL5DDataSet *data)
00222 : fEq(0),
00223 fHist(0),
00224 fF3(0),
00225 fStack(0),
00226 fPlotType(kGL5D)
00227 {
00228
00229 fGLPainter.reset(new TGL5DPainter(data, &fCamera, &fCoord));
00230 }
00231
00232
00233 TGLHistPainter::TGLHistPainter(TGLTH3Composition *data)
00234 : fEq(0),
00235 fHist(data),
00236 fF3(0),
00237 fStack(0),
00238 fPlotType(kGLTH3Composition)
00239 {
00240
00241 fGLPainter.reset(new TGLTH3CompositionPainter(data, &fCamera, &fCoord));
00242 }
00243
00244
00245 Int_t TGLHistPainter::DistancetoPrimitive(Int_t px, Int_t py)
00246 {
00247
00248
00249
00250
00251
00252
00253 if (fPlotType == kGLDefaultPlot)
00254 return fDefaultPainter.get() ? fDefaultPainter->DistancetoPrimitive(px, py) : 9999;
00255 else {
00256
00257
00258
00259
00260
00261
00262 py = gPad->GetWh() - py;
00263
00264
00265
00266 const Int_t glContext = gPad->GetGLDevice();
00267
00268 if (glContext != -1) {
00269
00270 PadToViewport(kTRUE);
00271
00272 if (!gGLManager->PlotSelected(fGLPainter.get(), px, py))
00273 gPad->SetSelected(gPad);
00274 } else {
00275 Error("DistancetoPrimitive",
00276 "Attempt to use TGLHistPainter, while the current pad (gPad) does not support gl");
00277 gPad->SetSelected(gPad);
00278 }
00279
00280 return 0;
00281 }
00282 }
00283
00284
00285 void TGLHistPainter::DrawPanel()
00286 {
00287
00288
00289
00290
00291 if (fDefaultPainter.get())
00292 fDefaultPainter->DrawPanel();
00293 }
00294
00295
00296 void TGLHistPainter::ExecuteEvent(Int_t event, Int_t px, Int_t py)
00297 {
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307 if (fPlotType == kGLDefaultPlot) {
00308 if(fDefaultPainter.get()) {
00309 fDefaultPainter->ExecuteEvent(event, px, py);
00310 }
00311 } else {
00312
00313
00314 const Int_t glContext = gPad->GetGLDevice();
00315
00316 if (glContext == -1) {
00317 Error("ExecuteEvent",
00318 "Attempt to use TGLHistPainter, while the current pad (gPad) does not support gl");
00319 return;
00320 } else {
00321
00322
00323
00324 PadToViewport();
00325 }
00326
00327 if (event != kKeyPress) {
00328
00329
00330
00331 py -= Int_t((1 - gPad->GetHNDC() - gPad->GetYlowNDC()) * gPad->GetWh());
00332 px -= Int_t(gPad->GetXlowNDC() * gPad->GetWw());
00333 }
00334
00335 switch (event) {
00336 case kButton1Double:
00337
00338 fGLPainter->ProcessEvent(event, px, py);
00339 break;
00340 case kButton1Down:
00341
00342 if (!fGLPainter->CutAxisSelected())
00343 fCamera.StartRotation(px, py);
00344 else
00345 fGLPainter->StartPan(px, py);
00346
00347
00348
00349 break;
00350 case kButton1Motion:
00351
00352
00353 fGLPainter->InvalidateSelection();
00354 if (fGLPainter->CutAxisSelected())
00355 gGLManager->PanObject(fGLPainter.get(), px, py);
00356 else
00357 fCamera.RotateCamera(px, py);
00358
00359
00360 gPad->Update();
00361 break;
00362 case kButton1Up:
00363 case kButton2Up:
00364 gGLManager->MarkForDirectCopy(glContext, kFALSE);
00365 break;
00366 case kMouseMotion:
00367 gPad->SetCursor(kRotate);
00368 break;
00369 case 7:
00370
00371
00372
00373
00374
00375
00376 fGLPainter->StartPan(px, py);
00377 gGLManager->MarkForDirectCopy(glContext, kTRUE);
00378 break;
00379 case 8:
00380 gGLManager->PanObject(fGLPainter.get(), px, py);
00381
00382 gPad->Update();
00383 break;
00384 case kKeyPress:
00385 case 5:
00386 case 6:
00387
00388
00389
00390
00391 gGLManager->MarkForDirectCopy(glContext, kTRUE);
00392 if (event == 6 || py == kKey_J || py == kKey_j) {
00393 fCamera.ZoomIn();
00394 fGLPainter->InvalidateSelection();
00395
00396 gPad->Update();
00397 } else if (event == 5 || py == kKey_K || py == kKey_k) {
00398 fCamera.ZoomOut();
00399 fGLPainter->InvalidateSelection();
00400
00401 gPad->Update();
00402 } else if (py == kKey_p || py == kKey_P || py == kKey_S || py == kKey_s
00403 || py == kKey_c || py == kKey_C || py == kKey_x || py == kKey_X
00404 || py == kKey_y || py == kKey_Y || py == kKey_z || py == kKey_Z
00405 || py == kKey_w || py == kKey_W || py == kKey_l || py == kKey_L
00406 )
00407 {
00408 fGLPainter->ProcessEvent(event, px, py);
00409
00410 gPad->Update();
00411 }
00412 gGLManager->MarkForDirectCopy(glContext, kFALSE);
00413 break;
00414 }
00415 }
00416 }
00417
00418
00419 TList *TGLHistPainter::GetContourList(Double_t contour)const
00420 {
00421
00422
00423
00424 return fDefaultPainter.get() ? fDefaultPainter->GetContourList(contour) : 0;
00425 }
00426
00427
00428 char *TGLHistPainter::GetObjectInfo(Int_t px, Int_t py)const
00429 {
00430
00431
00432
00433
00434
00435
00436 static char errMsg[] = { "TGLHistPainter::GetObjectInfo: Error in a hist painter\n" };
00437 if (fPlotType == kGLDefaultPlot)
00438 return fDefaultPainter.get() ? fDefaultPainter->GetObjectInfo(px, py)
00439 : errMsg;
00440 else
00441 return gGLManager->GetPlotInfo(fGLPainter.get(), px, py);
00442 }
00443
00444
00445 TList *TGLHistPainter::GetStack()const
00446 {
00447
00448 return fStack;
00449 }
00450
00451
00452 Bool_t TGLHistPainter::IsInside(Int_t x, Int_t y)
00453 {
00454
00455
00456 if (fPlotType == kGLDefaultPlot)
00457 return fDefaultPainter.get() ? fDefaultPainter->IsInside(x, y) : kFALSE;
00458
00459 return kFALSE;
00460 }
00461
00462
00463 Bool_t TGLHistPainter::IsInside(Double_t x, Double_t y)
00464 {
00465
00466
00467 if (fPlotType == kGLDefaultPlot)
00468 return fDefaultPainter.get() ? fDefaultPainter->IsInside(x, y) : kFALSE;
00469
00470 return kFALSE;
00471 }
00472
00473
00474 void TGLHistPainter::PaintStat(Int_t dostat, TF1 *fit)
00475 {
00476
00477
00478 if (fDefaultPainter.get())
00479 fDefaultPainter->PaintStat(dostat, fit);
00480 }
00481
00482
00483 void TGLHistPainter::ProcessMessage(const char *m, const TObject *o)
00484 {
00485
00486 if (!std::strcmp(m, "SetF3"))
00487 fF3 = (TF3 *)o;
00488
00489 if (fDefaultPainter.get())
00490 fDefaultPainter->ProcessMessage(m, o);
00491 }
00492
00493
00494 void TGLHistPainter::SetHistogram(TH1 *h)
00495 {
00496
00497 fHist = h;
00498
00499 if (fDefaultPainter.get())
00500 fDefaultPainter->SetHistogram(h);
00501 }
00502
00503
00504 void TGLHistPainter::SetStack(TList *s)
00505 {
00506
00507 fStack = s;
00508
00509 if (fDefaultPainter.get())
00510 fDefaultPainter->SetStack(s);
00511 }
00512
00513
00514 Int_t TGLHistPainter::MakeCuts(char *o)
00515 {
00516
00517 if (fPlotType == kGLDefaultPlot && fDefaultPainter.get())
00518 return fDefaultPainter->MakeCuts(o);
00519
00520 return 0;
00521 }
00522
00523 struct TGLHistPainter::PlotOption_t {
00524 EGLPlotType fPlotType;
00525 EGLCoordType fCoordType;
00526 Bool_t fBackBox;
00527 Bool_t fFrontBox;
00528 Bool_t fLogX;
00529 Bool_t fLogY;
00530 Bool_t fLogZ;
00531 };
00532
00533
00534 void TGLHistPainter::Paint(Option_t *o)
00535 {
00536
00537 TString option(o);
00538 option.ToLower();
00539
00540 const Ssiz_t glPos = option.Index("gl");
00541 if (glPos != kNPOS)
00542 option.Remove(glPos, 2);
00543 else if (fPlotType != kGLParametricPlot && fPlotType != kGL5D && fPlotType != kGLTH3Composition) {
00544 gPad->SetCopyGLDevice(kFALSE);
00545 if (fDefaultPainter.get())
00546 fDefaultPainter->Paint(o);
00547 return;
00548 }
00549
00550 if (fPlotType != kGLParametricPlot && fPlotType != kGL5D && fPlotType != kGLTH3Composition)
00551 CreatePainter(ParsePaintOption(option), option);
00552
00553 if (fPlotType == kGLDefaultPlot) {
00554
00555
00556
00557
00558
00559
00560
00561 if (fDefaultPainter.get())
00562 fDefaultPainter->Paint(option.Data());
00563 } else {
00564 Int_t glContext = gPad->GetGLDevice();
00565
00566 if (glContext != -1) {
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576 PadToViewport();
00577 if (gPad->GetFrameFillColor() != kWhite)
00578 fGLPainter->SetFrameColor(gROOT->GetColor(gPad->GetFrameFillColor()));
00579 fGLPainter->SetPadColor(gROOT->GetColor(gPad->GetFillColor()));
00580 if (fGLPainter->InitGeometry())
00581 gGLManager->PaintSingleObject(fGLPainter.get());
00582 }
00583 }
00584 }
00585
00586
00587 TGLHistPainter::PlotOption_t
00588 TGLHistPainter::ParsePaintOption(const TString &option)const
00589 {
00590
00591
00592 PlotOption_t parsedOption = {kGLDefaultPlot, kGLCartesian, kFALSE, kFALSE, gPad->GetLogx(),
00593 gPad->GetLogy(), gPad->GetLogz()};
00594
00595 if (option.Index("pol") != kNPOS)
00596 parsedOption.fCoordType = kGLPolar;
00597 if (option.Index("cyl") != kNPOS)
00598 parsedOption.fCoordType = kGLCylindrical;
00599 if (option.Index("sph") != kNPOS)
00600 parsedOption.fCoordType = kGLSpherical;
00601
00602 if (option.Index("lego") != kNPOS)
00603 fStack ? parsedOption.fPlotType = kGLStackPlot : parsedOption.fPlotType = kGLLegoPlot;
00604 if (option.Index("surf") != kNPOS)
00605 parsedOption.fPlotType = kGLSurfacePlot;
00606 if (option.Index("tf3") != kNPOS)
00607 parsedOption.fPlotType = kGLTF3Plot;
00608 if (option.Index("box") != kNPOS)
00609 parsedOption.fPlotType = kGLBoxPlot;
00610 if (option.Index("iso") != kNPOS)
00611 parsedOption.fPlotType = kGLIsoPlot;
00612
00613 return parsedOption;
00614 }
00615
00616
00617 void TGLHistPainter::CreatePainter(const PlotOption_t &option, const TString &addOption)
00618 {
00619
00620 if (option.fPlotType != fPlotType) {
00621 fCoord.ResetModified();
00622 fGLPainter.reset(0);
00623 }
00624
00625 if (option.fPlotType == kGLLegoPlot) {
00626 if (!fGLPainter.get()) {
00627 if (dynamic_cast<TH2Poly*>(fHist))
00628 fGLPainter.reset(new TGLH2PolyPainter(fHist, &fCamera, &fCoord));
00629 else
00630 fGLPainter.reset(new TGLLegoPainter(fHist, &fCamera, &fCoord));
00631 }
00632 } else if (option.fPlotType == kGLSurfacePlot) {
00633 if (!fGLPainter.get())
00634 fGLPainter.reset(new TGLSurfacePainter(fHist, &fCamera, &fCoord));
00635 } else if (option.fPlotType == kGLBoxPlot) {
00636 if (!fGLPainter.get())
00637 fGLPainter.reset(new TGLBoxPainter(fHist, &fCamera, &fCoord));
00638 } else if (option.fPlotType == kGLTF3Plot) {
00639 if (!fGLPainter.get())
00640 fGLPainter.reset(new TGLTF3Painter(fF3, fHist, &fCamera, &fCoord));
00641 } else if (option.fPlotType == kGLIsoPlot) {
00642 if (!fGLPainter.get())
00643 fGLPainter.reset(new TGLIsoPainter(fHist, &fCamera, &fCoord));
00644 }
00645
00646 if (fGLPainter.get()) {
00647 fPlotType = option.fPlotType;
00648 fCoord.SetXLog(gPad->GetLogx());
00649 fCoord.SetYLog(gPad->GetLogy());
00650 fCoord.SetZLog(gPad->GetLogz());
00651 fCoord.SetCoordType(option.fCoordType);
00652 fGLPainter->AddOption(addOption);
00653 } else
00654 fPlotType = kGLDefaultPlot;
00655 }
00656
00657
00658 void TGLHistPainter::SetShowProjection(const char *, Int_t)
00659 {
00660
00661
00662 Warning("SetShowProjection", "Not yet implemented for GL canvases.");
00663 }
00664
00665
00666 void TGLHistPainter::PadToViewport(Bool_t )
00667 {
00668 if (!fGLPainter.get())
00669 return;
00670
00671 TGLRect vp;
00672 vp.Width() = Int_t(gPad->GetAbsWNDC() * gPad->GetWw());
00673 vp.Height() = Int_t(gPad->GetAbsHNDC() * gPad->GetWh());
00674
00675 vp.X() = Int_t(gPad->XtoAbsPixel(gPad->GetX1()));
00676 vp.Y() = gPad->GetWh() - gPad->YtoAbsPixel(gPad->GetY1());
00677
00678 fCamera.SetViewport(vp);
00679 if (fCamera.ViewportChanged() && fGLPainter.get())
00680 fGLPainter->InvalidateSelection();
00681 }