piechart.C: Pie chart example. | Basic Graphics | polytest2.C: This macro is testing new "compacting" algorithm in TPadPainter |
//Author: Timur Pocheptsov, 20.01.2014. // //This macro is testing new "compacting" algorithm in TPadPainter //(it reduces the number of polygon's vertices using actual pixel coordinates). //It's not really usefull, but just to test that the resulting polygon //is still reasonable. Initial number of points is 1000000, after "compression" //it's 523904 (with default canvas size, before you tried to resize it) - so almost half of //vertices were removed but you can still see the reasonable shape. If you resize //a canvas to a smaller size, the number of vertices after compression can be something like 5000 and even less. //It's easy to 'fool' this algorithm though in this particular case (ellipse is a kind of fringe case, //you can easily have a sequence of almost unique vertices (at a pixel level). // //Includes for ACLiC. #include <cassert> #include <vector> #include "TRandom.h" #include "TCanvas.h" #include "TError.h" #include "Rtypes.h" #include "TNamed.h" #include "TMath.h" class PolyTest1 : public TNamed, public TAttLine, public TAttFill { public: PolyTest1(unsigned nVertices); void Paint(const Option_t *notUsed); void Reset(unsigned nVertices); private: enum { kNPointsDefault = 10000//minimal number of points. }; std::vector<Double_t> fXs; std::vector<Double_t> fYs; }; //_____________________________________________________________ PolyTest1::PolyTest1(unsigned nVertices) : TNamed("polygon_compression_test1", "polygon_compression_test1") { Reset(nVertices); } //_____________________________________________________________ void PolyTest1::Reset(unsigned nVertices) { //Some canvas must already exist by this point. assert(gPad != 0 && "Reset, gPad is null"); //We need a gRandom to exist. assert(gRandom != 0 && "Reset, gRandom is null"); if (nVertices < kNPointsDefault) { Warning("Reset", "resetting nVertices parameter to %u", unsigned(kNPointsDefault)); nVertices = kNPointsDefault; } fXs.resize(nVertices); fYs.resize(nVertices); Double_t xMin = 0., xMax = 0., yMin = 0., yMax = 0.; gPad->GetRange(xMin, yMin, xMax, yMax); assert(xMax - xMin > 0 && yMax - yMin > 0 && "Reset, invalid canvas' ranges"); const Double_t xCentre = xMin + 0.5 * (xMax - xMin); const Double_t yCentre = yMin + 0.5 * (yMax - yMin); const Double_t r = TMath::Min(xMax - xMin, yMax - yMin) * 0.8 / 2; const Double_t angle = TMath::TwoPi() / (nVertices - 1); for (unsigned i = 0; i < nVertices - 1; ++i) { const Double_t currR = r + gRandom->Rndm() * r * 0.01; fXs[i] = xCentre + currR * TMath::Cos(angle * i); fYs[i] = yCentre + currR * TMath::Sin(angle * i); } fXs[nVertices - 1] = fXs[0]; fYs[nVertices - 1] = fYs[0]; } //_____________________________________________________________ void PolyTest1::Paint(const Option_t * /*notUsed*/) { assert(gPad != 0 && "Paint, gPad is null"); TAttFill::Modify(); gPad->PaintFillArea((Int_t)fXs.size(), &fXs[0], &fYs[0]); TAttLine::Modify(); gPad->PaintPolyLine((Int_t)fXs.size(), &fXs[0], &fYs[0]); } void polytest1() { TCanvas * const cnv = new TCanvas; cnv->cd(); PolyTest1 * polygon = new PolyTest1(1000000); polygon->SetLineColor(kBlue); polygon->SetFillColor(kRed); polygon->SetLineWidth(1); polygon->Draw();//Attach a polygon to a canvas. } polytest1.C:1 polytest1.C:2 polytest1.C:3 polytest1.C:4 polytest1.C:5 polytest1.C:6 polytest1.C:7 polytest1.C:8 polytest1.C:9 polytest1.C:10 polytest1.C:11 polytest1.C:12 polytest1.C:13 polytest1.C:14 polytest1.C:15 polytest1.C:16 polytest1.C:17 polytest1.C:18 polytest1.C:19 polytest1.C:20 polytest1.C:21 polytest1.C:22 polytest1.C:23 polytest1.C:24 polytest1.C:25 polytest1.C:26 polytest1.C:27 polytest1.C:28 polytest1.C:29 polytest1.C:30 polytest1.C:31 polytest1.C:32 polytest1.C:33 polytest1.C:34 polytest1.C:35 polytest1.C:36 polytest1.C:37 polytest1.C:38 polytest1.C:39 polytest1.C:40 polytest1.C:41 polytest1.C:42 polytest1.C:43 polytest1.C:44 polytest1.C:45 polytest1.C:46 polytest1.C:47 polytest1.C:48 polytest1.C:49 polytest1.C:50 polytest1.C:51 polytest1.C:52 polytest1.C:53 polytest1.C:54 polytest1.C:55 polytest1.C:56 polytest1.C:57 polytest1.C:58 polytest1.C:59 polytest1.C:60 polytest1.C:61 polytest1.C:62 polytest1.C:63 polytest1.C:64 polytest1.C:65 polytest1.C:66 polytest1.C:67 polytest1.C:68 polytest1.C:69 polytest1.C:70 polytest1.C:71 polytest1.C:72 polytest1.C:73 polytest1.C:74 polytest1.C:75 polytest1.C:76 polytest1.C:77 polytest1.C:78 polytest1.C:79 polytest1.C:80 polytest1.C:81 polytest1.C:82 polytest1.C:83 polytest1.C:84 polytest1.C:85 polytest1.C:86 polytest1.C:87 polytest1.C:88 polytest1.C:89 polytest1.C:90 polytest1.C:91 polytest1.C:92 polytest1.C:93 polytest1.C:94 polytest1.C:95 polytest1.C:96 polytest1.C:97 polytest1.C:98 polytest1.C:99 polytest1.C:100 polytest1.C:101 polytest1.C:102 polytest1.C:103 polytest1.C:104 polytest1.C:105 polytest1.C:106 polytest1.C:107 |
|