DHART
Loading...
Searching...
No Matches
analysis_C.cpp
Go to the documentation of this file.
1#include <analysis_C.h>
2
3#include <robin_hood.h>
4
5#include <HFExceptions.h>
6#include <embree_raytracer.h>
7#include <graph_generator.h>
8#include <graph.h>
9
12using namespace HF::Exceptions;
13
14template <typename T>
15std::vector<T> MapToVector(int length, const T * in_ptr){
16 if (length == 0)
17 return std::vector<T>(0);
18 else
19 return std::vector<T>(in_ptr, in_ptr + length);
20}
21
24 const float* start_point,
25 const float* spacing,
26 int MaxNodes,
27 float UpStep,
28 float UpSlope,
29 float DownStep,
30 float DownSlope,
31 int max_step_connections,
32 int min_connections,
33 int core_count,
34 Graph** out_graph
35){
36 const std::array<float, 3> start_array{ start_point[0], start_point[1], start_point[2] };
37 const std::array<double, 3> spacing_array{ spacing[0], spacing[1], spacing[2] };
38
39 Graph* G = new Graph();
40 GraphGenerator GraphGen(*ray_tracer);
41 *G = GraphGen.BuildNetwork(
42 start_array,
43 spacing_array,
44 MaxNodes,
45 UpStep,
46 UpSlope,
47 DownStep,
48 DownSlope,
49 max_step_connections,
50 min_connections,
51 core_count
52 );
53
54 if (G->Nodes().size() < 1) {
55 delete G;
56 return HF_STATUS::NO_GRAPH;
57 }
58 *out_graph = G;
59 return OK;
60}
61
64 const float* start_point,
65 const float* spacing,
66 int MaxNodes,
67 float UpStep,
68 float UpSlope,
69 float DownStep,
70 float DownSlope,
71 int max_step_connections,
72 int min_connections,
73 int core_count,
74 const int* obstacle_ids,
75 const int* walkable_ids,
76 int num_obstacles,
77 int num_walkables,
78 Graph** out_graph
79) {
80 const std::array<float, 3> start_array{ start_point[0], start_point[1], start_point[2] };
81 const std::array<double, 3> spacing_array{ spacing[0], spacing[1], spacing[2] };
82
83 const std::vector<int> obstacle_vector = MapToVector(num_obstacles, obstacle_ids);
84 const std::vector<int> walkable_vector = MapToVector(num_walkables, walkable_ids);
85
86 Graph* G = new Graph();
87 GraphGenerator GraphGen(*ray_tracer, obstacle_vector, walkable_vector);
88 *G = GraphGen.BuildNetwork(
89 start_array,
90 spacing_array,
91 MaxNodes,
92 UpStep,
93 UpSlope,
94 DownStep,
95 DownSlope,
96 max_step_connections,
97 min_connections,
98 core_count
99 );
100
101 if (G->Nodes().size() < 1) {
102 delete G;
103 return HF_STATUS::NO_GRAPH;
104 }
105 *out_graph = G;
106 return OK;
107}
Contains declarations for all functions related to the graph generator.
Contains definitions for the Exceptions namespace.
Contains definitions for the EmbreeRayTracer
Contains definitions for the Graph class.
std::vector< T > MapToVector(int length, const T *in_ptr)
Definition: analysis_C.cpp:15
Header file for C Interface functions related to graph generation.
#define C_INTERFACE
Definition: analysis_C.h:16
C_INTERFACE GenerateGraph(HF::RayTracer::EmbreeRayTracer *ray_tracer, const float *start_point, const float *spacing, int MaxNodes, float UpStep, float UpSlope, float DownStep, float DownSlope, int max_step_connections, int min_connections, int core_count, Graph **out_graph)
Construct a graph by performing a breadth-first search of accessible space.
Definition: analysis_C.cpp:22
C_INTERFACE GenerateGraphObstacles(HF::RayTracer::EmbreeRayTracer *ray_tracer, const float *start_point, const float *spacing, int MaxNodes, float UpStep, float UpSlope, float DownStep, float DownSlope, int max_step_connections, int min_connections, int core_count, const int *obstacle_ids, const int *walkable_ids, int num_obstacles, int num_walkables, Graph **out_graph)
Construct a graph by performing a breadth-first search of accessible space, seperating obstacles from...
Definition: analysis_C.cpp:62
Custom exceptions and error codes used interally by DHARTAPI.
Definition: HFExceptions.h:22
@ OK
Operation was successful.
Definition: HFExceptions.h:32
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.
A wrapper for Intel's Embree Library.
A Graph of nodes connected by edges that supports both integers and HF::SpatialStructures::Node.
Definition: graph.h:486
std::vector< Node > Nodes() const
Get a list of nodes from the graph sorted by ID.