1 #include "NLTProjector.h"
2 #include "ReveManager.h"
6 #include "TBuffer3DTypes.h"
7 #include <TVirtualPad.h>
8 #include <TVirtualViewer3D.h>
14 //______________________________________________________________________________
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.
21 ClassImp(NLTProjector)
23 //______________________________________________________________________________
24 NLTProjector::NLTProjector():
25 RenderElementList("NLTProjector",""),
40 fProjection = new NLTCircularFishEye(fCenter);
44 //______________________________________________________________________________
45 NLTProjector::~NLTProjector()
49 if(fProjection) delete fProjection;
52 //______________________________________________________________________________
53 void NLTProjector::UpdateName()
55 // Updates name to have consitent information with prjection.
57 SetName(Form ("%s (%3.1f)", fProjection->GetName(), fProjection->GetDistortion()*1000));
61 //______________________________________________________________________________
62 void NLTProjector::SetProjection(NLTProjection::PType_e type, Float_t distort)
64 // Set projection type and distortion.
66 static const Exc_t eH("NLTProjector::SetProjection ");
73 case NLTProjection::PT_CFishEye:
75 fProjection = new NLTCircularFishEye(fCenter);
78 case NLTProjection::PT_RhoZ:
80 fProjection = new NLTRhoZ(fCenter);
84 throw(eH + "projection type not valid.");
87 fProjection->SetDistortion(distort);
90 //______________________________________________________________________________
91 void NLTProjector::SetCenter(Float_t x, Float_t y, Float_t z)
93 // Set projection center and rebuild projected scene.
96 fProjection->SetCenter(fCenter);
100 //______________________________________________________________________________
101 Bool_t NLTProjector::HandleElementPaste(RenderElement* el)
103 // React to element being pasted or dnd-ed.
104 // Return true if redraw is needed (virtual method).
106 size_t n_children = fChildren.size();
108 return n_children != fChildren.size();
111 //______________________________________________________________________________
112 Bool_t NLTProjector::ShouldImport(RenderElement* rnr_el)
114 // Returns true if rnr_el or any of its children is NTLProjectable.
116 if (rnr_el->IsA()->InheritsFrom(NLTProjectable::Class()))
118 for (List_i i=rnr_el->BeginChildren(); i!=rnr_el->EndChildren(); ++i)
119 if (ShouldImport(*i))
124 //______________________________________________________________________________
125 void NLTProjector::ImportElementsRecurse(RenderElement* rnr_el, RenderElement* parent)
127 // If rnr_el is NLTProjectable add projected instance else add plain RenderElementList
128 // to parent. Call same function on rnr_el children.
130 if (ShouldImport(rnr_el))
132 RenderElement *new_re = 0;
133 NLTProjected *new_pr = 0;
134 NLTProjectable *pble = dynamic_cast<NLTProjectable*>(rnr_el);
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);
144 new_re = new RenderElementList;
146 TObject *tobj = rnr_el->GetObject();
147 new_re->SetRnrElNameTitle(Form("NLT %s", tobj->GetName()),
149 new_re->SetRnrSelf (rnr_el->GetRnrSelf());
150 new_re->SetRnrChildren(rnr_el->GetRnrChildren());
151 gReve->AddRenderElement(new_re, parent);
153 for (List_i i=rnr_el->BeginChildren(); i!=rnr_el->EndChildren(); ++i)
154 ImportElementsRecurse(*i, new_re);
158 //______________________________________________________________________________
159 void NLTProjector::ImportElements(RenderElement* rnr_el)
161 // Recursively import elements and update projection on the projected objects.
163 ImportElementsRecurse(rnr_el, this);
167 //______________________________________________________________________________
168 void NLTProjector::ProjectChildrenRecurse(RenderElement* rnr_el)
170 // Go recursively through rnr_el tree and call UpdateProjection() on NLTProjected.
172 NLTProjected* pted = dynamic_cast<NLTProjected*>(rnr_el);
175 pted->UpdateProjection();
176 TAttBBox* bb = dynamic_cast<TAttBBox*>(pted);
179 Float_t* b = bb->AssertBBox();
180 BBoxCheckPoint(b[0], b[2], b[4]);
181 BBoxCheckPoint(b[1], b[3], b[5]);
183 rnr_el->ElementChanged(kFALSE);
186 for (List_i i=rnr_el->BeginChildren(); i!=rnr_el->EndChildren(); ++i)
187 ProjectChildrenRecurse(*i);
190 //______________________________________________________________________________
191 void NLTProjector::ProjectChildren()
193 // Project children recursevly, update BBox and notify ReveManger
194 // the scenes have chenged.
197 ProjectChildrenRecurse(this);
198 AssertBBoxExtents(0.1);
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);
208 CollectSceneParentsFromChildren(scenes, 0);
209 gReve->ScenesChanged(scenes);
212 //______________________________________________________________________________
213 void NLTProjector::Paint(Option_t* /*option*/)
215 // Paint this object. Only direct rendering is supported.
217 static const Exc_t eH("NLTProjector::Paint ");
218 TBuffer3D buff(TBuffer3DTypes::kGeneric);
222 buff.fColor = fAxisColor;
223 buff.fTransparency = 0;
224 buff.SetSectionsValid(TBuffer3D::kCore);
226 Int_t reqSections = gPad->GetViewer3D()->AddObject(buff);
227 if (reqSections != TBuffer3D::kNone)
228 Error(eH, "only direct GL rendering supported.");
231 //______________________________________________________________________________
232 void NLTProjector::ComputeBBox()
234 // Virtual from TAttBBox; fill bounding-box information.
236 static const Exc_t eH("NLTProjector::ComputeBBox ");
238 if(GetNChildren() == 0) {