TEvePolygonSetProjectedGL.cxx

Go to the documentation of this file.
00001 // @(#)root/eve:$Id: TEvePolygonSetProjectedGL.cxx 36892 2010-11-24 10:24:35Z 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 "TEvePolygonSetProjectedGL.h"
00013 #include "TEvePolygonSetProjected.h"
00014 #include "TEveVector.h"
00015 
00016 #include "TGLRnrCtx.h"
00017 #include "TGLCamera.h"
00018 #include "TGLPhysicalShape.h"
00019 #include "TGLIncludes.h"
00020 
00021 //==============================================================================
00022 //==============================================================================
00023 // TEvePolygonSetProjectedGL
00024 //==============================================================================
00025 
00026 //______________________________________________________________________________
00027 //
00028 // GL-renderer for TEvePolygonSetProjected class.
00029 
00030 ClassImp(TEvePolygonSetProjectedGL);
00031 
00032 //______________________________________________________________________________
00033 TEvePolygonSetProjectedGL::TEvePolygonSetProjectedGL() : TGLObject()
00034 {
00035    // Constructor
00036 
00037    // fDLCache = kFALSE; // Disable DL.
00038    fMultiColor = kTRUE; // Potentially false, reset in DirectDraw().
00039 }
00040 
00041 /******************************************************************************/
00042 
00043 //______________________________________________________________________________
00044 Bool_t TEvePolygonSetProjectedGL::SetModel(TObject* obj, const Option_t* /*opt*/)
00045 {
00046    // Set model object.
00047 
00048    fM = SetModelDynCast<TEvePolygonSetProjected>(obj);
00049    return kTRUE;
00050 }
00051 
00052 //______________________________________________________________________________
00053 void TEvePolygonSetProjectedGL::SetBBox()
00054 {
00055    // Setup bounding-box information.
00056 
00057    SetAxisAlignedBBox(fM->AssertBBox());
00058 }
00059 
00060 /******************************************************************************/
00061 
00062 //______________________________________________________________________________
00063 void TEvePolygonSetProjectedGL::Draw(TGLRnrCtx& rnrCtx) const
00064 {
00065    // Draw function for TEvePolygonSetProjectedGL.
00066    // Skips line-pass of outline mode.
00067 
00068    if (rnrCtx.IsDrawPassOutlineLine())
00069       return;
00070 
00071    TGLObject::Draw(rnrCtx);
00072 }
00073 
00074 //______________________________________________________________________________
00075 void TEvePolygonSetProjectedGL::DrawOutline() const
00076 {
00077    // Draw polygons outline.
00078 
00079    if (fM->fPols.size() == 0) return;
00080 
00081    if (fM->GetMiniFrame())
00082    {
00083       std::map<Edge_t, Int_t> edges;
00084 
00085       for (TEvePolygonSetProjected::vpPolygon_ci i = fM->fPols.begin();
00086            i != fM->fPols.end(); ++i)
00087       {
00088          for(Int_t k = 0; k < i->fNPnts - 1; ++k)
00089          {
00090             ++edges[Edge_t(i->fPnts[k], i->fPnts[k+1])];
00091          }
00092          ++edges[Edge_t(i->fPnts[0], i->fPnts[i->fNPnts - 1])];
00093       }
00094 
00095       glBegin(GL_LINES);
00096       for (std::map<Edge_t, Int_t>::iterator i = edges.begin(); i != edges.end(); ++i)
00097       {
00098          if (i->second == 1)
00099          {
00100             glVertex3fv(fM->fPnts[i->first.fI].Arr());
00101             glVertex3fv(fM->fPnts[i->first.fJ].Arr());
00102          }
00103       }
00104       glEnd();
00105    }
00106    else
00107    {
00108       for (TEvePolygonSetProjected::vpPolygon_ci i = fM->fPols.begin();
00109            i != fM->fPols.end(); ++i)
00110       {
00111          glBegin(GL_LINE_LOOP);
00112          for(Int_t k = 0; k < i->fNPnts; ++k)
00113          {
00114             glVertex3fv(fM->fPnts[i->fPnts[k]].Arr());
00115          }
00116          glEnd();
00117       }
00118    }
00119 }
00120 
00121 //______________________________________________________________________________
00122 void TEvePolygonSetProjectedGL::DirectDraw(TGLRnrCtx& /*rnrCtx*/) const
00123 {
00124    // Do GL rendering.
00125 
00126    if (fM->fPols.size() == 0) return;
00127 
00128    glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT | GL_POLYGON_BIT);
00129 
00130    glDisable(GL_LIGHTING);
00131    glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
00132    glEnable(GL_COLOR_MATERIAL);
00133    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00134    glDisable(GL_CULL_FACE);
00135 
00136    fMultiColor = (fM->fDrawFrame && fM->fFillColor != fM->fLineColor);
00137 
00138    // polygons
00139    glEnable(GL_POLYGON_OFFSET_FILL);
00140    glPolygonOffset(1.0f,1.0f);
00141    GLUtesselator *tessObj = TGLUtil::GetDrawTesselator3fv();
00142 
00143    TEveVector* pnts = fM->fPnts;
00144    for (TEvePolygonSetProjected::vpPolygon_ci i = fM->fPols.begin();
00145         i != fM->fPols.end(); ++i)
00146    {
00147       Int_t vi; //current vertex index of curent polygon
00148       Int_t pntsN = (*i).fNPnts; // number of points in current polygon
00149       if (pntsN < 4)
00150       {
00151          glBegin(GL_POLYGON);
00152          for (Int_t k = 0; k < pntsN; ++k)
00153          {
00154             vi = (*i).fPnts[k];
00155             glVertex3fv(pnts[vi].Arr());
00156          }
00157          glEnd();
00158       }
00159       else
00160       {
00161          gluBeginPolygon(tessObj);
00162          gluNextContour(tessObj, (GLenum)GLU_UNKNOWN);
00163          glNormal3f(0., 0., 1.);
00164          Double_t coords[3];
00165          coords[2] = 0.;
00166          for (Int_t k = 0; k < pntsN; ++k)
00167          {
00168             vi = (*i).fPnts[k];
00169             coords[0] = pnts[vi].fX;
00170             coords[1] = pnts[vi].fY;
00171             gluTessVertex(tessObj, coords, pnts[vi].Arr());
00172          }
00173          gluEndPolygon(tessObj);
00174       }
00175    }
00176    glDisable(GL_POLYGON_OFFSET_FILL);
00177 
00178    // Outline
00179    if (fM->fDrawFrame)
00180    {
00181       TGLUtil::Color(fM->fLineColor);
00182       glEnable(GL_LINE_SMOOTH);
00183       TGLUtil::LineWidth(fM->fLineWidth);
00184       DrawOutline();
00185    }
00186 
00187    glPopAttrib();
00188 }
00189 
00190 //______________________________________________________________________________
00191 void TEvePolygonSetProjectedGL::DrawHighlight(TGLRnrCtx& rnrCtx, const TGLPhysicalShape* pshp, Int_t lvl) const
00192 {
00193    // Draw polygons in highlight mode.
00194 
00195    // XXXX to support highlight AND selection ...
00196    if (lvl < 0) lvl = pshp->GetSelected();
00197 
00198    if (fM->GetHighlightFrame())
00199    {
00200       glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT);
00201       glDisable(GL_LIGHTING);
00202       glEnable(GL_LINE_SMOOTH);
00203 
00204       glColor4ubv(rnrCtx.ColorSet().Selection(pshp->GetSelected()).CArr());
00205 
00206       const TGLRect& vp = rnrCtx.RefCamera().RefViewport();
00207       Int_t inner[4][2] = { { 0,-1}, { 1, 0}, { 0, 1}, {-1, 0} };
00208       Int_t outer[8][2] = { {-1,-1}, { 1,-1}, { 1, 1}, {-1, 1},
00209                             { 0,-2}, { 2, 0}, { 0, 2}, {-2, 0} };
00210 
00211       rnrCtx.SetHighlightOutline(kTRUE);
00212       TGLUtil::LockColor();
00213       Int_t first_outer = (rnrCtx.CombiLOD() == TGLRnrCtx::kLODHigh) ? 0 : 4;
00214       for (int i = first_outer; i < 8; ++i)
00215       {
00216          glViewport(vp.X() + outer[i][0], vp.Y() + outer[i][1], vp.Width(), vp.Height());
00217          DrawOutline();
00218       }
00219       TGLUtil::UnlockColor();
00220       rnrCtx.SetHighlightOutline(kFALSE);
00221 
00222       TGLUtil::Color(fM->fLineColor);
00223       for (int i = 0; i < 4; ++i)
00224       {
00225          glViewport(vp.X() + inner[i][0], vp.Y() + inner[i][1], vp.Width(), vp.Height());
00226          DrawOutline();
00227       }
00228       glViewport(vp.X(), vp.Y(), vp.Width(), vp.Height());
00229 
00230       pshp->SetupGLColors(rnrCtx);
00231       Float_t dr[2];
00232       glGetFloatv(GL_DEPTH_RANGE,dr);
00233       glDepthRange(dr[0], 0.5*dr[1]);
00234       DrawOutline();
00235       glDepthRange(dr[0], dr[1]);
00236 
00237       glPopAttrib();
00238    }
00239    else
00240    {
00241       TGLLogicalShape::DrawHighlight(rnrCtx, pshp);
00242    }
00243 }

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