本文整理汇总了Python中networkx.DiGraph.get_edge_data方法的典型用法代码示例。如果您正苦于以下问题:Python DiGraph.get_edge_data方法的具体用法?Python DiGraph.get_edge_data怎么用?Python DiGraph.get_edge_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx.DiGraph
的用法示例。
在下文中一共展示了DiGraph.get_edge_data方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import get_edge_data [as 别名]
class TransformTree:
'''
A feature complete if not particularly optimized implementation of a transform graph.
Few allowances are made for thread safety, caching, or enforcing graph structure.
'''
def __init__(self, base_frame='world'):
self._transforms = DiGraph()
self._parents = {}
self._paths = {}
self._is_changed = False
self.base_frame = base_frame
def update(self,
frame_to,
frame_from = None,
**kwargs):
'''
Update a transform in the tree.
Arguments
---------
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')
Additional kwargs (can be used in combinations)
---------
matrix: (4,4) array
quaternion: (4) quatenion
axis: (3) array
angle: float, radians
translation: (3) array
'''
if frame_from is None:
frame_from = self.base_frame
matrix = np.eye(4)
if 'matrix' in kwargs:
# a matrix takes precedence over other options
matrix = kwargs['matrix']
elif 'quaternion' in kwargs:
matrix = quaternion_matrix(kwargs['quaternion'])
elif ('axis' in kwargs) and ('angle' in kwargs):
matrix = rotation_matrix(kwargs['angle'],
kwargs['axis'])
else:
raise ValueError('Couldn\'t update transform!')
if 'translation' in kwargs:
# translation can be used in conjunction with any of the methods of
# specifying transforms. In the case a matrix and translation are passed,
# we add the translations together rather than picking one.
matrix[0:3,3] += kwargs['translation']
if self._transforms.has_edge(frame_from, frame_to):
self._transforms.edge[frame_from][frame_to]['matrix'] = matrix
self._transforms.edge[frame_from][frame_to]['time'] = time.time()
else:
# since the connectivity has changed, throw out previously computed
# paths through the transform graph so queries compute new shortest paths
# we could only throw out transforms that are connected to the new edge,
# but this is less bookeeping at the expensive of being slower.
self._paths = {}
self._transforms.add_edge(frame_from,
frame_to,
matrix = matrix,
time = time.time())
self._is_changed = True
def get(self,
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.
Arguments
---------
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')
Returns
---------
transform: (4,4) homogenous transformation matrix
'''
if frame_from is None:
frame_from = self.base_frame
transform = np.eye(4)
path, inverted = self._get_path(frame_from, frame_to)
for i in range(len(path) - 1):
matrix = self._transforms.get_edge_data(path[i],
path[i+1])['matrix']
transform = np.dot(transform, matrix)
if inverted:
#.........这里部分代码省略.........