TEveBoxSet.cxx

Go to the documentation of this file.
00001 // @(#)root/eve:$Id: TEveBoxSet.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 "TEveBoxSet.h"
00013 #include "TEveShape.h"
00014 
00015 #include "TRandom.h"
00016 
00017 //==============================================================================
00018 // TEveBoxSet
00019 //==============================================================================
00020 
00021 //______________________________________________________________________________
00022 //
00023 // Collection of 3D primitives (fixed-size boxes, boxes of different
00024 // sizes, or arbitrary sexto-epipeds, cones); each primitive can be assigned
00025 // a signal value and a TRef.
00026 //
00027 // A collection of 3D-markers. The way how they are defined depends
00028 // on the fBoxType data-member.
00029 //   kBT_FreeBox         arbitrary box: specify 8*(x,y,z) box corners
00030 //   kBT_AABox           axis-aligned box: specify (x,y,z) and (w, h, d)
00031 //   kBT_AABoxFixedDim   axis-aligned box w/ fixed dimensions: specify (x,y,z)
00032 //                       also set fDefWidth, fDefHeight and fDefDepth
00033 //   kBT_Cone            cone defined with position, axis-vector and radius
00034 //   EllipticCone        conew with elliptic base (specify another radius and angle in deg)
00035 //
00036 // Each primitive can be assigned:
00037 // a) Color or signal value. Thresholds and signal-to-color mapping
00038 //    can then be set dynamically via the TEveRGBAPalette class.
00039 // b) External TObject* (stored as TRef).
00040 //
00041 // See also base-class TEveDigitSet for more information.
00042 // Tutorial: tutorials/eve/boxset_test.C
00043 
00044 
00045 ClassImp(TEveBoxSet);
00046 
00047 //______________________________________________________________________________
00048 TEveBoxSet::TEveBoxSet(const char* n, const char* t) :
00049    TEveDigitSet  (n, t),
00050 
00051    fBoxType      (kBT_Undef),
00052    fDefWidth     (1),
00053    fDefHeight    (1),
00054    fDefDepth     (1),
00055 
00056    fDrawConeCap  (kFALSE)
00057 {
00058    // Constructor.
00059 
00060    // Override from TEveDigitSet.
00061    fDisableLighting = kFALSE;
00062 }
00063 
00064 /******************************************************************************/
00065 
00066 //______________________________________________________________________________
00067 Int_t TEveBoxSet::SizeofAtom(TEveBoxSet::EBoxType_e bt)
00068 {
00069    // Return size of data-structure describing a box of type bt.
00070 
00071    static const TEveException eH("TEveBoxSet::SizeofAtom ");
00072 
00073    switch (bt) {
00074       case kBT_Undef:                return 0;
00075       case kBT_FreeBox:              return sizeof(BFreeBox_t);
00076       case kBT_AABox:                return sizeof(BAABox_t);
00077       case kBT_AABoxFixedDim:        return sizeof(BAABoxFixedDim_t);
00078       case kBT_Cone:                 return sizeof(BCone_t);
00079       case kBT_EllipticCone:         return sizeof(BEllipticCone_t);
00080       default:                       throw(eH + "unexpected atom type.");
00081    }
00082    return 0;
00083 }
00084 
00085 /******************************************************************************/
00086 
00087 //______________________________________________________________________________
00088 void TEveBoxSet::Reset(TEveBoxSet::EBoxType_e boxType, Bool_t valIsCol, Int_t chunkSize)
00089 {
00090    // Reset the data containers to zero size.
00091    // The arguments describe the basic parameters of data storage.
00092 
00093    fBoxType      = boxType;
00094    fValueIsColor = valIsCol;
00095    fDefaultValue = valIsCol ? 0 : kMinInt;
00096    if (fOwnIds)
00097       ReleaseIds();
00098    fPlex.Reset(SizeofAtom(fBoxType), chunkSize);
00099 }
00100 
00101 //______________________________________________________________________________
00102 void TEveBoxSet::Reset()
00103 {
00104    // Reset the data containers to zero size.
00105    // Keep the old data-storage parameters.
00106 
00107    if (fOwnIds)
00108       ReleaseIds();
00109    fPlex.Reset(SizeofAtom(fBoxType), TMath::Max(fPlex.N(), 64));
00110 }
00111 
00112 /******************************************************************************/
00113 
00114 //______________________________________________________________________________
00115 void TEveBoxSet::AddBox(const Float_t* verts)
00116 {
00117    // Create a new box from a set of 8 vertices.
00118    // To be used for box-type kBT_FreeBox.
00119 
00120    static const TEveException eH("TEveBoxSet::AddBox ");
00121 
00122    if (fBoxType != kBT_FreeBox)
00123       throw(eH + "expect free box-type.");
00124 
00125    BFreeBox_t* b = (BFreeBox_t*) NewDigit();
00126    memcpy(b->fVertices, verts, sizeof(b->fVertices));
00127    TEveShape::CheckAndFixBoxOrientationFv(b->fVertices);
00128 }
00129 
00130 //______________________________________________________________________________
00131 void TEveBoxSet::AddBox(Float_t a, Float_t b, Float_t c, Float_t w, Float_t h, Float_t d)
00132 {
00133    // Create a new axis-aligned box from at a given position and with
00134    // specified dimensions.
00135    // To be used for box-type kBT_AABox.
00136 
00137    static const TEveException eH("TEveBoxSet::AddBox ");
00138 
00139    if (fBoxType != kBT_AABox)
00140       throw(eH + "expect axis-aligned box-type.");
00141 
00142    BAABox_t* box = (BAABox_t*) NewDigit();
00143    box->fA = a; box->fB = b; box->fC = c;
00144    box->fW = w; box->fH = h; box->fD = d;
00145 }
00146 
00147 //______________________________________________________________________________
00148 void TEveBoxSet::AddBox(Float_t a, Float_t b, Float_t c)
00149 {
00150    // Create a new axis-aligned box from at a given position.
00151    // To be used for box-type kBT_AABoxFixedDim.
00152 
00153    static const TEveException eH("TEveBoxSet::AddBox ");
00154 
00155    if (fBoxType != kBT_AABoxFixedDim)
00156       throw(eH + "expect axis-aligned fixed-dimension box-type.");
00157 
00158    BAABoxFixedDim_t* box = (BAABoxFixedDim_t*) NewDigit();
00159    box->fA = a; box->fB = b; box->fC = c;
00160 }
00161 
00162 //______________________________________________________________________________
00163 void TEveBoxSet::AddCone(const TEveVector& pos, const TEveVector& dir, Float_t r)
00164 {
00165    // Create a cone with apex at pos, axis dir and radius r.
00166    // To be used for box-type kBT_Cone.
00167 
00168    static const TEveException eH("TEveBoxSet::AddCone ");
00169 
00170    if (fBoxType != kBT_Cone)
00171       throw(eH + "expect cone box-type.");
00172 
00173    BCone_t* cone = (BCone_t*) NewDigit();
00174    cone->fPos = pos;
00175    cone->fDir = dir;
00176    cone->fR   = r;
00177 }
00178 
00179 //______________________________________________________________________________
00180 void TEveBoxSet::AddEllipticCone(const TEveVector& pos, const TEveVector& dir,
00181                                  Float_t r, Float_t r2, Float_t angle)
00182 {
00183    // Create a cone with apex at pos, axis dir and radius r.
00184    // To be used for box-type kBT_Cone.
00185 
00186    static const TEveException eH("TEveBoxSet::AddEllipticCone ");
00187 
00188    if (fBoxType != kBT_EllipticCone)
00189       throw(eH + "expect ellicptic-cone box-type.");
00190 
00191    BEllipticCone_t* cone = (BEllipticCone_t*) NewDigit();
00192    cone->fPos = pos;
00193    cone->fDir = dir;
00194    cone->fR   = r;
00195    cone->fR2  = r2;
00196    cone->fAngle = angle;
00197 }
00198 
00199 /******************************************************************************/
00200 
00201 //______________________________________________________________________________
00202 void TEveBoxSet::ComputeBBox()
00203 {
00204    // Fill bounding-box information of the base-class TAttBBox (virtual method).
00205    // If member 'TEveFrameBox* fFrame' is set, frame's corners are used as bbox.
00206 
00207    static const TEveException eH("TEveBoxSet::ComputeBBox ");
00208 
00209    if (fFrame != 0)
00210    {
00211       BBoxInit();
00212       Int_t    n    = fFrame->GetFrameSize() / 3;
00213       Float_t *bbps = fFrame->GetFramePoints();
00214       for (int i=0; i<n; ++i, bbps+=3)
00215          BBoxCheckPoint(bbps);
00216       return;
00217    }
00218 
00219    if(fPlex.Size() == 0)
00220    {
00221       BBoxZero();
00222       return;
00223    }
00224 
00225    BBoxInit();
00226 
00227    TEveChunkManager::iterator bi(fPlex);
00228    switch (fBoxType)
00229    {
00230 
00231       case kBT_FreeBox:
00232       {
00233          while (bi.next()) {
00234             BFreeBox_t& b = * (BFreeBox_t*) bi();
00235             for (Int_t i = 0; i < 8; ++i)
00236                BBoxCheckPoint(b.fVertices[i]);
00237          }
00238          break;
00239       }
00240 
00241       case kBT_AABox:
00242       {
00243          while (bi.next()) {
00244             BAABox_t& b = * (BAABox_t*) bi();
00245             BBoxCheckPoint(b.fA, b.fB, b.fC);
00246             BBoxCheckPoint(b.fA + b.fW, b.fB + b.fH , b.fC + b.fD);
00247          }
00248          break;
00249       }
00250 
00251       case kBT_AABoxFixedDim:
00252       {
00253          while (bi.next()) {
00254             BAABoxFixedDim_t& b = * (BAABoxFixedDim_t*) bi();
00255             BBoxCheckPoint(b.fA, b.fB, b.fC);
00256             BBoxCheckPoint(b.fA + fDefWidth, b.fB + fDefHeight , b.fC + fDefDepth);
00257          }
00258          break;
00259       }
00260       case kBT_Cone:
00261       {
00262          Float_t mag2=0, mag2Max=0, rMax=0;
00263          while (bi.next()) {
00264             BCone_t& b = * (BCone_t*) bi();
00265             BBoxCheckPoint(b.fPos.fX, b.fPos.fY, b.fPos.fZ);
00266             mag2 = b.fDir.Mag2();
00267             if (mag2>mag2Max) mag2Max=mag2;
00268             if (b.fR>rMax)    rMax=b.fR;
00269          }
00270          Float_t off = TMath::Sqrt(mag2Max + rMax*rMax);
00271          fBBox[0] -= off;fBBox[2] -= off;fBBox[4] -= off;
00272          fBBox[1] += off;fBBox[3] += off;fBBox[5] += off;
00273          break;
00274       }
00275       case kBT_EllipticCone:
00276       {
00277          Float_t mag2=0, mag2Max=0, rMax=0;
00278          while (bi.next()) {
00279             BEllipticCone_t& b = * (BEllipticCone_t*) bi();
00280             BBoxCheckPoint(b.fPos.fX, b.fPos.fY, b.fPos.fZ);
00281             mag2 = b.fDir.Mag2();
00282             if (mag2>mag2Max) mag2Max=mag2;
00283             if (b.fR  > rMax) rMax = b.fR;
00284             if (b.fR2 > rMax) rMax = b.fR2;
00285          }
00286          Float_t off = TMath::Sqrt(mag2Max + rMax*rMax);
00287          fBBox[0] -= off;fBBox[2] -= off;fBBox[4] -= off;
00288          fBBox[1] += off;fBBox[3] += off;fBBox[5] += off;
00289          break;
00290       }
00291       default:
00292       {
00293          throw(eH + "unsupported box-type.");
00294       }
00295 
00296    } // end switch box-type
00297 }
00298 
00299 /******************************************************************************/
00300 
00301 //______________________________________________________________________________
00302 void TEveBoxSet::Test(Int_t nboxes)
00303 {
00304    // Fill the structure with a random set of boxes.
00305 
00306    Reset(kBT_AABox, kTRUE, nboxes);
00307    TRandom rnd(0);
00308    const Float_t origin = 10, size = 2;
00309    Int_t color;
00310    for(Int_t i=0; i<nboxes; ++i)
00311    {
00312       AddBox(origin * rnd.Uniform(-1, 1),
00313              origin * rnd.Uniform(-1, 1),
00314              origin * rnd.Uniform(-1, 1),
00315              size   * rnd.Uniform(0.1, 1),
00316              size   * rnd.Uniform(0.1, 1),
00317              size   * rnd.Uniform(0.1, 1));
00318 
00319       TEveUtil::ColorFromIdx(rnd.Integer(256), (UChar_t*)&color);
00320       DigitValue(color);
00321    }
00322 }

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