29 R__EXTERN TH1 *gCurrentHist;
30 R__EXTERN Hoption_t Hoption;
32 ClassImp(TGraph2DPainter);
48 TGraph2DPainter::TGraph2DPainter()
82 TGraph2DPainter::TGraph2DPainter(TGraphDelaunay *gd)
86 fGraph2D = fDelaunay->GetGraph2D();
87 fNpoints = fGraph2D->GetN();
88 fX = fGraph2D->GetX();
89 fY = fGraph2D->GetY();
90 fZ = fGraph2D->GetZ();
91 fEX = fGraph2D->GetEX();
92 fEY = fGraph2D->GetEY();
93 fEZ = fGraph2D->GetEZ();
115 TGraph2DPainter::TGraph2DPainter(TGraphDelaunay2D *gd)
119 fGraph2D = fDelaunay2D->GetGraph2D();
120 fNpoints = fGraph2D->GetN();
121 fX = fGraph2D->GetX();
122 fY = fGraph2D->GetY();
123 fZ = fGraph2D->GetZ();
124 fEX = fGraph2D->GetEX();
125 fEY = fGraph2D->GetEY();
126 fEZ = fGraph2D->GetEZ();
149 TGraph2DPainter::~TGraph2DPainter()
158 void TGraph2DPainter::FindTriangles()
161 fDelaunay->FindAllTriangles();
162 fNdt = fDelaunay->GetNdt();
163 fXN = fDelaunay->GetXN();
164 fYN = fDelaunay->GetYN();
165 fXNmin = fDelaunay->GetXNmin();
166 fXNmax = fDelaunay->GetXNmax();
167 fYNmin = fDelaunay->GetYNmin();
168 fYNmax = fDelaunay->GetYNmax();
169 fPTried = fDelaunay->GetPTried();
170 fNTried = fDelaunay->GetNTried();
171 fMTried = fDelaunay->GetMTried();
173 else if (fDelaunay2D) {
174 fDelaunay2D->FindAllTriangles();
175 fNdt = fDelaunay2D->GetNdt();
176 fXNmin = fDelaunay2D->GetXNmin();
177 fXNmax = fDelaunay2D->GetXNmax();
178 fYNmin = fDelaunay2D->GetYNmin();
179 fYNmax = fDelaunay2D->GetYNmax();
189 TList *TGraph2DPainter::GetContourList(Double_t contour)
192 Double_t zmin = gCurrentHist->GetMinimum();
193 Double_t zmax = gCurrentHist->GetMaximum();
196 zmin = TMath::Log10(zmin);
197 zmax = TMath::Log10(zmax);
202 if(contour<zmin || contour>zmax) {
203 Error(
"GetContourList",
"Contour level (%g) outside the Z scope [%g,%g]",
208 if (!fNdt) FindTriangles();
212 TList *list =
new TList();
216 Double_t r21, r20, r10;
221 Int_t t[3],i,it,i0,i1,i2;
225 Double_t xs0c, ys0c, xs1c, ys1c;
226 Double_t *xs0 =
new Double_t[fNdt];
227 Double_t *ys0 =
new Double_t[fNdt];
228 Double_t *xs1 =
new Double_t[fNdt];
229 Double_t *ys1 =
new Double_t[fNdt];
230 for (i=0;i<fNdt;i++) {
243 for(it=0; it<fNdt; it++) {
250 x0 = fX[p0]; x2 = fX[p0];
251 y0 = fY[p0]; y2 = fY[p0];
252 z0 = fZ[p0]; z2 = fZ[p0];
257 if (fZ[p1]<=z0) {z0=fZ[p1]; x0=fX[p1]; y0=fY[p1]; i0=1;}
258 if (fZ[p1]>z2) {z2=fZ[p1]; x2=fX[p1]; y2=fY[p1]; i2=1;}
259 if (fZ[p2]<=z0) {z0=fZ[p2]; x0=fX[p2]; y0=fY[p2]; i0=2;}
260 if (fZ[p2]>z2) {z2=fZ[p2]; x2=fX[p2]; y2=fY[p2]; i2=2;}
261 if (i0==0 && i2==0) {
262 Error(
"GetContourList",
"wrong vertices ordering");
276 z0 = TMath::Log10(z0);
277 z1 = TMath::Log10(z1);
278 z2 = TMath::Log10(z2);
281 if(contour >= z0 && contour <=z2) {
282 r20 = (contour-z0)/(z2-z0);
283 xs0c = r20*(x2-x0)+x0;
284 ys0c = r20*(y2-y0)+y0;
285 if(contour >= z1 && contour <=z2) {
286 r21 = (contour-z1)/(z2-z1);
287 xs1c = r21*(x2-x1)+x1;
288 ys1c = r21*(y2-y1)+y1;
290 r10 = (contour-z0)/(z1-z0);
291 xs1c = r10*(x1-x0)+x0;
292 ys1c = r10*(y1-y0)+y0;
295 if(xs0c != xs1c || ys0c != ys1c) {
305 else if (fDelaunay2D) {
308 for(
const auto & face : *fDelaunay2D) {
312 x0 = fX[p[0]]; x2 = fX[p[0]];
313 y0 = fY[p[0]]; y2 = fY[p[0]];
314 z0 = fZ[p[0]]; z2 = fZ[p[0]];
319 if (fZ[p[1]]<=z0) {z0=fZ[p[1]]; x0=fX[p[1]]; y0=fY[p[1]]; i0=1;}
320 if (fZ[p[1]]>z2) {z2=fZ[p[1]]; x2=fX[p[1]]; y2=fY[p[1]]; i2=1;}
321 if (fZ[p[2]]<=z0) {z0=fZ[p[2]]; x0=fX[p[2]]; y0=fY[p[2]]; i0=2;}
322 if (fZ[p[2]]>z2) {z2=fZ[p[2]]; x2=fX[p[2]]; y2=fY[p[2]]; i2=2;}
323 if (i0==0 && i2==0) {
324 Error(
"GetContourList",
"wrong vertices ordering");
338 z0 = TMath::Log10(z0);
339 z1 = TMath::Log10(z1);
340 z2 = TMath::Log10(z2);
343 if(contour >= z0 && contour <=z2) {
344 r20 = (contour-z0)/(z2-z0);
345 xs0c = r20*(x2-x0)+x0;
346 ys0c = r20*(y2-y0)+y0;
347 if(contour >= z1 && contour <=z2) {
348 r21 = (contour-z1)/(z2-z1);
349 xs1c = r21*(x2-x1)+x1;
350 ys1c = r21*(y2-y1)+y1;
352 r10 = (contour-z0)/(z1-z0);
353 xs1c = r10*(x1-x0)+x0;
354 ys1c = r10*(y1-y0)+y0;
357 if(xs0c != xs1c || ys0c != ys1c) {
368 Int_t *segUsed =
new Int_t[fNdt];
369 for(i=0; i<fNdt; i++) segUsed[i]=kFALSE;
375 Double_t xc=0, yc=0, xnc=0, ync=0;
379 for (is=0; is<nbSeg; is++) {
380 if (segUsed[is])
continue;
385 for (js=0; js<nbSeg; js++) {
386 if (is==js)
continue;
387 if (xs0[is]==xs0[js] && ys0[is]==ys0[js]) s0 = kTRUE;
388 if (xs0[is]==xs1[js] && ys0[is]==ys1[js]) s0 = kTRUE;
389 if (xs1[is]==xs0[js] && ys1[is]==ys0[js]) s1 = kTRUE;
390 if (xs1[is]==xs1[js] && ys1[is]==ys1[js]) s1 = kTRUE;
396 graph =
new TGraph();
397 graph->SetPoint(npg,xs0[is],ys0[is]); npg++;
398 graph->SetPoint(npg,xs1[is],ys1[is]); npg++;
400 list->Add(graph); npg = 0;
408 graph =
new TGraph();
409 if (s0) {xc = xs0[is]; yc = ys0[is]; xnc = xs1[is]; ync = ys1[is];}
410 if (s1) {xc = xs1[is]; yc = ys1[is]; xnc = xs0[is]; ync = ys0[is];}
411 graph->SetPoint(npg,xnc,ync); npg++;
416 if (js < nbSeg && segUsed[js]) {
419 }
else if (xc==xs0[js] && yc==ys0[js]) {
423 }
else if (xc==xs1[js] && yc==ys1[js]) {
430 graph->SetPoint(npg,xc,yc); npg++;
435 if (js<nbSeg)
goto L01;
436 list->Add(graph); npg = 0;
443 for (is=0; is<nbSeg; is++) {
444 if (segUsed[is])
continue;
447 graph =
new TGraph();
452 graph->SetPoint(npg,xc,yc); npg++;
455 if (js < nbSeg && segUsed[js]) {
458 }
else if (xc==xs0[js] && yc==ys0[js]) {
462 }
else if (xc==xs1[js] && yc==ys1[js]) {
469 graph->SetPoint(npg,xc,yc); npg++;
474 if (js<nbSeg)
goto L02;
476 graph->SetPoint(npg,xs0[is],ys0[is]); npg++;
477 list->Add(graph); npg = 0;
504 void TGraph2DPainter::Paint(Option_t *option)
506 TString opt = option;
508 Bool_t triangles = opt.Contains(
"tri") ||
509 opt.Contains(
"tri1") ||
510 opt.Contains(
"tri2");
511 if (opt.Contains(
"tri0")) triangles = kFALSE;
513 Bool_t markers = opt.Contains(
"p") && !triangles;
514 Bool_t contour = opt.Contains(
"cont");
515 Bool_t line = opt.Contains(
"line");
516 Bool_t err = opt.Contains(
"err");
518 fGraph2D->TAttLine::Modify();
519 fGraph2D->TAttFill::Modify();
520 fGraph2D->TAttMarker::Modify();
523 TAxis *xaxis = gCurrentHist->GetXaxis();
524 Int_t first = xaxis->GetFirst();
525 fXmin = xaxis->GetBinLowEdge(first);
526 if (Hoption.Logx && fXmin <= 0) fXmin = xaxis->GetBinUpEdge(xaxis->FindFixBin(0.01*xaxis->GetBinWidth(first)));
527 fXmax = xaxis->GetBinUpEdge(xaxis->GetLast());
528 TAxis *yaxis = gCurrentHist->GetYaxis();
529 first = yaxis->GetFirst();
530 fYmin = yaxis->GetBinLowEdge(first);
531 if (Hoption.Logy && fYmin <= 0) fYmin = yaxis->GetBinUpEdge(yaxis->FindFixBin(0.01*yaxis->GetBinWidth(first)));
532 fYmax = yaxis->GetBinUpEdge(yaxis->GetLast());
533 fZmax = fGraph2D->GetZmax();
534 fZmin = fGraph2D->GetZmin();
535 if (Hoption.Logz && fZmin <= 0) fZmin = TMath::Min((Double_t)1, (Double_t)0.001*fGraph2D->GetZmax());
537 if (triangles) PaintTriangles(option);
538 if (contour) PaintContour(option);
539 if (line) PaintPolyLine(option);
540 if (err) PaintErrors(option);
541 if (markers) PaintPolyMarker(option);
549 void TGraph2DPainter::PaintContour(Option_t * )
552 Int_t ncolors = gStyle->GetNumberOfColors();
553 Int_t ndiv = gCurrentHist->GetContour();
555 ndiv = gStyle->GetNumberContours();
556 gCurrentHist->SetContour(ndiv);
558 Int_t ndivz = TMath::Abs(ndiv);
559 if (gCurrentHist->TestBit(TH1::kUserContour) == 0) gCurrentHist->SetContour(ndiv);
567 if (!fNdt) FindTriangles();
569 for (Int_t k=0; k<ndiv; k++) {
570 c = gCurrentHist->GetContourLevelPad(k);
571 l = GetContourList(c);
573 while ((obj = next())) {
574 if(obj->InheritsFrom(TGraph::Class()) ) {
576 g->SetLineWidth(fGraph2D->GetLineWidth());
577 g->SetLineStyle(fGraph2D->GetLineStyle());
578 theColor = Int_t((k+0.99)*Float_t(ncolors)/Float_t(ndivz));
579 g->SetLineColor(gStyle->GetColorPalette(theColor));
590 void TGraph2DPainter::PaintErrors(Option_t * )
592 Double_t temp1[3],temp2[3];
594 TView *view = gPad->GetView();
596 Error(
"PaintErrors",
"No TView in current pad");
602 Double_t *xm =
new Double_t[2];
603 Double_t *ym =
new Double_t[2];
605 fGraph2D->SetLineStyle(fGraph2D->GetLineStyle());
606 fGraph2D->SetLineWidth(fGraph2D->GetLineWidth());
607 fGraph2D->SetLineColor(fGraph2D->GetLineColor());
608 fGraph2D->TAttLine::Modify();
610 for (it=0; it<fNpoints; it++) {
611 if(fX[it] < fXmin || fX[it] > fXmax)
continue;
612 if(fY[it] < fYmin || fY[it] > fYmax)
continue;
614 temp1[0] = fX[it]-fEX[it];
617 temp1[0] = TMath::Max(temp1[0],fXmin);
618 temp1[1] = TMath::Max(temp1[1],fYmin);
619 temp1[2] = TMath::Max(temp1[2],fZmin);
620 temp1[2] = TMath::Min(temp1[2],fZmax);
621 if (Hoption.Logx) temp1[0] = TMath::Log10(temp1[0]);
622 if (Hoption.Logy) temp1[1] = TMath::Log10(temp1[1]);
623 if (Hoption.Logz) temp1[2] = TMath::Log10(temp1[2]);
624 view->WCtoNDC(temp1, &temp2[0]);
628 temp1[0] = fX[it]+fEX[it];
629 temp1[0] = TMath::Max(temp1[0],fXmin);
630 if (Hoption.Logx) temp1[0] = TMath::Log10(temp1[0]);
631 view->WCtoNDC(temp1, &temp2[0]);
634 gPad->PaintPolyLine(2,xm,ym);
638 temp1[1] = fY[it]-fEY[it];
640 temp1[0] = TMath::Max(temp1[0],fXmin);
641 temp1[1] = TMath::Max(temp1[1],fYmin);
642 temp1[2] = TMath::Max(temp1[2],fZmin);
643 temp1[2] = TMath::Min(temp1[2],fZmax);
644 if (Hoption.Logx) temp1[0] = TMath::Log10(temp1[0]);
645 if (Hoption.Logy) temp1[1] = TMath::Log10(temp1[1]);
646 if (Hoption.Logz) temp1[2] = TMath::Log10(temp1[2]);
647 view->WCtoNDC(temp1, &temp2[0]);
651 temp1[1] = fY[it]+fEY[it];
652 temp1[1] = TMath::Max(temp1[1],fYmin);
653 if (Hoption.Logy) temp1[1] = TMath::Log10(temp1[1]);
654 view->WCtoNDC(temp1, &temp2[0]);
657 gPad->PaintPolyLine(2,xm,ym);
662 temp1[2] = fZ[it]-fEZ[it];
663 temp1[0] = TMath::Max(temp1[0],fXmin);
664 temp1[1] = TMath::Max(temp1[1],fYmin);
665 temp1[2] = TMath::Max(temp1[2],fZmin);
666 temp1[2] = TMath::Min(temp1[2],fZmax);
667 if (Hoption.Logx) temp1[0] = TMath::Log10(temp1[0]);
668 if (Hoption.Logy) temp1[1] = TMath::Log10(temp1[1]);
669 if (Hoption.Logz) temp1[2] = TMath::Log10(temp1[2]);
670 view->WCtoNDC(temp1, &temp2[0]);
674 temp1[2] = fZ[it]+fEZ[it];
675 temp1[2] = TMath::Max(temp1[2],fZmin);
676 temp1[2] = TMath::Min(temp1[2],fZmax);
677 if (Hoption.Logz) temp1[2] = TMath::Log10(temp1[2]);
678 view->WCtoNDC(temp1, &temp2[0]);
681 gPad->PaintPolyLine(2,xm,ym);
695 void TGraph2DPainter::PaintLevels(Int_t *t,Double_t *x, Double_t *y,
696 Int_t nblev, Double_t *glev)
698 Int_t i, fillColor, ncolors, theColor0, theColor2;
711 Double_t xl[2],yl[2];
712 Double_t zl, r21, r20, r10;
713 Double_t x0 = x[0] , x2 = x[0];
714 Double_t y0 = y[0] , y2 = y[0];
715 Double_t z0 = fZ[p[0]], z2 = fZ[p[0]];
716 Double_t zmin = fGraph2D->GetMinimum();
717 Double_t zmax = fGraph2D->GetMaximum();
718 if (zmin==-1111 && zmax==-1111) {
719 zmin = TMath::Min(fZmin, 0.);
720 if (Hoption.Logz && zmin <= 0) zmin = TMath::Min((Double_t)1, (Double_t)0.001*fGraph2D->GetZmax());
726 Int_t i0=0, i1=0, i2=0;
727 if (fZ[p[1]]<=z0) {z0=fZ[p[1]]; x0=x[1]; y0=y[1]; i0=1;}
728 if (fZ[p[1]]>z2) {z2=fZ[p[1]]; x2=x[1]; y2=y[1]; i2=1;}
729 if (fZ[p[2]]<=z0) {z0=fZ[p[2]]; x0=x[2]; y0=y[2]; i0=2;}
730 if (fZ[p[2]]>z2) {z2=fZ[p[2]]; x2=x[2]; y2=y[2]; i2=2;}
734 Double_t z1 = fZ[p[i1]];
736 if (z0>zmax) z0 = zmax;
737 if (z2>zmax) z2 = zmax;
738 if (z0<zmin) z0 = zmin;
739 if (z2<zmin) z2 = zmin;
740 if (z1>zmax) z1 = zmax;
741 if (z1<zmin) z1 = zmin;
744 z0 = TMath::Log10(z0);
745 z1 = TMath::Log10(z1);
746 z2 = TMath::Log10(z2);
747 zmin = TMath::Log10(zmin);
748 zmax = TMath::Log10(zmax);
753 Double_t zi=0, zip=0;
759 ncolors = gStyle->GetNumberOfColors();
760 theColor0 = (Int_t)( ((z0-zmin)/(zmax-zmin))*(ncolors-1) );
761 theColor2 = (Int_t)( ((z2-zmin)/(zmax-zmin))*(ncolors-1) );
764 Double_t xp[5], yp[5];
774 fillColor = fGraph2D->GetFillColor();
778 if(theColor0 == theColor2) {
779 fGraph2D->SetFillColor(gStyle->GetColorPalette(theColor0));
780 fGraph2D->TAttFill::Modify();
781 gPad->PaintFillArea(3,x,y);
785 for(ci=theColor0; ci<=theColor2; ci++) {
786 fGraph2D->SetFillColor(gStyle->GetColorPalette(ci));
787 fGraph2D->TAttFill::Modify();
789 zi = (((ci+1)*(zmax-zmin))/(ncolors-1))+zmin;
792 rl = (zi-z0)/(z2-z0);
793 xp[1] = rl*(x2-x0)+x0;
794 yp[1] = rl*(y2-y0)+y0;
795 if (zi>=z1 || z0==z1) {
796 rs = (zi-z1)/(z2-z1);
797 xp[2] = rs*(x2-x1)+x1;
798 yp[2] = rs*(y2-y1)+y1;
803 rs = (zi-z0)/(z1-z0);
804 xp[2] = rs*(x1-x0)+x0;
805 yp[2] = rs*(y1-y0)+y0;
808 }
else if (ci==theColor2) {
813 if (zi<z1 || z2==z1) {
823 zi = (((ci+1)*(zmax-zmin))/(ncolors-1))+zmin;
826 rl = (zi-z0)/(z2-z0);
827 xp[1] = rl*(x2-x0)+x0;
828 yp[1] = rl*(y2-y0)+y0;
829 if ( zi>=z1 && zip<=z1) {
841 rs = (zi-z0)/(z1-z0);
842 xp[2] = rs*(x1-x0)+x0;
843 yp[2] = rs*(y1-y0)+y0;
845 rs = (zi-z1)/(z2-z1);
846 xp[2] = rs*(x2-x1)+x1;
847 yp[2] = rs*(y2-y1)+y1;
852 gPad->PaintFillArea(npf,xp,yp);
855 fGraph2D->SetFillColor(fillColor);
856 fGraph2D->TAttFill::Modify();
860 fGraph2D->SetLineStyle(3);
861 fGraph2D->TAttLine::Modify();
862 for(i=0; i<nblev; i++){
864 if(zl >= z0 && zl <=z2) {
868 xl[0]=r20*(x2-x0)+x0;
869 yl[0]=r20*(y2-y0)+y0;
870 if(zl >= z1 && zl <=z2) {
871 xl[1]=r21*(x2-x1)+x1;
872 yl[1]=r21*(y2-y1)+y1;
874 xl[1]=r10*(x1-x0)+x0;
875 yl[1]=r10*(y1-y0)+y0;
877 gPad->PaintPolyLine(2,xl,yl);
880 fGraph2D->SetLineStyle(1);
881 fGraph2D->TAttLine::Modify();
889 void TGraph2DPainter::PaintPolyMarker(Option_t *option)
891 Double_t temp1[3],temp2[3];
893 TView *view = gPad->GetView();
895 Error(
"PaintPolyMarker",
"No TView in current pad");
899 TString opt = option;
901 Bool_t markers0 = opt.Contains(
"p0");
902 Bool_t colors = opt.Contains(
"pcol");
903 Int_t ncolors = gStyle->GetNumberOfColors();
908 Int_t ndiv = gCurrentHist->GetContour();
910 ndiv = gStyle->GetNumberContours();
911 gCurrentHist->SetContour(ndiv);
913 if (gCurrentHist->TestBit(TH1::kUserContour) == 0) gCurrentHist->SetContour(ndiv);
916 Double_t *xm =
new Double_t[fNpoints];
917 Double_t *ym =
new Double_t[fNpoints];
918 Double_t *zm =
new Double_t[fNpoints];
919 Double_t hzmin = gCurrentHist->GetMinimum();
920 Double_t hzmax = gCurrentHist->GetMaximum();
923 Double_t hzmincol = hzmin;
924 Double_t hzmaxcol = hzmax;
925 if (hzmincol==-1111 && hzmaxcol==-1111) {
926 hzmincol = TMath::Min(hzmincol, 0.);
927 if (Hoption.Logz && hzmincol <= 0) hzmincol = TMath::Min((Double_t)1, (Double_t)0.001*fGraph2D->GetZmax());
931 hzmincol = TMath::Log10(hzmincol);
932 hzmaxcol = TMath::Log10(hzmaxcol);
935 Double_t Xeps = (fXmax-fXmin)*0.0001;
936 Double_t Yeps = (fYmax-fYmin)*0.0001;
937 Double_t Zeps = (hzmax-hzmin)*0.0001;
940 for (it=0; it<fNpoints; it++) {
943 if(fXmin - fX[it] > Xeps || fX[it] - fXmax > Xeps)
continue;
944 if(fYmin - fY[it] > Yeps || fY[it] - fYmax > Yeps)
continue;
945 if(hzmin - fZ[it] > Zeps || fZ[it] - hzmax > Zeps)
continue;
949 temp1[0] = TMath::Max(temp1[0],fXmin);
950 temp1[1] = TMath::Max(temp1[1],fYmin);
951 temp1[2] = TMath::Max(temp1[2],hzmin);
952 temp1[2] = TMath::Min(temp1[2],hzmax);
953 if (Hoption.Logx) temp1[0] = TMath::Log10(temp1[0]);
954 if (Hoption.Logy) temp1[1] = TMath::Log10(temp1[1]);
955 if (Hoption.Logz) temp1[2] = TMath::Log10(temp1[2]);
956 view->WCtoNDC(temp1, &temp2[0]);
963 PaintPolyMarker0(npd,xm,ym);
965 Int_t cols = fGraph2D->GetMarkerColor();
966 for (it=0; it<npd; it++) {
967 theColor = (Int_t)( ((zm[it]-hzmincol)/(hzmaxcol-hzmincol))*(ncolors-1) );
968 fGraph2D->SetMarkerColor(gStyle->GetColorPalette(theColor));
969 fGraph2D->TAttMarker::Modify();
970 gPad->PaintPolyMarker(1,&xm[it],&ym[it]);
972 fGraph2D->SetMarkerColor(cols);
974 fGraph2D->SetMarkerStyle(fGraph2D->GetMarkerStyle());
975 fGraph2D->SetMarkerSize(fGraph2D->GetMarkerSize());
976 fGraph2D->SetMarkerColor(fGraph2D->GetMarkerColor());
977 fGraph2D->TAttMarker::Modify();
978 gPad->PaintPolyMarker(npd,xm,ym);
989 void TGraph2DPainter::PaintPolyLine(Option_t * )
991 Double_t temp1[3],temp2[3];
993 TView *view = gPad->GetView();
995 Error(
"PaintPolyLine",
"No TView in current pad");
1000 Double_t Xeps = (fXmax - fXmin) * 0.0001;
1001 Double_t Yeps = (fYmax - fYmin) * 0.0001;
1003 Double_t *xm =
new Double_t[fNpoints];
1004 Double_t *ym =
new Double_t[fNpoints];
1007 for (it=0; it<fNpoints; it++) {
1008 if (fXmin - fX[it] > Xeps || fX[it] - fXmax > Xeps)
1010 if (fYmin - fY[it] > Yeps || fY[it] - fYmax > Yeps)
1016 temp1[0] = TMath::Max(temp1[0],fXmin);
1017 temp1[1] = TMath::Max(temp1[1],fYmin);
1018 temp1[2] = TMath::Max(temp1[2],fZmin);
1019 temp1[2] = TMath::Min(temp1[2],fZmax);
1020 if (Hoption.Logx) temp1[0] = TMath::Log10(temp1[0]);
1021 if (Hoption.Logy) temp1[1] = TMath::Log10(temp1[1]);
1022 if (Hoption.Logz) temp1[2] = TMath::Log10(temp1[2]);
1023 view->WCtoNDC(temp1, &temp2[0]);
1024 xm[npd - 1] = temp2[0];
1025 ym[npd - 1] = temp2[1];
1027 fGraph2D->SetLineStyle(fGraph2D->GetLineStyle());
1028 fGraph2D->SetLineWidth(fGraph2D->GetLineWidth());
1029 fGraph2D->SetLineColor(fGraph2D->GetLineColor());
1030 fGraph2D->TAttLine::Modify();
1031 gPad->PaintPolyLine(npd,xm,ym);
1040 void TGraph2DPainter::PaintPolyMarker0(Int_t n, Double_t *x, Double_t *y)
1042 fGraph2D->SetMarkerSize(fGraph2D->GetMarkerSize());
1043 Int_t mc = fGraph2D->GetMarkerColor();
1044 Int_t ms = fGraph2D->GetMarkerStyle();
1045 for (Int_t i=0; i<n; i++) {
1046 fGraph2D->SetMarkerStyle(20);
1047 fGraph2D->SetMarkerColor(0);
1048 fGraph2D->TAttMarker::Modify();
1049 gPad->PaintPolyMarker(1,&x[i],&y[i]);
1050 fGraph2D->SetMarkerStyle(24);
1051 fGraph2D->SetMarkerColor(mc);
1052 fGraph2D->TAttMarker::Modify();
1053 gPad->PaintPolyMarker(1,&x[i],&y[i]);
1055 fGraph2D->SetMarkerStyle(ms);
1062 void TGraph2DPainter::PaintTriangles(Option_t *option)
1065 PaintTriangles_old(option);
1066 else if (fDelaunay2D)
1067 PaintTriangles_new(option);
1074 void TGraph2DPainter::PaintTriangles_old(Option_t *option)
1076 Double_t x[4], y[4], temp1[3],temp2[3];
1081 TView *view = gPad->GetView();
1083 Error(
"PaintTriangles",
"No TView in current pad");
1087 TString opt = option;
1089 Bool_t tri1 = opt.Contains(
"tri1");
1090 Bool_t tri2 = opt.Contains(
"tri2");
1091 Bool_t markers = opt.Contains(
"p");
1092 Bool_t markers0 = opt.Contains(
"p0");
1093 Bool_t wire = opt.Contains(
"w");
1099 if (!tri1 && !tri2 && !wire) {
1100 Int_t ndivz = gCurrentHist->GetZaxis()->GetNdivisions()%100;
1102 Double_t binLow = 0, binHigh = 0, binWidth = 0;
1105 Double_t *r0 = view->GetRmin();
1106 Double_t *r1 = view->GetRmax();
1107 if (!r0 || !r1)
return;
1110 THLimitsFinder::Optimize(r0[2], r1[2], ndivz,
1111 binLow, binHigh, nbins, binWidth,
" ");
1113 nbins = TMath::Abs(ndivz);
1116 binWidth = (binHigh-binLow)/nbins;
1120 glev =
new Double_t[nblev];
1121 for (Int_t i = 0; i < nblev; ++i) glev[i] = binLow+i*binWidth;
1126 Int_t ndiv = gCurrentHist->GetContour();
1128 ndiv = gStyle->GetNumberContours();
1129 gCurrentHist->SetContour(ndiv);
1131 if (gCurrentHist->TestBit(TH1::kUserContour) == 0) gCurrentHist->SetContour(ndiv);
1137 if (!fNdt) FindTriangles();
1138 Double_t cp = TMath::Cos(view->GetLongitude()*TMath::Pi()/180.);
1139 Double_t sp = TMath::Sin(view->GetLongitude()*TMath::Pi()/180.);
1140 order =
new Int_t[fNdt];
1141 dist =
new Double_t[fNdt];
1145 for (it=0; it<fNdt; it++) {
1149 xd = (fXN[p]+fXN[n]+fXN[m])/3;
1150 yd = (fYN[p]+fYN[n]+fYN[m])/3;
1151 if ((cp >= 0) && (sp >= 0.)) {
1152 dist[it] = -(fXNmax-xd+fYNmax-yd);
1153 }
else if ((cp <= 0) && (sp >= 0.)) {
1154 dist[it] = -(fXNmax-xd+yd-fYNmin);
1156 }
else if ((cp <= 0) && (sp <= 0.)) {
1157 dist[it] = -(xd-fXNmin+yd-fYNmin);
1159 dist[it] = -(xd-fXNmin+fYNmax-yd);
1163 TMath::Sort(fNdt, dist, order, o);
1166 fGraph2D->SetFillColor(fGraph2D->GetFillColor());
1167 Int_t fs = fGraph2D->GetFillStyle();
1168 fGraph2D->SetFillStyle(1001);
1169 fGraph2D->TAttFill::Modify();
1170 fGraph2D->SetLineColor(fGraph2D->GetLineColor());
1171 fGraph2D->TAttLine::Modify();
1172 int lst = fGraph2D->GetLineStyle();
1173 for (it=0; it<fNdt; it++) {
1174 t[0] = fPTried[order[it]];
1175 t[1] = fNTried[order[it]];
1176 t[2] = fMTried[order[it]];
1177 for (Int_t k=0; k<3; k++) {
1178 if(fX[t[k]-1] < fXmin || fX[t[k]-1] > fXmax)
goto endloop;
1179 if(fY[t[k]-1] < fYmin || fY[t[k]-1] > fYmax)
goto endloop;
1180 temp1[0] = fX[t[k]-1];
1181 temp1[1] = fY[t[k]-1];
1182 temp1[2] = fZ[t[k]-1];
1183 temp1[0] = TMath::Max(temp1[0],fXmin);
1184 temp1[1] = TMath::Max(temp1[1],fYmin);
1185 temp1[2] = TMath::Max(temp1[2],fZmin);
1186 temp1[2] = TMath::Min(temp1[2],fZmax);
1187 if (Hoption.Logx) temp1[0] = TMath::Log10(temp1[0]);
1188 if (Hoption.Logy) temp1[1] = TMath::Log10(temp1[1]);
1189 if (Hoption.Logz) temp1[2] = TMath::Log10(temp1[2]);
1190 view->WCtoNDC(temp1, &temp2[0]);
1196 if (tri1 || tri2) PaintLevels(t,x,y);
1197 if (!tri1 && !tri2 && !wire) {
1198 gPad->PaintFillArea(3,x,y);
1199 PaintLevels(t,x,y,nblev,glev);
1201 if (!tri2) gPad->PaintPolyLine(4,x,y);
1204 PaintPolyMarker0(3,x,y);
1206 fGraph2D->SetMarkerStyle(fGraph2D->GetMarkerStyle());
1207 fGraph2D->SetMarkerSize(fGraph2D->GetMarkerSize());
1208 fGraph2D->SetMarkerColor(fGraph2D->GetMarkerColor());
1209 fGraph2D->TAttMarker::Modify();
1210 gPad->PaintPolyMarker(3,x,y);
1216 fGraph2D->SetFillStyle(fs);
1217 fGraph2D->SetLineStyle(lst);
1218 fGraph2D->TAttLine::Modify();
1219 fGraph2D->TAttFill::Modify();
1222 if (glev)
delete [] glev;
1229 void TGraph2DPainter::PaintTriangles_new(Option_t *option)
1232 Double_t x[4], y[4], temp1[3],temp2[3];
1235 TView *view = gPad->GetView();
1237 Error(
"PaintTriangles",
"No TView in current pad");
1241 TString opt = option;
1243 Bool_t tri1 = opt.Contains(
"tri1");
1244 Bool_t tri2 = opt.Contains(
"tri2");
1245 Bool_t markers = opt.Contains(
"p");
1246 Bool_t markers0 = opt.Contains(
"p0");
1247 Bool_t wire = opt.Contains(
"w");
1253 if (!tri1 && !tri2 && !wire) {
1254 Int_t ndivz = gCurrentHist->GetZaxis()->GetNdivisions()%100;
1256 Double_t binLow = 0, binHigh = 0, binWidth = 0;
1259 Double_t *r0 = view->GetRmin();
1260 Double_t *r1 = view->GetRmax();
1261 if (!r0 || !r1)
return;
1264 THLimitsFinder::Optimize(r0[2], r1[2], ndivz,
1265 binLow, binHigh, nbins, binWidth,
" ");
1267 nbins = TMath::Abs(ndivz);
1270 binWidth = (binHigh-binLow)/nbins;
1274 glev =
new Double_t[nblev];
1275 for (Int_t i = 0; i < nblev; ++i) glev[i] = binLow+i*binWidth;
1280 Int_t ndiv = gCurrentHist->GetContour();
1282 ndiv = gStyle->GetNumberContours();
1283 gCurrentHist->SetContour(ndiv);
1285 if (gCurrentHist->TestBit(TH1::kUserContour) == 0) gCurrentHist->SetContour(ndiv);
1291 if (!fNdt) FindTriangles();
1292 Double_t cp = TMath::Cos(view->GetLongitude()*TMath::Pi()/180.);
1293 Double_t sp = TMath::Sin(view->GetLongitude()*TMath::Pi()/180.);
1295 Bool_t reverse = kFALSE;
1296 std::function<Double_t(Double_t, Double_t)> fDist;
1298 if ((cp >= 0) && (sp >= 0.)) {
1299 fDist = [&](Double_t xd, Double_t yd) -> Double_t {
return -(fXNmax-xd+fYNmax-yd);};
1300 }
else if ((cp <= 0) && (sp >= 0.)) {
1301 fDist = [&](Double_t xd, Double_t yd) -> Double_t {
return -(fXNmax-xd+yd-fYNmin);};
1303 }
else if ((cp <= 0) && (sp <= 0.)) {
1304 fDist = [&](Double_t xd, Double_t yd) -> Double_t {
return -(xd-fXNmin+yd-fYNmin);};
1306 fDist = [&](Double_t xd, Double_t yd) -> Double_t {
return -(xd-fXNmin+fYNmax-yd);};
1310 typedef std::pair<Double_t, TGraphDelaunay2D::Triangles::const_iterator> DistEntry;
1311 std::vector<DistEntry> dist;
1312 for(
auto it = fDelaunay2D->begin(); it != fDelaunay2D->end(); ++it){
1314 Double_t xd = (face.x[0] + face.x[1] + face.x[2]) / 3;
1315 Double_t yd = (face.y[0] + face.y[1] + face.y[2]) / 3;
1317 dist.emplace_back(fDist(xd, yd), it);
1320 std::sort(dist.begin(), dist.end(),
1321 [&](
const DistEntry & a,
const DistEntry & b){
return !reverse ? (a.first < b.first) : (b.first < a .first); });
1324 fGraph2D->SetFillColor(fGraph2D->GetFillColor());
1325 Int_t fs = fGraph2D->GetFillStyle();
1326 fGraph2D->SetFillStyle(1001);
1327 fGraph2D->TAttFill::Modify();
1328 fGraph2D->SetLineColor(fGraph2D->GetLineColor());
1329 fGraph2D->TAttLine::Modify();
1330 int lst = fGraph2D->GetLineStyle();
1331 for (
const auto & it : dist) {
1332 p[0] = it.second->idx[0];
1333 p[1] = it.second->idx[1];
1334 p[2] = it.second->idx[2];
1335 for (Int_t k=0; k<3; k++) {
1336 if(fX[p[k]] < fXmin || fX[p[k]] > fXmax)
goto endloop;
1337 if(fY[p[k]] < fYmin || fY[p[k]] > fYmax)
goto endloop;
1338 temp1[0] = fX[p[k]];
1339 temp1[1] = fY[p[k]];
1340 temp1[2] = fZ[p[k]];
1341 temp1[0] = TMath::Max(temp1[0],fXmin);
1342 temp1[1] = TMath::Max(temp1[1],fYmin);
1343 temp1[2] = TMath::Max(temp1[2],fZmin);
1344 temp1[2] = TMath::Min(temp1[2],fZmax);
1345 if (Hoption.Logx) temp1[0] = TMath::Log10(temp1[0]);
1346 if (Hoption.Logy) temp1[1] = TMath::Log10(temp1[1]);
1347 if (Hoption.Logz) temp1[2] = TMath::Log10(temp1[2]);
1348 view->WCtoNDC(temp1, &temp2[0]);
1354 if (tri1 || tri2) PaintLevels(p,x,y);
1355 if (!tri1 && !tri2 && !wire) {
1356 gPad->PaintFillArea(3,x,y);
1357 PaintLevels(p,x,y,nblev,glev);
1359 if (!tri2) gPad->PaintPolyLine(4,x,y);
1362 PaintPolyMarker0(3,x,y);
1364 fGraph2D->SetMarkerStyle(fGraph2D->GetMarkerStyle());
1365 fGraph2D->SetMarkerSize(fGraph2D->GetMarkerSize());
1366 fGraph2D->SetMarkerColor(fGraph2D->GetMarkerColor());
1367 fGraph2D->TAttMarker::Modify();
1368 gPad->PaintPolyMarker(3,x,y);
1374 fGraph2D->SetFillStyle(fs);
1375 fGraph2D->SetLineStyle(lst);
1376 fGraph2D->TAttLine::Modify();
1377 fGraph2D->TAttFill::Modify();
1379 if (glev)
delete [] glev;