// @(#)root/eve:$Id$
// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007

/*************************************************************************
 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "TEveGridStepper.h"
#include "TEveTrans.h"

//______________________________________________________________________________
// TEveGridStepper
//
// Provide discrete position coordinates for placement of objects on
// regular grids.

ClassImp(TEveGridStepper)

//______________________________________________________________________________
TEveGridStepper::TEveGridStepper(Int_t sm) :
   fMode(EStepMode_e(sm)),
   fCx(0), fCy(0), fCz(0), fNx(0), fNy(0), fNz(0),
   fDx(0), fDy(0), fDz(0), fOx(0), fOy(0), fOz(0)
{
   // Constructor.

   switch(fMode) {
      default:
      case kSM_XYZ:
         fLimitArr[0] = &fNx; fLimitArr[1] = &fNy; fLimitArr[2] = &fNz;
         fValueArr[0] = &fCx; fValueArr[1] = &fCy; fValueArr[2] = &fCz;
         break;
      case kSM_YXZ:
         fLimitArr[0] = &fNy; fLimitArr[1] = &fNx; fLimitArr[2] = &fNz;
         fValueArr[0] = &fCy; fValueArr[1] = &fCx; fValueArr[2] = &fCz;
         break;
      case kSM_XZY:
         fLimitArr[0] = &fNx; fLimitArr[1] = &fNz; fLimitArr[2] = &fNy;
         fValueArr[0] = &fCx; fValueArr[1] = &fCz; fValueArr[2] = &fCy;
         break;
   }

   fCx = fCy = fCz = 0;
   fNx = fNy = fNz = 16;
   fDx = fDy = fDz = 1;
   fOx = fOy = fOz = 0;
}

//______________________________________________________________________________
void TEveGridStepper::Reset()
{
   // Reset position to origin.

   fCx = fCy = fCz = 0;
}

//______________________________________________________________________________
void TEveGridStepper::Subtract(TEveGridStepper& s)
{
   // Subtract current position of 's' from origin of this.

   fOx = -(s.fOx + s.fCx*s.fDx);
   fOy = -(s.fOy + s.fCy*s.fDy);
   fOz = -(s.fOz + s.fCz*s.fDz);
}

/******************************************************************************/

//______________________________________________________________________________
Bool_t TEveGridStepper::Step()
{
   // Move to the next grid position.

   (*fValueArr[0])++;
   if (*fValueArr[0] >= *fLimitArr[0]) {
      *fValueArr[0] = 0; (*fValueArr[1])++;
      if (*fValueArr[1] >= *fLimitArr[1]) {
         *fValueArr[1] = 0; (*fValueArr[2])++;
         if (*fValueArr[2] >= *fLimitArr[2]) {
            return kFALSE;
         }
      }
   }
   return kTRUE;
}

/******************************************************************************/

//______________________________________________________________________________
void TEveGridStepper::GetPosition(Float_t* p)
{
   // Get current position.

   p[0] = fOx + fCx*fDx;
   p[1] = fOy + fCy*fDy;
   p[2] = fOz + fCz*fDz;
}

//______________________________________________________________________________
void TEveGridStepper::SetTrans(TEveTrans* mx)
{
   // Set position into the translation part of mx.

   mx->SetPos(fOx + fCx*fDx, fOy + fCy*fDy, fOz + fCz*fDz);
}

