TEveJetConeGL.cxx

Go to the documentation of this file.
00001 // @(#)root/eve:$Id: TEveJetConeGL.cxx 36417 2010-10-25 10:13:29Z matevz $
00002 // Author: Matevz Tadel, Jochen Thaeder 2009
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 "TEveJetConeGL.h"
00013 #include "TEveJetCone.h"
00014 #include "TEveProjectionManager.h"
00015 
00016 #include "TMath.h"
00017 
00018 #include "TGLRnrCtx.h"
00019 #include "TGLIncludes.h"
00020 
00021 //==============================================================================
00022 // TEveJetConeGL
00023 //==============================================================================
00024 
00025 //______________________________________________________________________________
00026 // OpenGL renderer class for TEveJetCone.
00027 //
00028 
00029 ClassImp(TEveJetConeGL);
00030 
00031 //______________________________________________________________________________
00032 TEveJetConeGL::TEveJetConeGL() :
00033    TGLObject(), fC(0)
00034 {
00035    // Constructor.
00036 
00037    // fDLCache = kFALSE; // Disable display list.
00038 }
00039 
00040 //______________________________________________________________________________
00041 Bool_t TEveJetConeGL::SetModel(TObject* obj, const Option_t* /*opt*/)
00042 {
00043    // Set model object.
00044 
00045    fC = SetModelDynCast<TEveJetCone>(obj);
00046    return kTRUE;
00047 }
00048 
00049 //______________________________________________________________________________
00050 void TEveJetConeGL::SetBBox()
00051 {
00052    // Set bounding box.
00053 
00054    SetAxisAlignedBBox(((TEveJetCone*)fExternalObj)->AssertBBox());
00055 }
00056 
00057 //______________________________________________________________________________
00058 void TEveJetConeGL::DLCacheClear()
00059 {
00060    // Clear DL cache and reset internal point array.
00061 
00062    fP.clear();
00063    TGLObject::DLCacheClear();
00064 }
00065 
00066 //______________________________________________________________________________
00067 void TEveJetConeGL::CalculatePoints() const
00068 {
00069    // Calculate points for drawing.
00070 
00071    assert(fC->fNDiv > 2);
00072 
00073    const Int_t  NP = fC->fNDiv;
00074    fP.resize(NP);
00075    {
00076       Float_t angle_step = TMath::TwoPi() / NP;
00077       Float_t angle      = 0;
00078       for (Int_t i = 0; i < NP; ++i, angle += angle_step)
00079       {
00080          fP[i] = fC->CalcBaseVec(angle);
00081       }
00082    }
00083 }
00084 
00085 //______________________________________________________________________________
00086 void TEveJetConeGL::Draw(TGLRnrCtx& rnrCtx) const
00087 {
00088    // Draw the cone.
00089 
00090    if (fP.empty()) CalculatePoints();
00091 
00092    if (fC->fHighlightFrame && rnrCtx.Highlight())
00093    {
00094       glPushAttrib(GL_ENABLE_BIT);
00095       glDisable(GL_LIGHTING);
00096 
00097       if (fC->fDrawFrame)
00098       {
00099          TGLUtil::LineWidth(fC->fLineWidth);
00100          TGLUtil::Color(fC->fLineColor);
00101       }
00102 
00103       const Int_t NP = fP.size();
00104       glBegin(GL_LINE_LOOP);
00105       for (Int_t i = 0; i < NP; ++i)
00106          glVertex3fv(fP[i]);
00107       glEnd();
00108       glBegin(GL_LINES);
00109       Double_t angle = 0;
00110       for (Int_t i = 0; i < 4; ++i, angle += TMath::PiOver2())
00111       {
00112          glVertex3fv(fC->fApex);
00113          glVertex3fv(fC->CalcBaseVec(angle));
00114       }
00115       glEnd();
00116 
00117       glPopAttrib();
00118    }
00119    else
00120    {
00121       TGLObject::Draw(rnrCtx);
00122    }
00123 }
00124 
00125 //______________________________________________________________________________
00126 void TEveJetConeGL::DirectDraw(TGLRnrCtx& /*rnrCtx*/) const
00127 {
00128    // Render with OpenGL.
00129 
00130    // printf("TEveJetConeGL::DirectDraw LOD %d\n", rnrCtx.CombiLOD());
00131 
00132    glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT | GL_LIGHTING_BIT);
00133 
00134    glDisable(GL_CULL_FACE);
00135    glEnable(GL_NORMALIZE);
00136    Int_t lmts = 1;
00137    glLightModeliv(GL_LIGHT_MODEL_TWO_SIDE, &lmts);
00138 
00139    const Int_t  NP = fC->fNDiv;
00140    Int_t prev = NP - 1;
00141    Int_t i    = 0;
00142    Int_t next = 1;
00143 
00144    TEveVector curr_normal;
00145    TEveVector prev_normal;
00146    TMath::Cross((fP[next] - fP[prev]).Arr(), (fP[i] - fC->fApex).Arr(), prev_normal.Arr());
00147 
00148    prev = i; i = next; ++next;
00149 
00150    glBegin(GL_TRIANGLES);
00151    do
00152    {
00153       TMath::Cross((fP[next] - fP[prev]).Arr(), (fP[i] - fC->fApex).Arr(), curr_normal.Arr());
00154 
00155       glNormal3fv(prev_normal);
00156       glVertex3fv(fP[prev]);
00157 
00158       glNormal3fv(prev_normal + curr_normal);
00159       glVertex3fv(fC->fApex);
00160 
00161       glNormal3fv(curr_normal);
00162       glVertex3fv(fP[i]);
00163          
00164       prev_normal = curr_normal;
00165 
00166       prev = i;
00167       i    = next;
00168       ++next; if (next >= NP) next = 0;
00169    } while (prev != 0);
00170    glEnd();
00171 
00172    glPopAttrib();
00173 }
00174 
00175 
00176 //==============================================================================
00177 // TEveJetConeProjectedGL
00178 //==============================================================================
00179 
00180 //______________________________________________________________________________
00181 // OpenGL renderer class for TEveJetConeProjected.
00182 //
00183 
00184 ClassImp(TEveJetConeProjectedGL);
00185 
00186 //______________________________________________________________________________
00187 TEveJetConeProjectedGL::TEveJetConeProjectedGL() :
00188    TEveJetConeGL(), fM(0)
00189 {
00190    // Constructor.
00191 
00192    // fDLCache = kFALSE; // Disable display list.
00193 }
00194 
00195 //______________________________________________________________________________
00196 Bool_t TEveJetConeProjectedGL::SetModel(TObject* obj, const Option_t* /*opt*/)
00197 {
00198    // Set model object.
00199 
00200    fM = SetModelDynCast<TEveJetConeProjected>(obj);
00201    fC = dynamic_cast<TEveJetCone*>(fM->GetProjectable());
00202    return fC != 0;
00203 }
00204 
00205 //______________________________________________________________________________
00206 void TEveJetConeProjectedGL::SetBBox()
00207 {
00208    // Set bounding box.
00209 
00210    SetAxisAlignedBBox(((TEveJetConeProjected*)fExternalObj)->AssertBBox());
00211 }
00212 
00213 namespace
00214 {
00215    struct less_eve_vec_phi_t
00216    {
00217       bool operator()(const TEveVector& a, const TEveVector& b)
00218       { return a.Phi() < b.Phi(); }
00219    };
00220 }
00221 
00222 //______________________________________________________________________________
00223 void TEveJetConeProjectedGL::CalculatePoints() const
00224 {
00225    // Calculate points for drawing.
00226 
00227    static const TEveException kEH("TEveJetConeProjectedGL::CalculatePoints ");
00228 
00229    fP.resize(3);
00230 
00231    TEveProjection *proj = fM->GetManager()->GetProjection();
00232 
00233    switch (proj->GetType())
00234    {
00235       case TEveProjection::kPT_RPhi:
00236       {
00237          fP[0] = fC->fApex;
00238          fP[1] = fC->CalcBaseVec(TMath::Pi() + TMath::PiOver2());
00239          fP[2] = fC->CalcBaseVec(TMath::PiOver2());
00240 
00241          for (Int_t i = 0; i < 3; ++i)
00242             proj->ProjectVector(fP[i], fM->fDepth);
00243 
00244          break;
00245       }
00246 
00247       case TEveProjection::kPT_RhoZ:
00248       {
00249          fP[0] = fC->fApex;
00250          fP[1] = fC->CalcBaseVec(0);
00251          fP[2] = fC->CalcBaseVec(TMath::Pi());
00252 
00253          Float_t tm = fP[1].Theta();
00254          Float_t tM = fP[2].Theta();
00255 
00256          if (tM > fC->fThetaC && tm < fC->fThetaC)
00257          {
00258             fP.reserve(fP.size() + 1);
00259             TEveVector v(0, fC->fLimits.fY, fC->fLimits.fZ);
00260             fP.push_back(fC->CalcBaseVec(v.Eta(), fC->fPhi));
00261          }
00262 
00263          if (tM > TMath::Pi() - fC->fThetaC && tm < TMath::Pi() - fC->fThetaC)
00264          {
00265             fP.reserve(fP.size() + 1);
00266             TEveVector v(0, fC->fLimits.fY, -fC->fLimits.fZ);
00267             fP.push_back(fC->CalcBaseVec(v.Eta(), fC->fPhi));
00268          }
00269 
00270          const Int_t NP = fP.size();
00271          for (Int_t i = 0; i < NP; ++i)
00272             proj->ProjectVector(fP[i], fM->fDepth);
00273 
00274          std::sort(fP.begin() + 1, fP.end(), less_eve_vec_phi_t());
00275 
00276          break;
00277       }
00278 
00279       default:
00280          throw kEH + "Unsupported projection type.";
00281    }
00282 
00283 }
00284 
00285 //______________________________________________________________________________
00286 void TEveJetConeProjectedGL::RenderOutline() const
00287 {
00288    // Draw jet outline.
00289 
00290    const Int_t NP = fP.size();
00291    glBegin(GL_LINE_LOOP);
00292    for (Int_t i = 0; i < NP; ++i)
00293    {
00294       glVertex3fv(fP[i].Arr());
00295    }
00296    glEnd();
00297 }
00298 
00299 //______________________________________________________________________________
00300 void TEveJetConeProjectedGL::RenderPolygon() const
00301 {
00302    // Draw jet surface.
00303 
00304    const Int_t NP = fP.size();
00305    glBegin(GL_POLYGON);
00306    for (Int_t i = 0; i < NP; ++i)
00307    {
00308       glVertex3fv(fP[i].Arr());
00309    }
00310    glEnd();
00311 }
00312 
00313 //______________________________________________________________________________
00314 void TEveJetConeProjectedGL::Draw(TGLRnrCtx& rnrCtx) const
00315 {
00316    // Draw the cone.
00317 
00318    if (fP.empty()) CalculatePoints();
00319 
00320    if (rnrCtx.IsDrawPassOutlineLine())
00321    {
00322       RenderOutline();
00323    }
00324    else if (fM->fHighlightFrame && rnrCtx.Highlight())
00325    {
00326       if (fM->fDrawFrame)
00327       {
00328          TGLUtil::LineWidth(fM->fLineWidth);
00329          TGLUtil::Color(fM->fLineColor);
00330       }
00331       RenderOutline();
00332    }
00333    else
00334    {
00335       TGLObject::Draw(rnrCtx);
00336    }
00337 }
00338 
00339 
00340 //______________________________________________________________________________
00341 void TEveJetConeProjectedGL::DirectDraw(TGLRnrCtx& /*rnrCtx*/) const
00342 {
00343    // Render with OpenGL.
00344 
00345    // printf("TEveJetConeProjectedGL::DirectDraw LOD %d\n", rnrCtx.CombiLOD());
00346 
00347    fMultiColor = (fM->fDrawFrame && fM->fFillColor != fM->fLineColor);
00348 
00349    glPushAttrib(GL_ENABLE_BIT);
00350    glDisable(GL_LIGHTING);
00351 
00352    if (fM->fDrawFrame)
00353    {
00354       glEnable(GL_POLYGON_OFFSET_FILL);
00355       glPolygonOffset(1.0f, 1.0f);
00356    }
00357 
00358    RenderPolygon();
00359 
00360    if (fM->fDrawFrame)
00361    {
00362       glEnable(GL_LINE_SMOOTH);
00363 
00364       TGLUtil::Color(fM->fLineColor);
00365       TGLUtil::LineWidth(fM->fLineWidth);
00366       RenderOutline();
00367    }
00368 
00369    glPopAttrib();
00370 }

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