RMF
reference_frames.py
1 ## \example reference_frames.py
2 # Show how to properly extract coordinates in the presence of rigid bodies.
3 import RMF
4 
5 # print out transformed coordinates
6 
7 
8 def print_coordinates(reference_frame, coords):
9  print(reference_frame.get_global_coordinates(coords))
10 
11 # walk through the hierarchy visiting each node and extracting coordinates
12 
13 
14 def visit(node, reference_frame, reference_frame_factory, particle_factory,
15  segment_factory, ball_factory):
16  if reference_frame_factory.get_is(node):
17  reference_frame = RMF.CoordinateTransformer(
18  reference_frame, reference_frame_factory.get(node))
19  print("reference frame is now", reference_frame)
20  elif segment_factory.get_is(node):
21  segment = segment_factory.get(node)
22  print("segment", node.get_name())
23  # silliness
24  coords = segment.get_coordinates()
25  for i in range(0, len(coords[0])):
26  print_coordinates(reference_frame, [coords[0][i],
27  coords[1][i],
28  coords[2][i]])
29  elif particle_factory.get_is(node):
30  particle = particle_factory.get(node)
31  print("particle", node.get_name(), print_coordinates(reference_frame, particle.get_coordinates()))
32  elif ball_factory.get_is(node):
33  particle = ball_factory.get(node)
34  print("ball", node.get_name(), print_coordinates(reference_frame, particle.get_coordinates()))
35  for c in node.get_children():
36  visit(c, reference_frame, reference_frame_factory, particle_factory,
37  segment_factory, ball_factory)
38 
39 fh = RMF.open_rmf_file_read_only(RMF.get_example_path("reference_frames.rmf3"))
40 
41 
42 visit(fh.get_root_node(), RMF.CoordinateTransformer(),
43  RMF.ReferenceFrameFactory(fh),
44  RMF.ParticleFactory(fh),
45  RMF.SegmentFactory(fh),
46  RMF.BallFactory(fh))
Transform coordinates into the global reference frame.
FileConstHandle open_rmf_file_read_only(std::string path)