TGLObject.cxx

Go to the documentation of this file.
00001 // @(#)root/gl:$Id: TGLObject.cxx 36884 2010-11-23 17:52:08Z matevz $
00002 // Author: Matevz Tadel  7/4/2006
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2006, 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 
00013 #include "TGLObject.h"
00014 #include "TGLRnrCtx.h"
00015 #include "TObject.h"
00016 #include "TClass.h"
00017 #include "TBaseClass.h"
00018 #include "TList.h"
00019 #include "TString.h"
00020 
00021 //==============================================================================
00022 // TGLObject
00023 //==============================================================================
00024 
00025 //______________________________________________________________________
00026 //
00027 // Base-class for direct OpenGL renderers.
00028 // This allows classes to circumvent passing of TBuffer3D and
00029 // use user-provided OpenGL code.
00030 // By convention, if you want class TFoo : public TObject to have direct rendering
00031 // you should also provide TFooGL : public TGLObject and implement
00032 // abstract functions SetModel() and SetBBox().
00033 // TAttBBox can be used to facilitate calculation of bounding-boxes.
00034 // See TPointSet3D and TPointSet3DGL.
00035 
00036 ClassImp(TGLObject);
00037 
00038 TMap TGLObject::fgGLClassMap;
00039 
00040 //______________________________________________________________________________
00041 Bool_t TGLObject::ShouldDLCache(const TGLRnrCtx& rnrCtx) const
00042 {
00043    // Decide if display-list should be used for this pass rendering,
00044    // as determined by rnrCtx.
00045 
00046    if (!fDLCache ||
00047        !fScene   ||
00048        (rnrCtx.SecSelection() && SupportsSecondarySelect()) ||
00049        (fMultiColor && (rnrCtx.HighlightOutline() || rnrCtx.IsDrawPassOutlineLine())) ||
00050        (AlwaysSecondarySelect() && rnrCtx.Highlight()))
00051    {
00052       return kFALSE;
00053    }
00054 
00055    return kTRUE;
00056 }
00057 
00058 //______________________________________________________________________________
00059 void TGLObject::UpdateBoundingBox()
00060 {
00061    // Update bounding box from external source.
00062    // We call abstract SetBBox() and propagate the change to all
00063    // attached physicals.
00064 
00065    SetBBox();
00066    UpdateBoundingBoxesOfPhysicals();
00067 }
00068 
00069 //______________________________________________________________________________
00070 Bool_t TGLObject::SetModelCheckClass(TObject* obj, TClass* cls)
00071 {
00072    // Checks if obj is of proper class and sets the model.
00073    // Protected helper for subclasses.
00074    // Most sub-classes use exception-throwing SetModelDynCast() instead.
00075 
00076    if(obj->InheritsFrom(cls) == kFALSE) {
00077       Warning("TGLObject::SetModelCheckClass", "object of wrong class passed.");
00078       return kFALSE;
00079    }
00080    fExternalObj = obj;
00081 
00082    return kTRUE;
00083 }
00084 
00085 //______________________________________________________________________________
00086 void TGLObject::SetAxisAlignedBBox(Float_t xmin, Float_t xmax,
00087                                    Float_t ymin, Float_t ymax,
00088                                    Float_t zmin, Float_t zmax)
00089 {
00090    // Set axis-aligned bounding-box.
00091    // Protected helper for subclasses.
00092 
00093    fBoundingBox.SetAligned(TGLVertex3(xmin, ymin, zmin),
00094                            TGLVertex3(xmax, ymax, zmax));
00095 }
00096 
00097 //______________________________________________________________________________
00098 void TGLObject::SetAxisAlignedBBox(const Float_t* p)
00099 {
00100    // Set axis-aligned bounding-box.
00101    // Protected helper for subclasses.
00102 
00103    SetAxisAlignedBBox(p[0], p[1], p[2], p[3], p[4], p[5]);
00104 }
00105 
00106 
00107 //______________________________________________________________________________
00108 TClass* TGLObject::SearchGLRenderer(TClass* cls)
00109 {
00110    // Recursively search cls and its base classes for a GL-renderer
00111    // class.
00112 
00113    TString rnr( cls->GetName() );
00114    rnr += "GL";
00115    TClass* c = TClass::GetClass(rnr);
00116    if (c != 0)
00117       return c;
00118 
00119    TList* bases = cls->GetListOfBases();
00120    if (bases == 0 || bases->IsEmpty())
00121       return 0;
00122 
00123    TIter  next_base(bases);
00124    TBaseClass* bc;
00125    while ((bc = (TBaseClass*) next_base()) != 0) {
00126       cls = bc->GetClassPointer();
00127       if ((c = SearchGLRenderer(cls)) != 0) {
00128          return c;
00129       }
00130    }
00131    return 0;
00132 }
00133 
00134 //______________________________________________________________________________
00135 TClass* TGLObject::GetGLRenderer(TClass* isa)
00136 {
00137    // Return direct-rendering GL class for class isa.
00138    // Zero is a valid response.
00139 
00140    TPair* p = (TPair*) fgGLClassMap.FindObject(isa);
00141    TClass* cls;
00142    if (p != 0) {
00143       cls = (TClass*) p->Value();
00144    } else {
00145       cls = SearchGLRenderer(isa);
00146       fgGLClassMap.Add(isa, cls);
00147    }
00148    return cls;
00149 }

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