Ejemplo n.º 1
0
void Tile::paintScoreNumber(int aNumber, float aX, float aY)
{
    //Check to see if its a walkable tile
    if(isWalkableTile() == true)
    {
        //Convert the number to a stringstream
        std::stringstream numberStream;
        numberStream << aNumber;
        
        //Next convert the stringstream into a string
        std::string numberString(numberStream.str());
        
        //Cycle through each number in the string and draw it
        for(int i = 0; i < (int)(numberString.length()); i++)
        {
            //Convert the letter in the string back to an int
            int index = atoi(numberString.substr(i,1).c_str());
            
            //Draw the texture that is equivalent to the number
            OpenGLRenderer::getInstance()->drawTexture(m_TileScoreNumbers[index], aX, aY);
            
            //Increment the X value
            aX += m_TileScoreNumbers[index]->getSourceWidth();
        }
    }
}
Ejemplo n.º 2
0
float Tile::getScoreNumberScale(int number, float padding)
{
    //Convert the number to a stringstream
    std::stringstream numberStream;
    numberStream << number;
    
    //Next convert the stringstream into a string
    std::string numberString(numberStream.str());
    
    //Cycle through each number in the string and calculate the total width of the string
    float stringWidth = 0.0f;
    float stringHeight = 0.0f;
    for(int i = 0; i < numberString.length(); i++)
    {
        //Convert the letter in the string back to an int
        int index = atoi(numberString.substr(i,1).c_str());
        
        //Increment the X value
        stringWidth += m_TileScoreNumbers[index]->getSourceWidth();
        stringHeight = stringHeight < m_TileScoreNumbers[index]->getSourceHeight() ? m_TileScoreNumbers[index]->getSourceHeight() : stringHeight;
    }
    
    float scale = fminf(((m_Width - padding * 2.0f) / 2.0f) / stringWidth, 1.0f);
    return scale;
}
Ejemplo n.º 3
0
  string Cancellator::int2string(unsigned number) {
    stringstream numberStringStream;
    numberStringStream << number;
    string numberString(numberStringStream.str());
    for (unsigned index(0); index < numberString.length(); index++) {
      numberString[index] -= '0';
      numberString[index] += 'A';
    }

    return numberString;
  }
void IntervalProgressDisplay::EllipticalPaintStrategy::drawCurrentBeatValue(QPainter &p, const QRectF &rect, const PaintContext &context, const PaintColors &colors)
{
    // draw current beat text in center
    p.setPen(QPen(colors.textColor, 1.0f));
    font.setPointSizeF(context.fontSize);
    p.setFont(font);
    QString numberString(QString::number(context.currentBeat + 1) + " / " + QString::number(context.beatsPerInterval));

    int strWidth =  p.fontMetrics().width(numberString);
    p.drawText(rect.center().x() - strWidth / 2, rect.center().y() + p.fontMetrics().height()/2, numberString);
}
Ejemplo n.º 5
0
  virtual void SetUp() {
    io::ResourceManager::getInstance().clear();

    // convert parameters for test
    std::string numberString(GetParam());

    // load input tables
    executeJsonAndWait(loadFromFile("test/tpcc/load_tpcc_tables.json"));

    // load expected output table
    hyrise::io::StorageManager* sm = hyrise::io::StorageManager::getInstance();
    sm->loadTableFile("refTable", "tpcch/query" + numberString + "_result.tbl");

    // load query from file
    query = loadFromFile("test/tpcch/query" + numberString + ".json");
  }
