BesPolygon2D Class Reference

#include <BesPolygon2D.h>

List of all members.

Public Member Functions

 BesPolygon2D ()
 info box
 BesPolygon2D (const char *name, const char *title, Int_t N, Double_t *P)
virtual ~BesPolygon2D ()
virtual void Draw (Option_t *option="")
virtual void Paint (Option_t *option="")
virtual char * GetObjectInfo (Int_t px, Int_t py) const
virtual void SetZRSign (Int_t sign)
virtual void Resize (Double_t ScaleFactor)
virtual Int_t DistancetoPrimitive (Int_t px, Int_t py)
virtual void ExecuteEvent (Int_t event, Int_t px, Int_t py)
virtual void SetInfoBox ()
virtual void GetCenter (Double_t *Center) const
virtual void RotatePhi (Double_t phi)
virtual void Restore ()
virtual void SetSize (Double_t size)
Bool_t IsRotatable ()
void SetRotatable (Bool_t input)
void SetName (const char *name)
void SetTitle (const char *name)
void Delete (Option_t *option)
void DrawClass ()
void DrawClone (Option_t *option)
void SetDrawOption (Option_t *option)
void SetPoints (Double_t *P)

Protected Attributes

Double_t * f_xx
Double_t * f_yy
Int_t fN
Double_t * fP
Double_t * fPBackUp
Double_t fCenter [3]
Bool_t fRotatable
TPaveText * fInfoBox

Static Private Attributes

static int num


Detailed Description

Definition at line 27 of file BesPolygon2D.h.


Constructor & Destructor Documentation

BesPolygon2D::BesPolygon2D (  ) 

info box

BesPolygon2D::BesPolygon2D ( const char *  name,
const char *  title,
Int_t  N,
Double_t *  P 
)

Definition at line 67 of file BesPolygon2D.cxx.

References f_xx, f_yy, fCenter, fInfoBox, fN, fP, fPBackUp, fRotatable, genRecEmupikp::i, ganga-rec::j, and SetPoints().

00068                                                  :
00069         TNamed(name, title), TAttLine(), TAttFill() {
00070     //
00071     // BesPolygon2D normal constructor
00072     //cout << "####################" << endl;
00073     //cout << "BesPolygon2D ctor called " << ++num << endl;
00074     //cout << "####################" << endl;
00075 
00076     fN = N;
00077     fP = new Double_t[fN*3];
00078     fPBackUp = new Double_t[fN*3];
00079     f_xx = NULL;
00080     f_yy = NULL;
00081 
00082     fInfoBox = 0;
00083     if (P!=NULL){
00084         SetPoints(P);
00085     }
00086 
00087     for ( Int_t i = 0; i < fN*3; i++ ) {
00088         fPBackUp[i] = fP[i];
00089     }
00090 
00091     for (Int_t j = 0; j < 3; j++) {
00092         fCenter[j] = 0.0;
00093         for ( Int_t i = 0; i < fN; i++) {
00094             fCenter[j] += fP[3*i+j];
00095         }
00096         fCenter[j] /= fN;
00097     }
00098 
00099     for ( Int_t i = 0; i < fN; i++ ) {
00100     }
00101 
00102     fRotatable = false;
00103 }

BesPolygon2D::~BesPolygon2D (  )  [virtual]

Definition at line 107 of file BesPolygon2D.cxx.

References fP, and fPBackUp.

00107                             {
00108     //
00109     // BesPolygon2D default destructor
00110     //cout << "####################" << endl;
00111     //cout << "BesPolygon2D dtor called " << --num << endl;
00112     //cout << "####################" << endl;
00113 
00114     if ( fP) delete [] fP;
00115     if ( fPBackUp) delete [] fPBackUp;
00116 }


Member Function Documentation

void BesPolygon2D::Delete ( Option_t *  option  )  [inline]

Definition at line 72 of file BesPolygon2D.h.

00072                                          {
00073         TObject::Delete(option);
00074     }

