#include "TEveProjectionManager.h"
#include "TEveManager.h"
#include "TEveProjectionBases.h"
#include "TEveCompound.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),
   fImportEmpty (kFALSE)
{
   
   for (Int_t i = 0; i < TEveProjection::kPT_End; ++i)
      fProjections[i] = 0;
   SetProjection(TEveProjection::kPT_RPhi);
}
TEveProjectionManager::~TEveProjectionManager()
{
   
   
   for (Int_t i = 0; i < TEveProjection::kPT_End; ++i)
   {
      delete fProjections[i];
   }
   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));
}
void TEveProjectionManager::SetProjection(TEveProjection::EPType_e type)
{
   
   static const TEveException eH("TEveProjectionManager::SetProjection ");
   if (fProjections[type] == 0)
   {
      switch (type)
      {
         case TEveProjection::kPT_RPhi:
         {
            fProjections[type] = new TEveRPhiProjection();
            break;
         }
         case TEveProjection::kPT_RhoZ:
         {
            fProjections[type] = new TEveRhoZProjection();
            break;
         }
         default:
            throw(eH + "projection type not valid.");
            break;
      }
   }
   fProjection = fProjections[type];
   fProjection->SetCenter(fCenter);
   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 (fImportEmpty)
      return kTRUE;
   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);
      TEveCompound *cmpnd    = dynamic_cast<TEveCompound*>(el);
      TEveCompound *cmpnd_pr = dynamic_cast<TEveCompound*>(new_el);
      for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
      {
         TEveElement* child_pr = ImportElementsRecurse(*i, new_el);
         if (cmpnd && (*i)->GetCompound() == cmpnd)
            child_pr->SetCompound(cmpnd_pr);
      }
   }
   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 (HasChildren() == kFALSE) {
      BBoxZero();
      return;
   }
   BBoxInit();
}
Last change: Wed Jun 25 08:37:49 2008
Last generated: 2008-06-25 08:37
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.