TGLPolyMarker.cxx

Go to the documentation of this file.
00001 // @(#)root/gl:$Id: TGLPolyMarker.cxx 34867 2010-08-19 16:47:14Z matevz $
00002 // Author:  Timur Pocheptsov  03/08/2004
00003 // NOTE: This code moved from obsoleted TGLSceneObject.h / .cxx - see these
00004 // attic files for previous CVS history
00005 
00006 /*************************************************************************
00007  * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers.               *
00008  * All rights reserved.                                                  *
00009  *                                                                       *
00010  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00011  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00012  *************************************************************************/
00013 
00014 #include "TGLPolyMarker.h"
00015 #include "TGLRnrCtx.h"
00016 #include "TGLIncludes.h"
00017 #include "TGLUtil.h"
00018 
00019 #include "TBuffer3D.h"
00020 #include "TBuffer3DTypes.h"
00021 #include "TMath.h"
00022 
00023 #include "TAttMarker.h"
00024 
00025 // For debug tracing
00026 #include "TClass.h"
00027 #include "TError.h"
00028 
00029 //______________________________________________________________________________
00030 /* Begin_Html
00031 <center><h2>GL Polymarker</h2></center>
00032 To draw a 3D polymarker in a GL window.
00033 End_Html */
00034 
00035 ClassImp(TGLPolyMarker)
00036 
00037 //______________________________________________________________________________
00038 TGLPolyMarker::TGLPolyMarker(const TBuffer3D & buffer) :
00039    TGLLogicalShape(buffer),
00040    fVertices(buffer.fPnts, buffer.fPnts + 3 * buffer.NbPnts()),
00041    fStyle(7),
00042    fSize(1.)
00043 {
00044    //TAttMarker is not TObject descendant, so I need dynamic_cast
00045    if (TAttMarker *realObj = dynamic_cast<TAttMarker *>(buffer.fID)) {
00046       fStyle = realObj->GetMarkerStyle();
00047       fSize  = realObj->GetMarkerSize() / 2.;
00048    }
00049 }
00050 
00051 
00052 //______________________________________________________________________________
00053 void TGLPolyMarker::DirectDraw(TGLRnrCtx & rnrCtx) const
00054 {
00055    // Debug tracing
00056    if (gDebug > 4) {
00057       Info("TGLPolyMarker::DirectDraw", "this %ld (class %s) LOD %d", (Long_t)this, IsA()->GetName(), rnrCtx.ShapeLOD());
00058    }
00059 
00060    if (rnrCtx.DrawPass() == TGLRnrCtx::kPassOutlineLine)
00061       return;
00062 
00063    const Double_t *vertices = &fVertices[0];
00064    UInt_t size = fVertices.size();
00065    Int_t stacks = 6, slices = 6;
00066    Float_t pixelSize  = 1;
00067    Double_t topRadius = fSize;
00068 
00069    switch (fStyle) {
00070    case 27:
00071       stacks = 2, slices = 4;
00072       // intentionaly no break
00073    case 4:case 8:case 20:case 24:
00074       for (UInt_t i = 0; i < size; i += 3) {
00075          glPushMatrix();
00076          glTranslated(vertices[i], vertices[i + 1], vertices[i + 2]);
00077          gluSphere(rnrCtx.GetGluQuadric(), fSize, slices, stacks);
00078          glPopMatrix();
00079       }
00080       break;
00081    case 22:case 26:
00082       topRadius = 0.;
00083       // intentionaly no break
00084    case 21:case 25:
00085       for (UInt_t i = 0; i < size; i += 3) {
00086          glPushMatrix();
00087          glTranslated(vertices[i], vertices[i + 1], vertices[i + 2]);
00088          gluCylinder(rnrCtx.GetGluQuadric(), fSize, topRadius, fSize, 4, 1);
00089          glPopMatrix();
00090       }
00091       break;
00092    case 23:
00093       for (UInt_t i = 0; i < size; i += 3) {
00094          glPushMatrix();
00095          glTranslated(vertices[i], vertices[i + 1], vertices[i + 2]);
00096          glRotated(180, 1., 0., 0.);
00097          gluCylinder(rnrCtx.GetGluQuadric(), fSize, 0., fSize, 4, 1);
00098          glPopMatrix();
00099       }
00100       break;
00101    case 3: case 2: case 5:
00102       DrawStars();
00103       break;
00104    case 7:
00105       pixelSize += 1;
00106       // intentionaly no break
00107    case 6:
00108       pixelSize += 1;
00109       // intentionaly no break
00110    case 1: case 9: case 10: case 11: default:
00111       TGLUtil::PointSize(pixelSize);
00112       glBegin(GL_POINTS);
00113       for (UInt_t i = 0; i < size; i += 3)
00114          glVertex3dv(vertices + i);
00115       glEnd();
00116       break;
00117    }
00118 }
00119 
00120 
00121 //______________________________________________________________________________
00122 void TGLPolyMarker::DrawStars()const
00123 {
00124    // Draw stars
00125    glDisable(GL_LIGHTING);
00126    const Double_t diag = TMath::Sqrt(2 * fSize * fSize) / 2;
00127 
00128    for (UInt_t i = 0; i < fVertices.size(); i += 3) {
00129       Double_t x = fVertices[i];
00130       Double_t y = fVertices[i + 1];
00131       Double_t z = fVertices[i + 2];
00132       glBegin(GL_LINES);
00133       if (fStyle == 2 || fStyle == 3) {
00134          glVertex3d(x - fSize, y, z);
00135          glVertex3d(x + fSize, y, z);
00136          glVertex3d(x, y, z - fSize);
00137          glVertex3d(x, y, z + fSize);
00138          glVertex3d(x, y - fSize, z);
00139          glVertex3d(x, y + fSize, z);
00140       }
00141       if(fStyle != 2) {
00142          glVertex3d(x - diag, y - diag, z - diag);
00143          glVertex3d(x + diag, y + diag, z + diag);
00144          glVertex3d(x - diag, y - diag, z + diag);
00145          glVertex3d(x + diag, y + diag, z - diag);
00146          glVertex3d(x - diag, y + diag, z - diag);
00147          glVertex3d(x + diag, y - diag, z + diag);
00148          glVertex3d(x - diag, y + diag, z + diag);
00149          glVertex3d(x + diag, y - diag, z - diag);
00150       }
00151       glEnd();
00152    }
00153    glEnable(GL_LIGHTING);
00154 }

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