Int_t BesPolygon2D::DistancetoPrimitive ( Int_t  px,
Int_t  py 
) [virtual]

Definition at line 176 of file BesPolygon2D.cxx.

References check_raw_filter::dist, fCenter, fP, genRecEmupikp::i, and BesView::WCtoNDC().

Referenced by Tof2DScin::DistancetoPrimitive(), Muc2DStrip::DistancetoPrimitive(), and Emc2DCrystal::DistancetoPrimitive().

00176                                                           {
00177     //
00178     // Compute the closest distance of approach from point px,py to the
00179     // center of this polygon
00180     // The distance is computed in pixels units.
00181 
00182     const Int_t inaxis = 7;
00183     Int_t  dist = 9999;
00184 
00185     if (this->IsRotatable()) return dist;
00186 
00187     Int_t puxmin = gPad->XtoAbsPixel(gPad->GetUxmin());
00188     Int_t puymin = gPad->YtoAbsPixel(gPad->GetUymin());
00189     Int_t puxmax = gPad->XtoAbsPixel(gPad->GetUxmax());
00190     Int_t puymax = gPad->YtoAbsPixel(gPad->GetUymax());
00191 
00192     // return if point is not in the user area
00193     if (px < puxmin - inaxis) return dist;
00194     if (py > puymin + inaxis) return dist;
00195     if (px > puxmax + inaxis) return dist;
00196     if (py < puymax - inaxis) return dist;
00197 
00198     // judge the mouse point and center are always on the same side of any line of ploygon
00199     // Transform to normalised desktop coordinates
00200 
00201     BesView *view = (BesView*)gPad->GetView();
00202     if (!view) return dist;
00203 
00204     Bool_t inPolygon = true;
00205     Int_t x1, y1, x2, y2, cx, cy;
00206     Double_t Pndc[3], k, b, pb, cb;
00207 
00208     view->WCtoNDC(&fCenter[0], Pndc);
00209     cx = gPad->XtoAbsPixel(Pndc[0]);
00210     cy = gPad->YtoAbsPixel(Pndc[1]);
00211 
00212     //cout << "px " << px << " py " << py << endl;
00213     //cout << "center " << cx << " " << cy << endl;
00214 
00215     for (Int_t i = 0; i < fN; i++) {
00216         view->WCtoNDC(&fP[3*i], Pndc);
00217         x1 = gPad->XtoAbsPixel(Pndc[0]);
00218         y1 = gPad->YtoAbsPixel(Pndc[1]);
00219 
00220         if (i != fN-1) {
00221             view->WCtoNDC(&fP[3*(i+1)], Pndc);
00222         }
00223         else
00224             view->WCtoNDC(&fP[0], Pndc);
00225 
00226         x2 = gPad->XtoAbsPixel(Pndc[0]);
00227         y2 = gPad->YtoAbsPixel(Pndc[1]);
00228 
00229         //cout << "x1 " << x1 << " y1 " << y1 << endl;
00230         //cout << "x2 " << x2 << " y2 " << y2 << endl;
00231         if (x1 == x2) {
00232             if ((px-x1)*(cx-x1) <= 0) {
00233                 inPolygon = false;
00234                 break;
00235             }
00236         }
00237         else {
00238             k = Double_t(y2-y1)/(x2-x1);
00239             b  = y1-k*x1;
00240             pb = py-k*px;
00241             cb = cy-k*cx;
00242             if ((pb-b)*(cb-b) <= 0) {
00243                 inPolygon = false;
00244                 break;
00245             }
00246         }
00247     }
00248 
00249     if (inPolygon == true) {
00250         //gPad->SetSelected(this);
00251         //gPad->SetCursor(kHand);
00252         return 0;
00253     }
00254     else return 9999;
00255 
00256     //cout << GetName() << dist << endl;
00257     //if (dist < 100) dist = 0;
00258 }

void BesPolygon2D::Draw ( Option_t *  option = ""  )  [virtual]

