VoronoiExpansion::Index VoronoiExpansion::expandVoronoi(Index start, Index end, int cycles, int8_t *map,
                                                        int8_t *voronoi_map, float *distance_map, float *potential)
{
  int cycle = 0;

  Index current(start.i, potential[start.i], 0, potential[start.i]);

  // clear the queue
  clearpq(queue_);
  queue_.push(current);

  while (!queue_.empty() && cycle < cycles && !isEndpoint(current))  //&& !isInGoalZone(current.i)
  {
    if (queue_.empty())
      return Index(-1, 0, 0, 0);

    current = queue_.top();
    queue_.pop();

    // If we have found a max potential return the pixel
    if (isEndpoint(current))
    {
      potential[current.i] = current.potential;
      return current;
    }

    addExpansionCandidate(start, current, current.offsetDist(1, 0, nx_, ny_), end, map, voronoi_map, distance_map,
                          potential, true, false);
    addExpansionCandidate(start, current, current.offsetDist(0, 1, nx_, ny_), end, map, voronoi_map, distance_map,
                          potential, true, false);
    addExpansionCandidate(start, current, current.offsetDist(-1, 0, nx_, ny_), end, map, voronoi_map, distance_map,
                          potential, true, false);
    addExpansionCandidate(start, current, current.offsetDist(0, -1, nx_, ny_), end, map, voronoi_map, distance_map,
                          potential, true, false);

    addExpansionCandidate(start, current, current.offsetDist(1, 1, nx_, ny_), end, map, voronoi_map, distance_map,
                          potential, true, false);
    addExpansionCandidate(start, current, current.offsetDist(-1, 1, nx_, ny_), end, map, voronoi_map, distance_map,
                          potential, true, false);
    addExpansionCandidate(start, current, current.offsetDist(-1, -1, nx_, ny_), end, map, voronoi_map, distance_map,
                          potential, true, false);
    addExpansionCandidate(start, current, current.offsetDist(1, -1, nx_, ny_), end, map, voronoi_map, distance_map,
                          potential, true, false);
    cycle++;
  }

  if (cycle >= cycles)
    return Index(-1, -1, -1, -1);
  else
    return end;
}
예제 #2
0
void WebPathSegment::print(int ident)
{
  cout << string(ident, '-') <<  getName() << (isEndpoint() ? " | " : "") << (isEndpoint() ? getContent() : "") << endl;
  for_each(_segmentList.begin(), _segmentList.end(), [ident](auto pair) { pair.second->print(ident + 2); });
}