Logo ROOT   6.08/07
Reference Guide
TGLPadUtils.h
Go to the documentation of this file.
1 // @(#)root/gl:$Id$
2 // Author: Timur Pocheptsov 06/05/2009
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2009, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TGLPadUtils
13 #define ROOT_TGLPadUtils
14 
15 #include <vector>
16 #include <list>
17 
18 #ifndef ROOT_RStipples
19 #include "RStipples.h"
20 #endif
21 #ifndef ROOT_TPoint
22 #include "TPoint.h"
23 #endif
24 #ifndef ROOT_Rtypes
25 #include "Rtypes.h"
26 #endif
27 
28 class TGLPadPainter;//For friend declarations.
29 
30 /*
31 
32 All code here and in corresponding *.cxx file is only
33 for TGLPadPainter. So, it can be limited or wrong
34 for something else, but it's OK for TGLPadPainter.
35 
36 */
37 
38 namespace Rgl {
39 namespace Pad {
40 /*
41 Auxiliary class to converts ROOT's polygon stipples from
42 RStipples.h into GL's stipples and hold them in a fStipples array.
43 */
45  friend class ::TGLPadPainter;
46  friend class FillAttribSet;
47 private:
48  std::vector<unsigned char> fStipples;
49 
50  static const UInt_t fgBitSwap[];
51  static UInt_t SwapBits(UInt_t bits);
52 
53  enum EGeometry {
54  kRowSize = 4,//For gl, stipple is a 32x32 pixel pattern. So, 4 GLubyte objects form a single line of a stipple.
55  kNRows = 32,
56  kStippleSize = kNRows * kRowSize//4 * 32 == 32 lines.
57  };
58 
59  enum EBitMasks {
60  kLow4 = 0xf,
61  kUp4 = 0xf0,
62  k16Bits = 0xff
63  };
64 public:
66 };
67 
68 /*
69 RAII class to enable/disable selected stipple.
70 */
74 public:
75  FillAttribSet(const PolygonStippleSet & set, Bool_t ignoreStipple);
76  ~FillAttribSet();
77 };
78 
79 /*
80 "ROOT like" line stipples.
81 */
82 
83 extern const UShort_t gLineStipples[];
84 extern const UInt_t gMaxStipple;
85 
86 /*
87 Set/unset line attributes.
88 */
90 private:
95 public:
96  LineAttribSet(Bool_t smooth, UInt_t stipple, Double_t maxWidth, Bool_t setWidth);
97  ~LineAttribSet();
98 };
99 
100 /*
101 Marker painter. Most markers can be painted by standlone functions.
102 For circles, it can be usefull to precalculate the marker geometry
103 and use it for poly-markers.
104 */
105 /*
106 Marker painter. Most markers can be painted by standlone functions.
107 For circles, it can be usefull to precalculate the marker geometry
108 and use it for poly-markers.
109 */
111 private:
112  //Different TArrMarker styles.
113  mutable TPoint fStar[8];
114  mutable TPoint fCross[4];
115 
116  mutable std::vector<TPoint> fCircle;
117 
118  enum {
119  kSmallCirclePts = 80,
120  kLargeCirclePts = 150
121  };
122 
123 public:
124  //Each function draw n markers.
125  void DrawDot(UInt_t n, const TPoint *xy)const;
126  void DrawPlus(UInt_t n, const TPoint *xy)const;
127  void DrawStar(UInt_t n, const TPoint *xy)const;
128  void DrawX(UInt_t n, const TPoint *xy)const;
129  void DrawFullDotSmall(UInt_t n, const TPoint *xy)const;
130  void DrawFullDotMedium(UInt_t n, const TPoint *xy)const;
131 
132  void DrawCircle(UInt_t n, const TPoint *xy)const;
133  void DrawFullDotLarge(UInt_t n, const TPoint *xy)const;
134 
135  void DrawFullSquare(UInt_t n, const TPoint *xy)const;
136  void DrawFullTrianlgeUp(UInt_t n, const TPoint *xy)const;
137  void DrawFullTrianlgeDown(UInt_t n, const TPoint *xy)const;
138  void DrawDiamond(UInt_t n, const TPoint *xy)const;
139  void DrawCross(UInt_t n, const TPoint *xy)const;
140  void DrawFullStar(UInt_t n, const TPoint *xy)const;
141  void DrawOpenStar(UInt_t n, const TPoint *xy)const;
142 
143 };
144 
145 //
146 // OpenGL's tesselator calls callback functions glBegin(MODE), glVertex3(v), glEnd(),
147 // where v can be new vertex (or existing) and MODE is a type of mesh patch.
148 // MeshPatch_t is a class to save such a tesselation
149 // (instead of using glVertex and glBegin to draw.
150 //
151 struct MeshPatch_t {
152  MeshPatch_t(Int_t type) : fPatchType(type)
153  {}
154 
155  Int_t fPatchType; //GL_QUADS, GL_QUAD_STRIP, etc.
156  std::vector<Double_t> fPatch; //vertices.
157 };
158 
159 typedef std::list<MeshPatch_t> Tesselation_t;
160 
161 class Tesselator {
162 
163 
164 public:
165  Tesselator(Bool_t dump = kFALSE);
166 
167  ~Tesselator();
168 
169  void *GetTess()const
170  {
171  return fTess;
172  }
173 
174  static void SetDump(Tesselation_t *t)
175  {
176  fVs = t;
177  }
178 
179  static Tesselation_t *GetDump()
180  {
181  return fVs;
182  }
183 
184 private:
185 
186  void *fTess;
187 
188  static Tesselation_t *fVs;//the current tesselator's dump.
189 };
190 
191 /*
192 In future, this should be an interface to per-pad FBO.
193 Currently, in only save sizes and coordinates (?)
194 */
196  friend class ::TGLPadPainter;
197 public:
199 
200 private:
206 };
207 
208 void ExtractRGBA(Color_t colorIndex, Float_t *rgba);
209 
210 class GLLimits {
211 public:
212  GLLimits();
213 
214  Double_t GetMaxLineWidth()const;
215  Double_t GetMaxPointSize()const;
216 private:
219 };
220 
221 //We have a lot of Rect_t/Point_t/TGLRect/TGLBoundingBox blah-blah-blah.
222 //What we do not have is a rectangle with floating point types.
223 
224 template<class ValueType>
225 struct BoundingRect {
226  ValueType fXMin = ValueType();
227  ValueType fYMin = ValueType();
228  ValueType fWidth = ValueType();
229  ValueType fHeight = ValueType();
230  //Sometimes it's more convenient:
231  ValueType fXMax = ValueType();
232  ValueType fYMax = ValueType();
233 };
234 
235 //It's explicitly instantiated for signed integer/fp types (in *.cxx).
236 template<class ValueType>
237 BoundingRect<ValueType> FindBoundingRect(Int_t nPoints, const ValueType *xs, const ValueType *ys);
238 
239 
240 }//namespace Pad
241 }//namespace Rgl
242 
243 #endif
std::vector< Double_t > fPatch
Definition: TGLPadUtils.h:156
static UInt_t SwapBits(UInt_t bits)
std::vector< TPoint > fCircle
Definition: TGLPadUtils.h:116
Double_t fMaxPointSize
Definition: TGLPadUtils.h:218
float Float_t
Definition: RtypesCore.h:53
unsigned short UShort_t
Definition: RtypesCore.h:36
TH1 * h
Definition: legend2.C:5
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
Double_t fMaxLineWidth
Definition: TGLPadUtils.h:217
void * GetTess() const
Definition: TGLPadUtils.h:169
Double_t x[n]
Definition: legend1.C:17
void ExtractRGBA(Color_t colorIndex, Float_t *rgba)
std::vector< unsigned char > fStipples
Definition: TGLPadUtils.h:48
const UInt_t gMaxStipple
static void SetDump(Tesselation_t *t)
Definition: TGLPadUtils.h:174
short Color_t
Definition: RtypesCore.h:79
Definition: TPoint.h:33
std::list< MeshPatch_t > Tesselation_t
Definition: TGLPadUtils.h:159
XPoint xy[kMAXMK]
Definition: TGX11.cxx:122
"Delegating" part of TGLPadPainter.
Definition: TGLPadPainter.h:36
const UShort_t gLineStipples[]
unsigned int UInt_t
Definition: RtypesCore.h:42
static Tesselation_t * fVs
Definition: TGLPadUtils.h:188
double Double_t
Definition: RtypesCore.h:55
int type
Definition: TGX11.cxx:120
Double_t y[n]
Definition: legend1.C:17
static Tesselation_t * GetDump()
Definition: TGLPadUtils.h:179
static const UInt_t fgBitSwap[]
Definition: TGLPadUtils.h:50
BoundingRect< ValueType > FindBoundingRect(Int_t nPoints, const ValueType *xs, const ValueType *ys)
MeshPatch_t(Int_t type)
Definition: TGLPadUtils.h:152
const Int_t n
Definition: legend1.C:16