plot_mprim.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import math
4 import matplotlib.pyplot as plt
5 import numpy as np
6 import sys
7 
8 
9 def get_value(strline, name):
10  if strline.find(name) < 0:
11  raise Exception("File format not matching the parser expectation", name)
12 
13  return strline.replace(name, "", 1)
14 
15 
16 def get_pose(line):
17  ss = line.split()
18  return np.array([float(ss[0]), float(ss[1]), float(ss[2])])
19 
20 
21 class MPrim:
22  def __init__(self, f):
23  self.primID = int(get_value(f.readline(), "primID:"))
24  self.startAngle = int(get_value(f.readline(), "startangle_c:"))
25  self.endPose = get_pose(get_value(f.readline(), "endpose_c:"))
26  self.cost = float(get_value(f.readline(), "additionalactioncostmult:"))
27  self.nrPoses = int(get_value(f.readline(), "intermediateposes:"))
28  poses = []
29  for _ in xrange(self.nrPoses):
30  poses.append(f.readline())
31  self.poses = np.loadtxt(poses, delimiter=" ")
32  self.cmap = plt.get_cmap("spectral")
33 
34  def plot(self, nr_angles):
35  plt.plot(self.poses[:, 0], self.poses[:, 1], c=self.cmap(self.startAngle * 256 / nr_angles))
36 
37 
38 class MPrims:
39  def __init__(self, filename):
40  f = open(filename, "r")
41 
42  self.resolution = float(get_value(f.readline(), "resolution_m:"))
43  self.nrAngles = int(get_value(f.readline(), "numberofangles:"))
44  self.nrPrims = int(get_value(f.readline(), "totalnumberofprimitives:"))
45 
46  self.prims = []
47  for _ in xrange(self.nrPrims):
48  self.prims.append(MPrim(f))
49 
50  f.close()
51 
52  def plot(self):
53  fig = plt.figure()
54  ax = fig.add_subplot(111)
55  ax.set_xticks(np.arange(-1, 1, self.resolution))
56  ax.set_yticks(np.arange(-1, 1, self.resolution))
57  for prim in self.prims:
58  prim.plot(self.nrAngles)
59  plt.grid()
60  plt.show()
61 
62 
63 prims = MPrims(sys.argv[1])
64 prims.plot()
def get_pose(line)
Definition: plot_mprim.py:16
def __init__(self, f)
Definition: plot_mprim.py:22
def get_value(strline, name)
Definition: plot_mprim.py:9
def __init__(self, filename)
Definition: plot_mprim.py:39
def plot(self)
Definition: plot_mprim.py:52
def plot(self, nr_angles)
Definition: plot_mprim.py:34


mir_navigation
Author(s): Martin Günther
autogenerated on Wed May 8 2019 02:39:00