Changeset 653 for trunk/MagicSoft/Mars/mgui/MHexagon.cc
- Timestamp:
- 03/01/01 15:42:32 (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mgui/MHexagon.cc
r589 r653 1 #include <stdlib.h> 2 #include <fstream.h> 3 #include <iostream.h> 4 5 #include "TROOT.h" 6 #include "TVirtualPad.h" 7 #include "TMath.h" 8 9 #include "MHexagon.h" 10 1 // 2 // The class MHexagon is needed for the Event Display of 3 // MAGIC. 4 // 5 #include "MHexagon.h" 6 7 #include <TVirtualPad.h> // gPad 8 9 #include "MGeomPix.h" // GetX 11 10 12 11 ClassImp(MHexagon) 13 12 14 // 15 // The class MHexagon is needed for the Event Display of 16 // MAGIC. 17 18 19 20 MHexagon::MHexagon() : TObject(), TAttLine(), TAttFill() 13 MHexagon::MHexagon() 21 14 { 22 15 // default constructor for MHexagon … … 24 17 } 25 18 26 MHexagon::MHexagon(Float_t x, Float_t y, Float_t d ) : TObject(), TAttLine(), TAttFill(0, 1001) 19 MHexagon::MHexagon(Float_t x, Float_t y, Float_t d ) 20 : TAttFill(0, 1001), fX(x), fY(y), fD(d) 27 21 { 28 22 // normal constructor for MHexagon 29 fX = x ; 30 fY = y ; 31 fD = d ; 32 33 } 23 } 24 25 MHexagon::MHexagon(MGeomPix &pix) 26 : TAttFill(0, 1001) 27 { 28 // normal constructor for MHexagon 29 fX = pix.GetX(); 30 fY = pix.GetY(); 31 fD = pix.GetR(); 32 } 33 34 34 MHexagon::MHexagon( const MHexagon &hexagon) 35 35 { … … 41 41 { 42 42 // default destructor for MHexagon 43 44 43 } 45 44 … … 47 46 { 48 47 // copy this hexagon to hexagon 49 50 TObject::Copy ( obj ) ; 51 TAttLine::Copy (((MHexagon&) obj ) ) ; 52 TAttFill::Copy (((MHexagon&) obj ) ) ; 53 54 ((MHexagon&) obj).fX = fX ; 55 ((MHexagon&) obj).fY = fY ; 56 ((MHexagon&) obj).fD = fD ; 57 } 58 Int_t MHexagon::DistancetoPrimitive( Int_t px, Int_t py ) 59 { 60 // compute the distance of a point (px,py) to the Hexagon 61 // this functions needed for graphical primitives, that 62 // means without this function you are not able to interact 63 // with the graphical primitive with the mouse!!! 64 // 65 // All calcutations are running in pixel coordinates 66 67 // compute the distance of the Point to the center of the Hexagon 68 69 Int_t pxhex = gPad->XtoAbsPixel( fX ) ; 70 Int_t pyhex = gPad->YtoAbsPixel( fY ) ; 71 72 Double_t DistPointHexagon = TMath::Sqrt( Double_t ((pxhex-px)*(pxhex-px) + (pyhex-py)*(pyhex-py))) ; 73 Double_t cosa = TMath::Abs(px-pxhex) / DistPointHexagon ; 74 Double_t sina = TMath::Abs(py-pyhex) / DistPointHexagon ; 48 TObject::Copy ( obj ) ; 49 TAttLine::Copy (((MHexagon&) obj ) ) ; 50 TAttFill::Copy (((MHexagon&) obj ) ) ; 51 52 ((MHexagon&) obj).fX = fX ; 53 ((MHexagon&) obj).fY = fY ; 54 ((MHexagon&) obj).fD = fD ; 55 } 56 Int_t MHexagon::DistancetoPrimitive( Int_t px, Int_t py ) 57 { 58 // compute the distance of a point (px,py) to the Hexagon 59 // this functions needed for graphical primitives, that 60 // means without this function you are not able to interact 61 // with the graphical primitive with the mouse!!! 62 // 63 // All calcutations are running in pixel coordinates 64 65 // compute the distance of the Point to the center of the Hexagon 66 67 const Int_t pxhex = gPad->XtoAbsPixel( fX ) ; 68 const Int_t pyhex = gPad->YtoAbsPixel( fY ) ; 69 70 const Double_t DistPointHexagon = TMath::Sqrt( Double_t ((pxhex-px)*(pxhex-px) + (pyhex-py)*(pyhex-py))) ; 71 const Double_t cosa = TMath::Abs(px-pxhex) / DistPointHexagon ; 72 const Double_t sina = TMath::Abs(py-pyhex) / DistPointHexagon ; 75 73 76 74 // comput the distance to pixel border 77 75 78 Double_t dx = fD * cosa / 2 ;79 Double_t dy = fD * sina / 2 ;80 81 Double_t xborder = fX + dx ;82 Double_t yborder = fY + dy ;83 84 Int_t pxborder = gPad->XtoAbsPixel( xborder ) ;85 Int_t pyborder = gPad->YtoAbsPixel( yborder ) ;86 87 Double_t DistBorderHexagon = TMath::Sqrt( Double_t ((pxborder-pxhex)*(pxborder-pxhex)+(pyborder-pyhex)*(pyborder-pyhex))) ;76 const Double_t dx = fD * cosa / 2 ; 77 const Double_t dy = fD * sina / 2 ; 78 79 const Double_t xborder = fX + dx ; 80 const Double_t yborder = fY + dy ; 81 82 const Int_t pxborder = gPad->XtoAbsPixel( xborder ) ; 83 const Int_t pyborder = gPad->YtoAbsPixel( yborder ) ; 84 85 const Double_t DistBorderHexagon = TMath::Sqrt( Double_t ((pxborder-pxhex)*(pxborder-pxhex)+(pyborder-pyhex)*(pyborder-pyhex))) ; 88 86 89 87 … … 91 89 // here in the first implementation is just circle inside 92 90 93 if ( DistBorderHexagon < DistPointHexagon ) 94 return 999999 ; 95 else 96 // return Int_t ( DistBorderHexagon - DistPointHexagon ) ; 97 return 0 ; 91 return DistBorderHexagon < DistPointHexagon ? 999999 : 0; 98 92 } 99 93 … … 147 141 // list this hexagon with its attributes 148 142 TROOT::IndentLevel() ; 149 printf ("%s: X= %f Y= %f R= %f \n", GetName , fX, fY, fD ) ;143 printf ("%s: X= %f Y= %f R= %f \n", GetName(), fX, fY, fD ) ; 150 144 } 151 145 … … 164 158 const Int_t np = 6 ; 165 159 166 Float_t dx[np+1] = { .5 , 0. , -.5 , -.5 , 0. , .5 , .5 } ;167 Float_t dy[np+1] = { .2886, .5772, .2886, -.2886, -.5772, -.2886, .2886 } ;160 const Float_t dx[np+1] = { .5 , 0. , -.5 , -.5 , 0. , .5 , .5 } ; 161 const Float_t dy[np+1] = { .2886, .5772, .2886, -.2886, -.5772, -.2886, .2886 } ; 168 162 169 163 static Float_t x[np+1], y[np+1] ; … … 189 183 { 190 184 // print/dump this hexagon with its attributes 191 printf ("Ellipse: X= %f Y= %f R= %f ", fX, fY, fD ) ; 185 printf ("Ellipse: X= %f Y= %f R= %f ", fX, fY, fD ) ; 192 186 193 187 if ( GetLineColor() != 1 ) printf (" Color=%d", GetLineColor() ) ;
Note:
See TracChangeset
for help on using the changeset viewer.