Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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) override;
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() : TNamed("polygon_compression_test2", "polygon_compression_test2")
49{
50 // Polygon 1, n of points is 10003, after 'compression' : 1897
51 // Polygon 2, n of points is 10003, after 'compression' : 2093
52
53 // Some canvas must already exist by this point.
54 assert(gPad != nullptr && "PolyTest2, gPad is null");
55 // We need a gRandom to exist.
56 assert(gRandom != nullptr && "PolyTest2, gRandom is null");
57
58 Double_t xMin = 0., xMax = 0., yMin = 0., yMax = 0.;
59 gPad->GetRange(xMin, yMin, xMax, yMax);
60 assert(xMax - xMin > 0 && yMax - yMin > 0 && "PolyTest2, invalid canvas' ranges");
61
62 // .(0/the last)--------.(1)
63 // | /
64 // | \
65 // | /
66 // .(kNSawPoints + 1)--.(kNSawPoints)
67
68 const unsigned nVertices = 3 + kNSawPoints;
69
70 {
71 // Polygon 1, "vertical saw":
72 fXs1.resize(nVertices);
73 fYs1.resize(nVertices);
74
75 fXs1[0] = 0.;
76 fYs1[0] = 0.;
77
78 const Double_t w1 = 0.2 * (xMax - xMin);
79 const Double_t saw1ToothSize = 0.1 * w1;
80 const Double_t yStep = (yMax - yMin) / (kNSawPoints - 1);
81
82 for (unsigned i = 1; i <= kNSawPoints; ++i) {
83 fXs1[i] = w1 + gRandom->Rndm() * saw1ToothSize;
84 fYs1[i] = yMin + yStep * (i - 1);
85 }
86
87 fXs1[nVertices - 2] = 0.;
88 fYs1[nVertices - 2] = yMax;
89 // Let's close it.
90 fXs1[nVertices - 1] = fXs1[0];
91 fYs1[nVertices - 1] = fYs1[0];
92 }
93
94 // Polygon 2, "horizontal saw":
95
96 {
97 const Double_t x2Min = xMin + 0.25 * (xMax - xMin);
98 const yMin);
99 const h2;
100 const Double_t xStep = (xMax - x2Min) / (kNSawPoints - 1);
101
102 fXs2.resize(nVertices);
103 fYs2.resize(nVertices);
104
105 fXs2[0] = x2Min;
106 fYs2[0] = 0.;
107
108 for (unsigned i = 1; i <= kNSawPoints; ++i) {
109 fXs2[i] = x2Min + xStep * i;
110 saw2ToothSize;
111 }
112
113 fXs2[nVertices - 2] = xMax;
114 fYs2[nVertices - 2] = 0.;
115 fXs2[nVertices - 1] = fXs2[0];
116 fYs2[nVertices - 1] = fYs2[0];
117 }
118}
119
120//_____________________________________________________________
121void PolyTest2::Paint(const Option_t * /*notUsed*/)
122{
123 assert(gPad != nullptr && "Paint, gPad is null");
124
127 gPad->PaintFillArea((Int_t)fXs1.size(), &fXs1[0], &fYs1[0]);
128
131 gPad->PaintPolyLine((Int_t)fXs1.size(), &fXs1[0], &fYs1[0]);
132
135 gPad->PaintFillArea((Int_t)fXs2.size(), &fXs2[0], &fYs2[0]);
136
139 gPad->PaintPolyLine((Int_t)fXs2.size(), &fXs2[0], &fYs2[0]);
140}
141
142void polytest2()
143{
144 TCanvas *const cnv = new TCanvas;
145 cnv->cd();
146
148 polygon->Draw(); // Attach a polygon to a canvas.
149}
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
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t SetLineColor
Option_t Option_t SetFillColor
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
#define gPad
Fill Area Attributes class.
Definition TAttFill.h:20
virtual void Modify()
Change current fill area attributes if necessary.
Definition TAttFill.cxx:216
Line Attributes class.
Definition TAttLine.h:20
virtual void Modify()
Change current line attributes if necessary.
Definition TAttLine.cxx:247
The Canvas class.
Definition TCanvas.h:23
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
Double_t Rndm() override
Machine independent random number generator.
Definition TRandom.cxx:559