TAttMarker.cxx

Go to the documentation of this file.
00001 // @(#)root/base:$Id: TAttMarker.cxx 34870 2010-08-20 06:55:12Z brun $
00002 // Author: Rene Brun   12/05/95
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "Riostream.h"
00013 #include "Strlen.h"
00014 #include "TAttMarker.h"
00015 #include "TVirtualPad.h"
00016 #include "TStyle.h"
00017 #include "TVirtualX.h"
00018 #include "TVirtualPadEditor.h"
00019 #include "TColor.h"
00020 
00021 ClassImp(TAttMarker)
00022 
00023 
00024 //______________________________________________________________________________
00025 /* Begin_Html
00026 <center><h2>Marker Attributes class</h2></center>
00027 
00028 This class is used (in general by secondary inheritance)
00029 by many other classes (graphics, histograms). It holds all the markers
00030 attributes.
00031 
00032 <h3>Marker attributes</h3>
00033 The marker attributes are:
00034 <ul>
00035 <li><a href="#M1">Marker color.</a></li>
00036 <li><a href="#M2">Marker style.</a></li>
00037 <li><a href="#M3">Marker size.</a></li>
00038 </ul>
00039 
00040 <a name="M1"></a><h3>Marker color</h3>
00041 The marker color is a color index (integer) pointing in the ROOT color
00042 table.
00043 The marker color of any class inheriting from <tt>TAttMarker</tt> can 
00044 be changed using the method <tt>SetMarkerColor</tt> and retrieved using the 
00045 method <tt>GetMarkerColor</tt>.
00046 The following table shows the first 50 default colors.
00047 End_Html
00048 Begin_Macro(source)
00049 {
00050    TCanvas *c = new TCanvas("c","Marker colors",0,0,500,200);
00051    c.DrawColorTable();
00052    return c;
00053 }
00054 End_Macro
00055 
00056 Begin_Html
00057 <a name="M2"></a><h3>Marker style</h3>
00058 The Marker style defines the markers' shape.
00059 The marker style of any class inheriting from <tt>TAttMarker</tt> can 
00060 be changed using the method <tt>SetMarkerStyle</tt> and retrieved using the 
00061 method <tt>GetMarkerStyle</tt>.
00062 The following list gives the currently supported markers (screen 
00063 and PostScript) style. Each marker style is identified by an integer number 
00064 (first column) corresponding to a marker shape (second column) and can be also
00065 accessed via a global name (third column).
00066 <pre>
00067    Marker number         Marker shape          Marker name
00068         1                    dot                  kDot
00069         2                    +                    kPlus
00070         3                    *                    kStar
00071         4                    o                    kCircle
00072         5                    x                    kMultiply
00073         6                    small dot            kFullDotSmall
00074         7                    medium dot           kFullDotMedium
00075         8                    large scalable dot   kFullDotLarge
00076         9 -->19              dot
00077        20                    full circle          kFullCircle
00078        21                    full square          kFullSquare
00079        22                    full triangle up     kFullTriangleUp
00080        23                    full triangle down   kFullTriangleDown
00081        24                    open circle          kOpenCircle
00082        25                    open square          kOpenSquare
00083        26                    open triangle up     kOpenTriangleUp
00084        27                    open diamond         kOpenDiamond
00085        28                    open cross           kOpenCross
00086        29                    open star            kOpenStar
00087        30                    full star            kFullStar
00088 </pre>
00089 End_Html
00090 Begin_Macro(source)
00091 {
00092    TCanvas *c = new TCanvas("c","Marker types",0,0,500,200);
00093    TMarker marker;
00094    marker.DisplayMarkerTypes();
00095    return c;
00096 }
00097 End_Macro
00098 
00099 Begin_Html
00100 <a name="M3"></a><h3>Marker size</h3>
00101 Various marker sizes are shown in the figure below. The default marker size=1
00102 is shown in the top left corner. Marker sizes smaller than 1 can be
00103 specified. The marker size does not refer to any coordinate systems, it is an
00104 absolute value. Therefore the marker size is not affected by any change 
00105 in TPad's scale. A marker size equl to 1 correspond to 8 pixels.
00106 That is, a square marker with size 1 will be drawn with a side equal to 8
00107 pixels on the screen.
00108 The marker size of any class inheriting from <tt>TAttMarker</tt> can 
00109 be changed using the method <tt>SetMarkerSize</tt> and retrieved using the 
00110 method <tt>GetMarkerSize</tt>.
00111 End_Html
00112 Begin_Macro(source)
00113 {
00114    c = new TCanvas("c","Marker sizes",0,0,500,200);
00115    TMarker marker;
00116    marker.SetMarkerStyle(3);
00117    Double_t x = 0;
00118    Double_t dx = 1/6.0;
00119    for (Int_t i=1; i<6; i++) {
00120       x += dx;
00121       marker.SetMarkerSize(i*0.2); marker.DrawMarker(x,.165);
00122       marker.SetMarkerSize(i*0.8); marker.DrawMarker(x,.495);
00123       marker.SetMarkerSize(i*1.0); marker.DrawMarker(x,.835);
00124    }
00125    return c;
00126 }
00127 End_Macro
00128 
00129 Begin_Html
00130 Note that the marker styles number 1 6 and 7 (the dots), cannot be scaled. They 
00131 are meant to be very fast to draw and are always drawn with the same number of
00132 pixels; therefore <tt>SetMarkerSize</tt> does not apply on them. To have a 
00133 "scalable dot" a filled circle should be used instead, i.e. the marker style
00134 number 20. By default (if <tt>SetMarkerStyle</tt> is not specified), the marker 
00135 style used is 1. That's the most common one to draw scatter plots.
00136 End_Html */
00137 
00138 
00139 //______________________________________________________________________________
00140 TAttMarker::TAttMarker()
00141 {
00142    // TAttMarker default constructor.
00143    //
00144    // Default text attributes are taking from the current style.
00145 
00146    if (!gStyle) {fMarkerColor=1; fMarkerStyle=1; fMarkerSize=1; return;}
00147    fMarkerColor = gStyle->GetMarkerColor();
00148    fMarkerStyle = gStyle->GetMarkerStyle();
00149    fMarkerSize  = gStyle->GetMarkerSize();
00150 }
00151 
00152 
00153 //______________________________________________________________________________
00154 TAttMarker::TAttMarker(Color_t color, Style_t style, Size_t msize)
00155 {
00156    // TAttMarker normal constructor.
00157    //
00158    // Text attributes are taking from the argument list
00159    //    color : Marker Color Index
00160    //    style : Marker style (from 1 to 30)
00161    //    size  : marker size (float)
00162 
00163    fMarkerColor = color;
00164    fMarkerSize  = msize;
00165    fMarkerStyle = style;
00166 }
00167 
00168 
00169 //______________________________________________________________________________
00170 TAttMarker::~TAttMarker()
00171 {
00172    // TAttMarker destructor.
00173 }
00174 
00175 
00176 //______________________________________________________________________________
00177 void TAttMarker::Copy(TAttMarker &attmarker) const
00178 {
00179    // Copy this marker attributes to a new TAttMarker.
00180 
00181    attmarker.fMarkerColor  = fMarkerColor;
00182    attmarker.fMarkerStyle  = fMarkerStyle;
00183    attmarker.fMarkerSize   = fMarkerSize;
00184 }
00185 
00186 
00187 //______________________________________________________________________________
00188 void TAttMarker::Modify()
00189 {
00190    // Change current marker attributes if necessary.
00191 
00192    if (!gPad) return;
00193    if (!gPad->IsBatch()) {
00194       gVirtualX->SetMarkerColor(fMarkerColor);
00195       gVirtualX->SetMarkerSize (fMarkerSize);
00196       gVirtualX->SetMarkerStyle(fMarkerStyle);
00197    }
00198 
00199    gPad->SetAttMarkerPS(fMarkerColor,fMarkerStyle,fMarkerSize);
00200 }
00201 
00202 
00203 //______________________________________________________________________________
00204 void TAttMarker::ResetAttMarker(Option_t *)
00205 {
00206    // Reset this marker attributes to the default values.
00207 
00208    fMarkerColor  = 1;
00209    fMarkerStyle  = 1;
00210    fMarkerSize   = 1;
00211 }
00212 
00213 
00214 //______________________________________________________________________________
00215 void TAttMarker::SaveMarkerAttributes(ostream &out, const char *name, Int_t coldef, Int_t stydef, Int_t sizdef)
00216 {
00217    // Save line attributes as C++ statement(s) on output stream out.
00218 
00219    if (fMarkerColor != coldef) {
00220       if (fMarkerColor > 228) {
00221          TColor::SaveColor(out, fMarkerColor);
00222          out<<"   "<<name<<"->SetMarkerColor(ci);" << endl;
00223       } else
00224          out<<"   "<<name<<"->SetMarkerColor("<<fMarkerColor<<");"<<endl;
00225    }
00226    if (fMarkerStyle != stydef) {
00227       out<<"   "<<name<<"->SetMarkerStyle("<<fMarkerStyle<<");"<<endl;
00228    }
00229    if (fMarkerSize != sizdef) {
00230       out<<"   "<<name<<"->SetMarkerSize("<<fMarkerSize<<");"<<endl;
00231    }
00232 }
00233 
00234 
00235 //______________________________________________________________________________
00236 void TAttMarker::SetMarkerAttributes()
00237 {
00238    // Invoke the DialogCanvas Marker attributes.
00239 
00240    TVirtualPadEditor::UpdateMarkerAttributes(fMarkerColor,fMarkerStyle,fMarkerSize);
00241 }

Generated on Tue Jul 5 14:11:18 2011 for ROOT_528-00b_version by  doxygen 1.5.1