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
19
20/** \class TAnnotation
21\ingroup gpad
22
23An annotation is a TLatex which can be drawn in a 2D or 3D space.
24
25Example:
26
27Begin_Macro(source)
28{
29 auto hsurf1 = new TH2F("hsurf1","3D text example ",30,-4,4,30,-20,20);
30 float px, py;
31 for (Int_t i = 0; i < 25000; i++) {
32 gRandom->Rannor(px,py);
33 hsurf1->Fill(px-1,5*py);
34 hsurf1->Fill(2+0.5*px,2*py-10.,0.1);
35 }
36 hsurf1->Draw("SURF1");
37 int binx,biny,binz;
38 int bmax = hsurf1->GetMaximumBin(binx,biny,binz);
39 double xm = hsurf1->GetXaxis()->GetBinCenter(binx);
40 double ym = hsurf1->GetYaxis()->GetBinCenter(biny);
41 double zm = hsurf1->GetMaximum();
42 auto t = new TAnnotation(xm,ym,zm,Form("Maximum = %g",zm));
43 t->SetTextFont(42);
44 t->SetTextSize(0.03);
45 t->Draw();
46}
47End_Macro
48
49Another example:
50
51Begin_Macro(source)
52../../../tutorials/visualisation/graphics/annotation3d.C
53End_Macro
54*/
55
56////////////////////////////////////////////////////////////////////////////////
57/// annotation default constructor.
58
60{
61 fX = x;
62 fY = y;
63 fZ = z;
64 fTitle = text;
65}
66
67
68////////////////////////////////////////////////////////////////////////////////
69/// annotation default destructor.
70
71
75
76////////////////////////////////////////////////////////////////////////////////
77/// List this annotation with its attributes.
78
80{
82 printf("OBJ: %s\t%s \tX= %f Y=%f Z=%f \n",IsA()->GetName(),GetTitle(),fX,fY,fZ);
83}
84
85
86////////////////////////////////////////////////////////////////////////////////
87/// Draw this annotation with new coordinates.
88
98
99
100////////////////////////////////////////////////////////////////////////////////
101/// Paint this annotation with new coordinates.
102
104{
105 TView *view = gPad->GetView();
106 if (!view) {
108 } else {
109 Double_t xyz[3] = { x, y, z }, xpad[3];
110 view->WCtoNDC(xyz, &xpad[0]);
111 PaintLatex(xpad[0], xpad[1], angle, size, text);
112 }
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// Paint a TAnnotation.
117
118void TAnnotation::Paint(Option_t * /* option */ )
119{
121}
122
123////////////////////////////////////////////////////////////////////////////////
124/// Dump this annotation with its attributes.
125
127{
128 printf("Annotation X=%f Y=%f Z = %f Text=%s Font=%d Size=%f",fX,fY,fZ,GetTitle(),GetTextFont(),GetTextSize());
129 if (GetTextColor() != 1 ) printf(" Color=%d",GetTextColor());
130 if (GetTextAlign() != 10) printf(" Align=%d",GetTextAlign());
131 if (GetTextAngle() != 0 ) printf(" Angle=%f",GetTextAngle());
132 printf("\n");
133}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
char Char_t
Character 1 byte (char)
Definition RtypesCore.h:51
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:38
virtual Short_t GetTextAlign() const
Return the text alignment.
Definition TAttText.h:34
virtual Font_t GetTextFont() const
Return the text font.
Definition TAttText.h:37
virtual Color_t GetTextColor() const
Return the text color.
Definition TAttText.h:36
virtual Float_t GetTextAngle() const
Return the text angle.
Definition TAttText.h:35
void Copy(TAttText &atttext) const
Copy this text attributes to a new TAttText.
Definition TAttText.cxx:293
@ kTextNDC
The text position is in NDC coordinates.
Definition TLatex.h:94
virtual void PaintLatex(Double_t x, Double_t y, Double_t angle, Double_t size, const char *text)
Main drawing function.
Definition TLatex.cxx:2113
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
TString fTitle
Definition TNamed.h:33
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:202
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:68
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition TROOT.cxx:2898
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
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