Ejemplo n.º 6
0
void Tile::paintIndex(int aIndex)
{
    //Convert the index to a stringstream
    std::stringstream numberStream;
    numberStream << aIndex;
    
    //Next convert the stringstream into a string
    std::string numberString(numberStream.str());
    
    //Cycle through each number in the string and calculate the total width of the string
    float stringWidth = 0.0f;
    float stringHeight = 0.0f;
    for(int i = 0; i < (int)(numberString.length()); i++)
    {
        //Convert the letter in the string back to an int
        int index = atoi(numberString.substr(i,1).c_str());
        
        //Increment the X value
        stringWidth += m_TileIndexNumbers[index]->getSourceWidth();
        stringHeight = stringHeight < m_TileIndexNumbers[index]->getSourceHeight() ? m_TileIndexNumbers[index]->getSourceHeight() : stringHeight;
    }
    
    float padding = 4.0f;
    float scale = fminf((m_Width - padding) / stringWidth, 1.0f);
    float scaledWidth = stringWidth * scale;
    float scaledHeight = stringHeight * scale;
    
    //Calculate the x and y position based on the string width and height
    float x = getX() + (getWidth() - scaledWidth) / 2.0f;
    float y = getY() + (getHeight() - scaledHeight) / 2.0f;
    for(int i = 0; i < (int)(numberString.length()); i++)
    {
        //Convert the letter in the string back to an int
        int index = atoi(numberString.substr(i,1).c_str());
        
        //Calculate the scaled width and height
        float width = m_TileIndexNumbers[index]->getSourceWidth() * scale;
        float height = m_TileIndexNumbers[index]->getSourceHeight() * scale;
        
        //Draw the texture that is equivalent to the number
        OpenGLRenderer::getInstance()->drawTexture(m_TileIndexNumbers[index], x, y, width, height);
        
        //Increment the X value
        x += width;
    }
}
Ejemplo n.º 7
0
void Node::print(int iterationNumber, bool lastIteration) {
  string fileName(name);
  if(lastIteration)
    fileName.append("_final");
  char numberChar[10];
  sprintf(numberChar, "%d", iterationNumber);
  string numberString(numberChar);
  fileName.append(".");
  fileName.append(numberString);

  ofstream out(fileName.c_str());  // Open file
  if(!out) {
    cout << "Can't open output file: " << fileName << endl;
    exit(1);
  }

  clustering.print(out);
  out.close();
}
Ejemplo n.º 8
0
void IntervalProgressDisplay::paintElliptical(QPainter &p, QColor textColor, int hRadius, int vRadius){
    if (beats <= 32) {
        drawBeatCircles(p, hRadius, vRadius, beats, 0);//draw a ellipse
    } else {
        int elementsInOuterEllipse= beats / 2;
        int elementsInNestedEllipse = beats - elementsInOuterEllipse;
        drawBeatCircles(p, hRadius, vRadius, elementsInOuterEllipse, 0);
        drawBeatCircles(p, (int) (hRadius * 0.75), (int) (vRadius * 0.75), elementsInNestedEllipse, elementsInOuterEllipse);
    }
    //drawCircles(&p, radius, beats, 0);

    //draw current beat text in center
    p.setPen(textColor);//use text color form pallete, allowing style sheet
    QString numberString( QString::number(currentBeat + 1) + " / " + QString::number(beats));
//    if(currentBeat + 1 < 10){
//        numberString.insert(0, ' ');
//    }
    int strWidth = fontMetrics().width(numberString);
    p.drawText(centerX - strWidth / 2, centerY + fontMetrics().height()/2 , numberString);
    //p.drawText(5, fontMetrics().height(), numberString);
}
Ejemplo n.º 9
0
QString CCard::description()
{
    QString s,s2;
    s=type->name+" ";
    switch (suit) {
    case SUIT_FANGKUAI:
        s2="♦";
        break;
    case SUIT_HEITAO:
        s2="♠";
        break;
    case SUIT_HONGTAO:
        s2="♥";
        break;
    case SUIT_MEIHUA:
        s2="♣";
        break;
    default:
        break;
    }
    s+=s2+numberString();
    return s;
}
Ejemplo n.º 10
0
ConstantToken* PreprocessorLexer::scanNumber(const std::string& input, size_t& end) const
{
    std::string numberString("");
    ConstantToken::Base base = ConstantToken::BASE_10;
    ConstantToken::ConstantType type = ConstantToken::TYPE_INT;
    bool hasExponent = false;
    bool (*pred)(const char ref) = &isDigit;

    size_t pos = 0;
    for (bool atEnd = false; ((! atEnd) && (pos < input.length())); ++pos) {
        const char top = input[pos];
        const char next = ((pos < (input.length() - 1)) ? input[pos + 1] : '\0');

        if ((pred != 0) && ((*pred)(top) == true)) {
            numberString += top;
            if ((pos == 0) && (top == '0')) {
                if ((next == 'x') || (next == 'X')) {
                    numberString += next;
                    ++pos;
                    pred = &isHexDigit;
                    base = ConstantToken::BASE_16;
                } else if (next == '.')
                    type = ConstantToken::TYPE_FLOAT;
                else {
                    pred = &isOctalDigit;
                    base = ConstantToken::BASE_8;
                }
            }

            switch (next) {
                case 'u':
                case 'U':
                    atEnd = true;
                    if (type == ConstantToken::TYPE_INT) {
                        numberString += next;
                        ++pos;
                        type = ConstantToken::TYPE_UINT;
                    }
                    break;

                case 'f':
                case 'F':
                    atEnd = true;
                    if (type == ConstantToken::TYPE_FLOAT) {
                        numberString += next;
                        ++pos;
                    }
                    break;

                case '.':
                    if (base == ConstantToken::BASE_10) {
                        type = ConstantToken::TYPE_FLOAT;
                        numberString += next;
                        ++pos;
                    }
                    break;

                case 'e':
                case 'E':
                    if (type == ConstantToken::TYPE_FLOAT) {
                        hasExponent = true;
                        numberString += next;
                        ++pos;
                    }
                    break;

                default:
                    break;
            }
        }  else if ((top == 'f') && (type == ConstantToken::TYPE_FLOAT)) {
            numberString += top;
        } else if ((top == '.') && (base == ConstantToken::BASE_10)) {
            // Accept the dot '.' only, if it is not the first character or
            // if a digit is following to avoid invalid ".f" strings.
            //
            if ((pos > 0) || (isDigit(next) == true)) {
                type = ConstantToken::TYPE_FLOAT;
                numberString += top;
            }
        } else if (((top == '+') || (top == '-')) && (hasExponent == true)) {
            numberString += top;
        } else
            break;
    }   // for (pos

    end = (pos > 0) ? --pos : 0;
    if (numberString.empty() == true)
        return 0;

    return new ConstantToken(PreprocessorTerminals::ID_CONSTANT, numberString, type, base);
}
Ejemplo n.º 11
0
ConstantToken* Lexer::scanNumber(const int tokenID) throw (std::runtime_error)
{
    std::string numberString("");
    ConstantToken::Base base = ConstantToken::BASE_10;
    ConstantToken::ConstantType type = ConstantToken::TYPE_INT;
    bool hasExponent = false;
    bool (*pred)(const char ref) = &isDigit;

    size_t pos = 0;
    for (bool atEnd = false; (! atEnd); ++pos) {
        if ((pred != 0) && ((*pred)(peek_) == true)) {
            numberString += peek_;

            if ((pos == 0) && (peek_ == '0')) {
                if ((nextChar() == 'x') || (nextChar() == 'X')) {
                    numberString += readChar();
                    ++pos;
                    pred = &isHexDigit;
                    base = ConstantToken::BASE_16;
                } else if (nextChar() == '.')
                    type = ConstantToken::TYPE_FLOAT;
                else {
                    pred = &isOctalDigit;
                    base = ConstantToken::BASE_8;
                }
            }

            switch (nextChar()) {
                case 'u':
                case 'U':
                    atEnd = true;
                    if (type == ConstantToken::TYPE_INT) {
                        numberString += readChar();
                        ++pos;
                        type = ConstantToken::TYPE_UINT;
                    }
                    break;

                case 'f':
                case 'F':
                    atEnd = true;
                    if (type == ConstantToken::TYPE_FLOAT) {
                        numberString += readChar();
                        ++pos;
                    }
                    break;

                case '.':
                    if (base == ConstantToken::BASE_10) {
                        type = ConstantToken::TYPE_FLOAT;
                        numberString += readChar();
                        ++pos;
                    }
                    break;

                case 'e':
                case 'E':
                    if (type == ConstantToken::TYPE_FLOAT) {
                        hasExponent = true;
                        numberString += readChar();
                        ++pos;
                    }
                    break;

                default:
                    if (! (*pred)(nextChar()))
                        atEnd = true;
                    break;
            }   // switch
        }
        else if ((peek_ == 'f') && (type == ConstantToken::TYPE_FLOAT))
            numberString += peek_;
        else if ((peek_ == '.') && (base == ConstantToken::BASE_10))
        {
            // Accept the dot '.' only, if it is not the first character or
            // if a digit is following to avoid invalid ".f" strings.
            //
            if ((pos > 0) || (isDigit(nextChar()) == true)) {
                type = ConstantToken::TYPE_FLOAT;
                numberString += peek_;
            }
        }
        else if (((peek_ == '+') || (peek_ == '-')) && (hasExponent == true)) {
            numberString += peek_;
        } else
            break;

        if (! atEnd)
            readChar();
    }   // for (pos

    if (numberString.empty() == true)
        return 0;

    return new ConstantToken(tokenID, numberString, type, base);
}
Ejemplo n.º 12
0
void Tile::paintScoreNumber(int number, ScoreNumberPosition position, float scale, float padding)
{
    //Check to see if its a walkable tile
    if(isWalkableTile() == true)
    {
        //Convert the number to a stringstream
        std::stringstream numberStream;
        numberStream << number;
        
        //Next convert the stringstream into a string
        std::string numberString(numberStream.str());
        
        //Cycle through each number in the string and calculate the total width of the string
        float stringWidth = 0.0f;
        float stringHeight = 0.0f;
        for(int i = 0; i < numberString.length(); i++)
        {
            //Convert the letter in the string back to an int
            int index = atoi(numberString.substr(i,1).c_str());
            
            //Increment the X value
            stringWidth += m_TileScoreNumbers[index]->getSourceWidth();
            stringHeight = stringHeight < m_TileScoreNumbers[index]->getSourceHeight() ? m_TileScoreNumbers[index]->getSourceHeight() : stringHeight;
        }
        
        float scaledWidth = stringWidth * scale;
        float scaledHeight = stringHeight * scale;
        float x = 0.0f;
        float y = 0.0f;
        
        //Calculate the x and y position based on the string width and height
        switch (position)
        {
            case TopLeft:
            x = getX() + padding;
            y = getY() + padding;
            break;

            case BottomLeft:
            x = getX() + padding;
            y = getY() + getHeight() - scaledHeight - padding;
            break;

            case BottomRight:
            x = getX() + getWidth() - scaledWidth - padding;
            y = getY() + getHeight() - scaledHeight - padding;
            break;
        }
        
        //Cycle through each number in the string and draw it
        for(int i = 0; i < numberString.length(); i++)
        {
            //Convert the letter in the string back to an int
            int index = atoi(numberString.substr(i,1).c_str());
            
            //Calculate the scaled width and height
            float width = m_TileScoreNumbers[index]->getSourceWidth() * scale;
            float height = m_TileScoreNumbers[index]->getSourceHeight() * scale;
            
            //Draw the texture that is equivalent to the number
            OpenGLRenderer::getInstance()->drawTexture(m_TileScoreNumbers[index], x, y, width, height);
            
            //Increment the X value
            x += m_TileScoreNumbers[index]->getSourceWidth() * scale;
        }
    }
}
Ejemplo n.º 13
0
/**
 * This function fits TH2F slices with a selected fitType function (gaussian, lorentz, ...).
 */
