Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TCurlyArc.cxx
Go to the documentation of this file.
1// @(#)root/graf:$Id$
2// Author: Otto Schaile 20/11/99
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/** \class TCurlyArc
13\ingroup BasicGraphics
14
15Implements curly or wavy arcs used to draw Feynman diagrams.
16
17Amplitudes and wavelengths may be specified in the constructors,
18via commands or interactively from popup menus.
19The class make use of TCurlyLine by inheritance, ExecuteEvent methods
20are highly inspired from the methods used in TPolyLine and TArc.
21The picture below has been generated by the tutorial feynman.
22
23Begin_Macro(source)
24../../../tutorials/visualisation/graphics/feynman.C
25End_Macro
26*/
27
28#include <iostream>
29#include "TCurlyArc.h"
30#include "TROOT.h"
31#include "TVirtualPad.h"
32#include "TVirtualPadPainter.h"
33#include "TAttMarker.h"
34#include "TMath.h"
35#include "TPoint.h"
36
40
41
42////////////////////////////////////////////////////////////////////////////////
43/// Default constructor
44
46{
47 fR1 = 0.;
48 fPhimin = 0.;
49 fPhimax = 0.;
50 fTheta = 0.;
51}
52
53////////////////////////////////////////////////////////////////////////////////
54/// Create a new TCurlyArc with center (x1, y1) and radius rad.
55/// The wavelength and amplitude are given in percent of the line length
56/// phimin and phimax are given in degrees.
57
61 : fR1(rad), fPhimin(phimin),fPhimax(phimax)
62{
63 fX1 = x1;
64 fY1 = y1;
68 fTheta = 0;
69 Build();
70}
71
72////////////////////////////////////////////////////////////////////////////////
73/// Create a curly (Gluon) or wavy (Gamma) arc.
74
76{
80 if (gPad) {
81 Double_t pxrange = gPad->GetPadWidth();
82 Double_t pyrange = -1. * gPad->GetPadHeight();
83 Double_t xrange = gPad->GetX2() - gPad->GetX1();
84 Double_t yrange = gPad->GetY2() - gPad->GetY1();
87 rPix = fR1 / pixeltoX;
88 }
90 if (dang < 0) dang += 360;
91 Double_t length = TMath::Pi() * fR1 * dang/180;
94 fX1 = fY1 = 0;
95 fX2 = length;
96 fY2 = 0;
98 fX1 = x1sav;
99 fY1 = y1sav;
100 Double_t *xv= GetX();
101 Double_t *yv= GetY();
103 for(Int_t i = 0; i < fNsteps; i++){
104 angle = xv[i] / rPix + fPhimin * TMath::Pi()/180;
105 xx = (yv[i] + rPix) * cos(angle);
106 yy = (yv[i] + rPix) * sin(angle);
107 xx *= pixeltoX;
109 xv[i] = xx + fX1;
110 yv[i] = yy + fY1;
111 }
112 if (gPad)
113 gPad->Modified();
114}
115
116////////////////////////////////////////////////////////////////////////////////
117/// Compute distance from point px,py to an arc.
118///
119/// Compute the closest distance of approach from point px,py to this arc.
120/// The distance is computed in pixels units.
121
123{
124 if (!gPad) return 9999;
125 // Compute distance of point to center of arc
126 Int_t pxc = gPad->XtoAbsPixel(gPad->XtoPad(fX1));
127 Int_t pyc = gPad->YtoAbsPixel(gPad->YtoPad(fY1));
128 Double_t dist = TMath::Sqrt(Long64_t(pxc-px)*(pxc-px)+Long64_t(pyc-py)*(pyc-py));
129 Double_t cosa = (px - pxc)/dist;
130 Double_t sina = (pyc - py)/dist;
132 if (phi < 0) phi += 2 * TMath::Pi();
133 phi = phi * 180 / TMath::Pi();
134 if (fPhimax > fPhimin){
135 if (phi < fPhimin || phi > fPhimax) return 9999;
136 } else {
137 if (phi > fPhimin && phi < fPhimax) return 9999;
138 }
139 Int_t pxa = gPad->XtoAbsPixel(gPad->XtoPad(fX1 + cosa*fR1));
140 Int_t pya = gPad->YtoAbsPixel(gPad->YtoPad(fY1 + sina*fR1));
142 return (Int_t) TMath::Abs(dist - dista);
143}
144
145////////////////////////////////////////////////////////////////////////////////
146/// Execute action corresponding to one event.
147///
148/// This member function is called when a TCurlyArc is clicked with the locator
149///
150/// If Left button clicked on one of the line end points, this point
151/// follows the cursor until button is released.
152///
153/// if Middle button clicked, the line is moved parallel to itself
154/// until the button is released.
155
157{
158 if (!gPad || !gPad->IsEditable()) return;
159
160 auto &parent = *gPad;
161
162 constexpr Int_t kMaxDiff = 10;
163 static enum { pNone, pTop, pL, pR, pBot, pINSIDE } mode = pNone;
164 static Int_t sdx = 0, sdy = 0;
165 static Bool_t first_move = kTRUE;
166
167 auto paint_hollow = [this, &parent]() {
168 int np = 10;
169 std::vector<Double_t> x(np+3), y(np+3);
170
171 Double_t dphi = (fPhimax - fPhimin) * TMath::Pi() / 180;
172 if (dphi < 0)
173 dphi += 2 * TMath::Pi();
174 Double_t phi0 = fPhimin * TMath::Pi() / 180;
175 for (int i = 0; i <= np; i++) {
176 Double_t angle = phi0 + i*dphi/np;
177 x[i] = parent.XtoPad(fX1 + fR1*TMath::Cos(angle));
178 y[i] = parent.YtoPad(fY1 + fR1*TMath::Sin(angle));
179 }
180 if (fPhimax - fPhimin < 360) {
181 ++np;
182 x[np] = parent.XtoPad(fX1);
183 y[np] = parent.YtoPad(fY1);
184 }
185 ++np;
186 x[np] = x[0];
187 y[np] = y[0];
188
189 auto pp = parent.GetPainter();
190 pp->SetAttLine(*this);
191 pp->DrawPolyLine(np + 1, x.data(), y.data());
192
193 Double_t xm[4] = { fX1, fX1, fX1 - fR1, fX1 + fR1 };
194 Double_t ym[4] = { fY1 + fR1, fY1 - fR1, fY1, fY1 };
195 for (Int_t i = 0; i < 4; ++i) {
196 xm[i] = parent.XtoPad(xm[i]);
197 ym[i] = parent.YtoPad(ym[i]);
198 }
199 pp->SetAttMarker({GetLineColor(), 25, 2});
200 pp->DrawPolyMarker(4, xm, ym);
201 };
202
203 Bool_t opaque = parent.OpaqueMoving();
204
205 switch (event) {
206
207 case kArrowKeyPress:
208 case kButton1Down:
209 // No break !!!
210 case kMouseMotion: {
211 Int_t px1 = parent.XtoAbsPixel(parent.XtoPad(fX1));
212 Int_t py1 = parent.YtoAbsPixel(parent.YtoPad(fY1));
213 Int_t pLx = parent.XtoAbsPixel(parent.XtoPad(fX1 - fR1));
214 Int_t pRx = parent.XtoAbsPixel(parent.XtoPad(fX1 + fR1));
215 Int_t pTy = parent.YtoAbsPixel(parent.YtoPad(fY1 + fR1));
216 Int_t pBy = parent.YtoAbsPixel(parent.YtoPad(fY1 - fR1));
217
218 if ((abs(px - px1) < kMaxDiff) && (abs(py - pTy) < kMaxDiff)) {
219 mode = pTop;
220 parent.SetCursor(kTopSide);
221 } else if ((abs(px - px1) < kMaxDiff) && (abs(py - pBy) < kMaxDiff)) {
222 mode = pBot;
223 parent.SetCursor(kBottomSide);
224 } else if ((abs(py - py1) < kMaxDiff) && (abs(px - pLx) < kMaxDiff)) {
225 mode = pL;
226 parent.SetCursor(kLeftSide);
227 } else if ((abs(py - py1) < kMaxDiff) && (abs(px - pRx) < kMaxDiff)) {
228 mode = pR;
229 parent.SetCursor(kRightSide);
230 } else {
231 mode = pINSIDE;
232 sdx = px1 - px;
233 sdy = py1 - py;
234 parent.SetCursor(kMove);
235 }
237
238 break;
239 }
240
241 case kArrowKeyRelease:
242 case kButton1Motion: {
243 if (!opaque && !first_move)
244 paint_hollow();
245 char guide = 0;
246 switch (mode) {
247 case pNone:
248 break;
249 case pTop:
250 fR1 = GetYCoord(py, kFALSE, kTRUE) - fY1;
251 guide = 't';
252 break;
253 case pBot:
254 fR1 = fY1 - GetYCoord(py, kFALSE, kTRUE);
255 guide = 'b';
256 break;
257 case pL:
258 fR1 = fX1 - GetXCoord(px, kFALSE, kTRUE);
259 guide = 'l';
260 break;
261 case pR:
262 fR1 = GetXCoord(px, kFALSE, kTRUE) - fX1;
263 guide = 'r';
264 break;
265 case pINSIDE:
266 fX1 = GetXCoord(px + sdx, kFALSE, kTRUE);
267 fY1 = GetYCoord(py + sdy, kFALSE, kTRUE);
268 guide = 'i';
269 break;
270 }
271
273
274 if (!opaque)
275 paint_hollow();
276 else {
277 if (guide)
278 parent.ShowGuidelines(this, event, guide, true);
279 Build();
280 parent.ModifiedUpdate();
281 }
282 break;
283 }
284
285 case kButton1Up:
286 if (opaque) {
287 parent.ShowGuidelines(this, event);
288 } else {
289 Build();
290 parent.Modified(kTRUE);
291 }
292 }
293}
294
295////////////////////////////////////////////////////////////////////////////////
296/// Save primitive as a C++ statement(s) on output stream out
297
298void TCurlyArc::SavePrimitive(std::ostream &out, Option_t *option)
299{
301 out, Class(), "curlyarc",
302 TString::Format("%g, %g, %g, %g, %g, %g, %g", fX1, fY1, fR1, fPhimin, fPhimax, fWaveLength, fAmplitude));
303
304 SaveLineAttributes(out, "curlyarc", 1, 1, 1);
305 if (!fIsCurly)
306 out << " curlyarc->SetWavy();\n";
307
308 SavePrimitiveDraw(out, "curlyarc", option);
309}
310
311////////////////////////////////////////////////////////////////////////////////
312/// Set Curly Arc center.
313
315{
316 fX1 = x;
317 fY1 = y;
318 Build();
319}
320
321////////////////////////////////////////////////////////////////////////////////
322/// Set Curly Arc radius.
323
325{
326 fR1 = x;
327 Build();
328}
329
330////////////////////////////////////////////////////////////////////////////////
331/// Set Curly Arc minimum Phi.
332
334{
335 fPhimin = x;
336 Build();
337}
338
339////////////////////////////////////////////////////////////////////////////////
340/// Set Curly Arc maximum Phi.
341
343{
344 fPhimax = x;
345 Build();
346}
347
348////////////////////////////////////////////////////////////////////////////////
349/// Set default wave length.
350
355
356////////////////////////////////////////////////////////////////////////////////
357/// Set default wave amplitude.
358
363
364////////////////////////////////////////////////////////////////////////////////
365/// Set default "IsCurly".
366
371
372////////////////////////////////////////////////////////////////////////////////
373/// Get default wave length.
374
379
380////////////////////////////////////////////////////////////////////////////////
381/// Get default wave amplitude.
382
387
388////////////////////////////////////////////////////////////////////////////////
389/// Get default "IsCurly".
390
395
396////////////////////////////////////////////////////////////////////////////////
397/// Return the bounding Box of the Line
398
400{
401 Rectangle_t bbox{0, 0, 0, 0};
402 if (gPad) {
403 Double_t R2 = fR1 * TMath::Abs(gPad->GetY2() - gPad->GetY1()) / TMath::Abs(gPad->GetX2() - gPad->GetX1());
404 bbox.fX = gPad->XtoPixel(fX1 - fR1);
405 bbox.fY = gPad->YtoPixel(fY1 + R2);
406 bbox.fWidth = gPad->XtoPixel(fX1 + fR1) - bbox.fX;
407 bbox.fHeight = gPad->YtoPixel(fY1 - R2) - bbox.fY;
408 }
409 return bbox;
410}
411
412////////////////////////////////////////////////////////////////////////////////
413/// Return the center of the BoundingBox as TPoint in pixels
414
416{
417 TPoint p(0,0);
418 if (gPad) {
419 p.SetX(gPad->XtoPixel(fX1));
420 p.SetY(gPad->YtoPixel(fY1));
421 }
422 return p;
423}
424
425////////////////////////////////////////////////////////////////////////////////
426/// Set X coordinate of the center of the BoundingBox
427
429{
430 fX1 = GetXCoord(x);
431 Build();
432}
433
434////////////////////////////////////////////////////////////////////////////////
435/// Set Y coordinate of the center of the BoundingBox
436
438{
439 fY1 = GetYCoord(y);
440 Build();
441}
442
443////////////////////////////////////////////////////////////////////////////////
444/// Set left hand side of BoundingBox to a value
445/// (resize in x direction on left)
446
448{
449 fR1 = fX1 - GetXCoord(x);
450}
451
452////////////////////////////////////////////////////////////////////////////////
453/// Set right hand side of BoundingBox to a value
454/// (resize in x direction on right)
455
457{
458 fR1 = GetXCoord(x) - fX1;
459}
460
461////////////////////////////////////////////////////////////////////////////////
462/// Set top of BoundingBox to a value (resize in y direction on top)
463
465{
466 fR1 = GetYCoord(y) - fY1;
467}
468
469////////////////////////////////////////////////////////////////////////////////
470/// Set bottom of BoundingBox to a value
471/// (resize in y direction on bottom)
472
474{
475 fR1 = fY1 - GetYCoord(y);
476}
@ 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:374
@ kBottomSide
Definition GuiTypes.h:374
@ kTopSide
Definition GuiTypes.h:374
@ kLeftSide
Definition GuiTypes.h:374
@ kMove
Definition GuiTypes.h:375
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
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.
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 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 winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint angle
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char y1
#define gPad
Double_t GetYCoord(const Int_t y, Bool_t is_ndc=kFALSE, Bool_t is_absolute=kFALSE)
Can return ndc or normal values Also one can specify to use absolute coordinates for input parameter ...
Double_t GetXCoord(const Int_t x, Bool_t is_ndc=kFALSE, Bool_t is_absolute=kFALSE)
Return user X coordinate for pixel X value Can return ndc or normal values Also one can specify to us...
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:36
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:289
Rectangle_t GetBBox() override
Return the bounding Box of the Line.
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to an arc.
void SetBBoxX1(const Int_t x) override
Set left hand side of BoundingBox to a value (resize in x direction on left)
virtual void SetRadius(Double_t radius)
Set Curly Arc radius.
static Bool_t GetDefaultIsCurly()
Get default "IsCurly".
void Build() override
Create a curly (Gluon) or wavy (Gamma) arc.
Definition TCurlyArc.cxx:75
virtual void SetPhimin(Double_t phimin)
Set Curly Arc minimum Phi.
Double_t fTheta
used internally
Definition TCurlyArc.h:22
static Double_t GetDefaultWaveLength()
Get default wave length.
static TClass * Class()
virtual void SetCenter(Double_t x1, Double_t y1)
Set Curly Arc center.
Double_t fPhimax
end phi (degrees)
Definition TCurlyArc.h:21
void SetBBoxY2(const Int_t y) override
Set bottom of BoundingBox to a value (resize in y direction on bottom)
void SetBBoxX2(const Int_t x) override
Set right hand side of BoundingBox to a value (resize in x direction on right)
TCurlyArc()
Default constructor.
Definition TCurlyArc.cxx:45
static Double_t fgDefaultWaveLength
default wavelength
Definition TCurlyArc.h:24
static void SetDefaultWaveLength(Double_t WaveLength)
Set default wave length.
static void SetDefaultAmplitude(Double_t Amplitude)
Set default wave amplitude.
Double_t fPhimin
start phi (degrees)
Definition TCurlyArc.h:20
Double_t fR1
Radius of arc.
Definition TCurlyArc.h:19
static Double_t fgDefaultAmplitude
default amplitude
Definition TCurlyArc.h:25
static Double_t GetDefaultAmplitude()
Get default wave amplitude.
static void SetDefaultIsCurly(Bool_t IsCurly)
Set default "IsCurly".
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
TPoint GetBBoxCenter() override
Return the center of the BoundingBox as TPoint in pixels.
static Bool_t fgDefaultIsCurly
default curly type
Definition TCurlyArc.h:26
void SavePrimitive(std::ostream &out, Option_t *="") override
Save primitive as a C++ statement(s) on output stream out.
void SetBBoxCenterY(const Int_t y) override
Set Y coordinate of the center of the BoundingBox.
void SetBBoxY1(const Int_t y) override
Set top of BoundingBox to a value (resize in y direction on top)
virtual void SetPhimax(Double_t phimax)
Set Curly Arc maximum Phi.
void SetBBoxCenterX(const Int_t x) override
Set X coordinate of the center of the BoundingBox.
Double_t fY1
start y, center for arc
Definition TCurlyLine.h:23
Double_t fWaveLength
wavelength of sinusoid in percent of pad height
Definition TCurlyLine.h:26
Double_t fAmplitude
amplitude of sinusoid in percent of pad height
Definition TCurlyLine.h:27
Int_t fNsteps
used internally (controls precision)
Definition TCurlyLine.h:28
virtual void Build()
Create a curly (Gluon) or wavy (Gamma) line.
Double_t fY2
end y
Definition TCurlyLine.h:25
Double_t fX1
start x, center for arc
Definition TCurlyLine.h:22
Double_t fX2
end x
Definition TCurlyLine.h:24
Bool_t fIsCurly
true: Gluon, false: Gamma
Definition TCurlyLine.h:29
static void SavePrimitiveDraw(std::ostream &out, const char *variable_name, Option_t *option=nullptr)
Save invocation of primitive Draw() method Skipped if option contains "nodraw" string.
Definition TObject.cxx:845
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:777
Double_t * GetX() const
Definition TPolyLine.h:54
Double_t * GetY() const
Definition TPolyLine.h:55
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:2385
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Double_t ATan2(Double_t y, Double_t x)
Returns the principal value of the arc tangent of y/x, expressed in radians.
Definition TMath.h:657
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:673
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Definition TMath.h:605
constexpr Double_t Pi()
Definition TMath.h:40
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Definition TMath.h:599
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:122
#define R2(v, w, x, y, z, i)
Definition sha1.inl:137
Rectangle structure (maps to the X11 XRectangle structure)
Definition GuiTypes.h:362