// @(#)root/g3d:$Id$
// Author: Rene Brun   22/09/95

/*************************************************************************
 * 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_TGeometry
#define ROOT_TGeometry


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TGeometry                                                            //
//                                                                      //
// Structure for Matrices, Shapes and Nodes.                            //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TNamed
#include "TNamed.h"
#endif
#ifndef ROOT_THashList
#include "THashList.h"
#endif

const Int_t kMAXLEVELS = 20;
const Int_t kVectorSize = 3;
const Int_t kMatrixSize = kVectorSize*kVectorSize;

class TNode;
class TBrowser;
class TMaterial;
class TRotMatrix;
class TShape;
class TObjArray;


class TGeometry : public TNamed {

private:
   THashList        *fMaterials;          //->Collection of materials
   THashList        *fMatrices;           //->Collection of rotation matrices
   THashList        *fShapes;             //->Collection of shapes
   TList            *fNodes;              //->Collection of nodes
   TRotMatrix       *fMatrix;             //!Pointers to current rotation matrices
   TNode            *fCurrentNode;        //!Pointer to current node
   TMaterial       **fMaterialPointer;    //!Pointers to materials
   TRotMatrix      **fMatrixPointer;      //!Pointers to rotation matrices
   TShape          **fShapePointer;       //!Pointers to shapes
   Float_t          fBomb;                //Bomb factor for exploded geometry
   Int_t            fGeomLevel;           //!
   Double_t         fX;                   //!
   Double_t         fY;                   //! The global translation of the current node
   Double_t         fZ;                   //!
   Double_t         fTranslation[kMAXLEVELS][kVectorSize];//!
   Double_t         fRotMatrix[kMAXLEVELS][kMatrixSize];  //!
   Bool_t           fIsReflection[kMAXLEVELS];            //!

protected:
   TGeometry(const TGeometry&);
   TGeometry& operator=(const TGeometry&);

public:
   TGeometry();
   TGeometry(const char *name, const char *title);
   virtual           ~TGeometry();
   virtual void      Browse(TBrowser *b);
   virtual void      cd(const char *path=0);
   virtual void      Draw(Option_t *option="");
   virtual TObject  *FindObject(const char *name) const;
   virtual TObject  *FindObject(const TObject *obj) const;
   Float_t           GetBomb() const {return fBomb;}
   Int_t             GeomLevel() const {return fGeomLevel;}
   THashList        *GetListOfShapes() const  {return fShapes;}
   TList            *GetListOfNodes()  const   {return fNodes;}
   THashList        *GetListOfMaterials() const {return fMaterials;}
   THashList        *GetListOfMatrices() const {return fMatrices;}
   TNode            *GetCurrentNode()  const {return fCurrentNode;}
   TMaterial        *GetMaterial(const char *name) const;
   TMaterial        *GetMaterialByNumber(Int_t number) const;
   TNode            *GetNode(const char *name) const;
   TShape           *GetShape(const char *name) const;
   TShape           *GetShapeByNumber(Int_t number) const;
   TRotMatrix       *GetRotMatrix(const char *name) const;
   TRotMatrix       *GetRotMatrixByNumber(Int_t number) const;
   TRotMatrix       *GetCurrentMatrix() const;
   TRotMatrix       *GetCurrentPosition(Double_t *x,Double_t *y,Double_t *z) const;
   TRotMatrix       *GetCurrentPosition(Float_t *x,Float_t *y,Float_t *z) const;
   Bool_t            GetCurrentReflection() const;
   Bool_t            IsFolder() const {return kTRUE;}
   virtual void      Local2Master(Double_t *local, Double_t *master);
   virtual void      Local2Master(Float_t *local, Float_t *master);
   virtual void      ls(Option_t *option="rsn2") const;
   virtual void      Master2Local(Double_t *master, Double_t *local);
   virtual void      Master2Local(Float_t *master, Float_t *local);
   virtual void      Node(const char *name, const char *title, const char *shapename, Double_t x=0, Double_t y=0, Double_t z=0
                        , const char *matrixname="", Option_t *option="");
   virtual Int_t     PushLevel(){return fGeomLevel++;}
   virtual Int_t     PopLevel(){return fGeomLevel>0?fGeomLevel--:0;}
   virtual void      RecursiveRemove(TObject *obj);
   virtual void      SetBomb(Float_t bomb=1.4) {fBomb = bomb;}
   virtual void      SetCurrentNode(TNode *node) {fCurrentNode = node;}
   virtual void      SetGeomLevel(Int_t level=0){fGeomLevel=level;}
   virtual void      SetMatrix(TRotMatrix *matrix=0){fMatrix = matrix;}
   virtual void      SetPosition(TRotMatrix *matrix, Double_t x=0,Double_t y=0,Double_t z=0);
   virtual void      SetPosition(TRotMatrix *matrix, Float_t x,Float_t y,Float_t z);
   virtual void      SetPosition(Double_t x,Double_t y,Double_t z);
   virtual void      SetPosition(Float_t x,Float_t y,Float_t z);
   virtual void      UpdateMatrix(TNode *node);
   virtual void      UpdateTempMatrix(Double_t x=0, Double_t y=0, Double_t z=0, TRotMatrix *matrix=0);
   virtual void      UpdateTempMatrix(Double_t x, Double_t y, Double_t z, Double_t *matrix,Bool_t isReflection=kFALSE);

   static TObjArray *Get(const char *name);
   static void       UpdateTempMatrix(Double_t *dx1,Double_t *rmat1,
                                      Double_t x, Double_t y, Double_t z, Double_t *matrix,
                                      Double_t *dxnew, Double_t *rmatnew);

   ClassDef(TGeometry,2)  //Structure for Matrices, Shapes and Nodes
};


inline TRotMatrix *TGeometry::GetCurrentMatrix() const
{
   return fMatrix;
}
inline TRotMatrix *TGeometry::GetCurrentPosition(Double_t *x,Double_t *y,Double_t *z) const
{
   *x = fX; *y = fY; *z = fZ; return GetCurrentMatrix();
}
inline TRotMatrix *TGeometry::GetCurrentPosition(Float_t *x,Float_t *y,Float_t *z) const
{
   *x = Float_t(fX); *y = Float_t(fY); *z = Float_t(fZ); return GetCurrentMatrix();
}
inline Bool_t TGeometry::GetCurrentReflection() const
{
   return fIsReflection[fGeomLevel];
}
inline void TGeometry::SetPosition(Double_t x,Double_t y,Double_t z)
{
   fX = x; fY = y; fZ = z;
}
inline void TGeometry::SetPosition(Float_t x,Float_t y,Float_t z)
{
   fX = x; fY = y; fZ = z;
}
inline void TGeometry::SetPosition(TRotMatrix *matrix, Double_t x,Double_t y,Double_t z)
{
   SetMatrix(matrix);
   SetPosition(x,y,z);
}
inline void TGeometry::SetPosition(TRotMatrix *matrix, Float_t x,Float_t y,Float_t z)
{
   SetMatrix(matrix);
   SetPosition(x,y,z);
}

R__EXTERN TGeometry *gGeometry;

#endif
 TGeometry.h:1
 TGeometry.h:2
 TGeometry.h:3
 TGeometry.h:4
 TGeometry.h:5
 TGeometry.h:6
 TGeometry.h:7
 TGeometry.h:8
 TGeometry.h:9
 TGeometry.h:10
 TGeometry.h:11
 TGeometry.h:12
 TGeometry.h:13
 TGeometry.h:14
 TGeometry.h:15
 TGeometry.h:16
 TGeometry.h:17
 TGeometry.h:18
 TGeometry.h:19
 TGeometry.h:20
 TGeometry.h:21
 TGeometry.h:22
 TGeometry.h:23
 TGeometry.h:24
 TGeometry.h:25
 TGeometry.h:26
 TGeometry.h:27
 TGeometry.h:28
 TGeometry.h:29
 TGeometry.h:30
 TGeometry.h:31
 TGeometry.h:32
 TGeometry.h:33
 TGeometry.h:34
 TGeometry.h:35
 TGeometry.h:36
 TGeometry.h:37
 TGeometry.h:38
 TGeometry.h:39
 TGeometry.h:40
 TGeometry.h:41
 TGeometry.h:42
 TGeometry.h:43
 TGeometry.h:44
 TGeometry.h:45
 TGeometry.h:46
 TGeometry.h:47
 TGeometry.h:48
 TGeometry.h:49
 TGeometry.h:50
 TGeometry.h:51
 TGeometry.h:52
 TGeometry.h:53
 TGeometry.h:54
 TGeometry.h:55
 TGeometry.h:56
 TGeometry.h:57
 TGeometry.h:58
 TGeometry.h:59
 TGeometry.h:60
 TGeometry.h:61
 TGeometry.h:62
 TGeometry.h:63
 TGeometry.h:64
 TGeometry.h:65
 TGeometry.h:66
 TGeometry.h:67
 TGeometry.h:68
 TGeometry.h:69
 TGeometry.h:70
 TGeometry.h:71
 TGeometry.h:72
 TGeometry.h:73
 TGeometry.h:74
 TGeometry.h:75
 TGeometry.h:76
 TGeometry.h:77
 TGeometry.h:78
 TGeometry.h:79
 TGeometry.h:80
 TGeometry.h:81
 TGeometry.h:82
 TGeometry.h:83
 TGeometry.h:84
 TGeometry.h:85
 TGeometry.h:86
 TGeometry.h:87
 TGeometry.h:88
 TGeometry.h:89
 TGeometry.h:90
 TGeometry.h:91
 TGeometry.h:92
 TGeometry.h:93
 TGeometry.h:94
 TGeometry.h:95
 TGeometry.h:96
 TGeometry.h:97
 TGeometry.h:98
 TGeometry.h:99
 TGeometry.h:100
 TGeometry.h:101
 TGeometry.h:102
 TGeometry.h:103
 TGeometry.h:104
 TGeometry.h:105
 TGeometry.h:106
 TGeometry.h:107
 TGeometry.h:108
 TGeometry.h:109
 TGeometry.h:110
 TGeometry.h:111
 TGeometry.h:112
 TGeometry.h:113
 TGeometry.h:114
 TGeometry.h:115
 TGeometry.h:116
 TGeometry.h:117
 TGeometry.h:118
 TGeometry.h:119
 TGeometry.h:120
 TGeometry.h:121
 TGeometry.h:122
 TGeometry.h:123
 TGeometry.h:124
 TGeometry.h:125
 TGeometry.h:126
 TGeometry.h:127
 TGeometry.h:128
 TGeometry.h:129
 TGeometry.h:130
 TGeometry.h:131
 TGeometry.h:132
 TGeometry.h:133
 TGeometry.h:134
 TGeometry.h:135
 TGeometry.h:136
 TGeometry.h:137
 TGeometry.h:138
 TGeometry.h:139
 TGeometry.h:140
 TGeometry.h:141
 TGeometry.h:142
 TGeometry.h:143
 TGeometry.h:144
 TGeometry.h:145
 TGeometry.h:146
 TGeometry.h:147
 TGeometry.h:148
 TGeometry.h:149
 TGeometry.h:150
 TGeometry.h:151
 TGeometry.h:152
 TGeometry.h:153
 TGeometry.h:154
 TGeometry.h:155
 TGeometry.h:156
 TGeometry.h:157
 TGeometry.h:158
 TGeometry.h:159
 TGeometry.h:160
 TGeometry.h:161
 TGeometry.h:162
 TGeometry.h:163
 TGeometry.h:164