ROOT logo
// @(#)root/eve:$Id: TEveProjections.h 39682 2011-06-11 05:37:08Z matevz $
// 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.             *
 *************************************************************************/

#ifndef ROOT_TEveProjections
#define ROOT_TEveProjections

#include "TEveVector.h"
#include "TString.h"

#include <vector>

class TEveTrans;

//==============================================================================
// TEveProjection
//==============================================================================

class TEveProjection
{
public:
   enum EPType_e   { kPT_Unknown, kPT_RPhi, kPT_RhoZ, kPT_3D, kPT_End }; // projection type
   enum EPProc_e   { kPP_Plane, kPP_Distort, kPP_Full };                 // projection procedure
   enum EGeoMode_e { kGM_Unknown, kGM_Polygons, kGM_Segments };          // strategy for geometry projections

   struct PreScaleEntry_t
   {
      Float_t fMin, fMax;
      Float_t fOffset;
      Float_t fScale;

      PreScaleEntry_t() :
         fMin(0), fMax(0), fOffset(0), fScale(1) {}
      PreScaleEntry_t(Float_t min, Float_t max, Float_t off, Float_t scale) :
         fMin(min), fMax(max), fOffset(off), fScale(scale) {}

      virtual ~PreScaleEntry_t() {}

      ClassDef(PreScaleEntry_t, 0);
   };

   typedef std::vector<PreScaleEntry_t>           vPreScale_t;
   typedef std::vector<PreScaleEntry_t>::iterator vPreScale_i;

protected:
   EPType_e            fType;          // type
   EGeoMode_e          fGeoMode;       // strategy of polygon projection (what to try first)
   TString             fName;          // name

   TEveVector          fCenter;        // center of distortionprivate:

   bool                fDisplaceOrigin; // displace point before projection

   Bool_t              fUsePreScale;   // use pre-scaling
   vPreScale_t         fPreScales[3];  // scaling before the distortion

   Float_t             fDistortion;    // distortion
   Float_t             fFixR;          // radius from which scaling remains constant
   Float_t             fFixZ;          // z-coordinate from which scaling remains constant
   Float_t             fPastFixRFac;   // relative scaling factor beyond fFixR as 10^x
   Float_t             fPastFixZFac;   // relative scaling factor beyond fFixZ as 10^x
   Float_t             fScaleR;        // scale factor to keep projected radius at fFixR fixed
   Float_t             fScaleZ;        // scale factor to keep projected z-coordinate at fFixZ fixed
   Float_t             fPastFixRScale; // relative scaling beyond fFixR
   Float_t             fPastFixZScale; // relative scaling beyond fFixZ
   Float_t             fMaxTrackStep;  // maximum distance between two points on a track

   void PreScaleVariable(Int_t dim, Float_t& v);

public:
   TEveProjection();
   virtual ~TEveProjection() {}

   virtual Bool_t      Is2D() const = 0;
   virtual Bool_t      Is3D() const = 0;

   virtual void        ProjectPoint(Float_t& x, Float_t& y, Float_t& z, Float_t d, EPProc_e p = kPP_Full) = 0;

   void                ProjectPointfv(Float_t* v, Float_t d);
   void                ProjectPointdv(Double_t* v, Float_t d);
   void                ProjectVector(TEveVector& v, Float_t d);

   void                ProjectPointfv(const TEveTrans* t, const Float_t*  p, Float_t* v, Float_t d);
   void                ProjectPointdv(const TEveTrans* t, const Double_t* p, Double_t* v, Float_t d);
   void                ProjectVector(const TEveTrans* t, TEveVector& v, Float_t d);

   const   Char_t*     GetName() const            { return fName.Data(); }
   void                SetName(const Char_t* txt) { fName = txt; }

   virtual void        SetCenter(TEveVector& v) { fCenter = v; }
   virtual Float_t*    GetProjectedCenter();
  
   void                SetDisplaceOrigin(bool);
   Bool_t              GetDisplaceOrigin() const { return fDisplaceOrigin; }

   void                SetType(EPType_e t)        { fType = t; }
   EPType_e            GetType() const            { return fType; }

