示例#1
0
void PageFrame::componentCopy(PageComponent* aComponent)
{
    PageSelectionDialog dialog(this);

    dialog.ui->titleLabel->setText("Выберите раздел, в который будет скопирован компонент:");

    if (dialog.exec())
    {
        int aRow=dialog.ui->pagesListWidget->currentRow();

        if (aRow==0)
        {
            QMessageBox::information(this, protocolCreatorVersion, "Нельзя вставлять компонент в глобальные переменные");
            return;
        }

        if (mainWindow->ui->pagesTabWidget->widget(aRow-1)==mainWindow->contentPage)
        {
            QMessageBox::information(this, protocolCreatorVersion, "Нельзя вставлять компонент в содержание");
            return;
        }

        QByteArray aBuffer;
        QDataStream aStream(&aBuffer, QIODevice::ReadWrite);

        aComponent->saveToStream(aStream);

        aStream.device()->seek(0);

        QString aMagicWord;
        aStream >> aMagicWord;

        PageComponent *aComponent=0;

        if (aMagicWord=="ComponentText")
        {
            aComponent=new ComponentTextFrame(mainWindow->ui->pagesTabWidget->widget(aRow-1));
        }
        else
        if (aMagicWord=="VarExtendedList")
        {
            aComponent=new VariableExtendedListFrame(mainWindow->ui->pagesTabWidget->widget(aRow-1));

            ((VariableExtendedListFrame*)aComponent)->mIsTable=true;
            ((VariableExtendedListFrame*)aComponent)->ui->titleLabel->setVisible(false);
            ((VariableExtendedListFrame*)aComponent)->ui->nameEdit->setText("Таблица");
            ((VariableExtendedListFrame*)aComponent)->ui->varNameEdit->setText("Table");
            ((VariableExtendedListFrame*)aComponent)->ui->editButton->setFlat(false);
        }

        if (aComponent)
        {
            ((PageFrame*)mainWindow->ui->pagesTabWidget->widget(aRow-1))->addComponent(aComponent);
            aComponent->loadFromStream(aStream);
        }
    }
示例#2
0
void WordXML::saveToFile(QString aFileName)
{
    QFile aFile(aFileName);
    aFile.open(QIODevice::WriteOnly);

    QTextStream aStream(&aFile);
    aStream.setCodec("UTF-8");

    writeToStream(aStream);
}
示例#3
0
 bool ArgumentParser::Parse(const char ** iArgv, int iArgc, const std::string& iDefinition)
 {
     bool aResult = false;
     
     boost::property_tree::ptree aTree;
     std::istringstream aStream (iDefinition);
     boost::property_tree::read_json(aStream, aTree);
     
     D(aTree.get<std::string>("verbose"));
     return aResult;
 }
示例#4
0
int main(int argc, char* argv[]) {
  if (argc < 2) {
    MAX_COUNTS = 5000000;
  } else {
    std::string valueStr(argv[1]);
    bool has_only_digits = (valueStr.find_first_not_of( "0123456789" ) == std::string::npos);
    if (has_only_digits) {
      std::istringstream aStream(valueStr);
      aStream >> MAX_COUNTS;
    } else {
      std::cerr << "Argument should be an integer\n";
      return 1;
    }
  }
bool JournalDM_Category::Load( const QString& thePath, const QList<JournalDM_IParser*>& theParsers )
{
  QFile aFile( thePath );
  if( !aFile.open( QFile::ReadOnly | QFile::Text ) )
    return false;

  QTextStream aStream( &aFile );
  while( !aStream.atEnd() )
  {
    QString aLine = aStream.readLine();
    myLines.append( aLine );
    GenerateExercises( aLine, theParsers );
  }
  aFile.close();
  return true;
}
示例#6
0
int main(int argc, char *argv[])
{
  std::string input_folder = DEFAULT_INPUT, output_folder = DEFAULT_OUTPUT;
  if(argc >= 2)
  {
    input_folder = argv[1];
    if(argc >= 3)
    {
      output_folder = argv[2];
    }
  }
  std::cout << "input folder: " << input_folder << std::endl;
  
  struct dirent **filelist;
  int fcount = -1;
  bool gray = false;
  fcount = scandir(input_folder.c_str(), &filelist, ppm_select, alphasort);
  if (fcount <= 0)
  {
    fcount = scandir(input_folder.c_str(), &filelist, pgm_select, alphasort);
    gray = true;
  }
  if (fcount <= 0)
  {
    std::cout << "There are no .ppm or .pgm files in this folder! Maybe you have to convert the images first e.g. using" << std::endl
      << "  mogrify -format ppm *.jpg" << std::endl;
    return 0;
  }
  std::cout << "found " << fcount << " files" << std::endl;
  char filename[255];
  sprintf(filename, "%s/init.txt", input_folder.c_str());
  std::ifstream aStream(filename);
  if(!aStream || aStream.eof())
  {
    std::cout << "please create the file \"" << filename 
        << "\" specifying the initial bounding box[es] (x1,y1,x2,y2)" << std::endl;
    return 0;
  }
  char line[255];
  int x1,y1,x2,y2,imgid, width,height;
  std::vector<ObjectBox> boxes;
  while(aStream.getline(line,255))
  {
    x1 = y1 = x2 = y2 = imgid = 0;
    int i = 0;
    for(;line[i] >= '0' && line[i] <= '9'; i++)
      x1 = x1*10 + (line[i] - '0');
    for(i++;line[i] >= '0' && line[i] <= '9'; i++)
      y1 = y1*10 + (line[i] - '0');
    for(i++;line[i] >= '0' && line[i] <= '9'; i++)
      x2 = x2*10 + (line[i] - '0');
    for(i++;line[i] >= '0' && line[i] <= '9'; i++)
      y2 = y2*10 + (line[i] - '0');
    if(line[i] == ',')
      for(i++;line[i] >= '0' && line[i] <= '9'; i++)
        imgid = imgid*10 + (line[i] - '0'); 
    ObjectBox b = {x1,y1,x2-x1,y2-y1,imgid};
    boxes.push_back(b);
  }
  aStream.close();
  
  std::cout << "output folder: " << output_folder << std::endl;
  if (access(output_folder.c_str(), 0) != 0)
  {
    std::cout << "\tdoes not exist -> try to create it" << std::endl;
    if(system(("mkdir "+output_folder).c_str()))
    {
      std::cout << "\t failed to create directory" << std::endl;
      return 0;
    }
  }

  sprintf(filename, "%s/%s", input_folder.c_str(), filelist[0]->d_name);
  int z;
  unsigned char* dummy = gray ? readFromPGM<unsigned char>(filename, width, height) :
                                readFromPPM<unsigned char>(filename, width, height, z);
  delete[] dummy;
    
  // Initialize MultiObjectTLD
#if LOADCLASSIFIERATSTART
  MultiObjectTLD p = MultiObjectTLD::loadClassifier((char*)CLASSIFIERFILENAME);
#else
  MOTLDSettings settings(gray ? COLOR_MODE_GRAY : COLOR_MODE_RGB);
  MultiObjectTLD p(width, height, settings);
#endif
  
#if LEARNMODEOFF
  p.enableLearning(false);
#endif
  
  std::vector<ObjectBox> addBoxes;
  std::vector<ObjectBox>::iterator boxIt = boxes.begin();
  
  sprintf(filename, "%s/output.txt", output_folder.c_str());
  std::ofstream outStream(filename);  

  for (int i=0; i < fcount && (!MAX_FILE_NUMBER || i<MAX_FILE_NUMBER); ++i)
  { 
    // first load the image
    sprintf(filename, "%s/%s", input_folder.c_str(), filelist[i]->d_name);
    int xS, yS, z;
    unsigned char* img = gray ? readFromPGM<unsigned char>(filename, xS, yS) :
                                  readFromPPM<unsigned char>(filename, xS, yS, z);
    // then process it with MultiObjectTLD
    p.processFrame(img);
    
    while(boxIt != boxes.end() && boxIt->objectId == i)
    {
      addBoxes.push_back(*boxIt);
      boxIt++;
    }
    if(addBoxes.size() > 0){
      p.addObjects(addBoxes);
      addBoxes.clear();
    }

    #if OUTPUT_IMAGES>0
    // and save debug image to file
    sprintf(filename, "%s/%s", output_folder.c_str(), filelist[i]->d_name);
    p.writeDebugImage(img,filename);
    #endif
    
    // print current box to output file
    if(p.getValid())
    {
      ObjectBox b = p.getObjectBox();
      if(i > 0)
        outStream << std::endl;
      outStream << b.x << "," << b.y << "," << (b.x + b.width) << "," << (b.y + b.height);
    }
    else
      outStream << std::endl << "NaN,NaN,NaN,NaN";
    delete[] img;
  }
  outStream.close();

  std::cout << "MultiObjectTLD finished!" << std::endl;
#if SAVECLASSIFIERATEND
  std::cout << "Saving ..." << std::endl;
  p.saveClassifier((char*)CLASSIFIERFILENAME);
#endif
  for(int i = 0; i < fcount; i++)
    free(filelist[i]);
  free(filelist);
  
  return 0;
}
示例#7
0
int SDLEngine::Run(void*)
{
  std::cout << "input folder: " << input_folder << std::endl;
  bool gray = false;
  fcount = scandir(input_folder.c_str(), &filelist, ppm_select, alphasort);
  if (fcount <= 0)
  {
    fcount = scandir(input_folder.c_str(), &filelist, pgm_select, alphasort);
    gray = true;
  }
  if (fcount <= 0)
  {
    std::cout << "There are no .ppm or .pgm files in this folder! Maybe you have to convert the images first e.g. using" << std::endl
      << "  mogrify -format ppm *.jpg" << std::endl;
    return 0;
  }
  std::cout << "found " << fcount << " files" << std::endl;
  char filename[255];
  sprintf(filename, "%s/init.txt", input_folder.c_str());
  std::ifstream aStream(filename);
  if(!aStream || aStream.eof())
  {
    std::cout << "please create the file \"" << filename << "\" specifying the initial bounding box (x1,y1,x2,y2)" << std::endl;
    return 0;
  }
  char line[255];
  int x1,y1,x2,y2,imgid, width,height;
  std::vector<ObjectBox> boxes;
  while(aStream.getline(line,255))
  {
    x1 = y1 = x2 = y2 = imgid = 0;
    int i = 0;
    for(;line[i] >= '0' && line[i] <= '9'; i++)
      x1 = x1*10 + (line[i] - '0');
    for(i++;line[i] >= '0' && line[i] <= '9'; i++)
      y1 = y1*10 + (line[i] - '0');
    for(i++;line[i] >= '0' && line[i] <= '9'; i++)
      x2 = x2*10 + (line[i] - '0');
    for(i++;line[i] >= '0' && line[i] <= '9'; i++)
      y2 = y2*10 + (line[i] - '0');
    if(line[i] == ',')
      for(i++;line[i] >= '0' && line[i] <= '9'; i++)
        imgid = imgid*10 + (line[i] - '0'); 
    ObjectBox b = {(float)x1,(float)y1,(float)(x2-x1),(float)(y2-y1),imgid};
    boxes.push_back(b);
  }
  aStream.close();
    
  std::cout << "output folder: " << output_folder << std::endl;
  DIR * dir = opendir(output_folder.c_str());
  if (dir == 0)
  {
    std::cout << "\tdoes not exist -> try to create it" << std::endl;
    if(system(("mkdir "+output_folder).c_str()))
    {
      std::cout << "\t failed to create directory" << std::endl;
      return 0;
    }
  }
  closedir(dir);

  sprintf(filename, "%s/%s", input_folder.c_str(), filelist[0]->d_name);
  int z;
  unsigned char* dummy = gray ? readFromPGM<unsigned char>(filename, width, height) :
                                readFromPPM<unsigned char>(filename, width, height, z);
  delete[] dummy;
    
  // Initialize MultiObjectTLD
  MOTLDSettings s(gray ? COLOR_MODE_GRAY : COLOR_MODE_RGB);
  // s.bbMin = 18;
  MultiObjectTLD p(width, height, s);
  std::vector<ObjectBox> addBoxes;
  std::vector<ObjectBox>::iterator boxIt = boxes.begin();

  if(ivScreen != NULL)
    SDL_FreeSurface(ivScreen);
  ivScreen = SDL_SetVideoMode( width, height, 0, SDL_HWSURFACE | SDL_DOUBLEBUF); // | SDL_RESIZABLE
  SDL_WM_SetCaption("MultiObjectTLD", 0 );

  sprintf(filename, "%s/output.txt", output_folder.c_str());
  std::ofstream outStream(filename);  

  for (int i=0; i < fcount && (!MAX_FILE_NUMBER || i<MAX_FILE_NUMBER); ++i)
  {
    // first load the image
    sprintf(filename, "%s/%s", input_folder.c_str(), filelist[i]->d_name);
    int xS, yS, z;
    unsigned char* img = gray ? readFromPGM<unsigned char>(filename, xS, yS) :
                                readFromPPM<unsigned char>(filename, xS, yS, z);
    // then process it with MultiObjectTLD
    p.processFrame(img);
    
    while(boxIt != boxes.end() && boxIt->objectId == i)
    {
      addBoxes.push_back(*boxIt);
      boxIt++;
    }
    if(addBoxes.size() > 0){
      p.addObjects(addBoxes);
      addBoxes.clear();
    }
    
    // and save debug image to file
    sprintf(filename, "%s/%s", output_folder.c_str(), filelist[i]->d_name);
    p.writeDebugImage(img,filename);
    displaymax = i;

    // print current box to output file
    if(p.getValid())
    {
      ObjectBox b = p.getObjectBox();
      if(i > 0)
        outStream << std::endl;
      outStream << b.x << "," << b.y << "," << (b.x + b.width) << "," << (b.y + b.height);
    }
    else
      outStream << std::endl << "NaN,NaN,NaN,NaN";
    delete[] img;
    if(ivQuit)
      break;
  }
  outStream.close();
  std::cout << "MultiObjectTLD finished!" << std::endl;
  return 0;
}