Definition at line 120 of file BesPolygon2D.cxx.

Referenced by MucROOTGeo::Draw(), MdcROOTGeo::Draw(), BesGeometry::Draw2DXY(), and BesGeometry::Draw2DZR().

00120                                         {
00121     //
00122     // BesPolygon2D draw function
00123     TString opt = option;
00124     opt.ToUpper();
00125 
00126     AppendPad(option);
00127 }

void BesPolygon2D::DrawClass (  )  [inline]

Definition at line 75 of file BesPolygon2D.h.

00075                             {
00076         TObject::DrawClass();
00077     }

void BesPolygon2D::DrawClone ( Option_t *  option  )  [inline]

Definition at line 78 of file BesPolygon2D.h.

00078                                             {
00079         TObject::DrawClone(option);
00080     }

void BesPolygon2D::ExecuteEvent ( Int_t  event,
Int_t  px,
Int_t  py 
) [virtual]

Definition at line 262 of file BesPolygon2D.cxx.

References BesView::ExecuteEvent().

00262                                                                {
00263     //cout << "I am in " << GetName() << endl;
00264 
00265     BesView *view = (BesView*)gPad->GetView();
00266     if (view) view->ExecuteEvent(event, px, py);
00267 }

void BesPolygon2D::GetCenter ( Double_t *  Center  )  const [virtual]

Definition at line 336 of file BesPolygon2D.cxx.

References fP, genRecEmupikp::i, and ganga-rec::j.

Referenced by Resize().

00336                                                    {
00337     //
00338     // Compute geometric center of this polygon
00339     for ( Int_t i = 0; i < 3; i++ ) {
00340         Center[i] = 0;
00341         for ( Int_t j = 0; j < fN; j++ ) Center[i] += fP[3*j+i];
00342         Center[i] /= fN;
00343     }
00344 }

char * BesPolygon2D::GetObjectInfo ( Int_t  px,
Int_t  py 
) const [virtual]

Definition at line 293 of file BesPolygon2D.cxx.

References BesView::GetObjectInfo().

Referenced by SetInfoBox().

00293                                                           {
00294 
00295     BesView *view = (BesView*)gPad->GetView();
00296     if (view) return view->GetObjectInfo(px, py);
00297     else return TObject::GetObjectInfo(px, py);
00298 }

Bool_t BesPolygon2D::IsRotatable (  )  [inline]

Definition at line 60 of file BesPolygon2D.h.

References fRotatable.

Referenced by Paint().

00060                                 {
00061         return fRotatable;
00062     }

void BesPolygon2D::Paint ( Option_t *  option = ""  )  [virtual]

Definition at line 131 of file BesPolygon2D.cxx.

References f_xx, f_yy, fP, BesTView::GetLongitude(), genRecEmupikp::i, IsRotatable(), Restore(), RotatePhi(), and BesView::WCtoNDC().

Referenced by Tof2DScin::Paint(), Mdc2DWire::Paint(), and Emc2DCrystal::Paint().

00131                                          {
00132     //
00133     // BesPolygon2D paint function
00134     TString opt = option;
00135     opt.ToUpper();
00136 
00137     // Transform to normalised desktop coordinates
00138     BesView *view = (BesView*)gPad->GetView();
00139     if (view == 0) cout << "no view found" << endl;
00140     Double_t viewPhi = view->GetLongitude();
00141     if (IsRotatable()) RotatePhi(viewPhi-180.0);
00142 
00143     if (f_xx) {
00144         delete [] f_xx;
00145         f_xx = NULL;
00146     }
00147     if (f_yy) {
00148         delete [] f_yy;
00149         f_yy = NULL;
00150     }
00151 
00152     f_xx = new Double_t[fN+1];
00153     f_yy = new Double_t[fN+1];
00154     Double_t Pndc[3];
00155 
00156     for ( Int_t i = 0; i < fN; i++ ) {
00157         view->WCtoNDC(&fP[i*3], Pndc);
00158         f_xx[i] = Pndc[0];
00159         f_yy[i] = Pndc[1];
00160     }
00161 
00162     // Close surface
00163     f_xx[fN] = f_xx[0];
00164     f_yy[fN] = f_yy[0];
00165 
00166     TAttLine::Modify();  //Change line attributes only if necessary
00167     TAttFill::Modify();  //Change fill attributes only if necessary
00168 
00169     gPad->PaintFillArea(fN, f_xx, f_yy);
00170     gPad->PaintPolyLine(fN+1, f_xx, f_yy);
00171     if (IsRotatable()) Restore();
00172 }

