33 using namespace ROOT::Experimental;
34 namespace REX = ROOT::Experimental;
39 REveProjectionManager::REveProjectionManager(REveProjection::EPType_e type):
40 REveElement(
"REveProjectionManager",
"")
42 for (Int_t i = 0; i < REveProjection::kPT_End; ++i)
43 fProjections[i] =
nullptr;
45 if (type != REveProjection::kPT_Unknown)
53 REveProjectionManager::~REveProjectionManager()
55 for (Int_t i = 0; i < REveProjection::kPT_End; ++i) {
56 delete fProjections[i];
58 while ( ! fDependentEls.empty()) {
59 fDependentEls.front()->Destroy();
66 void REveProjectionManager::AddDependent(REveElement *el)
68 fDependentEls.push_back(el);
74 void REveProjectionManager::RemoveDependent(REveElement *el)
76 fDependentEls.remove(el);
82 void REveProjectionManager::UpdateName()
84 if (fProjection->Is2D())
85 SetName(Form (
"%s (%3.1f)", fProjection->GetName(), fProjection->GetDistortion()*1000));
87 SetName(fProjection->GetName());
93 void REveProjectionManager::SetProjection(REveProjection::EPType_e type)
95 static const REveException eH(
"REveProjectionManager::SetProjection ");
97 if (fProjections[type] == 0)
101 case REveProjection::kPT_RPhi:
103 fProjections[type] =
new REveRPhiProjection();
106 case REveProjection::kPT_RhoZ:
108 fProjections[type] =
new REveRhoZProjection();
111 case REveProjection::kPT_3D:
113 fProjections[type] =
new REve3DProjection();
117 throw eH +
"projection type not valid.";
122 if (fProjection && fProjection->Is2D() != fProjections[type]->Is2D())
124 throw eH +
"switching between 2D and 3D projections not implemented.";
127 fProjection = fProjections[type];
128 fProjection->SetCenter(fCenter);
135 void REveProjectionManager::SetCenter(Float_t x, Float_t y, Float_t z)
137 fCenter.Set(x, y, z);
138 fProjection->SetCenter(fCenter);
149 Bool_t REveProjectionManager::ShouldImport(REveElement *el)
154 if (el->IsA()->InheritsFrom(TClass::GetClass<REveProjectable>()))
156 for (
auto &c: el->RefChildren())
166 void REveProjectionManager::UpdateDependentElsAndScenes(REveElement * )
168 for (
auto &d: fDependentEls) {
169 TAttBBox* bbox =
dynamic_cast<TAttBBox *
>(d);
174 static int warn_count = 0;
175 if (++warn_count <= 5)
176 Warning(
"REveProjectionManager::UpdateDependentElsAndScenes",
177 "Figure out if scene stamping is still needed.");
197 REveElement* REveProjectionManager::ImportElementsRecurse(REveElement* el,
200 static const REveException eh(
"REveProjectionManager::ImportElementsRecurse ");
202 REveElement *new_el =
nullptr;
204 if (ShouldImport(el))
206 REveProjected *new_pr =
nullptr;
207 REveProjectable *pble =
dynamic_cast<REveProjectable*
>(el);
210 new_el = (REveElement*) pble->ProjectedClass(fProjection)->New();
211 new_pr =
dynamic_cast<REveProjected*
>(new_el);
212 new_pr->SetProjection(
this, pble);
213 new_pr->SetDepth(fCurrentDepth);
217 new_el =
new REveElement;
219 new_el->SetName (Form(
"%s [P]", el->GetCName()));
220 new_el->SetTitle(Form(
"Projected replica.\n%s", el->GetCTitle()));
221 new_el->SetRnrSelf (el->GetRnrSelf());
222 new_el->SetRnrChildren (el->GetRnrChildren());
223 new_el->SetPickable (el->IsPickable());
225 parent->AddElement(new_el);
227 REveCompound *cmpnd =
dynamic_cast<REveCompound*
>(el);
228 REveCompound *cmpnd_pr =
dynamic_cast<REveCompound*
>(new_el);
229 for (
auto &c: el->RefChildren()) {
230 REveElement *child_pr = ImportElementsRecurse(c, new_el);
231 if (cmpnd && c->GetCompound() == cmpnd)
232 child_pr->SetCompound(cmpnd_pr);
251 REveElement* REveProjectionManager::ImportElements(REveElement* el,
252 REveElement* ext_list)
254 REveElement* new_el = ImportElementsRecurse(el, ext_list ? ext_list :
this);
258 ProjectChildrenRecurse(new_el);
259 AssertBBoxExtents(0.1);
262 UpdateDependentElsAndScenes(new_el);
283 REveElement* REveProjectionManager::SubImportElements(REveElement* el,
284 REveElement* proj_parent)
286 REveElement* new_el = ImportElementsRecurse(el, proj_parent);
290 ProjectChildrenRecurse(new_el);
291 AssertBBoxExtents(0.1);
294 UpdateDependentElsAndScenes(new_el);
312 Int_t REveProjectionManager::SubImportChildren(REveElement* el, REveElement* proj_parent)
315 for (
auto &c: el->RefChildren()) {
316 auto new_el = ImportElementsRecurse(c, proj_parent);
318 new_els.push_back(new_el);
321 if (!new_els.empty())
324 for (
auto &nel: new_els)
325 ProjectChildrenRecurse(nel);
326 AssertBBoxExtents(0.1);
329 UpdateDependentElsAndScenes(proj_parent);
331 return (Int_t) new_els.size();
339 void REveProjectionManager::ProjectChildrenRecurse(REveElement* el)
341 REveProjected* pted =
dynamic_cast<REveProjected*
>(el);
344 pted->UpdateProjection();
345 TAttBBox* bb =
dynamic_cast<TAttBBox*
>(pted);
348 Float_t* b = bb->AssertBBox();
349 BBoxCheckPoint(b[0], b[2], b[4]);
350 BBoxCheckPoint(b[1], b[3], b[5]);
355 for (
auto &c : el->RefChildren()) ProjectChildrenRecurse(c);
362 void REveProjectionManager::ProjectChildren()
366 for (
auto &c : fChildren) ProjectChildrenRecurse(c);
368 for (
auto &n : fNieces) ProjectChildrenRecurse(n);
370 AssertBBoxExtents(0.1);
373 UpdateDependentElsAndScenes(
this);
383 void REveProjectionManager::ComputeBBox()
385 static const REveException eH(
"REveProjectionManager::ComputeBBox ");
387 if ( ! HasChildren() && ! HasNieces())