35 template<
typename po
int_type>
37 return Node(ct[0], ct[1], ct[2]);
53 template<
typename n1_type,
typename n2_type>
55 return sqrt(pow((n1[0] - n2[0]), 2) + pow((n1[1] - n2[1]), 2) + pow((n1[2] - n2[2]), 2));
67 template<
typename vector_type>
69 auto magnitude = sqrt(pow(v[0], 2) + pow(v[1], 2) + pow(v[2], 2));
70 v[0] = v[0] / magnitude;
71 v[1] = v[1] / magnitude;
72 v[2] = v[2] / magnitude;
87 template<
typename vector_type>
88 inline vector_type
DirectionTo(
const vector_type& n1,
const vector_type& n2) {
89 vector_type direction_vector;
91 direction_vector[0] = n2[0] - n1[0];
92 direction_vector[1] = n2[1] - n1[1];
93 direction_vector[2] = n2[2] - n1[2];
97 return direction_vector;
143 return (goal == geom_dict[
id]);
149 const real3& direction,
158 res = ray_tracer.
Intersect(origin, direction);
169 return_pt.
pt[2] = HF::SpatialStructures::roundhf_tail<real_t>(return_pt.
pt[2], 1/node_z_tolerance);
183 steps.reserve(2 * limit);
185 for (
int i = 1; i < limit + 1; i++) {
190 std::set<std::pair<int, int>> perms;
195 if (abs(j) != abs(k))
196 perms.emplace(
pair(j, k));
212 out_directions.resize(out_directions.size() + perms.size());
213 std::move(perms.begin(), perms.end(), out_directions.begin() +
init_directs.size());
215 return out_directions;
220 const vector<real3>& possible_children,
225 std::vector<graph_edge> valid_edges;
229 const auto checked_children =
CheckChildren(parent, possible_children, rt, GP);
232 for (
const auto& child : checked_children)
239 if (connection_type != STEP::NOT_CONNECTED)
250 const std::vector<real3>& possible_children,
254 vector<real3> valid_children;
257 for (
const auto& child : possible_children)
266 auto& confirmed_child = potential_child.
pt;
272 real_t dstep = parent[2] - confirmed_child[2];
273 real_t ustep = confirmed_child[2] - parent[2];
277 valid_children.push_back(confirmed_child);
280 return valid_children;
293 const real_t run = sqrt(pow((parent[0] - child[0]), 2) + pow((parent[1] - child[1]), 2));
294 const real_t rise = child[2] - parent[2];
297 const real_t calc_slope = atan2(rise, run) * (
static_cast<real_t>(180.00) /
static_cast<real_t>(M_PI));
317 node1[2] += GROUND_OFFSET;
318 node2[2] += GROUND_OFFSET;
324 if (abs(node1[2] - node2[2]) < GROUND_OFFSET)
return STEP::NONE;
327 else if (
CheckSlope(parent, child, params))
return STEP::NONE;
329 return STEP::NOT_CONNECTED;
338 if (parent[2] > child[2])
343 node2[2] = node2[2] + GROUND_OFFSET;
350 else if (node1[2] < node2[2])
354 node1[2] = node1[2] + params.
up_step;
355 node2[2] = node2[2] + GROUND_OFFSET;
361 else if (node1[2] == node2[2])
365 node1[2] = node1[2] + params.
up_step;
366 node2[2] = node2[2] + GROUND_OFFSET;
378 return STEP::NOT_CONNECTED;
383 const std::vector<pair>& directions,
384 const real3& spacing,
388 vector<real3> out_children(directions.size());
391 for (
int i = 0; i < directions.size(); i++) {
393 const auto& dir = directions[i];
396 real_t x_offset = dir.first;
397 real_t y_offset = dir.second;
407 out_children[i] =
real3{ x, y, z };
Contains declarations for all functions related to the graph generator.
Contains definitions for the EmbreeRayTracer
Contains definitions for the HF::SpatialStructures namespace.
Contains definitions for the Edge structure.
Generate a graph of accessible space from a given start point.
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...
HF::SpatialStructures::Edge graph_edge
Type of edge for the graph generator to use internally.
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.
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.
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.
vector_type DirectionTo(const vector_type &n1, const vector_type &n2)
Calculate the normalized direction from one node to another.
real_t down_slope
The maximum downward slope the graph can traverse. Any slopes steeper than this will be considered in...
real_t DistanceTo(const n1_type &n1, const n2_type &n2)
Calculate the distance between two nodes.
std::array< real_t, 3 > real3
Type used for the standard coordinate set of the graph generator.
static const real3 down
Constant used as a direction for downwards raycasts.
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.
bool CheckGeometryID(HIT_FLAG goal, int id, const GeometryFlagMap &geom_dict)
Determine if a hit is against the geometry type specified.
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.
Node ToNode(const point_type &ct)
Convert a point_type to a node.
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.
void Normalize(vector_type &v)
Normalize a vector.
static const vector< pair > init_directs
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.
std::vector< pair > CreateDirecs(int max_step_connections)
Create a set of directions based on max_step_connections.
Precision precision
Tolerances for the graph.
@ 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.
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...
STEP
Describes the type of step an edge connects to.
Manages rules and ids for different types of geometry in the graph generator.
GeometryFilterMode Mode
Filter mode of this GeometryFlagMap.
A simple wrapper for real3 that is able to determine whether or not it's defined.
A simple hit struct to carry all relevant information about hits.
bool DidHit() const
Determine whether or not this hitstruct contains a hit.
numeric_type distance
Distance from the origin point to the hit point. Set to -1 if no hit was recorded.
int meshid
The ID of the hit mesh. Set to -1 if no hit was recorded.
bool Occluded(const real3 &origin, const real3 &direction, real_t distance)
HitStruct< real_t > Intersect(const real3 &origin, const real3 &direction)
A connection to a child node.
A point in space with an ID.