Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TAnnotation.cxx
Go to the documentation of this file.
1// @(#)root/gpad:$Id$
2// Author: Olivier Couet 03/05/23
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 "TROOT.h"
13#include "TAnnotation.h"
14#include "TVirtualPad.h"
15#include "TView.h"
16#include "TVirtualViewer3D.h"
17
18
20
21/** \class TAnnotation
22\ingroup gpad
23
24An annotation is a TLatex which can be drawn in a 2D or 3D space.
25
26Example:
27
28Begin_Macro(source)
29{
30 auto hsurf1 = new TH2F("hsurf1","3D text example ",30,-4,4,30,-20,20);
31 float px, py;
32 for (Int_t i = 0; i < 25000; i++) {
33 gRandom->Rannor(px,py);
34 hsurf1->Fill(px-1,5*py);
35 hsurf1->Fill(2+0.5*px,2*py-10.,0.1);
36 }
37 hsurf1->Draw("SURF1");
38 int binx,biny,binz;
39 int bmax = hsurf1->GetMaximumBin(binx,biny,binz);
40 double xm = hsurf1->GetXaxis()->GetBinCenter(binx);
41 double ym = hsurf1->GetYaxis()->GetBinCenter(biny);
42 double zm = hsurf1->GetMaximum();
43 auto t = new TAnnotation(xm,ym,zm,Form("Maximum = %g",zm));
44 t->SetTextFont(42);
45 t->SetTextSize(0.03);
46 t->Draw();
47}
48End_Macro
49
50Another example:
51
52Begin_Macro(source)
53../../../tutorials/graphs/annotation3d.C
54End_Macro
55*/
56
57////////////////////////////////////////////////////////////////////////////////
58/// annotation default constructor.
59
61{
62 fX = x;
63 fY = y;
64 fZ = z;
65 fTitle = text;
66}
67
68
69////////////////////////////////////////////////////////////////////////////////
70/// annotation default destructor.
71
72
74{
75}
76
77////////////////////////////////////////////////////////////////////////////////
78/// List this annotation with its attributes.
79
81{
83 printf("OBJ: %s\t%s \tX= %f Y=%f Z=%f \n",IsA()->GetName(),GetTitle(),fX,fY,fZ);
84}
85
86
87////////////////////////////////////////////////////////////////////////////////
88/// Draw this annotation with new coordinates.
89
91{
92 TAnnotation *newannotation = new TAnnotation(x, y, z, text);
93 TAttText::Copy(*newannotation);
94 newannotation->SetBit(kCanDelete);
95 if (TestBit(kTextNDC)) newannotation->SetNDC();
96 newannotation->AppendPad();
97 return newannotation;
98}
99
100
101////////////////////////////////////////////////////////////////////////////////
102/// Paint this annotation with new coordinates.
103
105{
106 TView *view = gPad->GetView();
107 if (!view) {
109 } else {
110 Double_t xyz[3] = { x, y, z }, xpad[3];
111 view->WCtoNDC(xyz, &xpad[0]);
112 PaintLatex(xpad[0], xpad[1], angle, size, text);
113 }
114}
115
116////////////////////////////////////////////////////////////////////////////////
117/// Paint a TAnnotation.
118
119void TAnnotation::Paint(Option_t * /* option */ )
120{
122}
123
124////////////////////////////////////////////////////////////////////////////////
125/// Dump this annotation with its attributes.
126
128{
129 printf("Annotation X=%f Y=%f Z = %f Text=%s Font=%d Size=%f",fX,fY,fZ,GetTitle(),GetTextFont(),GetTextSize());
130 if (GetTextColor() != 1 ) printf(" Color=%d",GetTextColor());
131 if (GetTextAlign() != 10) printf(" Align=%d",GetTextAlign());
132 if (GetTextAngle() != 0 ) printf(" Angle=%f",GetTextAngle());
133 printf("\n");
134}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
char Char_t
Definition RtypesCore.h:37
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
Option_t Option_t TPoint TPoint angle
Option_t Option_t TPoint TPoint const char text
#define gPad
An annotation is a TLatex which can be drawn in a 2D or 3D space.
Definition TAnnotation.h:18
void PaintAnnotation(Double_t x, Double_t y, Double_t z, Double_t angle, Double_t size, const Char_t *text)
Paint this annotation with new coordinates.
TClass * IsA() const override
Definition TAnnotation.h:37
~TAnnotation() override
annotation default destructor.
double fZ
Z position of text.
Definition TAnnotation.h:21
void ls(Option_t *option="") const override
List this annotation with its attributes.
void Print(Option_t *option="") const override
Dump this annotation with its attributes.
void Paint(Option_t *option="") override
Paint a TAnnotation.
virtual TAnnotation * DrawAnnotation(Double_t x, Double_t y, Double_t z, const char *text)
Draw this annotation with new coordinates.
virtual Float_t GetTextSize() const
Return the text size.
Definition TAttText.h:36
virtual Short_t GetTextAlign() const
Return the text alignment.
Definition TAttText.h:32
virtual Font_t GetTextFont() const
Return the text font.
Definition TAttText.h:35
virtual Color_t GetTextColor() const
Return the text color.
Definition TAttText.h:34
virtual Float_t GetTextAngle() const
Return the text angle.
Definition TAttText.h:33
void Copy(TAttText &atttext) const
Copy this text attributes to a new TAttText.
Definition TAttText.cxx:299
@ kTextNDC
The text position is in NDC coordinates.
Definition TLatex.h:93
virtual void PaintLatex(Double_t x, Double_t y, Double_t angle, Double_t size, const char *text)
Main drawing function.
Definition TLatex.cxx:2057
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
TString fTitle
Definition TNamed.h:33
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:199
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:184
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:780
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:62
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition TROOT.cxx:2870
Double_t fY
Y position of text (left,center,etc..)
Definition TText.h:26
Double_t fX
X position of text (left,center,etc..)
Definition TText.h:25
virtual void SetNDC(Bool_t isNDC=kTRUE)
Set NDC mode on if isNDC = kTRUE, off otherwise.
Definition TText.cxx:823
See TView3D.
Definition TView.h:25
virtual void WCtoNDC(const Float_t *pw, Float_t *pn)=0
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17