]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/NLTProjector.cxx
Dummy methods DefineParticle required by the interface added.
[u/mrichter/AliRoot.git] / EVE / Reve / NLTProjector.cxx
1 #include "NLTProjector.h"
2 #include "ReveManager.h"
3 #include "NLTBases.h"
4
5 #include "TBuffer3D.h"
6 #include "TBuffer3DTypes.h"
7 #include <TVirtualPad.h>
8 #include <TVirtualViewer3D.h>
9
10 #include <list>
11
12 using namespace Reve;
13
14 //______________________________________________________________________________
15 // NLTProjector
16 //
17 // Recursively projects RenderElement and draws axis in the projected scene.
18 // It enables to interactivly set NLTProjection parameters and updates
19 // projected scene accordingly.
20
21 ClassImp(NLTProjector)
22
23 //______________________________________________________________________________
24 NLTProjector::NLTProjector():
25   RenderElementList("NLTProjector",""),
26
27   fProjection (0),
28
29   fDrawCenter(kFALSE),
30   fDrawOrigin(kFALSE),
31
32   fSplitInfoMode(0),
33   fSplitInfoLevel(1),
34   fAxisColor(0),
35
36   fCurrentDepth(0)
37 {
38   // Constructor.
39
40   fProjection  = new NLTCircularFishEye(fCenter);
41   UpdateName();
42 }
43
44 //______________________________________________________________________________
45 NLTProjector::~NLTProjector()
46 {
47   // Destructor.
48
49   if(fProjection) delete fProjection;
50 }
51
52 //______________________________________________________________________________
53 void NLTProjector::UpdateName()
54 {
55   // Updates name to have consitent information with prjection.
56
57   SetName(Form ("%s (%3.1f)", fProjection->GetName(), fProjection->GetDistortion()*1000));
58   UpdateItems();
59 }
60
61 //______________________________________________________________________________
62 void NLTProjector::SetProjection(NLTProjection::PType_e type, Float_t distort)
63 {
64   // Set projection type and distortion.
65
66   static const Exc_t eH("NLTProjector::SetProjection ");
67
68   delete fProjection;
69   fProjection = 0;
70
71   switch (type)
72   {
73     case NLTProjection::PT_CFishEye:
74     {
75       fProjection  = new NLTCircularFishEye(fCenter);
76       break;
77     }
78     case NLTProjection::PT_RhoZ:
79     {
80       fProjection  = new NLTRhoZ(fCenter);
81       break;
82     }
83     default:
84       throw(eH + "projection type not valid.");
85       break;
86   }
87   fProjection->SetDistortion(distort);
88   UpdateName();
89 }
90 //______________________________________________________________________________
91 void NLTProjector::SetCenter(Float_t x, Float_t y, Float_t z)
92 {
93   // Set projection center and rebuild projected scene.
94
95   fCenter.Set(x, y, z);
96   fProjection->SetCenter(fCenter);
97   ProjectChildren();
98 }
99
100 //______________________________________________________________________________
101 Bool_t NLTProjector::HandleElementPaste(RenderElement* el)
102 {
103   // React to element being pasted or dnd-ed.
104   // Return true if redraw is needed (virtual method).
105
106   size_t n_children  = fChildren.size();
107   ImportElements(el);
108   return n_children != fChildren.size();
109 }
110
111 //______________________________________________________________________________
112 Bool_t NLTProjector::ShouldImport(RenderElement* rnr_el)
113 {
114   // Returns true if rnr_el or any of its children is NTLProjectable.
115
116   if (rnr_el->IsA()->InheritsFrom(NLTProjectable::Class()))
117     return kTRUE;
118   for (List_i i=rnr_el->BeginChildren(); i!=rnr_el->EndChildren(); ++i)
119     if (ShouldImport(*i))
120       return kTRUE;
121   return kFALSE;
122 }
123
124 //______________________________________________________________________________
125 void NLTProjector::ImportElementsRecurse(RenderElement* rnr_el, RenderElement* parent)
126 {
127   // If rnr_el is NLTProjectable add projected instance else add plain RenderElementList
128   // to parent. Call same function on rnr_el children.
129
130   if (ShouldImport(rnr_el))
131   {
132     RenderElement  *new_re = 0;
133     NLTProjected   *new_pr = 0;
134     NLTProjectable *pble   = dynamic_cast<NLTProjectable*>(rnr_el);
135     if (pble)
136     {
137       new_re = (RenderElement*) pble->ProjectedClass()->New();
138       new_pr = dynamic_cast<NLTProjected*>(new_re);
139       new_pr->SetProjection(this, pble);
140       new_pr->SetDepth(fCurrentDepth);
141     }
142     else
143     {
144       new_re = new RenderElementList;
145     }
146     TObject *tobj   = rnr_el->GetObject();
147     new_re->SetRnrElNameTitle(Form("NLT %s", tobj->GetName()),
148                               tobj->GetTitle());
149     new_re->SetRnrSelf     (rnr_el->GetRnrSelf());
150     new_re->SetRnrChildren(rnr_el->GetRnrChildren());
151     gReve->AddRenderElement(new_re, parent);
152
153     for (List_i i=rnr_el->BeginChildren(); i!=rnr_el->EndChildren(); ++i)
154       ImportElementsRecurse(*i, new_re);
155   }
156 }
157
158 //______________________________________________________________________________
159 void NLTProjector::ImportElements(RenderElement* rnr_el)
160 {
161   // Recursively import elements and update projection on the projected objects.
162
163   ImportElementsRecurse(rnr_el, this);
164   ProjectChildren();
165 }
166
167 //______________________________________________________________________________
168 void NLTProjector::ProjectChildrenRecurse(RenderElement* rnr_el)
169 {
170   // Go recursively through rnr_el tree and call UpdateProjection() on NLTProjected.
171
172   NLTProjected* pted = dynamic_cast<NLTProjected*>(rnr_el);
173   if (pted)
174   {
175     pted->UpdateProjection();
176     TAttBBox* bb = dynamic_cast<TAttBBox*>(pted);
177     if(bb)
178     {
179       Float_t* b = bb->AssertBBox();
180       BBoxCheckPoint(b[0], b[2], b[4]);
181       BBoxCheckPoint(b[1], b[3], b[5]);
182     }
183     rnr_el->ElementChanged(kFALSE);
184   }
185
186   for (List_i i=rnr_el->BeginChildren(); i!=rnr_el->EndChildren(); ++i)
187     ProjectChildrenRecurse(*i);
188 }
189
190 //______________________________________________________________________________
191 void NLTProjector::ProjectChildren()
192 {
193   // Project children recursevly, update BBox and notify ReveManger
194   // the scenes have chenged.
195
196   BBoxZero();
197   ProjectChildrenRecurse(this);
198   AssertBBoxExtents(0.1);
199   {
200     using namespace TMath;
201     fBBox[0] = 10.0f * Floor(fBBox[0]/10.0f);
202     fBBox[1] = 10.0f * Ceil (fBBox[1]/10.0f);
203     fBBox[2] = 10.0f * Floor(fBBox[2]/10.0f);
204     fBBox[3] = 10.0f * Ceil (fBBox[3]/10.0f);
205   }
206
207   List_t scenes;
208   CollectSceneParentsFromChildren(scenes, 0);
209   gReve->ScenesChanged(scenes);
210 }
211
212 //______________________________________________________________________________
213 void NLTProjector::Paint(Option_t* /*option*/)
214 {
215   // Paint this object. Only direct rendering is supported.
216
217   static const Exc_t eH("NLTProjector::Paint ");
218   TBuffer3D buff(TBuffer3DTypes::kGeneric);
219
220   // Section kCore
221   buff.fID           = this;
222   buff.fColor        = fAxisColor;
223   buff.fTransparency = 0;
224   buff.SetSectionsValid(TBuffer3D::kCore);
225
226   Int_t reqSections = gPad->GetViewer3D()->AddObject(buff);
227   if (reqSections != TBuffer3D::kNone)
228     Error(eH, "only direct GL rendering supported.");
229 }
230
231 //______________________________________________________________________________
232 void NLTProjector::ComputeBBox()
233 {
234   // Virtual from TAttBBox; fill bounding-box information.
235
236   static const Exc_t eH("NLTProjector::ComputeBBox ");
237
238   if(GetNChildren() == 0) {
239     BBoxZero();
240     return;
241   }
242
243   BBoxInit();
244 }