]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/NLTTrack.cxx
acc055d579b1550266048a0df76b248aae0052d4
[u/mrichter/AliRoot.git] / EVE / Reve / NLTTrack.cxx
1 // $Header$
2
3 #include "NLTTrack.h"
4 #include <Reve/NLTProjector.h>
5 #include <Reve/PODs.h>
6
7 using namespace Reve;
8
9 //______________________________________________________________________
10 // NLTTrack
11 //
12
13 ClassImp(NLTTrack)
14
15 NLTTrack::NLTTrack() :
16   Track     (),
17   fOrigPnts(0),
18   fProjection(0)
19 {}
20
21 /**************************************************************************/
22 void NLTTrack::SetProjection(NLTProjector* proj, NLTProjectable* model)
23 {
24   NLTProjected::SetProjection(proj, model);
25   Track* origTrack = dynamic_cast<Track*>(fProjectable);
26
27   SetTrackParams(*origTrack);
28
29   // unfortunately fPathMarks is a vector of PathMark pointers
30   PathMark* pm;
31   std::vector<PathMark*>& refs = origTrack->GetPathMarksRef();
32   for(std::vector<PathMark*>::iterator i=refs.begin(); i!=refs.end(); ++i)
33   {
34    pm = new PathMark();
35    pm->V = (*i)->V;
36    pm->P = (*i)->P;
37    pm->type = (*i)->type;
38    pm->time = (*i)->time;
39    fPathMarks.push_back(pm);
40   }
41 }
42
43 /**************************************************************************/
44 void NLTTrack::UpdateProjection()
45 {
46   fProjection = fProjector->GetProjection();
47   MakeTrack(kFALSE); //NLTProjector makes recursive calls
48 }
49
50 //______________________________________________________________________________
51 void  NLTTrack::GetBreakPoint(Int_t idx, Bool_t back,  Float_t& x, Float_t& y, Float_t& z)
52 {
53   Vector vL = fOrigPnts[idx];
54   Vector vR = fOrigPnts[idx+1];
55   Vector vM, vLP, vMP;
56   while((vL-vR).Mag() > 0.01)
57   { 
58     vM.Mult(vL+vR, 0.5f);
59     vLP.Set(vL); fProjection->ProjectPoint(vLP.x, vLP.y, vLP.z);
60     vMP.Set(vM); fProjection->ProjectPoint(vMP.x, vMP.y, vMP.z);
61     if(fProjection->AcceptSegment(vLP, vMP, 0.0f))
62     {
63       vL.Set(vM);
64     }
65     else 
66     {
67       vR.Set(vM);
68     }
69     //printf("new interval Mag %f (%f, %f, %f)(%f, %f, %f) \n",(vL-vR).Mag(), vL.x, vL.y, vL.z, vR.x, vR.y, vR.z);
70   }
71
72   if(back)
73   {
74     x = vL.x; y = vL.y; z = vL.z;
75   }
76   else
77   {
78     x = vR.x; y = vR.y; z = vR.z;
79   }
80   fProjection->ProjectPoint(x, y, z);
81   // printf("NLTTrack::GetBreakPoint %d (%f, %f, %f) \n", idx, x, y, z);
82 }
83
84 //______________________________________________________________________________
85 Int_t  NLTTrack::GetBreakPointIdx(Int_t start)
86 {
87   Int_t val = fLastPoint;
88
89   Vector v1; Vector v2;
90   if( Size() > 1 )
91   {
92     Bool_t broken = kFALSE;
93     Int_t i = start;
94     while(i < fLastPoint)
95     {
96       GetPoint(i,   v1.x, v1.y, v1.z);
97       GetPoint(i+1, v2.x, v2.y, v2.z);
98       if(fProjection->AcceptSegment(v1, v2, fRnrStyle->fDelta) == kFALSE)
99       {
100         broken = kTRUE;
101         break;
102       }
103       i++;
104     }
105     if(broken) val = i;
106   }
107   // printf("BreakPoint IDX start:%d, BREAK %d,  total:%d \n", start, val, Size());
108   return val;
109 }
110
111 /**************************************************************************/
112
113 void NLTTrack::MakeTrack(Bool_t recurse)
114 {
115   Track::MakeTrack(recurse);
116
117   fBreakPoints.clear();
118   if(Size() == 0) return; // it is possible to be outside the limits of MaxR, MaxZ ...
119
120   // poject line points
121   Float_t *p = GetP();
122   fOrigPnts = new Vector[Size()];
123   for(Int_t i = 0; i < Size(); ++i, p+=3)
124   {
125     fOrigPnts[i].Set(p);
126     fProjection->ProjectPoint(p[0], p[1], p[2]);
127     p[2] = fDepth;
128   } 
129   Float_t x, y, z;
130   std::vector<Vector> vvec;
131   Int_t bL = 0, bR = GetBreakPointIdx(0); 
132   while (1)
133   {
134     for(Int_t i=bL; i<=bR; i++)
135     {
136       GetPoint(i, x, y,z);
137       vvec.push_back(Vector(x, y, z));
138     }
139     if (bR == fLastPoint)
140       break;
141
142     GetBreakPoint(bR, kTRUE,  x, y, z); vvec.push_back(Vector(x, y, z));
143     fBreakPoints.push_back(vvec.size());
144     GetBreakPoint(bR, kFALSE, x, y, z); vvec.push_back(Vector(x, y, z));
145
146     bL = bR + 1;
147     bR = GetBreakPointIdx(bL);
148   }
149   fBreakPoints.push_back(fLastPoint+1); // enforce drawing to end of line
150   Reset(vvec.size());
151   for (std::vector<Reve::Vector>::iterator i=vvec.begin(); i!=vvec.end(); ++i)
152     SetNextPoint((*i).x, (*i).y, (*i).z); 
153   delete [] fOrigPnts;
154 }
155
156 /**************************************************************************/
157 void NLTTrack::PrintLineSegments()
158 {
159   printf("%s LineSegments:\n", GetName());
160   Int_t start = 0;
161   Int_t segment = 0;
162   Vector S;
163   Vector E;
164   for (std::vector<Int_t>::iterator bpi = fBreakPoints.begin();
165        bpi != fBreakPoints.end(); ++bpi)
166   {
167     Int_t size = *bpi - start;
168
169     GetPoint(start, S.x, S.y, S.z);
170     GetPoint((*bpi)-1, E.x, E.y, E.z);
171     printf("seg %d size %d start %d ::(%f, %f, %f) (%f, %f, %f)\n", 
172            segment, size, start, S.x, S.y, S.z, E.x, E.y, E.z);
173     start   += size;
174     segment ++;
175   }
176 }
177
178 /**************************************************************************/
179
180 void NLTTrack::CtrlClicked(Reve::Track* /*track*/)
181 {
182   Track* t = dynamic_cast<Track*>(fProjectable);
183   if (t)
184     t->CtrlClicked(t);
185 }
186
187 //______________________________________________________________________
188 // NLTTrackList
189 //
190
191 ClassImp(NLTTrackList)
192
193 NLTTrackList::NLTTrackList() :
194   TrackList    (),
195   NLTProjected ()
196 {
197 }
198
199 /**************************************************************************/
200 void NLTTrackList::SetProjection(NLTProjector* proj, NLTProjectable* model)
201 {
202   NLTProjected::SetProjection(proj, model);
203  
204   TrackList& tl   = * dynamic_cast<TrackList*>(model);
205   SetLineColor(tl.GetLineColor());
206   SetLineStyle(tl.GetLineStyle());
207   SetLineWidth(tl.GetLineWidth());
208   SetMarkerColor(tl.GetMarkerColor());
209   SetMarkerStyle(tl.GetMarkerStyle());
210   SetMarkerSize(tl.GetMarkerSize());
211   SetRnrLine(tl.GetRnrLine());
212   SetRnrPoints(tl.GetRnrPoints());
213  
214   SetRnrStyle(tl.GetRnrStyle());
215 }