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 <iostream>
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 
27 Marker Attributes class.
28 
29 This class is used (in general by secondary inheritance)
30 by many other classes (graphics, histograms). It holds all the markers
31 attributes.
32 
33 ## Marker attributes
34 The 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
42 The marker color is a color index (integer) pointing in the ROOT color
43 table.
44 The marker color of any class inheriting from `TAttMarker` can
45 be changed using the method `SetMarkerColor` and retrieved using the
46 method `GetMarkerColor`.
47 The following table shows the first 50 default colors.
48 
49 Begin_Macro
50 {
51  TCanvas *c = new TCanvas("c","Fill Area colors",0,0,500,200);
52  c->DrawColorTable();
53  return c;
54 }
55 End_Macro
56 
57 ### Color transparency
58 
59 `SetMarkerColorAlpha()`, allows to set a transparent color.
60 In the following example the marker color of the histogram `histo`
61 is set to blue with a transparency of 35%. The color `kBlue`
62 itself remains fully opaque.
63 
64 ~~~ {.cpp}
65 histo->SetMarkerColorAlpha(kBlue, 0.35);
66 ~~~
67 
68 The transparency is available on all platforms when the flag `OpenGL.CanvasPreferGL` is set to `1`
69 in `$ROOTSYS/etc/system.rootrc`, or on Mac with the Cocoa backend. On the file output
70 it is visible with PDF, PNG, Gif, JPEG, SVG, TeX ... but not PostScript.
71 
72 ## <a name="M2"></a> Marker style
73 
74 The Marker style defines the markers' shape.
75 The marker style of any class inheriting from `TAttMarker` can
76 be changed using the method `SetMarkerStyle` and retrieved using the
77 method `GetMarkerStyle`.
78 
79 The following list gives the currently supported markers (screen
80 and 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
82 accessed 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 
127 Begin_Macro
128 {
129  TCanvas *c = new TCanvas("c","Marker types",0,0,500,200);
130  TMarker marker;
131  marker.DisplayMarkerTypes();
132 }
133 End_Macro
134 
135 ### <a name="M21"></a> Marker line width
136 
137 The line width of a marker is not actually a marker attribute since it does
138 only apply to open marker symbols and marker symbols consisting of lines. All
139 of these marker symbols are redefined with thicker lines by style numbers
140 starting 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 
151 Begin_Macro
152 {
153  TCanvas *c = new TCanvas("c","Marker line widths",0,0,600,266);
154  TMarker marker;
155  marker.DisplayMarkerLineWidths();
156 }
157 End_Macro
158 
159 ## <a name="M3"></a> Marker size
160 
161 Various marker sizes are shown in the figure below. The default marker size=1
162 is shown in the top left corner. Marker sizes smaller than 1 can be
163 specified. The marker size does not refer to any coordinate systems, it is an
164 absolute value. Therefore the marker size is not affected by any change
165 in TPad's scale. A marker size equal to 1 correspond to 8 pixels.
166 That is, a square marker with size 1 will be drawn with a side equal to 8
167 pixels on the screen.
168 
169 The marker size of any class inheriting from `TAttMarker` can
170 be changed using the method `SetMarkerSize` and retrieved using the
171 method `GetMarkerSize`.
172 
173 Begin_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 }
187 End_Macro
188 
189 Note that the marker styles number 1 6 and 7 (the dots), cannot be scaled. They
190 are meant to be very fast to draw and are always drawn with the same number of
191 pixels; 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
193 number 20. By default (if `SetMarkerStyle` is not specified), the marker
194 style 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;}
205  fMarkerColor = gStyle->GetMarkerColor();
206  fMarkerStyle = gStyle->GetMarkerStyle();
207  fMarkerSize = gStyle->GetMarkerSize();
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 
235 void 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 
339 void 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 {
370  fMarkerColor = TColor::GetColorTransparent(mcolor, malpha);
371 }
TAttMarker::~TAttMarker
virtual ~TAttMarker()
TAttMarker destructor.
Definition: TAttMarker.cxx:228
Style_t
short Style_t
Definition: RtypesCore.h:80
TAttMarker::SetMarkerColorAlpha
virtual void SetMarkerColorAlpha(Color_t mcolor, Float_t malpha)
Set a transparent marker color.
Definition: TAttMarker.cxx:368
gVirtualX
#define gVirtualX
Definition: TVirtualX.h:338
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TAttMarker::GetMarkerLineWidth
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
TAttMarker::Copy
void Copy(TAttMarker &attmarker) const
Copy this marker attributes to a new TAttMarker.
Definition: TAttMarker.cxx:235
TAttMarker.h
Float_t
float Float_t
Definition: RtypesCore.h:57
TStyle.h
Strlen.h
TColor.h
TVirtualX.h
TColor::SaveColor
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:2118
Color_t
short Color_t
Definition: RtypesCore.h:83
style
TCanvas * style()
Definition: style.C:1
TAttMarker::SaveMarkerAttributes
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
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
TVirtualPadEditor.h
gStyle
R__EXTERN TStyle * gStyle
Definition: TStyle.h:412
TAttMarker::TAttMarker
TAttMarker()
TAttMarker default constructor.
Definition: TAttMarker.cxx:202
TAttMarker::ResetAttMarker
virtual void ResetAttMarker(Option_t *toption="")
Reset this marker attributes to the default values.
Definition: TAttMarker.cxx:329
Width_t
short Width_t
Definition: RtypesCore.h:82
TAttMarker::SetMarkerAttributes
virtual void SetMarkerAttributes()
Invoke the DialogCanvas Marker attributes.
Definition: TAttMarker.cxx:359
TAttMarker
Definition: TAttMarker.h:19
TVirtualPad.h
TVirtualPadEditor::UpdateMarkerAttributes
static void UpdateMarkerAttributes(Int_t col, Int_t sty, Float_t msiz)
Update marker attributes via the pad editor.
Definition: TVirtualPadEditor.cxx:164
TAttMarker::Modify
virtual void Modify()
Change current marker attributes if necessary.
Definition: TAttMarker.cxx:314
TAttMarker::GetMarkerStyleBase
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
TColor::GetColorTransparent
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition: TColor.cxx:1976
TAttMarker::fMarkerColor
Color_t fMarkerColor
Marker color.
Definition: TAttMarker.h:28
name
char name[80]
Definition: TGX11.cxx:110
TAttMarker::fMarkerStyle
Style_t fMarkerStyle
Marker style.
Definition: TAttMarker.h:29
gPad
#define gPad
Definition: TVirtualPad.h:287
TAttMarker::fMarkerSize
Size_t fMarkerSize
Marker size.
Definition: TAttMarker.h:30
int
Size_t
float Size_t
Definition: RtypesCore.h:87