#include <BesPolygon2D.h>
Public Member Functions | |
BesPolygon2D (const char *name, const char *title, Int_t N, Double_t *P) | |
BesPolygon2D () | |
info box | |
BesPolygon2D (const char *name, const char *title, Int_t N, Double_t *P) | |
BesPolygon2D () | |
info box | |
void | Delete (Option_t *option) |
void | Delete (Option_t *option) |
virtual Int_t | DistancetoPrimitive (Int_t px, Int_t py) |
virtual Int_t | DistancetoPrimitive (Int_t px, Int_t py) |
virtual void | Draw (Option_t *option="") |
virtual void | Draw (Option_t *option="") |
void | DrawClass () |
void | DrawClass () |
void | DrawClone (Option_t *option) |
void | DrawClone (Option_t *option) |
virtual void | ExecuteEvent (Int_t event, Int_t px, Int_t py) |
virtual void | ExecuteEvent (Int_t event, Int_t px, Int_t py) |
virtual void | GetCenter (Double_t *Center) const |
virtual void | GetCenter (Double_t *Center) const |
virtual char * | GetObjectInfo (Int_t px, Int_t py) const |
virtual char * | GetObjectInfo (Int_t px, Int_t py) const |
Bool_t | IsRotatable () |
Bool_t | IsRotatable () |
virtual void | Paint (Option_t *option="") |
virtual void | Paint (Option_t *option="") |
virtual void | Resize (Double_t ScaleFactor) |
virtual void | Resize (Double_t ScaleFactor) |
virtual void | Restore () |
virtual void | Restore () |
virtual void | RotatePhi (Double_t phi) |
virtual void | RotatePhi (Double_t phi) |
void | SetDrawOption (Option_t *option) |
void | SetDrawOption (Option_t *option) |
virtual void | SetInfoBox () |
virtual void | SetInfoBox () |
void | SetName (const char *name) |
void | SetName (const char *name) |
void | SetPoints (Double_t *P) |
void | SetPoints (Double_t *P) |
void | SetRotatable (Bool_t input) |
void | SetRotatable (Bool_t input) |
virtual void | SetSize (Double_t size) |
virtual void | SetSize (Double_t size) |
void | SetTitle (const char *name) |
void | SetTitle (const char *name) |
virtual void | SetZRSign (Int_t sign) |
virtual void | SetZRSign (Int_t sign) |
virtual | ~BesPolygon2D () |
virtual | ~BesPolygon2D () |
Protected Attributes | |
Double_t * | f_xx |
Double_t * | f_xx |
Double_t * | f_yy |
Double_t * | f_yy |
Double_t | fCenter [3] |
TPaveText * | fInfoBox |
TPaveText * | fInfoBox |
Int_t | fN |
Double_t * | fP |
Double_t * | fP |
Double_t * | fPBackUp |
Double_t * | fPBackUp |
Bool_t | fRotatable |
Static Private Attributes | |
int | num |
|
info box
|
|
00066 : 00067 TNamed(name, title), TAttLine(), TAttFill() { 00068 // 00069 // BesPolygon2D normal constructor 00070 //cout << "####################" << endl; 00071 //cout << "BesPolygon2D ctor called " << ++num << endl; 00072 //cout << "####################" << endl; 00073 00074 fN = N; 00075 fP = new Double_t[fN*3]; 00076 fPBackUp = new Double_t[fN*3]; 00077 f_xx = NULL; 00078 f_yy = NULL; 00079 00080 fInfoBox = 0; 00081 if (P!=NULL){ 00082 SetPoints(P); 00083 } 00084 00085 for ( Int_t i = 0; i < fN*3; i++ ) { 00086 fPBackUp[i] = fP[i]; 00087 } 00088 00089 for (Int_t j = 0; j < 3; j++) { 00090 fCenter[j] = 0.0; 00091 for ( Int_t i = 0; i < fN; i++) { 00092 fCenter[j] += fP[3*i+j]; 00093 } 00094 fCenter[j] /= fN; 00095 } 00096 00097 for ( Int_t i = 0; i < fN; i++ ) { 00098 } 00099 00100 fRotatable = false; 00101 }
|
|
00105 { 00106 // 00107 // BesPolygon2D default destructor 00108 //cout << "####################" << endl; 00109 //cout << "BesPolygon2D dtor called " << --num << endl; 00110 //cout << "####################" << endl; 00111 00112 if ( fP) delete [] fP; 00113 if ( fPBackUp) delete [] fPBackUp; 00114 }
|
|
info box
|
|
|
|
|
|
00072 { 00073 TObject::Delete(option); 00074 }
|
|
00072 { 00073 TObject::Delete(option); 00074 }
|
|
|
|
00174 { 00175 // 00176 // Compute the closest distance of approach from point px,py to the 00177 // center of this polygon 00178 // The distance is computed in pixels units. 00179 00180 const Int_t inaxis = 7; 00181 Int_t dist = 9999; 00182 00183 if (this->IsRotatable()) return dist; 00184 00185 Int_t puxmin = gPad->XtoAbsPixel(gPad->GetUxmin()); 00186 Int_t puymin = gPad->YtoAbsPixel(gPad->GetUymin()); 00187 Int_t puxmax = gPad->XtoAbsPixel(gPad->GetUxmax()); 00188 Int_t puymax = gPad->YtoAbsPixel(gPad->GetUymax()); 00189 00190 // return if point is not in the user area 00191 if (px < puxmin - inaxis) return dist; 00192 if (py > puymin + inaxis) return dist; 00193 if (px > puxmax + inaxis) return dist; 00194 if (py < puymax - inaxis) return dist; 00195 00196 // judge the mouse point and center are always on the same side of any line of ploygon 00197 // Transform to normalised desktop coordinates 00198 00199 BesView *view = (BesView*)gPad->GetView(); 00200 if (!view) return dist; 00201 00202 Bool_t inPolygon = true; 00203 Int_t x1, y1, x2, y2, cx, cy; 00204 Double_t Pndc[3], k, b, pb, cb; 00205 00206 view->WCtoNDC(&fCenter[0], Pndc); 00207 cx = gPad->XtoAbsPixel(Pndc[0]); 00208 cy = gPad->YtoAbsPixel(Pndc[1]); 00209 00210 //cout << "px " << px << " py " << py << endl; 00211 //cout << "center " << cx << " " << cy << endl; 00212 00213 for (Int_t i = 0; i < fN; i++) { 00214 view->WCtoNDC(&fP[3*i], Pndc); 00215 x1 = gPad->XtoAbsPixel(Pndc[0]); 00216 y1 = gPad->YtoAbsPixel(Pndc[1]); 00217 00218 if (i != fN-1) { 00219 view->WCtoNDC(&fP[3*(i+1)], Pndc); 00220 } 00221 else 00222 view->WCtoNDC(&fP[0], Pndc); 00223 00224 x2 = gPad->XtoAbsPixel(Pndc[0]); 00225 y2 = gPad->YtoAbsPixel(Pndc[1]); 00226 00227 //cout << "x1 " << x1 << " y1 " << y1 << endl; 00228 //cout << "x2 " << x2 << " y2 " << y2 << endl; 00229 if (x1 == x2) { 00230 if ((px-x1)*(cx-x1) <= 0) { 00231 inPolygon = false; 00232 break; 00233 } 00234 } 00235 else { 00236 k = Double_t(y2-y1)/(x2-x1); 00237 b = y1-k*x1; 00238 pb = py-k*px; 00239 cb = cy-k*cx; 00240 if ((pb-b)*(cb-b) <= 0) { 00241 inPolygon = false; 00242 break; 00243 } 00244 } 00245 } 00246 00247 if (inPolygon == true) { 00248 //gPad->SetSelected(this); 00249 //gPad->SetCursor(kHand); 00250 return 0; 00251 } 00252 else return 9999; 00253 00254 //cout << GetName() << dist << endl; 00255 //if (dist < 100) dist = 0; 00256 }
|
|
|
|
00118 { 00119 // 00120 // BesPolygon2D draw function 00121 TString opt = option; 00122 opt.ToUpper(); 00123 00124 AppendPad(option); 00125 }
|
|
00075 { 00076 TObject::DrawClass(); 00077 }
|
|
00075 { 00076 TObject::DrawClass(); 00077 }
|
|
00078 { 00079 TObject::DrawClone(option); 00080 }
|
|
00078 { 00079 TObject::DrawClone(option); 00080 }
|
|
|
|
00260 { 00261 //cout << "I am in " << GetName() << endl; 00262 00263 BesView *view = (BesView*)gPad->GetView(); 00264 if (view) view->ExecuteEvent(event, px, py); 00265 }
|
|
|
|
00334 { 00335 // 00336 // Compute geometric center of this polygon 00337 for ( Int_t i = 0; i < 3; i++ ) { 00338 Center[i] = 0; 00339 for ( Int_t j = 0; j < fN; j++ ) Center[i] += fP[3*j+i]; 00340 Center[i] /= fN; 00341 } 00342 }
|
|
|
|
00291 { 00292 00293 BesView *view = (BesView*)gPad->GetView(); 00294 if (view) return view->GetObjectInfo(px, py); 00295 else return TObject::GetObjectInfo(px, py); 00296 }
|
|
00060 {
00061 return fRotatable;
00062 }
|
|
00060 {
00061 return fRotatable;
00062 }
|
|
|
|
00129 { 00130 // 00131 // BesPolygon2D paint function 00132 TString opt = option; 00133 opt.ToUpper(); 00134 00135 // Transform to normalised desktop coordinates 00136 BesView *view = (BesView*)gPad->GetView(); 00137 if (view == 0) cout << "no view found" << endl; 00138 Double_t viewPhi = view->GetLongitude(); 00139 if (IsRotatable()) RotatePhi(viewPhi-180.0); 00140 00141 if (f_xx) { 00142 delete [] f_xx; 00143 f_xx = NULL; 00144 } 00145 if (f_yy) { 00146 delete [] f_yy; 00147 f_yy = NULL; 00148 } 00149 00150 f_xx = new Double_t[fN+1]; 00151 f_yy = new Double_t[fN+1]; 00152 Double_t Pndc[3]; 00153 00154 for ( Int_t i = 0; i < fN; i++ ) { 00155 view->WCtoNDC(&fP[i*3], Pndc); 00156 f_xx[i] = Pndc[0]; 00157 f_yy[i] = Pndc[1]; 00158 } 00159 00160 // Close surface 00161 f_xx[fN] = f_xx[0]; 00162 f_yy[fN] = f_yy[0]; 00163 00164 TAttLine::Modify(); //Change line attributes only if necessary 00165 TAttFill::Modify(); //Change fill attributes only if necessary 00166 00167 gPad->PaintFillArea(fN, f_xx, f_yy); 00168 gPad->PaintPolyLine(fN+1, f_xx, f_yy); 00169 if (IsRotatable()) Restore(); 00170 }
|
|
|
|
00316 { 00317 // 00318 // Resize the polygon by ScaleFactor 00319 00320 // Compute geometric center of the polygon 00321 Double_t C[3]; 00322 GetCenter(C); 00323 00324 // Rescale distances from the center 00325 for ( Int_t i = 0; i < 3; i++ ) { 00326 for ( Int_t j = 0; j < fN; j++ ) { 00327 fP[3*j+i] = C[i] + ScaleFactor*(fP[3*j+i]-C[i]); 00328 } 00329 } 00330 }
|
|
|
|
|
|
|
|
00346 { 00347 00348 //cout << "phi " << phi << endl; 00349 for (Int_t i = 0; i < fN; i++) { 00350 TVector3 vec(fP[i*3], fP[i*3+1], fP[i*3+2]); 00351 Double_t r = vec.Pt(); 00352 Double_t newPhi = vec.Phi() + phi*TMath::DegToRad(); 00353 fP[i*3] = r * cos(newPhi); 00354 fP[i*3+1] = r * sin(newPhi); 00355 } 00356 }
|
|
00081 { 00082 TObject::SetDrawOption(option); 00083 }
|
|
00081 { 00082 TObject::SetDrawOption(option); 00083 }
|
|
|
|
00269 { 00270 // 00271 // Set tooltip textbox with some information 00272 TView *view = (TView*)gPad->GetView(); 00273 Double_t Pndc[3]; 00274 view->WCtoNDC(&fP[0], Pndc); 00275 00276 if (fInfoBox){ 00277 delete fInfoBox; 00278 fInfoBox = 0; 00279 } 00280 fInfoBox = new TPaveText(Pndc[0], Pndc[1], 00281 Pndc[0]+0.4, Pndc[1]+0.1); 00282 fInfoBox->SetBorderSize(1); 00283 fInfoBox->SetFillColor(191); 00284 fInfoBox->AddText(GetTitle()); 00285 fInfoBox->AddText(GetObjectInfo(0,0)); 00286 fInfoBox->Draw(); 00287 }
|
|
00066 { 00067 TNamed::SetName(name); 00068 }
|
|
00066 { 00067 TNamed::SetName(name); 00068 }
|
|
|
|
|
|
00063 { 00064 fRotatable = input; 00065 }
|
|
00063 { 00064 fRotatable = input; 00065 }
|
|
|
|
00369 { 00370 00371 if (size > 0.95) size = 0.98; // too big could not see border 00372 if (size < 0.15) size = 0.2; // too small could not be seen 00373 00374 for (Int_t i = 0; i < 3; i++) { 00375 for (Int_t j = 0; j < fN; j++) { 00376 fP[3*j+i] = size * fP[3*j+i] + (1.0-size) * fCenter[i]; 00377 } 00378 } 00379 }
|
|
00069 { 00070 TNamed::SetTitle(name); 00071 }
|
|
00069 { 00070 TNamed::SetTitle(name); 00071 }
|
|
|
|
00300 { 00301 // 00302 // set sign of points for ZR view 00303 00304 for ( Int_t i = 0; i < fN; i++ ) { 00305 // clear sign 00306 fP[(i*3)+1] = TMath::Sign(1.,Double_t(fP[(i*3)+1])) * fP[(i*3)+1]; 00307 00308 // set sign 00309 fP[(i*3)+1] = TMath::Sign(1,sign) * fP[(i*3)+1]; 00310 } 00311 00312 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|