qHexWalker 0.0.1
Hexagonal Grid Pathfinding & Maze Visualization on Interactive Maps
Loading...
Searching...
No Matches
H3_VIEWER::H3Worker Class Referencefinal

Worker thread for asynchronous H3 operations. More...

#include <h3Worker.h>

+ Inheritance diagram for H3_VIEWER::H3Worker:
+ Collaboration diagram for H3_VIEWER::H3Worker:

Classes

struct  PendingRequest
 Structure holding queued cell computation requests. More...
 

Public Member Functions

 H3Worker (QObject *parent=nullptr)
 Constructs an H3Worker.
 
 ~H3Worker () override
 Destructor.
 
void doWork ()
 Main work loop executed in the worker thread.
 
void requestCell (const std::vector< H3Index > &index)
 Requests computation for a set of H3 cells.
 
void setWalls (const std::unordered_set< H3Index > &mazeWalls)
 Sets maze walls for pathfinding obstacle avoidance.
 
void cellComputed (quint8 res, H3Index id, const QVariantList &polygon, bool isSearching)
 Emitted when a single cell computation completes.
 
void cellsComputed (const QVariantList &polygon)
 Emitted when batch cell computation completes.
 
void mazePolygonsComputed (const std::vector< QVariantList > &polygons)
 Emitted with merged maze wall polygons for rendering.
 
void searchStats (int exploredCells, double timeMs, int pathLength)
 Emitted with pathfinding statistics after search completes.
 
void pathCellsBatch (const std::vector< std::tuple< quint8, H3Index, QVariantList > > &cells)
 Emitted with batch of path cells for efficient rendering.
 

Public Attributes

 : void finished()
 

Private Member Functions

void onAStarNewCell (H3Index cell)
 Handles cell exploration events from A* algorithm.
 

Private Attributes

std::unordered_set< H3Index > walls
 Maze wall cells for obstacle avoidance.
 
H3AStarastar_ {}
 A* pathfinding algorithm instance.
 
std::atomic_bool isRequested {false}
 Flag indicating a request is pending.
 
std::mutex mutex_
 Mutex for thread synchronization.
 
std::condition_variable cv_
 Condition variable for efficient waiting.
 
PendingRequest pending_
 Currently pending request.
 
std::atomic< int > exploredCellsCount_ {0}
 Counter for explored cells during current search.
 

Detailed Description

Worker thread for asynchronous H3 operations.

H3Worker handles CPU-intensive operations in a background thread:

  • Cell polygon computation
  • A* pathfinding between waypoints
  • Maze wall rendering preparation
Threading Model
The worker runs in a dedicated QThread and communicates via signals/slots:
Example Usage
auto worker = new H3Worker();
auto thread = new QThread();
worker->moveToThread(thread);
connect(thread, &QThread::started, worker, &H3Worker::doWork);
connect(worker, &H3Worker::cellComputed, this, &MyClass::onCell);
thread->start();
worker->requestCell(cellIndexes);
Worker thread for asynchronous H3 operations.
Definition h3Worker.h:54
void cellComputed(quint8 res, H3Index id, const QVariantList &polygon, bool isSearching)
Emitted when a single cell computation completes.
void doWork()
Main work loop executed in the worker thread.
Definition h3Worker.cpp:17
See also
H3Model for the main consumer of worker results
H3AStar for the pathfinding algorithm

Definition at line 54 of file h3Worker.h.


Class Documentation

◆ H3_VIEWER::H3Worker::PendingRequest

struct H3_VIEWER::H3Worker::PendingRequest

Structure holding queued cell computation requests.

Definition at line 74 of file h3Worker.h.

+ Collaboration diagram for H3_VIEWER::H3Worker::PendingRequest:
Class Members
bool has {} Flag indicating pending request.
vector< H3Index > indexes Cell indices to process.

Constructor & Destructor Documentation

◆ H3Worker()

H3Worker::H3Worker ( QObject *  parent = nullptr)
explicit

Constructs an H3Worker.

Parameters
parentOptional parent QObject.

Definition at line 8 of file h3Worker.cpp.

References astar_, and onAStarNewCell().

+ Here is the call graph for this function:

◆ ~H3Worker()

H3Worker::~H3Worker ( )
overridedefault

Destructor.

Member Function Documentation

◆ cellComputed()

void H3_VIEWER::H3Worker::cellComputed ( quint8  res,
H3Index  id,
const QVariantList &  polygon,
bool  isSearching 
)

Emitted when a single cell computation completes.

Parameters
resCell resolution (3-15).
idH3 cell index.
polygonCell boundary polygon coordinates.
isSearchingtrue if emitted during active pathfinding.

Referenced by doWork(), H3Model::Init(), and onAStarNewCell().

+ Here is the caller graph for this function:

◆ cellsComputed()

void H3_VIEWER::H3Worker::cellsComputed ( const QVariantList &  polygon)

Emitted when batch cell computation completes.

Parameters
polygonList of computed polygon data.

