Example #1
0
void ClusterMaker::generateClusters(Storage::Event* event, unsigned int planeNum)
{
   Storage::Plane* plane = event->getPlane(planeNum);
  if (plane->getNumClusters() > 0)
    throw "ClusterMaker: clusters already exist for this hit";

  for (unsigned int nhit = 0; nhit < plane->getNumHits(); nhit++)
  {
     Storage::Hit* hit = plane->getHit(nhit);
     //std::cout << "addHit: " << nhit  << " isclustered: " <<hit->getCluster() << " isHit: " << hit->getIsHit() << std::endl;
    // If the hit isn't clustered, make a new cluster
    if (!hit->getCluster()) {
       Storage::Cluster* cluster = event->newCluster(planeNum);
      cluster->addHit(hit);
    }

    // Add neighbouring clusters to this hit (this is recursive)
     Storage::Cluster* lastCluster = plane->getCluster(plane->getNumClusters() - 1);
    assert(lastCluster && "ClusterMaker: hits didn't generate any clusters");
    addNeighbours(hit, plane, lastCluster);
  }

  // Recursive search has ended, finalize all the cluster information
  for (unsigned int i = 0; i < plane->getNumClusters(); i++)
    calculateCluster(plane->getCluster(i));
}
Example #2
0
void ClusterMaker::addNeighbours(const Storage::Hit* hit, const  Storage::Plane* plane,
                                  Storage::Cluster* cluster)
{
  // Go through all hits
  for (unsigned int nhit = 0; nhit < plane->getNumHits(); nhit++)
  {
     Storage::Hit* compare = plane->getHit(nhit);

    // Continue if this hit is already clustered or if it is the one being considered
    if (compare->getCluster() || compare == hit) continue;

    // If a maximum separation has been defined in real coordinates, check now
    if (_maxSeparation > 0)
    {
      const double distX = compare->getPosX() - hit->getPosX();
      const double distY = compare->getPosY() - hit->getPosY();
      const double dist = sqrt(pow(distX, 2) + pow(distY, 2));
      if (dist > _maxSeparation) continue;
    }
    else
    {
      const int distX = compare->getPixX() - hit->getPixX();
      const int distY = compare->getPixY() - hit->getPixY();
      if (fabs(distX) > _maxSeparationX || fabs(distY) > _maxSeparationY)
        continue;
    }

    // Add this hit to the cluster we are making
    cluster->addHit(compare);

    // Continue adding neigbours of this hit into the cluster
    addNeighbours(compare, plane, cluster);
  }
}
/**
 * Refines the grid and updates the shadow storage.
 */
