/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/EventDisplay/BesVisLib/BesVisLib-00-04-04/src/BesCircle2D.cxx

Go to the documentation of this file.
00001 //
00002 // BesCircle2D.cxx
00003 //
00004 // $Author: zhangy $
00005 // 2005/7/16
00006 // Modified from zevis 2D shape
00007 //
00008 
00009 #include <TString.h>
00010 #include <TPad.h>
00011 #include <TMath.h>
00012 
00013 #include "BesVisLib/BesCircle2D.h"
00014 #include "BesVisLib/BesView.h"
00015 #include <iostream>
00016 
00017 using namespace std;
00018 
00019 #ifndef __CINT__
00020 ClassImp(BesCircle2D)
00021 #endif
00022 
00023 //_____________________________________________________
00024 // BesCircle2D
00025 // Circle in 2D
00026 //
00027 //
00028 BesCircle2D::BesCircle2D() {
00029     //
00030     // BesCircle2D default constructor
00031     if ( gDebug ) cout << "BesCircle2D ctor called" << endl;
00032     fInnerRadius = 0;
00033     fOuterRadius = 0;
00034     fCenter = 0;
00035     fNSegment = 40;
00036     f_innerCircleX = NULL;
00037     f_innerCircleY = NULL;
00038     f_outerCircleX = NULL;
00039     f_outerCircleY = NULL;
00040     f_areaX = NULL;
00041     f_areaY = NULL;
00042 }
00043 
00044 //_____________________________________________________
00045 
00046 BesCircle2D::BesCircle2D(const char* name, const char* title, Double_t innerRadius, Double_t outerRadius, Double_t *center) :
00047         TNamed(name, title), TAttLine(), TAttFill() {
00048     //
00049     // BesCircle2D normal constructor
00050     if ( gDebug ) cout << "BesCircle2D normal ctor called" << endl;
00051 
00052     fCenter = new Double_t[3];
00053     for ( Int_t i = 0; i < 3; i++ ) fCenter[i] = center[i];
00054     fInnerRadius = new Double_t[3];
00055     fOuterRadius = new Double_t[3];
00056     fInnerRadius[0]=innerRadius;
00057     fOuterRadius[0]=outerRadius;
00058     fNSegment = 40;
00059     f_innerCircleX = NULL;
00060     f_innerCircleY = NULL;
00061     f_outerCircleX = NULL;
00062     f_outerCircleY = NULL;
00063     f_areaX = NULL;
00064     f_areaY = NULL;
00065 }
00066 
00067 //_____________________________________________________
00068 
00069 BesCircle2D::~BesCircle2D() {
00070     //
00071     // BesCircle2D default destructor
00072     if ( gDebug ) cout << "BesCircle2D default dtor called" << endl;
00073 
00074     delete fCenter;
00075     delete fInnerRadius;
00076     delete fOuterRadius;
00077 }
00078 
00079 //_____________________________________________________
00080 
00081 Int_t BesCircle2D::DistancetoPrimitive(Int_t px, Int_t py) {
00082 
00083     const Int_t inaxis = 7;
00084     Int_t dist = 9999;
00085 
00086     Int_t puxmin = gPad->XtoAbsPixel(gPad->GetUxmin());
00087     Int_t puymin = gPad->YtoAbsPixel(gPad->GetUymin());
00088     Int_t puxmax = gPad->XtoAbsPixel(gPad->GetUxmax());
00089     Int_t puymax = gPad->YtoAbsPixel(gPad->GetUymax());
00090 
00091     // return if point is not in the user area
00092     if (px < puxmin - inaxis) return dist;
00093     if (py > puymin + inaxis) return dist;
00094     if (px > puxmax + inaxis) return dist;
00095     if (py < puymax - inaxis) return dist;
00096 
00097     BesView *view = (BesView*)gPad->GetView();
00098     if (!view) return dist;
00099 
00100     Double_t x = gPad->PadtoX(gPad->AbsPixeltoX(px));
00101     Double_t y = gPad->PadtoY(gPad->AbsPixeltoY(py));
00102     Double_t xndc[3];
00103     //if (view->GetViewType() & kXYView)
00104     xndc[0] = x;
00105     xndc[1] = y;
00106     xndc[2] = 0;
00107     //cout << "NDC    X:" << xndc[0] << " Y:" << xndc[1] << endl;
00108 
00109     Double_t xwc[3];
00110     view->NDCtoWC(xndc, xwc);
00111     //cout << "WC     X:" << xwc[0] << " Y:" << xwc[1] << endl;
00112     //cout << "Center X:" << fCenter[0] << " Y:" << fCenter[1] << endl;
00113 
00114     Double_t distw = 0.0;
00115     for (Int_t i = 0; i < 2; i++) {
00116         distw += (xwc[i]-fCenter[i]) * (xwc[i]-fCenter[i]);
00117     }
00118 
00119     if (distw >= fInnerRadius[0]*fInnerRadius[0] &&
00120             distw <= fOuterRadius[0]*fOuterRadius[0])
00121         return 0;
00122     else
00123         return dist;
00124 }
00125 
00126 //_____________________________________________________
00127 
00128 void BesCircle2D::ExecuteEvent(Int_t event, Int_t px, Int_t py) {
00129     //cout << "I am in " << GetName() << endl;
00130 
00131     BesView *view = (BesView*)gPad->GetView();
00132     if (view) view->ExecuteEvent(event, px, py);
00133 }
00134 
00135 //_____________________________________________________
00136 
00137 void BesCircle2D::Draw(Option_t *option) {
00138     //
00139     // BesCircle2D draw function
00140     TString opt = option;
00141     opt.ToUpper();
00142 
00143     AppendPad(option);
00144 }
00145 
00146 //_____________________________________________________
00147 
00148 void BesCircle2D::Paint(Option_t *option) {
00149     // BesCircle2D paint function
00150     TString opt = option;
00151     opt.ToUpper();
00152 
00153     // Transform to normalised desktop coordinates
00154     BesView *view = (BesView*)gPad->GetView();
00155     if (view == 0) cout << "no view found" << endl;
00156 
00157     // Draw Painted area between circles as PaintFilledArea
00158     Int_t np = fNSegment; //40;
00159 
00160     if (f_innerCircleX){
00161         delete [] f_innerCircleX;
00162         f_innerCircleX = NULL;
00163     }
00164     if (f_innerCircleY){
00165         delete [] f_innerCircleY;
00166         f_innerCircleY = NULL;
00167     }
00168     if (f_outerCircleX){
00169         delete [] f_outerCircleX;
00170         f_outerCircleX = NULL;
00171     }
00172     if (f_outerCircleY){
00173         delete [] f_outerCircleY;
00174         f_outerCircleY = NULL;
00175     }
00176     if (f_areaX) {
00177         delete [] f_areaX;
00178         f_areaX = NULL;
00179     }
00180     if (f_areaY) {
00181         delete [] f_areaY;
00182         f_areaY = NULL;
00183     }
00184 
00185     f_innerCircleX = new Double_t[np+1];
00186     f_innerCircleY = new Double_t[np+1];
00187     f_outerCircleX = new Double_t[np+1];
00188     f_outerCircleY = new Double_t[np+1];
00189     f_areaX = new Double_t[4*np];
00190     f_areaY = new Double_t[4*np];
00191 
00192     TAttLine::Modify();  //Change line attributes only if necessary
00193     TAttFill::Modify();  //Change fill attributes only if necessary
00194 
00195     Double_t angle;
00196     Double_t dphi = 2*TMath::Pi()/(np);
00197     Double_t pointWC[3],pointNDC[3];
00198 
00199     for (Int_t i=0; i< np ; i++) {
00200         angle = Double_t(i)*dphi;
00201 
00202         // inner circle
00203         pointWC[0] = fCenter[0] + fInnerRadius[0]*TMath::Cos(angle);
00204         pointWC[1] = fCenter[1] + fInnerRadius[0]*TMath::Sin(angle);
00205         pointWC[2] = fCenter[2];
00206         view->WCtoNDC(pointWC,pointNDC);
00207         f_innerCircleX[i] = pointNDC[0];
00208         f_innerCircleY[i] = pointNDC[1];
00209         f_areaX[4*i] = pointNDC[0];
00210         f_areaY[4*i] = pointNDC[1];
00211         if ( i == 0 ) {
00212             f_areaX[4*np - 3] = pointNDC[0];
00213             f_areaY[4*np - 3] = pointNDC[1];
00214         } else {
00215             f_areaX[4*i - 3] = pointNDC[0];
00216             f_areaY[4*i - 3] = pointNDC[1];
00217         }
00218 
00219         // outer circle
00220         pointWC[0] = fCenter[0] + fOuterRadius[0]*TMath::Cos(angle);
00221         pointWC[1] = fCenter[1] + fOuterRadius[0]*TMath::Sin(angle);
00222         pointWC[2] = fCenter[2];
00223         view->WCtoNDC(pointWC,pointNDC);
00224         f_outerCircleX[i] = pointNDC[0];
00225         f_outerCircleY[i] = pointNDC[1];
00226         f_areaX[4*i + 3] = pointNDC[0];
00227         f_areaY[4*i + 3] = pointNDC[1];
00228         if ( i == 0 ) {
00229             f_areaX[4*np - 2] = pointNDC[0];
00230             f_areaY[4*np - 2] = pointNDC[1];
00231         } else {
00232             f_areaX[4*i - 2] = pointNDC[0];
00233             f_areaY[4*i - 2] = pointNDC[1];
00234         }
00235 
00236     }
00237 
00238     // last point for circles
00239     f_innerCircleX[np] = f_innerCircleX[0];
00240     f_innerCircleY[np] = f_innerCircleY[0];
00241     f_outerCircleX[np] = f_outerCircleX[0];
00242     f_outerCircleY[np] = f_outerCircleY[0];
00243 
00244     // paint filled areas
00245     for (Int_t i = 0; i < np; i++ ) {
00246         gPad->PaintFillArea(4,&f_areaX[4*i],&f_areaY[4*i]);
00247     }
00248 
00249     // paint circles
00250     // yzhang
00251     gPad->PaintPolyLine(np+1,f_innerCircleX,f_innerCircleY);
00252     gPad->PaintPolyLine(np+1,f_outerCircleX,f_outerCircleY);
00253 
00254 }
00255 //_____________________________________________________
00256 
00257 char *BesCircle2D::GetObjectInfo(Int_t px, Int_t py) const {
00258 
00259     BesView *view = (BesView*)gPad->GetView();
00260     if (view) return view->GetObjectInfo(px, py);
00261     else return TObject::GetObjectInfo(px, py);
00262 }
00263 
00264 //_____________________________________________________
00265 
00266 void BesCircle2D::SetCenter(Double_t x, Double_t y, Double_t z)
00267 {
00268     fCenter[0] = x;
00269     fCenter[1] = y;
00270     fCenter[2] = z;
00271 }
00272 
00273 //_____________________________________________________
00274 
00275 void BesCircle2D::GetCenter(Double_t *center)
00276 {
00277     for (Int_t i = 0; i < 3; i++) center[i] = fCenter[i];
00278 }

Generated on Tue Nov 29 23:12:04 2016 for BOSS_7.0.2 by  doxygen 1.4.7