ROOT logo
// @(#)root/geom:$Id$
// Author: Andrei Gheata   04/02/02

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

#ifndef ROOT_TGeoVoxelFinder
#define ROOT_TGeoVoxelFinder

#ifndef ROOT_TObject
#include "TObject.h"
#endif

class TGeoVolume;
struct TGeoStateInfo;

/*************************************************************************
 * TGeoVoxelFinder - finder class handling voxels 
 *  
 *************************************************************************/

class TGeoVoxelFinder : public TObject
{
public:
enum EVoxelsType {
   kGeoInvalidVoxels = BIT(15),
   kGeoRebuildVoxels = BIT(16)
};

protected:
   TGeoVolume      *fVolume;          // volume to which applies

   Int_t             fIbx;            // number of different boundaries on X axis
   Int_t             fIby;            // number of different boundaries on Y axis
   Int_t             fIbz;            // number of different boundaries on Z axis
   Int_t             fNboxes;         // length of boxes array
   Int_t             fNox;            // length of array of X offsets
   Int_t             fNoy;            // length of array of Y offsets
   Int_t             fNoz;            // length of array of Z offsets
   Int_t             fNex;            // length of array of X extra offsets
   Int_t             fNey;            // length of array of Y extra offsets
   Int_t             fNez;            // length of array of Z extra offsets
   Int_t             fNx;             // length of array of X voxels
   Int_t             fNy;             // length of array of Y voxels
   Int_t             fNz;             // length of array of Z voxels
   Int_t             fPriority[3];    // priority for each axis
   Double_t         *fBoxes;          //[fNboxes] list of bounding boxes
   Double_t         *fXb;             //[fIbx] ordered array of X box boundaries
   Double_t         *fYb;             //[fIby] ordered array of Y box boundaries
   Double_t         *fZb;             //[fIbz] ordered array of Z box boundaries
   Int_t            *fOBx;            //[fNox] offsets of daughter indices for slices X
   Int_t            *fOBy;            //[fNoy] offsets of daughter indices for slices Y
   Int_t            *fOBz;            //[fNoz] offsets of daughter indices for slices Z
   Int_t            *fOEx;            //[fNox] offsets of extra indices for slices X
   Int_t            *fOEy;            //[fNoy] offsets of extra indices for slices Y
   Int_t            *fOEz;            //[fNoz] offsets of extra indices for slices Z
   Int_t            *fExtraX;         //[fNex] indices of extra daughters in X slices
   Int_t            *fExtraY;         //[fNey] indices of extra daughters in Y slices
   Int_t            *fExtraZ;         //[fNez] indices of extra daughters in Z slices
   Int_t            *fNsliceX;        //[fNox] number of candidates in X slice
   Int_t            *fNsliceY;        //[fNoy] number of candidates in Y slice
   Int_t            *fNsliceZ;        //[fNoz] number of candidates in Z slice
   UChar_t          *fIndcX;          //[fNx] array of slices bits on X
   UChar_t          *fIndcY;          //[fNy] array of slices bits on Y
   UChar_t          *fIndcZ;          //[fNz] array of slices bits on Z

   TGeoVoxelFinder(const TGeoVoxelFinder&);
   TGeoVoxelFinder& operator=(const TGeoVoxelFinder&);
   
   void                BuildVoxelLimits();
   Int_t              *GetExtraX(Int_t islice, Bool_t left, Int_t &nextra) const;
   Int_t              *GetExtraY(Int_t islice, Bool_t left, Int_t &nextra) const;
   Int_t              *GetExtraZ(Int_t islice, Bool_t left, Int_t &nextra) const;
   Bool_t              GetIndices(const Double_t *point, TGeoStateInfo &td);
   Int_t               GetPriority(Int_t iaxis) const {return fPriority[iaxis];}
   Int_t               GetNcandidates( TGeoStateInfo &td) const;
   Int_t              *GetValidExtra(Int_t *list, Int_t &ncheck, TGeoStateInfo &td);
   Int_t              *GetValidExtra(Int_t n1, UChar_t *array1, Int_t *list, Int_t &ncheck, TGeoStateInfo &td);
   Int_t              *GetValidExtra(Int_t n1, UChar_t *array1, Int_t n2, UChar_t *array2, Int_t *list, Int_t &ncheck, TGeoStateInfo &td);
   Int_t              *GetVoxelCandidates(Int_t i, Int_t j, Int_t k, Int_t &ncheck, TGeoStateInfo &td);
   Bool_t              Intersect(Int_t n1, UChar_t *array1, Int_t &nf, Int_t *result); 
   Bool_t              Intersect(Int_t n1, UChar_t *array1, Int_t n2, UChar_t *array2,
                             Int_t &nf, Int_t *result); 
   Bool_t              Intersect(Int_t n1, UChar_t *array1, Int_t n2, UChar_t *array2,
                             Int_t n3, UChar_t *array3, Int_t &nf, Int_t *result); 
   Bool_t              IntersectAndStore(Int_t n1, UChar_t *array1, TGeoStateInfo &td); 
   Bool_t              IntersectAndStore(Int_t n1, UChar_t *array1, Int_t n2, UChar_t *array2, TGeoStateInfo &td); 
   Bool_t              IntersectAndStore(Int_t n1, UChar_t *array1, Int_t n2, UChar_t *array2,
                             Int_t n3, UChar_t *array3, TGeoStateInfo &td);
   void                SortAll(Option_t *option="");
   Bool_t              Union(Int_t n1, UChar_t *array1, TGeoStateInfo &td);
   Bool_t              Union(Int_t n1, UChar_t *array1, Int_t n2, UChar_t *array2, TGeoStateInfo &td);
   Bool_t              Union(Int_t n1, UChar_t *array1, Int_t n2, UChar_t *array2,
                             Int_t n3, UChar_t *array3, TGeoStateInfo &td);
public :
   TGeoVoxelFinder();
   TGeoVoxelFinder(TGeoVolume *vol);
   virtual ~TGeoVoxelFinder();
   void                DaughterToMother(Int_t id, const Double_t *local, Double_t *master) const;
   virtual Double_t    Efficiency();
   virtual Int_t      *GetCheckList(const Double_t *point, Int_t &nelem, TGeoStateInfo &td);
   Int_t              *GetCheckList(Int_t &nelem, TGeoStateInfo &td) const;
   virtual Int_t      *GetNextCandidates(const Double_t *point, Int_t &ncheck, TGeoStateInfo &td); 
   virtual void        FindOverlaps(Int_t inode) const;
   Bool_t              IsInvalid() const {return TObject::TestBit(kGeoInvalidVoxels);}
   Bool_t              NeedRebuild() const {return TObject::TestBit(kGeoRebuildVoxels);}
   Double_t           *GetBoxes() const {return fBoxes;}
   Bool_t              IsSafeVoxel(const Double_t *point, Int_t inode, Double_t minsafe) const;
   virtual void        Print(Option_t *option="") const;
   void                PrintVoxelLimits(const Double_t *point) const;
   void                SetInvalid(Bool_t flag=kTRUE) {TObject::SetBit(kGeoInvalidVoxels, flag);}
   void                SetNeedRebuild(Bool_t flag=kTRUE) {TObject::SetBit(kGeoRebuildVoxels, flag);}
   virtual Int_t      *GetNextVoxel(const Double_t *point, const Double_t *dir, Int_t &ncheck, TGeoStateInfo &td);
   virtual void        SortCrossedVoxels(const Double_t *point, const Double_t *dir, TGeoStateInfo &td);
   virtual void        Voxelize(Option_t *option="");

   ClassDef(TGeoVoxelFinder, 4)                // voxel finder class
};

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