Esempio n. 1
0
void VoxelFile::load_fp(QFile & fp)
{
    QDataStream stream(&fp);
    stream.setByteOrder(QDataStream::LittleEndian);
    stream >> x_size;
    stream >> y_size;
    stream >> z_size;
    stream >> x_offset;
    stream >> y_offset;
    stream >> z_offset;
    if (data != NULL)
        delete[] data;
    data = new unsigned char[x_size * y_size * z_size];
    stream.readRawData((char*)data, x_size * y_size * z_size);
    stream.skipRawData(256 * 3);

    // reference points
    points.clear();
    quint8 point_count;
    if (stream.atEnd())
        point_count = 0;
    else
        stream >> point_count;
    QString name;
    qint32 x, y, z;
    for (int i = 0; i < point_count; i++) {
        read_cstring(stream, name);
        stream >> x;
        stream >> y;
        stream >> z;
        points.push_back(ReferencePoint(name, x, y, z));
    }
}
Esempio n. 2
0
  uint64_t Clock::getSchedulerTimeForLocalTime(uint64_t localTime) {
    double noise = 0;
    double simTime = 0;

    boost::mt19937 uGenerator(localTime*hostBlock->blockId);
    boost::normal_distribution<double> normalDist(0,sigma);
    boost::variate_generator<boost::mt19937&, boost::normal_distribution<double> > generator(uGenerator, normalDist);
  
    double minL = 0;
    double maxL = numeric_limits<double>::max();
    list<ReferencePoint>::iterator it;

    cleanReferencePoints();
    for (it = referencePoints.begin(); it != referencePoints.end(); it++) {
      if (it->local == localTime) {
	return it->simulation;
      }
	  
      if (it->local < localTime) {
	minL = max(minL,(double)it->simulation);
      }
	  
      if (it->local > localTime) {
	maxL = min(maxL,(double)it->simulation);
	break; //sorted list
      }
    }
  
    // TODO: noise ?
    //noise = generator();

    double delta =  pow(y0,2) - 4 * (1.0/2.0)*D * (x0+noise-(double)localTime);
    if (delta > 0) {
      double s1 = (-y0 + sqrt(delta)) / D;
      double s2 = (-y0 - sqrt(delta)) / D;
      // we take the value closest to localTime
      if (abs(s1-localTime) < abs(s2-localTime)) {
	simTime = s1;
      } else {
	simTime = s2;
      }
    } else if (delta == 0) {
      simTime = -y0 / D;
    } else {
      cerr << "delta should be positive!" << endl;
      simTime = minL;
    }

    simTime = max(minL,simTime);
    simTime = min(maxL,simTime);

    ReferencePoint p = ReferencePoint(localTime,(uint64_t)simTime); 
    if (it == referencePoints.end()) {
      referencePoints.push_back(p);
    } else {
      referencePoints.insert(it,p);
    }

    return (uint64_t) simTime;
  }
Esempio n. 3
0
  uint64_t Clock::getTimeUS(uint64_t simTime) {
    double localTime = 0;
    double noise = 0;

    boost::mt19937 uGenerator(simTime*hostBlock->blockId);
    boost::normal_distribution<double> normalDist(0,sigma);
    boost::variate_generator<boost::mt19937&, boost::normal_distribution<double> > generator(uGenerator, normalDist);
	
    double minL = 0;
    double maxL = numeric_limits<double>::max();
    list<ReferencePoint>::iterator it;

    cleanReferencePoints();
    for (it = referencePoints.begin(); it != referencePoints.end(); it++) {
      if (it->simulation == simTime) {
	return it->local;
      }	  
      if (it->simulation < simTime) {
	minL = max(minL,(double)it->local);
      }	  
      if (it->simulation > simTime) {
	maxL = min(maxL,(double)it->local);
	break; //sorted list
      }
    }

    // TODO: noise ?
    //noise = generator();

    localTime = (1.0/2.0)*D*pow((double)simTime,2) + y0*((double)simTime) + x0 + noise;
    localTime = max(minL,localTime);
    localTime = min(maxL,localTime);

    ReferencePoint p = ReferencePoint((uint64_t)localTime,simTime); 
    if (it == referencePoints.end()) {
      referencePoints.push_back(p);
    } else {
      referencePoints.insert(it,p);
    }

    return (uint64_t)localTime;
  }
Esempio n. 4
0
template<> ReferencePoint Init::undefined<ReferencePoint>()
{
    double ud = Init::undefined<double>();
    return ReferencePoint(ud, ud, ud, ud, ud);
}
Esempio n. 5
0
void VoxelFile::add_point(const QString & name,
                          int x, int y, int z)
{
    points.push_back(ReferencePoint(name, x, y, z));
}