TGraphErrors* fit2DProj(TString name, TString path, int minEntries, int rebinX, int rebinY, int fitType,
                        TFile * outputFile, const TString & resonanceType, const double & xDisplace, const TString & append) {

  //Read the TH2 from file
  TFile *inputFile = new TFile(path);
  TH2 * histo = (TH2*) inputFile->Get(name);
  if( rebinX > 0 ) histo->RebinX(rebinX);
  if( rebinY > 0 ) histo->RebinY(rebinY);

  //Declare some variables
  TH1 * histoY;
  TString nameY;
  std::vector<double> Ftop;
  std::vector<double> Fwidth;
  std::vector<double> Fmass;
  std::vector<double> Etop;
  std::vector<double> Ewidth;
  std::vector<double> Emass;
  std::vector<double> Fchi2;
  std::vector<double> Xcenter;
  std::vector<double> Ex;

  TString fileOutName("fitCompare2"+name);
  fileOutName += append;
  fileOutName += ".root";
  TFile *fileOut=new TFile(fileOutName,"RECREATE");

  for (int i=1; i<=(histo->GetXaxis()->GetNbins());i++) {

    //Project on Y (set name and title)
    std::stringstream number;
    number << i;
    TString numberString(number.str());
    nameY = name + "_" + numberString;
    // std::cout << "nameY  " << nameY << std::endl;

    histoY = histo->ProjectionY(nameY, i, i);

    double xBin = histo->GetXaxis()->GetBinCenter(i);
    std::stringstream xBinString;
    xBinString << xBin;
    TString title("Projection of x = ");
    title += xBinString.str();

    histoY->SetName(title);

    if (histoY->GetEntries() > minEntries) {

      //Make the dirty work!
      TF1 *fit;
      std::cout << "fitType = " << fitType << std::endl;
      if(fitType == 1) fit = gaussianFit(histoY, resonanceType);
      else if(fitType == 2) fit = lorentzianFit(histoY, resonanceType);
      else if(fitType == 3) fit = linLorentzianFit(histoY);
      else {
	std::cout<<"Wrong fit type: 1=gaussian, 2=lorentzian, 3=lorentzian+linear."<<std::endl;
	abort();
      }

      double *par = fit->GetParameters();
      double *err = fit->GetParErrors();

      // Check the histogram alone
      TCanvas *canvas = new TCanvas(nameY+"alone", nameY+" alone");
      histoY->Draw();
      canvas->Write();

      // Only for check
      TCanvas *c = new TCanvas(nameY, nameY);

      histoY->Draw();
      fit->Draw("same");
      fileOut->cd();
      c->Write();

      if( par[0] == par[0] ) {
        //Store the fit results
        Ftop.push_back(par[0]);
        Fwidth.push_back(fabs(par[1]));//sometimes the gaussian has negative width (checked with Rene Brun)
        Fmass.push_back(par[2]);
        Etop.push_back(err[0]);
        Ewidth.push_back(err[1]);
        Emass.push_back(err[2]);

        Fchi2.push_back(fit->GetChisquare()/fit->GetNDF());

        double xx= histo->GetXaxis()->GetBinCenter(i);
        Xcenter.push_back(xx);
        double ex = 0;
        Ex.push_back(ex); 
      }
      else {
        // Skip nan
        std::cout << "Skipping nan" << std::endl;
        Ftop.push_back(0);
        Fwidth.push_back(0);
        Fmass.push_back(0);
        Etop.push_back(1);
        Ewidth.push_back(1);
        Emass.push_back(1);

        Fchi2.push_back(100000);

        Xcenter.push_back(0);
        Ex.push_back(1); 
      }
    }
  }

  fileOut->Close();

  //Plots the fit results in  TGraphs
  const int nn= Ftop.size();                   
  double x[nn],ym[nn],e[nn],eym[nn];
  double yw[nn],eyw[nn],yc[nn];

  // std::cout << "number of bins = " << nn << std::endl;
  // std::cout << "Values:" << std::endl;

  for (int j=0;j<nn;j++){
    // std::cout << "xCenter["<<j<<"] = " << Xcenter[j] << std::endl;
    x[j]=Xcenter[j]+xDisplace;
    // std::cout << "Fmass["<<j<<"] = " << Fmass[j] << std::endl;
    ym[j]=Fmass[j];
    // std::cout << "Emass["<<j<<"] = " << Emass[j] << std::endl;
    eym[j]=Emass[j];
    // std::cout << "Fwidth["<<j<<"] = " << Fwidth[j] << std::endl;
    yw[j]=Fwidth[j];
    // std::cout << "Ewidth["<<j<<"] = " << Ewidth[j] << std::endl;
    eyw[j]=Ewidth[j];
    // std::cout << "Fchi2["<<j<<"] = " << Fchi2[j] << std::endl;
    yc[j]=Fchi2[j];
    e[j]=0;
  }

  TGraphErrors *grM = new TGraphErrors(nn,x,ym,e,eym);
  grM->SetTitle(name+"_M");
  grM->SetName(name+"_M");
  TGraphErrors *grW = new TGraphErrors(nn,x,yw,e,eyw);
  grW->SetTitle(name+"_W");
  grW->SetName(name+"_W");
  TGraphErrors *grC = new TGraphErrors(nn,x,yc,e,e);
  grC->SetTitle(name+"_chi2");
  grC->SetName(name+"_chi2");

  grM->SetMarkerColor(4);
  grM->SetMarkerStyle(20);
  grW->SetMarkerColor(4);
  grW->SetMarkerStyle(20);
  grC->SetMarkerColor(4);
  grC->SetMarkerStyle(20);

  //Draw and save the graphs
  outputFile->cd();
  TCanvas * c1 = new TCanvas(name+"_W",name+"_W");
  c1->cd();
  grW->Draw("AP");
  c1->Write();
  TCanvas * c2 = new TCanvas(name+"_M",name+"_M");
  c2->cd();
  grM->Draw("AP");
  c2->Write();
  TCanvas * c3 = new TCanvas(name+"_C",name+"_C");
  c3->cd();
  grC->Draw("AP");
  c3->Write();

  return grM;
}