DHART
Loading...
Searching...
No Matches
SpatialStructures

Functions

C_INTERFACE GetAllNodesFromGraph (const HF::SpatialStructures::Graph *graph, std::vector< HF::SpatialStructures::Node > **out_vector_ptr, HF::SpatialStructures::Node **out_data_ptr)
 Get a vector of every node in the given graph pointer. More...
 
C_INTERFACE GetEdgesForNode (const HF::SpatialStructures::Graph *graph, const HF::SpatialStructures::Node *Node, std::vector< HF::SpatialStructures::Edge > **out_vector_ptr, HF::SpatialStructures::Edge **out_edge_list_ptr, int *out_edge_list_size)
 Get a vector of edges every node in the given graph pointer. More...
 
C_INTERFACE GetSizeOfNodeVector (const std::vector< HF::SpatialStructures::Node > *node_list, int *out_size)
 Get the size of a node vector. More...
 
C_INTERFACE GetSizeOfEdgeVector (const std::vector< HF::SpatialStructures::Edge > *edge_list, int *out_size)
 Get the size of an edge vector. More...
 
C_INTERFACE GetEdgeCost (const HF::SpatialStructures::Graph *g, int parent, int child, const char *cost_type, float *out_float)
 Get the cost of traversing from parent to child More...
 
C_INTERFACE AggregateCosts (const HF::SpatialStructures::Graph *graph, int agg, bool directed, const char *cost_type, std::vector< float > **out_vector_ptr, float **out_data_ptr)
 Get an ordered array of costs for each node aggregated by the desired function. More...
 
C_INTERFACE CreateGraph (const float *nodes, int num_nodes, HF::SpatialStructures::Graph **out_graph)
 Create a new empty graph. More...
 
