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