MCPcopy Create free account
hub / github.com/danieljfarrell/pvtrace / Node

Class Node

pvtrace/scene/node.py:14–166  ·  view source on GitHub ↗

A node in a scene graph. Each node represents a new coordinate system with position and orientation relative to it's parent node.

Source from the content-addressed store, hash-verified

12
13
14class Node(NodeMixin, Transformable):
15 """ A node in a scene graph. Each node represents a new coordinate system
16 with position and orientation relative to it's parent node.
17 """
18
19 def __init__(
20 self, name=None, parent=None, location=None, geometry=None, light=None
21 ):
22 super(Node, self).__init__(location=location)
23 self.name = name
24 self.parent = parent
25 self.geometry = geometry
26 self.light = light
27
28 def __repr__(self):
29 return "Node({})".format(self.name)
30
31 def look_at(self, vector: tuple) -> None:
32 """ Align the node so that the Z axis is pointing along the vector.
33 """
34 raise NotImplementedError()
35
36 # Convert between coordinate systems
37
38 def transformation_to(self, node: Node) -> np.ndarray:
39 """ Transformation matrix from this node to another node.
40
41 Parameters
42 ----------
43 node : Node
44 The other node.
45
46 Returns
47 -------
48 numpy.ndarray
49 Homogeneous transformation matrix.
50 """
51 if self == node:
52 return np.identity(4)
53 upwards, common, downwards = Walker().walk(self, node)
54 transforms = tuple(map(lambda x: x.pose, upwards))
55 transforms = transforms + tuple(map(lambda x: np.linalg.inv(x.pose), downwards))
56 if len(transforms) == 1:
57 transform = transforms[0]
58 else:
59 transform = np.linalg.multi_dot(transforms[::-1])
60 return transform
61
62 def point_to_node(self, point: tuple, node: Node) -> tuple:
63 """ Convert local point into the the other node coordinate system.
64
65 The `node` must be somewhere in the hierarchy tree.
66
67 Parameters
68 ----------
69 point : tuple of float
70 Cartesian point `(x, y, z)` in the local coordinate system.
71 node : Node

Callers 15

_make_sceneMethod · 0.90
test_initMethod · 0.90
test_equalityMethod · 0.90
test_basic_sceneMethod · 0.90
test_intersectionMethod · 0.90
node_treeFunction · 0.90
test_initMethod · 0.90
test_nameMethod · 0.90

Calls

no outgoing calls

Tested by 15

test_initMethod · 0.72
test_equalityMethod · 0.72
test_basic_sceneMethod · 0.72
test_intersectionMethod · 0.72
node_treeFunction · 0.72
test_initMethod · 0.72
test_nameMethod · 0.72
test_parentMethod · 0.72