Logo ROOT   6.12/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 #include "RStipples.h"
19 #include "TPoint.h"
20 #include "Rtypes.h"
21 
22 class TGLPadPainter;//For friend declarations.
23 
24 /*
25 
26 All code here and in corresponding *.cxx file is only
27 for TGLPadPainter. So, it can be limited or wrong
28 for something else, but it's OK for TGLPadPainter.
29 
30 */
31 
32 namespace Rgl {
33 namespace Pad {
34 /*
35 Auxiliary class to converts ROOT's polygon stipples from
36 RStipples.h into GL's stipples and hold them in a fStipples array.
37 */
39  friend class ::TGLPadPainter;
40  friend class FillAttribSet;
41 private:
42  std::vector<unsigned char> fStipples;
43 
44  static const UInt_t fgBitSwap[];
45  static UInt_t SwapBits(UInt_t bits);
46 
47  enum EGeometry {
48  kRowSize = 4,//For gl, stipple is a 32x32 pixel pattern. So, 4 GLubyte objects form a single line of a stipple.
49  kNRows = 32,
50  kStippleSize = kNRows * kRowSize//4 * 32 == 32 lines.
51  };
52 
53  enum EBitMasks {
54  kLow4 = 0xf,
55  kUp4 = 0xf0,
56  k16Bits = 0xff
57  };
58 public:
60 };
61 
62 /*
63 RAII class to enable/disable selected stipple.
64 */
68 public:
69  FillAttribSet(const PolygonStippleSet & set, Bool_t ignoreStipple);
70  ~FillAttribSet();
71 };
72 
73 /*
74 "ROOT like" line stipples.
75 */
76 
77 extern const UShort_t gLineStipples[];
78 extern const UInt_t gMaxStipple;
79 
80 /*
81 Set/unset line attributes.
82 */
84 private:
89 public:
90  LineAttribSet(Bool_t smooth, UInt_t stipple, Double_t maxWidth, Bool_t setWidth);
91  ~LineAttribSet();
92 };
93 
94 /*
95 Marker painter. Most markers can be painted by standlone functions.
96 For circles, it can be usefull to precalculate the marker geometry
97 and use it for poly-markers.
98 */
99 /*
100 Marker painter. Most markers can be painted by standlone functions.
101 For circles, it can be usefull to precalculate the marker geometry
102 and use it for poly-markers.
103 */
105 private:
106  //Different TArrMarker styles.
107  mutable TPoint fStar[8];
108  mutable TPoint fCross[4];
109 
110  mutable std::vector<TPoint> fCircle;
111 
112  enum {
113  kSmallCirclePts = 80,
114  kLargeCirclePts = 150
115  };
116 
117 public:
118  //Each function draw n markers.
119  void DrawDot(UInt_t n, const TPoint *xy)const;
120  void DrawPlus(UInt_t n, const TPoint *xy)const;
121  void DrawStar(UInt_t n, const TPoint *xy)const;
122  void DrawX(UInt_t n, const TPoint *xy)const;
123  void DrawFullDotSmall(UInt_t n, const TPoint *xy)const;
124  void DrawFullDotMedium(UInt_t n, const TPoint *xy)const;
125 
126  void DrawCircle(UInt_t n, const TPoint *xy)const;
127  void DrawFullDotLarge(UInt_t n, const TPoint *xy)const;
128 
129  void DrawFullSquare(UInt_t n, const TPoint *xy)const;
130  void DrawFullTrianlgeUp(UInt_t n, const TPoint *xy)const;
131  void DrawFullTrianlgeDown(UInt_t n, const TPoint *xy)const;
132  void DrawDiamond(UInt_t n, const TPoint *xy)const;
133  void DrawFullDiamond(UInt_t n, const TPoint *xy)const;
134  void DrawOpenTrianlgeDown(UInt_t n, const TPoint *xy)const;
135  void DrawFullCross(UInt_t n, const TPoint *xy)const;
136  void DrawOpenCross(UInt_t n, const TPoint *xy)const;
137  void DrawFullStar(UInt_t n, const TPoint *xy)const;
138  void DrawOpenStar(UInt_t n, const TPoint *xy)const;
139  void DrawOpenSquareDiagonal(UInt_t n, const TPoint *xy)const;
140  void DrawOpenDiamondCross(UInt_t n, const TPoint *xy)const;
141  void DrawOpenThreeTriangles(UInt_t n, const TPoint *xy)const;
142  void DrawOctagonCross(UInt_t n, const TPoint *xy)const;
143  void DrawFullThreeTriangles(UInt_t n, const TPoint *xy)const;
144  void DrawOpenFourTrianglesX(UInt_t n, const TPoint *xy)const;
145  void DrawFullFourTrianglesX(UInt_t n, const TPoint *xy)const;
146  void DrawOpenDoubleDiamond(UInt_t n, const TPoint *xy)const;
147  void DrawFullDoubleDiamond(UInt_t n, const TPoint *xy)const;
148  void DrawOpenFourTrianglesPlus(UInt_t n, const TPoint *xy)const;
149  void DrawFullFourTrianglesPlus(UInt_t n, const TPoint *xy)const;
150  void DrawOpenCrossX(UInt_t n, const TPoint *xy)const;
151  void DrawFullCrossX(UInt_t n, const TPoint *xy)const;
152  void DrawFourSquaresX(UInt_t n, const TPoint *xy)const;
153  void DrawFourSquaresPlus(UInt_t n, const TPoint *xy)const;
154 };
155 
156 //
157 // OpenGL's tesselator calls callback functions glBegin(MODE), glVertex3(v), glEnd(),
158 // where v can be new vertex (or existing) and MODE is a type of mesh patch.
159 // MeshPatch_t is a class to save such a tesselation
160 // (instead of using glVertex and glBegin to draw.
161 //
162 struct MeshPatch_t {
163  MeshPatch_t(Int_t type) : fPatchType(type)
164  {}
165 
166  Int_t fPatchType; //GL_QUADS, GL_QUAD_STRIP, etc.
167  std::vector<Double_t> fPatch; //vertices.
168 };
169 
170 typedef std::list<MeshPatch_t> Tesselation_t;
171 
172 class Tesselator {
173 
174 
175 public:
176  Tesselator(Bool_t dump = kFALSE);
177 
178  ~Tesselator();
179 
180  void *GetTess()const
181  {
182  return fTess;
183  }
184 
185  static void SetDump(Tesselation_t *t)
186  {
187  fVs = t;
188  }
189 
190  static Tesselation_t *GetDump()
191  {
192  return fVs;
193  }
194 
195 private:
196 
197  void *fTess;
198 
199  static Tesselation_t *fVs;//the current tesselator's dump.
200 };
201 
202 /*
203 In future, this should be an interface to per-pad FBO.
204 Currently, in only save sizes and coordinates (?)
205 */
207  friend class ::TGLPadPainter;
208 public:
210 
211 private:
217 };
218 
219 void ExtractRGBA(Color_t colorIndex, Float_t *rgba);
220 
221 class GLLimits {
222 public:
223  GLLimits();
224 
225  Double_t GetMaxLineWidth()const;
226  Double_t GetMaxPointSize()const;
227 private:
230 };
231 
232 //We have a lot of Rect_t/Point_t/TGLRect/TGLBoundingBox blah-blah-blah.
233 //What we do not have is a rectangle with floating point types.
234 
235 template<class ValueType>
236 struct BoundingRect {
237  ValueType fXMin = ValueType();
238  ValueType fYMin = ValueType();
239  ValueType fWidth = ValueType();
240  ValueType fHeight = ValueType();
241  //Sometimes it's more convenient:
242  ValueType fXMax = ValueType();
243  ValueType fYMax = ValueType();
244 };
245 
246 //It's explicitly instantiated for signed integer/fp types (in *.cxx).
247 template<class ValueType>
248 BoundingRect<ValueType> FindBoundingRect(Int_t nPoints, const ValueType *xs, const ValueType *ys);
249 
250 
251 }//namespace Pad
252 }//namespace Rgl
253 
254 #endif
std::vector< Double_t > fPatch
Definition: TGLPadUtils.h:167
static UInt_t SwapBits(UInt_t bits)
std::vector< TPoint > fCircle
Definition: TGLPadUtils.h:110
Double_t fMaxPointSize
Definition: TGLPadUtils.h:229
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
Double_t fMaxLineWidth
Definition: TGLPadUtils.h:228
void * GetTess() const
Definition: TGLPadUtils.h:180
Double_t x[n]
Definition: legend1.C:17
void ExtractRGBA(Color_t colorIndex, Float_t *rgba)
std::vector< unsigned char > fStipples
Definition: TGLPadUtils.h:42
const UInt_t gMaxStipple
static void SetDump(Tesselation_t *t)
Definition: TGLPadUtils.h:185
short Color_t
Definition: RtypesCore.h:79
Definition: TPoint.h:31
std::list< MeshPatch_t > Tesselation_t
Definition: TGLPadUtils.h:170
XPoint xy[kMAXMK]
Definition: TGX11.cxx:122
"Delegating" part of TGLPadPainter.
Definition: TGLPadPainter.h:28
const UShort_t gLineStipples[]
unsigned int UInt_t
Definition: RtypesCore.h:42
static Tesselation_t * fVs
Definition: TGLPadUtils.h:199
const Bool_t kFALSE
Definition: RtypesCore.h:88
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:190
static const UInt_t fgBitSwap[]
Definition: TGLPadUtils.h:44
BoundingRect< ValueType > FindBoundingRect(Int_t nPoints, const ValueType *xs, const ValueType *ys)
MeshPatch_t(Int_t type)
Definition: TGLPadUtils.h:163
const Int_t n
Definition: legend1.C:16