trimesh.scene.transforms¶
-
class
trimesh.scene.transforms.
EnforcedForest
(*args, **kwargs)¶ Bases:
networkx.classes.digraph.DiGraph
A subclass of networkx.DiGraph that will raise an error if an edge is added which would make the DiGraph not a forest or tree.
-
add_edge
(u, v, *args, **kwargs)¶ Add an edge between u and v.
The nodes u and v will be automatically added if they are not already in the graph.
Edge attributes can be specified with keywords or by directly accessing the edge’s attribute dictionary. See examples below.
- Parameters
u (nodes) – Nodes can be, for example, strings or numbers. Nodes must be hashable (and not None) Python objects.
v (nodes) – Nodes can be, for example, strings or numbers. Nodes must be hashable (and not None) Python objects.
attr (keyword arguments, optional) – Edge data (or labels or objects) can be assigned using keyword arguments.
See also
add_edges_from
add a collection of edges
Notes
Adding an edge that already exists updates the edge data.
Many NetworkX algorithms designed for weighted graphs use an edge attribute (by default weight) to hold a numerical value.
Examples
The following all add the edge e=(1, 2) to graph G:
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> e = (1, 2) >>> G.add_edge(1, 2) # explicit two-node form >>> G.add_edge(*e) # single edge as tuple of two nodes >>> G.add_edges_from([(1, 2)]) # add edges from iterable container
Associate data to edges using keywords:
>>> G.add_edge(1, 2, weight=3) >>> G.add_edge(1, 3, weight=7, capacity=15, length=342.7)
For non-string attribute keys, use subscript notation.
>>> G.add_edge(1, 2) >>> G[1][2].update({0: 5}) >>> G.edges[1, 2].update({0: 5})
-
add_edges_from
(*args, **kwargs)¶ Add all the edges in ebunch_to_add.
- Parameters
ebunch_to_add (container of edges) – Each edge given in the container will be added to the graph. The edges must be given as 2-tuples (u, v) or 3-tuples (u, v, d) where d is a dictionary containing edge data.
attr (keyword arguments, optional) – Edge data (or labels or objects) can be assigned using keyword arguments.
See also
add_edge
add a single edge
add_weighted_edges_from
convenient way to add weighted edges
Notes
Adding the same edge twice has no effect but any edge data will be updated when each duplicate edge is added.
Edge attributes specified in an ebunch take precedence over attributes specified via keyword arguments.
Examples
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_edges_from([(0, 1), (1, 2)]) # using a list of edge tuples >>> e = zip(range(0, 3), range(1, 4)) >>> G.add_edges_from(e) # Add the path graph 0-1-2-3
Associate data to edges
>>> G.add_edges_from([(1, 2), (2, 3)], weight=3) >>> G.add_edges_from([(3, 4), (1, 4)], label="WN2898")
-
add_path
(*args, **kwargs)¶
-
disconnect_path
(path)¶
-
get_edge_data_direction
(u, v)¶
-
remove_edge
(*args, **kwargs)¶ Remove the edge between u and v.
- Parameters
u (nodes) – Remove the edge between nodes u and v.
v (nodes) – Remove the edge between nodes u and v.
- Raises
NetworkXError – If there is not an edge between u and v.
See also
remove_edges_from
remove a collection of edges
Examples
>>> G = nx.Graph() # or DiGraph, etc >>> nx.add_path(G, [0, 1, 2, 3]) >>> G.remove_edge(0, 1) >>> e = (1, 2) >>> G.remove_edge(*e) # unpacks e from an edge tuple >>> e = (2, 3, {"weight": 7}) # an edge with attribute data >>> G.remove_edge(*e[:2]) # select first part of edge tuple
-
remove_edges_from
(*args, **kwargs)¶ Remove all edges specified in ebunch.
- Parameters
ebunch (list or container of edge tuples) –
Each edge given in the list or container will be removed from the graph. The edges can be:
2-tuples (u, v) edge between u and v.
3-tuples (u, v, k) where k is ignored.
See also
remove_edge
remove a single edge
Notes
Will fail silently if an edge in ebunch is not in the graph.
Examples
>>> G = nx.path_graph(4) # or DiGraph, MultiGraph, MultiDiGraph, etc >>> ebunch = [(1, 2), (2, 3)] >>> G.remove_edges_from(ebunch)
-
shortest_path_undirected
(u, v)¶
-
-
class
trimesh.scene.transforms.
TransformForest
(base_frame='world')¶ Bases:
object
-
clear
()¶
-
copy
()¶ Return a copy of the current TransformForest
- Returns
copied
- Return type
-
from_edgelist
(edges, strict=True)¶ Load transform data from an edge list into the current scene graph.
- Parameters
edgelist ((n,) tuples) – (node_a, node_b, {key: value})
strict (bool) – If true, raise a ValueError when a malformed edge is passed in a tuple.
-
property
geometry_nodes
¶ Which nodes have this geometry?
- Returns
geometry_nodes – Geometry name : (n,) node names
- Return type
dict
-
get
(frame_to, frame_from=None)¶ Get the transform from one frame to another, assuming they are connected in the transform tree.
If the frames are not connected a NetworkXNoPath error will be raised.
- Parameters
frame_to (hashable) – Node name, usually a string (eg ‘mesh_0’)
frame_from (hashable) – Node name, usually a string (eg ‘world’). If None it will be set to self.base_frame
- Returns
transform – Homogeneous transformation matrix
- Return type
(4, 4) float
-
load
(edgelist)¶ Load transform data from an edge list into the current scene graph.
- Parameters
edgelist ((n,) tuples) – (node_a, node_b, {key: value})
-
md5
()¶
-
property
nodes
¶ A list of every node in the graph.
- Returns
nodes – All node names
- Return type
(n,) array
-
property
nodes_geometry
¶ The nodes in the scene graph with geometry attached.
- Returns
nodes_geometry – Node names which have geometry associated
- Return type
(m,) array
-
remove_geometries
(geometries)¶ Remove the reference for specified geometries from nodes without deleting the node.
- Parameters
geometries (list or str) – Name of scene.geometry to dereference.
-
show
()¶ Plot the graph layout of the scene.
-
to_edgelist
()¶ Export the current transforms as a list of edge tuples, with each tuple having the format: (node_a, node_b, {metadata})
- Returns
edgelist – Of edge tuples
- Return type
(n,) list
-
to_flattened
(base_frame=None)¶ Export the current transform graph as a flattened
-
to_gltf
(scene, mesh_index=None)¶ Export a transforms as the ‘nodes’ section of a GLTF dict. Flattens tree.
- Parameters
scene (trimesh.Scene) – Scene with geoemtry
mesh_index (dict or None) – Mapping { key in scene.geometry : int }
- Returns
gltf – with ‘nodes’ referencing a list of dicts
- Return type
dict
-
to_svg
()¶
-
update
(frame_to, frame_from=None, **kwargs)¶ Update a transform in the tree.
- Parameters
frame_from (hashable object) – Usually a string (eg ‘world’). If left as None it will be set to self.base_frame
frame_to (hashable object) – Usually a string (eg ‘mesh_0’)
matrix ((4,4) float) – Homogeneous transformation matrix
quaternion ((4,) float) – Quaternion ordered [w, x, y, z]
axis ((3,) float) – Axis of rotation
angle (float) – Angle of rotation, in radians
translation ((3,) float) – Distance to translate
geometry (hashable) – Geometry object name, e.g. ‘mesh_0’
extras (dictionary) – Optional metadata attached to the new frame (expors to glTF node ‘extras’).
-
-
trimesh.scene.transforms.
kwargs_to_matrix
(**kwargs)¶ Turn a set of keyword arguments into a transformation matrix.