TEveDigitSet.cxx

Go to the documentation of this file.
00001 // @(#)root/eve:$Id: TEveDigitSet.cxx 37390 2010-12-08 11:10:41Z 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 "TEveDigitSet.h"
00013 #include "TEveManager.h"
00014 #include "TEveTrans.h"
00015 
00016 #include "TColor.h"
00017 #include "TRefArray.h"
00018 
00019 
00020 //______________________________________________________________________________
00021 //
00022 // Base-class for storage of digit collections; provides
00023 // transformation matrix (TEveTrans), signal to color mapping
00024 // (TEveRGBAPalette) and visual grouping (TEveFrameBox).
00025 //
00026 // Base-class for displaying a digit collection.
00027 // Provdies common services for:
00028 // - specifying signal / color per digit;
00029 // - specifying object reference per digit;
00030 // - controlling palette and thresholds (external object TEveRGBAPalette);
00031 // - showing a frame around the digits (external object TEveFrameBox);
00032 // - specifying transformation matrix for the whole collection;
00033 //   by data-member of class TEveTrans.
00034 //
00035 // Use method DigitId(TObject* id) to assign additional identification
00036 // to the last created digit. By calling SetOwnIds(kTRUE) tje
00037 // digit-set becomes the owner of the assigned objects and deletes
00038 // them on destruction.
00039 // Note that TRef is used for referencing the objects and if you
00040 // instantiate the objects just to pass them to digit-set you should
00041 // also call  TProcessID::Get/SetObjectCount() at the beginning / end
00042 // of processing of an event. See documentation for class TRef, in
00043 // particular section 'ObjectNumber'.
00044 //
00045 // If you use value-is-color mode and want to use transparency, set
00046 // the transparency to non-zero value so that GL-renderer will be
00047 // properly informed.
00048 //
00049 // If you want to use single color for all elements call:
00050 //   UseSingleColor()
00051 // Palette controls will not work in this case.
00052 //
00053 // See also:
00054 //   TEveQuadSet: rectangle, hexagon or line per digit
00055 //   TEveBoxSet   a 3D box per digit
00056 
00057 ClassImp(TEveDigitSet);
00058 
00059 //______________________________________________________________________________
00060 TEveDigitSet::TEveDigitSet(const char* n, const char* t) :
00061    TEveElement     (fColor),
00062    TNamed          (n, t),
00063 
00064    fDigitIds       (0),
00065    fDefaultValue   (kMinInt),
00066    fValueIsColor   (kFALSE),
00067    fSingleColor    (kFALSE),
00068    fAntiFlick      (kTRUE),
00069    fOwnIds         (kFALSE),
00070    fPlex           (),
00071    fLastDigit      (0),
00072    fLastIdx        (-1),
00073 
00074    fColor          (kWhite),
00075    fFrame          (0),
00076    fPalette        (0),
00077    fRenderMode     (kRM_AsIs),
00078    fDisableLighting(kTRUE),
00079    fHistoButtons   (kTRUE),
00080    fEmitSignals    (kFALSE),
00081    fCallbackFoo    (0),
00082    fTooltipCBFoo   (0)
00083 {
00084    // Constructor.
00085 
00086    fCanEditMainColor        = kTRUE;
00087    fCanEditMainTransparency = kTRUE;
00088    InitMainTrans();
00089 }
00090 
00091 //______________________________________________________________________________
00092 TEveDigitSet::~TEveDigitSet()
00093 {
00094    // Destructor.
00095    // Unreference frame and palette. Destroy referenced objects if they
00096    // are owned by the TEveDigitSet.
00097 
00098    SetFrame(0);
00099    SetPalette(0);
00100    if (fOwnIds)
00101       ReleaseIds();
00102    delete fDigitIds;
00103 }
00104 
00105 /******************************************************************************/
00106 
00107 //______________________________________________________________________________
00108 TEveDigitSet::DigitBase_t* TEveDigitSet::NewDigit()
00109 {
00110    // Protected method called whenever a new digit is added.
00111 
00112    fLastIdx   = fPlex.Size();
00113    fLastDigit = new (fPlex.NewAtom()) DigitBase_t(fDefaultValue);
00114    return fLastDigit;
00115 }
00116 
00117 //______________________________________________________________________________
00118 void TEveDigitSet::ReleaseIds()
00119 {
00120    // Protected method. Release and delete the referenced objects, the
00121    // ownership is *NOT* checked.
00122 
00123    if (fDigitIds)
00124    {
00125       const Int_t N = fDigitIds->GetSize();
00126 
00127       for (Int_t i = 0; i < N; ++i)
00128          delete fDigitIds->At(i);
00129 
00130       fDigitIds->Expand(0);
00131    }
00132 }
00133 
00134 //------------------------------------------------------------------------------
00135 
00136 //______________________________________________________________________________
00137 void TEveDigitSet::UseSingleColor()
00138 {
00139    // Instruct digit-set to use single color for its digits.
00140    // Call SetMainColor/Transparency to initialize it.
00141 
00142    fSingleColor = kTRUE;
00143 }
00144 
00145 //______________________________________________________________________________
00146 void TEveDigitSet::SetMainColor(Color_t color)
00147 {
00148    // Override from TEveElement, forward to Frame.
00149 
00150    if (fSingleColor)
00151    {
00152       TEveElement::SetMainColor(color);
00153    }
00154    else if (fFrame)
00155    {
00156       fFrame->SetFrameColor(color);
00157       fFrame->StampBackPtrElements(kCBColorSelection);
00158    }
00159 }
00160 
00161 //______________________________________________________________________________
00162 void TEveDigitSet::UnSelected()
00163 {
00164    // Virtual function called when both fSelected is false and
00165    // fImpliedSelected is 0.
00166 
00167    fSelectedSet.clear();
00168    TEveElement::UnSelected();
00169 }
00170 
00171 //______________________________________________________________________________
00172 void TEveDigitSet::UnHighlighted()
00173 {
00174    // Virtual function called when both fHighlighted is false and
00175    // fImpliedHighlighted is 0.
00176 
00177    fHighlightedSet.clear();
00178    TEveElement::UnHighlighted();
00179 }
00180 
00181 //______________________________________________________________________________
00182 TString TEveDigitSet::GetHighlightTooltip()
00183 {
00184    // Return tooltip for highlighted element if always-sec-select is set.
00185    // Otherwise return the tooltip for this element.
00186 
00187    if (fHighlightedSet.empty()) return "";
00188 
00189    if (GetAlwaysSecSelect())
00190    {
00191       if (fTooltipCBFoo)
00192       {
00193          return (fTooltipCBFoo)(this, *fHighlightedSet.begin());
00194       }
00195       else if (fDigitIds)
00196       {
00197          TObject *o = GetId(*fHighlightedSet.begin());
00198          if (o)
00199             return TString(o->GetName());
00200       }
00201       return TString::Format("%s; idx=%d", GetElementName(), *fHighlightedSet.begin());
00202    }
00203    else
00204    {
00205       return TEveElement::GetHighlightTooltip();
00206    }
00207 }
00208 
00209 
00210 /******************************************************************************/
00211 /******************************************************************************/
00212 
00213 //______________________________________________________________________________
00214 void TEveDigitSet::RefitPlex()
00215 {
00216    // Instruct underlying memory allocator to regroup itself into a
00217    // contiguous memory chunk.
00218 
00219    fPlex.Refit();
00220 }
00221 
00222 /******************************************************************************/
00223 
00224 //______________________________________________________________________________
00225 void TEveDigitSet::ScanMinMaxValues(Int_t& min, Int_t& max)
00226 {
00227    // Iterate over the digits and detmine min and max signal values.
00228 
00229    if (fValueIsColor || fPlex.Size() == 0) return;
00230    min = kMaxInt;
00231    max = kMinInt;
00232    for (Int_t c=0; c<fPlex.VecSize(); ++c)
00233    {
00234       Char_t* a = fPlex.Chunk(c);
00235       Int_t   n = fPlex.NAtoms(c);
00236       while (n--)
00237       {
00238          Int_t v = ((DigitBase_t*)a)->fValue;
00239          if (v < min) min = v;
00240          if (v > max) max = v;
00241          a += fPlex.S();
00242       }
00243    }
00244    if (min == max)
00245       --min;
00246 }
00247 
00248 /******************************************************************************/
00249 
00250 //______________________________________________________________________________
00251 void TEveDigitSet::SetCurrentDigit(Int_t idx)
00252 {
00253    // Set current digit -- the one that will receive calls to
00254    // DigitValue/Color/Id/UserData() functions.
00255    // Note that various AddXyzz() functions set the current digit to the newly
00256    // added one.
00257 
00258    fLastIdx   = idx;
00259    fLastDigit = GetDigit(idx);
00260 }
00261 
00262 //______________________________________________________________________________
00263 void TEveDigitSet::DigitValue(Int_t value)
00264 {
00265    // Set signal value for the last digit added.
00266 
00267    fLastDigit->fValue = value;
00268 }
00269 
00270 //______________________________________________________________________________
00271 void TEveDigitSet::DigitColor(Color_t ci)
00272 {
00273    // Set color for the last digit added.
00274 
00275    TEveUtil::ColorFromIdx(ci, (UChar_t*) & fLastDigit->fValue, kTRUE);
00276 }
00277 
00278 //______________________________________________________________________________
00279 void TEveDigitSet::DigitColor(Color_t ci, Char_t transparency)
00280 {
00281    // Set color for the last digit added.
00282 
00283    TEveUtil::ColorFromIdx(ci, (UChar_t*) & fLastDigit->fValue, transparency);
00284 }
00285 
00286 //______________________________________________________________________________
00287 void TEveDigitSet::DigitColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
00288 {
00289    // Set color for the last digit added.
00290 
00291    UChar_t* x = (UChar_t*) & fLastDigit->fValue;
00292    x[0] = r; x[1] = g; x[2] = b; x[3] = a;
00293 }
00294 
00295 //______________________________________________________________________________
00296 void TEveDigitSet::DigitColor(UChar_t* rgba)
00297 {
00298    // Set color for the last digit added.
00299 
00300    UChar_t* x = (UChar_t*) & fLastDigit->fValue;
00301    x[0] = rgba[0]; x[1] = rgba[1]; x[2] = rgba[2]; x[3] = rgba[3];
00302 }
00303 
00304 //______________________________________________________________________________
00305 void TEveDigitSet::DigitId(TObject* id)
00306 {
00307    // Set external object reference for the last digit added.
00308 
00309    DigitId(fLastIdx, id);
00310 }
00311 
00312 //______________________________________________________________________________
00313 void TEveDigitSet::DigitUserData(void* ud)
00314 {
00315    // Set user-data for the last digit added.
00316 
00317    fLastDigit->fUserData = ud;
00318 }
00319 
00320 //______________________________________________________________________________
00321 void TEveDigitSet::DigitId(Int_t n, TObject* id)
00322 {
00323    // Set external object reference for digit n.
00324 
00325    if (!fDigitIds)
00326       fDigitIds = new TRefArray;
00327 
00328    if (fOwnIds && n < fDigitIds->GetSize() && fDigitIds->At(n))
00329       delete fDigitIds->At(n);
00330 
00331    fDigitIds->AddAtAndExpand(id, n);
00332 }
00333 
00334 //______________________________________________________________________________
00335 void TEveDigitSet::DigitUserData(Int_t n, void* ud)
00336 {
00337    // Set user-data for digit n.
00338 
00339    GetDigit(n)->fUserData = ud;
00340 }
00341 
00342 //______________________________________________________________________________
00343 TObject* TEveDigitSet::GetId(Int_t n) const
00344 {
00345    // Return external TObject associated with digit n.
00346 
00347    return fDigitIds ? fDigitIds->At(n) : 0;
00348 }
00349 
00350 //______________________________________________________________________________
00351 void* TEveDigitSet::GetUserData(Int_t n) const
00352 {
00353    // Get user-data associated with digit n.
00354 
00355    return GetDigit(n)->fUserData;
00356 }
00357 
00358 /******************************************************************************/
00359 /******************************************************************************/
00360 
00361 //______________________________________________________________________________
00362 void TEveDigitSet::Paint(Option_t*)
00363 {
00364    // Paint this object. Only direct rendering is supported.
00365 
00366    PaintStandard(this);
00367 }
00368 
00369 //______________________________________________________________________________
00370 void TEveDigitSet::DigitSelected(Int_t idx)
00371 {
00372    // Called from renderer when a digit with index idx is selected.
00373    // This is by-passed when always-secondary-select is active.
00374 
00375    DigitBase_t *qb  = GetDigit(idx);
00376    TObject     *obj = GetId(idx);
00377 
00378    if (fCallbackFoo) {
00379       (fCallbackFoo)(this, idx, obj);
00380    }
00381    if (fEmitSignals) {
00382       SecSelected(this, idx);
00383    } else {
00384       printf("TEveDigitSet::DigitSelected idx=%d, value=%d, obj=0x%lx\n",
00385              idx, qb->fValue, (ULong_t)obj);
00386       if (obj)
00387          obj->Print();
00388    }
00389 }
00390 
00391 //______________________________________________________________________________
00392 void TEveDigitSet::SecSelected(TEveDigitSet* qs, Int_t idx)
00393 {
00394    // Emit a SecSelected signal.
00395    // This is by-passed when always-secondary-select is active.
00396 
00397    Long_t args[2];
00398    args[0] = (Long_t) qs;
00399    args[1] = (Long_t) idx;
00400 
00401    Emit("SecSelected(TEveDigitSet*, Int_t)", args);
00402 }
00403 
00404 /******************************************************************************/
00405 // Getters / Setters for Frame, TEveRGBAPalette, TEveTrans
00406 /******************************************************************************/
00407 
00408 //______________________________________________________________________________
00409 void TEveDigitSet::SetFrame(TEveFrameBox* b)
00410 {
00411    // Set TEveFrameBox pointer.
00412 
00413    if (fFrame == b) return;
00414    if (fFrame) fFrame->DecRefCount(this);
00415    fFrame = b;
00416    if (fFrame) {
00417       fFrame->IncRefCount(this);
00418       if (!fSingleColor) {
00419          SetMainColorPtr(fFrame->PtrFrameColor());
00420       }
00421    } else {
00422       SetMainColorPtr(&fColor);
00423    }
00424 }
00425 
00426 //______________________________________________________________________________
00427 void TEveDigitSet::SetPalette(TEveRGBAPalette* p)
00428 {
00429    // Set TEveRGBAPalette pointer.
00430 
00431    if (fPalette == p) return;
00432    if (fPalette) fPalette->DecRefCount();
00433    fPalette = p;
00434    if (fPalette) fPalette->IncRefCount();
00435 }
00436 
00437 //______________________________________________________________________________
00438 TEveRGBAPalette* TEveDigitSet::AssertPalette()
00439 {
00440    // Make sure the TEveRGBAPalette pointer is not null.
00441    // If it is not set, a new one is instantiated and the range is set
00442    // to current min/max signal values.
00443 
00444    if (fPalette == 0) {
00445       fPalette = new TEveRGBAPalette;
00446       if (!fValueIsColor) {
00447          Int_t min, max;
00448          ScanMinMaxValues(min, max);
00449          fPalette->SetLimits(min, max);
00450          fPalette->SetMinMax(min, max);
00451       }
00452    }
00453    return fPalette;
00454 }

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