27 ClassImp(TPolyMarker3D);
 
   29 constexpr Int_t kDimension = 3;
 
   74 TPolyMarker3D::TPolyMarker3D()
 
   79    fName = 
"TPolyMarker3D";
 
   85 TPolyMarker3D::TPolyMarker3D(Int_t n, Marker_t marker, Option_t *option)
 
   87    fName = 
"TPolyMarker3D";
 
   89    SetMarkerStyle(marker);
 
   99    fP = 
new Float_t [kDimension*fN];
 
  100    for (Int_t i = 0; i < kDimension*fN; i++)  fP[i] = 0;
 
  106 TPolyMarker3D::TPolyMarker3D(Int_t n, Float_t *p, Marker_t marker,
 
  109    fName = 
"TPolyMarker3D";
 
  110    SetMarkerStyle(marker);
 
  121    fP = 
new Float_t [kDimension*fN];
 
  123       for (Int_t i = 0; i < kDimension*fN; i++)
 
  127       memset(fP,0,kDimension*fN*
sizeof(Float_t));
 
  134 TPolyMarker3D::TPolyMarker3D(Int_t n, Double_t *p, Marker_t marker,
 
  137    fName = 
"TPolyMarker3D";
 
  138    SetMarkerStyle(marker);
 
  149    fP = 
new Float_t [kDimension*fN];
 
  151       for (Int_t i = 0; i < kDimension*fN; i++)
 
  152          fP[i] = (Float_t) p[i];
 
  155       memset(fP,0,kDimension*fN*
sizeof(Float_t));
 
  161 TPolyMarker3D& TPolyMarker3D::operator=(
const TPolyMarker3D& tp3)
 
  164       TObject::operator=(tp3);
 
  165       TAttMarker::operator=(tp3);
 
  166       TAtt3D::operator=(tp3);
 
  170       fLastPoint=tp3.fLastPoint;
 
  179 TPolyMarker3D::~TPolyMarker3D()
 
  182    if (fP) 
delete [] fP;
 
  189 TPolyMarker3D::TPolyMarker3D(
const TPolyMarker3D &p) :
 
  190    TObject(p), TAttMarker(p), TAtt3D(p)
 
  201 void TPolyMarker3D::Copy(TObject &obj)
 const 
  204    ((TPolyMarker3D&)obj).fN = fN;
 
  206       ((TPolyMarker3D&)obj).fP = 
new Float_t [kDimension*fN];
 
  207       for (Int_t i = 0; i < kDimension*fN; i++)  ((TPolyMarker3D&)obj).fP[i] = fP[i];
 
  209       ((TPolyMarker3D&)obj).fP = 0;
 
  211    ((TPolyMarker3D&)obj).SetMarkerStyle(GetMarkerStyle());
 
  212    ((TPolyMarker3D&)obj).fOption = fOption;
 
  213    ((TPolyMarker3D&)obj).fLastPoint = fLastPoint;
 
  214    ((TPolyMarker3D&)obj).fName   = fName;
 
  224 Int_t TPolyMarker3D::DistancetoPrimitive(Int_t px, Int_t py)
 
  226    const Int_t inaxis = 7;
 
  229    Int_t puxmin = gPad->XtoAbsPixel(gPad->GetUxmin());
 
  230    Int_t puymin = gPad->YtoAbsPixel(gPad->GetUymin());
 
  231    Int_t puxmax = gPad->XtoAbsPixel(gPad->GetUxmax());
 
  232    Int_t puymax = gPad->YtoAbsPixel(gPad->GetUymax());
 
  235    if (px < puxmin - inaxis) 
return dist;
 
  236    if (py > puymin + inaxis) 
return dist;
 
  237    if (px > puxmax + inaxis) 
return dist;
 
  238    if (py < puymax - inaxis) 
return dist;
 
  240    TView *view = gPad->GetView();
 
  241    if (!view) 
return dist;
 
  246    for (i=0;i<Size();i++) {
 
  247       view->WCtoNDC(&fP[3*i], xndc);
 
  248       u      = (Double_t)xndc[0];
 
  249       v      = (Double_t)xndc[1];
 
  250       if (u < gPad->GetUxmin() || u > gPad->GetUxmax()) 
continue;
 
  251       if (v < gPad->GetUymin() || v > gPad->GetUymax()) 
continue;
 
  252       x1     = gPad->XtoAbsPixel(u);
 
  253       y1     = gPad->YtoAbsPixel(v);
 
  254       dpoint = Int_t(TMath::Sqrt((((Double_t)px-x1)*((Double_t)px-x1)
 
  255                                 + ((Double_t)py-y1)*((Double_t)py-y1))));
 
  256       if (dpoint < dist) dist = dpoint;
 
  264 void TPolyMarker3D::Draw(Option_t *option)
 
  274 void TPolyMarker3D::DrawPolyMarker(Int_t n, Float_t *p, Marker_t, Option_t *option)
 
  276    TPolyMarker3D *newpolymarker = 
new TPolyMarker3D();
 
  277    newpolymarker->fN = n;
 
  278    newpolymarker->fP = 
new Float_t [kDimension*fN];
 
  279    for (Int_t i = 0; i < kDimension*fN; i++)  newpolymarker->fP[i] = p[i];
 
  280    newpolymarker->SetMarkerStyle(GetMarkerStyle());
 
  281    newpolymarker->fOption = fOption;
 
  282    newpolymarker->fLastPoint = fLastPoint;
 
  283    newpolymarker->SetBit(kCanDelete);
 
  284    newpolymarker->AppendPad(option);
 
  290 void TPolyMarker3D::ExecuteEvent(Int_t event, Int_t px, Int_t py)
 
  293    if (gPad->GetView()) gPad->GetView()->ExecuteRotateView(event, px, py);
 
  299 void TPolyMarker3D::ls(Option_t *option)
 const 
  301    TROOT::IndentLevel();
 
  302    std::cout << 
"    TPolyMarker3D  N=" << Size() <<
" Option="<<option<<std::endl;
 
  308 Int_t TPolyMarker3D::Merge(TCollection *li)
 
  315    Int_t npoints = Size();
 
  316    while ((pm = (TPolyMarker3D*)next())) {
 
  317       if (!pm->InheritsFrom(TPolyMarker3D::Class())) {
 
  318          Error(
"Add",
"Attempt to add object of class: %s to a %s",pm->ClassName(),this->ClassName());
 
  321       npoints += pm->Size();
 
  323    Int_t currPoint = Size();
 
  326    SetPoint(npoints-1,0,0,0);
 
  330    while ((pm = (TPolyMarker3D*)next())) {
 
  331       Int_t np = pm->Size();
 
  332       Float_t *p = pm->GetP();
 
  333       for (Int_t i = 0; i < np; i++) {
 
  334          SetPoint(currPoint++, p[3*i], p[3*i+1], p[3*i+2]);
 
  343 void TPolyMarker3D::Paint(Option_t *  )
 
  346    if (Size() <= 0) 
return;
 
  348    static TBuffer3D buffer(TBuffer3DTypes::kMarker);
 
  350    buffer.ClearSectionsValid();
 
  354    buffer.fColor        = GetMarkerColor();
 
  355    buffer.fTransparency = 0;
 
  356    buffer.fLocalFrame   = kFALSE;
 
  357    buffer.SetSectionsValid(TBuffer3D::kCore);
 
  360    TVirtualViewer3D * viewer3D = gPad->GetViewer3D();
 
  361    if (!viewer3D) 
return;
 
  362    Int_t reqSections = viewer3D->AddObject(buffer);
 
  363    if (reqSections == TBuffer3D::kNone) {
 
  367    if (reqSections & TBuffer3D::kRawSizes) {
 
  368       if (!buffer.SetRawSizes(Size(), 3*Size(), 1, 1, 0, 0)) {
 
  371       buffer.SetSectionsValid(TBuffer3D::kRawSizes);
 
  374    if ((reqSections & TBuffer3D::kRaw) && buffer.SectionsValid(TBuffer3D::kRawSizes)) {
 
  376       for (UInt_t i=0; i<3*buffer.NbPnts(); i++) {
 
  377          buffer.fPnts[i] = (Double_t)fP[i];
 
  385          for (UInt_t j=0; j<buffer.NbPnts(); j++) {
 
  386             dlocal[0] = buffer.fPnts[3*j];
 
  387             dlocal[1] = buffer.fPnts[3*j+1];
 
  388             dlocal[2] = buffer.fPnts[3*j+2];
 
  389             gGeometry->Local2Master(&dlocal[0],&dmaster[0]);
 
  390             buffer.fPnts[3*j]   = dmaster[0];
 
  391             buffer.fPnts[3*j+1] = dmaster[1];
 
  392             buffer.fPnts[3*j+2] = dmaster[2];
 
  397       Int_t c = (((GetMarkerColor()) %8) -1) * 4;
 
  403       buffer.SetSectionsValid(TBuffer3D::kRaw);
 
  405       TAttMarker::Modify();
 
  408    viewer3D->AddObject(buffer);
 
  414 void TPolyMarker3D::PaintH3(TH1 *h, Option_t *option)
 
  416    const Int_t kMaxEntry = 100000;
 
  417    Int_t in, bin, binx, biny, binz;
 
  419    TAxis *xaxis = h->GetXaxis();
 
  420    TAxis *yaxis = h->GetYaxis();
 
  421    TAxis *zaxis = h->GetZaxis();
 
  423    for (binz=zaxis->GetFirst();binz<=zaxis->GetLast();binz++) {
 
  424       for (biny=yaxis->GetFirst();biny<=yaxis->GetLast();biny++) {
 
  425          for (binx=xaxis->GetFirst();binx<=xaxis->GetLast();binx++) {
 
  426             bin = h->GetBin(binx,biny,binz);
 
  427             entry += h->GetBinContent(bin);
 
  436    if (entry > kMaxEntry) scale = kMaxEntry/Double_t(entry);
 
  439    TView *view = gPad->GetView();
 
  441       gPad->Range(-1,-1,1,1);
 
  442       view = TView::CreateView(1,0,0);
 
  445    view->SetRange(xaxis->GetBinLowEdge(xaxis->GetFirst()),
 
  446                   yaxis->GetBinLowEdge(yaxis->GetFirst()),
 
  447                   zaxis->GetBinLowEdge(zaxis->GetFirst()),
 
  448                   xaxis->GetBinUpEdge(xaxis->GetLast()),
 
  449                   yaxis->GetBinUpEdge(yaxis->GetLast()),
 
  450                   zaxis->GetBinUpEdge(zaxis->GetLast()));
 
  452    view->PadRange(gPad->GetFrameFillColor());
 
  454    if (entry == 0) 
return;
 
  455    Int_t nmk = Int_t(TMath::Min(Double_t(kMaxEntry),entry));
 
  456    TPolyMarker3D *pm3d    = 
new TPolyMarker3D(nmk);
 
  457    pm3d->SetMarkerStyle(h->GetMarkerStyle());
 
  458    pm3d->SetMarkerColor(h->GetMarkerColor());
 
  459    pm3d->SetMarkerSize(h->GetMarkerSize());
 
  460    gPad->Modified(kTRUE);
 
  463    Double_t x,y,z,xw,yw,zw,xp,yp,zp;
 
  465    for (binz=zaxis->GetFirst();binz<=zaxis->GetLast();binz++) {
 
  466       z  = zaxis->GetBinLowEdge(binz);
 
  467       zw = zaxis->GetBinWidth(binz);
 
  468       for (biny=yaxis->GetFirst();biny<=yaxis->GetLast();biny++) {
 
  469          y  = yaxis->GetBinLowEdge(biny);
 
  470          yw = yaxis->GetBinWidth(biny);
 
  471          for (binx=xaxis->GetFirst();binx<=xaxis->GetLast();binx++) {
 
  472             x  = xaxis->GetBinLowEdge(binx);
 
  473             xw = xaxis->GetBinWidth(binx);
 
  474             bin = h->GetBin(binx,biny,binz);
 
  475             ncounts = Int_t(h->GetBinContent(bin)*scale+0.5);
 
  476             for (in=0;in<ncounts;in++) {
 
  477                xp = x + xw*gRandom->Rndm();
 
  478                yp = y + yw*gRandom->Rndm();
 
  479                zp = z + zw*gRandom->Rndm();
 
  480                pm3d->SetPoint(Int_t(entry),xp,yp,zp);
 
  493 void TPolyMarker3D::Print(Option_t *option)
 const 
  495    printf(
"TPolyMarker3D N=%d, Option=%s\n",fN,option);
 
  496    TString opt = option;
 
  498    if (opt.Contains(
"all")) {
 
  499       for (Int_t i=0;i<Size();i++) {
 
  500          TROOT::IndentLevel();
 
  501          printf(
" x[%d]=%g, y[%d]=%g, z[%d]=%g\n",i,fP[3*i],i,fP[3*i+1],i,fP[3*i+2]);
 
  509 void TPolyMarker3D::SavePrimitive(std::ostream &out, Option_t * )
 
  513    if (gROOT->ClassSaved(TPolyMarker3D::Class())) {
 
  516       out<<
"   TPolyMarker3D *";
 
  518    out<<
"pmarker3D = new TPolyMarker3D("<<fN<<
","<<GetMarkerStyle()<<
","<<quote<<fOption<<quote<<
");"<<std::endl;
 
  519    out<<
"   pmarker3D->SetName("<<quote<<GetName()<<quote<<
");"<<std::endl;
 
  521    SaveMarkerAttributes(out,
"pmarker3D",1,1,1);
 
  523    for (Int_t i=0;i<Size();i++) {
 
  524       out<<
"   pmarker3D->SetPoint("<<i<<
","<<fP[3*i]<<
","<<fP[3*i+1]<<
","<<fP[3*i+2]<<
");"<<std::endl;
 
  526    out<<
"   pmarker3D->Draw();"<<std::endl;
 
  535 void TPolyMarker3D::SetName(
const char *name)
 
  538    if (gPad && TestBit(kMustCleanup)) gPad->Modified();
 
  545 Int_t TPolyMarker3D::SetNextPoint(Double_t x, Double_t y, Double_t z)
 
  548    SetPoint(fLastPoint, x, y, z);
 
  557 void TPolyMarker3D::SetPoint(Int_t n, Double_t x, Double_t y, Double_t z)
 
  560    if (!fP || n >= fN) {
 
  562       Int_t newN = TMath::Max(2*fN,n+1);
 
  563       Float_t *savepoint = 
new Float_t [kDimension*newN];
 
  565          memcpy(savepoint,fP,kDimension*fN*
sizeof(Float_t));
 
  566          memset(&savepoint[kDimension*fN],0,(newN-fN)*
sizeof(Float_t));
 
  572    fP[kDimension*n  ] = x;
 
  573    fP[kDimension*n+1] = y;
 
  574    fP[kDimension*n+2] = z;
 
  575    fLastPoint = TMath::Max(fLastPoint,n);
 
  582 void TPolyMarker3D::SetPolyMarker(Int_t n, Float_t *p, Marker_t marker, Option_t *option)
 
  584    SetMarkerStyle(marker);
 
  594    if (fP) 
delete [] fP;
 
  595    fP = 
new Float_t [3*fN];
 
  597       for (Int_t i = 0; i < fN; i++) {
 
  599          fP[3*i+1] = p[3*i+1];
 
  600          fP[3*i+2] = p[3*i+2];
 
  603       memset(fP,0,kDimension*fN*
sizeof(Float_t));
 
  612 void TPolyMarker3D::SetPolyMarker(Int_t n, Double_t *p, Marker_t marker, Option_t *option)
 
  614    SetMarkerStyle(marker);
 
  624    if (fP) 
delete [] fP;
 
  625    fP = 
new Float_t [3*fN];
 
  627       for (Int_t i = 0; i < fN; i++) {
 
  628          fP[3*i]   = (Float_t) p[3*i];
 
  629          fP[3*i+1] = (Float_t) p[3*i+1];
 
  630          fP[3*i+2] = (Float_t) p[3*i+2];
 
  633       memset(fP,0,kDimension*fN*
sizeof(Float_t));
 
  641 void TPolyMarker3D::Streamer(TBuffer &b)
 
  645       Version_t R__v = b.ReadVersion(&R__s, &R__c);
 
  646       if (R__v > 2) b.ClassBegin(TPolyMarker3D::IsA());
 
  647       if (R__v > 2) b.ClassMember(
"TObject");
 
  648       TObject::Streamer(b);
 
  649       if (R__v > 2) b.ClassMember(
"TAttMarker");
 
  650       TAttMarker::Streamer(b);
 
  651       if (R__v > 2) b.ClassMember(
"fN",
"Int_t");
 
  654          if (R__v > 2) b.ClassMember(
"fP",
"Float_t", kDimension*fN);
 
  655          fP = 
new Float_t[kDimension*fN];
 
  656          b.ReadFastArray(fP,kDimension*fN);
 
  659       if (R__v > 2) b.ClassMember(
"fOption",
"TString");
 
  661       if (R__v > 2) b.ClassMember(
"fName",
"TString");
 
  662       if (R__v > 1) fName.Streamer(b);
 
  663       if (R__v > 2) b.ClassEnd(TPolyMarker3D::IsA());
 
  664       b.CheckByteCount(R__s, R__c, TPolyMarker3D::IsA());
 
  666       R__c = b.WriteVersion(TPolyMarker3D::IsA(), kTRUE);
 
  667       b.ClassBegin(TPolyMarker3D::IsA());
 
  668       b.ClassMember(
"TObject");
 
  669       TObject::Streamer(b);
 
  670       b.ClassMember(
"TAttMarker");
 
  671       TAttMarker::Streamer(b);
 
  672       b.ClassMember(
"fN",
"Int_t");
 
  676          b.ClassMember(
"fP",
"Float_t", kDimension*size);
 
  677          b.WriteFastArray(fP, kDimension*size);
 
  679       b.ClassMember(
"fOption",
"TString");
 
  681       b.ClassMember(
"fName",
"TString");
 
  683       b.ClassEnd(TPolyMarker3D::IsA());
 
  684       b.SetByteCount(R__c, kTRUE);
 
  692 void TPolyMarker3D::GetPoint(Int_t n, Float_t &x, Float_t &y, Float_t &z)
 const 
  694    if (n < 0 || n >= Size()) 
return;
 
  696    x = fP[kDimension*n  ];
 
  697    y = fP[kDimension*n+1];
 
  698    z = fP[kDimension*n+2];
 
  705 void TPolyMarker3D::GetPoint(Int_t n, Double_t &x, Double_t &y, Double_t &z)
 const 
  707    if (n < 0 || n >= Size()) 
return;
 
  709    x = (Double_t)fP[kDimension*n  ];
 
  710    y = (Double_t)fP[kDimension*n+1];
 
  711    z = (Double_t)fP[kDimension*n+2];