Logo ROOT  
Reference Guide
TAttMarker.cxx
Go to the documentation of this file.
1// @(#)root/base:$Id$
2// Author: Rene Brun 12/05/95
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, 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#include "Riostream.h"
13#include "Strlen.h"
14#include "TAttMarker.h"
15#include "TVirtualPad.h"
16#include "TStyle.h"
17#include "TVirtualX.h"
18#include "TVirtualPadEditor.h"
19#include "TColor.h"
20
22
23/** \class TAttMarker
24\ingroup Base
25\ingroup GraphicsAtt
26
27Marker Attributes class.
28
29This class is used (in general by secondary inheritance)
30by many other classes (graphics, histograms). It holds all the markers
31attributes.
32
33## Marker attributes
34The marker attributes are:
35
36 - [Marker color](#M1)
37 - [Marker style](#M2)
38 - [Marker line width](#M21)
39 - [Marker size](#M3)
40
41## <a name="M1"></a> Marker color
42The marker color is a color index (integer) pointing in the ROOT color
43table.
44The marker color of any class inheriting from `TAttMarker` can
45be changed using the method `SetMarkerColor` and retrieved using the
46method `GetMarkerColor`.
47The following table shows the first 50 default colors.
48
49Begin_Macro
50{
51 TCanvas *c = new TCanvas("c","Fill Area colors",0,0,500,200);
52 c->DrawColorTable();
53 return c;
54}
55End_Macro
56
57### Color transparency
58
59`SetMarkerColorAlpha()`, allows to set a transparent color.
60In the following example the marker color of the histogram `histo`
61is set to blue with a transparency of 35%. The color `kBlue`
62itself remains fully opaque.
63
64~~~ {.cpp}
65histo->SetMarkerColorAlpha(kBlue, 0.35);
66~~~
67
68The transparency is available on all platforms when the flag `OpenGL.CanvasPreferGL` is set to `1`
69in `$ROOTSYS/etc/system.rootrc`, or on Mac with the Cocoa backend. On the file output
70it is visible with PDF, PNG, Gif, JPEG, SVG, TeX ... but not PostScript.
71
72## <a name="M2"></a> Marker style
73
74The Marker style defines the markers' shape.
75The marker style of any class inheriting from `TAttMarker` can
76be changed using the method `SetMarkerStyle` and retrieved using the
77method `GetMarkerStyle`.
78
79The following list gives the currently supported markers (screen
80and PostScript) style. Each marker style is identified by an integer number
81(first column) corresponding to a marker shape (second column) and can be also
82accessed via a global name (third column).
83
84~~~ {.cpp}
85 Marker number Marker shape Marker name
86 1 dot kDot
87 2 + kPlus
88 3 * kStar
89 4 o kCircle
90 5 x kMultiply
91 6 small dot kFullDotSmall
92 7 medium dot kFullDotMedium
93 8 large scalable dot kFullDotLarge
94 9 -->19 large scalable dot
95 20 full circle kFullCircle
96 21 full square kFullSquare
97 22 full triangle up kFullTriangleUp
98 23 full triangle down kFullTriangleDown
99 24 open circle kOpenCircle
100 25 open square kOpenSquare
101 26 open triangle up kOpenTriangleUp
102 27 open diamond kOpenDiamond
103 28 open cross kOpenCross
104 29 full star kFullStar
105 30 open star kOpenStar
106 31 *
107 32 open triangle down kOpenTriangleDown
108 33 full diamond kFullDiamond
109 34 full cross kFullCross
110 35 open diamond cross kOpenDiamondCross
111 36 open square diagonal kOpenSquareDiagonal
112 37 open three triangle kOpenThreeTriangles
113 38 octagon with cross kOctagonCross
114 39 full three trangles kFullThreeTriangles
115 40 open four triangleX kOpenFourTrianglesX
116 41 full four triangleX kFullFourTrianglesX
117 42 open double diamond kOpenDoubleDiamond
118 43 full double diamond kFullDoubleDiamond
119 44 open four triangle+ kOpenFourTrianglesPlus
120 45 full four triangle+ kFullFourTrianglesPlus
121 46 open cross X kOpenCrossX
122 47 full cross X kFullCrossX
123 48 four squares X kFourSquaresX
124 49 four squares+ kFourSquaresPlus
125~~~
126
127Begin_Macro
128{
129 TCanvas *c = new TCanvas("c","Marker types",0,0,500,200);
130 TMarker marker;
131 marker.DisplayMarkerTypes();
132}
133End_Macro
134
135### <a name="M21"></a> Marker line width
136
137The line width of a marker is not actually a marker attribute since it does
138only apply to open marker symbols and marker symbols consisting of lines. All
139of these marker symbols are redefined with thicker lines by style numbers
140starting from 50:
141
142~~~ {.cpp}
143 Marker numbers Line width
144 50 - 67 2
145 68 - 85 3
146 86 - 103 4
147 104 - 121 5
148 ...
149~~~
150
151Begin_Macro
152{
153 TCanvas *c = new TCanvas("c","Marker line widths",0,0,600,266);
154 TMarker marker;
155 marker.DisplayMarkerLineWidths();
156}
157End_Macro
158
159## <a name="M3"></a> Marker size
160
161Various marker sizes are shown in the figure below. The default marker size=1
162is shown in the top left corner. Marker sizes smaller than 1 can be
163specified. The marker size does not refer to any coordinate systems, it is an
164absolute value. Therefore the marker size is not affected by any change
165in TPad's scale. A marker size equal to 1 correspond to 8 pixels.
166That is, a square marker with size 1 will be drawn with a side equal to 8
167pixels on the screen.
168
169The marker size of any class inheriting from `TAttMarker` can
170be changed using the method `SetMarkerSize` and retrieved using the
171method `GetMarkerSize`.
172
173Begin_Macro
174{
175 c = new TCanvas("c","Marker sizes",0,0,500,200);
176 TMarker marker;
177 marker.SetMarkerStyle(3);
178 Double_t x = 0;
179 Double_t dx = 1/6.0;
180 for (Int_t i=1; i<6; i++) {
181 x += dx;
182 marker.SetMarkerSize(i*0.2); marker.DrawMarker(x,.165);
183 marker.SetMarkerSize(i*0.8); marker.DrawMarker(x,.495);
184 marker.SetMarkerSize(i*1.0); marker.DrawMarker(x,.835);
185 }
186}
187End_Macro
188
189Note that the marker styles number 1 6 and 7 (the dots), cannot be scaled. They
190are meant to be very fast to draw and are always drawn with the same number of
191pixels; therefore `SetMarkerSize` does not apply on them. To have a
192"scalable dot" a filled circle should be used instead, i.e. the marker style
193number 20. By default (if `SetMarkerStyle` is not specified), the marker
194style used is 1. That's the most common one to draw scatter plots.
195*/
196
197////////////////////////////////////////////////////////////////////////////////
198/// TAttMarker default constructor.
199///
200/// Default text attributes are taking from the current style.
201
203{
204 if (!gStyle) {fMarkerColor=1; fMarkerStyle=1; fMarkerSize=1; return;}
208}
209
210////////////////////////////////////////////////////////////////////////////////
211/// TAttMarker normal constructor.
212///
213/// Text attributes are taking from the argument list
214/// - color : Marker Color Index
215/// - style : Marker style (from 1 to 30)
216/// - size : marker size (float)
217
219{
220 fMarkerColor = color;
221 fMarkerSize = msize;
223}
224
225////////////////////////////////////////////////////////////////////////////////
226/// TAttMarker destructor.
227
229{
230}
231
232////////////////////////////////////////////////////////////////////////////////
233/// Copy this marker attributes to a new TAttMarker.
234
235void TAttMarker::Copy(TAttMarker &attmarker) const
236{
237 attmarker.fMarkerColor = fMarkerColor;
238 attmarker.fMarkerStyle = fMarkerStyle;
239 attmarker.fMarkerSize = fMarkerSize;
240}
241
242////////////////////////////////////////////////////////////////////////////////
243/// Internal helper function that returns the corresponding marker style with
244/// line width 1 for the given style.
245
247{
248 if (style <= 49)
249 return style;
250
251 switch ((style - 50) % 18) {
252 case 0:
253 return 2;
254 case 1:
255 return 3;
256 case 2:
257 return 5;
258 case 3:
259 return 24;
260 case 4:
261 return 25;
262 case 5:
263 return 26;
264 case 6:
265 return 27;
266 case 7:
267 return 28;
268 case 8:
269 return 30;
270 case 9:
271 return 32;
272 case 10:
273 return 35;
274 case 11:
275 return 36;
276 case 12:
277 return 37;
278 case 13:
279 return 38;
280 case 14:
281 return 40;
282 case 15:
283 return 42;
284 case 16:
285 return 44;
286 case 17:
287 return 46;
288 default:
289 return style;
290 }
291}
292
293////////////////////////////////////////////////////////////////////////////////
294/// Internal helper function that returns the line width of the given marker
295/// style (0 = filled marker)
296
298{
299 if (style >= 50)
300 return ((style - 50) / 18) + 2;
301 else if (style == 2 || style == 3 || style == 4 || style == 5
302 || style == 24 || style == 25 || style == 26 || style == 27
303 || style == 28 || style == 30 || style == 31 || style == 32
304 || style == 35 || style == 36 || style == 37 || style == 38
305 || style == 40 || style == 42 || style == 44 || style == 46)
306 return 1;
307 else
308 return 0;
309}
310
311////////////////////////////////////////////////////////////////////////////////
312/// Change current marker attributes if necessary.
313
315{
316 if (!gPad) return;
317 if (!gPad->IsBatch()) {
318 gVirtualX->SetMarkerColor(fMarkerColor);
319 gVirtualX->SetMarkerSize (fMarkerSize);
320 gVirtualX->SetMarkerStyle(fMarkerStyle);
321 }
322
323 gPad->SetAttMarkerPS(fMarkerColor,fMarkerStyle,fMarkerSize);
324}
325
326////////////////////////////////////////////////////////////////////////////////
327/// Reset this marker attributes to the default values.
328
330{
331 fMarkerColor = 1;
332 fMarkerStyle = 1;
333 fMarkerSize = 1;
334}
335
336////////////////////////////////////////////////////////////////////////////////
337/// Save line attributes as C++ statement(s) on output stream out.
338
339void TAttMarker::SaveMarkerAttributes(std::ostream &out, const char *name, Int_t coldef, Int_t stydef, Int_t sizdef)
340{
341 if (fMarkerColor != coldef) {
342 if (fMarkerColor > 228) {
344 out<<" "<<name<<"->SetMarkerColor(ci);" << std::endl;
345 } else
346 out<<" "<<name<<"->SetMarkerColor("<<fMarkerColor<<");"<<std::endl;
347 }
348 if (fMarkerStyle != stydef) {
349 out<<" "<<name<<"->SetMarkerStyle("<<fMarkerStyle<<");"<<std::endl;
350 }
351 if (fMarkerSize != sizdef) {
352 out<<" "<<name<<"->SetMarkerSize("<<fMarkerSize<<");"<<std::endl;
353 }
354}
355
356////////////////////////////////////////////////////////////////////////////////
357/// Invoke the DialogCanvas Marker attributes.
358
360{
362}
363
364////////////////////////////////////////////////////////////////////////////////
365/// Set a transparent marker color. malpha defines the percentage of
366/// the color opacity from 0. (fully transparent) to 1. (fully opaque).
367
369{
371}
float Size_t
Definition: RtypesCore.h:85
short Width_t
Definition: RtypesCore.h:80
short Color_t
Definition: RtypesCore.h:81
short Style_t
Definition: RtypesCore.h:78
float Float_t
Definition: RtypesCore.h:55
const char Option_t
Definition: RtypesCore.h:64
#define ClassImp(name)
Definition: Rtypes.h:361
char name[80]
Definition: TGX11.cxx:109
R__EXTERN TStyle * gStyle
Definition: TStyle.h:410
#define gPad
Definition: TVirtualPad.h:287
#define gVirtualX
Definition: TVirtualX.h:338
Marker Attributes class.
Definition: TAttMarker.h:19
virtual void SaveMarkerAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t sizdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition: TAttMarker.cxx:339
virtual void Modify()
Change current marker attributes if necessary.
Definition: TAttMarker.cxx:314
virtual Style_t GetMarkerStyle() const
Return the marker style.
Definition: TAttMarker.h:32
virtual Color_t GetMarkerColor() const
Return the marker color.
Definition: TAttMarker.h:31
Color_t fMarkerColor
Marker color.
Definition: TAttMarker.h:22
virtual Size_t GetMarkerSize() const
Return the marker size.
Definition: TAttMarker.h:33
static Width_t GetMarkerLineWidth(Style_t style)
Internal helper function that returns the line width of the given marker style (0 = filled marker)
Definition: TAttMarker.cxx:297
virtual ~TAttMarker()
TAttMarker destructor.
Definition: TAttMarker.cxx:228
virtual void SetMarkerAttributes()
Invoke the DialogCanvas Marker attributes.
Definition: TAttMarker.cxx:359
virtual void ResetAttMarker(Option_t *toption="")
Reset this marker attributes to the default values.
Definition: TAttMarker.cxx:329
void Copy(TAttMarker &attmarker) const
Copy this marker attributes to a new TAttMarker.
Definition: TAttMarker.cxx:235
TAttMarker()
TAttMarker default constructor.
Definition: TAttMarker.cxx:202
virtual void SetMarkerColorAlpha(Color_t mcolor, Float_t malpha)
Set a transparent marker color.
Definition: TAttMarker.cxx:368
Size_t fMarkerSize
Marker size.
Definition: TAttMarker.h:24
Style_t fMarkerStyle
Marker style.
Definition: TAttMarker.h:23
static Style_t GetMarkerStyleBase(Style_t style)
Internal helper function that returns the corresponding marker style with line width 1 for the given ...
Definition: TAttMarker.cxx:246
static void SaveColor(std::ostream &out, Int_t ci)
Save a color with index > 228 as a C++ statement(s) on output stream out.
Definition: TColor.cxx:2121
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition: TColor.cxx:1979
static void UpdateMarkerAttributes(Int_t col, Int_t sty, Float_t msiz)
Update marker attributes via the pad editor.
TCanvas * style()
Definition: style.C:1