8#define _USE_MATH_DEFINES
18#include <unordered_map>
71 struct optional_real3;
74 using real3 = std::array<real_t, 3>;
82 using pair = std::pair<int, int>;
90 template<
typename real_type>
103 template<
typename real_3_type>
134 using hashmap = std::unordered_map<int, HIT_FLAG>;
177 const std::vector<int>& walkable,
178 const std::vector<int>& obstacle)
180 bool has_walkable = !(walkable.empty());
181 bool has_obstacle = !(obstacle.empty());
201 const std::vector<int> & obstacle_geometry,
202 const std::vector<int> & walkable_geometry)
204 for (
auto id : obstacle_geometry)
206 for (
auto id : walkable_geometry)
312 inline explicit operator bool()
const {
313 return !(std::isnan(
pt[0]) && std::isnan(
pt[1]) && std::isnan(
pt[2]));
456 typename up_step_type,
457 typename up_slope_type,
458 typename down_step_type,
459 typename down_slope_type,
460 typename z_precision_type =
real_t,
461 typename connect_offset_type =
real_t,
462 typename spacing_precision_type =
real_t
465 const node_type& start_point,
466 const node2_type& Spacing,
469 up_slope_type UpSlope,
470 down_step_type DownStep,
471 down_slope_type DownSlope,
472 int max_step_connections,
479 assert(node_z_precision != 0);
488 max_step_connections,
537 const real3& start_point,
538 const real3& Spacing,
544 int max_step_connections,
638 const real3& direction,
641 const GeometryFlagMap& geometry_dict = GeometryFlagMap()
659 std::vector<pair>
CreateDirecs(
int max_step_connections);
687 const real3 & parent,
688 const std::vector<real3>& possible_children,
690 const GraphParams & GP
713 const std::vector<pair>& direcs,
714 const real3& spacing,
715 const GraphParams & gp
730 template<
typename A,
typename D,
typename N>
731 inline void MoveNode(
const A& dist,
const D& direction, N& node) {
732 node[0] = std::fma(direction[0], dist, node[0]);
733 node[1] = std::fma(direction[1], dist, node[1]);
734 node[2] = std::fma(direction[2], dist, node[2]);
757 const std::vector<real3>& possible_children,
759 const GraphParams & params
779 const real3 & parent,
782 const GraphParams & params
820 const real3 & parent,
822 const GraphParams & gp
Contains definitions for the Node structure.
Generate a graph of accessible space from a given start point.
Various parameters to set the precision of certain parts of the graph generator.
Holds parameters for the GraphGenerator.
real_t up_step
Maximum height of a step the graph can traverse.Any steps higher this will be considered inaccessible...
constexpr real_t default_spacing_precision
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.
std::vector< real3 > CheckChildren(const real3 &parent, const std::vector< real3 > &possible_children, RayTracer &rt, const GraphParams ¶ms)
Determine whether children are over valid ground, and and meet upstep/downstep requirements.
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.
void MoveNode(const A &dist, const D &direction, N &node)
Move a node in direction by dist units.
GeometryFlagMap geom_ids
Stores a map of geometry IDs to their HIT_FLAGS and the current filter mode of the graph.
HIT_FLAG
Determines which geometry the ray will collide with.
@ OBSTACLES
Obstacles only.
@ BOTH
Collide with floors and obstacles.
double real_t
Internal decimal type of the graph generator.
real_t node_z
Precision to round the z-component of nodes after a raycast is performed.
real_t CastToReal(real_type t)
Cast an input value to real_t using static cast.
optional_real3 CheckRay(RayTracer &RT, const real3 &origin, const real3 &direction, real_t node_z_tolerance, HIT_FLAG flag=BOTH, const GeometryFlagMap &geometry_dict=GeometryFlagMap())
Cast a ray and get the point of intersection if it connects.
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.
bool CheckSlope(const real3 &parent, const real3 &child, const GraphParams &gp)
Determine if the slope between parent and child is traversable according to the graph parameters.
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::pair< int, int > pair
Type for Directions to be stored as.
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.
bool OcclusionCheck(const real3 &parent, const real3 &child, RayTracer &RT)
Determine if there is a valid line of sight between parent and child.
constexpr real_t default_ground_offset
constexpr real_t default_z_precision
std::unordered_map< int, HIT_FLAG > hashmap
Hashmap used for assigning and storing hitflags for IDs.
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...
HF::SpatialStructures::STEP CheckConnection(const real3 &parent, const real3 &child, RayTracer &rt, const GraphParams ¶ms)
Determine what kind of step (if any) is between parent and child.
HF::RayTracer::MultiRT RayTracer
Type of raytracer to be used internally.
std::vector< pair > CreateDirecs(int max_step_connections)
Create a set of directions based on max_step_connections.
Precision precision
Tolerances for the graph.
GeometryFilterMode
Different rules for how geometry is filtered by the graph generator.
@ ALL_INTERSECTIONS
Consider all geometry as walkable surfaces.
@ OBSTACLES_ONLY
Consider all geometry that isn't an obstacle as walkable.
@ OBSTACLES_AND_FLOORS
Explicitly tag geometry ids as either obstacle or floor. Any ids outside of these ranges will always ...
std::set< std::pair< int, int > > permutations(int limit)
Calculate P(n,r) as an array with each unique permutaton of 2 values being a pair.
Cast rays to determine if and where they intersect geometry.
Contains standard fundamental data structures for representing space used throughout DHARTAPI.
STEP
Describes the type of step an edge connects to.
Manages rules and ids for different types of geometry in the graph generator.
bool HasKey(int id) const
Check if this id exists in the dictionary.
void SetGeometryIds(const std::vector< int > &obstacle_geometry, const std::vector< int > &walkable_geometry)
Set geometry ids as being walkable or obstacles.
GeometryFilterMode Mode
Filter mode of this GeometryFlagMap.
void DetermineFilterMode(const std::vector< int > &walkable, const std::vector< int > &obstacle)
Set the filter mode of this GeometryFlagMap based on the input types.
void Set(int id, HIT_FLAG flag)
Set the value of a key in the internal dictionary.
hashmap internal_dictionary
HIT_FLAG operator[](int id) const
Get the flag of the geometry in this hit dictionary.
A simple wrapper for real3 that is able to determine whether or not it's defined.
optional_real3()
Construct an invalid optional_real3.
real3 & operator*()
Get a reference to the point held by this optional_real3.
optional_real3(real_t x, real_t y, real_t z)
Construct an valid optreal3 from x,y,z parameters.
optional_real3(const real3 &in_real3)
Construct an optreal3 from x,y,z parameters.
Generate a graph of accessible space from a given start point.
SpatialStructures::Graph BuildNetwork(const node_type &start_point, const node2_type &Spacing, int MaxNodes, up_step_type UpStep, up_slope_type UpSlope, down_step_type DownStep, down_slope_type DownSlope, int max_step_connections, int min_connections=1, int cores=-1, z_precision_type node_z_precision=default_z_precision, connect_offset_type node_spacing_precision=default_spacing_precision, spacing_precision_type ground_offset=default_ground_offset)
Generate a graph of accessible space.
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...
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.