6using namespace std::chrono_literals;
18 while (!QThread::currentThread()->isInterruptionRequested()) {
20 std::unique_lock lk(
mutex_);
27 std::lock_guard lk(
mutex_);
38 auto startTime = std::chrono::high_resolution_clock::now();
40 H3Index prevIndex = req.
indexes.front();
41 std::vector<H3Index> path;
42 path.reserve(req.
indexes.size());
43 int totalPathLength = 0;
45 for (
size_t indexId = 1; indexId < req.
indexes.size(); indexId++) {
48 prevIndex = req.
indexes.at(indexId);
49 totalPathLength +=
static_cast<int>(path.size());
51 for (
const auto index : path) {
53 if (!childPolygon.has_value()) {
56 emit
cellComputed(getResolution(index), index, childPolygon.value(),
true);
58 }
catch (
const std::exception &e) {
59 spdlog::warn(
"{}", e.what());
64 auto endTime = std::chrono::high_resolution_clock::now();
65 auto duration = std::chrono::duration_cast<std::chrono::microseconds>(endTime - startTime);
66 const auto timeMs =
static_cast<double>(duration.count()) / 1000.0;
72 std::lock_guard lk(
mutex_);
81 std::lock_guard lk(
mutex_);
83 SPDLOG_WARN(
"cancel <requestCell>");
94 std::lock_guard lk(
mutex_);
101 spdlog::info(
"H3Worker: Walls updated for A* algorithm, {} wall cells",
walls.size());
109 static int counter = 0;
110 static constexpr int THROTTLE_FACTOR = 25;
112 if (++counter % THROTTLE_FACTOR != 0) {
118 if (!polygon.has_value()) {
123 emit
cellComputed(getResolution(cell), cell, polygon.value(),
false);
Bidirectional A* pathfinding algorithm for H3 hexagonal cells.
std::vector< H3Index > findShortestPath(H3Index start, H3Index end)
Finds the shortest path between two H3 cells.
void setBlockedCells(const std::unordered_set< H3Index > &blocked)
Sets cells that cannot be traversed (obstacles).
std::condition_variable cv_
Condition variable for efficient waiting.
void requestCell(const std::vector< H3Index > &index)
Requests computation for a set of H3 cells.
std::atomic< int > exploredCellsCount_
Counter for explored cells during current search.
void onAStarNewCell(H3Index cell)
Handles cell exploration events from A* algorithm.
H3AStar * astar_
A* pathfinding algorithm instance.
void searchStats(int exploredCells, double timeMs, int pathLength)
Emitted with pathfinding statistics after search completes.
void cellComputed(quint8 res, H3Index id, const QVariantList &polygon, bool isSearching)
Emitted when a single cell computation completes.
std::atomic_bool isRequested
Flag indicating a request is pending.
void setWalls(const std::unordered_set< H3Index > &mazeWalls)
Sets maze walls for pathfinding obstacle avoidance.
~H3Worker() override
Destructor.
bool has
Flag indicating pending request.
void doWork()
Main work loop executed in the worker thread.
std::unordered_set< H3Index > walls
Maze wall cells for obstacle avoidance.
PendingRequest pending_
Currently pending request.
std::mutex mutex_
Mutex for thread synchronization.
H3Worker(QObject *parent=nullptr)
Constructs an H3Worker.
std::vector< H3Index > indexes
Cell indices to process.
Structure holding queued cell computation requests.
Worker thread for asynchronous H3 cell processing and pathfinding.
Namespace containing H3 visualization components.
static std::optional< QVariantList > indexToPolygon(const H3Index index)