plot_mprim.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import math
00004 import matplotlib.pyplot as plt
00005 import numpy as np
00006 import sys
00007 
00008 
00009 def get_value(strline, name):
00010     if strline.find(name) < 0:
00011         raise Exception("File format not matching the parser expectation", name)
00012 
00013     return strline.replace(name, "", 1)
00014 
00015 
00016 def get_pose(line):
00017     ss = line.split()
00018     return np.array([float(ss[0]), float(ss[1]), float(ss[2])])
00019 
00020 
00021 class MPrim:
00022     def __init__(self, f):
00023         self.primID = int(get_value(f.readline(), "primID:"))
00024         self.startAngle = int(get_value(f.readline(), "startangle_c:"))
00025         self.endPose = get_pose(get_value(f.readline(), "endpose_c:"))
00026         self.cost = float(get_value(f.readline(), "additionalactioncostmult:"))
00027         self.nrPoses = int(get_value(f.readline(), "intermediateposes:"))
00028         poses = []
00029         for _ in xrange(self.nrPoses):
00030             poses.append(f.readline())
00031         self.poses = np.loadtxt(poses, delimiter=" ")
00032         self.cmap = plt.get_cmap("spectral")
00033 
00034     def plot(self, nr_angles):
00035         plt.plot(self.poses[:, 0], self.poses[:, 1], c=self.cmap(self.startAngle * 256 / nr_angles))
00036 
00037 
00038 class MPrims:
00039     def __init__(self, filename):
00040         f = open(filename, "r")
00041 
00042         self.resolution = float(get_value(f.readline(), "resolution_m:"))
00043         self.nrAngles = int(get_value(f.readline(), "numberofangles:"))
00044         self.nrPrims = int(get_value(f.readline(), "totalnumberofprimitives:"))
00045 
00046         self.prims = []
00047         for _ in xrange(self.nrPrims):
00048             self.prims.append(MPrim(f))
00049 
00050         f.close()
00051 
00052     def plot(self):
00053         fig = plt.figure()
00054         ax = fig.add_subplot(111)
00055         ax.set_xticks(np.arange(-1, 1, self.resolution))
00056         ax.set_yticks(np.arange(-1, 1, self.resolution))
00057         for prim in self.prims:
00058             prim.plot(self.nrAngles)
00059         plt.grid()
00060         plt.show()
00061 
00062 
00063 prims = MPrims(sys.argv[1])
00064 prims.plot()


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