Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 <vector>
14#include "TROOT.h"
15#include "TBuffer.h"
16#include "TMath.h"
17#include "TVirtualPad.h"
18#include "TVirtualX.h"
19#include "TPolyLine.h"
20
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
49
50////////////////////////////////////////////////////////////////////////////////
51/// PolyLine normal constructor without initialisation.
52/// Allocates n points.
53
56{
58 if (n <= 0)
59 return;
60
61 fN = n;
62 fX = new Double_t[fN];
63 fY = new Double_t[fN];
64}
65
66////////////////////////////////////////////////////////////////////////////////
67/// PolyLine normal constructor (single precision).
68/// Makes n points with (x, y) coordinates from x and y.
69
72{
74 if (n <= 0)
75 return;
76
77 fN = n;
78 fX = new Double_t[fN];
79 fY = new Double_t[fN];
80 if (!x || !y) return;
81 for (Int_t i = 0; i < fN; i++) {
82 fX[i] = x[i];
83 fY[i] = y[i];
84 }
85 fLastPoint = fN-1;
86}
87
88////////////////////////////////////////////////////////////////////////////////
89/// PolyLine normal constructor (double precision).
90/// Makes n points with (x, y) coordinates from x and y.
91
94{
96 if (n <= 0)
97 return;
98 fN = n;
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++) {
103 fX[i] = x[i];
104 fY[i] = y[i];
105 }
106 fLastPoint = fN-1;
107}
108
109////////////////////////////////////////////////////////////////////////////////
110///assignment operator
111
113{
114 if(this != &pl)
115 pl.TPolyLine::Copy(*this);
116 return *this;
117}
118
119////////////////////////////////////////////////////////////////////////////////
120/// PolyLine default destructor.
121
123{
124 if (fX) delete [] fX;
125 if (fY) delete [] fY;
126}
127
128////////////////////////////////////////////////////////////////////////////////
129/// PolyLine copy constructor.
130
135
136////////////////////////////////////////////////////////////////////////////////
137/// Copy this polyline to polyline.
138
139void TPolyLine::Copy(TObject &obj) const
140{
141 TObject::Copy(obj);
142 TAttLine::Copy(((TPolyLine&)obj));
143 TAttFill::Copy(((TPolyLine&)obj));
144 ((TPolyLine&)obj).fN = fN;
145 delete [] ((TPolyLine&)obj).fX;
146 delete [] ((TPolyLine&)obj).fY;
147 if (fN > 0) {
148 ((TPolyLine&)obj).fX = new Double_t[fN];
149 ((TPolyLine&)obj).fY = new Double_t[fN];
150 for (Int_t i = 0; i < fN; i++) {
151 ((TPolyLine &)obj).fX[i] = fX[i];
152 ((TPolyLine &)obj).fY[i] = fY[i];
153 }
154 } else {
155 ((TPolyLine&)obj).fX = nullptr;
156 ((TPolyLine&)obj).fY = nullptr;
157 }
158 ((TPolyLine&)obj).fOption = fOption;
159 ((TPolyLine&)obj).fLastPoint = fLastPoint;
160}
161
162////////////////////////////////////////////////////////////////////////////////
163/// Returns closest distance in pixels from point (px, py) to a polyline.
164///
165/// First looks for distances to the points of the polyline. Stops search
166/// and returns if a vertex of the polyline is found to be closer than 10
167/// pixels. Thus the return value may depend on the ordering of points
168/// in the polyline.
169///
170/// Then looks for distances to the lines of the polyline. There is no
171/// arbitrary cutoff; any distance may be found.
172///
173/// Finally checks whether (px, py) is inside a closed and filled polyline.
174/// (Must be EXACTLY closed. "Filled" means fill color and fill style are
175/// both non-zero.) If so, returns zero.
176///
177/// Returns 9999 if the polyline has no points.
178
180{
181 const Int_t big = 9999;
182 if (!gPad) return big;
183 const Int_t kMaxDiff = 10;
184
185 // check if point is near one of the points
186 Int_t i, pxp, pyp, d;
188 if (Size() <= 0) return distance;
189
190 for (i=0;i<Size();i++) {
191 pxp = gPad->XtoAbsPixel(gPad->XtoPad(fX[i]));
192 pyp = gPad->YtoAbsPixel(gPad->YtoPad(fY[i]));
193 d = TMath::Abs(pxp-px) + TMath::Abs(pyp-py);
194 if (d < distance) distance = d;
195 }
196 if (distance < kMaxDiff) return distance;
197
198 // check if point is near one of the connecting lines
199 for (i=0;i<Size()-1;i++) {
200 d = DistancetoLine(px, py, gPad->XtoPad(fX[i]), gPad->YtoPad(fY[i]), gPad->XtoPad(fX[i+1]), gPad->YtoPad(fY[i+1]));
201 if (d < distance) distance = d;
202 }
203
204 // in case of a closed and filled polyline, check if we are inside
205 if (fFillColor && fFillStyle && fX[0] == fX[fLastPoint] && fY[0] == fY[fLastPoint]) {
206 if (TMath::IsInside(gPad->AbsPixeltoX(px),gPad->AbsPixeltoY(py),fLastPoint+1,fX,fY)) distance = 0;
207 }
208 return distance;
209}
210
211////////////////////////////////////////////////////////////////////////////////
212/// Draw this polyline with its current attributes.
213
218
219////////////////////////////////////////////////////////////////////////////////
220/// Draw this polyline with new coordinates.
221
232
233////////////////////////////////////////////////////////////////////////////////
234/// Execute action corresponding to one event.
235///
236/// This member function is called when a polyline is clicked with the locator
237///
238/// If Left button clicked on one of the line end points, this point
239/// follows the cursor until button is released.
240///
241/// if Middle button clicked, the line is moved parallel to itself
242/// until the button is released.
243
245{
246 if (!gPad) return;
247
248 Int_t i, d;
250 const Int_t kMaxDiff = 10;
251 static Bool_t middle;
252 static Int_t ipoint, pxp, pyp;
253 static Int_t px1,px2,py1,py2;
255 static Int_t dpx, dpy;
256 static std::vector<Int_t> x, y;
257 Bool_t opaque = gPad->OpaqueMoving();
258
259 if (!gPad->IsEditable()) return;
260
261 Int_t np = Size();
262
263 switch (event) {
264
265 case kButton1Down:
266 gVirtualX->SetLineColor(-1);
267 TAttLine::Modify(); //Change line attributes only if necessary
268 px1 = gPad->XtoAbsPixel(gPad->GetX1());
269 py1 = gPad->YtoAbsPixel(gPad->GetY1());
270 px2 = gPad->XtoAbsPixel(gPad->GetX2());
271 py2 = gPad->YtoAbsPixel(gPad->GetY2());
272 ipoint = -1;
273
274
275 if (!x.empty() || !y.empty()) break;
276 x.resize(np+1, 0);
277 y.resize(np+1, 0);
278 for (i=0;i<np;i++) {
279 pxp = gPad->XtoAbsPixel(gPad->XtoPad(fX[i]));
280 pyp = gPad->YtoAbsPixel(gPad->YtoPad(fY[i]));
281 if (!opaque) {
282 gVirtualX->DrawLine(pxp-4, pyp-4, pxp+4, pyp-4);
283 gVirtualX->DrawLine(pxp+4, pyp-4, pxp+4, pyp+4);
284 gVirtualX->DrawLine(pxp+4, pyp+4, pxp-4, pyp+4);
285 gVirtualX->DrawLine(pxp-4, pyp+4, pxp-4, pyp-4);
286 }
287 x[i] = pxp;
288 y[i] = pyp;
289 d = TMath::Abs(pxp-px) + TMath::Abs(pyp-py);
290 if (d < kMaxDiff) ipoint =i;
291 }
292 dpx = 0;
293 dpy = 0;
294 pxold = px;
295 pyold = py;
296 if (ipoint < 0) return;
297 if (ipoint == 0) {
298 px1old = 0;
299 py1old = 0;
300 px2old = gPad->XtoAbsPixel(fX[1]);
301 py2old = gPad->YtoAbsPixel(fY[1]);
302 } else if (ipoint == fN-1) {
303 px1old = gPad->XtoAbsPixel(gPad->XtoPad(fX[fN-2]));
304 py1old = gPad->YtoAbsPixel(gPad->YtoPad(fY[fN-2]));
305 px2old = 0;
306 py2old = 0;
307 } else {
308 px1old = gPad->XtoAbsPixel(gPad->XtoPad(fX[ipoint-1]));
309 py1old = gPad->YtoAbsPixel(gPad->YtoPad(fY[ipoint-1]));
310 px2old = gPad->XtoAbsPixel(gPad->XtoPad(fX[ipoint+1]));
311 py2old = gPad->YtoAbsPixel(gPad->YtoPad(fY[ipoint+1]));
312 }
313 pxold = gPad->XtoAbsPixel(gPad->XtoPad(fX[ipoint]));
314 pyold = gPad->YtoAbsPixel(gPad->YtoPad(fY[ipoint]));
315
316 break;
317
318
319 case kMouseMotion:
320
321 middle = kTRUE;
322 for (i=0;i<np;i++) {
323 pxp = gPad->XtoAbsPixel(gPad->XtoPad(fX[i]));
324 pyp = gPad->YtoAbsPixel(gPad->YtoPad(fY[i]));
325 d = TMath::Abs(pxp-px) + TMath::Abs(pyp-py);
326 if (d < kMaxDiff) middle = kFALSE;
327 }
328
329
330 // check if point is close to an axis
331 if (middle) gPad->SetCursor(kMove);
332 else gPad->SetCursor(kHand);
333 break;
334
335 case kButton1Motion:
336 if (!opaque) {
337 if (middle) {
338 for(i=0;i<np-1;i++) {
339 gVirtualX->DrawLine(x[i]+dpx, y[i]+dpy, x[i+1]+dpx, y[i+1]+dpy);
340 pxp = x[i]+dpx;
341 pyp = y[i]+dpy;
342 gVirtualX->DrawLine(pxp-4, pyp-4, pxp+4, pyp-4);
343 gVirtualX->DrawLine(pxp+4, pyp-4, pxp+4, pyp+4);
344 gVirtualX->DrawLine(pxp+4, pyp+4, pxp-4, pyp+4);
345 gVirtualX->DrawLine(pxp-4, pyp+4, pxp-4, pyp-4);
346 }
347 pxp = x[np-1]+dpx;
348 pyp = y[np-1]+dpy;
349 gVirtualX->DrawLine(pxp-4, pyp-4, pxp+4, pyp-4);
350 gVirtualX->DrawLine(pxp+4, pyp-4, pxp+4, pyp+4);
351 gVirtualX->DrawLine(pxp+4, pyp+4, pxp-4, pyp+4);
352 gVirtualX->DrawLine(pxp-4, pyp+4, pxp-4, pyp-4);
353 dpx += px - pxold;
354 dpy += py - pyold;
355 pxold = px;
356 pyold = py;
357 for(i=0;i<np-1;i++) {
358 gVirtualX->DrawLine(x[i]+dpx, y[i]+dpy, x[i+1]+dpx, y[i+1]+dpy);
359 pxp = x[i]+dpx;
360 pyp = y[i]+dpy;
361 gVirtualX->DrawLine(pxp-4, pyp-4, pxp+4, pyp-4);
362 gVirtualX->DrawLine(pxp+4, pyp-4, pxp+4, pyp+4);
363 gVirtualX->DrawLine(pxp+4, pyp+4, pxp-4, pyp+4);
364 gVirtualX->DrawLine(pxp-4, pyp+4, pxp-4, pyp-4);
365 }
366 pxp = x[np-1]+dpx;
367 pyp = y[np-1]+dpy;
368 gVirtualX->DrawLine(pxp-4, pyp-4, pxp+4, pyp-4);
369 gVirtualX->DrawLine(pxp+4, pyp-4, pxp+4, pyp+4);
370 gVirtualX->DrawLine(pxp+4, pyp+4, pxp-4, pyp+4);
371 gVirtualX->DrawLine(pxp-4, pyp+4, pxp-4, pyp-4);
372 } else {
373 if (px1old) gVirtualX->DrawLine(px1old, py1old, pxold, pyold);
374 if (px2old) gVirtualX->DrawLine(pxold, pyold, px2old, py2old);
375 gVirtualX->DrawLine(pxold-4, pyold-4, pxold+4, pyold-4);
376 gVirtualX->DrawLine(pxold+4, pyold-4, pxold+4, pyold+4);
377 gVirtualX->DrawLine(pxold+4, pyold+4, pxold-4, pyold+4);
378 gVirtualX->DrawLine(pxold-4, pyold+4, pxold-4, pyold-4);
379 pxold = px;
380 pxold = TMath::Max(pxold, px1);
381 pxold = TMath::Min(pxold, px2);
382 pyold = py;
383 pyold = TMath::Max(pyold, py2);
384 pyold = TMath::Min(pyold, py1);
385 if (px1old) gVirtualX->DrawLine(px1old, py1old, pxold, pyold);
386 if (px2old) gVirtualX->DrawLine(pxold, pyold, px2old, py2old);
387 gVirtualX->DrawLine(pxold-4, pyold-4, pxold+4, pyold-4);
388 gVirtualX->DrawLine(pxold+4, pyold-4, pxold+4, pyold+4);
389 gVirtualX->DrawLine(pxold+4, pyold+4, pxold-4, pyold+4);
390 gVirtualX->DrawLine(pxold-4, pyold+4, pxold-4, pyold-4);
391 }
392 } else {
393 if (middle) {
394 for(i=0;i<np-1;i++) {
395 pxp = x[i]+dpx;
396 pyp = y[i]+dpy;
397 }
398 pxp = x[np-1]+dpx;
399 pyp = y[np-1]+dpy;
400 dpx += px - pxold;
401 dpy += py - pyold;
402 pxold = px;
403 pyold = py;
404 } else {
405 pxold = px;
406 pxold = TMath::Max(pxold, px1);
407 pxold = TMath::Min(pxold, px2);
408 pyold = py;
409 pyold = TMath::Max(pyold, py2);
410 pyold = TMath::Min(pyold, py1);
411 }
412 if (!x.empty() && !y.empty()) {
413 if (middle) {
414 for(i=0;i<np;i++) {
415 fX[i] = gPad->PadtoX(gPad->AbsPixeltoX(x[i]+dpx));
416 fY[i] = gPad->PadtoY(gPad->AbsPixeltoY(y[i]+dpy));
417 }
418 } else {
419 fX[ipoint] = gPad->PadtoX(gPad->AbsPixeltoX(pxold));
420 fY[ipoint] = gPad->PadtoY(gPad->AbsPixeltoY(pyold));
421 }
422 }
423 gPad->Modified(kTRUE);
424 }
425 break;
426
427 case kButton1Up:
428
429 // Compute x,y range
430 xmin = gPad->GetUxmin();
431 xmax = gPad->GetUxmax();
432 ymin = gPad->GetUymin();
433 ymax = gPad->GetUymax();
434 dx = xmax-xmin;
435 dy = ymax-ymin;
436 dxr = dx/(1 - gPad->GetLeftMargin() - gPad->GetRightMargin());
437 dyr = dy/(1 - gPad->GetBottomMargin() - gPad->GetTopMargin());
438
439 // Range() could change the size of the pad pixmap and therefore should
440 // be called before the other paint routines
441 gPad->Range(xmin - dxr*gPad->GetLeftMargin(),
442 ymin - dyr*gPad->GetBottomMargin(),
443 xmax + dxr*gPad->GetRightMargin(),
444 ymax + dyr*gPad->GetTopMargin());
445 gPad->RangeAxis(xmin, ymin, xmax, ymax);
446
447 if (!x.empty() && !y.empty()) {
448 if (middle) {
449 for(i=0;i<np;i++) {
450 fX[i] = gPad->PadtoX(gPad->AbsPixeltoX(x[i]+dpx));
451 fY[i] = gPad->PadtoY(gPad->AbsPixeltoY(y[i]+dpy));
452 }
453 } else {
454 fX[ipoint] = gPad->PadtoX(gPad->AbsPixeltoX(pxold));
455 fY[ipoint] = gPad->PadtoY(gPad->AbsPixeltoY(pyold));
456 }
457 x.clear();
458 y.clear();
459 }
460 gPad->Modified(kTRUE);
461 gVirtualX->SetLineColor(-1);
462 }
463}
464
465////////////////////////////////////////////////////////////////////////////////
466/// List this polyline with its attributes.
467/// The option string is ignored.
468
470{
472 printf("TPolyLine N=%d\n",fN);
473}
474
475////////////////////////////////////////////////////////////////////////////////
476/// Merge polylines in the collection in this polyline
477
479{
480 if (!li) return 0;
481 TIter next(li);
482
483 //first loop to count the number of entries
484 TPolyLine *pl;
485 Int_t npoints = 0;
486 while ((pl = (TPolyLine*)next())) {
487 if (!pl->InheritsFrom(TPolyLine::Class())) {
488 Error("Add","Attempt to add object of class: %s to a %s",pl->ClassName(),this->ClassName());
489 return -1;
490 }
491 npoints += pl->Size();
492 }
493
494 //extend this polyline to hold npoints
495 if (npoints > 1) SetPoint(npoints-1,0,0);
496
497 //merge all polylines
498 next.Reset();
499 while ((pl = (TPolyLine*)next())) {
500 Int_t np = pl->Size();
501 Double_t *x = pl->GetX();
502 Double_t *y = pl->GetY();
503 for (Int_t i=0;i<np;i++) {
504 SetPoint(i,x[i],y[i]);
505 }
506 }
507
508 return npoints;
509}
510
511////////////////////////////////////////////////////////////////////////////////
512/// Paint this polyline with its current attributes.
513
524
525////////////////////////////////////////////////////////////////////////////////
526/// Draw this polyline with new coordinates.
527///
528/// If option = 'f' or 'F' the fill area is drawn.
529/// The default is to draw the lines only.
530
532{
533 if (!gPad || n <= 0) return;
534 TAttLine::Modify(); //Change line attributes only if necessary
535 TAttFill::Modify(); //Change fill area attributes only if necessary
536 Double_t *xx = x;
537 Double_t *yy = y;
538 if (gPad->GetLogx()) {
539 xx = new Double_t[n];
540 for (Int_t ix=0;ix<n;ix++) xx[ix] = gPad->XtoPad(x[ix]);
541 }
542 if (gPad->GetLogy()) {
543 yy = new Double_t[n];
544 for (Int_t iy=0;iy<n;iy++) yy[iy] = gPad->YtoPad(y[iy]);
545 }
546 if (option && (*option == 'f' || *option == 'F'))
547 gPad->PaintFillArea(n, xx, yy, option);
548 else
549 gPad->PaintPolyLine(n, xx, yy, option);
550 if (x != xx)
551 delete[] xx;
552 if (y != yy)
553 delete[] yy;
554}
555
556////////////////////////////////////////////////////////////////////////////////
557/// Draw this polyline with new coordinates in NDC.
558
560{
561 TAttLine::Modify(); //Change line attributes only if necessary
562 TAttFill::Modify(); //Change fill area attributes only if necessary
563 if (*option == 'f' || *option == 'F') gPad->PaintFillAreaNDC(n,x,y,option);
564 else gPad->PaintPolyLineNDC(n,x,y,option);
565}
566
567////////////////////////////////////////////////////////////////////////////////
568/// Dump this polyline with its attributes.
569/// The option string is ignored.
570
572{
573 printf("PolyLine N=%d\n",fN);
574}
575
576////////////////////////////////////////////////////////////////////////////////
577/// Save primitive as a C++ statement(s) on output stream out
578
579void TPolyLine::SavePrimitive(std::ostream &out, Option_t *option)
580{
581 TString args;
582 if (Size() > 0) {
583 TString arrx = SavePrimitiveVector(out, "polyline", Size(), fX, kTRUE);
584 TString arry = SavePrimitiveVector(out, "polyline", Size(), fY);
585 args.Form("%d, %s.data(), %s.data(), ", Size(), arrx.Data(), arry.Data());
586 } else {
587 args.Form("%d, ", fN);
588 }
589 args.Append(TString::Format("\"%s\"", TString(fOption).ReplaceSpecialCppChars().Data()));
590
591 SavePrimitiveConstructor(out, Class(), "polyline", args, Size() == 0);
592 SaveFillAttributes(out, "polyline", 0, 1001);
593 SaveLineAttributes(out, "polyline", 1, 1, 1);
594
595 if (!option || !strstr(option, "nodraw"))
596 out << " polyline->Draw(\"" << TString(option).ReplaceSpecialCppChars() << "\");\n";
597}
598
599////////////////////////////////////////////////////////////////////////////////
600/// Set NDC mode on if isNDC = kTRUE, off otherwise
601
607
608////////////////////////////////////////////////////////////////////////////////
609/// Set point following LastPoint to x, y.
610/// Returns index of the point (new last point).
611
618
619////////////////////////////////////////////////////////////////////////////////
620/// Set point number n to (x, y)
621/// If n is greater than the current size, the arrays are automatically
622/// extended.
623
625{
626 if (n < 0) return;
627 if (!fX || !fY || n >= fN) {
628 // re-allocate the object
629 Int_t newN = TMath::Max(2*fN,n+1);
630 Double_t *savex = new Double_t [newN];
631 Double_t *savey = new Double_t [newN];
632 if (fX && fN){
633 memcpy(savex,fX,fN*sizeof(Double_t));
634 memset(&savex[fN],0,(newN-fN)*sizeof(Double_t));
635 delete [] fX;
636 }
637 if (fY && fN){
638 memcpy(savey,fY,fN*sizeof(Double_t));
639 memset(&savey[fN],0,(newN-fN)*sizeof(Double_t));
640 delete [] fY;
641 }
642 fX = savex;
643 fY = savey;
644 fN = newN;
645 }
646 fX[n] = x;
647 fY[n] = y;
649}
650
651////////////////////////////////////////////////////////////////////////////////
652/// Resize this polyline to size n.
653/// If n <= 0 the current arrays of points are deleted.
654/// If n is greater than the current size, the new points are set to (0, 0)
655
657{
658 if (n <= 0) {
659 fN = 0;
660 fLastPoint = -1;
661 delete [] fX;
662 delete [] fY;
663 fX = fY = nullptr;
664 return;
665 }
666 if (n < fN) {
667 fN = n;
668 fLastPoint = n - 1;
669 } else {
670 SetPoint(n-1,0,0);
671 }
672}
673
674////////////////////////////////////////////////////////////////////////////////
675/// Set new values for this polyline (single precision).
676///
677/// If n <= 0 the current arrays of points are deleted.
678
680{
681 if (n <= 0) {
682 fN = 0;
683 fLastPoint = -1;
684 delete [] fX;
685 delete [] fY;
686 fX = fY = nullptr;
687 return;
688 }
689 fN =n;
690 if (fX) delete [] fX;
691 if (fY) delete [] fY;
692 fX = new Double_t[fN];
693 fY = new Double_t[fN];
694 for (Int_t i=0; i<fN;i++) {
695 if (x) fX[i] = (Double_t)x[i];
696 if (y) fY[i] = (Double_t)y[i];
697 }
698 fOption = option;
699 fLastPoint = fN-1;
700}
701
702////////////////////////////////////////////////////////////////////////////////
703/// Set new values for this polyline (double precision).
704///
705/// If n <= 0 the current arrays of points are deleted.
706
708{
709 if (n <= 0) {
710 fN = 0;
711 fLastPoint = -1;
712 delete [] fX;
713 delete [] fY;
714 fX = fY = nullptr;
715 return;
716 }
717 fN =n;
718 if (fX) delete [] fX;
719 if (fY) delete [] fY;
720 fX = new Double_t[fN];
721 fY = new Double_t[fN];
722 for (Int_t i=0; i<fN;i++) {
723 if (x) fX[i] = x[i];
724 if (y) fY[i] = y[i];
725 }
726 fOption = option;
727 fLastPoint = fN-1;
728}
729
730////////////////////////////////////////////////////////////////////////////////
731/// Stream a class object.
732
734{
735 if (b.IsReading()) {
737 Version_t R__v = b.ReadVersion(&R__s, &R__c);
738 if (R__v > 1) {
739 b.ReadClassBuffer(TPolyLine::Class(), this, R__v, R__s, R__c);
740 return;
741 }
742 //====process old versions before automatic schema evolution
746 b >> fN;
747 fX = new Double_t[fN];
748 fY = new Double_t[fN];
749 Float_t *x = new Float_t[fN];
750 Float_t *y = new Float_t[fN];
751 b.ReadFastArray(x,fN);
752 b.ReadFastArray(y,fN);
753 for (Int_t i=0;i<fN;i++) {
754 fX[i] = x[i];
755 fY[i] = y[i];
756 }
758 b.CheckByteCount(R__s, R__c, TPolyLine::IsA());
759 //====end of old versions
760
761 delete [] x;
762 delete [] y;
763 } else {
764 b.WriteClassBuffer(TPolyLine::Class(),this);
765 }
766}
@ 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
#define b(i)
Definition RSha256.hxx:100
short Version_t
Class version identifier (short)
Definition RtypesCore.h:79
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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 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
float ymin
float xmax
float ymax
#define gPad
#define gVirtualX
Definition TVirtualX.h:337
Fill Area Attributes class.
Definition TAttFill.h:20
virtual void Streamer(TBuffer &)
void Copy(TAttFill &attfill) const
Copy this fill attributes to a new TAttFill.
Definition TAttFill.cxx:206
virtual void Modify()
Change current fill area attributes if necessary.
Definition TAttFill.cxx:215
Style_t fFillStyle
Fill area style.
Definition TAttFill.h:24
Color_t fFillColor
Fill area color.
Definition TAttFill.h:23
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:238
Line Attributes class.
Definition TAttLine.h:20
virtual void Streamer(TBuffer &)
virtual void Modify()
Change current line attributes if necessary.
Definition TAttLine.cxx:246
void Copy(TAttLine &attline) const
Copy this line attributes to a new TAttLine.
Definition TAttLine.cxx:176
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:210
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:274
Buffer base class used for serializing objects.
Definition TBuffer.h:43
Collection abstract base class.
Definition TCollection.h:65
void Reset()
Mother of all ROOT objects.
Definition TObject.h:41
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:202
static TString SavePrimitiveVector(std::ostream &out, const char *prefix, Int_t len, Double_t *arr, Bool_t empty_line=kFALSE)
Save array in the output stream "out" as vector.
Definition TObject.cxx:788
virtual void Streamer(TBuffer &)
Stream an object of class TObject.
Definition TObject.cxx:972
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:203
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:864
virtual void Copy(TObject &object) const
Copy this to obj.
Definition TObject.cxx:159
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
static void SavePrimitiveConstructor(std::ostream &out, TClass *cl, const char *variable_name, const char *constructor_agrs="", Bool_t empty_line=kTRUE)
Save object constructor in the output stream "out".
Definition TObject.cxx:771
void ResetBit(UInt_t f)
Definition TObject.h:201
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:68
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.
virtual void PaintPolyLineNDC(Int_t n, Double_t *x, Double_t *y, Option_t *option="")
Draw this polyline with new coordinates in NDC.
void Copy(TObject &polyline) const override
Copy this polyline to polyline.
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Returns closest distance in pixels from point (px, py) to a polyline.
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
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...
TPolyLine()
PolyLine default constructor.
Definition TPolyLine.cxx:46
TClass * IsA() const override
Definition TPolyLine.h:73
~TPolyLine() override
PolyLine default destructor.
virtual void PaintPolyLine(Int_t n, Double_t *x, Double_t *y, Option_t *option="")
Draw this polyline with new coordinates.
void Draw(Option_t *option="") override
Draw this polyline with its current attributes.
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.
void ls(Option_t *option="") const override
List this polyline with its attributes.
TPolyLine & operator=(const TPolyLine &)
assignment operator
void Streamer(TBuffer &) override
Stream a class object.
virtual TPolyLine * DrawPolyLine(Int_t n, Double_t *x, Double_t *y, Option_t *option="")
Draw this polyline with new coordinates.
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.
virtual void SetNDC(Bool_t isNDC=kTRUE)
Set NDC mode on if isNDC = kTRUE, off otherwise.
virtual Int_t SetNextPoint(Double_t x, Double_t y)
Set point following LastPoint to x, y.
void Print(Option_t *option="") const override
Dump this polyline with its attributes.
@ kPolyLineNDC
Polyline coordinates are in NDC space.
Definition TPolyLine.h:37
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition TROOT.cxx:2898
Basic string class.
Definition TString.h:138
TString & ReplaceSpecialCppChars()
Find special characters which are typically used in printf() calls and replace them by appropriate es...
Definition TString.cxx:1121
const char * Data() const
Definition TString.h:384
virtual void Streamer(TBuffer &)
Stream a string object.
Definition TString.cxx:1418
TString & Append(const char *cs)
Definition TString.h:580
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2384
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2362
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)
Returns the largest of a and b.
Definition TMathBase.h:251
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:1320
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:199
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:124