]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/GridStepper.cxx
First big commit of the mchview program and its accompanying library,
[u/mrichter/AliRoot.git] / EVE / Reve / GridStepper.cxx
1 // $Header$
2
3 #include "GridStepper.h"
4 #include "ZTrans.h"
5
6 using namespace Reve;
7
8 //______________________________________________________________________
9 // GridStepper
10 //
11 // Provide position coordinates for regular-grid placement of objects.
12 //
13
14 ClassImp(GridStepper)
15
16 GridStepper::GridStepper(Int_t sm) :
17   Mode(StepMode_e(sm)),
18   nx(0), ny(0), nz(0), Nx(0), Ny(0), Nz(0),
19   Dx(0), Dy(0), Dz(0), Ox(0), Oy(0), Oz(0)
20 {
21   switch(Mode) {
22   default:
23   case SM_XYZ:
24     ls[0] = &Nx; ls[1] = &Ny; ls[2] = &Nz;
25     ns[0] = &nx; ns[1] = &ny; ns[2] = &nz;
26     break;
27   case SM_YXZ:
28     ls[0] = &Ny; ls[1] = &Nx; ls[2] = &Nz;
29     ns[0] = &ny; ns[1] = &nx; ns[2] = &nz;
30     break;
31   case SM_XZY:
32     ls[0] = &Nx; ls[1] = &Nz; ls[2] = &Ny;
33     ns[0] = &nx; ns[1] = &nz; ns[2] = &ny;
34     break;
35   }
36
37   nx = ny = nz = 0;
38   Nx = Ny = Nz = 16;
39   Dx = Dy = Dz = 1;
40   Ox = Oy = Oz = 0;
41 }
42
43 void GridStepper::Reset()
44 {
45   nx = ny = nz = 0;
46 }
47
48 void GridStepper::Subtract(GridStepper& s)
49 {
50   Ox = -(s.Ox + s.nx*s.Dx);
51   Oy = -(s.Oy + s.ny*s.Dy);
52   Oz = -(s.Oz + s.nz*s.Dz);
53 }
54 /**************************************************************************/
55
56 Bool_t GridStepper::Step()
57 {
58   (*ns[0])++;
59   if (*ns[0] >= *ls[0]) {
60     *ns[0] = 0; (*ns[1])++;
61     if (*ns[1] >= *ls[1]) {
62       *ns[1] = 0; (*ns[2])++;
63       if (*ns[2] >= *ls[2]) {
64         return kFALSE;
65       }
66     }
67   }
68   return kTRUE;
69 }
70
71 /**************************************************************************/
72
73 void GridStepper::GetPosition(Float_t* p)
74 {
75   p[0] = Ox + nx*Dx; p[1] = Oy + ny*Dy; p[2] = Oz + nz*Dz;
76 }
77
78 void GridStepper::SetTrans(ZTrans* mx)
79 {
80   mx->SetPos(Ox + nx*Dx, Oy + ny*Dy, Oz + nz*Dz);
81 }
82
83 void GridStepper::SetTransAdvance(ZTrans* mx)
84 {
85   SetTrans(mx);
86   Step();
87 }