Logo ROOT  
Reference Guide
TEllipse.cxx
Go to the documentation of this file.
1// @(#)root/graf:$Id$
2// Author: Rene Brun 16/10/95
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 <stdlib.h>
13
14#include <iostream>
15#include "TROOT.h"
16#include "TBuffer.h"
17#include "TEllipse.h"
18#include "TVirtualPad.h"
19#include "TMath.h"
20#include "TPoint.h"
21#include "TVirtualX.h"
22
23
24const Double_t kPI = 3.14159265358979323846;
25
27
28/** \class TEllipse
29\ingroup BasicGraphics
30
31Draw Ellipses.
32
33The ellipse can be truncated and rotated. It is defined by its center `(x1,y1)`
34and two radius `r1` and `r2`.
35
36A minimum and maximum angle may be specified `(phimin, phimax)`.
37The ellipse may be rotated with an angle `theta`. All these
38angles are in degrees.
39The attributes of the outline line are given via `TAttLine`.
40The attributes of the fill area are given via `TAttFill`.
41The picture below illustrates different types of ellipses.
42
43When an ellipse sector only is drawn, the lines connecting the center
44of the ellipse to the edges are drawn by default. One can specify
45the drawing option "only" to not draw these lines or alternatively
46call the function `SetNoEdges()`. To remove completely the ellipse
47outline it is enough to specify 0 as line style.
48
49Begin_Macro(source)
50../../../tutorials/graphics/ellipse.C
51End_Macro
52*/
53
54////////////////////////////////////////////////////////////////////////////////
55/// Ellipse default constructor.
56
58{
59 fX1 = 0;
60 fY1 = 0;
61 fR1 = 1;
62 fR2 = 1;
63 fPhimin = 0;
64 fPhimax = 360;
65 fTheta = 0;
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// Ellipse normal constructor.
70
72 :TObject(), TAttLine(), TAttFill(0,1001)
73{
74 fX1 = x1;
75 fY1 = y1;
76 fR1 = r1;
77 fR2 = r2;
78 fPhimin = phimin;
79 fPhimax = phimax;
80 fTheta = theta;
81 if (r2 <= 0) fR2 = fR1;
82}
83
84////////////////////////////////////////////////////////////////////////////////
85/// Ellipse default destructor.
86
88{
89}
90
91////////////////////////////////////////////////////////////////////////////////
92/// Copy constructor.
93
94TEllipse::TEllipse(const TEllipse &ellipse) : TObject(ellipse), TAttLine(ellipse), TAttFill(ellipse), TAttBBox2D(ellipse)
95{
96 fX1 = 0;
97 fY1 = 0;
98 fR1 = 1;
99 fR2 = 1;
100 fPhimin = 0;
101 fPhimax = 360;
102 fTheta = 0;
103
104 ellipse.TEllipse::Copy(*this);
105}
106
107////////////////////////////////////////////////////////////////////////////////
108/// Copy this ellipse to ellipse.
109
110void TEllipse::Copy(TObject &obj) const
111{
112 TObject::Copy(obj);
113 TAttLine::Copy(((TEllipse&)obj));
114 TAttFill::Copy(((TEllipse&)obj));
115 ((TEllipse&)obj).fX1 = fX1;
116 ((TEllipse&)obj).fY1 = fY1;
117 ((TEllipse&)obj).fR1 = fR1;
118 ((TEllipse&)obj).fR2 = fR2;
119 ((TEllipse&)obj).fPhimin = fPhimin;
120 ((TEllipse&)obj).fPhimax = fPhimax;
121 ((TEllipse&)obj).fTheta = fTheta;
122}
123
124////////////////////////////////////////////////////////////////////////////////
125/// Compute distance from point px,py to an ellipse.
126///
127/// Compute the closest distance of approach from point px,py to this
128/// ellipse. The distance is computed in pixels units.
129///
130/// In case of a filled ellipse the distance returned is 0 if the point
131/// (px,py) is inside the ellipse, and is huge if the point is outside.
132
134{
135 Double_t x = gPad->PadtoX(gPad->AbsPixeltoX(px));
136 Double_t y = gPad->PadtoY(gPad->AbsPixeltoY(py));
137
138 Double_t dxnr = x - fX1;
139 Double_t dynr = y - fY1;
140
141 Double_t ct = TMath::Cos(kPI*GetTheta()/180.0);
142 Double_t st = TMath::Sin(kPI*GetTheta()/180.0);
143
144 Double_t dx = dxnr*ct + dynr*st;
145 Double_t dy = -dxnr*st + dynr*ct;
146
147 Double_t r1 = fR1;
148 Double_t r2 = fR2;
149
150 if (dx == 0 || r1 == 0 || r2 == 0) return 9999;
151 Double_t distp = TMath::Sqrt(dx*dx + dy*dy);
152
153 Double_t tana = dy/dx;
154 tana *= tana;
155 Double_t distr = TMath::Sqrt((1+tana)/(1.0/(r1*r1) + tana/(r2*r2)));
156 Int_t dist = 9999;
157 if (GetFillColor() && GetFillStyle()) {
158 if (distr > distp) dist = 0;
159 } else {
160 if (TMath::Abs(distr-distp)/(r1+r2) < 0.01) dist = 0;
161 }
162 return dist;
163}
164
165////////////////////////////////////////////////////////////////////////////////
166/// Draw this ellipse with its current attributes.
167
169{
171}
172
173////////////////////////////////////////////////////////////////////////////////
174/// Draw this ellipse with new coordinates.
175
177{
178 TEllipse *newellipse = new TEllipse(x1, y1, r1, r2, phimin, phimax,theta);
179 TAttLine::Copy(*newellipse);
180 TAttFill::Copy(*newellipse);
181 newellipse->SetBit(kCanDelete);
182 newellipse->AppendPad(option);
183 if (TestBit(kNoEdges)) newellipse->SetBit(kNoEdges);
184 return newellipse;
185}
186
187////////////////////////////////////////////////////////////////////////////////
188/// Execute action corresponding to one event.
189///
190/// This member function is called when a line is clicked with the locator
191///
192/// If Left button clicked on one of the line end points, this point
193/// follows the cursor until button is released.
194///
195/// if Middle button clicked, the line is moved parallel to itself
196/// until the button is released.
197///
198/// NOTE that support for log scale is not implemented
199
201{
202 if (!gPad) return;
203
204 Int_t kMaxDiff = 10;
205
206 Int_t i, dpx, dpy;
207 Double_t angle,dx,dy,dphi,ct,st,fTy,fBy,fLx,fRx;
208 static Int_t px1,py1,npe,r1,r2,sav1,sav2;
209 const Int_t kMinSize = 25;
210 const Int_t np = 40;
211 static Bool_t pTop, pL, pR, pBot, pINSIDE;
212 static Int_t pTx,pTy,pLx,pLy,pRx,pRy,pBx,pBy;
213 static Int_t x[np+2], y[np+2];
214 static Int_t pxold, pyold;
215 static Int_t sig,impair;
216 static Double_t sdx, sdy;
217 static Double_t oldX1, oldY1, oldR1, oldR2;
218
219 Bool_t opaque = gPad->OpaqueMoving();
220
221 if (!gPad->IsEditable()) return;
222
223 switch (event) {
224
225 case kArrowKeyPress:
226 case kButton1Down:
227 oldX1 = fX1;
228 oldY1 = fY1;
229 oldR1 = fR1;
230 oldR2 = fR2;
231 dphi = (fPhimax-fPhimin)*kPI/(180*np);
232 ct = TMath::Cos(kPI*fTheta/180);
233 st = TMath::Sin(kPI*fTheta/180);
234 for (i=0;i<np;i++) {
235 angle = fPhimin*kPI/180 + Double_t(i)*dphi;
236 dx = fR1*TMath::Cos(angle);
237 dy = fR2*TMath::Sin(angle);
238 x[i] = gPad->XtoAbsPixel(fX1 + dx*ct - dy*st);
239 y[i] = gPad->YtoAbsPixel(fY1 + dx*st + dy*ct);
240 }
241 if (fPhimax-fPhimin >= 360 ) {
242 x[np] = x[0];
243 y[np] = y[0];
244 npe = np;
245 } else {
246 x[np] = gPad->XtoAbsPixel(fX1);
247 y[np] = gPad->YtoAbsPixel(fY1);
248 x[np+1] = x[0];
249 y[np+1] = y[0];
250 npe = np + 1;
251 }
252 impair = 0;
253 px1 = gPad->XtoAbsPixel(fX1);
254 py1 = gPad->YtoAbsPixel(fY1);
255 pTx = pBx = px1;
256 pLy = pRy = py1;
257 pTy = gPad->YtoAbsPixel(fR2+fY1);
258 pBy = gPad->YtoAbsPixel(-fR2+fY1);
259 pLx = gPad->XtoAbsPixel(-fR1+fX1);
260 pRx = gPad->XtoAbsPixel(fR1+fX1);
261 r2 = (pBy-pTy)/2;
262 r1 = (pRx-pLx)/2;
263 if (!opaque) {
264 gVirtualX->SetLineColor(-1);
266 gVirtualX->DrawLine(pRx+4, py1+4, pRx-4, py1+4);
267 gVirtualX->DrawLine(pRx-4, py1+4, pRx-4, py1-4);
268 gVirtualX->DrawLine(pRx-4, py1-4, pRx+4, py1-4);
269 gVirtualX->DrawLine(pRx+4, py1-4, pRx+4, py1+4);
270 gVirtualX->DrawLine(pLx+4, py1+4, pLx-4, py1+4);
271 gVirtualX->DrawLine(pLx-4, py1+4, pLx-4, py1-4);
272 gVirtualX->DrawLine(pLx-4, py1-4, pLx+4, py1-4);
273 gVirtualX->DrawLine(pLx+4, py1-4, pLx+4, py1+4);
274 gVirtualX->DrawLine(px1+4, pBy+4, px1-4, pBy+4);
275 gVirtualX->DrawLine(px1-4, pBy+4, px1-4, pBy-4);
276 gVirtualX->DrawLine(px1-4, pBy-4, px1+4, pBy-4);
277 gVirtualX->DrawLine(px1+4, pBy-4, px1+4, pBy+4);
278 gVirtualX->DrawLine(px1+4, pTy+4, px1-4, pTy+4);
279 gVirtualX->DrawLine(px1-4, pTy+4, px1-4, pTy-4);
280 gVirtualX->DrawLine(px1-4, pTy-4, px1+4, pTy-4);
281 gVirtualX->DrawLine(px1+4, pTy-4, px1+4, pTy+4);
282 }
283 else {
284 sdx = this->GetX1()-gPad->AbsPixeltoX(px);
285 sdy = this->GetY1()-gPad->AbsPixeltoY(py);
286 }
287 // No break !!!
288
289 case kMouseMotion:
290 px1 = gPad->XtoAbsPixel(fX1);
291 py1 = gPad->YtoAbsPixel(fY1);
292 pTx = pBx = px1;
293 pLy = pRy = py1;
294 pTy = gPad->YtoAbsPixel(fR2+fY1);
295 pBy = gPad->YtoAbsPixel(-fR2+fY1);
296 pLx = gPad->XtoAbsPixel(-fR1+fX1);
297 pRx = gPad->XtoAbsPixel(fR1+fX1);
298 pTop = pL = pR = pBot = pINSIDE = kFALSE;
299 if ((TMath::Abs(px - pTx) < kMaxDiff) &&
300 (TMath::Abs(py - pTy) < kMaxDiff)) { // top edge
301 pTop = kTRUE;
302 gPad->SetCursor(kTopSide);
303 }
304 else
305 if ((TMath::Abs(px - pBx) < kMaxDiff) &&
306 (TMath::Abs(py - pBy) < kMaxDiff)) { // bottom edge
307 pBot = kTRUE;
308 gPad->SetCursor(kBottomSide);
309 }
310 else
311 if ((TMath::Abs(py - pLy) < kMaxDiff) &&
312 (TMath::Abs(px - pLx) < kMaxDiff)) { // left edge
313 pL = kTRUE;
314 gPad->SetCursor(kLeftSide);
315 }
316 else
317 if ((TMath::Abs(py - pRy) < kMaxDiff) &&
318 (TMath::Abs(px - pRx) < kMaxDiff)) { // right edge
319 pR = kTRUE;
320 gPad->SetCursor(kRightSide);
321 }
322 else {pINSIDE= kTRUE; gPad->SetCursor(kMove); }
323 pxold = px; pyold = py;
324
325 break;
326
327 case kArrowKeyRelease:
328 case kButton1Motion:
329 if (!opaque)
330 {
331 gVirtualX->DrawLine(pRx+4, py1+4, pRx-4, py1+4);
332 gVirtualX->DrawLine(pRx-4, py1+4, pRx-4, py1-4);
333 gVirtualX->DrawLine(pRx-4, py1-4, pRx+4, py1-4);
334 gVirtualX->DrawLine(pRx+4, py1-4, pRx+4, py1+4);
335 gVirtualX->DrawLine(pLx+4, py1+4, pLx-4, py1+4);
336 gVirtualX->DrawLine(pLx-4, py1+4, pLx-4, py1-4);
337 gVirtualX->DrawLine(pLx-4, py1-4, pLx+4, py1-4);
338 gVirtualX->DrawLine(pLx+4, py1-4, pLx+4, py1+4);
339 gVirtualX->DrawLine(px1+4, pBy+4, px1-4, pBy+4);
340 gVirtualX->DrawLine(px1-4, pBy+4, px1-4, pBy-4);
341 gVirtualX->DrawLine(px1-4, pBy-4, px1+4, pBy-4);
342 gVirtualX->DrawLine(px1+4, pBy-4, px1+4, pBy+4);
343 gVirtualX->DrawLine(px1+4, pTy+4, px1-4, pTy+4);
344 gVirtualX->DrawLine(px1-4, pTy+4, px1-4, pTy-4);
345 gVirtualX->DrawLine(px1-4, pTy-4, px1+4, pTy-4);
346 gVirtualX->DrawLine(px1+4, pTy-4, px1+4, pTy+4);
347 for (i=0;i<npe;i++) gVirtualX->DrawLine(x[i], y[i], x[i+1], y[i+1]);
348 }
349 if (pTop) {
350 sav1 = py1;
351 sav2 = r2;
352 py1 += (py - pyold)/2;
353 r2 -= (py - pyold)/2;
354 if (TMath::Abs(pyold-py)%2==1) impair++;
355 if (py-pyold>0) sig=+1;
356 else sig=-1;
357 if (impair==2) { impair = 0; py1 += sig; r2 -= sig;}
358 if (py1 > pBy-kMinSize) {py1 = sav1; r2 = sav2; py = pyold;}
359 }
360 if (pBot) {
361 sav1 = py1;
362 sav2 = r2;
363 py1 += (py - pyold)/2;
364 r2 += (py - pyold)/2;
365 if (TMath::Abs(pyold-py)%2==1) impair++;
366 if (py-pyold>0) sig=+1;
367 else sig=-1;
368 if (impair==2) { impair = 0; py1 += sig; r2 += sig;}
369 if (py1 < pTy+kMinSize) {py1 = sav1; r2 = sav2; py = pyold;}
370 }
371 if (pL) {
372 sav1 = px1;
373 sav2 = r1;
374 px1 += (px - pxold)/2;
375 r1 -= (px - pxold)/2;
376 if (TMath::Abs(pxold-px)%2==1) impair++;
377 if (px-pxold>0) sig=+1;
378 else sig=-1;
379 if (impair==2) { impair = 0; px1 += sig; r1 -= sig;}
380 if (px1 > pRx-kMinSize) {px1 = sav1; r1 = sav2; px = pxold;}
381 }
382 if (pR) {
383 sav1 = px1;
384 sav2 = r1;
385 px1 += (px - pxold)/2;
386 r1 += (px - pxold)/2;
387 if (TMath::Abs(pxold-px)%2==1) impair++;
388 if (px-pxold>0) sig=+1;
389 else sig=-1;
390 if (impair==2) { impair = 0; px1 += sig; r1 += sig;}
391 if (px1 < pLx+kMinSize) {px1 = sav1; r1 = sav2; px = pxold;}
392 }
393 if (pTop || pBot || pL || pR) {
394 if (!opaque) {
395 dphi = (fPhimax-fPhimin)*kPI/(180*np);
396 ct = TMath::Cos(kPI*fTheta/180);
397 st = TMath::Sin(kPI*fTheta/180);
398 for (i=0;i<np;i++) {
399 angle = fPhimin*kPI/180 + Double_t(i)*dphi;
400 dx = r1*TMath::Cos(angle);
401 dy = r2*TMath::Sin(angle);
402 x[i] = px1 + Int_t(dx*ct - dy*st);
403 y[i] = py1 + Int_t(dx*st + dy*ct);
404 }
405 if (fPhimax-fPhimin >= 360 ) {
406 x[np] = x[0];
407 y[np] = y[0];
408 npe = np;
409 } else {
410 x[np] = px1;
411 y[np] = py1;
412 x[np+1] = x[0];
413 y[np+1] = y[0];
414 npe = np + 1;
415 }
416 gVirtualX->SetLineColor(-1);
418 for (i=0;i<npe;i++)
419 gVirtualX->DrawLine(x[i], y[i], x[i+1], y[i+1]);
420 }
421 else
422 {
423 this->SetX1(gPad->AbsPixeltoX(px1));
424 this->SetY1(gPad->AbsPixeltoY(py1));
425 this->SetR1(TMath::Abs(gPad->AbsPixeltoX(px1-r1)-gPad->AbsPixeltoX(px1+r1))/2);
426 this->SetR2(TMath::Abs(gPad->AbsPixeltoY(py1-r2)-gPad->AbsPixeltoY(py1+r2))/2);
427 if (pTop) gPad->ShowGuidelines(this, event, 't', true);
428 if (pBot) gPad->ShowGuidelines(this, event, 'b', true);
429 if (pL) gPad->ShowGuidelines(this, event, 'l', true);
430 if (pR) gPad->ShowGuidelines(this, event, 'r', true);
431 gPad->Modified(kTRUE);
432 gPad->Update();
433 }
434 }
435 if (pINSIDE) {
436 if (!opaque){
437 dpx = px-pxold; dpy = py-pyold;
438 px1 += dpx; py1 += dpy;
439 for (i=0;i<=npe;i++) { x[i] += dpx; y[i] += dpy;}
440 for (i=0;i<npe;i++) gVirtualX->DrawLine(x[i], y[i], x[i+1], y[i+1]);
441 }
442 else {
443 this->SetX1(gPad->AbsPixeltoX(px)+sdx);
444 this->SetY1(gPad->AbsPixeltoY(py)+sdy);
445 gPad->ShowGuidelines(this, event, 'i', true);
446 gPad->Modified(kTRUE);
447 gPad->Update();
448 }
449 }
450 if (!opaque){
451 pTx = pBx = px1;
452 pRx = px1+r1;
453 pLx = px1-r1;
454 pRy = pLy = py1;
455 pTy = py1-r2;
456 pBy = py1+r2;
457 gVirtualX->DrawLine(pRx+4, py1+4, pRx-4, py1+4);
458 gVirtualX->DrawLine(pRx-4, py1+4, pRx-4, py1-4);
459 gVirtualX->DrawLine(pRx-4, py1-4, pRx+4, py1-4);
460 gVirtualX->DrawLine(pRx+4, py1-4, pRx+4, py1+4);
461 gVirtualX->DrawLine(pLx+4, py1+4, pLx-4, py1+4);
462 gVirtualX->DrawLine(pLx-4, py1+4, pLx-4, py1-4);
463 gVirtualX->DrawLine(pLx-4, py1-4, pLx+4, py1-4);
464 gVirtualX->DrawLine(pLx+4, py1-4, pLx+4, py1+4);
465 gVirtualX->DrawLine(px1+4, pBy+4, px1-4, pBy+4);
466 gVirtualX->DrawLine(px1-4, pBy+4, px1-4, pBy-4);
467 gVirtualX->DrawLine(px1-4, pBy-4, px1+4, pBy-4);
468 gVirtualX->DrawLine(px1+4, pBy-4, px1+4, pBy+4);
469 gVirtualX->DrawLine(px1+4, pTy+4, px1-4, pTy+4);
470 gVirtualX->DrawLine(px1-4, pTy+4, px1-4, pTy-4);
471 gVirtualX->DrawLine(px1-4, pTy-4, px1+4, pTy-4);
472 gVirtualX->DrawLine(px1+4, pTy-4, px1+4, pTy+4);
473 }
474 pxold = px;
475 pyold = py;
476 break;
477
478 case kButton1Up:
479 if (gROOT->IsEscaped()) {
480 gROOT->SetEscape(kFALSE);
481 if (opaque) {
482 this->SetX1(oldX1);
483 this->SetY1(oldY1);
484 this->SetR1(oldR1);
485 this->SetR2(oldR2);
486 gPad->Modified(kTRUE);
487 gPad->Update();
488 }
489 break;
490 }
491
492 if (opaque) {
493 gPad->ShowGuidelines(this, event);
494 } else {
495 fX1 = gPad->AbsPixeltoX(px1);
496 fY1 = gPad->AbsPixeltoY(py1);
497 fBy = gPad->AbsPixeltoY(py1+r2);
498 fTy = gPad->AbsPixeltoY(py1-r2);
499 fLx = gPad->AbsPixeltoX(px1+r1);
500 fRx = gPad->AbsPixeltoX(px1-r1);
501 fR1 = TMath::Abs(fRx-fLx)/2;
502 fR2 = TMath::Abs(fTy-fBy)/2;
503 gPad->Modified(kTRUE);
504 gVirtualX->SetLineColor(-1);
505 }
506 }
507}
508
509////////////////////////////////////////////////////////////////////////////////
510/// List this ellipse with its attributes.
511
513{
515 printf("%s: X1= %f Y1=%f R1=%f R2=%f\n",GetName(),fX1,fY1,fR1,fR2);
516}
517
518////////////////////////////////////////////////////////////////////////////////
519/// Paint this ellipse with its current attributes.
520
522{
524}
525
526////////////////////////////////////////////////////////////////////////////////
527/// Draw this ellipse with new coordinates.
528
530 Double_t phimin, Double_t phimax, Double_t theta,
532{
533 const Int_t np = 200;
534 static Double_t x[np+3], y[np+3];
535 TAttLine::Modify(); //Change line attributes only if necessary
536 TAttFill::Modify(); //Change fill attributes only if necessary
537
538 Double_t phi1 = TMath::Min(phimin,phimax);
539 Double_t phi2 = TMath::Max(phimin,phimax);
540
541 //set number of points approximatively proportional to the ellipse circumference
542 Double_t circ = kPI*(r1+r2)*(phi2-phi1)/360;
543 Int_t n = (Int_t)(np*circ/((gPad->GetX2()-gPad->GetX1())+(gPad->GetY2()-gPad->GetY1())));
544 if (n < 8) n= 8;
545 if (n > np) n = np;
546 Double_t angle,dx,dy;
547 Double_t dphi = (phi2-phi1)*kPI/(180*n);
548 Double_t ct = TMath::Cos(kPI*theta/180);
549 Double_t st = TMath::Sin(kPI*theta/180);
550 for (Int_t i=0;i<=n;i++) {
551 angle = phi1*kPI/180 + Double_t(i)*dphi;
552 dx = r1*TMath::Cos(angle);
553 dy = r2*TMath::Sin(angle);
554 x[i] = gPad->XtoPad(x1 + dx*ct - dy*st);
555 y[i] = gPad->YtoPad(y1 + dx*st + dy*ct);
556 }
557 TString opt = option;
558 opt.ToLower();
559 if (phi2-phi1 >= 360 ) {
560 if (GetFillStyle()) gPad->PaintFillArea(n,x,y);
561 if (GetLineStyle()) gPad->PaintPolyLine(n+1,x,y);
562 } else {
563 x[n+1] = gPad->XtoPad(x1);
564 y[n+1] = gPad->YtoPad(y1);
565 x[n+2] = x[0];
566 y[n+2] = y[0];
567 if (GetFillStyle()) gPad->PaintFillArea(n+2,x,y);
568 if (GetLineStyle()) {
569 if (TestBit(kNoEdges) || opt.Contains("only")) gPad->PaintPolyLine(n+1,x,y);
570 else gPad->PaintPolyLine(n+3,x,y);
571 }
572 }
573}
574
575////////////////////////////////////////////////////////////////////////////////
576/// Dump this ellipse with its attributes.
577
579{
580 printf("Ellipse: X1=%f Y1=%f R1=%f R2=%f",fX1,fY1,fR1,fR2);
581 if (GetLineColor() != 1) printf(" Color=%d",GetLineColor());
582 if (GetLineStyle() != 1) printf(" Style=%d",GetLineStyle());
583 if (GetLineWidth() != 1) printf(" Width=%d",GetLineWidth());
584 printf("\n");
585}
586
587////////////////////////////////////////////////////////////////////////////////
588/// Save primitive as a C++ statement(s) on output stream out
589
590void TEllipse::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
591{
592 out<<" "<<std::endl;
593 if (gROOT->ClassSaved(TEllipse::Class())) {
594 out<<" ";
595 } else {
596 out<<" TEllipse *";
597 }
598 out<<"ellipse = new TEllipse("<<fX1<<","<<fY1<<","<<fR1<<","<<fR2
599 <<","<<fPhimin<<","<<fPhimax<<","<<fTheta<<");"<<std::endl;
600
601 SaveFillAttributes(out,"ellipse",0,1001);
602 SaveLineAttributes(out,"ellipse",1,1,1);
603
604 if (GetNoEdges()) out<<" ellipse->SetNoEdges();"<<std::endl;
605
606 out<<" ellipse->Draw();"<<std::endl;
607}
608
609////////////////////////////////////////////////////////////////////////////////
610/// Return kTRUE if kNoEdges bit is set, kFALSE otherwise.
611
613{
614 return TestBit(kNoEdges) ? kTRUE : kFALSE;
615}
616
617////////////////////////////////////////////////////////////////////////////////
618/// if noEdges = kTRUE the lines connecting the center to the edges
619/// will not be drawn.
620/// default is to draw the edges.
621
623{
624 if (noEdges) SetBit(kNoEdges);
625 else ResetBit(kNoEdges);
626}
627
628////////////////////////////////////////////////////////////////////////////////
629/// Stream an object of class TEllipse.
630
632{
633 if (R__b.IsReading()) {
634 UInt_t R__s, R__c;
635 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
636 if (R__v > 1) {
637 R__b.ReadClassBuffer(TEllipse::Class(), this, R__v, R__s, R__c);
638 return;
639 }
640 //====process old versions before automatic schema evolution
641 TObject::Streamer(R__b);
642 TAttLine::Streamer(R__b);
643 TAttFill::Streamer(R__b);
644 Float_t x1,y1,r1,r2,phimin,phimax,theta;
645 R__b >> x1; fX1 = x1;
646 R__b >> y1; fY1 = y1;
647 R__b >> r1; fR1 = r1;
648 R__b >> r2; fR2 = r2;
649 R__b >> phimin; fPhimin = phimin;
650 R__b >> phimax; fPhimax = phimax;
651 R__b >> theta; fTheta = theta;
652 R__b.CheckByteCount(R__s, R__c, TEllipse::IsA());
653 //====end of old versions
654
655 } else {
657 }
658}
659
660////////////////////////////////////////////////////////////////////////////////
661/// Return the bounding Box of the Ellipse, currently not taking into
662/// account the rotating angle.
663
665{
666 Rectangle_t BBox;
667 if (!gPad) return (BBox);
668 BBox.fX = gPad->XtoPixel(fX1-fR1);
669 BBox.fY = gPad->YtoPixel(fY1+fR2);
670 BBox.fWidth = gPad->XtoPixel(fX1+fR1)-gPad->XtoPixel(fX1-fR1);
671 BBox.fHeight = gPad->YtoPixel(fY1-fR2)-gPad->YtoPixel(fY1+fR2);
672 return (BBox);
673}
674
675////////////////////////////////////////////////////////////////////////////////
676/// Return the center of the Ellipse as TPoint in pixels
677
679{
680 TPoint p;
681 if (!gPad) return (p);
682 p.SetX(gPad->XtoPixel(fX1));
683 p.SetY(gPad->YtoPixel(fY1));
684 return(p);
685}
686
687////////////////////////////////////////////////////////////////////////////////
688/// Set center of the Ellipse
689
691{
692 if (!gPad) return;
693 fX1 = gPad->PixeltoX(p.GetX());
694 fY1 = gPad->PixeltoY(p.GetY()-gPad->VtoPixel(0));
695}
696
697////////////////////////////////////////////////////////////////////////////////
698/// Set X coordinate of the center of the Ellipse
699
701{
702 if (!gPad) return;
703 fX1 = gPad->PixeltoX(x);
704}
705
706////////////////////////////////////////////////////////////////////////////////
707/// Set Y coordinate of the center of the Ellipse
708
710{
711 if (!gPad) return;
712 fY1 = gPad->PixeltoY(y-gPad->VtoPixel(0));
713}
714
715////////////////////////////////////////////////////////////////////////////////
716/// Set left hand side of BoundingBox to a value
717/// (resize in x direction on left)
718
720{
721 Double_t x1 = gPad->PixeltoX(x);
722 if (x1>fX1+fR1) return;
723
724 fR1 = (fX1+fR1-x1)*0.5;
725 fX1 = x1 + fR1;
726}
727
728////////////////////////////////////////////////////////////////////////////////
729/// Set right hand side of BoundingBox to a value
730/// (resize in x direction on right)
731
733{
734 if (!gPad) return;
735 Double_t x2 = gPad->PixeltoX(x);
736 if (x2<fX1-fR1) return;
737
738 fR1 = (x2-fX1+fR1)*0.5;
739 fX1 = x2-fR1;
740}
741
742////////////////////////////////////////////////////////////////////////////////
743/// Set top of BoundingBox to a value (resize in y direction on top)
744
746{
747 if (!gPad) return;
748 Double_t y1 = gPad->PixeltoY(y-gPad->VtoPixel(0));
749 if (y1<fY1-fR2) return;
750
751 fR2 = (y1-fY1+fR2)*0.5;
752 fY1 = y1-fR2;
753}
754
755////////////////////////////////////////////////////////////////////////////////
756/// Set bottom of BoundingBox to a value
757/// (resize in y direction on bottom)
758
760{
761 if (!gPad) return;
762 Double_t y2 = gPad->PixeltoY(y-gPad->VtoPixel(0));
763
764 if (y2>fY1+fR2) return;
765
766 fR2 = (fY1+fR2-y2)*0.5;
767 fY1 = y2+fR2;
768}
@ kMouseMotion
Definition: Buttons.h:23
@ kArrowKeyRelease
Definition: Buttons.h:21
@ kButton1Motion
Definition: Buttons.h:20
@ kButton1Up
Definition: Buttons.h:19
@ kArrowKeyPress
Definition: Buttons.h:21
@ kButton1Down
Definition: Buttons.h:17
@ kRightSide
Definition: GuiTypes.h:373
@ kBottomSide
Definition: GuiTypes.h:373
@ kTopSide
Definition: GuiTypes.h:373
@ kLeftSide
Definition: GuiTypes.h:373
@ kMove
Definition: GuiTypes.h:374
int Int_t
Definition: RtypesCore.h:45
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
const Double_t kPI
Definition: TEllipse.cxx:24
winID h TVirtualViewer3D TVirtualGLPainter p
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
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint angle
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char y1
#define gROOT
Definition: TROOT.h:404
#define gPad
Definition: TVirtualPad.h:288
#define gVirtualX
Definition: TVirtualX.h:338
Abstract base class for elements drawn in the editor.
Definition: TAttBBox2D.h:19
Fill Area Attributes class.
Definition: TAttFill.h:19
virtual void Streamer(TBuffer &)
virtual Color_t GetFillColor() const
Return the fill area color.
Definition: TAttFill.h:30
void Copy(TAttFill &attfill) const
Copy this fill attributes to a new TAttFill.
Definition: TAttFill.cxx:204
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition: TAttFill.h:31
virtual void Modify()
Change current fill area attributes if necessary.
Definition: TAttFill.cxx:213
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 Color_t GetLineColor() const
Return the line color.
Definition: TAttLine.h:33
virtual Width_t GetLineWidth() const
Return the line width.
Definition: TAttLine.h:35
virtual Style_t GetLineStyle() const
Return the line style.
Definition: TAttLine.h:34
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
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
virtual Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
Bool_t IsReading() const
Definition: TBuffer.h:86
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
Draw Ellipses.
Definition: TEllipse.h:23
TClass * IsA() const override
Definition: TEllipse.h:79
virtual void SetR1(Double_t r1)
Definition: TEllipse.h:64
void ls(Option_t *option="") const override
List this ellipse with its attributes.
Definition: TEllipse.cxx:512
virtual void SetX1(Double_t x1)
Definition: TEllipse.h:67
virtual void PaintEllipse(Double_t x1, Double_t y1, Double_t r1, Double_t r2, Double_t phimin, Double_t phimax, Double_t theta, Option_t *option="")
Draw this ellipse with new coordinates.
Definition: TEllipse.cxx:529
void SetBBoxCenterY(const Int_t y) override
Set Y coordinate of the center of the Ellipse.
Definition: TEllipse.cxx:709
Double_t GetTheta() const
Definition: TEllipse.h:54
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition: TEllipse.cxx:200
void SetBBoxY1(const Int_t y) override
Set top of BoundingBox to a value (resize in y direction on top)
Definition: TEllipse.cxx:745
void SetBBoxX1(const Int_t x) override
Set left hand side of BoundingBox to a value (resize in x direction on left)
Definition: TEllipse.cxx:719
void SetBBoxY2(const Int_t y) override
Set bottom of BoundingBox to a value (resize in y direction on bottom)
Definition: TEllipse.cxx:759
virtual ~TEllipse()
Ellipse default destructor.
Definition: TEllipse.cxx:87
@ kNoEdges
Definition: TEllipse.h:37
Double_t GetX1() const
Definition: TEllipse.h:48
Double_t fPhimax
Maximum angle (degrees)
Definition: TEllipse.h:31
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to an ellipse.
Definition: TEllipse.cxx:133
Double_t fX1
X coordinate of centre.
Definition: TEllipse.h:26
void SetBBoxX2(const Int_t x) override
Set right hand side of BoundingBox to a value (resize in x direction on right)
Definition: TEllipse.cxx:732
Bool_t GetNoEdges() const
Return kTRUE if kNoEdges bit is set, kFALSE otherwise.
Definition: TEllipse.cxx:612
void Draw(Option_t *option="") override
Draw this ellipse with its current attributes.
Definition: TEllipse.cxx:168
Rectangle_t GetBBox() override
Return the bounding Box of the Ellipse, currently not taking into account the rotating angle.
Definition: TEllipse.cxx:664
void Paint(Option_t *option="") override
Paint this ellipse with its current attributes.
Definition: TEllipse.cxx:521
Double_t fY1
Y coordinate of centre.
Definition: TEllipse.h:27
Double_t fTheta
Rotation angle (degrees)
Definition: TEllipse.h:32
void SetBBoxCenter(const TPoint &p) override
Set center of the Ellipse.
Definition: TEllipse.cxx:690
void SetBBoxCenterX(const Int_t x) override
Set X coordinate of the center of the Ellipse.
Definition: TEllipse.cxx:700
virtual void SetY1(Double_t y1)
Definition: TEllipse.h:68
Double_t fR2
second radius
Definition: TEllipse.h:29
void Streamer(TBuffer &) override
Stream an object of class TEllipse.
Definition: TEllipse.cxx:631
virtual void SetNoEdges(Bool_t noEdges=kTRUE)
if noEdges = kTRUE the lines connecting the center to the edges will not be drawn.
Definition: TEllipse.cxx:622
void Copy(TObject &ellipse) const override
Copy this ellipse to ellipse.
Definition: TEllipse.cxx:110
Double_t fPhimin
Minimum angle (degrees)
Definition: TEllipse.h:30
Double_t GetY1() const
Definition: TEllipse.h:49
TPoint GetBBoxCenter() override
Return the center of the Ellipse as TPoint in pixels.
Definition: TEllipse.cxx:678
TEllipse()
Ellipse default constructor.
Definition: TEllipse.cxx:57
Double_t fR1
first radius
Definition: TEllipse.h:28
static TClass * Class()
virtual TEllipse * DrawEllipse(Double_t x1, Double_t y1, Double_t r1, Double_t r2, Double_t phimin, Double_t phimax, Double_t theta, Option_t *option="")
Draw this ellipse with new coordinates.
Definition: TEllipse.cxx:176
virtual void SetR2(Double_t r2)
Definition: TEllipse.h:65
void Print(Option_t *option="") const override
Dump this ellipse with its attributes.
Definition: TEllipse.cxx:578
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
Definition: TEllipse.cxx:590
Mother of all ROOT objects.
Definition: TObject.h:41
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:433
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:201
virtual void Streamer(TBuffer &)
Stream an object of class TObject.
Definition: TObject.cxx:876
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition: TObject.cxx:177
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:768
virtual void Copy(TObject &object) const
Copy this to obj.
Definition: TObject.cxx:133
void ResetBit(UInt_t f)
Definition: TObject.h:200
@ kCanDelete
if object in a list can be deleted
Definition: TObject.h:62
Definition: TPoint.h:31
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition: TROOT.cxx:2813
Basic string class.
Definition: TString.h:136
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1159
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16
double dist(Rotation3D const &r1, Rotation3D const &r2)
Definition: 3DDistances.cxx:48
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition: TMathBase.h:250
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition: TMath.h:660
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition: TMathBase.h:198
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Definition: TMath.h:592
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Definition: TMath.h:586
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition: TMathBase.h:123
Rectangle structure (maps to the X11 XRectangle structure)
Definition: GuiTypes.h:361
Short_t fX
Definition: GuiTypes.h:362
UShort_t fHeight
Definition: GuiTypes.h:363
Short_t fY
Definition: GuiTypes.h:362
UShort_t fWidth
Definition: GuiTypes.h:363