void BesPolygon2D::Resize ( Double_t  ScaleFactor  )  [virtual]

Definition at line 318 of file BesPolygon2D.cxx.

References EvtCyclic3::C, fP, GetCenter(), genRecEmupikp::i, and ganga-rec::j.

00318                                               {
00319     //
00320     // Resize the polygon by ScaleFactor
00321 
00322     // Compute geometric center of the polygon
00323     Double_t C[3];
00324     GetCenter(C);
00325 
00326     // Rescale distances from the center
00327     for ( Int_t i = 0; i < 3; i++ ) {
00328         for ( Int_t j = 0; j < fN; j++ ) {
00329             fP[3*j+i] = C[i] + ScaleFactor*(fP[3*j+i]-C[i]);
00330         }
00331     }
00332 }

void BesPolygon2D::Restore (  )  [virtual]

Definition at line 362 of file BesPolygon2D.cxx.

References fP, fPBackUp, and genRecEmupikp::i.

Referenced by Paint().

00362                            {
00363 
00364     for (Int_t i = 0; i < fN*3; i++) {
00365         fP[i] = fPBackUp[i];
00366     }
00367 }

void BesPolygon2D::RotatePhi ( Double_t  phi  )  [virtual]

Definition at line 348 of file BesPolygon2D.cxx.

References cos(), fP, genRecEmupikp::i, sin(), and vec.

Referenced by Paint().

00348                                          {
00349 
00350     //cout << "phi " << phi << endl;
00351     for (Int_t i = 0; i < fN; i++) {
00352         TVector3 vec(fP[i*3], fP[i*3+1], fP[i*3+2]);
00353         Double_t r = vec.Pt();
00354         Double_t newPhi = vec.Phi() + phi*TMath::DegToRad();
00355         fP[i*3]   = r * cos(newPhi);
00356         fP[i*3+1] = r * sin(newPhi);
00357     }
00358 }

void BesPolygon2D::SetDrawOption ( Option_t *  option  )  [inline]

Definition at line 81 of file BesPolygon2D.h.

00081                                                 {
00082         TObject::SetDrawOption(option);
00083     }

void BesPolygon2D::SetInfoBox (  )  [virtual]

Definition at line 271 of file BesPolygon2D.cxx.

References fInfoBox, fP, and GetObjectInfo().

00271                               {
00272     //
00273     // Set tooltip textbox with some information
00274     TView *view = (TView*)gPad->GetView();
00275     Double_t Pndc[3];
00276     view->WCtoNDC(&fP[0], Pndc);
00277 
00278     if (fInfoBox){
00279         delete fInfoBox;
00280         fInfoBox = 0;
00281     }
00282     fInfoBox  = new TPaveText(Pndc[0], Pndc[1],
00283                               Pndc[0]+0.4, Pndc[1]+0.1);
00284     fInfoBox->SetBorderSize(1);
00285     fInfoBox->SetFillColor(191);
00286     fInfoBox->AddText(GetTitle());
00287     fInfoBox->AddText(GetObjectInfo(0,0));
00288     fInfoBox->Draw();
00289 }

void BesPolygon2D::SetName ( const char *  name  )  [inline]

Definition at line 66 of file BesPolygon2D.h.

00066                                           {
00067         TNamed::SetName(name);
00068     }

void BesPolygon2D::SetPoints ( Double_t *  P  )  [inline]

