TGLUtil.h

Go to the documentation of this file.
00001 // @(#)root/gl:$Id: TGLUtil.h 36624 2010-11-12 12:17:06Z couet $
00002 // Author:  Richard Maunder  25/05/2005
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2004, 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 #ifndef ROOT_TGLUtil
00013 #define ROOT_TGLUtil
00014 
00015 #ifndef ROOT_Rtypes
00016 #include "Rtypes.h"
00017 #endif
00018 #ifndef ROOT_TError
00019 #include "TError.h"
00020 #endif
00021 
00022 class TString;
00023 class TGLBoundingBox;
00024 class TGLCamera;
00025 
00026 class TAttMarker;
00027 class TAttLine;
00028 
00029 class GLUtesselator;
00030 
00031 #include <vector>
00032 #include <cmath>
00033 #include <cassert>
00034 
00035 // TODO:Find a better place for these enums - TGLEnum.h?
00036 // Whole GL viewer should be moved into own namespace
00037 // probably
00038 enum EPosition
00039 {
00040    kInFront = 0,
00041    kBehind
00042 };
00043 
00044 enum EOverlap
00045 {
00046    kInside = 0,
00047    kPartial,
00048    kOutside
00049 };
00050 
00051 enum EClipType
00052 {
00053    kClipNone = 0,
00054    kClipPlane,
00055    kClipBox
00056 };
00057 
00058 enum EManipType
00059 {
00060    kManipTrans = 0,
00061    kManipScale,
00062    kManipRotate
00063 };
00064 
00065 enum EGLCoordType {
00066    kGLCartesian,
00067    kGLPolar,
00068    kGLCylindrical,
00069    kGLSpherical
00070 };
00071 
00072 enum EGLPlotType {
00073    kGLLegoPlot,
00074    kGLSurfacePlot,
00075    kGLBoxPlot,
00076    kGLTF3Plot,
00077    kGLStackPlot,
00078    kGLParametricPlot,
00079    kGLIsoPlot,
00080    kGL5D,
00081    kGLTH3Composition,
00082    kGLDefaultPlot
00083 };
00084 
00085 
00086 // TODO: Split these into own h/cxx files - too long now!
00087 
00088 //////////////////////////////////////////////////////////////////////////
00089 //                                                                      //
00090 // TGLVertex3                                                           //
00091 //                                                                      //
00092 // 3 component (x/y/z) vertex class                                     //
00093 //                                                                      //
00094 // This is part of collection of utility classes for GL in TGLUtil.h/cxx//
00095 // These provide const and non-const accessors Arr() / CArr() to a GL   //
00096 // compatible internal field - so can be used directly with OpenGL C API//
00097 // calls. They are not intended to be fully featured just provide       //
00098 // minimum required.                                                    //
00099 //////////////////////////////////////////////////////////////////////////
00100 
00101 class TGLVector3; // Forward declare for Shift()
00102 
00103 class TGLVertex3
00104 {
00105 protected:
00106    // Fields
00107    Bool_t ValidIndex(UInt_t index) const { return (index < 3); }
00108    Double_t fVals[3];
00109 
00110 public:
00111    TGLVertex3();
00112    TGLVertex3(Double_t x, Double_t y, Double_t z);
00113    TGLVertex3(Double_t* v);
00114    TGLVertex3(const TGLVertex3 & other);
00115    virtual ~TGLVertex3();
00116 
00117    Bool_t       operator == (const TGLVertex3 & rhs) const;
00118    TGLVertex3 & operator =  (const TGLVertex3 & rhs);
00119    TGLVertex3 & operator *= (Double_t f);
00120    TGLVertex3   operator -  () const;
00121    const TGLVertex3 & operator -= (const TGLVector3 & val);
00122    const TGLVertex3 & operator += (const TGLVector3 & val);
00123 
00124    // Manipulators
00125    void Fill(Double_t val);
00126    void Set(Double_t x, Double_t y, Double_t z);
00127    void Set(const Double_t* xyz);
00128    void Set(const TGLVertex3 & other);
00129    void Shift(TGLVector3 & shift);
00130    void Shift(Double_t xDelta, Double_t yDelta, Double_t zDelta);
00131    void Negate();
00132 
00133    void Minimum(const TGLVertex3 & other);
00134    void Maximum(const TGLVertex3 & other);
00135 
00136    // Accessors
00137          Double_t & operator [] (Int_t index);
00138    const Double_t & operator [] (Int_t index) const;
00139    Double_t   X() const { return fVals[0]; }
00140    Double_t & X()       { return fVals[0]; }
00141    Double_t   Y() const { return fVals[1]; }
00142    Double_t & Y()       { return fVals[1]; }
00143    Double_t   Z() const { return fVals[2]; }
00144    Double_t & Z()       { return fVals[2]; }
00145 
00146    const Double_t * CArr() const { return fVals; }
00147    Double_t *       Arr()        { return fVals; }
00148 
00149    void Dump() const;
00150 
00151    ClassDef(TGLVertex3,0); // GL 3 component vertex helper/wrapper class
00152 };
00153 
00154 //______________________________________________________________________________
00155 inline TGLVertex3 operator*(Double_t f, const TGLVertex3& v)
00156 {
00157    return TGLVertex3(f*v.X(), f*v.Y(), f*v.Z());
00158 }
00159 
00160 //______________________________________________________________________________
00161 inline void TGLVertex3::Negate()
00162 {
00163    fVals[0] = -fVals[0];
00164    fVals[1] = -fVals[1];
00165    fVals[2] = -fVals[2];
00166 }
00167 
00168 //______________________________________________________________________________
00169 inline Bool_t TGLVertex3::operator == (const TGLVertex3 & rhs) const
00170 {
00171    return (fVals[0] == rhs.fVals[0] && fVals[1] == rhs.fVals[1] && fVals[2] == rhs.fVals[2]);
00172 }
00173 
00174 //______________________________________________________________________________
00175 inline TGLVertex3 & TGLVertex3::operator = (const TGLVertex3 & rhs)
00176 {
00177    // Check for self-assignment
00178    if (this != &rhs) {
00179       Set(rhs);
00180    }
00181    return *this;
00182 }
00183 
00184 // operator -= & operator += inline needs to be defered until full TGLVector3 definition
00185 
00186 //______________________________________________________________________________
00187 inline TGLVertex3 TGLVertex3::operator - () const
00188 {
00189    return TGLVertex3(-fVals[0], -fVals[1], -fVals[2]);
00190 }
00191 
00192 //______________________________________________________________________________
00193 inline TGLVertex3& TGLVertex3::operator *= (Double_t f)
00194 {
00195    fVals[0] *= f;
00196    fVals[1] *= f;
00197    fVals[2] *= f;
00198    return *this;
00199 }
00200 
00201 //______________________________________________________________________________
00202 inline Double_t & TGLVertex3::operator [] (Int_t index)
00203 {
00204    /*if (!ValidIndex(index)) {
00205       assert(kFALSE);
00206       return fVals[0];
00207    } else {*/
00208       return fVals[index];
00209    //}
00210 }
00211 
00212 //______________________________________________________________________________
00213 inline const Double_t& TGLVertex3::operator [] (Int_t index) const
00214 {
00215    /*if (!ValidIndex(index)) {
00216       assert(kFALSE);
00217       return fVals[0];
00218    } else {*/
00219       return fVals[index];
00220    //}
00221 }
00222 
00223 //______________________________________________________________________________
00224 inline void TGLVertex3::Fill(Double_t val)
00225 {
00226    Set(val,val,val);
00227 }
00228 
00229 //______________________________________________________________________________
00230 inline void TGLVertex3::Set(Double_t x, Double_t y, Double_t z)
00231 {
00232    fVals[0]=x;
00233    fVals[1]=y;
00234    fVals[2]=z;
00235 }
00236 
00237 //______________________________________________________________________________
00238 inline void TGLVertex3::Set(const Double_t* xyz)
00239 {
00240    fVals[0]=xyz[0];
00241    fVals[1]=xyz[1];
00242    fVals[2]=xyz[2];
00243 }
00244 
00245 //______________________________________________________________________________
00246 inline void TGLVertex3::Set(const TGLVertex3 & other)
00247 {
00248    fVals[0]=other.fVals[0];
00249    fVals[1]=other.fVals[1];
00250    fVals[2]=other.fVals[2];
00251 }
00252 
00253 
00254 //////////////////////////////////////////////////////////////////////////
00255 //                                                                      //
00256 // TGLVector3                                                           //
00257 //                                                                      //
00258 // 3 component (x/y/z) vector class                                     //
00259 //                                                                      //
00260 // This is part of collection of utility classes for GL in TGLUtil.h/cxx//
00261 // These provide const and non-const accessors Arr() / CArr() to a GL   //
00262 // compatible internal field - so can be used directly with OpenGL C API//
00263 // calls. They are not intended to be fully featured just provide       //
00264 // minimum required.                                                    //
00265 //////////////////////////////////////////////////////////////////////////
00266 
00267 class TGLVector3 : public TGLVertex3
00268 {
00269 public:
00270    TGLVector3();
00271    TGLVector3(Double_t x, Double_t y, Double_t z);
00272    TGLVector3(const Double_t *src);
00273    TGLVector3(const TGLVector3 & other);
00274    virtual ~TGLVector3();
00275 
00276    TGLVector3& operator = (const TGLVertex3& v)
00277    { fVals[0] = v[0]; fVals[1] = v[1]; fVals[2] = v[2]; return *this; }
00278 
00279    TGLVector3 & operator /= (Double_t val);
00280    TGLVector3   operator -  () const;
00281 
00282    Double_t Mag() const;
00283    void     Normalise();
00284 
00285    ClassDef(TGLVector3,0); // GL 3 component vector helper/wrapper class
00286 };
00287 
00288 // Inline for TGLVertex3 requiring full TGLVector definition
00289 //______________________________________________________________________________
00290 inline const TGLVertex3 & TGLVertex3::operator -= (const TGLVector3 & vec)
00291 {
00292    fVals[0] -= vec[0]; fVals[1] -= vec[1]; fVals[2] -= vec[2];
00293    return *this;
00294 }
00295 
00296 // Inline for TGLVertex3 requiring full TGLVector definition
00297 //______________________________________________________________________________
00298 inline const TGLVertex3 & TGLVertex3::operator += (const TGLVector3 & vec)
00299 {
00300    fVals[0] += vec[0]; fVals[1] += vec[1]; fVals[2] += vec[2];
00301    return *this;
00302 }
00303 
00304 //______________________________________________________________________________
00305 inline TGLVector3 & TGLVector3::operator /= (Double_t val)
00306 {
00307    fVals[0] /= val;
00308    fVals[1] /= val;
00309    fVals[2] /= val;
00310    return *this;
00311 }
00312 
00313 //______________________________________________________________________________
00314 inline TGLVector3 TGLVector3::operator - () const
00315 {
00316    return TGLVector3(-fVals[0], -fVals[1], -fVals[2]);
00317 }
00318 
00319 //______________________________________________________________________________
00320 inline Double_t TGLVector3::Mag() const
00321 {
00322    return std::sqrt(fVals[0]*fVals[0] + fVals[1]*fVals[1] + fVals[2]*fVals[2]);
00323 }
00324 
00325 //______________________________________________________________________________
00326 inline void TGLVector3::Normalise()
00327 {
00328    Double_t mag = Mag();
00329    if ( mag == 0.0 ) {
00330       Error("TGLVector3::Normalise", "vector has zero magnitude");
00331       return;
00332    }
00333    fVals[0] /= mag;
00334    fVals[1] /= mag;
00335    fVals[2] /= mag;
00336 }
00337 
00338 //______________________________________________________________________________
00339 inline Double_t Dot(const TGLVector3 & v1, const TGLVector3 & v2)
00340 {
00341    return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
00342 }
00343 
00344 //______________________________________________________________________________
00345 inline TGLVector3 Cross(const TGLVector3 & v1, const TGLVector3 & v2)
00346 {
00347     return TGLVector3(v1[1]*v2[2] - v2[1]*v1[2],
00348                       v1[2]*v2[0] - v2[2]*v1[0],
00349                       v1[0]*v2[1] - v2[0]*v1[1]);
00350 }
00351 
00352 //______________________________________________________________________________
00353 inline const TGLVector3 operator / (const TGLVector3 & vec, Double_t val)
00354 {
00355    return TGLVector3(vec[0] / val, vec[1] / val, vec[2] / val);
00356 }
00357 
00358 //______________________________________________________________________________
00359 inline const TGLVector3 operator * (const TGLVector3 & vec, Double_t val)
00360 {
00361    return TGLVector3(vec[0] * val, vec[1] * val, vec[2] * val);
00362 }
00363 
00364 //______________________________________________________________________________
00365 // Vertex + Vector => Vertex
00366 inline TGLVertex3 operator + (const TGLVertex3 & vertex1, const TGLVector3 & vertex2)
00367 {
00368    return TGLVertex3(vertex1[0] + vertex2[0], vertex1[1] + vertex2[1], vertex1[2] + vertex2[2]);
00369 }
00370 
00371 //______________________________________________________________________________
00372 // Vertex - Vertex => Vector
00373 inline TGLVector3 operator - (const TGLVertex3 & vertex1, const TGLVertex3 & vertex2)
00374 {
00375    return TGLVector3(vertex1[0] - vertex2[0], vertex1[1] - vertex2[1], vertex1[2] - vertex2[2]);
00376 }
00377 
00378 //______________________________________________________________________________
00379 // Vector + Vector => Vector
00380 inline TGLVector3 operator + (const TGLVector3 & vector1, const TGLVector3 & vector2)
00381 {
00382    return TGLVector3(vector1[0] + vector2[0], vector1[1] + vector2[1], vector1[2] + vector2[2]);
00383 }
00384 
00385 //______________________________________________________________________________
00386 // Vector - Vector => Vector
00387 inline TGLVector3 operator - (const TGLVector3 & vector1, const TGLVector3 & vector2)
00388 {
00389    return TGLVector3(vector1[0] - vector2[0], vector1[1] - vector2[1], vector1[2] - vector2[2]);
00390 }
00391 
00392 //______________________________________________________________________________
00393 // Dot-product
00394 inline Double_t operator * (const TGLVector3 & a, const TGLVector3 & b)
00395 {
00396    return a[0]*b[0] + a[1]*b[1] + a[2]*b[2];
00397 }
00398 
00399 //////////////////////////////////////////////////////////////////////////
00400 //                                                                      //
00401 // TGLLine3                                                             //
00402 //                                                                      //
00403 // 3D space, fixed length, line class, with direction / length 'vector',//
00404 // passing through point 'vertex'. Just wraps a TGLVector3 / TGLVertex3 //
00405 // pair.                                                                //
00406 //////////////////////////////////////////////////////////////////////////
00407 
00408 class TGLLine3
00409 {
00410 private:
00411    // Fields
00412    TGLVertex3 fVertex; //! Start vertex of line
00413    TGLVector3 fVector; //! Vector of line from fVertex
00414 
00415 public:
00416    TGLLine3(const TGLVertex3 & start, const TGLVertex3 & end);
00417    TGLLine3(const TGLVertex3 & start, const TGLVector3 & vector);
00418    virtual ~TGLLine3();
00419 
00420    void Set(const TGLVertex3 & start, const TGLVertex3 & end);
00421    void Set(const TGLVertex3 & start, const TGLVector3 & vector);
00422 
00423    // Bitwise copy constructor and = operator are fine
00424 
00425    // Accessors
00426    const TGLVertex3 & Start()  const { return fVertex; }
00427    const TGLVertex3   End()    const { return fVertex + fVector; }
00428    const TGLVector3 & Vector() const { return fVector; }
00429 
00430    // Debug
00431    void Draw() const;
00432 
00433    ClassDef(TGLLine3,0); // GL line wrapper class
00434 };
00435 
00436 //////////////////////////////////////////////////////////////////////////
00437 //                                                                      //
00438 // TGLRect                                                              //
00439 //                                                                      //
00440 // Viewport (pixel base) 2D rectangle class                             //
00441 //////////////////////////////////////////////////////////////////////////
00442 
00443 class TGLRect
00444 {
00445 private:
00446    // Fields
00447    Int_t    fX, fY;           //! Corner
00448    Int_t    fWidth, fHeight;  //! Positive width/height
00449 
00450 public:
00451    TGLRect();
00452    TGLRect(Int_t x, Int_t y, Int_t width, Int_t height);
00453    TGLRect(Int_t x, Int_t y, UInt_t width, UInt_t height);
00454    virtual ~TGLRect();
00455 
00456    // Bitwise copy const & =op are ok at present
00457 
00458    // Manipulators
00459    void Set(Int_t x, Int_t y, Int_t width, Int_t height);
00460    void SetCorner(Int_t x, Int_t y);
00461    void Offset(Int_t dX, Int_t dY);
00462    void Expand(Int_t x, Int_t y);
00463 
00464    // Accessors
00465    const Int_t* CArr() const { return &fX; }
00466          Int_t* CArr()       { return &fX; }
00467 
00468    Int_t    X()       const { return fX; }
00469    Int_t &  X()             { return fX; }
00470    Int_t    Y()       const { return fY; }
00471    Int_t &  Y()             { return fY; }
00472    Int_t    Width()   const { return fWidth; }
00473    Int_t &  Width()         { return fWidth; }
00474    Int_t    Height()  const { return fHeight; }
00475    Int_t &  Height()        { return fHeight; }
00476    Int_t    CenterX() const { return fX + fWidth/2; }
00477    Int_t    CenterY() const { return fY + fHeight/2; }
00478    Int_t    Left()    const { return fX; }
00479    Int_t    Right()   const { return fX + fWidth; }
00480    Int_t    Top()     const { return fY; }
00481    Int_t    Bottom()  const { return fY + fHeight; }
00482 
00483    Int_t Diagonal() const;
00484    Int_t Longest() const;
00485 
00486    Double_t Aspect() const;
00487    EOverlap Overlap(const TGLRect & other) const;
00488 
00489    ClassDef(TGLRect,0); // GL rect helper/wrapper class
00490 };
00491 
00492 //______________________________________________________________________________
00493 inline void TGLRect::Set(Int_t x, Int_t y, Int_t width, Int_t height)
00494 {
00495    fX = x;
00496    fY = y;
00497    fWidth = width;
00498    fHeight = height;
00499 }
00500 
00501 //______________________________________________________________________________
00502 inline void TGLRect::SetCorner(Int_t x, Int_t y)
00503 {
00504    fX = x;
00505    fY = y;
00506 }
00507 
00508 //______________________________________________________________________________
00509 inline void TGLRect::Offset(Int_t dX, Int_t dY)
00510 {
00511    fX += dX;
00512    fY += dY;
00513 }
00514 
00515 //______________________________________________________________________________
00516 inline Int_t TGLRect::Longest() const
00517 {
00518    return fWidth > fHeight ? fWidth : fHeight;
00519 }
00520 
00521 //______________________________________________________________________________
00522 inline Double_t TGLRect::Aspect() const
00523 {
00524    // Return aspect ratio (width/height)
00525    if (fHeight == 0) {
00526       return 0.0;
00527    } else {
00528       return static_cast<Double_t>(fWidth) / static_cast<Double_t>(fHeight);
00529    }
00530 }
00531 
00532 //////////////////////////////////////////////////////////////////////////
00533 //                                                                      //
00534 // TGLPlane                                                             //
00535 //                                                                      //
00536 // 3D plane class - of format Ax + By + Cz + D = 0                      //
00537 //                                                                      //
00538 // This is part of collection of simple utility classes for GL only in  //
00539 // TGLUtil.h/cxx. These provide const and non-const accessors Arr() &   //
00540 // CArr() to a GL compatible internal field - so can be used directly   //
00541 // with OpenGL C API calls - which TVector3 etc cannot (easily).        //
00542 // They are not intended to be fully featured just provide minimum      //
00543 // required.                                                            //
00544 //////////////////////////////////////////////////////////////////////////
00545 
00546 class TGLPlane
00547 {
00548 private:
00549    // Fields
00550    Double_t fVals[4];
00551 
00552    // Methods
00553    void Normalise();
00554 
00555 public:
00556    TGLPlane();
00557    TGLPlane(const TGLPlane & other);
00558    TGLPlane(Double_t a, Double_t b, Double_t c, Double_t d);
00559    TGLPlane(Double_t eq[4]);
00560    TGLPlane(const TGLVector3 & norm, const TGLVertex3 & point);
00561    TGLPlane(const TGLVertex3 & p1, const TGLVertex3 & p2, const TGLVertex3 & p3);
00562    virtual ~TGLPlane();
00563 
00564    // Manipulators
00565    void Set(const TGLPlane & other);
00566    void Set(Double_t a, Double_t b, Double_t c, Double_t d);
00567    void Set(Double_t eq[4]);
00568    void Set(const TGLVector3 & norm, const TGLVertex3 & point);
00569    void Set(const TGLVertex3 & p1, const TGLVertex3 & p2, const TGLVertex3 & p3);
00570    void Negate();
00571 
00572    // Accessors
00573    Double_t A() const { return fVals[0]; }
00574    Double_t B() const { return fVals[1]; }
00575    Double_t C() const { return fVals[2]; }
00576    Double_t D() const { return fVals[3]; }
00577 
00578    TGLVector3 Norm() const { return TGLVector3( fVals[0], fVals[1], fVals[2]); }
00579    Double_t DistanceTo(const TGLVertex3 & vertex) const;
00580    TGLVertex3 NearestOn(const TGLVertex3 & point) const;
00581 
00582    // Internal data accessors - for GL API
00583    const Double_t * CArr() const { return fVals; }
00584    Double_t * Arr() { return fVals; }
00585 
00586    void Dump() const;
00587 
00588    ClassDef(TGLPlane,0); // GL plane helper/wrapper class
00589 };
00590 
00591 typedef std::vector<TGLPlane>                 TGLPlaneSet_t;
00592 typedef std::vector<TGLPlane>::iterator       TGLPlaneSet_i;
00593 typedef std::vector<TGLPlane>::const_iterator TGLPlaneSet_ci;
00594 
00595 // Some free functions for planes
00596 std::pair<Bool_t, TGLLine3>   Intersection(const TGLPlane & p1, const TGLPlane & p2);
00597 std::pair<Bool_t, TGLVertex3> Intersection(const TGLPlane & p1, const TGLPlane & p2, const TGLPlane & p3);
00598 std::pair<Bool_t, TGLVertex3> Intersection(const TGLPlane & plane, const TGLLine3 & line, Bool_t extend);
00599 
00600 
00601 //////////////////////////////////////////////////////////////////////////
00602 //                                                                      //
00603 // TGLMatrix                                                            //
00604 //                                                                      //
00605 // 16 component (4x4) transform matrix - column MAJOR as per GL.        //
00606 // Provides limited support for adjusting the translation, scale and    //
00607 // rotation components.                                                 //
00608 //                                                                      //
00609 // This is part of collection of simple utility classes for GL only in  //
00610 // TGLUtil.h/cxx. These provide const and non-const accessors Arr() &   //
00611 // CArr() to a GL compatible internal field - so can be used directly   //
00612 // with OpenGL C API calls - which TVector3 etc cannot (easily).        //
00613 // They are not intended to be fully featured just provide minimum      //
00614 // required.                                                            //
00615 //////////////////////////////////////////////////////////////////////////
00616 
00617 class TGLMatrix
00618 {
00619 private:
00620    // Fields
00621    Double_t fVals[16]; // Column MAJOR as per OGL
00622 
00623    // Methods
00624    Bool_t ValidIndex(UInt_t index) const { return (index < 16); }
00625 
00626 public:
00627    TGLMatrix();
00628    TGLMatrix(Double_t x, Double_t y, Double_t z);
00629    TGLMatrix(const TGLVertex3 & translation);
00630    TGLMatrix(const TGLVertex3 & origin, const TGLVector3 & zAxis, const TGLVector3 & xAxis);
00631    TGLMatrix(const TGLVertex3 & origin, const TGLVector3 & zAxis);
00632    TGLMatrix(const Double_t vals[16]);
00633    TGLMatrix(const TGLMatrix & other);
00634    virtual ~TGLMatrix();
00635 
00636    // Operators
00637    TGLMatrix & operator =(const TGLMatrix & rhs);
00638    Double_t  & operator [] (Int_t index);
00639    Double_t    operator [] (Int_t index) const;
00640 
00641    void MultRight(const TGLMatrix & rhs);
00642    void MultLeft (const TGLMatrix & lhs);
00643    TGLMatrix & operator*=(const TGLMatrix & rhs) { MultRight(rhs); return *this; }
00644 
00645    // Manipulators
00646    void Set(const TGLVertex3 & origin, const TGLVector3 & zAxis, const TGLVector3 & xAxis = 0);
00647    void Set(const Double_t vals[16]);
00648    void SetIdentity();
00649 
00650    void SetTranslation(Double_t x, Double_t y, Double_t z);
00651    void SetTranslation(const TGLVertex3 & translation);
00652 
00653    void Translate(const TGLVector3 & vect);
00654    void MoveLF(Int_t ai, Double_t amount);
00655    void Move3LF(Double_t x, Double_t y, Double_t z);
00656 
00657    void Scale(const TGLVector3 & scale);
00658    void Rotate(const TGLVertex3 & pivot, const TGLVector3 & axis, Double_t angle);
00659    void RotateLF(Int_t i1, Int_t i2, Double_t amount);
00660    void RotatePF(Int_t i1, Int_t i2, Double_t amount);
00661    void TransformVertex(TGLVertex3 & vertex) const;
00662    void Transpose3x3();
00663    Double_t Invert();
00664 
00665    // Accesors
00666    TGLVector3  GetTranslation() const;
00667    TGLVector3  GetScale() const;
00668 
00669    void SetBaseVec(Int_t b, Double_t x, Double_t y, Double_t z);
00670    void SetBaseVec(Int_t b, const TGLVector3& v);
00671    void SetBaseVec(Int_t b, Double_t* x);
00672 
00673    TGLVector3 GetBaseVec(Int_t b) const;
00674    void       GetBaseVec(Int_t b, TGLVector3& v) const;
00675    void       GetBaseVec(Int_t b, Double_t* x) const;
00676 
00677    TGLVector3 Multiply(const TGLVector3& v, Double_t w=1) const;
00678    TGLVector3 Rotate(const TGLVector3& v) const;
00679    void       MultiplyIP(TGLVector3& v, Double_t w=1) const;
00680    void       RotateIP(TGLVector3& v) const;
00681 
00682    // Internal data accessors - for GL API
00683    const Double_t * CArr() const { return fVals; }
00684    Double_t * Arr() { return fVals; }
00685 
00686    void Dump() const;
00687 
00688    ClassDef(TGLMatrix,0); // GL matrix helper/wrapper class
00689 };
00690 
00691 //______________________________________________________________________________
00692 inline TGLMatrix & TGLMatrix::operator =(const TGLMatrix & rhs)
00693 {
00694    // Check for self-assignment
00695    if (this != &rhs) {
00696       Set(rhs.fVals);
00697    }
00698    return *this;
00699 }
00700 
00701 //______________________________________________________________________________
00702 inline Double_t & TGLMatrix::operator [] (Int_t index)
00703 {
00704    /*if (!ValidIndex(index)) {
00705       assert(kFALSE);
00706       return fVals[0];
00707    } else {*/
00708       return fVals[index];
00709    //}
00710 }
00711 
00712 //______________________________________________________________________________
00713 inline Double_t TGLMatrix::operator [] (Int_t index) const
00714 {
00715    /*if (!ValidIndex(index)) {
00716       assert(kFALSE);
00717       return fVals[0];
00718    } else {*/
00719       return fVals[index];
00720    //}
00721 }
00722 
00723 //______________________________________________________________________________
00724 inline TGLMatrix operator * (const TGLMatrix & lhs, const TGLMatrix & rhs)
00725 {
00726    TGLMatrix res;
00727 
00728    res[ 0] = rhs[ 0] * lhs[ 0] + rhs[ 1] * lhs[ 4] + rhs[ 2] * lhs[ 8] + rhs[ 3] * lhs[12];
00729    res[ 1] = rhs[ 0] * lhs[ 1] + rhs[ 1] * lhs[ 5] + rhs[ 2] * lhs[ 9] + rhs[ 3] * lhs[13];
00730    res[ 2] = rhs[ 0] * lhs[ 2] + rhs[ 1] * lhs[ 6] + rhs[ 2] * lhs[10] + rhs[ 3] * lhs[14];
00731    res[ 3] = rhs[ 0] * lhs[ 3] + rhs[ 1] * lhs[ 7] + rhs[ 2] * lhs[11] + rhs[ 3] * lhs[15];
00732 
00733    res[ 4] = rhs[ 4] * lhs[ 0] + rhs[ 5] * lhs[ 4] + rhs[ 6] * lhs[ 8] + rhs[ 7] * lhs[12];
00734    res[ 5] = rhs[ 4] * lhs[ 1] + rhs[ 5] * lhs[ 5] + rhs[ 6] * lhs[ 9] + rhs[ 7] * lhs[13];
00735    res[ 6] = rhs[ 4] * lhs[ 2] + rhs[ 5] * lhs[ 6] + rhs[ 6] * lhs[10] + rhs[ 7] * lhs[14];
00736    res[ 7] = rhs[ 4] * lhs[ 3] + rhs[ 5] * lhs[ 7] + rhs[ 6] * lhs[11] + rhs[ 7] * lhs[15];
00737 
00738    res[ 8] = rhs[ 8] * lhs[ 0] + rhs[ 9] * lhs[ 4] + rhs[10] * lhs[ 8] + rhs[11] * lhs[12];
00739    res[ 9] = rhs[ 8] * lhs[ 1] + rhs[ 9] * lhs[ 5] + rhs[10] * lhs[ 9] + rhs[11] * lhs[13];
00740    res[10] = rhs[ 8] * lhs[ 2] + rhs[ 9] * lhs[ 6] + rhs[10] * lhs[10] + rhs[11] * lhs[14];
00741    res[11] = rhs[ 8] * lhs[ 3] + rhs[ 9] * lhs[ 7] + rhs[10] * lhs[11] + rhs[11] * lhs[15];
00742 
00743    res[12] = rhs[12] * lhs[ 0] + rhs[13] * lhs[ 4] + rhs[14] * lhs[ 8] + rhs[15] * lhs[12];
00744    res[13] = rhs[12] * lhs[ 1] + rhs[13] * lhs[ 5] + rhs[14] * lhs[ 9] + rhs[15] * lhs[13];
00745    res[14] = rhs[12] * lhs[ 2] + rhs[13] * lhs[ 6] + rhs[14] * lhs[10] + rhs[15] * lhs[14];
00746    res[15] = rhs[12] * lhs[ 3] + rhs[13] * lhs[ 7] + rhs[14] * lhs[11] + rhs[15] * lhs[15];
00747 
00748    return res;
00749 }
00750 
00751 //______________________________________________________________________________
00752 inline void TGLMatrix::SetBaseVec(Int_t b, Double_t x, Double_t y, Double_t z)
00753 {
00754    Double_t* C = fVals + 4*--b;
00755    C[0] = x; C[1] = y; C[2] = z;
00756 }
00757 
00758 //______________________________________________________________________________
00759 inline void TGLMatrix::SetBaseVec(Int_t b, const TGLVector3& v)
00760 {
00761    Double_t* C = fVals + 4*--b;
00762    C[0] = v[0]; C[1] = v[1]; C[2] = v[2];
00763 }
00764 
00765 //______________________________________________________________________________
00766 inline void TGLMatrix::SetBaseVec(Int_t b, Double_t* x)
00767 {
00768    Double_t* C = fVals + 4*--b;
00769    C[0] = x[0]; C[1] = x[1]; C[2] = x[2];
00770 }
00771 
00772 //______________________________________________________________________________
00773 inline TGLVector3 TGLMatrix::GetBaseVec(Int_t b) const
00774 {
00775    return TGLVector3(&fVals[4*--b]);
00776 }
00777 
00778 //______________________________________________________________________________
00779 inline void TGLMatrix::GetBaseVec(Int_t b, TGLVector3& v) const
00780 {
00781    const Double_t* C = fVals + 4*--b;
00782    v[0] = C[0]; v[1] = C[1]; v[2] = C[2];
00783 }
00784 
00785 //______________________________________________________________________________
00786 inline void TGLMatrix::GetBaseVec(Int_t b, Double_t* x) const
00787 {
00788    const Double_t* C = fVals + 4*--b;
00789    x[0] = C[0], x[1] = C[1], x[2] = C[2];
00790 }
00791 
00792 
00793 //////////////////////////////////////////////////////////////////////////
00794 //
00795 // TGLColor
00796 //
00797 // Encapsulate color in preferred GL format - UChar_t RGBA array.
00798 // Color index is also cached for easier interfacing with the
00799 // traditional ROOT graphics.
00800 //
00801 //////////////////////////////////////////////////////////////////////////
00802 
00803 class TGLColor
00804 {
00805 protected:
00806    UChar_t         fRGBA[4];
00807    mutable Short_t fIndex;
00808 
00809 public:
00810    TGLColor();
00811    TGLColor(Int_t r, Int_t g, Int_t b, Int_t a=255);
00812    TGLColor(Float_t r, Float_t g, Float_t b, Float_t a=1);
00813    TGLColor(Color_t color_index, Char_t transparency=0);
00814    virtual ~TGLColor();
00815 
00816    TGLColor& operator=(const TGLColor& c);
00817 
00818    UChar_t*        Arr()       { return fRGBA; }
00819    const UChar_t* CArr() const { return fRGBA; }
00820 
00821    UChar_t GetRed()   const { return fRGBA[0]; }
00822    UChar_t GetGreen() const { return fRGBA[1]; }
00823    UChar_t GetBlue()  const { return fRGBA[2]; }
00824    UChar_t GetAlpha() const { return fRGBA[3]; }
00825 
00826    Color_t GetColorIndex()   const;
00827    Char_t  GetTransparency() const;
00828 
00829    void SetRed(Int_t v)   { fRGBA[0] = v; }
00830    void SetGreen(Int_t v) { fRGBA[1] = v; }
00831    void SetBlue(Int_t v)  { fRGBA[2] = v; }
00832    void SetAlpha(Int_t v) { fRGBA[3] = v; }
00833 
00834    void SetColor(Int_t r, Int_t g, Int_t b, Int_t a=255);
00835    void SetColor(Float_t r, Float_t g, Float_t b, Float_t a=1);
00836    void SetColor(Color_t color_index);
00837    void SetColor(Color_t color_index, Char_t transparency);
00838    void SetTransparency(Char_t transparency);
00839 
00840    TString AsString() const;
00841 
00842    ClassDef(TGLColor, 0); // Color in preferred GL format - RGBA.
00843 };
00844 
00845 
00846 //////////////////////////////////////////////////////////////////////////
00847 //
00848 // TGLColorSet
00849 //
00850 // A collection of colors used for OpenGL rendering.
00851 //
00852 //////////////////////////////////////////////////////////////////////////
00853 
00854 class TGLColorSet
00855 {
00856 protected:
00857    TGLColor        fBackground;
00858    TGLColor        fForeground;
00859    TGLColor        fOutline;
00860    TGLColor        fMarkup;
00861    TGLColor        fSelection[5];   // Colors for shape-selection-levels
00862 
00863 public:
00864    TGLColorSet();
00865    virtual ~TGLColorSet();
00866 
00867    TGLColorSet& operator=(const TGLColorSet& s);
00868 
00869    TGLColor& Background()       { return fBackground; }
00870    TGLColor& Foreground()       { return fForeground; }
00871    TGLColor& Outline()          { return fOutline; }
00872    TGLColor& Markup()           { return fMarkup;  }
00873    TGLColor& Selection(Int_t i) { return fSelection[i]; }
00874 
00875    const TGLColor& Background()       const { return fBackground; }
00876    const TGLColor& Foreground()       const { return fForeground; }
00877    const TGLColor& Outline()          const { return fOutline; }
00878    const TGLColor& Markup()           const { return fMarkup;  }
00879    const TGLColor& Selection(Int_t i) const { return fSelection[i]; }
00880 
00881    void StdDarkBackground();
00882    void StdLightBackground();
00883 
00884    ClassDef(TGLColorSet, 0); // Collection of colors used for GL rendering.
00885 };
00886 
00887 //////////////////////////////////////////////////////////////////////////
00888 //                                                                      //
00889 // TGLUtil                                                              //
00890 //                                                                      //
00891 // Wrapper class for various misc static functions - error checking,    //
00892 // draw helpers etc.                                                    //
00893 //                                                                      //
00894 //////////////////////////////////////////////////////////////////////////
00895 
00896 class TGLUtil
00897 {
00898 public:
00899    class TColorLocker
00900    {
00901    public:
00902       TColorLocker()          { LockColor();   }
00903       virtual ~TColorLocker() { UnlockColor(); }
00904 
00905       ClassDef(TColorLocker,0); // Lock/unlock color in constructor/destructor.
00906    };
00907 
00908    class TDrawQualityModifier
00909    {
00910       Int_t fOldQuality;
00911    public:
00912       TDrawQualityModifier(Int_t dq) :
00913       fOldQuality(GetDrawQuality()) {SetDrawQuality(dq); }
00914 
00915       virtual ~TDrawQualityModifier()
00916       { SetDrawQuality(fOldQuality); }
00917 
00918       ClassDef(TDrawQualityModifier,0); // Set/restore draw quality in constructor/destructor.
00919    };
00920 
00921    class TDrawQualityScaler
00922    {
00923       Int_t fOldQuality;
00924    public:
00925       TDrawQualityScaler(Float_t fac) :
00926       fOldQuality(GetDrawQuality()) {SetDrawQuality((Int_t)(fac*fOldQuality)); }
00927 
00928       virtual ~TDrawQualityScaler()
00929       { SetDrawQuality(fOldQuality); }
00930 
00931       ClassDef(TDrawQualityScaler,0); // Multiply/restore draw quality in constructor/destructor.
00932    };
00933 
00934 private:
00935    static UInt_t fgDefaultDrawQuality;
00936    static UInt_t fgDrawQuality;
00937 
00938    static UInt_t fgColorLockCount;
00939 
00940    static Float_t fgPointSize;
00941    static Float_t fgLineWidth;
00942    static Float_t fgPointSizeScale;
00943    static Float_t fgLineWidthScale;
00944 
00945    TGLUtil(const TGLUtil&);            // Not implemented.
00946    TGLUtil& operator=(const TGLUtil&); // Not implemented.
00947 
00948 public:
00949    virtual ~TGLUtil() {}
00950 
00951    // Error checking
00952    static void   CheckError(const char * loc);
00953 
00954    // Polygon tesselator for direct drawing
00955    static GLUtesselator* GetDrawTesselator3fv();
00956    static GLUtesselator* GetDrawTesselator4fv();
00957    static GLUtesselator* GetDrawTesselator3dv();
00958    static GLUtesselator* GetDrawTesselator4dv();
00959 
00960    // Some simple shape drawing utils
00961    enum ELineHeadShape { kLineHeadNone, kLineHeadArrow, kLineHeadBox };
00962    enum EAxesType      { kAxesNone, kAxesEdge, kAxesOrigin };
00963 
00964    static UInt_t GetDrawQuality();
00965    static void   SetDrawQuality(UInt_t dq);
00966    static void   ResetDrawQuality();
00967    static UInt_t GetDefaultDrawQuality();
00968    static void   SetDefaultDrawQuality(UInt_t dq);
00969 
00970    static UInt_t LockColor();
00971    static UInt_t UnlockColor();
00972    static Bool_t IsColorLocked();
00973 
00974    static void Color(const TGLColor& color);
00975    static void ColorAlpha(const TGLColor& color, UChar_t alpha);
00976    static void ColorAlpha(const TGLColor& color, Float_t alpha);
00977    static void ColorAlpha(Color_t color_index, Float_t alpha=1);
00978    static void ColorTransparency(Color_t color_index, Char_t transparency=0);
00979    static void Color3ub(UChar_t r, UChar_t g, UChar_t b);
00980    static void Color4ub(UChar_t r, UChar_t g, UChar_t b, UChar_t a);
00981    static void Color3ubv(const UChar_t* rgb);
00982    static void Color4ubv(const UChar_t* rgba);
00983    static void Color3f(Float_t r, Float_t g, Float_t b);
00984    static void Color4f(Float_t r, Float_t g, Float_t b, Float_t a);
00985    static void Color3fv(const Float_t* rgb);
00986    static void Color4fv(const Float_t* rgba);
00987 
00988    static Float_t GetPointSizeScale();
00989    static void    SetPointSizeScale(Float_t scale);
00990    static Float_t GetLineWidthScale();
00991    static void    SetLineWidthScale(Float_t scale);
00992 
00993    static void    PointSize(Float_t point_size);
00994    static void    LineWidth(Float_t line_width);
00995 
00996    static Float_t PointSize();
00997    static Float_t LineWidth();
00998 
00999    static void BeginExtendPickRegion(Float_t scale);
01000    static void EndExtendPickRegion();
01001 
01002    static void RenderPolyMarkers(const TAttMarker& marker, Char_t transp,
01003                                  Float_t* p, Int_t n,
01004                                  Int_t pick_radius=0, Bool_t selection=kFALSE,
01005                                  Bool_t sec_selection=kFALSE);
01006 
01007    static void RenderPoints(const TAttMarker& marker,
01008                             Float_t* p, Int_t n,
01009                             Int_t pick_radius=0, Bool_t selection=kFALSE,
01010                             Bool_t sec_selection=kFALSE);
01011 
01012    static void RenderCrosses(const TAttMarker& marker,
01013                              Float_t* p, Int_t n,
01014                              Bool_t sec_selection=kFALSE);
01015 
01016    static void RenderPolyLine(const TAttLine& aline, Char_t transp,
01017                               Float_t* p, Int_t n,
01018                               Int_t pick_radius=0, Bool_t selection=kFALSE);
01019 
01020    static void BeginAttLine(const TAttLine& aline, Char_t transp,
01021                             Int_t pick_radius=0, Bool_t selection=kFALSE);
01022    static void EndAttLine(Int_t pick_radius=0, Bool_t selection=kFALSE);
01023 
01024    // TODO: These draw routines should take LOD hints
01025    static void SetDrawColors(const UChar_t rgba[4]);
01026    static void DrawSphere(const TGLVertex3 & position, Double_t radius, const UChar_t rgba[4]);
01027    static void DrawLine(const TGLLine3 & line, ELineHeadShape head, Double_t size, const UChar_t rgba[4]);
01028    static void DrawLine(const TGLVertex3 & start, const TGLVector3 & vector, ELineHeadShape head,
01029                         Double_t size, const UChar_t rgba[4]);
01030    static void DrawRing(const TGLVertex3 & center, const TGLVector3 & normal,
01031                         Double_t radius, const UChar_t* rgba);
01032 
01033    static void DrawReferenceMarker(const TGLCamera  & camera,
01034                                    const TGLVertex3 & pos,
01035                                          Float_t      radius = 3,
01036                                    const UChar_t    * rgba   = 0);
01037    static void DrawSimpleAxes(const TGLCamera      & camera,
01038                               const TGLBoundingBox & bbox,
01039                                     Int_t            axesType);
01040    static void DrawNumber(const TString    & num,
01041                           const TGLVertex3 & pos,
01042                                 Bool_t       center = kFALSE);
01043 
01044    // Frequently used colors.
01045    static const UChar_t fgRed[4];
01046    static const UChar_t fgGreen[4];
01047    static const UChar_t fgBlue[4];
01048    static const UChar_t fgYellow[4];
01049    static const UChar_t fgWhite[4];
01050    static const UChar_t fgGrey[4];
01051 
01052    ClassDef(TGLUtil,0); // Wrapper class for misc GL pieces
01053 };
01054 
01055 /**************************************************************************/
01056 
01057 class TGLCapabilitySwitch
01058 {
01059 private:
01060    TGLCapabilitySwitch(const TGLCapabilitySwitch &);
01061    TGLCapabilitySwitch &operator = (const TGLCapabilitySwitch &);
01062 
01063    Int_t    fWhat;
01064    Bool_t   fState;
01065    Bool_t   fFlip;
01066 
01067    void SetState(Bool_t s);
01068 
01069 public:
01070    TGLCapabilitySwitch(Int_t what, Bool_t state);
01071    ~TGLCapabilitySwitch();
01072 };
01073 
01074 class TGLCapabilityEnabler
01075 {
01076 private:
01077    TGLCapabilityEnabler(const TGLCapabilityEnabler &);
01078    TGLCapabilityEnabler &operator = (const TGLCapabilityEnabler &);
01079 
01080    Int_t    fWhat;
01081    Bool_t   fFlip;
01082 
01083 public:
01084    TGLCapabilityEnabler(Int_t what, Bool_t state);
01085    ~TGLCapabilityEnabler();
01086 };
01087 
01088 class TGLFloatHolder
01089 {
01090    TGLFloatHolder(const TGLFloatHolder&);            // Not implemented
01091    TGLFloatHolder& operator=(const TGLFloatHolder&); // Not implemented
01092 
01093    Int_t    fWhat;
01094    Float_t  fState;
01095    Bool_t   fFlip;
01096    void   (*fFoo)(Float_t);
01097 
01098 public:
01099    TGLFloatHolder(Int_t what, Float_t state, void (*foo)(Float_t));
01100    ~TGLFloatHolder();
01101 };
01102 
01103 class TGLEnableGuard {
01104 private:
01105    Int_t fCap;
01106 
01107 public:
01108    TGLEnableGuard(Int_t cap);
01109    ~TGLEnableGuard();
01110 
01111 private:
01112    TGLEnableGuard(const TGLEnableGuard &);
01113    TGLEnableGuard &operator = (const TGLEnableGuard &);
01114 };
01115 
01116 class TGLDisableGuard {
01117 private:
01118    Int_t fCap;
01119 
01120 public:
01121    TGLDisableGuard(Int_t cap);
01122    ~TGLDisableGuard();
01123 
01124 private:
01125    TGLDisableGuard(const TGLDisableGuard &);
01126    TGLDisableGuard &operator = (const TGLDisableGuard &);
01127 };
01128 
01129 class TGLSelectionBuffer {
01130    std::vector<UChar_t> fBuffer;
01131    Int_t                fWidth;
01132    Int_t                fHeight;
01133 
01134 public:
01135    TGLSelectionBuffer();
01136    virtual ~TGLSelectionBuffer();
01137 
01138    void           ReadColorBuffer(Int_t width, Int_t height);
01139    void           ReadColorBuffer(Int_t x, Int_t y, Int_t width, Int_t height);
01140    const UChar_t *GetPixelColor(Int_t px, Int_t py)const;
01141 
01142 private:
01143    TGLSelectionBuffer(const TGLSelectionBuffer &);
01144    TGLSelectionBuffer &operator = (const TGLSelectionBuffer &);
01145 
01146    ClassDef(TGLSelectionBuffer, 0); //Holds color buffer content for selection
01147 };
01148 
01149 template<class T>
01150 class TGL2DArray : public std::vector<T> {
01151 private:
01152    Int_t fRowLen;
01153    Int_t fMaxRow;
01154    typedef typename std::vector<T>::size_type size_type;
01155 
01156 public:
01157    TGL2DArray() : fRowLen(0), fMaxRow(0){}
01158    void SetMaxRow(Int_t max)
01159    {
01160       fMaxRow = max;
01161    }
01162    void SetRowLen(Int_t len)
01163    {
01164       fRowLen = len;
01165    }
01166    const T *operator [] (size_type ind)const
01167    {
01168       return &std::vector<T>::operator [](ind * fRowLen);
01169    }
01170    T *operator [] (size_type ind)
01171    {
01172       return &std::vector<T>::operator [] (ind * fRowLen);
01173    }
01174 };
01175 
01176 class TGLPlotCoordinates;
01177 class TGLQuadric;
01178 class TAxis;
01179 
01180 namespace Rgl {
01181 
01182 extern const Float_t gRedEmission[];
01183 extern const Float_t gGreenEmission[];
01184 extern const Float_t gBlueEmission[];
01185 extern const Float_t gOrangeEmission[];
01186 extern const Float_t gWhiteEmission[];
01187 extern const Float_t gGrayEmission[];
01188 extern const Float_t gNullEmission[];
01189 
01190 typedef std::pair<Int_t, Int_t> BinRange_t;
01191 typedef std::pair<Double_t, Double_t> Range_t;
01192 
01193 void ObjectIDToColor(Int_t objectID, Bool_t highColor);
01194 Int_t ColorToObjectID(const UChar_t *color, Bool_t highColor);
01195 void DrawQuadOutline(const TGLVertex3 &v1, const TGLVertex3 &v2,
01196                      const TGLVertex3 &v3, const TGLVertex3 &v4);
01197 void DrawQuadFilled(const TGLVertex3 &v0, const TGLVertex3 &v1,
01198                     const TGLVertex3 &v2, const TGLVertex3 &v3,
01199                     const TGLVector3 &normal);
01200 void DrawQuadFilled(const Double_t *v0, const Double_t *v1,
01201                     const Double_t *v2, const Double_t *v3,
01202                     const Double_t *normal);
01203 
01204 void DrawSmoothFace(const TGLVertex3 &v1, const TGLVertex3 &v2,
01205                      const TGLVertex3 &v3, const TGLVector3 &norm1,
01206                      const TGLVector3 &norm2, const TGLVector3 &norm3);
01207 void DrawBoxFront(Double_t xMin, Double_t xMax, Double_t yMin, Double_t yMax,
01208                   Double_t zMin, Double_t zMax, Int_t fp);
01209 
01210 void DrawBoxFrontTextured(Double_t xMin, Double_t xMax, Double_t yMin,
01211                           Double_t yMax, Double_t zMin, Double_t zMax,
01212                           Double_t tMin, Double_t tMax, Int_t front);
01213 
01214 #ifndef __CINT__
01215 void DrawTrapezoidTextured(const Double_t ver[][2], Double_t zMin, Double_t zMax,
01216                            Double_t tMin, Double_t tMax);
01217 void DrawTrapezoidTextured(const Double_t ver[][3], Double_t texMin, Double_t texMax);
01218 void DrawTrapezoidTextured2(const Double_t ver[][2], Double_t zMin, Double_t zMax,
01219                             Double_t tMin, Double_t tMax);
01220 #endif
01221 
01222 void DrawCylinder(TGLQuadric *quadric, Double_t xMin, Double_t xMax, Double_t yMin,
01223                   Double_t yMax, Double_t zMin, Double_t zMax);
01224 void DrawSphere(TGLQuadric *quadric, Double_t xMin, Double_t xMax, Double_t yMin,
01225                 Double_t yMax, Double_t zMin, Double_t zMax);
01226 void DrawError(Double_t xMin, Double_t xMax, Double_t yMin,
01227                Double_t yMax, Double_t zMin, Double_t zMax);
01228 
01229 #ifndef __CINT__
01230 void DrawTrapezoid(const Double_t ver[][2], Double_t zMin, Double_t zMax, Bool_t color = kTRUE);
01231 void DrawTrapezoid(const Double_t ver[][3]);
01232 #endif
01233 
01234 void DrawAxes(Int_t frontPoint, const Int_t *viewport, const TGLVertex3 *box2D,
01235               const TGLPlotCoordinates *plotCoord, TAxis *xAxis, TAxis *yAxis,
01236               TAxis *zAxis);
01237 void SetZLevels(TAxis *zAxis, Double_t zMin, Double_t zMax,
01238                 Double_t zScale, std::vector<Double_t> &zLevels);
01239 
01240 void DrawFaceTextured(const TGLVertex3 &v1, const TGLVertex3 &v2, const TGLVertex3 &v3,
01241                       Double_t t1, Double_t t2, Double_t t3, const TGLVector3 &norm1,
01242                       const TGLVector3 &norm2, const TGLVector3 &norm3);
01243 void DrawFaceTextured(const TGLVertex3 &v1, const TGLVertex3 &v2, const TGLVertex3 &v3,
01244                       Double_t t1, Double_t t2, Double_t t3, Double_t z, const TGLVector3 &planeNormal);
01245 void GetColor(Float_t v, Float_t vmin, Float_t vmax, Int_t type, Float_t *rgba);
01246 
01247 class TGuardBase {
01248 private:
01249    mutable Bool_t fActive;
01250 
01251    TGuardBase &operator = (const TGuardBase &rhs);
01252 protected:
01253    TGuardBase()
01254       : fActive(kTRUE)
01255    {
01256    }
01257    TGuardBase(const TGuardBase &rhs)
01258       : fActive(kTRUE)
01259    {
01260       rhs.fActive = kFALSE;
01261    }
01262 
01263    Bool_t IsActive()const
01264    {
01265       return fActive;
01266    }
01267 
01268 public:
01269    void Stop()const
01270    {
01271       fActive = kFALSE;
01272    }
01273 };
01274 
01275 template<class Func, class Arg>
01276 class TOneArgGuard : public TGuardBase {
01277 private:
01278    Func fFunc;
01279    Arg  fArg;
01280 public:
01281    TOneArgGuard(Func f, Arg a)
01282       : fFunc(f), fArg(a)
01283    {
01284    }
01285    ~TOneArgGuard()
01286    {
01287       if (IsActive())
01288          fFunc(fArg);
01289    }
01290 };
01291 
01292 template<class Func, class Arg1, class Arg2>
01293 class TTwoArgsGuard : public TGuardBase {
01294 private:
01295    Func fFunc;
01296    Arg1 fArg1;
01297    Arg2 fArg2;
01298 
01299 public:
01300    TTwoArgsGuard(Func f, Arg1 a1, Arg2 a2)
01301       : fFunc(f), fArg1(a1), fArg2(a2)
01302    {
01303    }
01304    ~TTwoArgsGuard()
01305    {
01306       if (IsActive())
01307          fFunc(fArg1, fArg2);
01308    }
01309 };
01310 
01311 template<class Func, class Arg>
01312 TOneArgGuard<Func, Arg> make_guard(Func f, Arg a)
01313 {
01314    return TOneArgGuard<Func, Arg>(f, a);
01315 }
01316 
01317 template<class Func, class Arg1, class Arg2>
01318 TTwoArgsGuard<Func, Arg1, Arg2> make_guard(Func f, Arg1 a1, Arg2 a2)
01319 {
01320    return TTwoArgsGuard<Func, Arg1, Arg2>(f, a1, a2);
01321 }
01322 
01323 }//namespace Rgl.
01324 
01325 class TGLLevelPalette {
01326 private:
01327    std::vector<UChar_t>         fTexels;
01328    const std::vector<Double_t> *fContours;
01329    UInt_t                       fPaletteSize;
01330    mutable UInt_t               fTexture;
01331    Int_t                        fMaxPaletteSize;
01332    Rgl::Range_t                 fZRange;
01333 
01334    TGLLevelPalette(const TGLLevelPalette&);    // Not implemented
01335    TGLLevelPalette& operator=(const TGLLevelPalette&);  // Not implemented
01336 
01337 public:
01338    TGLLevelPalette();
01339 
01340    Bool_t GeneratePalette(UInt_t paletteSize, const Rgl::Range_t &zRange, Bool_t checkSize = kTRUE);
01341 
01342    void   SetContours(const std::vector<Double_t> *contours);
01343 
01344    void   EnableTexture(Int_t mode)const;
01345    void   DisableTexture()const;
01346 
01347    Int_t  GetPaletteSize()const;
01348 
01349    Double_t       GetTexCoord(Double_t z)const;
01350 
01351    const UChar_t *GetColour(Double_t z)const;
01352    const UChar_t *GetColour(Int_t ind)const;
01353 };
01354 
01355 #endif // ROOT_TGLUtil

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