C_INTERFACE AddEdgeFromNodes (HF::SpatialStructures::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, they will be added and automatically assigned new IDs. More...
 
C_INTERFACE AddEdgeFromNodeIDs (HF::SpatialStructures::Graph *graph, int parent_id, int child_id, float score, const char *cost_type)
 Create a new edge between parent_id and child_id. If these IDs do not exist in the graph, they will be added. More...
 
C_INTERFACE GetCSRPointers (HF::SpatialStructures::Graph *graph, int *out_nnz, int *out_num_rows, int *out_num_cols, float **out_data_ptr, int **out_inner_indices_ptr, int **out_outer_indices_ptr, const char *cost_type)
 Retrieve all information for a graph's CSR representation. This will compress the graph if it was not already compressed. More...
 
C_INTERFACE GetNodeID (HF::SpatialStructures::Graph *graph, const float *point, int *out_id)
 Get the ID of the given node in the graph. If the node does not exist, out_id will be set to -1. More...
 
C_INTERFACE Compress (HF::SpatialStructures::Graph *graph)
 Compress the given graph into a CSR representation. More...
 
C_INTERFACE ClearGraph (HF::SpatialStructures::Graph *graph, const char *cost_type)
 Clear the nodes/edges for the given graph, or clear a specific cost type. More...
 
C_INTERFACE DestroyNodes (std::vector< HF::SpatialStructures::Node > *nodelist_to_destroy)
 Delete the vector of nodes at the given pointer. More...
 
C_INTERFACE DestroyEdges (std::vector< HF::SpatialStructures::Edge > *edgelist_to_destroy)
 Delete the vector of edges at the given pointer. More...
 
C_INTERFACE DestroyGraph (HF::SpatialStructures::Graph *graph_to_destroy)
 Delete a graph. More...
 
C_INTERFACE CalculateAndStoreCrossSlope (HF::SpatialStructures::Graph *g)
 Calculates cross slope for all subgraphs in *g. More...
 
C_INTERFACE CalculateAndStoreEnergyExpenditure (HF::SpatialStructures::Graph *g)
 Calculates energy expenditure for all subgraphs in *g and stores them in the graph at AlgorithmCostTitle(ALG_COST_KEY::EnergyExpenditure) More...
 
C_INTERFACE AddNodeAttributes (HF::SpatialStructures::Graph *g, const int *ids, const char *attribute, const char **scores, int num_nodes)
 Add a new node attribute in the graph for the nodes at ids. More...
 
C_INTERFACE GetNodeAttributes (const HF::SpatialStructures::Graph *g, const char *attribute, char **out_scores, int *out_score_size)
 Retrieve node attribute values from *g. More...
 
C_INTERFACE DeleteScoreArray (char **scores_to_delete, int num_char_arrays)
 Free the memory of every (char *) in scores_to_delete. More...
 
C_INTERFACE ClearAttributeType (HF::SpatialStructures::Graph *g, const char *s)
 Deletes the node attribute values of the type denoted by s, from graph *g. More...
 
C_INTERFACE GetSizeOfGraph (const HF::SpatialStructures::Graph *g, int *out_size)
 Get the number of nodes in a graph. More...
 
C_INTERFACE GraphAttrsToCosts (HF::SpatialStructures::Graph *graph_ptr, const char *attr_key, const char *cost_string, HF::SpatialStructures::Direction dir)
 Create a cost in the graph based on a set of node parameters. More...
 

Detailed Description

Contains the Graph and Node data types.

Graph Manipulation

Although graphs can be generated (see Graph generation),
they can also be created by objects instantiated or obtained by the user.

Graph setup

Call CreateGraph :

// Status code variable, value returned by C Interface functions
// See documentation for HF::Exceptions::HF_STATUS for error code definitions.
int status = 0;
// Declare a pointer to Graph.
// This will point to memory on the free store;
// it will be allocated within CreateGraph.
// It is the caller's responsibility to call DestroyGraph on g.
// The first two parameters are unused, according to documentation.
status = CreateGraph(nullptr, -1, &g);
if (status != 1) {
// Error!
std::cerr << "Error at CreateGraph, code: " << status << std::endl;
}
else {
std::cout << "CreateGraph ran successfully, graph is at address " << g << ", code: " << status << std::endl;
}
C_INTERFACE CreateGraph(const float *nodes, int num_nodes, Graph **out_graph)
Create a new empty graph.
A Graph of nodes connected by edges that supports both integers and HF::SpatialStructures::Node.
Definition: graph.h:486

Adding edges from nodes

Call AddEdgeFromNodes :

// Create three nodes, in the form of { x, y, z } coordinates
std::array<float, 3> n0 { 0, 0, 0 };
std::array<float, 3> n1 { 0, 1, 2 };
std::array<float, 3> n2 { 0, 1, 3 };
// Leave cost_type blank. We do not need a specific cost type now.
const char* cost_type = "";
status = AddEdgeFromNodes(g, n0.data(), n1.data(), 1, cost_type);
status = AddEdgeFromNodes(g, n0.data(), n2.data(), 2, cost_type);
status = AddEdgeFromNodes(g, n1.data(), n0.data(), 3, cost_type);
status = AddEdgeFromNodes(g, n1.data(), n2.data(), 4, cost_type);
status = AddEdgeFromNodes(g, n2.data(), n0.data(), 5, cost_type);
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,...

Adding edges from node IDs

Call AddEdgeFromNodeIds :

const int node_id_0 = 2;
const int node_id_1 = 1;
const float edge_weight = 5;
const char* cost_type = "";
status = AddEdgeFromNodeIDs(g, node_id_0, node_id_1, edge_weight, cost_type);
C_INTERFACE AddEdgeFromNodeIDs(Graph *graph, int parent_id, int child_id, float score, const char *cost_type)
Create a new edge between parent_id and child_id. If these IDs do not exist in the graph,...

Compressing the graph

status = Compress(g);
C_INTERFACE Compress(Graph *graph)
Compress the given graph into a CSR representation.

Retrieve a CSR of the graph

Call GetCSRPointers :

// Retrieve the CSR from the graph
status = GetCSRPointers(g, &csr.nnz, &csr.rows, &csr.cols, &csr.data, &csr.inner_indices, &csr.outer_indices, cost_type);
// data = { 1, 2, 3, 4, 5, 6 }
// r = { 0, 2, 4 }
// c = { 1, 2, 0, 2, 0, 1 }
if (status != 1) {
std::cerr << "Error at GetCSRPointers, code: " << status << std::endl;
}
else {
std::cout << "GetCSRPointers ran successfully on graph addressed at " << g << ", code: " << status << std::endl;
}
C_INTERFACE GetCSRPointers(Graph *graph, int *out_nnz, int *out_num_rows, int *out_num_cols, float **out_data_ptr, int **out_inner_indices_ptr, int **out_outer_indices_ptr, const char *cost_type)
Retrieve all information for a graph's CSR representation. This will compress the graph if it was not...
A struct to hold all necessary information for a CSR.
Definition: graph.h:54
int * outer_indices
Stores for each column (resp. row) the index of the first non-zero in the previous two arrays.
Definition: graph.h:60
int cols
Number of columns in this CSR.
Definition: graph.h:57
int nnz
Number of non-zeros contained by the CSR.
Definition: graph.h:55
int * inner_indices
Stores the row (resp. column) indices of the non-zeros.
Definition: graph.h:61
float * data
Stores the coefficient values of the non-zeros.
Definition: graph.h:59
int rows
Number of rows in this CSR.
Definition: graph.h:56


When you are finished with a graph, be sure to destroy it.
(see Destroy graph)

Destroying containers returned by graph operations

Graph operations deal in std::vector<HF::SpatialStructures::Node> *
and std::vector<HF::SpatialStructures::Edge> *.

Destroying a vector of node

Call DestroyNodes :

// Destroy vector<Node>
status = DestroyNodes(node_vec);
if (status != 1) {
std::cerr << "Error at DestroyNodes, code: " << status << std::endl;
}
else {
std::cout << "DestroyNodes ran successfully on address " << node_vec << ", code: " << status << std::endl;
}
C_INTERFACE DestroyNodes(std::vector< HF::SpatialStructures::Node > *nodelist_to_destroy)
Delete the vector of nodes at the given pointer.
Definition: CInterface.cpp:70

Destroying a vector of edge

Call DestroyEdges :

// Destroy vector<Edge>
status = DestroyEdges(edge_vec);
if (status != 1) {
std::cerr << "Error at DestroyEdges, code: " << status << std::endl;
}
else {
std::cout << "DestroyEdges ran successfully on address " << edge_vec << ", code: " << status << std::endl;
}
C_INTERFACE DestroyEdges(std::vector< HF::SpatialStructures::Edge > *edgelist_to_destroy)
Delete the vector of edges at the given pointer.
Definition: CInterface.cpp:75

Function Documentation

◆ AddEdgeFromNodeIDs()

C_INTERFACE AddEdgeFromNodeIDs ( HF::SpatialStructures::Graph graph,
int  parent_id,
int  child_id,
float  score,
const char *  cost_type 
)

#include <Cinterface/spatialstructures_C.h>

Create a new edge between parent_id and child_id. If these IDs do not exist in the graph, they will be added.

Parameters
graphGraph to create the new edge in
parentThe parent's ID in the graph
childThe child's ID in the graph
scoreThe cost from parent to child.
cost_typeThe type of cost to add this edge to.
Returns
HF_STATUS::OK on completion.
HF_STATUS::NOT_COMPRESSED if an alternate cost was added without first compressing the graph
HF_STATUS::NO_COST The given cost string was invalid.
See also
Graph setup (how to create a graph)
Adding edges from node IDs (how to add edges to a graph using node IDs)
Compressing the graph (how to compress a graph after adding/removing edges)
Destroy graph (how to destroy a graph)

Definition at line 170 of file spatialstructures_C.cpp.

References HF::SpatialStructures::Graph::addEdge(), HF::Exceptions::NO_COST, HF::Exceptions::NOT_COMPRESSED, HF::Exceptions::OK, HF::Exceptions::OUT_OF_RANGE, and parse_string().

+ Here is the call graph for this function:

◆ AddEdgeFromNodes()

C_INTERFACE AddEdgeFromNodes ( HF::SpatialStructures::Graph graph,
const float *  parent,
const float *  child,
float  score,
const char *  cost_type 
)

#include <Cinterface/spatialstructures_C.h>

Add an edge between parent and child. If parent or child does not already exist in the graph, they will be added and automatically assigned new IDs.

Parameters
graphGraph to add the new edge to
parentA three-element array of float containing the x, y, and z coordinates of the parent node
childA three-element array of float containing the x, y, and z coordinates of the child node.
scoreThe edge cost from parent to child
cost_typeEdge cost type
Returns
HF_STATUS::OK on success.
HF_STATUS::INVALID_PTR on an invalid parent or child node.
HF_STATUS::NOT_COMPRESSED Tried to add an edge to an alternate cost type when the graph wasn't compressed.
HF_STATUS::OUT_OF_RANGE Tried to add an edge to an alternate cost that didn't already exist in the default graph.
Precondition
cost_type MUST be a valid delimited char array. If the entire program crashes when this is called, this is why.
See also
Graph setup (how to create a graph)
Adding edges from nodes (how to add edges to a graph using nodes)
Compressing the graph (how to compress a graph after adding/removing edges)
Destroy graph (how to destroy a graph)

Definition at line 135 of file spatialstructures_C.cpp.

References HF::SpatialStructures::Graph::addEdge(), HF::Exceptions::INVALID_PTR, HF::Exceptions::NO_COST, HF::Exceptions::NOT_COMPRESSED, HF::Exceptions::OK, HF::Exceptions::OUT_OF_RANGE, and parse_string().

+ Here is the call graph for this function:

◆ AddNodeAttributes()

C_INTERFACE AddNodeAttributes ( HF::SpatialStructures::Graph g,
const int *  ids,
const char *  attribute,
const char **  scores,
int  num_nodes 
)

#include <Cinterface/spatialstructures_C.h>

Add a new node attribute in the graph for the nodes at ids.

Parameters
gGraph to add attributes to
idsIDs of nodes to add attributes to
attributeThe name of the attribute to add the scores to.
scoresAn ordered array of null terminated char arrays that correspond to the score of the ID in ids at the same index.
num_nodesLength of both the ids and scores arrays
Returns
HF_STATUS::OK on completion. Note that this does not guarantee that some or all of the node attributes have been added

For any id in ids, if said ID doesn't already exist in the graph, then it and its cost will silently be ignored without error.

Precondition
ids and scores arrays must be the same length
See also
Graph setup (how to create a graph)
Adding edges from nodes (how to add edges to a graph using nodes)
Adding edges from node IDs (how to add edges to a graph using node IDs)
Compressing the graph (how to compress a graph after adding/removing edges)
Retrieve a CSR of the graph (how to retrieve a CSR representation of a graph)
Destroy graph (how to destroy a graph)

Begin by reviewing the example at Graph setup to create a graph.

You may add edges to the graph using nodes (Adding edges from nodes)
or alternative, you may provide node IDs (graph_add_edge_from_node_IDs).

Be sure to compress the graph (Compressing the graph) every time you add/remove edges.

// We do not need edge cost type now.
const char* cost_type = "";
// Add edges by node IDs.
AddEdgeFromNodeIDs(g, 0, 1, 1, cost_type);
AddEdgeFromNodeIDs(g, 0, 2, 1, cost_type);
AddEdgeFromNodeIDs(g, 1, 3, 1, cost_type);
AddEdgeFromNodeIDs(g, 1, 4, 1, cost_type);
AddEdgeFromNodeIDs(g, 2, 4, 1, cost_type);
AddEdgeFromNodeIDs(g, 3, 5, 1, cost_type);
AddEdgeFromNodeIDs(g, 3, 6, 1, cost_type);
AddEdgeFromNodeIDs(g, 4, 5, 1, cost_type);
AddEdgeFromNodeIDs(g, 5, 6, 1, cost_type);
AddEdgeFromNodeIDs(g, 5, 7, 1, cost_type);
AddEdgeFromNodeIDs(g, 5, 8, 1, cost_type);
AddEdgeFromNodeIDs(g, 4, 8, 1, cost_type);
AddEdgeFromNodeIDs(g, 6, 7, 1, cost_type);
AddEdgeFromNodeIDs(g, 7, 8, 1, cost_type);
// Add some node attributes
std::vector<int> ids{ 1, 3, 5, 7 };
std::string attr_type = "cross slope";
const char* scores[4] = { "1.4", "2.0", "2.8", "4.0" };
AddNodeAttributes(g, ids.data(), attr_type.c_str(), scores, ids.size());
C_INTERFACE AddNodeAttributes(Graph *g, const int *ids, const char *attribute, const char **scores, int num_nodes)
Add a new node attribute in the graph for the nodes at ids.

Finally, when you are finished with the graph,
it must be destroyed. (Destroy graph)

Definition at line 290 of file spatialstructures_C.cpp.

References HF::SpatialStructures::Graph::AddNodeAttributes(), and HF::Exceptions::OK.

+ Here is the call graph for this function:

◆ AggregateCosts()

C_INTERFACE AggregateCosts ( const HF::SpatialStructures::Graph graph,
int  agg,
bool  directed,
const char *  cost_type,
std::vector< float > **  out_vector_ptr,
float **  out_data_ptr 
)

#include <Cinterface/spatialstructures_C.h>

Get an ordered array of costs for each node aggregated by the desired function.

Parameters
graphGraph to aggregate edges from
aggAggregation type to use
directedIf true, only consider edges for a node – otherwise, consider both outgoing and incoming edges.
cost_typeNode cost type string; type of cost to use for the graph
out_vector_ptrOutput parameter for the vector
out_data_ptrOutput parameter for the vector's internal buffer
Returns
HF_STATUS::OK if successful.
HF_STATUS::NOT_COMPRESSED if the graph wasn't compressed.
See also
Graph setup (how to create a graph)
Adding edges from nodes (how to add edges to a graph using nodes)
Adding edges from node IDs (how to add edges to a graph using node IDs)
Compressing the graph (how to compress a graph after adding/removing edges)
Destroy graph (how to destroy a graph)

Begin by reviewing the example at Graph setup to create a graph.

You may add edges to the graph using nodes (Adding edges from nodes)
or alternative, you may provide node IDs (graph_add_edge_from_node_IDs).

Be sure to compress the graph (Compressing the graph) every time you add/remove edges.

// Create three nodes in the form of { x, y, z } coordinates.
std::array<float, 3> n0 { 0, 0, 0 };
std::array<float, 3> n1 { 0, 1, 2 };
std::array<float, 3> n2 { 0, 1, 3 };
// We do not need a specific cost type now. Leave this as an empty string.
const char* cost_type = "";
status = AddEdgeFromNodes(g, n0.data(), n1.data(), 1, cost_type);
status = AddEdgeFromNodes(g, n0.data(), n2.data(), 2, cost_type);
status = AddEdgeFromNodes(g, n1.data(), n0.data(), 3, cost_type);
status = AddEdgeFromNodes(g, n1.data(), n2.data(), 4, cost_type);
status = AddEdgeFromNodes(g, n2.data(), n0.data(), 5, cost_type);
status = AddEdgeFromNodes(g, n2.data(), n1.data(), 6, cost_type);
// AggregateCosts will allocate memory for out_vector.
// out_data will point to *out_vector's internal buffer.
std::vector<float>* out_vector = nullptr;
float* out_data = nullptr;
int aggregation_type = 0;
status = AggregateCosts(g,
aggregation_type, false,
cost_type,
&out_vector, &out_data);
// Destroy vector<float>
status = DestroyFloatVector(out_vector);
if (status != 1) {
// Error!
std::cerr << "Error at DestroyFloatVector, code: " << status << std::endl;
}
else {
std::cout << "DestroyFloatVector ran successfully on address " << g << ", code: " << status << std::endl;
}
C_INTERFACE DestroyFloatVector(std::vector< float > *float_vector)
Delete a float vector that's pointed to by float_vector
C_INTERFACE AggregateCosts(const Graph *graph, int agg, bool directed, const char *cost_type, std::vector< float > **out_vector_ptr, float **out_data_ptr)
Get an ordered array of costs for each node aggregated by the desired function.

Finally, when you are finished with the graph,
it must be destroyed. (Destroy graph)

Definition at line 94 of file spatialstructures_C.cpp.

References HF::SpatialStructures::Graph::AggregateGraph(), HF::Exceptions::GENERIC_ERROR, HF::Exceptions::NO_COST, HF::Exceptions::NOT_COMPRESSED, HF::Exceptions::OK, and parse_string().

+ Here is the call graph for this function:

◆ CalculateAndStoreCrossSlope()

C_INTERFACE CalculateAndStoreCrossSlope ( HF::SpatialStructures::Graph g)

#include <Cinterface/spatialstructures_C.h>

Calculates cross slope for all subgraphs in *g.

Parameters
gThe graph to calculate cross slope on
Returns
HF_STATUS::OK on completion

Begin by reviewing the example at Graph setup to create a graph.

You may add edges to the graph using nodes (Adding edges from nodes)
or alternative, you may provide node IDs (graph_add_edge_from_node_IDs).

Be sure to compress the graph (Compressing the graph) every time you add/remove edges.

See also
Graph setup (how to create a graph)
Adding edges from nodes (how to add edges to a graph using nodes)
Adding edges from node IDs (how to add edges to a graph using node IDs)
Compressing the graph (how to compress a graph after adding/removing edges)
Retrieve a CSR of the graph (how to retrieve a CSR representation of a graph)
Destroy graph (how to destroy a graph)
// Create 7 nodes, in the form of {x, y, z}
std::array<float, 3> n0{ 0, 0, 0 };
std::array<float, 3> n1{ 1, 3, 5 };
std::array<float, 3> n2{ 3, -1, 2 };
std::array<float, 3> n3{ 1, 2, 1 };
std::array<float, 3> n4{ 4, 5, 7 };
std::array<float, 3> n5{ 5, 3, 2 };
std::array<float, 3> n6{ -2, -5, 1 };
// Retrieve the cost type string
const char* cost_type = AlgorithmCostTitle(COST_ALG_KEY::CROSS_SLOPE).c_str();
AddEdgeFromNodes(g, n0.data(), n1.data(), 0, cost_type);
AddEdgeFromNodes(g, n1.data(), n2.data(), 0, cost_type);
AddEdgeFromNodes(g, n1.data(), n3.data(), 0, cost_type);
AddEdgeFromNodes(g, n1.data(), n4.data(), 0, cost_type);
AddEdgeFromNodes(g, n2.data(), n4.data(), 0, cost_type);
AddEdgeFromNodes(g, n3.data(), n5.data(), 0, cost_type);
AddEdgeFromNodes(g, n5.data(), n6.data(), 0, cost_type);
AddEdgeFromNodes(g, n4.data(), n6.data(), 0, cost_type);
// Always compress the graph after adding edges!
status = Compress(g);
// Cross Slope will be calculated and stored within edges
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.
C_INTERFACE CalculateAndStoreCrossSlope(HF::SpatialStructures::Graph *g)
Calculates cross slope for all subgraphs in *g.

Finally, when you are finished with the graph,
it must be destroyed. (Destroy graph)

Definition at line 381 of file spatialstructures_C.cpp.

References HF::SpatialStructures::Graph::AddEdges(), AlgorithmCostTitle(), HF::SpatialStructures::CostAlgorithms::CalculateCrossSlope(), CROSS_SLOPE, and HF::Exceptions::OK.

+ Here is the call graph for this function:

◆ CalculateAndStoreEnergyExpenditure()

C_INTERFACE CalculateAndStoreEnergyExpenditure ( HF::SpatialStructures::Graph g)

#include <Cinterface/spatialstructures_C.h>

Calculates energy expenditure for all subgraphs in *g and stores them in the graph at AlgorithmCostTitle(ALG_COST_KEY::EnergyExpenditure)

Parameters
gThe address of a Graph
Returns
HF_STATUS::OK on completion

Begin by reviewing the example at Graph setup to create a graph.

You may add edges to the graph using nodes (Adding edges from nodes)
or alternative, you may provide node IDs (graph_add_edge_from_node_IDs).

Be sure to compress the graph (Compressing the graph) every time you add/remove edges.

See also
Graph setup (how to create a graph)
Adding edges from nodes (how to add edges to a graph using nodes)
Adding edges from node IDs (how to add edges to a graph using node IDs)
Compressing the graph (how to compress a graph after adding/removing edges)
Retrieve a CSR of the graph (how to retrieve a CSR representation of a graph)
Destroy graph (how to destroy a graph)
// Create 7 nodes, in the form of {x, y, z}
std::array<float, 3> n0{ 0, 0, 0 };
std::array<float, 3> n1{ 1, 3, 5 };
std::array<float, 3> n2{ 3, -1, 2 };
std::array<float, 3> n3{ 1, 2, 1 };
std::array<float, 3> n4{ 4, 5, 7 };
std::array<float, 3> n5{ 5, 3, 2 };
std::array<float, 3> n6{ -2, -5, 1 };
// Retrieve the cost type string
const char* cost_type = AlgorithmCostTitle(COST_ALG_KEY::CROSS_SLOPE).c_str();
AddEdgeFromNodes(g, n0.data(), n1.data(), 0, cost_type);
AddEdgeFromNodes(g, n1.data(), n2.data(), 0, cost_type);
AddEdgeFromNodes(g, n1.data(), n3.data(), 0, cost_type);
AddEdgeFromNodes(g, n1.data(), n4.data(), 0, cost_type);
AddEdgeFromNodes(g, n2.data(), n4.data(), 0, cost_type);
AddEdgeFromNodes(g, n3.data(), n5.data(), 0, cost_type);
AddEdgeFromNodes(g, n5.data(), n6.data(), 0, cost_type);
AddEdgeFromNodes(g, n4.data(), n6.data(), 0, cost_type);
// Always compress the graph after adding edges!
status = Compress(g);
// Energy Expenditure will be calculated and stored within edges
C_INTERFACE CalculateAndStoreEnergyExpenditure(HF::SpatialStructures::Graph *g)
Calculates energy expenditure for all subgraphs in *g and stores them in the graph at AlgorithmCostTi...

Finally, when you are finished with the graph,
it must be destroyed. (Destroy graph)

Definition at line 273 of file spatialstructures_C.cpp.

References HF::SpatialStructures::Graph::AddEdges(), AlgorithmCostTitle(), HF::SpatialStructures::CostAlgorithms::CalculateEnergyExpenditure(), ENERGY_EXPENDITURE, and HF::Exceptions::OK.

+ Here is the call graph for this function:

◆ ClearAttributeType()

C_INTERFACE ClearAttributeType ( HF::SpatialStructures::Graph g,
const char *  s 
)

#include <Cinterface/spatialstructures_C.h>

Deletes the node attribute values of the type denoted by s, from graph *g.

Parameters
gThe graph from which attributes of type s will be deleted
sThe attribute value type to be cleared from within g
Returns
HF_STATUS::OK on completion
// Create a graph and add some edges.
g.addEdge(0, 1, 1); g.addEdge(0, 2, 1); g.addEdge(1, 3, 1); g.addEdge(1, 4, 1);
g.addEdge(2, 4, 1); g.addEdge(3, 5, 1); g.addEdge(3, 6, 1); g.addEdge(4, 5, 1);
g.addEdge(5, 6, 1); g.addEdge(5, 7, 1); g.addEdge(5, 8, 1); g.addEdge(4, 8, 1);
g.addEdge(6, 7, 1); g.addEdge(7, 8, 1);
// Create score arrays, then assign them to the graph
std::vector<int> ids{ 1, 3, 5, 7 };
std::string attr_type = "cross slope";
const char* scores[4] = { "1.4", "2.0", "2.8", "4.0" };
AddNodeAttributes(&g, ids.data(), attr_type.c_str(), scores, ids.size());
// Clear the attribute type and capture the error code
auto res = ClearAttributeType(&g, attr_type.c_str());
C_INTERFACE ClearAttributeType(HF::SpatialStructures::Graph *g, const char *s)
Deletes the node attribute values of the type denoted by s, from graph *g.
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.
See also
Graph setup (how to create a graph)
Adding edges from nodes (how to add edges to a graph using nodes)
Adding edges from node IDs (how to add edges to a graph using node IDs)
Compressing the graph (how to compress a graph after adding/removing edges)
Retrieve a CSR of the graph (how to retrieve a CSR representation of a graph)
AddNodeAttributes (how to add node attributes)
link GetNodeAttributes (how to retrieve node attributes)
Destroy graph (how to destroy a graph)

Begin by reviewing the example at Graph setup to create a graph.

You may add edges to the graph using nodes (Adding edges from nodes)
or alternative, you may provide node IDs (graph_add_edge_from_node_IDs).

Be sure to compress the graph (Compressing the graph) every time you add/remove edges.

Finally, when you are finished with the graph,
it must be destroyed. (Destroy graph)

Definition at line 368 of file spatialstructures_C.cpp.

References HF::SpatialStructures::Graph::ClearNodeAttributes(), HF::Exceptions::INVALID_PTR, and HF::Exceptions::OK.

+ Here is the call graph for this function:

◆ ClearGraph()

C_INTERFACE ClearGraph ( HF::SpatialStructures::Graph graph,
const char *  cost_type 
)

#include <Cinterface/spatialstructures_C.h>

Clear the nodes/edges for the given graph, or clear a specific cost type.

Parameters
graphGraph to clear nodes from
cost_typeEdge cost type string (if clearing a specific cost type).
cost_typeIf blank, delete the graph, otherwise only clear the cost at this type.
Returns
HF_STATUS::OK if the operation succeeded
HF_STATUS::NO_COST if a cost was specified and it couldn't be found.
See also
Graph setup (how to create a graph)
Adding edges from nodes (how to add edges to a graph using nodes)
Adding edges from node IDs (how to add edges to a graph using node IDs)
Compressing the graph (how to compress a graph after adding/removing edges)
Retrieve a CSR of the graph (how to retrieve a CSR representation of a graph)
Destroy graph (how to destroy a graph)

Begin by reviewing the example at Graph setup to create a graph.

You may add edges to the graph using nodes (Adding edges from nodes)
or alternative, you may provide node IDs (graph_add_edge_from_node_IDs).

// Create two nodes in the form of { x, y, z } coordinates.
std::array<float, 3> n0{ 0, 0, 0 };
std::array<float, 3> n1{ 0, 1, 2 };
const float edge_weight = 3;
const char* cost_type = "";
AddEdgeFromNodes(g, n0.data(), n1.data(), edge_weight, cost_type);
ClearGraph(g, cost_type);
// The graph will now have a node count of 0.
C_INTERFACE ClearGraph(HF::SpatialStructures::Graph *graph, const char *cost_type)
Clear the nodes/edges for the given graph, or clear a specific cost type.

Finally, when you are finished with the graph,
it must be destroyed. (Destroy graph)

Definition at line 234 of file spatialstructures_C.cpp.

References HF::SpatialStructures::Graph::Clear(), HF::SpatialStructures::Graph::ClearCostArrays(), HF::Exceptions::NO_COST, and HF::Exceptions::OK.

+ Here is the call graph for this function:

◆ Compress()

#include <Cinterface/spatialstructures_C.h>

Compress the given graph into a CSR representation.

Parameters
graphThe graph to compress into a CSR.
Returns
HF_STATUS::OK on completion.
Remarks
This will reduce the memory footprint of the graph, and invalidate all existing CSR representation of it. If the graph is already compressed, this function will be a no-op.
See also
Graph setup (how to create a graph)
Adding edges from nodes (how to add edges to a graph using nodes)
Adding edges from node IDs (how to add edges to a graph using node IDs)
Compressing the graph (how to compress a graph after adding/removing edges)
Destroy graph (how to destroy a graph)

Definition at line 228 of file spatialstructures_C.cpp.

References HF::SpatialStructures::Graph::Compress(), and HF::Exceptions::OK.

+ Here is the call graph for this function:

◆ CreateGraph()

C_INTERFACE CreateGraph ( const float *  nodes,
int  num_nodes,
HF::SpatialStructures::Graph **  out_graph 
)

#include <Cinterface/spatialstructures_C.h>

Create a new empty graph.

Parameters
nodes(unused parameter) The node IDs to create nodes from
num_nodes(unused parameter) Size of nodes array
out_graphOutput parameter to store the graph in
Returns
HF_STATUS::OK on completion.
See also
Graph setup (how to create a graph)
Compressing the graph (how to compress a graph)
Destroy graph (how to destroy a graph)

Definition at line 124 of file spatialstructures_C.cpp.

References HF::Exceptions::OK.

◆ DeleteScoreArray()

C_INTERFACE DeleteScoreArray ( char **  scores_to_delete,
int  num_char_arrays 
)

#include <Cinterface/spatialstructures_C.h>

Free the memory of every (char *) in scores_to_delete.

Parameters
scores_to_deletePointer to array of (char *), allocate by the caller
num_char_arraysBlock count of scores_to_delete
Returns
HF_STATUS::OK on completion
See also
GetNodeAttributes on using DeleteScoreArray

Definition at line 354 of file spatialstructures_C.cpp.

References HF::Exceptions::OK.

◆ DestroyEdges()

C_INTERFACE DestroyEdges ( std::vector< HF::SpatialStructures::Edge > *  edgelist_to_destroy)

#include <Cinterface/spatialstructures_C.h>

Delete the vector of edges at the given pointer.

Parameters
edgelist_to_destroyVector of nodes to destroy
Returns
HF_STATUS::OK on completion.
See also
Destroying a vector of edge (how to destroy a vector of edge)

Definition at line 75 of file CInterface.cpp.

References HF::Exceptions::OK.

◆ DestroyGraph()

C_INTERFACE DestroyGraph ( HF::SpatialStructures::Graph graph_to_destroy)

#include <Cinterface/spatialstructures_C.h>

Delete a graph.

Parameters
graph_to_destroyGraph to delete
Returns
HF_STATUS::OK on completion
See also
Destroy graph (how to destroy a graph)

Definition at line 80 of file CInterface.cpp.

References HF::Exceptions::OK.

◆ DestroyNodes()

C_INTERFACE DestroyNodes ( std::vector< HF::SpatialStructures::Node > *  nodelist_to_destroy)

#include <Cinterface/spatialstructures_C.h>

Delete the vector of nodes at the given pointer.

Parameters
nodelist_to_destroyVector of nodes to destroy
Returns
HF_STATUS::OK on completion.
See also
Destroying a vector of node (how to destroy a vector of node)

Definition at line 70 of file CInterface.cpp.

References HF::Exceptions::OK.

◆ GetAllNodesFromGraph()

C_INTERFACE GetAllNodesFromGraph ( const HF::SpatialStructures::Graph graph,
std::vector< HF::SpatialStructures::Node > **  out_vector_ptr,
HF::SpatialStructures::Node **  out_data_ptr 
)

#include <Cinterface/spatialstructures_C.h>

Get a vector of every node in the given graph pointer.

Parameters
graphGraph to retrieve nodes from
out_vector_ptrOutput parameter for the new vector
out_data_ptrOutput parameter for the vector's data
Returns
HF_STATUS::INVALID_PTR if the given pointer was invalid. HF_STATUS::GENERIC_ERROR if the graph is not valid. HF_STATUS::OK if successful.
See also
Graph setup (how to create a graph)
Adding edges from nodes (how to add edges to a graph using nodes)
Adding edges from node IDs (how to add edges to a graph using node IDs)
Compressing the graph (how to compress a graph after adding/removing edges)
Destroying a vector of node (how to destroy a vector of node)
Destroy graph (how to destroy a graph)

Begin by reviewing the example at Graph setup to create a graph.

You may add edges to the graph using nodes (Adding edges from nodes)
or alternative, you may provide node IDs (graph_add_edge_from_node_IDs).

Be sure to compress the graph (Compressing the graph) every time you add/remove edges.

// Create three nodes, in the form of { x, y, z } coordinates
std::array<float, 3> n0 { 0, 0, 0 };
std::array<float, 3> n1 { 0, 1, 2 };
std::array<float, 3> n2 { 0, 1, 3 };
// Leave cost_type blank. We do not need a specific cost type now.
const char* cost_type = "";
status = AddEdgeFromNodes(g, n0.data(), n1.data(), 1, cost_type);
status = AddEdgeFromNodes(g, n0.data(), n2.data(), 2, cost_type);
status = AddEdgeFromNodes(g, n1.data(), n0.data(), 3, cost_type);
status = AddEdgeFromNodes(g, n1.data(), n2.data(), 4, cost_type);
status = AddEdgeFromNodes(g, n2.data(), n0.data(), 5, cost_type);
status = AddEdgeFromNodes(g, n2.data(), n1.data(), 6, cost_type);
// GetNodesFromGraph will allocate memory for out_vec.
// out_data will point to *out_vec's internal buffer.
std::vector<HF::SpatialStructures::Node>* out_vec = nullptr;
HF::SpatialStructures::Node* out_data = nullptr;
status = GetAllNodesFromGraph(g, &out_vec, &out_data);
// Destroy vector<Node>
status = DestroyNodes(out_vec);
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.
A point in space with an ID.
Definition: node.h:38

When you are finished with the node vector,
it must be destroyed. (Destroying a vector of node)

Finally, when you are finished with the graph,
it must be destroyed. (Destroy graph)

Definition at line 32 of file spatialstructures_C.cpp.

References HF::Exceptions::GENERIC_ERROR, HF::SpatialStructures::Graph::Nodes(), and HF::Exceptions::OK.

+ Here is the call graph for this function:

◆ GetCSRPointers()

C_INTERFACE GetCSRPointers ( HF::SpatialStructures::Graph graph,
int *  out_nnz,
int *  out_num_rows,
int *  out_num_cols,
float **  out_data_ptr,
int **  out_inner_indices_ptr,
int **  out_outer_indices_ptr,
const char *  cost_type 
)

#include <Cinterface/spatialstructures_C.h>

Retrieve all information for a graph's CSR representation. This will compress the graph if it was not already compressed.

Parameters
out_nnzNumber of non-zero values contained within the CSR
out_num_rowsNumber of rows contained within the CSR
out_num_colsNumber of columns contained within the CSR
out_data_ptrPointer to the CSR's data array
out_inner_indices_ptrPointer to the graph's inner indices array (columns)
out_outer_indices_ptrPointer to the graph's outer indices array (rpws)
cost_typeCost type to compress the CSR with.
Returns
HF_STATUS::OK on success.
HF_STATUS::NO_COST if the asked for cost doesn't exist.
See also
Graph setup (how to create a graph)
Adding edges from nodes (how to add edges to a graph using nodes)
Adding edges from node IDs (how to add edges to a graph using node IDs)
Compressing the graph (how to compress a graph after adding/removing edges)
Retrieve a CSR of the graph (how to retrieve a CSR representation of a graph)
Destroy graph (how to destroy a graph)

Definition at line 187 of file spatialstructures_C.cpp.

References HF::Exceptions::GENERIC_ERROR, HF::SpatialStructures::Graph::GetCSRPointers(), HF::SpatialStructures::CSRPtrs::nnz, HF::Exceptions::NO_COST, and HF::Exceptions::OK.

+ Here is the call graph for this function:

◆ GetEdgeCost()

C_INTERFACE GetEdgeCost ( const HF::SpatialStructures::Graph g,
int  parent,
int  child,
const char *  cost_type,
float *  out_float 
)

#include <Cinterface/spatialstructures_C.h>

Get the cost of traversing from parent to child

Parameters
gThe graph to traverse
parentID of the node being traversed from
childID of the node being traversed to
cost_typename of the cost type to get the cost from
out_floatOutput parameter for the cost of traversing from parent to child
Precondition
g is a valid graph.
Postcondition
out_float is updated with the cost of traversing from parent to child. If no edge exists between parent and child, -1 will be inserted into out_float.
Returns
HF_STATUS::OK on success
HF_STATUS::NO_COST if there was no cost with cost_name
See also
Graph setup (how to create a graph)
Adding edges from nodes (how to add edges to a graph using nodes)
Adding edges from node IDs (how to add edges to a graph using node IDs)
Compressing the graph (how to compress a graph after adding/removing edges)
Destroy graph (how to destroy a graph)

Begin by reviewing the example at Graph setup to create a graph.

You may add edges to the graph using nodes (Adding edges from nodes)
or alternative, you may provide node IDs (graph_add_edge_from_node_IDs).

Be sure to compress the graph (Compressing the graph) every time you add/remove edges.

Finally, when you are finished with the graph,
it must be destroyed. (Destroy graph)

Definition at line 66 of file spatialstructures_C.cpp.

References HF::Exceptions::GENERIC_ERROR, HF::SpatialStructures::Graph::GetCost(), HF::Exceptions::NO_COST, HF::Exceptions::NOT_COMPRESSED, and HF::Exceptions::OK.

+ Here is the call graph for this function:

◆ GetEdgesForNode()

C_INTERFACE GetEdgesForNode ( const HF::SpatialStructures::Graph graph,
const HF::SpatialStructures::Node Node,
std::vector< HF::SpatialStructures::Edge > **  out_vector_ptr,
HF::SpatialStructures::Edge **  out_edge_list_ptr,
int *  out_edge_list_size 
)

#include <Cinterface/spatialstructures_C.h>

Get a vector of edges every node in the given graph pointer.

Parameters
graphGraph to retrieve edges from
nodeNode within graph to retrieve edges for
out_vector_ptrOutput parameter for retrieved edges
out_edge_list_ptrAddress of pointer to *out_vector_ptr's internal buffer
out_edge_list_sizeWill store out_vector_ptr->size()
Returns
HF_STATUS::OK on completion.
See also
Graph setup (how to create a graph)
Adding edges from nodes (how to add edges to a graph using nodes)
Adding edges from node IDs (how to add edges to a graph using node IDs)
Compressing the graph (how to compress a graph after adding/removing edges)
Destroying a vector of edge (how to destroy a vector of edge)
Destroy graph (how to destroy a graph)

Begin by reviewing the example at Graph setup to create a graph.

You may add edges to the graph using nodes (Adding edges from nodes)
or alternative, you may provide node IDs (graph_add_edge_from_node_IDs).

Be sure to compress the graph (Compressing the graph) every time you add/remove edges.

When you are finished with the edge vector,
it must be destroyed. (Destroying a vector of edge)

Finally, when you are finished with the graph,
it must be destroyed. (Destroy graph)

◆ GetNodeAttributes()

C_INTERFACE GetNodeAttributes ( const HF::SpatialStructures::Graph g,
const char *  attribute,
char **  out_scores,
int *  out_score_size 
)

#include <Cinterface/spatialstructures_C.h>

Retrieve node attribute values from *g.

Parameters
gThe graph that will be used to retrieve node attribute values from
attributeThe node attribute type to retrieve from *g
out_scoresPointer to array of (char *), allocated by the caller
out_score_sizeKeeps track of the size of out_scores buffer, updated as required
Returns
HF_STATUS::OK on completion.

Memory shall be allocated in *out_scores to hold the char arrays. out_scores is a pointer to an array of (char *), which will be allocated by the caller. The caller must call DeleteScores to deallocate the memory addressed by each pointer in out_scores.

See also
Graph setup (how to create a graph)
Adding edges from nodes (how to add edges to a graph using nodes)
Adding edges from node IDs (how to add edges to a graph using node IDs)
Compressing the graph (how to compress a graph after adding/removing edges)
Retrieve a CSR of the graph (how to retrieve a CSR representation of a graph)
AddNodeAttributes (how to add node attributes)
Destroy graph (how to destroy a graph)

Begin by reviewing the example at Graph setup to create a graph.

You may add edges to the graph using nodes (Adding edges from nodes)
or alternative, you may provide node IDs (graph_add_edge_from_node_IDs).

Be sure to compress the graph (Compressing the graph) every time you add/remove edges.

// Create a graph and add edges
g.addEdge(0, 1, 1); g.addEdge(0, 2, 1); g.addEdge(1, 3, 1); g.addEdge(1, 4, 1);
g.addEdge(2, 4, 1); g.addEdge(3, 5, 1); g.addEdge(3, 6, 1); g.addEdge(4, 5, 1);
g.addEdge(5, 6, 1); g.addEdge(5, 7, 1); g.addEdge(5, 8, 1); g.addEdge(4, 8, 1);
g.addEdge(6, 7, 1); g.addEdge(7, 8, 1);
// Create a vector of node IDs and their corresponding values for our attribute
std::vector<int> ids{ 1, 3, 5, 7 };
std::string attr_type = "cross slope";
const char* scores[4] = { "1.4", "2.0", "2.8", "4.0" };
// Add node attributes to the graph
AddNodeAttributes(&g, ids.data(), attr_type.c_str(), scores, ids.size());
// Allocate an array of char arrays to meet the preconditions of GetNodeAttributes
char** scores_out = new char* [g.size()];
int scores_out_size = 0;
// By the postconditions of GetNodeAttributes, this should update scores_out,
// and scores_out_size with the variables we need
GetNodeAttributes(&g, attr_type.c_str(), scores_out, &scores_out_size);
// Assert that we can get the scores from this array
for (int i = 0; i < scores_out_size; i++)
{
// Convert score at this index to a string.
std::string score = scores_out[i];
// If it's in our input array, ensure that the score at this value
// matches the one we passed
auto itr = std::find(ids.begin(), ids.end(), i);
if (itr != ids.end())
{
// Get the index of the id in the scores array so we
// can compare use it to get our input score at that
// index as well.
int index = std::distance(ids.begin(), itr);
}
}
// Resource cleanup
DeleteScoreArray(scores_out, g.size());
C_INTERFACE GetNodeAttributes(const HF::SpatialStructures::Graph *g, const char *attribute, char **out_scores, int *out_score_size)
Retrieve node attribute values from *g.
C_INTERFACE DeleteScoreArray(char **scores_to_delete, int num_char_arrays)
Free the memory of every (char *) in scores_to_delete.
int size() const
Determine how many nodes are in the graph.

Finally, when you are finished with the graph,
it must be destroyed. (Destroy graph)

Definition at line 322 of file spatialstructures_C.cpp.

References HF::SpatialStructures::Graph::GetNodeAttributes(), and HF::Exceptions::OK.

+ Here is the call graph for this function:

◆ GetNodeID()

C_INTERFACE GetNodeID ( HF::SpatialStructures::Graph graph,
const float *  point,
int *  out_id 
)

#include <Cinterface/spatialstructures_C.h>

Get the ID of the given node in the graph. If the node does not exist, out_id will be set to -1.

Parameters
graphThe graph to get the ID from
pointA three-element array of float containing the x, y, and z coordinates of the point to get the ID for.
out_idOutput parameter for the ID. Set to -1 if point could not be found in graph .
Returns
HF_STATUS::OK on completion.
See also
Graph setup (how to create a graph)
Adding edges from nodes (how to add edges to a graph using nodes)
Adding edges from node IDs (how to add edges to a graph using node IDs)
Compressing the graph (how to compress a graph after adding/removing edges)
Destroy graph (how to destroy a graph)

Begin by reviewing the example at Graph setup to create a graph.

You may add edges to the graph using nodes (Adding edges from nodes)
or alternative, you may provide node IDs (graph_add_edge_from_node_IDs).

// Create two nodes in the form of { x, y, z } coordinates.
std::array<float, 3> n0 { 0, 0, 0 };
std::array<float, 3> n1 { 0, 1, 2 };
const float edge_weight = 3;
const char* cost_type = "";
status = AddEdgeFromNodes(g, n0.data(), n1.data(), edge_weight, cost_type);
// Determine the coordinates of the node whose ID you want to retrieve. result_id will store the retrieved ID.
std::array<float, 3> point { 0, 1, 2 };
int result_id = -1;
status = GetNodeID(g, point.data(), &result_id);
C_INTERFACE GetNodeID(HF::SpatialStructures::Graph *graph, const float *point, int *out_id)
Get the ID of the given node in the graph. If the node does not exist, out_id will be set to -1.

Finally, when you are finished with the graph,
it must be destroyed. (Destroy graph)

Definition at line 217 of file spatialstructures_C.cpp.

References HF::SpatialStructures::Graph::getID(), and HF::Exceptions::OK.

+ Here is the call graph for this function:

◆ GetSizeOfEdgeVector()

C_INTERFACE GetSizeOfEdgeVector ( const std::vector< HF::SpatialStructures::Edge > *  edge_list,
int *  out_size 
)

#include <Cinterface/spatialstructures_C.h>

Get the size of an edge vector.

Parameters
edge_listEdge vector to get the size from
out_sizeSize of the vector will be written to *out_size
Returns
HF_STATUS::OK on completion
Deprecated:
This is never used. Do not include.

Definition at line 65 of file CInterface.cpp.

References HF::Exceptions::OK.

◆ GetSizeOfGraph()

C_INTERFACE GetSizeOfGraph ( const HF::SpatialStructures::Graph g,
int *  out_size 
)

#include <Cinterface/spatialstructures_C.h>

Get the number of nodes in a graph.

Parameters
gPointer to the graph to get the size of
out_sizeLocation where the size of the graph will be written
Returns
HF_STATUS::OK on completion
See also
Graph setup (how to create a graph)
Adding edges from nodes (how to add edges to a graph using nodes)
Adding edges from node IDs (how to add edges to a graph using node IDs)
Compressing the graph (how to compress a graph after adding/removing edges)
Retrieve a CSR of the graph (how to retrieve a CSR representation of a graph)
Destroy graph (how to destroy a graph)

Begin by reviewing the example at Graph setup to create a graph.

You may add edges to the graph using nodes (Adding edges from nodes)
or alternative, you may provide node IDs (graph_add_edge_from_node_IDs).

Be sure to compress the graph (Compressing the graph) every time you add/remove edges.

// Create three nodes in the form of { x, y, z } coordinates.
std::array<float, 3> n0{ 0, 0, 0 };
std::array<float, 3> n1{ 0, 1, 2 };
std::array<float, 3> n2{ 0, 1, 3 };
// We do not need a specific cost type now. Leave this as an empty string.
const char* cost_type = "";
status = AddEdgeFromNodes(g, n0.data(), n1.data(), 1, cost_type);
status = AddEdgeFromNodes(g, n0.data(), n2.data(), 2, cost_type);
status = AddEdgeFromNodes(g, n1.data(), n0.data(), 3, cost_type);
status = AddEdgeFromNodes(g, n1.data(), n2.data(), 4, cost_type);
status = AddEdgeFromNodes(g, n2.data(), n0.data(), 5, cost_type);
status = AddEdgeFromNodes(g, n2.data(), n1.data(), 6, cost_type);
int graph_size = -1;
status = GetSizeOfGraph(g, &graph_size);
// graph_size will have the node count (graph size)
C_INTERFACE GetSizeOfGraph(const Graph *g, int *out_size)
Get the number of nodes in a graph.

Finally, when you are finished with the graph,
it must be destroyed. (Destroy graph)

Definition at line 400 of file spatialstructures_C.cpp.

References HF::Exceptions::OK, and HF::SpatialStructures::Graph::size().

+ Here is the call graph for this function:

◆ GetSizeOfNodeVector()

C_INTERFACE GetSizeOfNodeVector ( const std::vector< HF::SpatialStructures::Node > *  node_list,
int *  out_size 
)

#include <Cinterface/spatialstructures_C.h>

Get the size of a node vector.

Parameters
node_listNode vector to get the size from
out_sizeSize of the vector will be written to *out_size
Returns
HF_STATUS::OK on completion.
See also
Graph setup (how to create a graph)
Adding edges from nodes (how to add edges to a graph using nodes)
Adding edges from node IDs (how to add edges to a graph using node IDs)
Compressing the graph (how to compress a graph after adding/removing edges)
Destroying a vector of node (how to destroy a vector of node)
Destroy graph (how to destroy a graph)

Begin by reviewing the example at Graph setup to create a graph.

You may add edges to the graph using nodes (Adding edges from nodes)
or alternative, you may provide node IDs (graph_add_edge_from_node_IDs).

Be sure to compress the graph (Compressing the graph) every time you add/remove edges.

// Requires #include "node.h", #include <vector>
// Status code variable, value returned by C Interface functions
// See documentation for HF::Exceptions::HF_STATUS for error code definitions.
int status = 0;
// Since GetSizeOfNodeVector only operators on a vector<Node>,
// we can construct from free nodes and put them into a container.
// GetSizeOfNodeVector will return the size of *node_vec below.
std::vector<HF::SpatialStructures::Node>* node_vec = new std::vector<HF::SpatialStructures::Node>{ n0, n1, n2, n3 };
int node_vec_size = -1;
status = GetSizeOfNodeVector(node_vec, &node_vec_size);
// node_vec_size will have the size of *node_vec.
C_INTERFACE GetSizeOfNodeVector(const std::vector< HF::SpatialStructures::Node > *node_list, int *out_size)
Get the size of a node vector.
Definition: CInterface.cpp:60

When you are finished with the node vector,
it must be destroyed. (Destroying a vector of node)

Finally, when you are finished with the graph,
it must be destroyed. (Destroy graph)

Definition at line 60 of file CInterface.cpp.

References HF::Exceptions::OK.

◆ GraphAttrsToCosts()

C_INTERFACE GraphAttrsToCosts ( HF::SpatialStructures::Graph graph_ptr,
const char *  attr_key,
const char *  cost_string,
HF::SpatialStructures::Direction  dir 
)

#include <Cinterface/spatialstructures_C.h>

Create a cost in the graph based on a set of node parameters.

Parameters
graph_ptrGraph to perform this operation on
attr_keyAttribute to create a new cost set from.
cost_stringName of the new cost set.
dirDirection that the cost of the edge should be calculated in. For example INCOMING will use the cost of the node being traveled to by the edge.
Returns
HF_STATUS::OK If the cost was successfully added to the graph
HF_STATUS::NOT_FOUND If attr_key is not the key of an already existing node parameter.

Definition at line 405 of file spatialstructures_C.cpp.

References HF::SpatialStructures::Graph::AttrToCost(), HF::Exceptions::NOT_FOUND, and HF::Exceptions::OK.

+ Here is the call graph for this function: