Logo ROOT   6.12/07
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 
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 size](#M3)
39 
40 ## <a name="M1"></a> Marker color
41 The marker color is a color index (integer) pointing in the ROOT color
42 table.
43 The marker color of any class inheriting from `TAttMarker` can
44 be changed using the method `SetMarkerColor` and retrieved using the
45 method `GetMarkerColor`.
46 The following table shows the first 50 default colors.
47 
48 Begin_Macro
49 {
50  TCanvas *c = new TCanvas("c","Marker colors",0,0,500,200);
51  c->DrawColorTable();
52 }
53 End_Macro
54 
55 ### Color transparency
56 
57 `SetMarkerColorAlpha()`, allows to set a transparent color.
58 In the following example the marker color of the histogram `histo`
59 is set to blue with a transparency of 35%. The color `kBlue`
60 itself remains fully opaque.
61 
62 ~~~ {.cpp}
63 histo->SetMarkerColorAlpha(kBlue, 0.35);
64 ~~~
65 
66 The transparency is available on all platforms when the `flagOpenGL.CanvasPreferGL` is set to `1`
67 in `$ROOTSYS/etc/system.rootrc`, or on Mac with the Cocoa backend. On the file output
68 it is visible with PDF, PNG, Gif, JPEG, SVG ... but not PostScript.
69 
70 ## <a name="M2"></a> Marker style
71 
72 The Marker style defines the markers' shape.
73 The marker style of any class inheriting from `TAttMarker` can
74 be changed using the method `SetMarkerStyle` and retrieved using the
75 method `GetMarkerStyle`.
76 
77 The following list gives the currently supported markers (screen
78 and PostScript) style. Each marker style is identified by an integer number
79 (first column) corresponding to a marker shape (second column) and can be also
80 accessed via a global name (third column).
81 
82 ~~~ {.cpp}
83  Marker number Marker shape Marker name
84  1 dot kDot
85  2 + kPlus
86  3 * kStar
87  4 o kCircle
88  5 x kMultiply
89  6 small dot kFullDotSmall
90  7 medium dot kFullDotMedium
91  8 large scalable dot kFullDotLarge
92  9 -->19 large scalable dot
93  20 full circle kFullCircle
94  21 full square kFullSquare
95  22 full triangle up kFullTriangleUp
96  23 full triangle down kFullTriangleDown
97  24 open circle kOpenCircle
98  25 open square kOpenSquare
99  26 open triangle up kOpenTriangleUp
100  27 open diamond kOpenDiamond
101  28 open cross kOpenCross
102  29 full star kFullStar
103  30 open star kOpenStar
104  31 *
105  32 open triangle down kOpenTriangleDown
106  33 full diamond kFullDiamond
107  34 full cross kFullCross
108  35 open diamond cross kOpenDiamondCross
109  36 open square diagonal kOpenSquareDiagonal
110  37 open three triangle kOpenThreeTriangles
111  38 octagon with cross kOctagonCross
112  39 full three trangles kFullThreeTriangles
113  40 open four triangleX kOpenFourTrianglesX
114  41 full four triangleX kFullFourTrianglesX
115  42 open double diamond kOpenDoubleDiamond
116  43 full double diamond kFullDoubleDiamond
117  44 open four triangle+ kOpenFourTrianglesPlus
118  45 full four triangle+ kFullFourTrianglesPlus
119  46 open cross X kOpenCrossX
120  47 full cross X kFullCrossX
121  48 four squares X kFourSquaresX
122  49 four squares+ kFourSquaresPlus
123 ~~~
124 
125 Begin_Macro
126 {
127  TCanvas *c = new TCanvas("c","Marker types",0,0,500,200);
128  TMarker marker;
129  marker.DisplayMarkerTypes();
130 }
131 End_Macro
132 
133 ## <a name="M3"></a> Marker size
134 
135 Various marker sizes are shown in the figure below. The default marker size=1
136 is shown in the top left corner. Marker sizes smaller than 1 can be
137 specified. The marker size does not refer to any coordinate systems, it is an
138 absolute value. Therefore the marker size is not affected by any change
139 in TPad's scale. A marker size equal to 1 correspond to 8 pixels.
140 That is, a square marker with size 1 will be drawn with a side equal to 8
141 pixels on the screen.
142 
143 The marker size of any class inheriting from `TAttMarker` can
144 be changed using the method `SetMarkerSize` and retrieved using the
145 method `GetMarkerSize`.
146 
147 Begin_Macro
148 {
149  c = new TCanvas("c","Marker sizes",0,0,500,200);
150  TMarker marker;
151  marker.SetMarkerStyle(3);
152  Double_t x = 0;
153  Double_t dx = 1/6.0;
154  for (Int_t i=1; i<6; i++) {
155  x += dx;
156  marker.SetMarkerSize(i*0.2); marker.DrawMarker(x,.165);
157  marker.SetMarkerSize(i*0.8); marker.DrawMarker(x,.495);
158  marker.SetMarkerSize(i*1.0); marker.DrawMarker(x,.835);
159  }
160 }
161 End_Macro
162 
163 Note that the marker styles number 1 6 and 7 (the dots), cannot be scaled. They
164 are meant to be very fast to draw and are always drawn with the same number of
165 pixels; therefore `SetMarkerSize` does not apply on them. To have a
166 "scalable dot" a filled circle should be used instead, i.e. the marker style
167 number 20. By default (if `SetMarkerStyle` is not specified), the marker
168 style used is 1. That's the most common one to draw scatter plots.
169 */
170 
171 ////////////////////////////////////////////////////////////////////////////////
172 /// TAttMarker default constructor.
173 ///
174 /// Default text attributes are taking from the current style.
175 
177 {
178  if (!gStyle) {fMarkerColor=1; fMarkerStyle=1; fMarkerSize=1; return;}
182 }
183 
184 ////////////////////////////////////////////////////////////////////////////////
185 /// TAttMarker normal constructor.
186 ///
187 /// Text attributes are taking from the argument list
188 /// - color : Marker Color Index
189 /// - style : Marker style (from 1 to 30)
190 /// - size : marker size (float)
191 
193 {
194  fMarkerColor = color;
195  fMarkerSize = msize;
197 }
198 
199 ////////////////////////////////////////////////////////////////////////////////
200 /// TAttMarker destructor.
201 
203 {
204 }
205 
206 ////////////////////////////////////////////////////////////////////////////////
207 /// Copy this marker attributes to a new TAttMarker.
208 
209 void TAttMarker::Copy(TAttMarker &attmarker) const
210 {
211  attmarker.fMarkerColor = fMarkerColor;
212  attmarker.fMarkerStyle = fMarkerStyle;
213  attmarker.fMarkerSize = fMarkerSize;
214 }
215 
216 ////////////////////////////////////////////////////////////////////////////////
217 /// Change current marker attributes if necessary.
218 
220 {
221  if (!gPad) return;
222  if (!gPad->IsBatch()) {
223  gVirtualX->SetMarkerColor(fMarkerColor);
224  gVirtualX->SetMarkerSize (fMarkerSize);
225  gVirtualX->SetMarkerStyle(fMarkerStyle);
226  }
227 
228  gPad->SetAttMarkerPS(fMarkerColor,fMarkerStyle,fMarkerSize);
229 }
230 
231 ////////////////////////////////////////////////////////////////////////////////
232 /// Reset this marker attributes to the default values.
233 
235 {
236  fMarkerColor = 1;
237  fMarkerStyle = 1;
238  fMarkerSize = 1;
239 }
240 
241 ////////////////////////////////////////////////////////////////////////////////
242 /// Save line attributes as C++ statement(s) on output stream out.
243 
244 void TAttMarker::SaveMarkerAttributes(std::ostream &out, const char *name, Int_t coldef, Int_t stydef, Int_t sizdef)
245 {
246  if (fMarkerColor != coldef) {
247  if (fMarkerColor > 228) {
249  out<<" "<<name<<"->SetMarkerColor(ci);" << std::endl;
250  } else
251  out<<" "<<name<<"->SetMarkerColor("<<fMarkerColor<<");"<<std::endl;
252  }
253  if (fMarkerStyle != stydef) {
254  out<<" "<<name<<"->SetMarkerStyle("<<fMarkerStyle<<");"<<std::endl;
255  }
256  if (fMarkerSize != sizdef) {
257  out<<" "<<name<<"->SetMarkerSize("<<fMarkerSize<<");"<<std::endl;
258  }
259 }
260 
261 ////////////////////////////////////////////////////////////////////////////////
262 /// Invoke the DialogCanvas Marker attributes.
263 
265 {
267 }
268 
269 ////////////////////////////////////////////////////////////////////////////////
270 /// Set a transparent marker color. malpha defines the percentage of
271 /// the color opacity from 0. (fully transparent) to 1. (fully opaque).
272 
274 {
275  fMarkerColor = TColor::GetColorTransparent(mcolor, malpha);
276 }
short Style_t
Definition: RtypesCore.h:76
float Float_t
Definition: RtypesCore.h:53
float Size_t
Definition: RtypesCore.h:83
const char Option_t
Definition: RtypesCore.h:62
R__EXTERN TStyle * gStyle
Definition: TStyle.h:402
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:2095
TAttMarker()
TAttMarker default constructor.
Definition: TAttMarker.cxx:176
Size_t fMarkerSize
Marker size.
Definition: TAttMarker.h:24
virtual void SetMarkerAttributes()
Invoke the DialogCanvas Marker attributes.
Definition: TAttMarker.cxx:264
int Int_t
Definition: RtypesCore.h:41
void Copy(TAttMarker &attmarker) const
Copy this marker attributes to a new TAttMarker.
Definition: TAttMarker.cxx:209
virtual Style_t GetMarkerStyle() const
Return the marker style.
Definition: TAttMarker.h:32
Marker Attributes class.
Definition: TAttMarker.h:19
virtual void SetMarkerColorAlpha(Color_t mcolor, Float_t malpha)
Set a transparent marker color.
Definition: TAttMarker.cxx:273
virtual Size_t GetMarkerSize() const
Return the marker size.
Definition: TAttMarker.h:33
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:244
short Color_t
Definition: RtypesCore.h:79
Style_t fMarkerStyle
Marker style.
Definition: TAttMarker.h:23
virtual void Modify()
Change current marker attributes if necessary.
Definition: TAttMarker.cxx:219
#define gVirtualX
Definition: TVirtualX.h:350
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition: TColor.cxx:1953
virtual void ResetAttMarker(Option_t *toption="")
Reset this marker attributes to the default values.
Definition: TAttMarker.cxx:234
static void UpdateMarkerAttributes(Int_t col, Int_t sty, Float_t msiz)
Update marker attributes via the pad editor.
#define ClassImp(name)
Definition: Rtypes.h:359
TCanvas * style()
Definition: style.C:1
virtual ~TAttMarker()
TAttMarker destructor.
Definition: TAttMarker.cxx:202
#define gPad
Definition: TVirtualPad.h:285
virtual Color_t GetMarkerColor() const
Return the marker color.
Definition: TAttMarker.h:31
Color_t fMarkerColor
Marker color.
Definition: TAttMarker.h:22
char name[80]
Definition: TGX11.cxx:109