plot_mprim.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 # Copyright (c) 2018-2022, Martin Günther (DFKI GmbH) and contributors
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are met:
6 #
7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 #
10 # * Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
13 #
14 # * Neither the name of the copyright holder nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 # POSSIBILITY OF SUCH DAMAGE.
29 #
30 # Author: Martin Günther
31 
32 import matplotlib.pyplot as plt
33 import numpy as np
34 import sys
35 
36 
37 def get_value(strline, name):
38  if strline.find(name) < 0:
39  raise Exception("File format not matching the parser expectation", name)
40 
41  return strline.replace(name, "", 1)
42 
43 
44 def get_pose(line):
45  ss = line.split()
46  return np.array([float(ss[0]), float(ss[1]), float(ss[2])])
47 
48 
49 class MPrim:
50  def __init__(self, f):
51  self.primID = int(get_value(f.readline(), "primID:"))
52  self.startAngle = int(get_value(f.readline(), "startangle_c:"))
53  self.endPose = get_pose(get_value(f.readline(), "endpose_c:"))
54  self.cost = float(get_value(f.readline(), "additionalactioncostmult:"))
55  self.nrPoses = int(get_value(f.readline(), "intermediateposes:"))
56  poses = []
57  for _ in range(self.nrPoses):
58  poses.append(f.readline())
59  self.poses = np.loadtxt(poses, delimiter=" ")
60  self.cmap = plt.get_cmap("nipy_spectral")
61 
62  def plot(self, nr_angles):
63  plt.plot(self.poses[:, 0], self.poses[:, 1], c=self.cmap(float(self.startAngle) / nr_angles))
64 
65 
66 class MPrims:
67  def __init__(self, filename):
68  f = open(filename, "r")
69 
70  self.resolution = float(get_value(f.readline(), "resolution_m:"))
71  self.nrAngles = int(get_value(f.readline(), "numberofangles:"))
72  self.nrPrims = int(get_value(f.readline(), "totalnumberofprimitives:"))
73 
74  self.prims = []
75  for _ in range(self.nrPrims):
76  self.prims.append(MPrim(f))
77 
78  f.close()
79 
80  def plot(self):
81  fig = plt.figure()
82  ax = fig.add_subplot(111)
83  ax.set_xticks(np.arange(-1, 1, self.resolution))
84  ax.set_yticks(np.arange(-1, 1, self.resolution))
85  for prim in self.prims:
86  prim.plot(self.nrAngles)
87  plt.grid()
88  plt.show()
89 
90 
91 prims = MPrims(sys.argv[1])
92 prims.plot()
plot_mprim.MPrim.cmap
cmap
Definition: plot_mprim.py:60
plot_mprim.MPrims.resolution
resolution
Definition: plot_mprim.py:70
plot_mprim.MPrim.cost
cost
Definition: plot_mprim.py:54
plot_mprim.MPrim.endPose
endPose
Definition: plot_mprim.py:53
plot_mprim.MPrim.poses
poses
Definition: plot_mprim.py:59
plot_mprim.get_value
def get_value(strline, name)
Definition: plot_mprim.py:37
plot_mprim.MPrim.plot
def plot(self, nr_angles)
Definition: plot_mprim.py:62
plot_mprim.MPrim.__init__
def __init__(self, f)
Definition: plot_mprim.py:50
plot_mprim.MPrims.nrPrims
nrPrims
Definition: plot_mprim.py:72
plot_mprim.MPrims.prims
prims
Definition: plot_mprim.py:74
plot_mprim.MPrims
Definition: plot_mprim.py:66
plot_mprim.MPrim
Definition: plot_mprim.py:49
plot_mprim.MPrims.__init__
def __init__(self, filename)
Definition: plot_mprim.py:67
plot_mprim.MPrim.startAngle
startAngle
Definition: plot_mprim.py:52
plot_mprim.MPrims.plot
def plot(self)
Definition: plot_mprim.py:80
plot_mprim.get_pose
def get_pose(line)
Definition: plot_mprim.py:44
plot_mprim.MPrim.nrPoses
nrPoses
Definition: plot_mprim.py:55
plot_mprim.MPrims.nrAngles
nrAngles
Definition: plot_mprim.py:71
plot_mprim.MPrim.primID
primID
Definition: plot_mprim.py:51


mir_navigation
Author(s): Martin Günther
autogenerated on Tue May 13 2025 02:41:48