   void                SetGeoMode(EGeoMode_e m)   { fGeoMode = m; }
   EGeoMode_e          GetGeoMode() const         { return fGeoMode; }

   Bool_t   GetUsePreScale() const   { return fUsePreScale; }
   void     SetUsePreScale(Bool_t x) { fUsePreScale = x; }

   void     PreScalePoint(Float_t& x, Float_t& y);
   void     PreScalePoint(Float_t& x, Float_t& y, Float_t& z);
   void     AddPreScaleEntry(Int_t coord, Float_t max_val, Float_t scale);
   void     ChangePreScaleEntry(Int_t coord, Int_t entry, Float_t new_scale);
   void     ClearPreScales();

   void     SetDistortion(Float_t d);
   Float_t  GetDistortion() const { return fDistortion; }
   Float_t  GetFixR() const { return fFixR; }
   Float_t  GetFixZ() const { return fFixZ; }
   void     SetFixR(Float_t x);
   void     SetFixZ(Float_t x);
   Float_t  GetPastFixRFac() const { return fPastFixRFac; }
   Float_t  GetPastFixZFac() const { return fPastFixZFac; }
   void     SetPastFixRFac(Float_t x);
   void     SetPastFixZFac(Float_t x);
   Float_t  GetMaxTrackStep() const    { return fMaxTrackStep; }
   void     SetMaxTrackStep(Float_t x) { fMaxTrackStep = TMath::Max(x, 1.0f); }

   virtual Bool_t      HasSeveralSubSpaces() const { return kFALSE; }
   virtual Bool_t      AcceptSegment(TEveVector&, TEveVector&, Float_t /*tolerance*/) const { return kTRUE; }
   virtual Int_t       SubSpaceId(const TEveVector&) const { return 0; }
   virtual Bool_t      IsOnSubSpaceBoundrary(const TEveVector&) const { return kFALSE; }
   virtual void        BisectBreakPoint(TEveVector& vL, TEveVector& vR, Float_t eps_sqr);
   virtual void        BisectBreakPoint(TEveVector& vL, TEveVector& vR, Bool_t project_result=kFALSE, Float_t depth=0);
   virtual void        SetDirectionalVector(Int_t screenAxis, TEveVector& vec);

   // utils to draw axis
   TEveVector          GetOrthogonalCenter(int idx, TEveVector& out);
   virtual Float_t     GetValForScreenPos(Int_t ax, Float_t value);
   virtual Float_t     GetScreenVal(Int_t ax, Float_t value);
   Float_t             GetScreenVal(Int_t i, Float_t x, TEveVector& dirVec, TEveVector& oCenter);
   Float_t             GetLimit(Int_t i, Bool_t pos);


   static   Float_t    fgEps;    // resolution of projected points
   static   Float_t    fgEpsSqr; // square of resolution of projected points

   ClassDef(TEveProjection, 0); // Base for specific classes that implement non-linear projections.
};


//==============================================================================
// TEveRhoZProjection
//==============================================================================

class TEveRhoZProjection: public TEveProjection
{
private:
   TEveVector   fProjectedCenter; // projected center of distortion.

public:
   TEveRhoZProjection();
   virtual ~TEveRhoZProjection() {}

   virtual Bool_t      Is2D() const { return kTRUE;  }
   virtual Bool_t      Is3D() const { return kFALSE; }

   virtual void        ProjectPoint(Float_t& x, Float_t& y, Float_t& z, Float_t d, EPProc_e proc = kPP_Full);

   virtual void        SetCenter(TEveVector& v); 
   virtual Float_t*    GetProjectedCenter() { return fProjectedCenter.Arr(); }

   virtual Bool_t      HasSeveralSubSpaces() const { return kTRUE; }
   virtual Bool_t      AcceptSegment(TEveVector& v1, TEveVector& v2, Float_t tolerance) const;
   virtual Int_t       SubSpaceId(const TEveVector& v) const;
   virtual Bool_t      IsOnSubSpaceBoundrary(const TEveVector& v) const;
   virtual void        SetDirectionalVector(Int_t screenAxis, TEveVector& vec);

