示例#1
0
Interval
GroupManager::calculateInterval
  (MillisecondsSince1970 timeSlot, map<Name, Blob>& memberKeys)
{
  // Prepare.
  Interval positiveResult;
  Interval negativeResult;
  memberKeys.clear();

  // Get the all intervals from the schedules.
  vector<string> scheduleNames;
  database_->listAllScheduleNames(scheduleNames);
  for (size_t i = 0; i < scheduleNames.size(); ++i) {
    string& scheduleName = scheduleNames[i];

    ptr_lib::shared_ptr<Schedule> schedule = database_->getSchedule(scheduleName);
    Schedule::Result result = schedule->getCoveringInterval(timeSlot);
    Interval tempInterval = result.interval;

    if (result.isPositive) {
      if (!positiveResult.isValid())
        positiveResult = tempInterval;
      positiveResult.intersectWith(tempInterval);

      map<Name, Blob> map;
      database_->getScheduleMembers(scheduleName, map);
      memberKeys.insert(map.begin(), map.end());
    }
    else {
      if (!negativeResult.isValid())
        negativeResult = tempInterval;
      negativeResult.intersectWith(tempInterval);
    }
  }
  if (!positiveResult.isValid())
    // Return an invalid interval when there is no member which has an
    // interval covering the time slot.
    return Interval(false);

  // Get the final interval result.
  Interval finalInterval;
  if (negativeResult.isValid())
    finalInterval = positiveResult.intersectWith(negativeResult);
  else
    finalInterval = positiveResult;

  return finalInterval;
}
Interval
Schedule::getCoveringInterval(const TimeStamp& tp) const
{
  Interval blackResult;
  Interval whiteResult(true);
  Interval tempInterval;
  bool isPositive;

  // get the blackResult
  for (const RepetitiveInterval& element : m_blackIntervalList) {
    std::tie(isPositive, tempInterval) = element.getInterval(tp);
    if (isPositive == true) {
      // tempInterval is a black repetitive interval covering the time stamp, return empty interval
      return Interval(true);
    }
    else {
      // tempInterval is not covering the time stamp, && the tempInterval to the blackResult
      if (!blackResult.isValid())
        blackResult = tempInterval;
      else
        blackResult && tempInterval;
    }
  }

  // get the whiteResult
  for (const RepetitiveInterval& element : m_whiteIntervalList) {
    std::tie(isPositive, tempInterval) = element.getInterval(tp);
    if (isPositive == true) {
      // tempInterval is a white repetitive interval covering the time stamp, || to the white result
      whiteResult || tempInterval;
    }
  }

  return whiteResult && blackResult;
}
示例#3
0
void SectorHistogram::construct( const Billon &billon, const Interval<uint> &sliceInterval, const Interval<int> &intensity,
								 const uint &zMotionMin, const int &radiusAroundPith )
{
	clear();

	if ( billon.hasPith() && sliceInterval.isValid() && sliceInterval.width() > 0 )
	{
		const int &width = billon.n_cols;
		const int &height = billon.n_rows;
		const qreal squareRadius = qPow(radiusAroundPith,2);

		fill(0.,PieChartSingleton::getInstance()->nbSectors());

		QVector<int> circleLines;
		circleLines.reserve(2*radiusAroundPith+1);
		for ( int lineIndex=-radiusAroundPith ; lineIndex<=radiusAroundPith ; ++lineIndex )
		{
			circleLines.append(qSqrt(squareRadius-qPow(lineIndex,2)));
		}

		QVector<int>::ConstIterator circlesLinesIterator;
		int iRadius;
		uint diff;
		iCoord2D currentPos;

		// Calcul du diagramme en parcourant les tranches du billon comprises dans l'intervalle
		for ( uint k=sliceInterval.min() ; k<=sliceInterval.max() ; ++k )
		{
			const Slice &currentSlice = billon.slice(k);
			const Slice &previousSlice = billon.previousSlice(k);
			const iCoord2D &currentPithCoord = billon.pithCoord(k);
			currentPos.y = currentPithCoord.y-radiusAroundPith;
			for ( circlesLinesIterator = circleLines.constBegin() ; circlesLinesIterator != circleLines.constEnd() ; ++circlesLinesIterator )
			{
				iRadius = *circlesLinesIterator;
				currentPos.x = currentPithCoord.x-iRadius;
				iRadius += currentPithCoord.x;
				while ( currentPos.x <= iRadius )
				{
					if ( currentPos.x < width && currentPos.y < height && intensity.containsOpen(currentSlice.at(currentPos.y,currentPos.x)) &&
						 intensity.containsOpen(previousSlice.at(currentPos.y,currentPos.x)) )
					{
						diff = billon.zMotion(currentPos.x,currentPos.y,k);
						//if ( motionInterval.containsClosed(diff) )
						if ( diff >= zMotionMin )
						{
							(*this)[PieChartSingleton::getInstance()->sectorIndexOfAngle( currentPithCoord.angle(currentPos) )] += diff-zMotionMin;
						}
					}
					currentPos.x++;
				}
				currentPos.y++;
			}
		}
	}
}
示例#4
0
void
GroupManager::getGroupKey
  (MillisecondsSince1970 timeSlot, vector<ptr_lib::shared_ptr<Data> >& result,
   bool needRegenerate)
{
  result.clear();
  map<Name, Blob> memberKeys;

  // Get the time interval.
  Interval finalInterval = calculateInterval(timeSlot, memberKeys);
  if (finalInterval.isValid() == false)
    return;

  string startTimeStamp = Schedule::toIsoString(finalInterval.getStartTime());
  string endTimeStamp = Schedule::toIsoString(finalInterval.getEndTime());

  // Generate the private and public keys.
  Blob privateKeyBlob;
  Blob publicKeyBlob;
  Name eKeyName(namespace_);
  eKeyName.append(Encryptor::getNAME_COMPONENT_E_KEY()).append(startTimeStamp)
    .append(endTimeStamp);

  if (!needRegenerate && database_->hasEKey(eKeyName))
    getEKey(eKeyName, publicKeyBlob, privateKeyBlob);
  else {
    generateKeyPair(privateKeyBlob, publicKeyBlob);
    if (database_->hasEKey(eKeyName))
      deleteEKey(eKeyName);
    addEKey(eKeyName, publicKeyBlob, privateKeyBlob);
  }

  // Add the first element to the result.
  // The E-KEY (public key) data packet name convention is:
  // /<data_type>/E-KEY/[start-ts]/[end-ts]
  ptr_lib::shared_ptr<Data> data = createEKeyData
    (startTimeStamp, endTimeStamp, publicKeyBlob);
  result.push_back(data);

  // Encrypt the private key with the public key from each member's certificate.
  for (map<Name, Blob>::iterator i = memberKeys.begin(); i != memberKeys.end(); ++i) {
    const Name& keyName = i->first;
    Blob& certificateKey = i->second;

    // Generate the name of the packet.
    // The D-KEY (private key) data packet name convention is:
    // /<data_type>/D-KEY/[start-ts]/[end-ts]/[member-name]
    data = createDKeyData
      (startTimeStamp, endTimeStamp, keyName, privateKeyBlob, certificateKey);
    result.push_back(data);
  }
}
void PlotConcavityPointSerieCurve::update( const ConcavityPointSerieCurve &curve, const Interval<qreal> &angularInterval )
{
	QVector<QPointF> datasMinConcavity(0);
	QVector<QPointF> datasMaxConcavity(0);
	QVector<QPointF> datasMinKnotArea(0);
	QVector<QPointF> datasMaxKnotArea(0);

	const int nbMaxConcavityPoints = curve.nbMaxConcavityPoints();
	const int nbMinConcavityPoints = curve.nbMinConcavityPoints();

	if ( nbMaxConcavityPoints || nbMinConcavityPoints )
	{
		const qreal minAngle = angularInterval.min();
		const qreal maxAngle = angularInterval.isValid() ? angularInterval.max() : angularInterval.max()+TWO_PI;

		int firstX, lastX;
		firstX = lastX = 0;
		if ( nbMaxConcavityPoints>0 && nbMinConcavityPoints>0 )
		{
			firstX = qMin(curve.maxConcavityPointsSerie().first().x,curve.minConcavityPointsSerie().first().x);
			lastX = qMax(curve.maxConcavityPointsSerie().last().x,curve.minConcavityPointsSerie().last().x);
		}
		else if ( nbMaxConcavityPoints>0 )
		{
			firstX = curve.maxConcavityPointsSerie().first().x;
			lastX = curve.maxConcavityPointsSerie().last().x;
		}
		else if ( nbMinConcavityPoints>0 )
		{
			firstX = curve.minConcavityPointsSerie().first().x;
			lastX = curve.minConcavityPointsSerie().last().x;
		}

		if ( curve.nbMinConcavityPoints() > 0 )
		{
			datasMinConcavity.reserve(curve.nbMinConcavityPoints());
			QVector<rCoord2D>::ConstIterator begin = curve.minConcavityPointsSerie().begin();
			const QVector<rCoord2D>::ConstIterator end = curve.minConcavityPointsSerie().end();
			while ( begin != end )
			{
				datasMinConcavity.append(QPointF(begin->x,begin->y));
				++begin;
			}
			datasMinKnotArea.resize(2);
			datasMinKnotArea[0] = QPointF( firstX, minAngle*RAD_TO_DEG_FACT );
			datasMinKnotArea[1] = QPointF( lastX, minAngle*RAD_TO_DEG_FACT );
		}
		if ( curve.nbMaxConcavityPoints() > 0 )
		{
			datasMaxConcavity.reserve(curve.nbMaxConcavityPoints());
			QVector<rCoord2D>::ConstIterator begin = curve.maxConcavityPointsSerie().begin();
			const QVector<rCoord2D>::ConstIterator end = curve.maxConcavityPointsSerie().end();
			while ( begin != end )
			{
				datasMaxConcavity.append(QPointF(begin->x,begin->y));
				++begin;
			}
			datasMaxKnotArea.resize(2);
			datasMaxKnotArea[0] = QPointF( firstX, maxAngle*RAD_TO_DEG_FACT );
			datasMaxKnotArea[1] = QPointF( lastX, maxAngle*RAD_TO_DEG_FACT );
		}
	}

	_minConcavityPointsData.setSamples(datasMinConcavity);
	_maxConcavityPointsData.setSamples(datasMaxConcavity);
	_minKnotAreaAngle.setSamples(datasMinKnotArea);
	_maxKnotAreaAngle.setSamples(datasMaxKnotArea);
}