dhart.spatialstructures.Graph¶
- class dhart.spatialstructures.Graph(graph_ptr: c_void_p | None = None)¶
A graph representing connections between points in space.
Every Node in the graph contains a set of X,Y,Z coordinates which can be used to represent a specific point in space. This graph internally is stored as a Sparse Matrix for space efficency. Nodes are stored in a hashmap containing X,Y, and Z coordinates, allowing for quick indexing of specific nodes by location alone. Access to this graph’s internal CSR is available through Graph.CompressToCSR().
- Cost Types:
This Graph is capable of holding multiple cost types for any of it’s edges. Each cost type has a distinct key as it’s name, such as “CrossSlope” or “EnergyExpenditure”. Upon creation, the graph is assigned a default cost type, Distance which can be accessed explicitly by the key “Distance” or leaving the cost_type field blank. Alternate costs have corresponding edges in the default cost set, but different costs to traverse from the parent to the child node.
- Node Attributes:
The graph is able to store an arbitrary amount of information about the nodes it contains as strings. Similar to alternate cost types, node attributes are each have a distinct key as their name, but instead of conatining information about edges in the graph, node attributes contain information about nodes. Unlike the cost algorithms in edgecosts, right now there is no functionality within DHARTAPI that populates the node attributes of the graph with any kind of metric, however the methods to add and clear node attributes are made available so you are free to add your own node attributes.
- csr¶
csr pointing to the underlying graph in C++.
Methods
AddEdgeToGraph
(parent, child, cost[, cost_type])Add a new edge to the graph from parent to child with the given cost
AggregateEdgeCosts
(ct, directed[, cost_type])Get an aggregated score for every node in the graph based on
Clear
([cost_type])Clear all edges/nodes from the graph or a specific cost type
CompressToCSR
([cost_type])Compress the graph if needed then return a reference as a CSR matrix
ConvertToLists
([just_nodes])Convert the CSR to a list of nodes and tuples, useful for serialization
GetEdgeCost
(parent, child[, cost_type])Get the cost from parent to child for a specific cost type
GetNodeID
(node)Get the id of a node in the graph
NumNodes
()Get the number of nodes in the graph.
add_node_attributes
(attribute, ids, scores)Add attributes to one or more nodes
attrs_to_costs
(attribute_string, ...)Generate a cost set based on a set of node parameters
clear_node_attribute
(attribute)Clear a node attribute and all of its scores from the graph
getNodes
()Get a list of nodes from the graph as a nodelist
get_closest_nodes
(p_desired[, x, y, z])Get the closet nodes to the input set of points
Get the closest point in the graph to the input set of points
get_node_attributes
(attribute)Get scores of every node for a specific attribute
get_node_points
([x, y, z])Get the nodes of the graph as xyz values in a numpy array by defining the array name view to be used as the x,y,z values.
Attributes
graph_ptr