35 ClassImp(TEveProjectionManager);
40 TEveProjectionManager::TEveProjectionManager(TEveProjection::EPType_e type):
41 TEveElementList(
"TEveProjectionManager",
""),
47 for (Int_t i = 0; i < TEveProjection::kPT_End; ++i)
50 if (type != TEveProjection::kPT_Unknown)
58 TEveProjectionManager::~TEveProjectionManager()
60 for (Int_t i = 0; i < TEveProjection::kPT_End; ++i)
62 delete fProjections[i];
64 while ( ! fDependentEls.empty())
66 fDependentEls.front()->Destroy();
73 void TEveProjectionManager::AddDependent(TEveElement* el)
75 fDependentEls.push_back(el);
81 void TEveProjectionManager::RemoveDependent(TEveElement* el)
83 fDependentEls.remove(el);
89 void TEveProjectionManager::UpdateName()
91 if (fProjection->Is2D())
92 SetName(Form (
"%s (%3.1f)", fProjection->GetName(), fProjection->GetDistortion()*1000));
94 SetName(fProjection->GetName());
100 void TEveProjectionManager::SetProjection(TEveProjection::EPType_e type)
102 static const TEveException eH(
"TEveProjectionManager::SetProjection ");
104 if (fProjections[type] == 0)
108 case TEveProjection::kPT_RPhi:
110 fProjections[type] =
new TEveRPhiProjection();
113 case TEveProjection::kPT_RhoZ:
115 fProjections[type] =
new TEveRhoZProjection();
118 case TEveProjection::kPT_3D:
120 fProjections[type] =
new TEve3DProjection();
124 throw eH +
"projection type not valid.";
129 if (fProjection && fProjection->Is2D() != fProjections[type]->Is2D())
131 throw eH +
"switching between 2D and 3D projections not implemented.";
134 fProjection = fProjections[type];
135 fProjection->SetCenter(fCenter);
142 void TEveProjectionManager::SetCenter(Float_t x, Float_t y, Float_t z)
144 fCenter.Set(x, y, z);
145 fProjection->SetCenter(fCenter);
153 Bool_t TEveProjectionManager::HandleElementPaste(TEveElement* el)
155 List_t::size_type n_children = fChildren.size();
157 return n_children != fChildren.size();
167 Bool_t TEveProjectionManager::ShouldImport(TEveElement* el)
172 if (el->IsA() != TEveElementList::Class() && el->IsA()->InheritsFrom(TEveProjectable::Class()))
174 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
175 if (ShouldImport(*i))
184 void TEveProjectionManager::UpdateDependentElsAndScenes(TEveElement* root)
186 for (List_i i=fDependentEls.begin(); i!=fDependentEls.end(); ++i)
188 TAttBBox* bbox =
dynamic_cast<TAttBBox*
>(*i);
194 root->CollectSceneParentsFromChildren(scenes, 0);
195 gEve->ScenesChanged(scenes);
206 TEveElement* TEveProjectionManager::ImportElementsRecurse(TEveElement* el,
209 static const TEveException eh(
"TEveProjectionManager::ImportElementsRecurse ");
211 TEveElement *new_el = 0;
213 if (ShouldImport(el))
215 TEveProjected *new_pr = 0;
216 TEveProjectable *pble =
dynamic_cast<TEveProjectable*
>(el);
219 new_el = (TEveElement*) pble->ProjectedClass(fProjection)->New();
220 new_pr =
dynamic_cast<TEveProjected*
>(new_el);
221 new_pr->SetProjection(
this, pble);
222 new_pr->SetDepth(fCurrentDepth);
226 new_el =
new TEveElementList;
228 new_el->SetElementName (Form(
"%s [P]", el->GetElementName()));
229 new_el->SetElementTitle(Form(
"Projected replica.\n%s", el->GetElementTitle()));
230 new_el->SetRnrSelf (el->GetRnrSelf());
231 new_el->SetRnrChildren (el->GetRnrChildren());
232 new_el->SetPickable (el->IsPickable());
233 parent->AddElement(new_el);
235 TEveCompound *cmpnd =
dynamic_cast<TEveCompound*
>(el);
236 TEveCompound *cmpnd_pr =
dynamic_cast<TEveCompound*
>(new_el);
237 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
239 TEveElement* child_pr = ImportElementsRecurse(*i, new_el);
240 if (cmpnd && (*i)->GetCompound() == cmpnd)
241 child_pr->SetCompound(cmpnd_pr);
260 TEveElement* TEveProjectionManager::ImportElements(TEveElement* el,
261 TEveElement* ext_list)
263 TEveElement* new_el = ImportElementsRecurse(el,
this);
267 ProjectChildrenRecurse(new_el);
268 AssertBBoxExtents(0.1);
271 UpdateDependentElsAndScenes(new_el);
274 ext_list->AddElement(new_el);
292 TEveElement* TEveProjectionManager::SubImportElements(TEveElement* el,
293 TEveElement* proj_parent)
295 TEveElement* new_el = ImportElementsRecurse(el, proj_parent);
299 ProjectChildrenRecurse(new_el);
300 AssertBBoxExtents(0.1);
303 UpdateDependentElsAndScenes(new_el);
321 Int_t TEveProjectionManager::SubImportChildren(TEveElement* el, TEveElement* proj_parent)
324 for (List_i i = el->BeginChildren(); i != el->EndChildren(); ++i)
326 TEveElement* new_el = ImportElementsRecurse(*i, proj_parent);
328 new_els.push_back(new_el);
331 if ( ! new_els.empty())
334 for (List_i i = new_els.begin(); i != new_els.end(); ++i)
336 ProjectChildrenRecurse(*i);
338 AssertBBoxExtents(0.1);
341 UpdateDependentElsAndScenes(proj_parent);
343 return (Int_t) new_els.size();
351 void TEveProjectionManager::ProjectChildrenRecurse(TEveElement* el)
353 TEveProjected* pted =
dynamic_cast<TEveProjected*
>(el);
356 pted->UpdateProjection();
357 TAttBBox* bb =
dynamic_cast<TAttBBox*
>(pted);
360 Float_t* b = bb->AssertBBox();
361 BBoxCheckPoint(b[0], b[2], b[4]);
362 BBoxCheckPoint(b[1], b[3], b[5]);
364 el->ElementChanged(kFALSE);
367 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
368 ProjectChildrenRecurse(*i);
375 void TEveProjectionManager::ProjectChildren()
378 for (List_i i=BeginChildren(); i!=EndChildren(); ++i)
379 ProjectChildrenRecurse(*i);
380 AssertBBoxExtents(0.1);
383 UpdateDependentElsAndScenes(
this);
393 void TEveProjectionManager::ComputeBBox()
395 static const TEveException eH(
"TEveProjectionManager::ComputeBBox ");
397 if (HasChildren() == kFALSE) {