   ClassDef(TEveRhoZProjection, 0); // Rho/Z non-linear projection.
};


//==============================================================================
// TEveRPhiProjection
//==============================================================================

class TEveRPhiProjection : public TEveProjection
{
public:
   TEveRPhiProjection();
   virtual ~TEveRPhiProjection() {}

   virtual Bool_t Is2D() const { return kTRUE;  }
   virtual Bool_t Is3D() const { return kFALSE; }

   virtual void   ProjectPoint(Float_t& x, Float_t& y, Float_t& z, Float_t d, EPProc_e proc = kPP_Full);

   ClassDef(TEveRPhiProjection, 0); // XY non-linear projection.
};


//==============================================================================
// TEve3DProjection
//==============================================================================

class TEve3DProjection : public TEveProjection
{
public:
   TEve3DProjection();
   virtual ~TEve3DProjection() {}

   virtual Bool_t Is2D() const { return kFALSE; }
   virtual Bool_t Is3D() const { return kTRUE;  }

   virtual void   ProjectPoint(Float_t& x, Float_t& y, Float_t& z, Float_t d, EPProc_e proc = kPP_Full);

   ClassDef(TEve3DProjection, 0); // 3D scaling "projection"
};

// AMT: temporary workaround till root pactches are integrated in CMSSW 	 
#define TEVEPROJECTIONS_DISPLACE_ORIGIN_MODE	 
	 
#endif
 TEveProjections.h:1
 TEveProjections.h:2
 TEveProjections.h:3
 TEveProjections.h:4
 TEveProjections.h:5
 TEveProjections.h:6
 TEveProjections.h:7
 TEveProjections.h:8
 TEveProjections.h:9
 TEveProjections.h:10
 TEveProjections.h:11
 TEveProjections.h:12
 TEveProjections.h:13
 TEveProjections.h:14
 TEveProjections.h:15
 TEveProjections.h:16
 TEveProjections.h:17
 TEveProjections.h:18
 TEveProjections.h:19
 TEveProjections.h:20
 TEveProjections.h:21
 TEveProjections.h:22
 TEveProjections.h:23
 TEveProjections.h:24
 TEveProjections.h:25
 TEveProjections.h:26
 TEveProjections.h:27
 TEveProjections.h:28
 TEveProjections.h:29
 TEveProjections.h:30
 TEveProjections.h:31
 TEveProjections.h:32
 TEveProjections.h:33
 TEveProjections.h:34
 TEveProjections.h:35
 TEveProjections.h:36
 TEveProjections.h:37
 TEveProjections.h:38
 TEveProjections.h:39
 TEveProjections.h:40
 TEveProjections.h:41
 TEveProjections.h:42
 TEveProjections.h:43
 TEveProjections.h:44
 TEveProjections.h:45
 TEveProjections.h:46
 TEveProjections.h:47
 TEveProjections.h:48
 TEveProjections.h:49
 TEveProjections.h:50
 TEveProjections.h:51
 TEveProjections.h:52
 TEveProjections.h:53
 TEveProjections.h:54
 TEveProjections.h:55
 TEveProjections.h:56
 TEveProjections.h:57
 TEveProjections.h:58
 TEveProjections.h:59
 TEveProjections.h:60
 TEveProjections.h:61
 TEveProjections.h:62
 TEveProjections.h:63
 TEveProjections.h:64
 TEveProjections.h:65
 TEveProjections.h:66
 TEveProjections.h:67
 TEveProjections.h:68
 TEveProjections.h:69
 TEveProjections.h:70
 TEveProjections.h:71
 TEveProjections.h:72
 TEveProjections.h:73
 TEveProjections.h:74
 TEveProjections.h:75
 TEveProjections.h:76
 TEveProjections.h:77
 TEveProjections.h:78
 TEveProjections.h:79
 TEveProjections.h:80
 TEveProjections.h:81
 TEveProjections.h:82
 TEveProjections.h:83
 TEveProjections.h:84
 TEveProjections.h:85
 TEveProjections.h:86
 TEveProjections.h:87
 TEveProjections.h:88
 TEveProjections.h:89
 TEveProjections.h:90
 TEveProjections.h:91
 TEveProjections.h:92
 TEveProjections.h:93
 TEveProjections.h:94
 TEveProjections.h:95
 TEveProjections.h:96
 TEveProjections.h:97
 TEveProjections.h:98
 TEveProjections.h:99
 TEveProjections.h:100
 TEveProjections.h:101
 TEveProjections.h:102
 TEveProjections.h:103
 TEveProjections.h:104
 TEveProjections.h:105
 TEveProjections.h:106
 TEveProjections.h:107
 TEveProjections.h:108
 TEveProjections.h:109
 TEveProjections.h:110
 TEveProjections.h:111
 TEveProjections.h:112
 TEveProjections.h:113
 TEveProjections.h:114
 TEveProjections.h:115
 TEveProjections.h:116
 TEveProjections.h:117
 TEveProjections.h:118
 TEveProjections.h:119
 TEveProjections.h:120
 TEveProjections.h:121
 TEveProjections.h:122
 TEveProjections.h:123
 TEveProjections.h:124
 TEveProjections.h:125
 TEveProjections.h:126
 TEveProjections.h:127
 TEveProjections.h:128
 TEveProjections.h:129
 TEveProjections.h:130
 TEveProjections.h:131
 TEveProjections.h:132
 TEveProjections.h:133
 TEveProjections.h:134
 TEveProjections.h:135
 TEveProjections.h:136
 TEveProjections.h:137
 TEveProjections.h:138
 TEveProjections.h:139
 TEveProjections.h:140
 TEveProjections.h:141
 TEveProjections.h:142
 TEveProjections.h:143
 TEveProjections.h:144
 TEveProjections.h:145
 TEveProjections.h:146
 TEveProjections.h:147
 TEveProjections.h:148
 TEveProjections.h:149
 TEveProjections.h:150
 TEveProjections.h:151
 TEveProjections.h:152
 TEveProjections.h:153
 TEveProjections.h:154
 TEveProjections.h:155
 TEveProjections.h:156
 TEveProjections.h:157
 TEveProjections.h:158
 TEveProjections.h:159
 TEveProjections.h:160
 TEveProjections.h:161
 TEveProjections.h:162
 TEveProjections.h:163
 TEveProjections.h:164
 TEveProjections.h:165
 TEveProjections.h:166
 TEveProjections.h:167
 TEveProjections.h:168
 TEveProjections.h:169
 TEveProjections.h:170
 TEveProjections.h:171
 TEveProjections.h:172
 TEveProjections.h:173
 TEveProjections.h:174
 TEveProjections.h:175
 TEveProjections.h:176
 TEveProjections.h:177
 TEveProjections.h:178
 TEveProjections.h:179
 TEveProjections.h:180
 TEveProjections.h:181
 TEveProjections.h:182
 TEveProjections.h:183
 TEveProjections.h:184
 TEveProjections.h:185
 TEveProjections.h:186
 TEveProjections.h:187
 TEveProjections.h:188
 TEveProjections.h:189
 TEveProjections.h:190
 TEveProjections.h:191
 TEveProjections.h:192
 TEveProjections.h:193
 TEveProjections.h:194
 TEveProjections.h:195
 TEveProjections.h:196
 TEveProjections.h:197
 TEveProjections.h:198
 TEveProjections.h:199
 TEveProjections.h:200
 TEveProjections.h:201
 TEveProjections.h:202
 TEveProjections.h:203
 TEveProjections.h:204
 TEveProjections.h:205
 TEveProjections.h:206
 TEveProjections.h:207
 TEveProjections.h:208
 TEveProjections.h:209
 TEveProjections.h:210
 TEveProjections.h:211
 TEveProjections.h:212
 TEveProjections.h:213
 TEveProjections.h:214
 TEveProjections.h:215
 TEveProjections.h:216
 TEveProjections.h:217
 TEveProjections.h:218
 TEveProjections.h:219
 TEveProjections.h:220
 TEveProjections.h:221
 TEveProjections.h:222
 TEveProjections.h:223
 TEveProjections.h:224
 TEveProjections.h:225