|
C_INTERFACE | CreatePath (const HF::SpatialStructures::Graph *g, int start, int end, const char *cost_type, int *out_size, HF::SpatialStructures::Path **out_path, HF::SpatialStructures::PathMember **out_data) |
| Find the shortest path from start to end. More...
|
|
C_INTERFACE | CreatePaths (const HF::SpatialStructures::Graph *g, const int *start, const int *end, const char *cost_type, HF::SpatialStructures::Path **out_path_ptr_holder, HF::SpatialStructures::PathMember **out_path_member_ptr_holder, int *out_sizes, int num_paths) |
| Find multiple shortest paths in paralllel. More...
|
|
C_INTERFACE | GetPathInfo (HF::SpatialStructures::Path *p, HF::SpatialStructures::PathMember **out_member_ptr, int *out_size) |
| Get the size of a path and a pointer to its path members. More...
|
|
C_INTERFACE | DestroyPath (HF::SpatialStructures::Path *path_to_destroy) |
| Delete a path. More...
|
|
C_INTERFACE | CreateAllToAllPaths (const HF::SpatialStructures::Graph *g, const char *cost_type, HF::SpatialStructures::Path **out_path_ptr_holder, HF::SpatialStructures::PathMember **out_path_member_ptr_holder, int *out_sizes, int num_paths) |
| Find a path from every node in a graph to every other node. More...
|
|
C_INTERFACE | CalculateDistanceAndPredecessor (const HF::SpatialStructures::Graph *g, const char *cost_name, std::vector< float > **out_dist_vector, float **out_dist_data, std::vector< int > **out_pred_vector, int **out_pred_data) |
| Calculate the distance and predecessor matricies for a graph. More...
|
|
Find paths between different points in a graph.
Mesh setup (energy blob)
Begin by loading an .obj file:
int status = 0;
const std::string obj_path_str = "energy_blob_zup.obj";
const int obj_length = static_cast<int>(obj_path_str.size());
std::vector<HF::Geometry::MeshInfo>* loaded_obj = nullptr;
const std::array<float, 3> rot { 0.0f, 0.0f, 0.0f };
status =
LoadOBJ(obj_path_str.c_str(), obj_length, rot[0], rot[1], rot[2], &loaded_obj);
if (status != 1) {
std::cerr << "Error at LoadOBJ, code: " << status << std::endl;
}
else {
std::cout << "LoadOBJ loaded mesh successfully into loaded_obj at address " << loaded_obj << ", code: " << status << std::endl;
}
C_INTERFACE LoadOBJ(const char *obj_path, HF::Geometry::GROUP_METHOD gm, float xrot, float yrot, float zrot, MeshInfo< float > ***out_data_array, int *num_meshes)
Load an obj from the given path then rotate it by x,y, and z.
Then, review the example at Raytracer setup (how to create a BVH).
Graph generation
You will then generate a graph, using the BVH:
const std::array<float, 3> start_point{ -30.0f, 0.0f, 20.0f };
const std::array<float, 3> spacing{ 2.0f, 2.0f, 180.0f };
const int max_nodes = 5000;
const int up_step = 30;
const int down_step = 70;
const int up_slope = 60;
const int down_slope = 60;
const int max_step_connections = 1;
const int min_connections = 1;
const int core_count = -1;
status =
GenerateGraph(bvh, start_point.data(), spacing.data(), max_nodes,
up_step, down_step, up_slope, down_slope,
max_step_connections, min_connections, core_count, &graph);
if (status != 1) {
std::cerr << "Error at GenerateGraph, code: " << status << std::endl;
}
else {
std::cout << "Generate graph ran successfully - graph stored at address " << graph << ", code: " << status << std::endl;
}
if (status != 1) {
std::cerr << "Error at Compress, code: " << status << std::endl;
}
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.
C_INTERFACE Compress(Graph *graph)
Compress the given graph into a CSR representation.
A Graph of nodes connected by edges that supports both integers and HF::SpatialStructures::Node.
Get nodes from graph
You can retrieve the nodes from the generated graph like this:
std::vector<HF::SpatialStructures::Node>* node_vector = nullptr;
if (status != 1) {
std::cerr << "Error at GetAllNodesFromGraph, code: " << status << std::endl;
}
int node_vector_size = -1;
if (status != 1) {
std::cerr << "Error at GetSizeOfNodeVector code: " << status << std::endl;
}
const int max_node = node_vector_size - 1;
std::cout << "Graph Generated with " << node_vector_size << " nodes" << std::endl;
C_INTERFACE GetAllNodesFromGraph(const Graph *graph, vector< Node > **out_vector_ptr, Node **out_data_ptr)
Get a vector of every node in the given graph pointer.
C_INTERFACE GetSizeOfNodeVector(const std::vector< HF::SpatialStructures::Node > *node_list, int *out_size)
Get the size of a node vector.
A point in space with an ID.
Destroy nodes from graph
When you are finished with the graph node container, you must destroy it:
if (status != 1) {
std::cerr << "Error at DestroyNodes, code: " << status << std::endl;
}
C_INTERFACE DestroyNodes(std::vector< HF::SpatialStructures::Node > *nodelist_to_destroy)
Delete the vector of nodes at the given pointer.
Destroy graph
When you are finished with the graph, you must destroy it:
if (status != 1) {
std::cerr << "Error at DestroyGraph, code: " << status << std::endl;
}
C_INTERFACE DestroyGraph(HF::SpatialStructures::Graph *graph_to_destroy)
Delete a graph.
◆ CalculateDistanceAndPredecessor()
C_INTERFACE CalculateDistanceAndPredecessor |
( |
const HF::SpatialStructures::Graph * |
g, |
|
|
const char * |
cost_name, |
|
|
std::vector< float > ** |
out_dist_vector, |
|
|
float ** |
out_dist_data, |
|
|
std::vector< int > ** |
out_pred_vector, |
|
|
int ** |
out_pred_data |
|
) |
| |
#include <Cinterface/pathfinder_C.h>
Calculate the distance and predecessor matricies for a graph.
- Parameters
-
g | The graph calculate the distance and predecessor matricies for |
cost_name | The name of the cost type to use for generating paths. Leaving as an empty string will use the default cost of g . |
out_dist_vector | Pointer to be updated with a vector containing the distance matrix |
out_dist_data | Pointer to be updated with a pointer to the data contained by out_dist_vector |
out_pred_vector | Pointer to be updated with the vector containing the predecessor matrix. |
out_pred_data | Pointer to be updated with the data of out_pred_vector |
- Returns
HF_STATUS::OK
If the function completed successfully.
-
HF_STATUS::NO_COST
If cost type
was not the key of any existing cost type in the graph.
- Postcondition
- 1)
out_dist_vector
is updated to contain a pointer to the newly created distance matrix
-
2)
out_dist_data
is updated to contain a pointer to the data of out_dist_vector
-
3)
out_pred_vector
is updated to contain a pointer to the newly created predecessor matrix
-
4)
out_pred_data
is updated to contain a pointer to the data of out_pred_vector
- Warning
- It is the caller's responsibility to deallocate the distance and predecessor matricies by calling DestroyIntVector and DestroyFloatVector. Failing to do so WILL leak memory. Do NOT attempt to delete the data arrays, they will automatically be deleted when their vectors are deleted.
- See also
- Raytracer setup (how to create a BVH), Raytracer teardown (how to destroy a BVH)
-
DestroyFloatVector
-
DestroyIntVector
-
DestroyPath for information on deleting the path after usage.
Begin by reviewing the example at Raytracer setup to load an .obj file (mesh), and create a BVH from the mesh.
Then generate a graph (Graph generation) from the BVH – see Get nodes from graph on how to retrieve nodes from the graph.
- Example
Create a graph, add some edges – then invoke CalculateDistanceAndPredecessor
Graph * g;
vector<vector<float>> nodes = {
{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 1, 2}
};
std::vector<float>* dist_vector; std::vector<int>* pred_vector;
float* dist_data; int* pred_data;
C_INTERFACE CalculateDistanceAndPredecessor(const Graph *g, const char *cost_name, vector< float > **out_dist_vector, float **out_dist_data, vector< int > **out_pred_vector, int **out_pred_data)
Calculate the distance and predecessor matricies for a graph.
C_INTERFACE CreateGraph(const float *nodes, int num_nodes, Graph **out_graph)
Create a new empty graph.
C_INTERFACE AddEdgeFromNodes(Graph *graph, const float *parent, const float *child, float score, const char *cost_type)
Add an edge between parent and child. If parent or child does not already exist in the graph,...
Print the result:
const int array_length = dist_vector->size();
std::cout << "Distance Matrix: [";
for (int i = 0; i < array_length; i++)
std::cout << dist_vector->at(i) << (i == array_length - 1 ? "]\r\nPredecessor Mattrix: [" : ", ");
for (int i = 0; i < array_length; i++)
std::cout << pred_vector->at(i) << (i == array_length - 1 ? "]\r\n" : ", ");
C_INTERFACE DestroyIntVector(std::vector< int > *int_vector)
Delete a vector of integers.
C_INTERFACE DestroyFloatVector(std::vector< float > *float_vector)
Delete a float vector that's pointed to by float_vector
>>> Distance Matrix: [0.000000, 10.000000, 5.000000, 10.000000, 0.000000, 15.000000, -1.000000, -1.000000, 0.000000]
>>> Predecessor Matrix: [0, 0, 0, 1, 1, 0, -1, -1, 2]\n
Definition at line 171 of file pathfinder_C.cpp.
References HF::Pathfinding::CreateBoostGraph(), HF::Pathfinding::DistanceAndPredecessor::dist, HF::Pathfinding::GenerateDistanceAndPred(), and HF::Pathfinding::DistanceAndPredecessor::pred.
◆ CreateAllToAllPaths()
#include <Cinterface/pathfinder_C.h>
Find a path from every node in a graph to every other node.
- Parameters
-
g | The graph to conduct the search on nodes that already exist within the graph. |
cost_name | The name of the cost type to use for generating paths. Leaving as an empty string will use the default cost of g . |
out_size | An empty array of integers that will be updated to contain the length of every path in path_members . Paths that could not be generated will be left with a length of zero. |
out_path | Location for the the path pointer array to be created. Paths that could not be generated will be left as null pointers. |
out_data | Location for the pathmember pointer array to be created. All path member pointers will point to the PathMembers of the Path in paths at the same index. Paths that could not be generated will be left as null pointers. |
- Returns
HF_STATUS::OK
The completed successfully and all postconditions were fulfilled.
-
HF_STATUS::NO_COST
cost_name
is not a valid cost type name
- Precondition
- If
cost_type
is specified, cost_type
must be the the key of an already existing cost in g
- Postcondition
- 1)
out_path_members
will point to a vector of pointers to vectors of PathMembers with an element for every path. Paths that could not be generated will be set to null pointers.
-
2)
out_paths
will point to a vector of pointers to paths with an element for every path. Paths that could not be generated will be set to null pointers.
-
3)
out_sizes
will point to an array of integers containing the size of every path in out_paths
. Paths that could not be generated will have a size of 0.
- Warning
- The caller is responsible for freeing all of the memory allocated in
out_paths
and out_sizes
. The contents of out_path_members
will automatically be deleted when the path they belong to is deleted. Do not try to manually delete out_path_members
or the path that owns it will throw a null pointer exception when it is deleted.
- See also
- Mesh setup (how to load an .OBJ file/create a mesh)
-
Raytracer setup (how to create a BVH)
-
Graph generation (how to generate a graph from a BVH)
-
Get nodes from graph (how to retrieve nodes from a graph)
-
DestroyPath for information on deleting the path after usage.
-
Destroy nodes from graph (how to destroy nodes from a graph)
-
Destroy graph (how to destroy a graph)
-
Raytracer teardown (how to destroy a BVH)
-
Mesh teardown (how to destroy a mesh)
Now we are ready to invoke CreateAllToAllPaths .
auto bg = CreateBoostGraph(g);
const size_t node_count = g.
Nodes().size();
const size_t path_count = node_count * node_count;
std::vector<Path*> out_paths(path_count);
std::vector<PathMember*> out_path_member(path_count);
std::vector<int> sizes(path_count);
int curr_id = 0;
std::vector<int> start_points(path_count);
for (int i = 0; i < node_count; i++) {
for (int k = 0; k < node_count; k++) {
start_points[curr_id++] = i;
}
}
curr_id = 0;
std::vector<int> end_points(path_count);
for (int i = 0; i < node_count; i++) {
for (int k = 0; k < node_count; k++) {
end_points[curr_id++] = k;
}
}
CreateAllToAllPaths(&g,
"", out_paths.data(), out_path_member.data(), sizes.data(), path_count);
auto start_points_it = start_points.begin();
auto end_points_it = end_points.begin();
for (auto p : out_paths) {
if (p) {
int total_cost = 0;
std::cout << "Path from " << *(start_points_it++) << " to " << *(end_points_it++) << std::endl;
for (auto m : p->members) {
total_cost += m.cost;
std::cout << "node ID: " << m.node << "\tcost " << m.cost << std::endl;
}
std::cout << "Total cost: " << total_cost << std::endl;
std::cout << "--------------------------" << std::endl;
}
}
for (auto& p : out_paths) {
p = nullptr;
}
C_INTERFACE DestroyPath(Path *path_to_destroy)
Delete a path.
C_INTERFACE CreateAllToAllPaths(const HF::SpatialStructures::Graph *g, const char *cost_type, HF::SpatialStructures::Path **out_path_ptr_holder, HF::SpatialStructures::PathMember **out_path_member_ptr_holder, int *out_sizes, int num_paths)
Find a path from every node in a graph to every other 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.
void Compress()
Compress the graph to a CSR and enable the usage of several functions.
std::vector< Node > Nodes() const
Get a list of nodes from the graph sorted by ID.
Path from 0 to 1
node ID : 0 cost 1
node ID : 1 cost 0
Total cost : 1
--------------------------
Path from 0 to 2
node ID : 0 cost 2
node ID : 2 cost 0
Total cost : 2
--------------------------
Path from 0 to 3
node ID : 0 cost 1
node ID : 1 cost 3
node ID : 3 cost 0
Total cost : 4
--------------------------
Path from 0 to 4
node ID : 0 cost 1
node ID : 1 cost 4
node ID : 4 cost 0
Total cost : 5
--------------------------
Path from 0 to 5
node ID : 0 cost 1
node ID : 1 cost 3
node ID : 3 cost 5
node ID : 5 cost 0
Total cost : 9
--------------------------
Path from 0 to 6
node ID : 0 cost 1
node ID : 1 cost 4
node ID : 4 cost 3
node ID : 6 cost 0
Total cost : 8
--------------------------
Path from 1 to 3
node ID : 1 cost 3
node ID : 3 cost 0
Total cost : 3
--------------------------
Path from 1 to 4
node ID : 1 cost 4
node ID : 4 cost 0
Total cost : 4
--------------------------
Path from 1 to 5
node ID : 1 cost 3
node ID : 3 cost 5
node ID : 5 cost 0
Total cost : 8
--------------------------
Path from 1 to 6
node ID : 1 cost 4
node ID : 4 cost 3
node ID : 6 cost 0
Total cost : 7
--------------------------
Path from 2 to 4
node ID : 2 cost 4
node ID : 4 cost 0
Total cost : 4
--------------------------
Path from 2 to 6
node ID : 2 cost 4
node ID : 4 cost 3
node ID : 6 cost 0
Total cost : 7
--------------------------
Path from 3 to 5
node ID : 3 cost 5
node ID : 5 cost 0
Total cost : 5
--------------------------
Path from 3 to 6
node ID : 3 cost 5
node ID : 5 cost 1
node ID : 6 cost 0
Total cost : 6
--------------------------
Path from 4 to 6
node ID : 4 cost 3
node ID : 6 cost 0
Total cost : 3
--------------------------
Path from 5 to 6
node ID : 5 cost 1
node ID : 6 cost 0
Total cost : 1
--------------------------
Definition at line 138 of file pathfinder_C.cpp.
References HF::Pathfinding::CreateBoostGraph(), and HF::Pathfinding::InsertAllToAllPathsIntoArray().
◆ CreatePath()
#include <Cinterface/pathfinder_C.h>
Find the shortest path from start to end.
- Parameters
-
g | The graph to conduct the search on. |
start | Start node of the path. |
end | End node of the path. |
cost_name | The name of the cost in g to use for shortest path calculations. Set to an empty string to use the cost g was constructed with. |
out_size | Updated to the length of the found path on success. Set to 0 if no path could be found. |
out_path | Output parameter for a pointer to the generated path. Will be null if no path could be found |
out_data | Output parameter for a pointer to the data of the generated path. Will be null if no path could be found. |
- Returns
HF_STATUS::OK
The function completed successfully.
-
HF_STATUS::NO_PATH
No path could be found
-
HF_STATUS::NO_COST
cost_name
is not an empty string or the key of a cost that already exists in G
- Precondition
- 1)
start
and end
contain both contain the Ids of nodes already in the graph
-
2) If not set to the empty string,
cost_name
is the key to a valid cost type already defined in g
.
- Postcondition
- If
OK
is returned, a path between start and end was found and out_size
, out_path
, and out_data
, are updated to contain the number of nodes in the path, a pointer to the path itself, and a pointer to the PathMembers it holds respectively.
- Warning
- The caller is responsible for deleting the path returned by out_path by calling DestroyPath if this function completes successfully. Freeing the memory for a path will also free the memory for its path members, so do not attempt to access its members after deletion.
- See also
- Mesh setup (how to load an .OBJ file/create a mesh)
-
Raytracer setup (how to create a BVH)
-
Graph generation (how to generate a graph from a BVH)
-
Get nodes from graph (how to retrieve nodes from a graph)
-
DestroyPath for information on deleting the path after usage.
-
Destroy nodes from graph (how to destroy nodes from a graph)
-
Destroy graph (how to destroy a graph)
-
Raytracer teardown (how to destroy a BVH)
-
Mesh teardown (how to destroy a mesh)
Begin by reviewing the example at Raytracer setup to load an .obj file (mesh), and create a BVH from the mesh.
Then generate a graph (Graph generation) from the BVH – see Get nodes from graph on how to retrieve nodes from the graph.
Now we are ready to create a path. We will find the path from the first node to the last indexed node.
const int start_id = 0;
const int end_id = node_vector->size() - 1;
const char* cost_type = "";
int path_size = -1;
status =
CreatePath(graph, start_id, end_id, cost_type, &path_size, &path, &path_data);
if (status != 1) {
std::cerr << "Error at CreatePath, code: " << status << std::endl;
}
else {
if (path) {
std::cout << "CreatePath stored path successfully - path stored at address " << path << ", code: " << status << std::endl;
auto path_sum = 0.0f;
for (
auto& member : path->
members) { path_sum += member.cost; }
std::cout << "Total path cost: " << path_sum << std::endl;
}
}
C_INTERFACE CreatePath(const HF::SpatialStructures::Graph *g, int start, int end, const char *cost_type, int *out_size, HF::SpatialStructures::Path **out_path, HF::SpatialStructures::PathMember **out_data)
Find the shortest path from start to end.
The ID of a node, and the cost cost to the node after it.
A collection of nodes that form a path.
std::vector< PathMember > members
Ordered array of PathMembers that comprise the path.
From here, please review the examples on how to destroy a path (DestroyPath),
as well as how to destroy a vector<HF::SpatialStructures::Node> (Destroy nodes from graph),
how to destroy a HF::SpatialStructures::Graph (Destroy graph),
how to destroy a HF::RayTracer::EmbreeRayTracer (Raytracer teardown),
and how to destroy a vector<HF::Geometry::MeshInfo> (Mesh teardown).
>>> LoadOBJ loaded mesh successfully into loaded_obj at address 000001DF01EB9470, code: 1
>>> CreateRaytracer created EmbreeRayTracer successfully into bvh at address 000001DF01EB5100, code: 1
>>> Generate graph ran successfully - graph stored at address 000001DF0BCEDDA0, code: 1
>>> Graph Generated with 886 nodes
>>> CreatePath stored path successfully - path stored at address 000001DF01EB9590, code: 1
>>> Total path cost: 77.6772
Definition at line 23 of file pathfinder_C.cpp.
References HF::Pathfinding::CreateBoostGraph(), HF::SpatialStructures::Path::empty(), HF::Pathfinding::FindPath(), HF::Exceptions::GENERIC_ERROR, HF::SpatialStructures::Path::GetPMPointer(), HF::Exceptions::NO_COST, HF::Exceptions::NO_PATH, HF::Exceptions::OK, and HF::SpatialStructures::Path::size().
◆ CreatePaths()
#include <Cinterface/pathfinder_C.h>
Find multiple shortest paths in paralllel.
- Parameters
-
g | The graph to conduct the search on |
start | An array of ids for starting nodes. Length must match that of end and all the IDS must belong to nodes that already exist within the graph. |
end | An array of ids for ending nodes. Length must match that of start and all the IDS must belong to nodes that already exist within the graph. |
cost_name | The name of the cost type to use for generating paths. Leaving as an empty string will use the default cost of g . |
out_size | An empty array of integers that will be updated to contain the length of every path in path_members . Paths that could not be generated will be left with a length of zero. |
out_path | Location for the the path pointer array to be created. Paths that could not be generated will be left as null pointers. |
out_data | Location for the pathmember pointer array to be created. All path member pointers will point to the PathMembers of the Path in paths at the same index. Paths that could not be generated will be left as null pointers. |
- Returns
HF_STATUS::OK
if the function completes successfully
-
HF_STATUS::NO_COST
is cost_name
is not a valid cost type name
- Precondition
- 1) The length of
start_ids
, end_ids
, and out_size
must be equal.
-
2) If
cost_type
is specified, cost_type
must be the the key of an already existing cost in g
- Postcondition
- 1)
out_path_members
will point to a vector of pointers to vectors of PathMembers with an element for every path. paths that could not be generated will be set to null pointers.
-
2)
out_paths
will point to a vector of pointers to paths with an element for every path. Paths that could not be generated will be set to null pointers.
-
3)
out_sizes
will point to an array of integers containing the size of every path in out_paths
. Paths that could not be generated will have a size of 0.
- Warning
- The caller is responsible for freeing all of the memory allocated in
out_paths
and out_sizes
. The contents of out_path_members
will automatically be deleted when the path they belong to is deleted. Do not try to manually delete out_path_members
or the path that owns it will throw a null pointer exception when it is deleted.
- See also
- Mesh setup (how to load an .OBJ file/create a mesh)
-
Raytracer setup (how to create a BVH)
-
Graph generation (how to generate a graph from a BVH)
-
Get nodes from graph (how to retrieve nodes from a graph)
-
DestroyPath for information on deleting the path after usage.
-
Destroy nodes from graph (how to destroy nodes from a graph)
-
Destroy graph (how to destroy a graph)
-
Raytracer teardown (how to destroy a BVH)
-
Mesh teardown (how to destroy a mesh)
No cost type:
Graph g;
g.addEdge(0, 1, 1);
g.addEdge(0, 2, 2);
g.addEdge(1, 3, 3);
g.addEdge(2, 4, 1);
g.addEdge(3, 4, 5);
g.Compress();
const int MAX_PATHS = 2;
const int MAX_PATHMEMBERS = 2;
std::array<int, 2> start_nodes{ 0, 0 };
std::array<int, 2> end_nodes{ 3, 4 };
std::array<Path*, MAX_PATHS> out_path;
std::array<PathMember*, MAX_PATHMEMBERS> out_path_member;
std::array<int, MAX_PATHS> out_sizes;
CreatePaths(&g, start_nodes.data(), end_nodes.data(),
"\0", out_path.data(), out_path_member.data(), out_sizes.data(), MAX_PATHS);
for (auto& p : out_path) {
p = nullptr;
}
C_INTERFACE CreatePaths(const HF::SpatialStructures::Graph *g, const int *start, const int *end, const char *cost_type, HF::SpatialStructures::Path **out_path_ptr_holder, HF::SpatialStructures::PathMember **out_path_member_ptr_holder, int *out_sizes, int num_paths)
Find multiple shortest paths in paralllel.
std::unique_ptr< BoostGraph, BoostGraphDeleter > CreateBoostGraph(const Graph &g, const std::string &cost_type)
Create a new boost graph from a HF::SpatialStructures:Graph.
With a cost type:
Node node_0(1.0f, 1.0f, 2.0f);
Node node_1(2.0f, 3.0f, 4.0f);
Node node_2(11.0f, 22.0f, 14.0f);
Node node_3(62.9f, 39.1f, 18.0f);
Node node_4(99.5f, 47.1f, 29.9f);
Graph graph;
graph.addEdge(node_0, node_1, 1);
graph.addEdge(node_0, node_2, 2.5);
graph.addEdge(node_1, node_3, 54.0);
graph.addEdge(node_2, node_4, 39.0);
graph.addEdge(node_3, node_4, 1.2);
graph.Compress();
auto edge_set = CalculateEnergyExpenditure(graph);
graph.AddEdges(edge_set, desired_cost_type);
const int MAX_PATHS = 2;
const int MAX_PATHMEMBERS = 2;
std::array<int, 2> start_nodes{ 0, 0 };
std::array<int, 2> end_nodes{ 3, 4 };
std::array<Path*, MAX_PATHS> out_path;
std::array<PathMember*, MAX_PATHMEMBERS> out_path_member;
std::array<int, MAX_PATHS> out_sizes;
CreatePaths(&graph, start_nodes.data(), end_nodes.data(), desired_cost_type.c_str(), out_path.data(), out_path_member.data(), out_sizes.data(), MAX_PATHS);
for (auto& p : out_path) {
p = nullptr;
}
std::string AlgorithmCostTitle(COST_ALG_KEY key)
Get the cost algorithm title (as std::string) from the COST_ALG_KEY enum member.
@ CROSS_SLOPE
Cost created by CalculateAndStoreCrossSlope.
EdgeSet CalculateEnergyExpenditure(const Subgraph &sg)
A graph usable with the BoostGraphLibrary.
>>> TODO output
Definition at line 70 of file pathfinder_C.cpp.
References HF::Pathfinding::CreateBoostGraph(), HF::Exceptions::GENERIC_ERROR, HF::Pathfinding::InsertPathsIntoArray(), HF::Exceptions::NO_COST, and HF::Exceptions::OK.
◆ DestroyPath()
◆ GetPathInfo()
#include <Cinterface/pathfinder_C.h>
Get the size of a path and a pointer to its path members.
- Parameters
-
p | Pointer to the path to get information from. This can handle null values. |
out_member_ptr | Pointer to the path to get information from. Should not be null. |
out_size | The number of path members in the path. (PathMember count within *p) |
- Returns
- HF_STATUS::OK on success, HF_STATUS::NO_PATH if the path *p is invalid
- See also
- Mesh setup (how to load an .OBJ file/create a mesh)
-
Raytracer setup (how to create a BVH)
-
Graph generation (how to generate a graph from a BVH)
-
Get nodes from graph (how to retrieve nodes from a graph)
-
DestroyPath for information on deleting the path after usage.
-
Destroy nodes from graph (how to destroy nodes from a graph)
-
Destroy graph (how to destroy a graph)
-
Raytracer teardown (how to destroy a BVH)
-
Mesh teardown (how to destroy a mesh)
int out_size = -1;
CreatePath(&g, 0, 4,
"\0", &out_size, &out_path, &out_path_member);
out_path_member = nullptr;
C_INTERFACE GetPathInfo(HF::SpatialStructures::Path *p, PathMember **out_member_ptr, int *out_size)
Get the size of a path
>>> TODO output
Get the size of a path and a pointer to its path members.
Definition at line 115 of file pathfinder_C.cpp.
References HF::SpatialStructures::Path::GetPMPointer(), HF::Exceptions::NO_PATH, HF::Exceptions::OK, and HF::SpatialStructures::Path::size().