23 std::string test_string(c);
35 return HF_STATUS::INVALID_PTR;
39 std::vector<Node>* nodes =
new vector<Node>();
41 *nodes = graph->
Nodes();
43 *out_data_ptr = nodes->data();
44 *out_vector_ptr = nodes;
47 catch (...) {
return HF_STATUS::GENERIC_ERROR; }
51 const vector<Node>* node_list,
54 *out_size = node_list->size();
59 const vector<Edge>* edge_list,
62 *out_size = edge_list->size();
70 const char* cost_type,
75 *out_float = g->
GetCost(parent, child, std::string(cost_type));
76 if (!std::isfinite(*out_float)) *out_float = -1.0f;
82 catch (std::logic_error)
98 const char* cost_type,
99 std::vector<float>** out_vector_ptr,
107 std::string cost_string(cost_type);
108 *out_vector_ptr =
new std::vector<float>();
110 *out_data_ptr = (**out_vector_ptr).data();
115 catch (std::logic_error) {
118 catch (std::exception & e){
140 const char* cost_type
142 Node parent_node, child_node;
147 std::string cost_name(cost_type);
149 parent_node =
Node(parent[0], parent[1], parent[2]);
150 child_node =
Node(child[0], child[1], child[2]);
152 catch(std::exception & E){
153 std::cerr <<
"Invalid parent or child node " << std::endl;
158 graph->
addEdge(parent_node, child_node, score, cost_name);
160 catch (std::out_of_range) {
163 catch (std::logic_error){
175 graph->
addEdge(parent_id, child_id, score, std::string(cost_type));
177 catch (std::out_of_range) {
180 catch (std::logic_error) {
192 float** out_data_ptr,
193 int ** out_inner_indices_ptr,
194 int ** out_outer_indices_ptr,
195 const char * cost_type
200 *out_num_rows = CSR.rows;
201 *out_num_cols = CSR.cols;
203 *out_data_ptr = CSR.data;
204 *out_inner_indices_ptr = CSR.inner_indices;
205 *out_outer_indices_ptr = CSR.outer_indices;
223 Node node(point[0], point[1], point[2]);
224 *out_id = graph->
getID(node);
236 std::string cost_name(cost_type);
239 if (cost_name.empty())
257 if (nodelist_to_destroy)
delete nodelist_to_destroy;
263 if (edgelist_to_destroy)
delete edgelist_to_destroy;
269 if (graph_to_destroy)
delete graph_to_destroy;
293 const char* attribute,
302 std::vector<int> v_ids(ids, ids + num_nodes);
305 std::vector<std::string> v_scores(scores, scores + num_nodes);
312 catch (std::logic_error) {
323 char** out_scores,
int* out_score_size) {
330 for (
int i = 0; i < v_attrs.size(); i++){
333 const string& v_str = v_attrs[i];
334 const char* cstr = v_str.c_str();
337 const int string_length = v_str.size() + 1;
339 out_scores[i] =
new char[string_length];
342 std::memcpy(out_scores[i], cstr, string_length);
347 * out_score_size = v_attrs.size();
356 if (scores_to_delete) {
360 for (
int i = 0; i < num_char_arrays; i++) {
361 char* score_string = scores_to_delete[i];
401 *out_size = g->
size();
407 const char* attr_key,
408 const char* cost_string,
413 graph_ptr->
AttrToCost(std::string(attr_key), std::string(cost_string), dir);
415 catch (std::out_of_range) {
Contains definitions for the Exceptions namespace.
Contains implementation for the HF::SpatialStructures::CostAlgorithms namespace.
Contains definitions for the Edge structure.
Contains definitions for the Graph class.
Contains definitions for the Node structure.
bool parse_string(const char *c)
Header file related to manipulating nodes, edges, and graphs via CInterface.
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.
@ ENERGY_EXPENDITURE
Cost created by CalculateAndStoreEnergyExpenditure.
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,...
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.
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 CreateGraph(const float *nodes, int num_nodes, Graph **out_graph)
Create a new empty graph.
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.
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,...
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...
C_INTERFACE GetSizeOfGraph(const Graph *g, int *out_size)
Get the number of nodes in a graph.
C_INTERFACE DestroyGraph(Graph *graph_to_destroy)
Delete a graph.
C_INTERFACE GetSizeOfEdgeVector(const vector< Edge > *edge_list, int *out_size)
Get the size of an edge vector.
C_INTERFACE ClearAttributeType(HF::SpatialStructures::Graph *g, const char *s)
Deletes the node attribute values of the type denoted by s, from graph *g.
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.
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 CalculateAndStoreEnergyExpenditure(HF::SpatialStructures::Graph *g)
Calculates energy expenditure for all subgraphs in *g and stores them in the graph at AlgorithmCostTi...
C_INTERFACE DestroyNodes(vector< Node > *nodelist_to_destroy)
Delete the vector of nodes at the given pointer.
C_INTERFACE GetEdgeCost(const Graph *g, int parent, int child, const char *cost_type, float *out_float)
Get the cost of traversing from parent to child
C_INTERFACE Compress(Graph *graph)
Compress the given graph into a CSR representation.
C_INTERFACE GetSizeOfNodeVector(const vector< Node > *node_list, int *out_size)
Get the size of a node vector.
C_INTERFACE DestroyEdges(vector< Edge > *edgelist_to_destroy)
Delete the vector of edges at the given pointer.
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.
C_INTERFACE DeleteScoreArray(char **scores_to_delete, int num_char_arrays)
Free the memory of every (char *) in scores_to_delete.
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.
C_INTERFACE CalculateAndStoreCrossSlope(HF::SpatialStructures::Graph *g)
Calculates cross slope for all subgraphs in *g.
A Subgraph consists of a parent Node m_parent and a container of Edge m_edges such that all Edge in m...
COST_AGGREGATE
Methods of aggregating the costs for edges for each node in the graph.
Direction
Node to use for calculating the cost of an edge when converting node attributes to edge costs.
Custom exceptions and error codes used interally by DHARTAPI.
@ OK
Operation was successful.
@ NOT_FOUND
The path given did not lead to any file.
@ GENERIC_ERROR
Not sure what happened here (If this gets thrown, either fix it or give it a status code!...
@ NOT_COMPRESSED
Graph wasn't compressed!
@ INVALID_PTR
One or more of the given pointers didn't lead to anything.
@ NO_COST
There is no cost with the given name in the given graph.
@ OUT_OF_RANGE
Tried to reference something not in the given container.
std::vector< IntEdge > CalculateCrossSlope(const Subgraph &sg)
EdgeSet CalculateEnergyExpenditure(const Subgraph &sg)
Thrown when a dependency is missing such as Embree.
A connection to a child node.
int nnz
Number of non-zeros contained by the CSR.
A Graph of nodes connected by edges that supports both integers and HF::SpatialStructures::Node.
void ClearNodeAttributes(std::string name)
Clears the attribute at name and all of its contents from the internal hashmap
int size() const
Determine how many nodes are in the graph.
float GetCost(int parent_id, int child_id, const std::string &cost_type="") const
get the cost from parent_id to child_id in the given cost_type.
void AddNodeAttributes(const std::vector< int > &id, const std::string &name, const std::vector< std::string > &scores)
Add an attribute to the node at id. If the node at id already has a score for the attribute at name,...
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< float > AggregateGraph(COST_AGGREGATE agg_type, bool directed=true, const std::string &cost_type="") const
Summarize the costs of every outgoing edge for every node in the graph.
void AddEdges(const EdgeSet &edges, const std::string &cost_name="")
Add multiple edges to the graph.
CSRPtrs GetCSRPointers(const std::string &cost_type="")
Obtain the size of and pointers to the 3 arrays that comprise this graph's CSR. graph if it isn't com...
void ClearCostArrays(const std::string &cost_name="")
Clear one or more cost arrays from the graph.
void Clear()
Clear all nodes and edges from the graph.
std::vector< Node > Nodes() const
Get a list of nodes from the graph sorted by ID.
void AttrToCost(const std::string &node_attribute, const std::string &cost_to_store_as, Direction consider=Direction::INCOMING)
Generate edge costs from a set of node attributes.
std::vector< std::string > GetNodeAttributes(std::string attribute) const
Get the score for the given attribute of every node in the graph. Nodes that do not have a score for ...
int getID(const Node &node) const
Retrieve the ID for node in this graph.
A point in space with an ID.