Logo ROOT  
Reference Guide
TPolyLine.cxx
Go to the documentation of this file.
1// @(#)root/graf:$Id$
2// Author: Rene Brun 12/12/94
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include <iostream>
13#include "TROOT.h"
14#include "TBuffer.h"
15#include "TMath.h"
16#include "TVirtualPad.h"
17#include "TVirtualX.h"
18#include "TPolyLine.h"
19
21
22/** \class TPolyLine
23\ingroup BasicGraphics
24
25Defined by an array on N points in a 2-D space.
26
27One can draw the contour of the polyline or/and its fill area.
28Example:
29Begin_Macro(source)
30{
31 Double_t x[5] = {.2,.7,.6,.25,.2};
32 Double_t y[5] = {.5,.1,.9,.7,.5};
33 TPolyLine *pline = new TPolyLine(5,x,y);
34 pline->SetFillColor(38);
35 pline->SetLineColor(2);
36 pline->SetLineWidth(4);
37 pline->Draw("f");
38 pline->Draw();
39}
40End_Macro
41*/
42
43////////////////////////////////////////////////////////////////////////////////
44/// PolyLine default constructor.
45
47{
48 fN = 0;
49 fX = 0;
50 fY = 0;
51 fLastPoint = -1;
52}
53
54////////////////////////////////////////////////////////////////////////////////
55/// PolyLine normal constructor without initialisation.
56/// Allocates n points. The option string is ignored.
57
60{
62 fLastPoint = -1;
63 if (n <= 0) {
64 fN = 0;
65 fLastPoint = -1;
66 fX = fY = 0;
67 return;
68 }
69 fN = n;
70 fX = new Double_t[fN];
71 fY = new Double_t[fN];
72}
73
74////////////////////////////////////////////////////////////////////////////////
75/// PolyLine normal constructor (single precision).
76/// Makes n points with (x, y) coordinates from x and y.
77/// The option string is ignored.
78
81{
83 fLastPoint = -1;
84 if (n <= 0) {
85 fN = 0;
86 fLastPoint = -1;
87 fX = fY = 0;
88 return;
89 }
90 fN = n;
91 fX = new Double_t[fN];
92 fY = new Double_t[fN];
93 if (!x || !y) return;
94 for (Int_t i=0; i<fN;i++) { fX[i] = x[i]; fY[i] = y[i];}
95 fLastPoint = fN-1;
96}
97
98////////////////////////////////////////////////////////////////////////////////
99/// PolyLine normal constructor (double precision).
100/// Makes n points with (x, y) coordinates from x and y.
101/// The option string is ignored.
102
104 :TObject(), TAttLine(), TAttFill()
105{
106 fOption = option;
107 fLastPoint = -1;
108 if (n <= 0) {
109 fN = 0;
110 fLastPoint = -1;
111 fX = fY = 0;
112 return;
113 }
114 fN = n;
115 fX = new Double_t[fN];
116 fY = new Double_t[fN];
117 if (!x || !y) return;
118 for (Int_t i=0; i<fN;i++) { fX[i] = x[i]; fY[i] = y[i];}
119 fLastPoint = fN-1;
120}
121
122////////////////////////////////////////////////////////////////////////////////
123///assignment operator
124
126{
127 if(this!=&pl) {
128 pl.Copy(*this);
129 }
130 return *this;
131}
132
133////////////////////////////////////////////////////////////////////////////////
134/// PolyLine default destructor.
135
137{
138 if (fX) delete [] fX;
139 if (fY) delete [] fY;
140}
141
142////////////////////////////////////////////////////////////////////////////////
143/// PolyLine copy constructor.
144
145TPolyLine::TPolyLine(const TPolyLine &polyline) : TObject(polyline), TAttLine(polyline), TAttFill(polyline)
146{
147 fN = 0;
148 fX = 0;
149 fY = 0;
150 fLastPoint = -1;
151 ((TPolyLine&)polyline).Copy(*this);
152}
153
154////////////////////////////////////////////////////////////////////////////////
155/// Copy this polyline to polyline.
156
157void TPolyLine::Copy(TObject &obj) const
158{
159 TObject::Copy(obj);
160 TAttLine::Copy(((TPolyLine&)obj));
161 TAttFill::Copy(((TPolyLine&)obj));
162 ((TPolyLine&)obj).fN = fN;
163 delete [] ((TPolyLine&)obj).fX;
164 delete [] ((TPolyLine&)obj).fY;
165 if (fN > 0) {
166 ((TPolyLine&)obj).fX = new Double_t[fN];
167 ((TPolyLine&)obj).fY = new Double_t[fN];
168 for (Int_t i=0; i<fN;i++) {((TPolyLine&)obj).fX[i] = fX[i]; ((TPolyLine&)obj).fY[i] = fY[i];}
169 } else {
170 ((TPolyLine&)obj).fX = 0;
171 ((TPolyLine&)obj).fY = 0;
172 }
173 ((TPolyLine&)obj).fOption = fOption;
174 ((TPolyLine&)obj).fLastPoint = fLastPoint;
175}
176
177////////////////////////////////////////////////////////////////////////////////
178/// Returns closest distance in pixels from point (px, py) to a polyline.
179///
180/// First looks for distances to the points of the polyline. Stops search
181/// and returns if a vertex of the polyline is found to be closer than 10
182/// pixels. Thus the return value may depend on the ordering of points
183/// in the polyline.
184///
185/// Then looks for distances to the lines of the polyline. There is no
186/// arbitrary cutoff; any distance may be found.
187///
188/// Finally checks whether (px, py) is inside a closed and filled polyline.
189/// (Must be EXACTLY closed. "Filled" means fill color and fill style are
190/// both non-zero.) If so, returns zero.
191///
192/// Returns 9999 if the polyline has no points.
193
195{
196 const Int_t big = 9999;
197 const Int_t kMaxDiff = 10;
198
199 // check if point is near one of the points
200 Int_t i, pxp, pyp, d;
201 Int_t distance = big;
202 if (Size() <= 0) return distance;
203
204 for (i=0;i<Size();i++) {
205 pxp = gPad->XtoAbsPixel(gPad->XtoPad(fX[i]));
206 pyp = gPad->YtoAbsPixel(gPad->YtoPad(fY[i]));
207 d = TMath::Abs(pxp-px) + TMath::Abs(pyp-py);
208 if (d < distance) distance = d;
209 }
210 if (distance < kMaxDiff) return distance;
211
212 // check if point is near one of the connecting lines
213 for (i=0;i<Size()-1;i++) {
214 d = DistancetoLine(px, py, gPad->XtoPad(fX[i]), gPad->YtoPad(fY[i]), gPad->XtoPad(fX[i+1]), gPad->YtoPad(fY[i+1]));
215 if (d < distance) distance = d;
216 }
217
218 // in case of a closed and filled polyline, check if we are inside
219 if (fFillColor && fFillStyle && fX[0] == fX[fLastPoint] && fY[0] == fY[fLastPoint]) {
220 if (TMath::IsInside(gPad->AbsPixeltoX(px),gPad->AbsPixeltoY(py),fLastPoint+1,fX,fY)) distance = 0;
221 }
222 return distance;
223}
224
225////////////////////////////////////////////////////////////////////////////////
226/// Draw this polyline with its current attributes.
227
229{
231}
232
233////////////////////////////////////////////////////////////////////////////////
234/// Draw this polyline with new coordinates.
235
237{
238 TPolyLine *newpolyline = new TPolyLine(n,x,y);
239 TAttLine::Copy(*newpolyline);
240 TAttFill::Copy(*newpolyline);
241 newpolyline->fOption = fOption;
242 newpolyline->SetBit(kCanDelete);
243 newpolyline->AppendPad(option);
244 return newpolyline;
245}
246
247////////////////////////////////////////////////////////////////////////////////
248/// Execute action corresponding to one event.
249///
250/// This member function is called when a polyline is clicked with the locator
251///
252/// If Left button clicked on one of the line end points, this point
253/// follows the cursor until button is released.
254///
255/// if Middle button clicked, the line is moved parallel to itself
256/// until the button is released.
257
259{
260 if (!gPad) return;
261
262 Int_t i, d;
263 Double_t xmin, xmax, ymin, ymax, dx, dy, dxr, dyr;
264 const Int_t kMaxDiff = 10;
265 static Bool_t middle;
266 static Int_t ipoint, pxp, pyp;
267 static Int_t px1,px2,py1,py2;
268 static Int_t pxold, pyold, px1old, py1old, px2old, py2old;
269 static Int_t dpx, dpy;
270 static Int_t *x=0, *y=0;
271 Bool_t opaque = gPad->OpaqueMoving();
272
273 if (!gPad->IsEditable()) return;
274
275 Int_t np = Size();
276
277 switch (event) {
278
279 case kButton1Down:
280 gVirtualX->SetLineColor(-1);
281 TAttLine::Modify(); //Change line attributes only if necessary
282 px1 = gPad->XtoAbsPixel(gPad->GetX1());
283 py1 = gPad->YtoAbsPixel(gPad->GetY1());
284 px2 = gPad->XtoAbsPixel(gPad->GetX2());
285 py2 = gPad->YtoAbsPixel(gPad->GetY2());
286 ipoint = -1;
287
288
289 if (x || y) break;
290 x = new Int_t[np+1];
291 y = new Int_t[np+1];
292 for (i=0;i<np;i++) {
293 pxp = gPad->XtoAbsPixel(gPad->XtoPad(fX[i]));
294 pyp = gPad->YtoAbsPixel(gPad->YtoPad(fY[i]));
295 if (!opaque) {
296 gVirtualX->DrawLine(pxp-4, pyp-4, pxp+4, pyp-4);
297 gVirtualX->DrawLine(pxp+4, pyp-4, pxp+4, pyp+4);
298 gVirtualX->DrawLine(pxp+4, pyp+4, pxp-4, pyp+4);
299 gVirtualX->DrawLine(pxp-4, pyp+4, pxp-4, pyp-4);
300 }
301 x[i] = pxp;
302 y[i] = pyp;
303 d = TMath::Abs(pxp-px) + TMath::Abs(pyp-py);
304 if (d < kMaxDiff) ipoint =i;
305 }
306 dpx = 0;
307 dpy = 0;
308 pxold = px;
309 pyold = py;
310 if (ipoint < 0) return;
311 if (ipoint == 0) {
312 px1old = 0;
313 py1old = 0;
314 px2old = gPad->XtoAbsPixel(fX[1]);
315 py2old = gPad->YtoAbsPixel(fY[1]);
316 } else if (ipoint == fN-1) {
317 px1old = gPad->XtoAbsPixel(gPad->XtoPad(fX[fN-2]));
318 py1old = gPad->YtoAbsPixel(gPad->YtoPad(fY[fN-2]));
319 px2old = 0;
320 py2old = 0;
321 } else {
322 px1old = gPad->XtoAbsPixel(gPad->XtoPad(fX[ipoint-1]));
323 py1old = gPad->YtoAbsPixel(gPad->YtoPad(fY[ipoint-1]));
324 px2old = gPad->XtoAbsPixel(gPad->XtoPad(fX[ipoint+1]));
325 py2old = gPad->YtoAbsPixel(gPad->YtoPad(fY[ipoint+1]));
326 }
327 pxold = gPad->XtoAbsPixel(gPad->XtoPad(fX[ipoint]));
328 pyold = gPad->YtoAbsPixel(gPad->YtoPad(fY[ipoint]));
329
330 break;
331
332
333 case kMouseMotion:
334
335 middle = kTRUE;
336 for (i=0;i<np;i++) {
337 pxp = gPad->XtoAbsPixel(gPad->XtoPad(fX[i]));
338 pyp = gPad->YtoAbsPixel(gPad->YtoPad(fY[i]));
339 d = TMath::Abs(pxp-px) + TMath::Abs(pyp-py);
340 if (d < kMaxDiff) middle = kFALSE;
341 }
342
343
344 // check if point is close to an axis
345 if (middle) gPad->SetCursor(kMove);
346 else gPad->SetCursor(kHand);
347 break;
348
349 case kButton1Motion:
350 if (!opaque) {
351 if (middle) {
352 for(i=0;i<np-1;i++) {
353 gVirtualX->DrawLine(x[i]+dpx, y[i]+dpy, x[i+1]+dpx, y[i+1]+dpy);
354 pxp = x[i]+dpx;
355 pyp = y[i]+dpy;
356 gVirtualX->DrawLine(pxp-4, pyp-4, pxp+4, pyp-4);
357 gVirtualX->DrawLine(pxp+4, pyp-4, pxp+4, pyp+4);
358 gVirtualX->DrawLine(pxp+4, pyp+4, pxp-4, pyp+4);
359 gVirtualX->DrawLine(pxp-4, pyp+4, pxp-4, pyp-4);
360 }
361 pxp = x[np-1]+dpx;
362 pyp = y[np-1]+dpy;
363 gVirtualX->DrawLine(pxp-4, pyp-4, pxp+4, pyp-4);
364 gVirtualX->DrawLine(pxp+4, pyp-4, pxp+4, pyp+4);
365 gVirtualX->DrawLine(pxp+4, pyp+4, pxp-4, pyp+4);
366 gVirtualX->DrawLine(pxp-4, pyp+4, pxp-4, pyp-4);
367 dpx += px - pxold;
368 dpy += py - pyold;
369 pxold = px;
370 pyold = py;
371 for(i=0;i<np-1;i++) {
372 gVirtualX->DrawLine(x[i]+dpx, y[i]+dpy, x[i+1]+dpx, y[i+1]+dpy);
373 pxp = x[i]+dpx;
374 pyp = y[i]+dpy;
375 gVirtualX->DrawLine(pxp-4, pyp-4, pxp+4, pyp-4);
376 gVirtualX->DrawLine(pxp+4, pyp-4, pxp+4, pyp+4);
377 gVirtualX->DrawLine(pxp+4, pyp+4, pxp-4, pyp+4);
378 gVirtualX->DrawLine(pxp-4, pyp+4, pxp-4, pyp-4);
379 }
380 pxp = x[np-1]+dpx;
381 pyp = y[np-1]+dpy;
382 gVirtualX->DrawLine(pxp-4, pyp-4, pxp+4, pyp-4);
383 gVirtualX->DrawLine(pxp+4, pyp-4, pxp+4, pyp+4);
384 gVirtualX->DrawLine(pxp+4, pyp+4, pxp-4, pyp+4);
385 gVirtualX->DrawLine(pxp-4, pyp+4, pxp-4, pyp-4);
386 } else {
387 if (px1old) gVirtualX->DrawLine(px1old, py1old, pxold, pyold);
388 if (px2old) gVirtualX->DrawLine(pxold, pyold, px2old, py2old);
389 gVirtualX->DrawLine(pxold-4, pyold-4, pxold+4, pyold-4);
390 gVirtualX->DrawLine(pxold+4, pyold-4, pxold+4, pyold+4);
391 gVirtualX->DrawLine(pxold+4, pyold+4, pxold-4, pyold+4);
392 gVirtualX->DrawLine(pxold-4, pyold+4, pxold-4, pyold-4);
393 pxold = px;
394 pxold = TMath::Max(pxold, px1);
395 pxold = TMath::Min(pxold, px2);
396 pyold = py;
397 pyold = TMath::Max(pyold, py2);
398 pyold = TMath::Min(pyold, py1);
399 if (px1old) gVirtualX->DrawLine(px1old, py1old, pxold, pyold);
400 if (px2old) gVirtualX->DrawLine(pxold, pyold, px2old, py2old);
401 gVirtualX->DrawLine(pxold-4, pyold-4, pxold+4, pyold-4);
402 gVirtualX->DrawLine(pxold+4, pyold-4, pxold+4, pyold+4);
403 gVirtualX->DrawLine(pxold+4, pyold+4, pxold-4, pyold+4);
404 gVirtualX->DrawLine(pxold-4, pyold+4, pxold-4, pyold-4);
405 }
406 } else {
407 if (middle) {
408 for(i=0;i<np-1;i++) {
409 pxp = x[i]+dpx;
410 pyp = y[i]+dpy;
411 }
412 pxp = x[np-1]+dpx;
413 pyp = y[np-1]+dpy;
414 dpx += px - pxold;
415 dpy += py - pyold;
416 pxold = px;
417 pyold = py;
418 } else {
419 pxold = px;
420 pxold = TMath::Max(pxold, px1);
421 pxold = TMath::Min(pxold, px2);
422 pyold = py;
423 pyold = TMath::Max(pyold, py2);
424 pyold = TMath::Min(pyold, py1);
425 }
426 if (x && y) {
427 if (middle) {
428 for(i=0;i<np;i++) {
429 fX[i] = gPad->PadtoX(gPad->AbsPixeltoX(x[i]+dpx));
430 fY[i] = gPad->PadtoY(gPad->AbsPixeltoY(y[i]+dpy));
431 }
432 } else {
433 fX[ipoint] = gPad->PadtoX(gPad->AbsPixeltoX(pxold));
434 fY[ipoint] = gPad->PadtoY(gPad->AbsPixeltoY(pyold));
435 }
436 }
437 gPad->Modified(kTRUE);
438 }
439 break;
440
441 case kButton1Up:
442
443 // Compute x,y range
444 xmin = gPad->GetUxmin();
445 xmax = gPad->GetUxmax();
446 ymin = gPad->GetUymin();
447 ymax = gPad->GetUymax();
448 dx = xmax-xmin;
449 dy = ymax-ymin;
450 dxr = dx/(1 - gPad->GetLeftMargin() - gPad->GetRightMargin());
451 dyr = dy/(1 - gPad->GetBottomMargin() - gPad->GetTopMargin());
452
453 // Range() could change the size of the pad pixmap and therefore should
454 // be called before the other paint routines
455 gPad->Range(xmin - dxr*gPad->GetLeftMargin(),
456 ymin - dyr*gPad->GetBottomMargin(),
457 xmax + dxr*gPad->GetRightMargin(),
458 ymax + dyr*gPad->GetTopMargin());
459 gPad->RangeAxis(xmin, ymin, xmax, ymax);
460
461 if (x && y) {
462 if (middle) {
463 for(i=0;i<np;i++) {
464 fX[i] = gPad->PadtoX(gPad->AbsPixeltoX(x[i]+dpx));
465 fY[i] = gPad->PadtoY(gPad->AbsPixeltoY(y[i]+dpy));
466 }
467 } else {
468 fX[ipoint] = gPad->PadtoX(gPad->AbsPixeltoX(pxold));
469 fY[ipoint] = gPad->PadtoY(gPad->AbsPixeltoY(pyold));
470 }
471 delete [] x; x = 0;
472 delete [] y; y = 0;
473 }
474 gPad->Modified(kTRUE);
475 gVirtualX->SetLineColor(-1);
476 }
477}
478
479////////////////////////////////////////////////////////////////////////////////
480/// List this polyline with its attributes.
481/// The option string is ignored.
482
484{
486 printf("TPolyLine N=%d\n",fN);
487}
488
489////////////////////////////////////////////////////////////////////////////////
490/// Merge polylines in the collection in this polyline
491
493{
494 if (!li) return 0;
495 TIter next(li);
496
497 //first loop to count the number of entries
498 TPolyLine *pl;
499 Int_t npoints = 0;
500 while ((pl = (TPolyLine*)next())) {
501 if (!pl->InheritsFrom(TPolyLine::Class())) {
502 Error("Add","Attempt to add object of class: %s to a %s",pl->ClassName(),this->ClassName());
503 return -1;
504 }
505 npoints += pl->Size();
506 }
507
508 //extend this polyline to hold npoints
509 if (npoints > 1) SetPoint(npoints-1,0,0);
510
511 //merge all polylines
512 next.Reset();
513 while ((pl = (TPolyLine*)next())) {
514 Int_t np = pl->Size();
515 Double_t *x = pl->GetX();
516 Double_t *y = pl->GetY();
517 for (Int_t i=0;i<np;i++) {
518 SetPoint(i,x[i],y[i]);
519 }
520 }
521
522 return npoints;
523}
524
525////////////////////////////////////////////////////////////////////////////////
526/// Paint this polyline with its current attributes.
527
529{
530 if (TestBit(kPolyLineNDC)) {
531 if (strlen(option) > 0) PaintPolyLineNDC(fLastPoint+1, fX, fY, option);
533 } else {
534 if (strlen(option) > 0) PaintPolyLine(fLastPoint+1, fX, fY, option);
536 }
537}
538
539////////////////////////////////////////////////////////////////////////////////
540/// Draw this polyline with new coordinates.
541///
542/// If option = 'f' or 'F' the fill area is drawn.
543/// The default is to draw the lines only.
544
546{
547 if (!gPad) return;
548 if (n <= 0) return;
549 TAttLine::Modify(); //Change line attributes only if necessary
550 TAttFill::Modify(); //Change fill area attributes only if necessary
551 Double_t *xx = x;
552 Double_t *yy = y;
553 if (gPad->GetLogx()) {
554 xx = new Double_t[n];
555 for (Int_t ix=0;ix<n;ix++) xx[ix] = gPad->XtoPad(x[ix]);
556 }
557 if (gPad->GetLogy()) {
558 yy = new Double_t[n];
559 for (Int_t iy=0;iy<n;iy++) yy[iy] = gPad->YtoPad(y[iy]);
560 }
561 if (*option == 'f' || *option == 'F') gPad->PaintFillArea(n,xx,yy,option);
562 else gPad->PaintPolyLine(n,xx,yy,option);
563 if (x != xx) delete [] xx;
564 if (y != yy) delete [] yy;
565}
566
567////////////////////////////////////////////////////////////////////////////////
568/// Draw this polyline with new coordinates in NDC.
569
571{
572 TAttLine::Modify(); //Change line attributes only if necessary
573 TAttFill::Modify(); //Change fill area attributes only if necessary
574 if (*option == 'f' || *option == 'F') gPad->PaintFillAreaNDC(n,x,y,option);
575 else gPad->PaintPolyLineNDC(n,x,y,option);
576}
577
578////////////////////////////////////////////////////////////////////////////////
579/// Dump this polyline with its attributes.
580/// The option string is ignored.
581
583{
584 printf("PolyLine N=%d\n",fN);
585}
586
587////////////////////////////////////////////////////////////////////////////////
588/// Save primitive as a C++ statement(s) on output stream out
589
590void TPolyLine::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
591{
592 char quote = '"';
593 out<<" "<<std::endl;
594 if (gROOT->ClassSaved(TPolyLine::Class())) {
595 out<<" ";
596 } else {
597 out<<" Double_t *dum = 0;"<<std::endl;
598 out<<" TPolyLine *";
599 }
600 out<<"pline = new TPolyLine("<<fN<<",dum,dum,"<<quote<<fOption<<quote<<");"<<std::endl;
601
602 SaveFillAttributes(out,"pline",0,1001);
603 SaveLineAttributes(out,"pline",1,1,1);
604
605 for (Int_t i=0;i<Size();i++) {
606 out<<" pline->SetPoint("<<i<<","<<fX[i]<<","<<fY[i]<<");"<<std::endl;
607 }
608 out<<" pline->Draw("
609 <<quote<<option<<quote<<");"<<std::endl;
610}
611
612////////////////////////////////////////////////////////////////////////////////
613/// Set NDC mode on if isNDC = kTRUE, off otherwise
614
616{
618 if (isNDC) SetBit(kPolyLineNDC);
619}
620
621////////////////////////////////////////////////////////////////////////////////
622/// Set point following LastPoint to x, y.
623/// Returns index of the point (new last point).
624
626{
627 fLastPoint++;
629 return fLastPoint;
630}
631
632////////////////////////////////////////////////////////////////////////////////
633/// Set point number n to (x, y)
634/// If n is greater than the current size, the arrays are automatically
635/// extended.
636
638{
639 if (n < 0) return;
640 if (!fX || !fY || n >= fN) {
641 // re-allocate the object
642 Int_t newN = TMath::Max(2*fN,n+1);
643 Double_t *savex = new Double_t [newN];
644 Double_t *savey = new Double_t [newN];
645 if (fX && fN){
646 memcpy(savex,fX,fN*sizeof(Double_t));
647 memset(&savex[fN],0,(newN-fN)*sizeof(Double_t));
648 delete [] fX;
649 }
650 if (fY && fN){
651 memcpy(savey,fY,fN*sizeof(Double_t));
652 memset(&savey[fN],0,(newN-fN)*sizeof(Double_t));
653 delete [] fY;
654 }
655 fX = savex;
656 fY = savey;
657 fN = newN;
658 }
659 fX[n] = x;
660 fY[n] = y;
662}
663
664////////////////////////////////////////////////////////////////////////////////
665/// Resize this polyline to size n.
666/// If n <= 0 the current arrays of points are deleted.
667/// If n is greater than the current size, the new points are set to (0, 0)
668
670{
671 if (n <= 0) {
672 fN = 0;
673 fLastPoint = -1;
674 delete [] fX;
675 delete [] fY;
676 fX = fY = 0;
677 return;
678 }
679 if (n < fN) {
680 fN = n;
681 fLastPoint = n - 1;
682 } else {
683 SetPoint(n-1,0,0);
684 }
685}
686
687////////////////////////////////////////////////////////////////////////////////
688/// Set new values for this polyline (single precision).
689///
690/// If n <= 0 the current arrays of points are deleted.
691
693{
694 if (n <= 0) {
695 fN = 0;
696 fLastPoint = -1;
697 delete [] fX;
698 delete [] fY;
699 fX = fY = 0;
700 return;
701 }
702 fN =n;
703 if (fX) delete [] fX;
704 if (fY) delete [] fY;
705 fX = new Double_t[fN];
706 fY = new Double_t[fN];
707 for (Int_t i=0; i<fN;i++) {
708 if (x) fX[i] = (Double_t)x[i];
709 if (y) fY[i] = (Double_t)y[i];
710 }
711 fOption = option;
712 fLastPoint = fN-1;
713}
714
715////////////////////////////////////////////////////////////////////////////////
716/// Set new values for this polyline (double precision).
717///
718/// If n <= 0 the current arrays of points are deleted.
719
721{
722 if (n <= 0) {
723 fN = 0;
724 fLastPoint = -1;
725 delete [] fX;
726 delete [] fY;
727 fX = fY = 0;
728 return;
729 }
730 fN =n;
731 if (fX) delete [] fX;
732 if (fY) delete [] fY;
733 fX = new Double_t[fN];
734 fY = new Double_t[fN];
735 for (Int_t i=0; i<fN;i++) {
736 if (x) fX[i] = x[i];
737 if (y) fY[i] = y[i];
738 }
739 fOption = option;
740 fLastPoint = fN-1;
741}
742
743////////////////////////////////////////////////////////////////////////////////
744/// Stream a class object.
745
747{
748 if (b.IsReading()) {
749 UInt_t R__s, R__c;
750 Version_t R__v = b.ReadVersion(&R__s, &R__c);
751 if (R__v > 1) {
752 b.ReadClassBuffer(TPolyLine::Class(), this, R__v, R__s, R__c);
753 return;
754 }
755 //====process old versions before automatic schema evolution
759 b >> fN;
760 fX = new Double_t[fN];
761 fY = new Double_t[fN];
762 Float_t *x = new Float_t[fN];
763 Float_t *y = new Float_t[fN];
764 b.ReadFastArray(x,fN);
765 b.ReadFastArray(y,fN);
766 for (Int_t i=0;i<fN;i++) {
767 fX[i] = x[i];
768 fY[i] = y[i];
769 }
771 b.CheckByteCount(R__s, R__c, TPolyLine::IsA());
772 //====end of old versions
773
774 } else {
775 b.WriteClassBuffer(TPolyLine::Class(),this);
776 }
777}
@ kMouseMotion
Definition: Buttons.h:23
@ kButton1Motion
Definition: Buttons.h:20
@ kButton1Up
Definition: Buttons.h:19
@ kButton1Down
Definition: Buttons.h:17
@ kMove
Definition: GuiTypes.h:374
@ kHand
Definition: GuiTypes.h:374
#define d(i)
Definition: RSha256.hxx:102
short Version_t
Definition: RtypesCore.h:65
const Bool_t kFALSE
Definition: RtypesCore.h:101
float Float_t
Definition: RtypesCore.h:57
double Double_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:100
const char Option_t
Definition: RtypesCore.h:66
#define ClassImp(name)
Definition: Rtypes.h:375
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t b
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
float xmin
Definition: THbookFile.cxx:95
float ymin
Definition: THbookFile.cxx:95
float xmax
Definition: THbookFile.cxx:95
float ymax
Definition: THbookFile.cxx:95
#define gROOT
Definition: TROOT.h:404
#define gPad
Definition: TVirtualPad.h:288
#define gVirtualX
Definition: TVirtualX.h:338
Fill Area Attributes class.
Definition: TAttFill.h:19
virtual void Streamer(TBuffer &)
void Copy(TAttFill &attfill) const
Copy this fill attributes to a new TAttFill.
Definition: TAttFill.cxx:204
virtual void Modify()
Change current fill area attributes if necessary.
Definition: TAttFill.cxx:213
Style_t fFillStyle
Fill area style.
Definition: TAttFill.h:23
Color_t fFillColor
Fill area color.
Definition: TAttFill.h:22
virtual void SaveFillAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1001)
Save fill attributes as C++ statement(s) on output stream out.
Definition: TAttFill.cxx:236
Line Attributes class.
Definition: TAttLine.h:18
virtual void Streamer(TBuffer &)
virtual void Modify()
Change current line attributes if necessary.
Definition: TAttLine.cxx:245
void Copy(TAttLine &attline) const
Copy this line attributes to a new TAttLine.
Definition: TAttLine.cxx:175
Int_t DistancetoLine(Int_t px, Int_t py, Double_t xp1, Double_t yp1, Double_t xp2, Double_t yp2)
Compute distance from point px,py to a line.
Definition: TAttLine.cxx:209
virtual void SaveLineAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t widdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition: TAttLine.cxx:273
Buffer base class used for serializing objects.
Definition: TBuffer.h:43
Collection abstract base class.
Definition: TCollection.h:65
void Reset()
Definition: TCollection.h:254
Mother of all ROOT objects.
Definition: TObject.h:37
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:187
virtual void Streamer(TBuffer &)
Stream an object of class TObject.
Definition: TObject.cxx:806
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:130
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition: TObject.cxx:107
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:696
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:445
virtual void Copy(TObject &object) const
Copy this to obj.
Definition: TObject.cxx:63
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:893
void ResetBit(UInt_t f)
Definition: TObject.h:186
@ kCanDelete
if object in a list can be deleted
Definition: TObject.h:58
Defined by an array on N points in a 2-D space.
Definition: TPolyLine.h:23
TString fOption
options
Definition: TPolyLine.h:30
virtual Int_t Size() const
Definition: TPolyLine.h:71
Int_t fLastPoint
The index of the last filled point.
Definition: TPolyLine.h:27
virtual Int_t Merge(TCollection *list)
Merge polylines in the collection in this polyline.
Definition: TPolyLine.cxx:492
virtual void PaintPolyLineNDC(Int_t n, Double_t *x, Double_t *y, Option_t *option="")
Draw this polyline with new coordinates in NDC.
Definition: TPolyLine.cxx:570
void Copy(TObject &polyline) const override
Copy this polyline to polyline.
Definition: TPolyLine.cxx:157
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Returns closest distance in pixels from point (px, py) to a polyline.
Definition: TPolyLine.cxx:194
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
Definition: TPolyLine.cxx:590
Double_t * GetX() const
Definition: TPolyLine.h:54
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition: TPolyLine.cxx:258
virtual void SetPoint(Int_t point, Double_t x, Double_t y)
Set point number n to (x, y) If n is greater than the current size, the arrays are automatically exte...
Definition: TPolyLine.cxx:637
virtual ~TPolyLine()
PolyLine default destructor.
Definition: TPolyLine.cxx:136
TPolyLine()
PolyLine default constructor.
Definition: TPolyLine.cxx:46
TClass * IsA() const override
Definition: TPolyLine.h:73
Double_t * GetY() const
Definition: TPolyLine.h:55
virtual void PaintPolyLine(Int_t n, Double_t *x, Double_t *y, Option_t *option="")
Draw this polyline with new coordinates.
Definition: TPolyLine.cxx:545
void Draw(Option_t *option="") override
Draw this polyline with its current attributes.
Definition: TPolyLine.cxx:228
Double_t * fX
[fN] Array of X coordinates
Definition: TPolyLine.h:28
static TClass * Class()
void Paint(Option_t *option="") override
Paint this polyline with its current attributes.
Definition: TPolyLine.cxx:528
void ls(Option_t *option="") const override
List this polyline with its attributes.
Definition: TPolyLine.cxx:483
TPolyLine & operator=(const TPolyLine &)
assignment operator
Definition: TPolyLine.cxx:125
void Streamer(TBuffer &) override
Stream a class object.
Definition: TPolyLine.cxx:746
virtual TPolyLine * DrawPolyLine(Int_t n, Double_t *x, Double_t *y, Option_t *option="")
Draw this polyline with new coordinates.
Definition: TPolyLine.cxx:236
Int_t fN
Number of points.
Definition: TPolyLine.h:26
Double_t * fY
[fN] Array of Y coordinates
Definition: TPolyLine.h:29
virtual void SetPolyLine(Int_t n)
Resize this polyline to size n.
Definition: TPolyLine.cxx:669
@ kPolyLineNDC
Polyline coordinates are in NDC space.
Definition: TPolyLine.h:37
virtual void SetNDC(Bool_t isNDC=kTRUE)
Set NDC mode on if isNDC = kTRUE, off otherwise.
Definition: TPolyLine.cxx:615
virtual Int_t SetNextPoint(Double_t x, Double_t y)
Set point following LastPoint to x, y.
Definition: TPolyLine.cxx:625
void Print(Option_t *option="") const override
Dump this polyline with its attributes.
Definition: TPolyLine.cxx:582
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition: TROOT.cxx:2807
const char * Data() const
Definition: TString.h:369
virtual void Streamer(TBuffer &)
Stream a string object.
Definition: TString.cxx:1370
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:208
Bool_t IsInside(T xp, T yp, Int_t np, T *x, T *y)
Function which returns kTRUE if point xp,yp lies inside the polygon defined by the np points in array...
Definition: TMath.h:1159
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:176
Short_t Abs(Short_t d)
Definition: TMathBase.h:120