Ejemplo n.º 1
0
 index_type
 emplace(S inString) {
   switch (access) {
     case access_type::read_only: {
       auto index = string2index(inString);
       if (index != Dictionary::unknownIndex) {
         return index;
       }
       throw illegal_access_exception();
     }
     case access_type::write_shared: {
       auto index = string2index(inString);
       if (index != Dictionary::unknownIndex) {
         return index;
       }
       index = mPersistent.get()->size();
       int numberOfTries = 0;
       while (true) {
         try {
           // emplace tries to allocate
           // a node even if one already exists.
           // That's why we check for it first.
           assert(mPersistent.get());
           mPersistent.get()->emplace(jerome::shared::to_string(inString, mPersistent.get()->get_allocator()), index);
           break;
         } catch (const boost::interprocess::bad_alloc& error) {
           if (++numberOfTries > 3) throw error;
           mPersistent.grow(mPersistent.storageSize());
         }
       }
       return index;
     }
     case access_type::write_private: {
       auto index = string2index(inString);
       if (index != Dictionary::unknownIndex) {
         return index;
       }
       assert(mTransient.get());
       index = (mPersistent ? mPersistent.get()->size() : 0)
       + mTransient.get()->size();
       mTransient.get()->emplace(std::string(inString), index);
       return index;
     }
   }
 }
Ejemplo n.º 2
0
bool KITTIReader::ReadCalibrationCam2Cam(QVector<CamProperties> & cprops, double & cornerdist, const QString & fname)
{
    // try opening file
    QFile file(fname);
    if(!file.open(QIODevice::ReadOnly)) {
        QMessageBox::information(0, "Error reading KITTI calibration file", QString("%1: %2").arg(fname).arg(file.errorString()));
        return false;
    }

    QTextStream in(&file);
    int first;
    int curr = 0;
    int max = 0;

    // read all lines
    while(!in.atEnd()) {
        QString line = in.readLine();
        QString numbers = line, name = line;
        QStringList n;

        first = line.indexOf(':');

        // get string between ':' and end and split
        if (first != -1) {
            name.truncate(first);
            numbers.remove(0, first + 1);
            curr = string2index(name.trimmed());
        }
        if (first != -1) n = numbers.split(QRegExp("\\s"), QString::SkipEmptyParts);

        if (curr >= cprops.size()) cprops.resize(curr + 1);
        if (curr > max) max = curr;

        // find correct lines and assign matrix values
        if (line.startsWith("S_")){
            if (line.startsWith("S_rect_")){
                cprops[curr].S_rect = List2Int2(n);
            }
            else{
                cprops[curr].S = List2Int2(n);
            }
        }

        if (line.startsWith("K_")){
            cprops[curr].K = List2Matrix(n);
        }

        if (line.startsWith("D_")){
            cprops[curr].D = List2Float5(n);
        }

        if (line.startsWith("R_")){
            if (line.startsWith("R_rect")){
                cprops[curr].R_rect = List2Matrix(n);
            }
            else{
                cprops[curr].R = List2Matrix(n);
            }
        }

        if (line.startsWith("T_")){
            cprops[curr].T = List2Vector3(n);
        }

        if (line.startsWith("P_rect_")){
            cprops[curr].P_rect = List2Transform(n);
        }

        if (line.startsWith("corner_dist")){
            cornerdist = n.at(0).trimmed().toDouble();
        }
    }

    cprops.resize(max + 1);

    file.close();
    return true;
}
Ejemplo n.º 3
0
int main(int argc, char ** argv) {
  uint32_t i, cs0, cs1, checksum;
  uint32_t nthreads, ngames, totgames;
  if (argc < 4) {
    fprintf(stderr, "incorrect number of arguments\n");
    fprintf(stderr, "required: <#players> <card1> <card2>\n");
    return 1;
  }
  nthreads = sysconf(_SC_NPROCESSORS_ONLN);
  ngames = MAXGAMES/nthreads;
  totgames = ngames*nthreads;
  printf("cores:%d\n", nthreads);
  printf("games:%d\n", totgames);
  // read the arguments and create the known cards
  np = atoi(argv[1]);
  kc = argc-2;
  for (i=0; i<kc; i++) {
    as[i] = string2index(argv[i+2]);
    if (as[i] >= 52) {
      fprintf(stderr, "wrong card identifier: %s\n", argv[i+2]);
      return 1;
    }
  }
  // initialize the rng seed and the mutex
  srand(time(NULL));
  pthread_mutex_init(&tlock, NULL);
  pthread_mutex_unlock(&tlock);
  // run the simulation threads
  tpool = (pthread_t *)malloc(nthreads*sizeof(pthread_t));
  for (i=0; i<nthreads; i++) {
    pthread_create(&tpool[i], NULL, simulator, (void *)(&ngames));
  }
  // wait for the threads to finish
  for (i=0; i<nthreads; i++) {
    pthread_join(tpool[i], NULL);
  }
  // check correctness (sum counters)
  checksum = 0;
  for (i=0; i<3; i++) checksum += counters[i];
  if (checksum != totgames) {
    fprintf(stderr, "counters do not sum up\n");
    return 1;
  }
  checksum = 0;
  for (i=3; i<12; i++) checksum += counters[i];
  if (checksum != totgames) {
    fprintf(stderr, "counters do not sum up\n");
    return 1;
  }
  // show the results
  printf("win:%.3f\n", ((float)counters[WIN])/totgames);
  printf("draw:%.3f\n", ((float)counters[DRAW])/totgames);
  printf("pair:%.3f\n", ((float)counters[PAIR])/totgames);
  printf("two-pairs:%.3f\n", ((float)counters[TWOPAIRS])/totgames);
  printf("three-of-a-kind:%.3f\n", ((float)counters[TOAK])/totgames);
  printf("straight:%.3f\n", ((float)counters[STRAIGHT])/totgames);
  printf("flush:%.3f\n", ((float)counters[FLUSH])/totgames);
  printf("full-house:%.3f\n", ((float)counters[FULLHOUSE])/totgames);
  printf("four-of-a-kind:%.3f\n", ((float)counters[FOAK])/totgames);
  printf("straight-flush:%.3f\n", ((float)counters[STRFLUSH])/totgames);
  // clear all
  pthread_mutex_destroy(&tlock);
  return 0;
}