//______________________________________________________________________________
void TEveGridStepper::SetTransAdvance(TEveTrans* mx)
{
   // Set position into the translation part of mx and advance to the
   // next grid position.

   SetTrans(mx);
   Step();
}
 TEveGridStepper.cxx:1
 TEveGridStepper.cxx:2
 TEveGridStepper.cxx:3
 TEveGridStepper.cxx:4
 TEveGridStepper.cxx:5
 TEveGridStepper.cxx:6
 TEveGridStepper.cxx:7
 TEveGridStepper.cxx:8
 TEveGridStepper.cxx:9
 TEveGridStepper.cxx:10
 TEveGridStepper.cxx:11
 TEveGridStepper.cxx:12
 TEveGridStepper.cxx:13
 TEveGridStepper.cxx:14
 TEveGridStepper.cxx:15
 TEveGridStepper.cxx:16
 TEveGridStepper.cxx:17
 TEveGridStepper.cxx:18
 TEveGridStepper.cxx:19
 TEveGridStepper.cxx:20
 TEveGridStepper.cxx:21
 TEveGridStepper.cxx:22
 TEveGridStepper.cxx:23
 TEveGridStepper.cxx:24
 TEveGridStepper.cxx:25
 TEveGridStepper.cxx:26
 TEveGridStepper.cxx:27
 TEveGridStepper.cxx:28
 TEveGridStepper.cxx:29
 TEveGridStepper.cxx:30
 TEveGridStepper.cxx:31
 TEveGridStepper.cxx:32
 TEveGridStepper.cxx:33
 TEveGridStepper.cxx:34
 TEveGridStepper.cxx:35
 TEveGridStepper.cxx:36
 TEveGridStepper.cxx:37
 TEveGridStepper.cxx:38
 TEveGridStepper.cxx:39
 TEveGridStepper.cxx:40
 TEveGridStepper.cxx:41
 TEveGridStepper.cxx:42
 TEveGridStepper.cxx:43
 TEveGridStepper.cxx:44
 TEveGridStepper.cxx:45
 TEveGridStepper.cxx:46
 TEveGridStepper.cxx:47
 TEveGridStepper.cxx:48
 TEveGridStepper.cxx:49
 TEveGridStepper.cxx:50
 TEveGridStepper.cxx:51
 TEveGridStepper.cxx:52
 TEveGridStepper.cxx:53
 TEveGridStepper.cxx:54
 TEveGridStepper.cxx:55
 TEveGridStepper.cxx:56
 TEveGridStepper.cxx:57
 TEveGridStepper.cxx:58
 TEveGridStepper.cxx:59
 TEveGridStepper.cxx:60
 TEveGridStepper.cxx:61
 TEveGridStepper.cxx:62
 TEveGridStepper.cxx:63
 TEveGridStepper.cxx:64
 TEveGridStepper.cxx:65
 TEveGridStepper.cxx:66
 TEveGridStepper.cxx:67
 TEveGridStepper.cxx:68
 TEveGridStepper.cxx:69
 TEveGridStepper.cxx:70
 TEveGridStepper.cxx:71
 TEveGridStepper.cxx:72
 TEveGridStepper.cxx:73
 TEveGridStepper.cxx:74
 TEveGridStepper.cxx:75
 TEveGridStepper.cxx:76
 TEveGridStepper.cxx:77
 TEveGridStepper.cxx:78
 TEveGridStepper.cxx:79
 TEveGridStepper.cxx:80
 TEveGridStepper.cxx:81
 TEveGridStepper.cxx:82
 TEveGridStepper.cxx:83
 TEveGridStepper.cxx:84
 TEveGridStepper.cxx:85
 TEveGridStepper.cxx:86
 TEveGridStepper.cxx:87
 TEveGridStepper.cxx:88
 TEveGridStepper.cxx:89
 TEveGridStepper.cxx:90
 TEveGridStepper.cxx:91
 TEveGridStepper.cxx:92
 TEveGridStepper.cxx:93
 TEveGridStepper.cxx:94
 TEveGridStepper.cxx:95
 TEveGridStepper.cxx:96
 TEveGridStepper.cxx:97
 TEveGridStepper.cxx:98
 TEveGridStepper.cxx:99
 TEveGridStepper.cxx:100
 TEveGridStepper.cxx:101
 TEveGridStepper.cxx:102
 TEveGridStepper.cxx:103
 TEveGridStepper.cxx:104
 TEveGridStepper.cxx:105
 TEveGridStepper.cxx:106
 TEveGridStepper.cxx:107
 TEveGridStepper.cxx:108
 TEveGridStepper.cxx:109
 TEveGridStepper.cxx:110
 TEveGridStepper.cxx:111
 TEveGridStepper.cxx:112
 TEveGridStepper.cxx:113
 TEveGridStepper.cxx:114
 TEveGridStepper.cxx:115
 TEveGridStepper.cxx:116
 TEveGridStepper.cxx:117
 TEveGridStepper.cxx:118
 TEveGridStepper.cxx:119