TEveProjectionBases.cxx

Go to the documentation of this file.
00001 // @(#)root/eve:$Id: TEveProjectionBases.cxx 36373 2010-10-19 17:43:35Z matevz $
00002 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "TEveProjectionBases.h"
00013 #include "TEveProjectionManager.h"
00014 #include "TEveManager.h"
00015 
00016 #include <cassert>
00017 
00018 //==============================================================================
00019 //==============================================================================
00020 // TEveProjectable
00021 //==============================================================================
00022 
00023 //______________________________________________________________________________
00024 //
00025 // Abstract base-class for non-linear projectable objects.
00026 //
00027 // Via ProjectedClass(const TEveProjection* p) method it returns a
00028 // TClass instance for the projected class and keeps references to the
00029 // projected objects.
00030 //
00031 // It is assumed that all classes deriving from TEveProjectable are also
00032 // derived from TEveElement.
00033 //
00034 // See also TEveProjectionManager::ImportElements().
00035 
00036 ClassImp(TEveProjectable);
00037 
00038 //______________________________________________________________________________
00039 TEveProjectable::TEveProjectable()
00040 {
00041    // Constructor.
00042 }
00043 
00044 //______________________________________________________________________________
00045 TEveProjectable::~TEveProjectable()
00046 {
00047    // Destructor.
00048    // Force projected replicas to unreference *this, then destroy them.
00049 
00050    while ( ! fProjectedList.empty())
00051    {
00052       TEveProjected* p = fProjectedList.front();
00053       p->UnRefProjectable(this);
00054       TEveElement* el = p->GetProjectedAsElement();
00055       assert(el);
00056       {
00057          gEve->PreDeleteElement(el);
00058          delete el;
00059       }
00060    }
00061 }
00062 
00063 //______________________________________________________________________________
00064 void TEveProjectable::AnnihilateProjecteds()
00065 {
00066    // Optimized destroy of projected elements with condition 
00067    // there is only one parent for projected element. Method is 
00068    // called from TEveElement::Annihilate(). 
00069 
00070    for (ProjList_i i=fProjectedList.begin(); i!=fProjectedList.end(); ++i)
00071    {
00072       (*i)->UnRefProjectable(this, kFALSE);
00073       (*i)->GetProjectedAsElement()->Annihilate();
00074    }
00075    fProjectedList.clear();
00076 }
00077 
00078 //______________________________________________________________________________
00079 void TEveProjectable::ClearProjectedList()
00080 {
00081    fProjectedList.clear();
00082 }
00083 
00084 //______________________________________________________________________________
00085 void TEveProjectable::AddProjectedsToSet(std::set<TEveElement*>& set)
00086 {
00087    // Add the projected elements to the set, dyn-casting them to
00088    // TEveElement.
00089 
00090    for (ProjList_i i=fProjectedList.begin(); i!=fProjectedList.end(); ++i)
00091    {
00092       set.insert((*i)->GetProjectedAsElement());
00093    }
00094 }
00095 
00096 //==============================================================================
00097 
00098 //______________________________________________________________________________
00099 void TEveProjectable::PropagateVizParams(TEveElement* el)
00100 {
00101    // Set visualization parameters of projecteds.
00102    // Use element el as model. If el == 0 (default), this casted to
00103    // TEveElement is used.
00104 
00105    if (el == 0)
00106       el = dynamic_cast<TEveElement*>(this);
00107 
00108    for (ProjList_i i=fProjectedList.begin(); i!=fProjectedList.end(); ++i)
00109    {
00110       (*i)->GetProjectedAsElement()->CopyVizParams(el);
00111    }
00112 }
00113 
00114 //______________________________________________________________________________
00115 void TEveProjectable::PropagateRenderState(Bool_t rnr_self, Bool_t rnr_children)
00116 {
00117    // Set render state of projecteds.
00118 
00119    for (ProjList_i i=fProjectedList.begin(); i!=fProjectedList.end(); ++i)
00120    {
00121       if ((*i)->GetProjectedAsElement()->SetRnrSelfChildren(rnr_self, rnr_children))
00122          (*i)->GetProjectedAsElement()->ElementChanged();
00123    }
00124 }
00125 
00126 //______________________________________________________________________________
00127 void TEveProjectable::PropagateMainColor(Color_t color, Color_t old_color)
00128 {
00129    // Set main color of projecteds if their color is the same as old_color.
00130 
00131    for (ProjList_i i=fProjectedList.begin(); i!=fProjectedList.end(); ++i)
00132    {
00133       if ((*i)->GetProjectedAsElement()->GetMainColor() == old_color)
00134          (*i)->GetProjectedAsElement()->SetMainColor(color);
00135    }
00136 }
00137 
00138 //______________________________________________________________________________
00139 void TEveProjectable::PropagateMainTransparency(Char_t t, Char_t old_t)
00140 {
00141    // Set main transparency of projecteds if their transparecy is the
00142    // same as the old one.
00143 
00144    for (ProjList_i i=fProjectedList.begin(); i!=fProjectedList.end(); ++i)
00145    {
00146       if ((*i)->GetProjectedAsElement()->GetMainTransparency() == old_t)
00147          (*i)->GetProjectedAsElement()->SetMainTransparency(t);
00148    }
00149 }
00150 
00151 
00152 //==============================================================================
00153 //==============================================================================
00154 // TEveProjected
00155 //==============================================================================
00156 
00157 //______________________________________________________________________________
00158 //
00159 // Abstract base class for classes that hold results of a non-linear
00160 // projection transformation.
00161 //
00162 // It is assumed that all classes deriving from TEveProjected are also
00163 // derived from TEveElement.
00164 
00165 ClassImp(TEveProjected);
00166 
00167 //______________________________________________________________________________
00168 TEveProjected::TEveProjected() :
00169    fManager     (0),
00170    fProjectable (0),
00171    fDepth       (0)
00172 {
00173    // Constructor.
00174 }
00175 
00176 //______________________________________________________________________________
00177 TEveProjected::~TEveProjected()
00178 {
00179    // Destructor.
00180    // If fProjectable is non-null, *this is removed from its list of
00181    // projected replicas.
00182 
00183    if (fProjectable) fProjectable->RemoveProjected(this);
00184 }
00185 
00186 //______________________________________________________________________________
00187 TEveElement* TEveProjected::GetProjectedAsElement()
00188 {
00189    // Returns fProjectable dynamic-casted to TEveElement.
00190 
00191    return dynamic_cast<TEveElement*>(this);
00192 }
00193 
00194 //______________________________________________________________________________
00195 void TEveProjected::SetProjection(TEveProjectionManager* mng, TEveProjectable* model)
00196 {
00197    // Sets projection manager and reference in the projectable object. Method called
00198    // immediately after default constructor.
00199    // See also TEveProjectionManager::ImportElements().
00200 
00201    fManager   = mng;
00202    if (fProjectable) fProjectable->RemoveProjected(this);
00203    fProjectable = model;
00204    if (fProjectable) fProjectable->AddProjected(this);
00205 }
00206 
00207 //______________________________________________________________________________
00208 void TEveProjected::UnRefProjectable(TEveProjectable* assumed_parent, bool notifyParent)
00209 {
00210    // Remove reference to projectable.
00211 
00212    static const TEveException eH("TEveProjected::UnRefProjectable ");
00213 
00214    assert(fProjectable == assumed_parent);
00215 
00216    if (notifyParent) fProjectable->RemoveProjected(this);
00217    fProjectable = 0;
00218 }
00219 
00220 //______________________________________________________________________________
00221 void TEveProjected::SetDepth(Float_t d)
00222 {
00223    // Set depth coordinate for the element.
00224    // Bounding-box should also be updated.
00225    // If projection type is 3D, this only sets fDepth member.
00226 
00227    if (fManager->GetProjection()->Is2D())
00228    {
00229       SetDepthLocal(d);
00230    }
00231    else
00232    {
00233       fDepth = d;
00234    }
00235 }
00236 
00237 //______________________________________________________________________________
00238 void TEveProjected::SetDepthCommon(Float_t d, TEveElement* el, Float_t* bbox)
00239 {
00240    // Utility function to update the z-values of the bounding-box.
00241    // As this is an abstract interface, the element and bbox pointers
00242    // must be passed from outside.
00243 
00244    Float_t delta = d - fDepth;
00245    fDepth = d;
00246    if (bbox) {
00247       bbox[4] += delta;
00248       bbox[5] += delta;
00249       el->StampTransBBox();
00250    }
00251 }
00252 
00253 //______________________________________________________________________________
00254 void TEveProjected::SetDepthLocal(Float_t d)
00255 {
00256    // Base-class implementation -- just sets fDepth.
00257 
00258    fDepth = d;
00259 }

Generated on Tue Jul 5 14:16:13 2011 for ROOT_528-00b_version by  doxygen 1.5.1