Ignore:
Timestamp:
03/01/01 15:42:32 (24 years ago)
Author:
tbretz
Message:
*** empty log message ***
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
    1110
    1211ClassImp(MHexagon)
    1312
    14   //
    15   //  The class MHexagon is needed for the Event Display of
    16   //  MAGIC.
    17 
    18 
    19 
    20 MHexagon::MHexagon() : TObject(), TAttLine(), TAttFill()
     13MHexagon::MHexagon()
    2114{
    2215  //   default constructor for MHexagon
     
    2417}
    2518
    26 MHexagon::MHexagon(Float_t x, Float_t y, Float_t d ) : TObject(), TAttLine(), TAttFill(0, 1001)
     19MHexagon::MHexagon(Float_t x, Float_t y, Float_t d )
     20 : TAttFill(0, 1001), fX(x), fY(y), fD(d)
    2721{
    2822  //    normal constructor for MHexagon
    29   fX = x ;
    30   fY = y ;
    31   fD = d ;
    32 
    33 }
     23}
     24
     25MHexagon::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
    3434MHexagon::MHexagon( const MHexagon &hexagon)
    3535{
     
    4141{
    4242  //     default destructor for MHexagon
    43 
    4443
    4544
     
    4746{
    4847  //     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}
     56Int_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 ;
    7573
    7674  //       comput the distance to pixel border
    7775 
    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))) ; 
    8886 
    8987 
     
    9189  //       here in the first implementation is just circle inside
    9290
    93   if ( DistBorderHexagon <  DistPointHexagon )
    94     return 999999 ;
    95   else   
    96     //  return Int_t ( DistBorderHexagon - DistPointHexagon ) ;
    97     return 0 ;
     91  return DistBorderHexagon <  DistPointHexagon ? 999999 : 0;
    9892}
    9993
     
    147141  //     list this hexagon with its attributes
    148142  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 ) ;
    150144}
    151145
     
    164158  const Int_t np =  6 ;
    165159 
    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 } ;
    168162
    169163  static Float_t x[np+1], y[np+1] ;
     
    189183{
    190184  //     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 ) ;
    192186 
    193187  if ( GetLineColor() != 1 ) printf (" Color=%d", GetLineColor() ) ;
Note: See TracChangeset for help on using the changeset viewer.