|
Packit |
ea1746 |
#!/usr/bin/python
|
|
Packit |
ea1746 |
#
|
|
Packit |
ea1746 |
# Plots the results from the 3D pose graph optimization. It will draw a line
|
|
Packit |
ea1746 |
# between consecutive vertices. The commandline expects two optional filenames:
|
|
Packit |
ea1746 |
#
|
|
Packit |
ea1746 |
# ./plot_results.py --initial_poses filename --optimized_poses filename
|
|
Packit |
ea1746 |
#
|
|
Packit |
ea1746 |
# The files have the following format:
|
|
Packit |
ea1746 |
# ID x y z q_x q_y q_z q_w
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
from mpl_toolkits.mplot3d import Axes3D
|
|
Packit |
ea1746 |
import matplotlib.pyplot as plot
|
|
Packit |
ea1746 |
import numpy
|
|
Packit |
ea1746 |
import sys
|
|
Packit |
ea1746 |
from optparse import OptionParser
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
def set_axes_equal(axes):
|
|
Packit |
ea1746 |
''' Sets the axes of a 3D plot to have equal scale. '''
|
|
Packit |
ea1746 |
x_limits = axes.get_xlim3d()
|
|
Packit |
ea1746 |
y_limits = axes.get_ylim3d()
|
|
Packit |
ea1746 |
z_limits = axes.get_zlim3d()
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
x_range = abs(x_limits[1] - x_limits[0])
|
|
Packit |
ea1746 |
x_middle = numpy.mean(x_limits)
|
|
Packit |
ea1746 |
y_range = abs(y_limits[1] - y_limits[0])
|
|
Packit |
ea1746 |
y_middle = numpy.mean(y_limits)
|
|
Packit |
ea1746 |
z_range = abs(z_limits[1] - z_limits[0])
|
|
Packit |
ea1746 |
z_middle = numpy.mean(z_limits)
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
length = 0.5 * max([x_range, y_range, z_range])
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
axes.set_xlim3d([x_middle - length, x_middle + length])
|
|
Packit |
ea1746 |
axes.set_ylim3d([y_middle - length, y_middle + length])
|
|
Packit |
ea1746 |
axes.set_zlim3d([z_middle - length, z_middle + length])
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
parser = OptionParser()
|
|
Packit |
ea1746 |
parser.add_option("--initial_poses", dest="initial_poses",
|
|
Packit |
ea1746 |
default="", help="The filename that contains the original poses.")
|
|
Packit |
ea1746 |
parser.add_option("--optimized_poses", dest="optimized_poses",
|
|
Packit |
ea1746 |
default="", help="The filename that contains the optimized poses.")
|
|
Packit |
ea1746 |
parser.add_option("-e", "--axes_equal", action="store_true", dest="axes_equal",
|
|
Packit |
ea1746 |
default="", help="Make the plot axes equal.")
|
|
Packit |
ea1746 |
(options, args) = parser.parse_args()
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
# Read the original and optimized poses files.
|
|
Packit |
ea1746 |
poses_original = None
|
|
Packit |
ea1746 |
if options.initial_poses != '':
|
|
Packit |
ea1746 |
poses_original = numpy.genfromtxt(options.initial_poses,
|
|
Packit |
ea1746 |
usecols = (1, 2, 3))
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
poses_optimized = None
|
|
Packit |
ea1746 |
if options.optimized_poses != '':
|
|
Packit |
ea1746 |
poses_optimized = numpy.genfromtxt(options.optimized_poses,
|
|
Packit |
ea1746 |
usecols = (1, 2, 3))
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
# Plots the results for the specified poses.
|
|
Packit |
ea1746 |
figure = plot.figure()
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
if poses_original is not None:
|
|
Packit |
ea1746 |
axes = plot.subplot(1, 2, 1, projection='3d')
|
|
Packit |
ea1746 |
plot.plot(poses_original[:, 0], poses_original[:, 1], poses_original[:, 2],
|
|
Packit |
ea1746 |
'-', alpha=0.5, color="green")
|
|
Packit |
ea1746 |
plot.title('Original')
|
|
Packit |
ea1746 |
if options.axes_equal:
|
|
Packit |
ea1746 |
axes.set_aspect('equal')
|
|
Packit |
ea1746 |
set_axes_equal(axes)
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
if poses_optimized is not None:
|
|
Packit |
ea1746 |
axes = plot.subplot(1, 2, 2, projection='3d')
|
|
Packit |
ea1746 |
plot.plot(poses_optimized[:, 0], poses_optimized[:, 1], poses_optimized[:, 2],
|
|
Packit |
ea1746 |
'-', alpha=0.5, color="blue")
|
|
Packit |
ea1746 |
plot.title('Optimized')
|
|
Packit |
ea1746 |
if options.axes_equal:
|
|
Packit |
ea1746 |
axes.set_aspect('equal')
|
|
Packit |
ea1746 |
set_axes_equal(plot.gca())
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
# Show the plot and wait for the user to close.
|
|
Packit |
ea1746 |
plot.show()
|