Referenced by H3Model::Init().

+ Here is the caller graph for this function:

◆ doWork()

void H3Worker::doWork ( )

Main work loop executed in the worker thread.

Continuously processes pending requests and performs pathfinding. Uses condition variable to wait efficiently when no work is available.

Definition at line 17 of file h3Worker.cpp.

References astar_, cellComputed(), cv_, exploredCellsCount_, H3AStar::findShortestPath(), H3_VIEWER::H3Worker::PendingRequest::has, H3_VIEWER::H3Worker::PendingRequest::indexes, H3_VIEWER::Helper::indexToPolygon(), isRequested, mutex_, pending_, and searchStats().

Referenced by H3Model::Init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mazePolygonsComputed()

void H3_VIEWER::H3Worker::mazePolygonsComputed ( const std::vector< QVariantList > &  polygons)

Emitted with merged maze wall polygons for rendering.

Polygons are pre-merged for efficient map rendering.

Parameters
polygonsVector of polygon coordinate lists.

Referenced by H3Model::Init().

+ Here is the caller graph for this function:

◆ onAStarNewCell()

void H3Worker::onAStarNewCell ( H3Index  cell)
private

Handles cell exploration events from A* algorithm.

Called during pathfinding to enable real-time visualization.

Parameters
cellThe H3 index of the newly explored cell.

Definition at line 104 of file h3Worker.cpp.

References cellComputed(), exploredCellsCount_, and H3_VIEWER::Helper::indexToPolygon().

Referenced by H3Worker().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pathCellsBatch()

void H3_VIEWER::H3Worker::pathCellsBatch ( const std::vector< std::tuple< quint8, H3Index, QVariantList > > &  cells)

Emitted with batch of path cells for efficient rendering.

Parameters
cellsVector of cell data tuples (resolution, index, polygon).

◆ requestCell()

void H3Worker::requestCell ( const std::vector< H3Index > &  index)

Requests computation for a set of H3 cells.

Queues cells for polygon computation and pathfinding. Thread-safe - can be called from any thread.

Parameters
indexVector of H3 cell indices to process.

Definition at line 79 of file h3Worker.cpp.

References cv_, H3_VIEWER::H3Worker::PendingRequest::has, H3_VIEWER::H3Worker::PendingRequest::indexes, isRequested, mutex_, and pending_.

Referenced by H3Model::requestCells().

+ Here is the caller graph for this function:

◆ searchStats()

void H3_VIEWER::H3Worker::searchStats ( int  exploredCells,
double  timeMs,
int  pathLength 
)

Emitted with pathfinding statistics after search completes.

Parameters
exploredCellsNumber of cells explored during search.
timeMsSearch duration in milliseconds.
pathLengthNumber of cells in the found path.

Referenced by doWork(), and H3Model::Init().

+ Here is the caller graph for this function:

◆ setWalls()

void H3Worker::setWalls ( const std::unordered_set< H3Index > &  mazeWalls)

Sets maze walls for pathfinding obstacle avoidance.

Parameters
mazeWallsSet of H3 cell indices representing walls.

Definition at line 93 of file h3Worker.cpp.

References astar_, mutex_, H3AStar::setBlockedCells(), and walls.

Referenced by H3Model::Init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ __pad0__

H3_VIEWER::H3Worker::__pad0__

Definition at line 113 of file h3Worker.h.

◆ astar_

H3AStar* H3_VIEWER::H3Worker::astar_ {}
private

A* pathfinding algorithm instance.

Definition at line 167 of file h3Worker.h.

Referenced by H3Worker(), doWork(), and setWalls().

◆ cv_

std::condition_variable H3_VIEWER::H3Worker::cv_
private

Condition variable for efficient waiting.

Definition at line 176 of file h3Worker.h.

Referenced by doWork(), and requestCell().

◆ exploredCellsCount_

std::atomic<int> H3_VIEWER::H3Worker::exploredCellsCount_ {0}
private

Counter for explored cells during current search.

Definition at line 182 of file h3Worker.h.

Referenced by doWork(), and onAStarNewCell().

◆ isRequested

std::atomic_bool H3_VIEWER::H3Worker::isRequested {false}
private

Flag indicating a request is pending.

Definition at line 170 of file h3Worker.h.

Referenced by doWork(), and requestCell().

◆ mutex_

std::mutex H3_VIEWER::H3Worker::mutex_
private

Mutex for thread synchronization.

Definition at line 173 of file h3Worker.h.

Referenced by doWork(), requestCell(), and setWalls().

◆ pending_

PendingRequest H3_VIEWER::H3Worker::pending_
private

Currently pending request.

Definition at line 179 of file h3Worker.h.

Referenced by doWork(), and requestCell().

◆ walls

std::unordered_set<H3Index> H3_VIEWER::H3Worker::walls
private

Maze wall cells for obstacle avoidance.

Definition at line 164 of file h3Worker.h.

Referenced by setWalls().


The documentation for this class was generated from the following files: