#include "TEveProjections.h"
#include "TEveUtil.h"
ClassImp(TEveProjection)
Float_t TEveProjection::fgEps = 0.005f;
TEveProjection::TEveProjection(TEveVector& center) :
   fType(kPT_Unknown),
   fGeoMode(kGM_Unknown),
   fName(0),
   fCenter(center.fX, center.fY, center.fZ),
   fDistortion(0.0f),
   fFixedRadius(300),
   fScale(1.0f)
{
   
}
void TEveProjection::ProjectVector(TEveVector& v)
{
   
   ProjectPoint(v.fX, v.fY, v.fZ);
}
void TEveProjection::UpdateLimit()
{
   
   if (fDistortion == 0.0f)
      return;
   Float_t lim =  1.0f/fDistortion + fFixedRadius;
   Float_t* c = GetProjectedCenter();
   fUpLimit.Set(lim + c[0], lim + c[1], c[2]);
   fLowLimit.Set(-lim + c[0], -lim + c[1], c[2]);
}
void TEveProjection::SetDistortion(Float_t d)
{
   
   fDistortion = d;
   fScale      = 1.0f + fFixedRadius*fDistortion;
   UpdateLimit();
}
void TEveProjection::SetFixedRadius(Float_t r)
{
   
   fFixedRadius=r;
   fScale = 1 + fFixedRadius*fDistortion;
   UpdateLimit();
}
void TEveProjection::SetDirectionalVector(Int_t screenAxis, TEveVector& vec)
{
   
   for (Int_t i=0; i<3; i++)
   {
      vec[i] = (i==screenAxis) ? 1. : 0.;
   }
}
Float_t TEveProjection::GetValForScreenPos(Int_t i, Float_t sv)
{
   
   static const TEveException eH("TEveProjection::GetValForScreenPos ");
   Float_t xL, xM, xR;
   TEveVector vec;
   TEveVector dirVec;
   SetDirectionalVector(i, dirVec);
   if (fDistortion > 0.0f && ((sv > 0 && sv > fUpLimit[i]) || (sv < 0 && sv < fLowLimit[i])))
      throw(eH + Form("screen value '%f' out of limit '%f'.", sv, sv > 0 ? fUpLimit[i] : fLowLimit[i]));
   TEveVector zero; ProjectVector(zero);
   
   if (sv > zero[i])
   {
      xL = 0; xR = 1000;
      while (1)
      {
         vec.Mult(dirVec, xR); ProjectVector(vec);
         
         if (vec[i] > sv || vec[i] == sv) break;
         xL = xR; xR *= 2;
      }
   }
   else if (sv < zero[i])
   {
      xR = 0; xL = -1000;
      while (1)
      {
         vec.Mult(dirVec, xL); ProjectVector(vec);
         
         if (vec[i] < sv || vec[i] == sv) break;
         xR = xL; xL *= 2;
      }
   }
   else
   {
      return 0.0f;
   }
   do
   {
      xM = 0.5f * (xL + xR);
      vec.Mult(dirVec, xM);
      ProjectVector(vec);
      if (vec[i] > sv)
         xR = xM;
      else
         xL = xM;
   } while(TMath::Abs(vec[i] - sv) >= fgEps);
   return xM;
}
Float_t TEveProjection::GetScreenVal(Int_t i, Float_t x)
{
   
   TEveVector dv;
   SetDirectionalVector(i, dv); dv = dv*x;
   ProjectVector(dv);
   return dv[i];
}
ClassImp(TEveRhoZProjection)
void TEveRhoZProjection::SetCenter(TEveVector& v)
{
   
   fCenter = v;
   Float_t r = TMath::Sqrt(v.fX*v.fX + v.fY*v.fY);
   fProjectedCenter.fX = fCenter.fZ;
   fProjectedCenter.fY = TMath::Sign(r, fCenter.fY);
   fProjectedCenter.fZ = 0;
   UpdateLimit();
}
void TEveRhoZProjection::ProjectPoint(Float_t& x, Float_t& y, Float_t& z,  EPProc_e proc )
{
   
   using namespace TMath;
   if(proc == kPP_Plane || proc == kPP_Full)
   {
      
      y = Sign((Float_t)Sqrt(x*x+y*y), y);
      x = z;
   }
   if(proc == kPP_Distort || proc == kPP_Full)
   {
      
      x -= fProjectedCenter.fX;
      y -= fProjectedCenter.fY;
      
      y = (y*fScale) / (1.0f + Abs(y)*fDistortion);
      x = (x*fScale) / (1.0f + Abs(x)*fDistortion);
      
      x += fProjectedCenter.fX;
      y += fProjectedCenter.fY;
   }
   z = 0.0f;
}
void TEveRhoZProjection::SetDirectionalVector(Int_t screenAxis, TEveVector& vec)
{
   
   
   
   if(screenAxis == 0)
      vec.Set(0., 0., 1);
   else if (screenAxis == 1)
      vec.Set(0., 1., 0);
}
Bool_t TEveRhoZProjection::AcceptSegment(TEveVector& v1, TEveVector& v2, Float_t tolerance)
{
   
   Float_t a = fProjectedCenter.fY;
   Bool_t val = kTRUE;
   if((v1.fY <  a && v2.fY > a) || (v1.fY > a && v2.fY < a))
   {
      val = kFALSE;
      if (tolerance > 0)
      {
         Float_t a1 = TMath::Abs(v1.fY - a), a2 = TMath::Abs(v2.fY - a);
         if (a1 < a2)
         {
            if (a1 < tolerance) { v1.fY = a; val = kTRUE; }
         }
         else
         {
            if (a2 < tolerance) { v2.fY = a; val = kTRUE; }
         }
      }
   }
   return val;
}
ClassImp(TEveCircularFishEyeProjection)
void TEveCircularFishEyeProjection::ProjectPoint(Float_t& x, Float_t& y, Float_t& z,
                                                 EPProc_e proc)
{
   
   using namespace TMath;
   if (proc != kPP_Plane)
   {
      x -= fCenter.fX;
      y -= fCenter.fY;
      Float_t phi = (x == 0.0 && y == 0.0) ? 0.0f : ATan2(y, x);
      Float_t r = Sqrt(x*x + y*y);
      
      Float_t nR = (r*fScale) / (1.0f + r*fDistortion);
      x = nR*Cos(phi) + fCenter.fX;
      y = nR*Sin(phi) + fCenter.fY;
   }
   z = 0.0f;
}
Last update: Thu Jan 17 08:48:15 2008
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.