19 ClassImp(TPolyMarker);
33 TPolyMarker::TPolyMarker(): TObject()
43 TPolyMarker::TPolyMarker(Int_t n, Option_t *option)
44 :TObject(), TAttMarker()
56 fX =
new Double_t [fN];
57 fY =
new Double_t [fN];
63 TPolyMarker::TPolyMarker(Int_t n, Float_t *x, Float_t *y, Option_t *option)
64 :TObject(), TAttMarker()
76 fX =
new Double_t [fN];
77 fY =
new Double_t [fN];
79 for (Int_t i=0; i<fN;i++) { fX[i] = x[i]; fY[i] = y[i]; }
86 TPolyMarker::TPolyMarker(Int_t n, Double_t *x, Double_t *y, Option_t *option)
87 :TObject(), TAttMarker()
99 fX =
new Double_t [fN];
100 fY =
new Double_t [fN];
101 if (!x || !y)
return;
102 for (Int_t i=0; i<fN;i++) { fX[i] = x[i]; fY[i] = y[i]; }
109 TPolyMarker& TPolyMarker::operator=(
const TPolyMarker& pm)
112 TObject::operator=(pm);
113 TAttMarker::operator=(pm);
115 fLastPoint=pm.fLastPoint;
117 if (fX)
delete [] fX;
118 if (fY)
delete [] fY;
129 TPolyMarker::~TPolyMarker()
131 if (fX)
delete [] fX;
132 if (fY)
delete [] fY;
139 TPolyMarker::TPolyMarker(
const TPolyMarker &polymarker) : TObject(polymarker), TAttMarker(polymarker)
144 ((TPolyMarker&)polymarker).Copy(*
this);
149 void TPolyMarker::Copy(TObject &obj)
const
154 TAttMarker::Copy(((TPolyMarker&)obj));
155 ((TPolyMarker&)obj).fN = fN;
157 if (((TPolyMarker&)obj).fX)
delete [] (((TPolyMarker&)obj).fX);
158 if (((TPolyMarker&)obj).fY)
delete [] (((TPolyMarker&)obj).fY);
160 ((TPolyMarker&)obj).fX =
new Double_t [fN];
161 ((TPolyMarker&)obj).fY =
new Double_t [fN];
162 for (Int_t i=0; i<fN;i++) { ((TPolyMarker&)obj).fX[i] = fX[i], ((TPolyMarker&)obj).fY[i] = fY[i]; }
164 ((TPolyMarker&)obj).fX = 0;
165 ((TPolyMarker&)obj).fY = 0;
167 ((TPolyMarker&)obj).fOption = fOption;
168 ((TPolyMarker&)obj).fLastPoint = fLastPoint;
179 Int_t TPolyMarker::DistancetoPrimitive(Int_t px, Int_t py)
181 const Int_t big = 9999;
184 Int_t i, pxp, pyp, d;
185 Int_t distance = big;
187 for (i=0;i<Size();i++) {
188 pxp = gPad->XtoAbsPixel(gPad->XtoPad(fX[i]));
189 pyp = gPad->YtoAbsPixel(gPad->YtoPad(fY[i]));
190 d = TMath::Abs(pxp-px) + TMath::Abs(pyp-py);
191 if (d < distance) distance = d;
199 void TPolyMarker::Draw(Option_t *option)
207 void TPolyMarker::DrawPolyMarker(Int_t n, Double_t *x, Double_t *y, Option_t *)
209 TPolyMarker *newpolymarker =
new TPolyMarker(n,x,y);
210 TAttMarker::Copy(*newpolymarker);
211 newpolymarker->fOption = fOption;
212 newpolymarker->SetBit(kCanDelete);
213 newpolymarker->AppendPad();
222 void TPolyMarker::ExecuteEvent(Int_t, Int_t, Int_t)
229 void TPolyMarker::ls(Option_t *)
const
231 TROOT::IndentLevel();
232 printf(
"TPolyMarker N=%d\n",fN);
238 Int_t TPolyMarker::Merge(TCollection *li)
246 while ((pm = (TPolyMarker*)next())) {
247 if (!pm->InheritsFrom(TPolyMarker::Class())) {
248 Error(
"Add",
"Attempt to add object of class: %s to a %s",pm->ClassName(),this->ClassName());
251 npoints += pm->Size();
255 SetPoint(npoints-1,0,0);
259 while ((pm = (TPolyMarker*)next())) {
260 Int_t np = pm->Size();
261 Double_t *x = pm->GetX();
262 Double_t *y = pm->GetY();
263 for (Int_t i=0;i<np;i++) {
264 SetPoint(i,x[i],y[i]);
274 void TPolyMarker::Paint(Option_t *option)
276 PaintPolyMarker(fLastPoint+1, fX, fY, option);
282 void TPolyMarker::PaintPolyMarker(Int_t n, Double_t *x, Double_t *y, Option_t *option)
285 TAttMarker::Modify();
288 if (gPad->GetLogx()) {
289 xx =
new Double_t[n];
290 for (Int_t ix=0;ix<n;ix++) xx[ix] = gPad->XtoPad(x[ix]);
292 if (gPad->GetLogy()) {
293 yy =
new Double_t[n];
294 for (Int_t iy=0;iy<n;iy++) yy[iy] = gPad->YtoPad(y[iy]);
296 gPad->PaintPolyMarker(n,xx,yy,option);
297 if (x != xx)
delete [] xx;
298 if (y != yy)
delete [] yy;
304 void TPolyMarker::Print(Option_t *)
const
306 printf(
"TPolyMarker N=%d\n",fN);
312 void TPolyMarker::SavePrimitive(std::ostream &out, Option_t *option )
316 out<<
" Double_t *dum = 0;"<<std::endl;
317 if (gROOT->ClassSaved(TPolyMarker::Class())) {
320 out<<
" TPolyMarker *";
322 out<<
"pmarker = new TPolyMarker("<<fN<<
",dum,dum,"<<quote<<fOption<<quote<<
");"<<std::endl;
324 SaveMarkerAttributes(out,
"pmarker",1,1,1);
326 for (Int_t i=0;i<Size();i++) {
327 out<<
" pmarker->SetPoint("<<i<<
","<<fX[i]<<
","<<fY[i]<<
");"<<std::endl;
329 if (!strstr(option,
"nodraw")) {
330 out<<
" pmarker->Draw("
331 <<quote<<option<<quote<<
");"<<std::endl;
339 Int_t TPolyMarker::SetNextPoint(Double_t x, Double_t y)
342 SetPoint(fLastPoint, x, y);
351 void TPolyMarker::SetPoint(Int_t n, Double_t x, Double_t y)
354 if (!fX || !fY || n >= fN) {
356 Int_t newN = TMath::Max(2*fN,n+1);
357 Double_t *savex =
new Double_t [newN];
358 Double_t *savey =
new Double_t [newN];
360 memcpy(savex,fX,fN*
sizeof(Double_t));
361 memset(&savex[fN],0,(newN-fN)*
sizeof(Double_t));
365 memcpy(savey,fY,fN*
sizeof(Double_t));
366 memset(&savey[fN],0,(newN-fN)*
sizeof(Double_t));
375 fLastPoint = TMath::Max(fLastPoint,n);
381 void TPolyMarker::SetPolyMarker(Int_t n)
397 void TPolyMarker::SetPolyMarker(Int_t n, Float_t *x, Float_t *y, Option_t *option)
408 if (fX)
delete [] fX;
409 if (fY)
delete [] fY;
410 fX =
new Double_t[fN];
411 fY =
new Double_t[fN];
412 for (Int_t i=0; i<fN;i++) {
413 if (x) fX[i] = (Double_t)x[i];
414 if (y) fY[i] = (Double_t)y[i];
423 void TPolyMarker::SetPolyMarker(Int_t n, Double_t *x, Double_t *y, Option_t *option)
434 if (fX)
delete [] fX;
435 if (fY)
delete [] fY;
436 fX =
new Double_t[fN];
437 fY =
new Double_t[fN];
438 for (Int_t i=0; i<fN;i++) {
449 void TPolyMarker::Streamer(TBuffer &R__b)
451 if (R__b.IsReading()) {
453 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
455 R__b.ReadClassBuffer(TPolyMarker::Class(),
this, R__v, R__s, R__c);
459 TObject::Streamer(R__b);
460 TAttMarker::Streamer(R__b);
462 fX =
new Double_t[fN];
463 fY =
new Double_t[fN];
466 for (i=0;i<fN;i++) {R__b >> xold; fX[i] = xold;}
467 for (i=0;i<fN;i++) {R__b >> yold; fY[i] = yold;}
468 fOption.Streamer(R__b);
469 R__b.CheckByteCount(R__s, R__c, TPolyMarker::IsA());
473 R__b.WriteClassBuffer(TPolyMarker::Class(),
this);