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