TEveBox.cxx

Go to the documentation of this file.
00001 // @(#)root/eve:$Id: TEveBox.cxx 37228 2010-12-03 16:55:15Z matevz $
00002 // Author: Matevz Tadel, 2010
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 "TEveBox.h"
00013 #include "TEveProjectionManager.h"
00014 
00015 //==============================================================================
00016 // TEveBox
00017 //==============================================================================
00018 
00019 //______________________________________________________________________________
00020 //
00021 // 3D box with arbitrary vertices (cuboid).
00022 // Vertices 0-3 specify the "bottom" rectangle in clockwise direction and
00023 // vertices 4-7 the "top" rectangle so that 4 is above 0, 5 above 1 and so on.
00024 //
00025 // If vertices are provided some local coordinates the transformation matrix
00026 // of the element should also be set (but then the memory usage is increased
00027 // by the size of the TEveTrans object).
00028 //
00029 // Currently only supports 3D -> 2D projections.
00030 
00031 ClassImp(TEveBox);
00032 
00033 //______________________________________________________________________________
00034 TEveBox::TEveBox(const char* n, const char* t) :
00035    TEveShape(n, t)
00036 {
00037    // Constructor.
00038 }
00039 
00040 //______________________________________________________________________________
00041 TEveBox::~TEveBox()
00042 {
00043    // Destructor.
00044 }
00045 
00046 //______________________________________________________________________________
00047 void TEveBox::SetVertex(Int_t i, Float_t x, Float_t y, Float_t z)
00048 {
00049    // Set vertex 'i'.
00050 
00051    fVertices[i][0] = x;
00052    fVertices[i][1] = y;
00053    fVertices[i][2] = z;
00054    ResetBBox();
00055 }
00056 
00057 //______________________________________________________________________________
00058 void TEveBox::SetVertex(Int_t i, const Float_t* v)
00059 {
00060    // Set vertex 'i'.
00061 
00062    fVertices[i][0] = v[0];
00063    fVertices[i][1] = v[1];
00064    fVertices[i][2] = v[2];
00065    ResetBBox();
00066 }
00067 
00068 //______________________________________________________________________________
00069 void TEveBox::SetVertices(const Float_t* vs)
00070 {
00071    // Set vertices.
00072 
00073    memcpy(fVertices, vs, sizeof(fVertices));
00074    ResetBBox();
00075 }
00076 
00077 //==============================================================================
00078 
00079 //______________________________________________________________________________
00080 void TEveBox::ComputeBBox()
00081 {
00082    // Compute bounding-box of the data.
00083 
00084    TEveShape::CheckAndFixBoxOrientationFv(fVertices);
00085 
00086    BBoxInit();
00087    for (Int_t i=0; i<8; ++i)
00088    {
00089       BBoxCheckPoint(fVertices[i]);
00090    }
00091 }
00092 
00093 //______________________________________________________________________________
00094 TClass* TEveBox::ProjectedClass(const TEveProjection*) const
00095 {
00096    // Virtual from TEveProjectable, return TEveBoxProjected class.
00097 
00098    return TEveBoxProjected::Class();
00099 }
00100 
00101 
00102 //==============================================================================
00103 // TEveBoxProjected
00104 //==============================================================================
00105 
00106 //______________________________________________________________________________
00107 //
00108 // Projection of TEveBox.
00109 
00110 ClassImp(TEveBoxProjected);
00111 
00112 Bool_t TEveBoxProjected::fgDebugCornerPoints = kFALSE;
00113 
00114 //______________________________________________________________________________
00115 TEveBoxProjected::TEveBoxProjected(const char* n, const char* t) :
00116    TEveShape(n, t),
00117    fBreakIdx(0)
00118 {
00119    // Constructor.
00120 }
00121 
00122 //______________________________________________________________________________
00123 TEveBoxProjected::~TEveBoxProjected()
00124 {
00125    // Destructor.
00126 }
00127 
00128 //______________________________________________________________________________
00129 void TEveBoxProjected::ComputeBBox()
00130 {
00131    // Compute bounding-box, virtual from TAttBBox.
00132 
00133    BBoxInit();
00134    for (vVector2_i i = fPoints.begin(); i != fPoints.end(); ++i)
00135    {
00136       BBoxCheckPoint(i->fX, i->fY, fDepth);
00137    }
00138 }
00139 
00140 //______________________________________________________________________________
00141 void TEveBoxProjected::SetDepthLocal(Float_t d)
00142 {
00143    // This is virtual method from base-class TEveProjected.
00144 
00145    SetDepthCommon(d, this, fBBox);
00146 }
00147 
00148 //______________________________________________________________________________
00149 void TEveBoxProjected::SetProjection(TEveProjectionManager* mng, TEveProjectable* model)
00150 {
00151    // This is virtual method from base-class TEveProjected.
00152 
00153    TEveProjected::SetProjection(mng, model);
00154    CopyVizParams(dynamic_cast<TEveElement*>(model));
00155 }
00156 
00157 //______________________________________________________________________________
00158 void TEveBoxProjected::UpdateProjection()
00159 {
00160    // Re-project the box. Projects all points and finds 2D convex-hull.
00161    //
00162    // The only issue is with making sure that initial conditions for
00163    // hull-search are reasonable -- that is, there are no overlaps with the
00164    // first point.
00165 
00166    TEveBox *box = dynamic_cast<TEveBox*>(fProjectable);
00167 
00168    fDebugPoints.clear();
00169 
00170    // Project points in global CS, remove overlaps.
00171    vVector2_t pp[2];
00172    {
00173       TEveProjection *projection = fManager->GetProjection();
00174       TEveTrans      *trans      = box->PtrMainTrans(kFALSE);
00175 
00176       TEveVector pbuf;
00177       for (Int_t i = 0; i < 8; ++i)
00178       {
00179          projection->ProjectPointfv(trans, box->GetVertex(i), pbuf, fDepth);
00180          vVector2_t& ppv = pp[projection->SubSpaceId(pbuf)];
00181 
00182          TEveVector2 p(pbuf);
00183          Bool_t      overlap = kFALSE;
00184          for (vVector2_i j = ppv.begin(); j != ppv.end(); ++j)
00185          {
00186             if (p.SquareDistance(*j) < TEveProjection::fgEpsSqr)
00187             {
00188                overlap = kTRUE;
00189                break;
00190             }
00191          }
00192          if (! overlap)
00193          {
00194             ppv.push_back(p);
00195             if (fgDebugCornerPoints)
00196                fDebugPoints.push_back(p);
00197          }
00198       }
00199    }
00200 
00201    fPoints.clear();
00202    fBreakIdx = 0;
00203 
00204    if ( ! pp[0].empty())
00205    {
00206       FindConvexHull(pp[0], fPoints, this);
00207    }
00208    if ( ! pp[1].empty())
00209    {
00210       fBreakIdx = fPoints.size();
00211       FindConvexHull(pp[1], fPoints, this);
00212    }
00213 }
00214 
00215 //______________________________________________________________________________
00216 Bool_t TEveBoxProjected::GetDebugCornerPoints()
00217 {
00218    // Get state of fgDebugCornerPoints static.
00219 
00220    return fgDebugCornerPoints;
00221 }
00222 
00223 //______________________________________________________________________________
00224 void TEveBoxProjected::SetDebugCornerPoints(Bool_t d)
00225 {
00226    // Set state of fgDebugCornerPoints static.
00227    // When this is true, points will be drawn at the corners of
00228    // computed convex hull.
00229 
00230    fgDebugCornerPoints = d;
00231 }

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