BOSS 7.0.3
BESIII Offline Software System
Loading...
Searching...
No Matches
BesCircle2D.cxx
Go to the documentation of this file.
1//
2// BesCircle2D.cxx
3//
4// $Author: zhangy $
5// 2005/7/16
6// Modified from zevis 2D shape
7//
8
9#include <TString.h>
10#include <TPad.h>
11#include <TMath.h>
12
13#include "BesVisLib/BesCircle2D.h"
14#include "BesVisLib/BesView.h"
15#include <iostream>
16
17using namespace std;
18
19#ifndef __CINT__
21#endif
22
23//_____________________________________________________
24// BesCircle2D
25// Circle in 2D
26//
27//
29 //
30 // BesCircle2D default constructor
31 if ( gDebug ) cout << "BesCircle2D ctor called" << endl;
32 fInnerRadius = 0;
33 fOuterRadius = 0;
34 fCenter = 0;
35 fNSegment = 40;
36 f_innerCircleX = NULL;
37 f_innerCircleY = NULL;
38 f_outerCircleX = NULL;
39 f_outerCircleY = NULL;
40 f_areaX = NULL;
41 f_areaY = NULL;
42}
43
44//_____________________________________________________
45
46BesCircle2D::BesCircle2D(const char* name, const char* title, Double_t innerRadius, Double_t outerRadius, Double_t *center) :
47 TNamed(name, title), TAttLine(), TAttFill() {
48 //
49 // BesCircle2D normal constructor
50 if ( gDebug ) cout << "BesCircle2D normal ctor called" << endl;
51
52 fCenter = new Double_t[3];
53 for ( Int_t i = 0; i < 3; i++ ) fCenter[i] = center[i];
54 fInnerRadius = new Double_t[3];
55 fOuterRadius = new Double_t[3];
56 fInnerRadius[0]=innerRadius;
57 fOuterRadius[0]=outerRadius;
58 fNSegment = 40;
59 f_innerCircleX = NULL;
60 f_innerCircleY = NULL;
61 f_outerCircleX = NULL;
62 f_outerCircleY = NULL;
63 f_areaX = NULL;
64 f_areaY = NULL;
65}
66
67//_____________________________________________________
68
70 //
71 // BesCircle2D default destructor
72 if ( gDebug ) cout << "BesCircle2D default dtor called" << endl;
73
74 delete fCenter;
75 delete fInnerRadius;
76 delete fOuterRadius;
77}
78
79//_____________________________________________________
80
81Int_t BesCircle2D::DistancetoPrimitive(Int_t px, Int_t py) {
82
83 const Int_t inaxis = 7;
84 Int_t dist = 9999;
85
86 Int_t puxmin = gPad->XtoAbsPixel(gPad->GetUxmin());
87 Int_t puymin = gPad->YtoAbsPixel(gPad->GetUymin());
88 Int_t puxmax = gPad->XtoAbsPixel(gPad->GetUxmax());
89 Int_t puymax = gPad->YtoAbsPixel(gPad->GetUymax());
90
91 // return if point is not in the user area
92 if (px < puxmin - inaxis) return dist;
93 if (py > puymin + inaxis) return dist;
94 if (px > puxmax + inaxis) return dist;
95 if (py < puymax - inaxis) return dist;
96
97 BesView *view = (BesView*)gPad->GetView();
98 if (!view) return dist;
99
100 Double_t x = gPad->PadtoX(gPad->AbsPixeltoX(px));
101 Double_t y = gPad->PadtoY(gPad->AbsPixeltoY(py));
102 Double_t xndc[3];
103 //if (view->GetViewType() & kXYView)
104 xndc[0] = x;
105 xndc[1] = y;
106 xndc[2] = 0;
107 //cout << "NDC X:" << xndc[0] << " Y:" << xndc[1] << endl;
108
109 Double_t xwc[3];
110 view->NDCtoWC(xndc, xwc);
111 //cout << "WC X:" << xwc[0] << " Y:" << xwc[1] << endl;
112 //cout << "Center X:" << fCenter[0] << " Y:" << fCenter[1] << endl;
113
114 Double_t distw = 0.0;
115 for (Int_t i = 0; i < 2; i++) {
116 distw += (xwc[i]-fCenter[i]) * (xwc[i]-fCenter[i]);
117 }
118
119 if (distw >= fInnerRadius[0]*fInnerRadius[0] &&
120 distw <= fOuterRadius[0]*fOuterRadius[0])
121 return 0;
122 else
123 return dist;
124}
125
126//_____________________________________________________
127
128void BesCircle2D::ExecuteEvent(Int_t event, Int_t px, Int_t py) {
129 //cout << "I am in " << GetName() << endl;
130
131 BesView *view = (BesView*)gPad->GetView();
132 if (view) view->ExecuteEvent(event, px, py);
133}
134
135//_____________________________________________________
136
137void BesCircle2D::Draw(Option_t *option) {
138 //
139 // BesCircle2D draw function
140 TString opt = option;
141 opt.ToUpper();
142
143 AppendPad(option);
144}
145
146//_____________________________________________________
147
148void BesCircle2D::Paint(Option_t *option) {
149 // BesCircle2D paint function
150 TString opt = option;
151 opt.ToUpper();
152
153 // Transform to normalised desktop coordinates
154 BesView *view = (BesView*)gPad->GetView();
155 if (view == 0) cout << "no view found" << endl;
156
157 // Draw Painted area between circles as PaintFilledArea
158 Int_t np = fNSegment; //40;
159
160 if (f_innerCircleX){
161 delete [] f_innerCircleX;
162 f_innerCircleX = NULL;
163 }
164 if (f_innerCircleY){
165 delete [] f_innerCircleY;
166 f_innerCircleY = NULL;
167 }
168 if (f_outerCircleX){
169 delete [] f_outerCircleX;
170 f_outerCircleX = NULL;
171 }
172 if (f_outerCircleY){
173 delete [] f_outerCircleY;
174 f_outerCircleY = NULL;
175 }
176 if (f_areaX) {
177 delete [] f_areaX;
178 f_areaX = NULL;
179 }
180 if (f_areaY) {
181 delete [] f_areaY;
182 f_areaY = NULL;
183 }
184
185 f_innerCircleX = new Double_t[np+1];
186 f_innerCircleY = new Double_t[np+1];
187 f_outerCircleX = new Double_t[np+1];
188 f_outerCircleY = new Double_t[np+1];
189 f_areaX = new Double_t[4*np];
190 f_areaY = new Double_t[4*np];
191
192 TAttLine::Modify(); //Change line attributes only if necessary
193 TAttFill::Modify(); //Change fill attributes only if necessary
194
195 Double_t angle;
196 Double_t dphi = 2*TMath::Pi()/(np);
197 Double_t pointWC[3],pointNDC[3];
198
199 for (Int_t i=0; i< np ; i++) {
200 angle = Double_t(i)*dphi;
201
202 // inner circle
203 pointWC[0] = fCenter[0] + fInnerRadius[0]*TMath::Cos(angle);
204 pointWC[1] = fCenter[1] + fInnerRadius[0]*TMath::Sin(angle);
205 pointWC[2] = fCenter[2];
206 view->WCtoNDC(pointWC,pointNDC);
207 f_innerCircleX[i] = pointNDC[0];
208 f_innerCircleY[i] = pointNDC[1];
209 f_areaX[4*i] = pointNDC[0];
210 f_areaY[4*i] = pointNDC[1];
211 if ( i == 0 ) {
212 f_areaX[4*np - 3] = pointNDC[0];
213 f_areaY[4*np - 3] = pointNDC[1];
214 } else {
215 f_areaX[4*i - 3] = pointNDC[0];
216 f_areaY[4*i - 3] = pointNDC[1];
217 }
218
219 // outer circle
220 pointWC[0] = fCenter[0] + fOuterRadius[0]*TMath::Cos(angle);
221 pointWC[1] = fCenter[1] + fOuterRadius[0]*TMath::Sin(angle);
222 pointWC[2] = fCenter[2];
223 view->WCtoNDC(pointWC,pointNDC);
224 f_outerCircleX[i] = pointNDC[0];
225 f_outerCircleY[i] = pointNDC[1];
226 f_areaX[4*i + 3] = pointNDC[0];
227 f_areaY[4*i + 3] = pointNDC[1];
228 if ( i == 0 ) {
229 f_areaX[4*np - 2] = pointNDC[0];
230 f_areaY[4*np - 2] = pointNDC[1];
231 } else {
232 f_areaX[4*i - 2] = pointNDC[0];
233 f_areaY[4*i - 2] = pointNDC[1];
234 }
235
236 }
237
238 // last point for circles
239 f_innerCircleX[np] = f_innerCircleX[0];
240 f_innerCircleY[np] = f_innerCircleY[0];
241 f_outerCircleX[np] = f_outerCircleX[0];
242 f_outerCircleY[np] = f_outerCircleY[0];
243
244 // paint filled areas
245 for (Int_t i = 0; i < np; i++ ) {
246 gPad->PaintFillArea(4,&f_areaX[4*i],&f_areaY[4*i]);
247 }
248
249 // paint circles
250 // yzhang
251 gPad->PaintPolyLine(np+1,f_innerCircleX,f_innerCircleY);
252 gPad->PaintPolyLine(np+1,f_outerCircleX,f_outerCircleY);
253
254}
255//_____________________________________________________
256
257char *BesCircle2D::GetObjectInfo(Int_t px, Int_t py) const {
258
259 BesView *view = (BesView*)gPad->GetView();
260 if (view) return view->GetObjectInfo(px, py);
261 else return TObject::GetObjectInfo(px, py);
262}
263
264//_____________________________________________________
265
266void BesCircle2D::SetCenter(Double_t x, Double_t y, Double_t z)
267{
268 fCenter[0] = x;
269 fCenter[1] = y;
270 fCenter[2] = z;
271}
272
273//_____________________________________________________
274
275void BesCircle2D::GetCenter(Double_t *center)
276{
277 for (Int_t i = 0; i < 3; i++) center[i] = fCenter[i];
278}
ClassImp(BesCircle2D) BesCircle2D
Definition: BesCircle2D.cxx:20
Double_t x[10]
titledef title[20]
virtual void Paint(Option_t *option="")
virtual void Draw(Option_t *option="")
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Definition: BesCircle2D.cxx:81
virtual void SetCenter(Double_t x, Double_t y, Double_t z)
virtual char * GetObjectInfo(Int_t px, Int_t py) const
virtual ~BesCircle2D()
Definition: BesCircle2D.cxx:69
virtual void GetCenter(Double_t *center)
virtual void WCtoNDC(const Float_t *pw, Float_t *pn)
Definition: BesView.cxx:659
virtual char * GetObjectInfo(Int_t px, Int_t py) const
Definition: BesView.cxx:800
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Definition: BesView.cxx:365
virtual void NDCtoWC(const Float_t *pn, Float_t *pw)
Definition: BesView.cxx:725