void Gosu::drawText(Bitmap& bitmap, const std::wstring& text, int x, int y, Color c, const std::wstring& fontName, unsigned fontHeight, unsigned fontFlags) { if (text.find_first_of(L"\r\n") != std::wstring::npos) throw std::invalid_argument("the argument to drawText cannot contain line breaks"); if (text.empty()) return; CachedFontInfo& font = getFont(fontName); ATSULayoutAndStyle atlas(text, fontName, fontHeight, fontFlags); Rect rect = atlas.textExtents(); unsigned width = rect.right + 1 - rect.left + 1; // add one pixel on OS X std::vector<std::tr1::uint32_t> buf(width * fontHeight); { MacBitmap helper(&buf[0], width, fontHeight); atlas.drawToContext(X2Fix(-rect.left), X2Fix(fontHeight / font.heightAt1Pt * font.descentAt1Pt), helper.context()); } for (unsigned relY = 0; relY < fontHeight; ++relY) for (unsigned relX = 0; relX < width; ++relX) { #ifdef __BIG_ENDIAN__ Color::Channel alpha = buf[relY * width + relX]; #else Color::Channel alpha = Color(buf[relY * width + relX]).alpha(); #endif if (alpha != 0) bitmap.setPixel(x + relX, y + relY, multiply(c, Color(alpha, 0xff, 0xff, 0xff))); } }
int main(int argc, char *argv[]) { QApplication a(argc, argv); ControlleurMain atlas(0); atlas.exec(); return a.exec(); }
//----------------------------------------------------------------------------- // Name: CreateTextureAtlases() // Desc: Creates atlases for the given textures. // All options/info is stored in the options parameter. // Returns false if errors occur. //----------------------------------------------------------------------------- bool CMyD3DApplication::CreateTextureAtlases(CmdLineOptionCollection const &options) const { // Create an array of texture objects and load the filenames/textures into that array. int const kNumTextures = options.GetNumFilenames(); char const *pFilename = NULL; int i; Texture2D * pSourceTex = new Texture2D[kNumTextures]; for (i = 0; i < kNumTextures; ++i) { options.GetFilename(i, &pFilename); pSourceTex[i].Init(m_pd3dDevice, pFilename); if (FAILED(pSourceTex[i].LoadTexture(options))) { delete [] pSourceTex; return false; } } // Bin these textures into format groups (maps of vectors) TNewFormatMap formatMap; for (i = 0; i < kNumTextures; ++i) formatMap[pSourceTex[i].GetFormat()].push_back( &(pSourceTex[i]) ); // We do not do format conversions, so all these different formats // require their own atlases. Each format may have multiple atlases, e.g., // there is not enough space in a single atlas for all textures of the // same format. An atlas container contains all these concepts. AtlasContainer atlas(options, formatMap.size()); // For each format-vector of textures, Sort textures by size (width*height, then height TNewFormatMap::iterator fmSort; for ( fmSort = formatMap.begin(); fmSort != formatMap.end(); ++fmSort) std::sort( (*fmSort).second.begin(), (*fmSort).second.end(), Texture2DGreater() ); // For each format-vector of textures, insert them into their respective // atlas vector: TNewFormatMap::const_iterator fmIter; for (i = 0, fmIter = formatMap.begin(); fmIter != formatMap.end(); ++fmIter, ++i) atlas.Insert(i, fmIter->second); // Done inserting data: shrink all atlases to minimum size atlas.Shrink(); // Write all atlases to disk w/ the filenames they have stored atlas.WriteToDisk(); // Save the Texture Atlas Info (tai) file. // For each original texture read-out where it landed up // and write that into the tai file. bool const kSuccess = CreateTAIFile(options, formatMap); // free all memory: clear all vectors of everything delete [] pSourceTex; return kSuccess; }
unsigned Gosu::textWidth(const std::wstring& text, const std::wstring& fontName, unsigned fontHeight, unsigned fontFlags) { if (text.find_first_of(L"\r\n") != std::wstring::npos) throw std::invalid_argument("the argument to textWidth cannot contain line breaks"); // TODO: Why 1? if (text.empty()) return 1; // TODO: special case :( // TODO: Why? I guess it was empty otherwise? if (text == L" ") return fontHeight / 3; ATSULayoutAndStyle atlas(text, fontName, fontHeight, fontFlags); Rect rect = atlas.textExtents(); return rect.right + 1 - rect.left + 1; // add one pixel on OS X }
Animation AnimationLoader::loadFromResources(const Resources::ResourcePack& resourcePack) { auto atlasResource = resourcePack.resource("atlas"); Texture atlas(atlasResource); auto configResource = resourcePack.resource("config"); ConfigReader reader(configResource.asString()); unsigned frames = reader.getInt("Frames"); if (frames == 1) return Animation(atlas); int frameDuration = reader.getInt("FrameDuration"); std::vector<Rectangle> frameRects; frameRects.reserve(frames); for (unsigned i = 0; i < frames; ++i) { String rectName = String("Rect") + String::fromInt(i + 1); std::vector<String> rectCoords = reader.getArray(rectName); int x = rectCoords[0].toInt(), y = rectCoords[1].toInt(); unsigned w = rectCoords[2].toInt(), h = rectCoords[3].toInt(); frameRects.emplace_back(x, y, w, h); } return Animation(atlas, frameRects, std::chrono::milliseconds(frameDuration)); }
void SUSY_bRPV_m0_vs_m12_all_withBand_cls( TString fname0="", TString fname1="", TString fname2="", TString gridname="", const char* prefix="test", const float& lumi = 20.3, bool showsig = true, int discexcl = 1, int showtevatron = 0, int showcms = 0, int showOneSigmaExpBand = 0, bool showSR = false, bool useShape = false, int channel = -1, TString hname0 = "sigp1clsf", TString hname1 = "sigp1expclsf", TString hname3 = "sigclsu1s", TString hname5 = "sigclsd1s", TString hname6 = "sigp1ref", TString fnameMass= "contourmacros/mSugraGridtanbeta10_gluinoSquarkMasses.root") { // set style and remove existing canvas' CombinationGlob::Initialize(); cout << "--- Plotting m0 versus m12 " << endl; // --- prepare // open reference files, and retrieve histogram cout << "--- Reading root base file: " << fname0 << endl; TFile* f0 = TFile::Open( fname0, "READ" ); if (!f0) { cout << "*** Error: could not retrieve histogram: " << hname0 << " in file: " << f0->GetName() << " ==> abort macro execution" << endl; return; } TFile *f1; TFile *f2; if(fname1 != "") f1 = TFile::Open( fname1, "READ" ); if(!f1) cout << "Warning: could not open " << fname1 << endl; if(fname2 != "") f2 = TFile::Open( fname2, "READ" ); if(!f2) cout << "Warning: could not open " << fname2 << endl; TH2F* histecls = (TH2F*)f0->Get( "sigp1expclsf" ); TH2F* histocls = (TH2F*)f0->Get( "sigp1clsf" ); if (histecls!=0) histecls->SetDirectory(0); if (histocls!=0) histocls->SetDirectory(0); TH2F* histe_esigxsp1s; if (fname1 != "" && f1) { histe_esigxsp1s = (TH2F*)f1->Get( hname0 ); cout << "Read up histogram " << histe_esigxsp1s << endl; } TH2F* histe_esigxsm1s; if (fname2 != "" && f2) { histe_esigxsm1s = (TH2F*)f2->Get( hname0 ); cout << "Read down histogram " << histe_esigxsm1s << endl; } if (histe_esigxsp1s!=0) histe_esigxsp1s->SetDirectory(0); if (histe_esigxsm1s!=0) histe_esigxsm1s->SetDirectory(0); TH2F* contour_esigxsp1s = ( histe_esigxsp1s!=0 ? FixAndSetBorders( *histe_esigxsp1s, "contour_esigxsp1s", "contour_esigxsp1s", 0 ) : 0); TH2F* contour_esigxsm1s = ( histe_esigxsm1s!=0 ? FixAndSetBorders( *histe_esigxsm1s, "contour_esigxsm1s", "contour_esigxsm1s", 0 ) : 0); // TFile* f3 = TFile::Open( fname3, "READ" ); TH2F* histe(0); TH2F* histe_u1s(0); TH2F* histe_d1s(0); // TFile* f4 = TFile::Open( fname4, "READ" ); bool extExpectation = 0; TH2F* hist0 = (TH2F*)f0->Get( hname0 ); TH2F* hist1 = (TH2F*)f0->Get( hname1 ); TH2F* hist3 = (TH2F*)f0->Get( hname3 ); TH2F* hist5 = (TH2F*)f0->Get( hname5 ); TH2F* hist6 = (TH2F*)f0->Get( hname6 ); if (hist0!=0) hist0->SetDirectory(0); if (hist1!=0) hist1->SetDirectory(0); if (hist3!=0) hist3->SetDirectory(0); if (hist5!=0) hist5->SetDirectory(0); if (hist6!=0) hist6->SetDirectory(0); f0->Close(); TH2F* histe_esigxsp1s; if (fname1!="" && f1) histe_esigxsp1s = (TH2F*)f1->Get( hname0 ); TH2F* histe_esigxsm1s; if (fname2!="" && f2) histe_esigxsm1s = (TH2F*)f2->Get( hname0 ); if (fname1!="" &&histe_esigxsp1s!=0) histe_esigxsp1s->SetDirectory(0); if (fname2!="" && histe_esigxsm1s!=0) histe_esigxsm1s->SetDirectory(0); TH2F* contour_esigxsp1s = ( histe_esigxsp1s!=0 ? FixAndSetBorders( *histe_esigxsp1s, "contour_esigxsp1s", "contour_esigxsp1s", 0 ) : 0); TH2F* contour_esigxsm1s = ( histe_esigxsm1s!=0 ? FixAndSetBorders( *histe_esigxsm1s, "contour_esigxsm1s", "contour_esigxsm1s", 0 ) : 0); TH2F* contour = ( hist1!=0 ? FixAndSetBorders( *hist1, "contour", "contour", 0 ) : 0); TH2F* contour_obs = ( hist0!=0 ? FixAndSetBorders( *hist0, "contour_obs", "contour_obs") : 0 ); TH2F* contour_ep1s = ( hist3!=0 ? FixAndSetBorders( *hist3, "contour", "contour", 0 ) : 0 ); TH2F* contour_em1s = ( hist5!=0 ? FixAndSetBorders( *hist5, "contour", "contour", 0 ) : 0 ); // For Band if (showOneSigmaExpBand){ TGraph* gr_contour_ep1s = ContourGraph( contour_ep1s )->Clone(); TGraph* gr_contour_em1s= ContourGraph( contour_em1s )->Clone(); } TH2F* contour_exp(0); if (histe!=0) { contour_exp = FixAndSetBorders( *histe, "contour_exp", "contour_exp", 0 ); } TH2F* contour_au1s(0); if (histe_u1s!=0) { contour_au1s = FixAndSetBorders( *histe_u1s, "contour", "contour", 0 ); } TH2F* contour_ad1s(0); if (histe_d1s!=0) { contour_ad1s = FixAndSetBorders( *histe_d1s, "contour", "contour", 0 ); } TH2F* contour_expcls(0); if (histecls!=0) { contour_expcls = FixAndSetBorders( *histecls, "contour_expcls", "contour_expcls", 0 ); } TH2F* contour_obscls(0); if (histocls!=0) { contour_obscls = FixAndSetBorders( *histocls, "contour_obscls", "contour_obscls", 0 ); } if (contour_obs==0) { cout << "contour is zero" << endl; return; } // set text style gStyle->SetPaintTextFormat(".2g"); if (hist1!=0) hist1->SetMarkerStyle(21); if (hist1!=0) hist1->SetMarkerSize(1.5); Float_t nsigmax(0) if (hist1!=0) nsigmax = hist1->GetMaximum(); // --- draw // create canvas TCanvas* c = new TCanvas( "c", "A scan of "+gridname, 0, 0, CombinationGlob::StandardCanvas[0], CombinationGlob::StandardCanvas[1] ); //c->SetGrayscale(); // create and draw the frame double plotrange=2250.; TH2F *frame = new TH2F("frame", "m_{gluino} vs. m_{lsp} - ATLAS work in progress", 100, 350.,plotrange, 100, 200., 900. ); // set common frame style CombinationGlob::SetFrameStyle2D( frame, 1.0 ); // the size (scale) is 1.0 frame->SetXTitle( "m_{0} [GeV]" ); frame->SetYTitle( "m_{1/2} [GeV]" ); frame->GetYaxis()->SetTitleOffset(1.35); //frame->SetTextFont( 42 ); frame->GetXaxis()->SetTitleFont( 42 ); frame->GetYaxis()->SetTitleFont( 42 ); frame->GetXaxis()->SetLabelFont( 42 ); frame->GetYaxis()->SetLabelFont( 42 ); frame->GetXaxis()->SetTitleSize( 0.04 ); frame->GetYaxis()->SetTitleSize( 0.04 ); frame->GetXaxis()->SetLabelSize( 0.04 ); frame->GetYaxis()->SetLabelSize( 0.04 ); frame->Draw(); const int nsig(3); //TH2F *chist[3]; // draw contours //!instead of printing sigma in 68% 95% 98% levels now printing +1 sigma deviations //for (Int_t nsigma=1; nsigma<=nsig; nsigma++) // DrawContourSameColor( contour, nsigma, "blue", kFALSE, (nsigma==1?inverse:0) ) ; TString basecolor="yellow"; Int_t nsigma=2; TLegend *leg = new TLegend(0.6,0.7,0.92,0.9); leg->SetTextSize( CombinationGlob::DescriptionTextSize ); leg->SetTextSize( 0.03 ); leg->SetTextFont( 42 ); leg->SetFillColor( 0 ); leg->SetFillStyle(1001); if (false && channel==1) { // electron cout << "removing islands in electron channel ..." << endl; // contour line is drawn for values at 1.64485 TAxis* ax = contour_obs->GetXaxis(); TAxis* ay = contour_obs->GetYaxis(); /* contour_em1s for (int xbin = 1; xbin <= contour_obs->GetNbinsX(); xbin++) { for (int ybin = 1; ybin <= contour_obs->GetNbinsY(); ybin++) { // island 2 if ( ax->GetBinCenter( xbin) > 420. && ax->GetBinCenter( xbin) < 480. && ay->GetBinCenter( ybin) > 140. && ay->GetBinCenter( ybin) < 160. ) { cout << "Found spot here: " << xbin << " (" << ax->GetBinCenter( xbin) << "), " << ybin << " (" << ay->GetBinCenter( ybin) << "), " << " value: " << contour->GetBinContent(xbin,ybin) << endl; cout << " HACK : Setting above point by hand to 1.50 (!)" << endl; contour->SetBinContent(xbin, ybin, 1.50); } } } */ } if (false && channel==2) { // combined cout << "removing islands in combined channel ..." << endl; } ///////////////////////////////////////////////////////// //// add 2011 results Int_t c_myYellow = TColor::GetColor("#ffe938"); Int_t c_myRed = TColor::GetColor("#aa000"); // turn off yellow band if (showOneSigmaExpBand) TGraph* grshadeExp= DrawExpectedBand( gr_contour_ep1s, gr_contour_em1s, CombinationGlob::c_DarkYellow , 1001 , 0)->Clone(); if (discexcl==1) { DrawContourLine95( leg, contour_obs, "Observed limit (#pm1 #sigma^{SUSY}_{theory})", c_myRed, 1, 4 ); // 95% CL_{S} if (contour_esigxsp1s) DrawContourLine95( leg, contour_esigxsp1s, "", c_myRed, 3, 2 ); // Observed limit #pm 1 #sigma^{SUSY}_{theory} if (contour_esigxsm1s) DrawContourLine95( leg, contour_esigxsm1s, "", c_myRed, 3, 2 ); // Observed limit #pm 1 #sigma^{SUSY}_{theory} if (!extExpectation) { // Compare the expected limits! if (contour_expcls!=0) { //DrawContourLine95( leg, contour_expcls, fname0, CombinationGlob::c_DarkGray, 6 ); DrawContourLine95( leg, contour_expcls, fname0, CombinationGlob::c_DarkBlueT3, 6 ); } if (showOneSigmaExpBand) { if (contour_ep1s!=0) { DrawContourLine95( leg, contour_ep1s, "", c_myYellow, 1 ); } if (contour_em1s!=0) { DrawContourLine95( leg, contour_em1s, "", c_myYellow, 1 ); } DummyLegendExpected(leg, "Expected limit (#pm1 #sigma_{exp})", c_myYellow, 1001, CombinationGlob::c_DarkBlueT3, 6, 2); } else { //if (contour!=0) DrawContourLine68( leg, contour, "exp. limit 68% CL", CombinationGlob::c_DarkBlueT3, 2 ); //if (contour!=0) DrawContourLine99( leg, contour, "exp. limit 99% CL", CombinationGlob::c_DarkBlueT3, 3 ); } } else { // expectation from asimov if (contour_exp!=0) DrawContourLine95( leg, contour_exp, "Median expected limit", CombinationGlob::c_DarkBlueT3, 6); if (showOneSigmaExpBand) { if (contour_au1s!=0) DrawContourLine95( leg, contour_au1s, "Expected limit #pm1#sigma", CombinationGlob::c_DarkBlueT3, 3 ); if (contour_ad1s!=0) DrawContourLine95( leg, contour_ad1s, "", CombinationGlob::c_DarkBlueT3, 3 ); } } } // plot tevatron limits TGraph* lep2slep(0); TGraph* lep2char(0); TGraph* d0o(0); TGraph* d0graph(0); TGraph* cdfgraph(0); TGraph* atlas(0); TGraph* atlasexp(0); if (showtevatron==1 && discexcl==1) { lep2char = ol1(); d0graph = d0tanb3muneg(); cdfgraph = cdftanb5(); //atlas = ATLAS10_1lepton(); //atlasexp = ATLAS10_1leptonexp(); } //:w(void) stautanb3(); TGraph* cmscurve(0); if (showcms==1) { //cmscurve = cmsoff(); cmscurve = cms(); } // legend Float_t textSizeOffset = +0.000; Double_t xmax = frame->GetXaxis()->GetXmax(); Double_t xmin = frame->GetXaxis()->GetXmin(); Double_t ymax = frame->GetYaxis()->GetXmax(); Double_t ymin = frame->GetYaxis()->GetXmin(); Double_t dx = xmax - xmin; Double_t dy = ymax - ymin; //TString t1a = "99%, 95%, 68% CL fit contour (excluded)" ; // TString t1a = "-1#sigma, central, +1#sigma fit contour (excluded)" ; TString t1b = "tan#beta = 3, A_{0}= 0, #mu < 0" ; Float_t nbkg(0); if( hist5!=0) nbkg = hist5->GetMaximum(); TString t1c = Form("MC: n_{bkg}= %.1f", nbkg) ; // TLatex* text1a = new TLatex( 70, 260, t1a ); TLatex* text1b = new TLatex( 150, ymax + dy*0.025, t1b ); TLatex* text1c = new TLatex( 70, 280, t1c ); // text1a->SetTextColor( 1 ); //CombinationGlob::c_VDarkGreen ); text1b->SetTextColor( 1 ); //CombinationGlob::c_VDarkGreen ); text1c->SetTextColor( 1 ); text1b->SetTextFont( 42 ); //CombinationGlob::c_VDarkGreen ); // text1a->SetTextAlign( 11 ); text1b->SetTextAlign( 11 ); text1c->SetTextAlign( 11 ); // text1a->SetTextSize( CombinationGlob::DescriptionTextSize + textSizeOffset ); text1b->SetTextSize( CombinationGlob::DescriptionTextSize ); text1c->SetTextSize( CombinationGlob::DescriptionTextSize ); TString plottitle="bRPV-MSUGRA: tan #beta = 30, A_{0}= -2m_{0}, #mu>0"; if(showSR){ std::cout << "--- printing best SRs" << std::endl; Show_SR(fname0, c, xmin, xmax, ymin, ymax, useShape, leg); } TLatex *Leg0 = new TLatex( xmin, ymax + dy*0.025,plottitle ); Leg0->SetTextAlign( 11 ); Leg0->SetTextFont( 42 ); Leg0->SetTextSize( CombinationGlob::DescriptionTextSize); Leg0->SetTextColor( 1 ); Leg0->AppendPad(); TLatex *Leg1 = new TLatex(); Leg1->SetNDC(); Leg1->SetTextAlign( 11 ); Leg1->SetTextFont( 42 ); Leg1->SetTextSize( CombinationGlob::DescriptionTextSize ); Leg1->SetTextColor( 1 ); Leg1->DrawLatex(0.15,0.78, Form("#int L dt = %1.1f fb^{-1}, #sqrt{s}=8 TeV",lumi)); // 0.32,0.87 if(useShape){ Leg1->DrawLatex(0.15,0.72, "0 leptons, 2-6 jets, 5-bin"); // 0.32,0.87 } else { Leg1->DrawLatex(0.15,0.72, "0 leptons, 2-6 jets"); // 0.32,0.87 } Leg1->AppendPad(); TLatex *Leg2 = new TLatex(); Leg2->SetNDC(); Leg2->SetTextAlign( 11 ); Leg2->SetTextSize( CombinationGlob::DescriptionTextSize ); Leg2->SetTextColor( 1 ); Leg2->SetTextFont(70); if (prefix!=0) { Leg2->DrawLatex(0.7,0.85,prefix); // 0.15,0.81 Leg2->AppendPad(); } TLatex *atlasLabel = new TLatex(); atlasLabel->SetNDC(); atlasLabel->SetTextFont( 42 ); atlasLabel->SetTextColor( 1 ); atlasLabel->SetTextSize( 0.05 ); atlasLabel->DrawLatex(0.15,0.87, "#bf{#it{ATLAS}} Internal"); // 0.15,0.87 atlasLabel->AppendPad(); //// draw number of signal events if (nsigmax>0 && showsig) { hist1->Draw("textsame"); } //else { // // draw grid for clarity // c->SetGrid(); //} //reddraw cahnnel label // c->SetGrid(); if (prefix!=0) { Leg2->AppendPad(); } // redraw axes frame->Draw( "sameaxis" ); // leg->Draw("same"); // update the canvas double xline=1000.; double yline=1000.; if (fname0.Contains("SS")) { xline=800.; yline=800.; } TLine *line=new TLine(200.,200.,xline,yline); line->SetLineStyle(3); //line->Draw(); c->Update(); gPad->RedrawAxis("same"); c->Update(); gPad->Update(); //////////////////////////////////////////////////////////////////////////////////////////// //gROOT->GetListOfSpecials()->Print(); TObjArray *contours = (TObjArray*)gROOT->GetListOfSpecials()->FindObject("contours"); if (contours!=0) { //contours->Print("v"); TList *lcontour1 = (TList*)contours->At(0); //lcontour1->Print(); if (lcontour1!=0) { TGraph *gc1 = (TGraph*)lcontour1->First(); if (gc1!=0) { //gc1->Print(); //if (gc1->GetN() < 10) return; //gc1->SetMarkerStyle(21); //gc1->Draw("alp"); } } } //////////////////////////////////////////////////////////////////////////////////////////// // create plots // store histograms to output file TObjArray* arr = fname0.Tokenize("/"); TObjString* objstring = (TObjString*)arr->At( arr->GetEntries()-1 ); TString outfile = TString(Form("%1.2finvfb_",lumi)) + TString(Form("wband%d_",showOneSigmaExpBand)) + TString(Form("showcms%d_",showcms)) + objstring->GetString().ReplaceAll(".root",""); delete arr; if(!showSR) outfile += TString("_noLabel"); TString prefixsave = TString(prefix).ReplaceAll(" ","_") + Form("%1.2finvfb_",lumi) + Form("wband%d_",showOneSigmaExpBand); CombinationGlob::imgconv( c, Form("plots/atlascls_m0m12_%s",outfile.Data()) ); }
void glDeinit() { atlas().audienceForReposition() -= this; glText.deinit(); drawable.clear(); }