Logo ROOT  
Reference Guide
polytest2.C
Go to the documentation of this file.
1/// \file
2/// \notebook
3/// \ingroup tutorial_graphics
4/// This macro is testing the "compacting" algorithm in TPadPainter.
5/// It reduces the number of polygon's vertices using actual pixel coordinates.
6///
7/// \macro_image
8///
9/// This macro is testing new "compacting" algorithm in TPadPainter
10/// (it reduces the number of polygon's vertices using actual pixel coordinates).
11/// In principle, this test case is what our histograms (fringe cases) are:
12/// "saw-like" polygon (bins == teeth).
13///
14/// \macro_code
15///
16/// \author Timur Pocheptsov
17
18//Includes for ACLiC.
19#include <cassert>
20#include <vector>
21
22#include "TRandom.h"
23#include "TCanvas.h"
24#include "Rtypes.h"
25#include "TNamed.h"
26
27class PolyTest2 : public TNamed, public TAttLine, public TAttFill {
28public:
29 PolyTest2();
30
31 void Paint(const Option_t *notUsed);
32
33private:
34 enum TestSize {
35 kNSawPoints = 10000
36 };
37
38 //Part 1.
39 std::vector<Double_t> fXs1;
40 std::vector<Double_t> fYs1;
41 //Part 2.
42
43 std::vector<Double_t> fXs2;
44 std::vector<Double_t> fYs2;
45};
46
47//_____________________________________________________________
48PolyTest2::PolyTest2()
49 : TNamed("polygon_compression_test2", "polygon_compression_test2")
50{
51 //Polygon 1, n of points is 10003, after 'compression' : 1897
52 //Polygon 2, n of points is 10003, after 'compression' : 2093
53
54 //Some canvas must already exist by this point.
55 assert(gPad != 0 && "PolyTest2, gPad is null");
56 //We need a gRandom to exist.
57 assert(gRandom != 0 && "PolyTest2, gRandom is null");
58
59 Double_t xMin = 0., xMax = 0., yMin = 0., yMax = 0.;
60 gPad->GetRange(xMin, yMin, xMax, yMax);
61 assert(xMax - xMin > 0 && yMax - yMin > 0 && "PolyTest2, invalid canvas' ranges");
62
63
64 // .(0/the last)--------.(1)
65 // | /
66 // | \
67 // | /
68 // .(kNSawPoints + 1)--.(kNSawPoints)
69
70 const unsigned nVertices = 3 + kNSawPoints;
71
72 {
73 //Polygon 1, "vertical saw":
74 fXs1.resize(nVertices);
75 fYs1.resize(nVertices);
76
77 fXs1[0] = 0.;
78 fYs1[0] = 0.;
79
80 const Double_t w1 = 0.2 * (xMax - xMin);
81 const Double_t saw1ToothSize = 0.1 * w1;
82 const Double_t yStep = (yMax - yMin) / (kNSawPoints - 1);
83
84 for (unsigned i = 1; i <= kNSawPoints; ++i) {
85 fXs1[i] = w1 + gRandom->Rndm() * saw1ToothSize;
86 fYs1[i] = yMin + yStep * (i - 1);
87 }
88
89 fXs1[nVertices - 2] = 0.;
90 fYs1[nVertices - 2] = yMax;
91 //Let's close it.
92 fXs1[nVertices - 1] = fXs1[0];
93 fYs1[nVertices - 1] = fYs1[0];
94
95 }
96
97 //Polygon 2, "horizontal saw":
98
99 {
100 const Double_t x2Min = xMin + 0.25 * (xMax - xMin);
101 const Double_t h2 = 0.1 * (yMax - yMin);
102 const Double_t saw2ToothSize = 0.1 * h2;
103 const Double_t xStep = (xMax - x2Min) / (kNSawPoints - 1);
104
105 fXs2.resize(nVertices);
106 fYs2.resize(nVertices);
107
108 fXs2[0] = x2Min;
109 fYs2[0] = 0.;
110
111 for (unsigned i = 1; i <= kNSawPoints; ++i) {
112 fXs2[i] = x2Min + xStep * i;
113 fYs2[i] = h2 + gRandom->Rndm() * saw2ToothSize;
114 }
115
116 fXs2[nVertices - 2] = xMax;
117 fYs2[nVertices - 2] = 0.;
118 fXs2[nVertices - 1] = fXs2[0];
119 fYs2[nVertices - 1] = fYs2[0];
120 }
121}
122
123//_____________________________________________________________
124void PolyTest2::Paint(const Option_t * /*notUsed*/)
125{
126 assert(gPad != 0 && "Paint, gPad is null");
127
130 gPad->PaintFillArea((Int_t)fXs1.size(), &fXs1[0], &fYs1[0]);
131
134 gPad->PaintPolyLine((Int_t)fXs1.size(), &fXs1[0], &fYs1[0]);
135
138 gPad->PaintFillArea((Int_t)fXs2.size(), &fXs2[0], &fYs2[0]);
139
142 gPad->PaintPolyLine((Int_t)fXs2.size(), &fXs2[0], &fYs2[0]);
143}
144
145void polytest2()
146{
147 TCanvas * const cnv = new TCanvas;
148 cnv->cd();
149
150 PolyTest2 * polygon = new PolyTest2;
151 polygon->Draw();//Attach a polygon to a canvas.
152}
int Int_t
Definition: RtypesCore.h:45
double Double_t
Definition: RtypesCore.h:59
const char Option_t
Definition: RtypesCore.h:66
@ kOrange
Definition: Rtypes.h:67
@ kGreen
Definition: Rtypes.h:66
@ kMagenta
Definition: Rtypes.h:66
@ kBlue
Definition: Rtypes.h:66
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
#define gPad
Definition: TVirtualPad.h:287
Fill Area Attributes class.
Definition: TAttFill.h:19
virtual void Modify()
Change current fill area attributes if necessary.
Definition: TAttFill.cxx:213
Line Attributes class.
Definition: TAttLine.h:18
virtual void Modify()
Change current line attributes if necessary.
Definition: TAttLine.cxx:245
The Canvas class.
Definition: TCanvas.h:23
TVirtualPad * cd(Int_t subpadnumber=0) override
Set current canvas & pad.
Definition: TCanvas.cxx:706
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
virtual void Paint(Option_t *option="")
This method must be overridden if a class wants to paint itself.
Definition: TObject.cxx:521
virtual Double_t Rndm()
Machine independent random number generator.
Definition: TRandom.cxx:552
h1 SetFillColor(kGreen)
lv SetLineColor(kBlue)