Definition at line 84 of file BesPolygon2D.h.

References fN, fP, and genRecEmupikp::i.

Referenced by BesPolygon2D().

00084                                        {
00085         for ( Int_t i = 0; i < fN*3; i++ ) fP[i] = P[i];
00086     }

void BesPolygon2D::SetRotatable ( Bool_t  input  )  [inline]

Definition at line 63 of file BesPolygon2D.h.

References fRotatable.

Referenced by MucROOTGeo::Draw(), and BesGeometry::InitGeometry().

00063                                            {
00064         fRotatable = input;
00065     }

void BesPolygon2D::SetSize ( Double_t  size  )  [virtual]

Definition at line 371 of file BesPolygon2D.cxx.

References fCenter, fP, genRecEmupikp::i, and ganga-rec::j.

00371                                         {
00372 
00373     if (size > 0.95) size = 0.98; // too big could not see border
00374     if (size < 0.15) size = 0.2; // too small could not be seen
00375 
00376     for (Int_t i = 0; i < 3; i++) {
00377         for (Int_t j = 0; j < fN; j++) {
00378             fP[3*j+i] = size * fP[3*j+i] + (1.0-size) * fCenter[i];
00379         }
00380     }
00381 }

void BesPolygon2D::SetTitle ( const char *  name  )  [inline]

Definition at line 69 of file BesPolygon2D.h.

00069                                            {
00070         TNamed::SetTitle(name);
00071     }

void BesPolygon2D::SetZRSign ( Int_t  sign  )  [virtual]

Definition at line 302 of file BesPolygon2D.cxx.

References fP, and genRecEmupikp::i.

00302                                        {
00303     //
00304     // set sign of points for ZR view
00305 
00306     for ( Int_t i = 0; i < fN; i++ ) {
00307         // clear sign
00308         fP[(i*3)+1] = TMath::Sign(1.,Double_t(fP[(i*3)+1])) * fP[(i*3)+1];
00309 
00310         // set sign
00311         fP[(i*3)+1] = TMath::Sign(1,sign) * fP[(i*3)+1];
00312     }
00313 
00314 }


Member Data Documentation

Double_t* BesPolygon2D::f_xx [protected]

Definition at line 31 of file BesPolygon2D.h.

Referenced by BesPolygon2D(), and Paint().

Double_t* BesPolygon2D::f_yy [protected]

Definition at line 32 of file BesPolygon2D.h.

Referenced by BesPolygon2D(), and Paint().

Double_t BesPolygon2D::fCenter[3] [protected]

Definition at line 36 of file BesPolygon2D.h.

Referenced by BesPolygon2D(), DistancetoPrimitive(), and SetSize().

TPaveText* BesPolygon2D::fInfoBox [protected]

Definition at line 39 of file BesPolygon2D.h.

Referenced by BesPolygon2D(), and SetInfoBox().

Int_t BesPolygon2D::fN [protected]

Definition at line 33 of file BesPolygon2D.h.

Referenced by BesPolygon2D(), and SetPoints().

Double_t* BesPolygon2D::fP [protected]

Definition at line 34 of file BesPolygon2D.h.

Referenced by BesPolygon2D(), DistancetoPrimitive(), GetCenter(), Paint(), Resize(), Restore(), RotatePhi(), SetInfoBox(), SetPoints(), SetSize(), SetZRSign(), and ~BesPolygon2D().

Double_t* BesPolygon2D::fPBackUp [protected]

Definition at line 35 of file BesPolygon2D.h.

Referenced by BesPolygon2D(), Restore(), and ~BesPolygon2D().

Bool_t BesPolygon2D::fRotatable [protected]

Definition at line 37 of file BesPolygon2D.h.

Referenced by BesPolygon2D(), IsRotatable(), and SetRotatable().

int BesPolygon2D::num [static, private]

Definition at line 29 of file BesPolygon2D.h.


Generated on Tue Nov 29 23:17:34 2016 for BOSS_7.0.2 by  doxygen 1.4.7