13#include <robin_hood.h>
36 if (cores > 1) omp_set_num_threads(cores);
37 else omp_set_num_threads(std::thread::hardware_concurrency());
49 template <
typename raytracer_type>
50 inline void setupRT(
GraphGenerator* gg, raytracer_type & rt,
const std::vector<int> & obs_ids,
const std::vector<int> & walk_ids ) {
56 setupRT<HF::RayTracer::EmbreeRayTracer> (
this, rt, obstacle_ids, walkable_ids);
60 setupRT<HF::RayTracer::NanoRTRayTracer> (
this, rt, obstacle_ids, walkable_ids);
70 const real3& start_point,
77 int max_step_connections,
81 real_t node_spacing_precision,
84 if (ground_offset < node_z_precision)
86 std::cerr <<
"Ground offset is less than z-precision. Setting node offset to Z-Precision." << std::endl;
87 ground_offset = node_z_precision;
122 start = *checked_start;
158 int to_do_count = todo.
size();
163 auto to_be_done = todo.
popMany(to_do_count);
168 assert(to_be_done.size() > 0);
171 vector<vector<Edge>> OutEdges(to_do_count);
174 #pragma omp parallel for schedule(dynamic) if (to_be_done.size() > 100)
175 for (
int i = 0; i < to_do_count; i++)
179 const Node& n = to_be_done[i];
202 for (
int i = 0; i < to_do_count; i++) {
205 if (!OutEdges[i].empty() && OutEdges[i].size() >= this->
min_connections) {
208 for (
const auto& e : OutEdges[i]) {
210 G.
addEdge(to_be_done[i], e.child, e.score);
232 while (!todo.
empty() && (num_nodes < this->
max_nodes || this->max_nodes < 0)) {
235 const auto parent = todo.
pop();
257 if (!OutEdges.empty() && OutEdges.size() >= this->min_connections)
262 for (
auto edge : OutEdges)
266 if (!OutEdges.empty())
267 for (
const auto& edge : OutEdges)
268 G.
addEdge(parent, edge.child, edge.score);
Contains declarations for all functions related to the graph generator.
Contains definitions for the UniqueQueue class.
Contains definitions for the HF::SpatialStructures namespace.
Contains definitions for the Edge structure.
Contains definitions for the Graph class.
Contains definitions for the Node structure.
Generate a graph of accessible space from a given start point.
real_t up_step
Maximum height of a step the graph can traverse.Any steps higher this will be considered inaccessible...
void setupRT(GraphGenerator *gg, raytracer_type &rt, const std::vector< int > &obs_ids, const std::vector< int > &walk_ids)
Converts the raytracer to a multiRT if required, then map geometry ids to hitflags.
std::vector< real3 > GeneratePotentialChildren(const real3 &parent, const std::vector< pair > &direcs, const real3 &spacing, const GraphParams &gp)
Populare out_children with a potential child position for every direction in directions.
real_t ground_offset
Distance to offset nodes from the ground before checking line of sight.
real3 CastToReal3(real_3_type t)
Cast an array of 3 values to the graph_generator's real_3 type.
GeometryFlagMap geom_ids
Stores a map of geometry IDs to their HIT_FLAGS and the current filter mode of the graph.
real_t node_z
Precision to round the z-component of nodes after a raycast is performed.
real_t down_slope
The maximum downward slope the graph can traverse. Any slopes steeper than this will be considered in...
std::array< real_t, 3 > real3
Type used for the standard coordinate set of the graph generator.
optional_real3 ValidateStartPoint(RayTracer &RT, const real3 &start_point, const GraphParams &Params)
Determine if the start point of the graph is over valid ground.
std::vector< graph_edge > GetChildren(const real3 &parent, const std::vector< real3 > &possible_children, RayTracer &rt, const GraphParams &GP)
Calculate all possible edges between parent and possible_children.
real_t node_spacing
Precision to round nodes after spacing is calculated.
real_t down_step
Maximum step down the graph can traverse.Any steps steeper than this will be considered inaccessible.
real_t up_slope
Maximum upward slope the graph can traverse in degrees.Any slopes steeper than this will be considere...
std::vector< pair > CreateDirecs(int max_step_connections)
Create a set of directions based on max_step_connections.
Precision precision
Tolerances for the graph.
void SetupCoreCount(int cores=-1)
Sets the core count of OpenMP.
constexpr numeric_type roundhf_tmp(numeric_type f, numeric_type p, numeric_type r)
round a number to the nearest precision defined globally. The global values can be overridden with op...
constexpr numeric_type trunchf_tmp(numeric_type f, numeric_type p, numeric_type r)
truncate a number to the nearest precision defined globally. The global values can be overridden with...
Manages rules and ids for different types of geometry in the graph generator.
void SetGeometryIds(const std::vector< int > &obstacle_geometry, const std::vector< int > &walkable_geometry)
Set geometry ids as being walkable or obstacles.
A simple wrapper for real3 that is able to determine whether or not it's defined.
Generate a graph of accessible space from a given start point.
int core_count
Number of cores to use for graph generation.
SpatialStructures::Graph IMPL_BuildNetwork(const real3 &start_point, const real3 &Spacing, int MaxNodes, real_t UpStep, real_t UpSlope, real_t DownStep, real_t DownSlope, int max_step_connections, int min_connections, int cores=-1, real_t node_z_precision=default_z_precision, real_t node_spacing_precision=default_spacing_precision, real_t ground_offset=default_ground_offset)
Generate a graph of accessible space.
RayTracer ray_tracer
A pointer to the raytracer to use for ray intersections.
int max_nodes
Maximum number of nodes to generate. If less than zero, generate nodes without a limit.
GraphParams params
Parameters to run the graph generator.
int max_step_connection
Multiplier for number of children to generate. The higher this is, the more directions there will be.
SpatialStructures::Graph CrawlGeomParallel(UniqueQueue &todo)
Perform breadth first search to populate the graph with nodes and edges using multiple cores.
real3 spacing
Spacing between nodes. New nodes will be generated with atleast this much distance between them.
int min_connections
Minimum number of step connections for a node to be valid (minimum out degree of node)
SpatialStructures::Graph CrawlGeom(UniqueQueue &todo)
Perform breadth first search to populate the graph with with nodes and edges.
A queue that remembers every object inserted, and prevents the addition of nodes that have already be...
bool PushAny(const arr_type &node)
Call push with any type of object.
HF::SpatialStructures::Node pop()
Remove the topmost node from the queue and return it.
int size() const
Determine how many nodes are currently in the queue.
bool empty() const
Tell if the queue is empty.
bool push(const HF::SpatialStructures::Node &p)
Add a node to the queue if it has never previously been in the queue.
std::vector< SpatialStructures::Node > popMany(int max=-1)
Pop a set amount of nodes from the queue, and return them as a vector.
A wrapper for Intel's Embree Library.
A connection to a child node.
A Graph of nodes connected by edges that supports both integers and HF::SpatialStructures::Node.
void addEdge(const Node &parent, const Node &child, float score=1.0f, const std::string &cost_type="")
Add a new edge to the graph from parent to child.
A point in space with an ID.