trimesh.scene.transforms module¶
Classes
|
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. |
|
Functions
|
Turn a set of keyword arguments into a transformation matrix. |
-
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.
Methods
add_edge
(u, v, *args, **kwargs)Add an edge between u and v.
add_edges_from
(*args, **kwargs)Add all the edges in ebunch.
add_path
(*args, **kwargs)Add a path.
disconnect_path
(path)get_edge_data_direction
(u, v)remove_edge
(*args, **kwargs)Remove the edge between u and v.
remove_edges_from
(*args, **kwargs)Remove all edges specified in ebunch.
shortest_path_undirected
(u, v)-
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 providing a dictionary with key/value pairs. See examples below.
- Parameters
v (u,) – Nodes can be, for example, strings or numbers. Nodes must be hashable (and not None) Python objects.
attr_dict (dictionary, optional (default= no attributes)) – Dictionary of edge attributes. Key/value pairs will update existing data associated with the edge.
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 as the edge weight a numerical value assigned to a keyword which by default is ‘weight’.
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)
-
add_edges_from
(*args, **kwargs)¶ Add all the edges in ebunch.
- Parameters
ebunch (container of edges) – Each edge given in the container will be added to the graph. The edges must be given as as 2-tuples (u,v) or 3-tuples (u,v,d) where d is a dictionary containing edge data.
attr_dict (dictionary, optional (default= no attributes)) – Dictionary of edge attributes. Key/value pairs will update existing data associated with each edge.
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 edges take precedence over attributes specified generally.
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)¶ Add a path.
- Parameters
nodes (iterable container) – A container of nodes. A path will be constructed from the nodes (in order) and added to the graph.
attr (keyword arguments, optional (default= no attributes)) – Attributes to add to every edge in path.
See also
add_star()
,add_cycle()
Examples
>>> G=nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_path([0,1,2,3]) >>> G.add_path([10,11,12],weight=7)
-
disconnect_path
(path)¶
-
get_edge_data_direction
(u, v)¶
-
remove_edge
(*args, **kwargs)¶ Remove the edge between u and v.
- Parameters
v (u,) – 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 >>> G.add_path([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.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_path([0,1,2,3]) >>> 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
Methods
clear
()copy
()Return a copy of the current TransformForest
from_edgelist
(edges[, strict])Load transform data from an edge list into the current scene graph.
get
(frame_to[, frame_from])Get the transform from one frame to another, assuming they are connected in the transform tree.
load
(edgelist)Load transform data from an edge list into the current scene graph.
md5
()show
()Plot the graph layout of the scene.
Export the current transforms as a list of
to_flattened
([base_frame])Export the current transform graph as a flattened
to_gltf
(scene)Export a transforms as the ‘nodes’ section of a GLTF dict.
to_svg
()update
(frame_to[, frame_from])Update a transform in the tree.
Attributes
A list of every node in the graph.
The nodes in the scene graph with geometry attached.
-
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.
-
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
-
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)¶ Export a transforms as the ‘nodes’ section of a GLTF dict. Flattens tree.
- 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’
-
-
trimesh.scene.transforms.
kwargs_to_matrix
(**kwargs)¶ Turn a set of keyword arguments into a transformation matrix.