void PrewaveletGridGenerator::refine(RefinementFunctor* func) {
  HashRefinement refine;
  size_t start = this->storage->size();
  refine.free_refine(this->storage, func);
  size_t end = this->storage->size();
  // All added gridpoint are between [start,end[

  // Check if a gridpoint within the shadow storage
  // is now part of the actual grid!
  for (size_t i = start; i < end; i++) {
    if (shadowstorage->find(storage->get(i)) != shadowstorage->end()) {
      consolidateShadow();
      break;
    }
  }

  // Now add all missing neigbours to the shadowStorage
  for (size_t i = start; i < end; i++) {
    GridStorage::index_pointer index = this->storage->get(i);

    level_t sum = 0;

    for (size_t d = 0; d < storage->dim(); ++d) {
      index_t current_index;
      level_t current_level;
      index->get(d, current_level, current_index);
      sum += current_level;
    }

    GridStorage::grid_iterator iter(storage);
    GridStorage::grid_iterator shadowIter(shadowstorage);
    addNeighbours(*this->storage->get(i), 0, sum, iter, shadowIter);
  }
}
Example #4
0
void ZoneManager::spawnMap()
{
	int startX, startY(50);
	float width = zoneBegin.width();
	float heigth = zoneBegin.heigth();

	float spareSpaceHorizontal = 1.5;
	float spareSpaceVertical = 2;

	int zonePerLine = (screenSize_.height / width) ;
	int lineInScreen = (screenSize_.width / heigth);
	int completeLineModifier(0);
	startX = (screenSize_.width - width*(zonePerLine-1)*spareSpaceHorizontal) / 2;

	Zone temp;
	int curId = 1;
	for (int j(0); j <= lineInScreen; ++j)
	{
		for (int i(0); i < zonePerLine - completeLineModifier; ++i)
		{
			temp = spawnZone(startX + i*width*spareSpaceHorizontal + completeLineModifier*width*0.75, j*heigth / spareSpaceVertical + startY);
			temp.setId(curId);

			addNeighbours(curId, temp, lineInScreen, zonePerLine, i, j, completeLineModifier);
			
			zoneDict[curId] = temp;
			zoneDict[curId].addToLayer(*layer_);
			zoneList.push_back(&zoneDict[curId]);
			curId++;
		}
		if (completeLineModifier == 0)
			completeLineModifier = 1;
		else
			completeLineModifier = 0;
	}

	zoneBegin.setPosition(Vec2(screenSize_.width / 2 - spareSpaceHorizontal * width, screenSize_.height - heigth/1.5));
	zoneEnd.setPosition(Vec2(screenSize_.width / 2, screenSize_.height - heigth/1.5));
	zoneObstacle.setPosition(Vec2(screenSize_.width / 2 + spareSpaceHorizontal * width, screenSize_.height - heigth/1.5));

	zoneList.push_back(&zoneBegin);
	zoneList.push_back(&zoneEnd);
	zoneList.push_back(&zoneObstacle);

	zoneBegin.addToLayer(*layer_);
	zoneEnd.addToLayer(*layer_);
	zoneObstacle.addToLayer(*layer_);
}
void PrewaveletGridGenerator::addNeighbours(index_type& index,
    size_t current_dim, level_t target_level,
    GridStorage::grid_iterator& iter,
    GridStorage::grid_iterator& shadowIter) {

  level_t sum = 0;

  for (size_t d = 0; d < storage->dim(); ++d) {
    index_t current_index;
    level_t current_level;
    iter.get(d, current_level, current_index);
    sum += current_level;
  }

  if (sum == target_level) {
    GridStorage::index_pointer new_index = new GridStorage::index_type(
      storage->dim());

    if (storage->end(iter.seq()) && shadowstorage->end(shadowIter.seq())) {
      // Ok, point is neither in storage, nor in shadowstorage ...
      // check if the border of index and iter touching
      for (size_t d = 0; d < storage->dim(); ++d) {
        index_t target_index;
        level_t target_level;

        index_t current_index;
        level_t current_level;

        iter.get(d, current_level, current_index);
        index.get(d, target_level, target_index);

        new_index->set(d, current_level, current_index);

        // The index cast to int is required to allow a negative index
        int target_left =
          static_cast<int>((1.0 / (1 << target_level))
                           * static_cast<float_t>(
                             static_cast<int>(target_index) - 3));
        int target_right =
          static_cast<int>((1.0 / (1 << target_level))
                           * static_cast<float_t>(
                             static_cast<int>(target_index) + 3));
        int current_left =
          static_cast<int>((1.0 / (1 << current_index))
                           * static_cast<float_t>(
                             static_cast<int>(current_level) + 3));
        int current_right =
          static_cast<int>((1.0 / (1 << current_index))
                           * static_cast<float_t>(
                             static_cast<int>(current_level) + 3));

        if (!(current_right > target_left || current_left
              < target_right)) {
          return;
          delete new_index;
        }
      }

      // Yepp, the supports touching each other! Add point to shadow!
      shadowstorage->insert(*new_index);
      delete new_index;
      // Call for parents
      insertParents(iter, shadowIter);
    }

    return;
  } else if (sum > target_level) {
    return;
  }

  for (size_t d = current_dim; d < storage->dim(); d++) {
    index_t save_index;
    level_t save_level;
    iter.get(d, save_level, save_index);  // Save current index

    iter.leftChild(d);
    shadowIter.leftChild(d);
    addNeighbours(index, d, target_level, iter, shadowIter);
    iter.set(d, save_level, save_index);  // reset index
    shadowIter.set(d, save_level, save_index);  // reset index

    iter.rightChild(d);
    shadowIter.rightChild(d);
    addNeighbours(index, d, target_level, iter, shadowIter);
    iter.set(d, save_level, save_index);  // reset index
    shadowIter.set(d, save_level, save_index);
  }
}