#include "TEveProjectionManager.h"
#include "TEveManager.h"
#include "TEveProjectionBases.h"
#include "TAttBBox.h"
#include "TBuffer3D.h"
#include "TBuffer3DTypes.h"
#include "TVirtualPad.h"
#include "TVirtualViewer3D.h"
#include "TClass.h"
#include <list>
ClassImp(TEveProjectionManager);
TEveProjectionManager::TEveProjectionManager():
TEveElementList("TEveProjectionManager",""),
TAttBBox(),
fProjection (0),
fCurrentDepth(0)
{
fProjection = new TEveRPhiProjection(fCenter);
UpdateName();
}
TEveProjectionManager::~TEveProjectionManager()
{
if (fProjection) delete fProjection;
while ( ! fDependentEls.empty())
{
fDependentEls.front()->Destroy();
}
}
void TEveProjectionManager::AddDependent(TEveElement* el)
{
fDependentEls.push_back(el);
}
void TEveProjectionManager::RemoveDependent(TEveElement* el)
{
fDependentEls.remove(el);
}
void TEveProjectionManager::UpdateName()
{
SetName(Form ("%s (%3.1f)", fProjection->GetName(), fProjection->GetDistortion()*1000));
UpdateItems();
}
void TEveProjectionManager::SetProjection(TEveProjection::EPType_e type, Float_t distort)
{
static const TEveException eH("TEveProjectionManager::SetProjection ");
delete fProjection;
fProjection = 0;
switch (type)
{
case TEveProjection::kPT_RPhi:
{
fProjection = new TEveRPhiProjection(fCenter);
break;
}
case TEveProjection::kPT_RhoZ:
{
fProjection = new TEveRhoZProjection(fCenter);
break;
}
default:
throw(eH + "projection type not valid.");
break;
}
fProjection->SetDistortion(distort);
UpdateName();
}
void TEveProjectionManager::SetCenter(Float_t x, Float_t y, Float_t z)
{
fCenter.Set(x, y, z);
fProjection->SetCenter(fCenter);
ProjectChildren();
}
Bool_t TEveProjectionManager::HandleElementPaste(TEveElement* el)
{
List_t::size_type n_children = fChildren.size();
ImportElements(el);
return n_children != fChildren.size();
}
Bool_t TEveProjectionManager::ShouldImport(TEveElement* el)
{
if (el->IsA()->InheritsFrom(TEveProjectable::Class()))
return kTRUE;
for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
if (ShouldImport(*i))
return kTRUE;
return kFALSE;
}
void TEveProjectionManager::UpdateDependentElsAndScenes(TEveElement* root)
{
for (List_i i=fDependentEls.begin(); i!=fDependentEls.end(); ++i)
{
TAttBBox* bbox = dynamic_cast<TAttBBox*>(*i);
if (bbox)
bbox->ComputeBBox();
}
List_t scenes;
root->CollectSceneParentsFromChildren(scenes, 0);
gEve->ScenesChanged(scenes);
}
TEveElement* TEveProjectionManager::ImportElementsRecurse(TEveElement* el,
TEveElement* parent)
{
static const TEveException eh("TEveProjectionManager::ImportElementsRecurse ");
TEveElement *new_el = 0;
if (ShouldImport(el))
{
TEveProjected *new_pr = 0;
TEveProjectable *pble = dynamic_cast<TEveProjectable*>(el);
if (pble)
{
new_el = (TEveElement*) pble->ProjectedClass()->New();
new_pr = dynamic_cast<TEveProjected*>(new_el);
new_pr->SetProjection(this, pble);
new_pr->SetDepth(fCurrentDepth);
}
else
{
new_el = new TEveElementList;
}
new_el->SetElementName (Form("%s [P]", el->GetElementName()));
new_el->SetElementTitle(Form("Projected replica.\n%s", el->GetElementTitle()));
new_el->SetRnrSelf (el->GetRnrSelf());
new_el->SetRnrChildren (el->GetRnrChildren());
new_el->SetPickable (el->IsPickable());
parent->AddElement(new_el);
for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
ImportElementsRecurse(*i, new_el);
}
return new_el;
}
TEveElement* TEveProjectionManager::ImportElements(TEveElement* el,
TEveElement* ext_list)
{
TEveElement* new_el = ImportElementsRecurse(el, this);
if (new_el)
{
AssertBBox();
ProjectChildrenRecurse(new_el);
AssertBBoxExtents(0.1);
UpdateDependentElsAndScenes(new_el);
if (ext_list)
ext_list->AddElement(new_el);
}
return new_el;
}
void TEveProjectionManager::ProjectChildrenRecurse(TEveElement* el)
{
TEveProjected* pted = dynamic_cast<TEveProjected*>(el);
if (pted)
{
pted->UpdateProjection();
TAttBBox* bb = dynamic_cast<TAttBBox*>(pted);
if (bb)
{
Float_t* b = bb->AssertBBox();
BBoxCheckPoint(b[0], b[2], b[4]);
BBoxCheckPoint(b[1], b[3], b[5]);
}
el->ElementChanged(kFALSE);
}
for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
ProjectChildrenRecurse(*i);
}
void TEveProjectionManager::ProjectChildren()
{
BBoxInit();
ProjectChildrenRecurse(this);
AssertBBoxExtents(0.1);
UpdateDependentElsAndScenes(this);
}
void TEveProjectionManager::ComputeBBox()
{
static const TEveException eH("TEveProjectionManager::ComputeBBox ");
if (GetNChildren() == 0) {
BBoxZero();
return;
}
BBoxInit();
}
Last change: Tue May 13 17:09:36 2008
Last generated: 2008-05-13 17:09
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.