| 
									
										
										
										
											2012-07-24 03:21:00 +08:00
										 |  |  | function plot2DTrajectory(values, linespec, marginals)
 | 
					
						
							| 
									
										
										
										
											2012-07-22 08:57:39 +08:00
										 |  |  | %PLOT2DTRAJECTORY Plots the Pose2's in a values, with optional covariances | 
					
						
							|  |  |  | %   Finds all the Pose2 objects in the given Values object and plots them | 
					
						
							|  |  |  | % in increasing key order, connecting consecutive poses with a line.  If | 
					
						
							|  |  |  | % a Marginals object is given, this function will also plot marginal | 
					
						
							|  |  |  | % covariance ellipses for each pose. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import gtsam.* | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-24 03:21:00 +08:00
										 |  |  | if ~exist('linespec', 'var') || isempty(linespec) | 
					
						
							|  |  |  |     linespec = 'k*-'; | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-22 08:57:39 +08:00
										 |  |  | haveMarginals = exist('marginals', 'var'); | 
					
						
							|  |  |  | keys = KeyVector(values.keys); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-24 03:21:00 +08:00
										 |  |  | holdstate = ishold; | 
					
						
							|  |  |  | hold on | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | % Plot poses and covariance matrices | 
					
						
							| 
									
										
										
										
											2012-07-22 08:57:39 +08:00
										 |  |  | lastIndex = []; | 
					
						
							|  |  |  | for i = 0:keys.size-1 | 
					
						
							|  |  |  |     key = keys.at(i); | 
					
						
							|  |  |  |     x = values.at(key); | 
					
						
							|  |  |  |     if isa(x, 'gtsam.Pose2') | 
					
						
							|  |  |  |         if ~isempty(lastIndex) | 
					
						
							|  |  |  |             % Draw line from last pose then covariance ellipse on top of | 
					
						
							|  |  |  |             % last pose. | 
					
						
							|  |  |  |             lastKey = keys.at(lastIndex); | 
					
						
							|  |  |  |             lastPose = values.at(lastKey); | 
					
						
							| 
									
										
										
										
											2012-07-24 03:21:00 +08:00
										 |  |  |             plot([ x.x; lastPose.x ], [ x.y; lastPose.y ], linespec); | 
					
						
							| 
									
										
										
										
											2012-07-22 08:57:39 +08:00
										 |  |  |             if haveMarginals | 
					
						
							|  |  |  |                 P = marginals.marginalCovariance(lastKey); | 
					
						
							| 
									
										
										
										
											2012-08-04 05:02:45 +08:00
										 |  |  |                 gtsam.plotPose2(lastPose, 'g', P); | 
					
						
							| 
									
										
										
										
											2013-03-26 00:01:49 +08:00
										 |  |  |             else | 
					
						
							|  |  |  |                 gtsam.plotPose2(lastPose, 'g', []); | 
					
						
							| 
									
										
										
										
											2012-07-22 08:57:39 +08:00
										 |  |  |             end | 
					
						
							| 
									
										
										
										
											2013-03-26 00:01:49 +08:00
										 |  |  |              | 
					
						
							| 
									
										
										
										
											2012-07-22 08:57:39 +08:00
										 |  |  |         end | 
					
						
							|  |  |  |         lastIndex = i; | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | % Draw final covariance ellipse | 
					
						
							| 
									
										
										
										
											2013-03-26 01:58:11 +08:00
										 |  |  | if ~isempty(lastIndex) | 
					
						
							| 
									
										
										
										
											2012-07-22 08:57:39 +08:00
										 |  |  |     lastKey = keys.at(lastIndex); | 
					
						
							|  |  |  |     lastPose = values.at(lastKey); | 
					
						
							| 
									
										
										
										
											2013-03-26 01:58:11 +08:00
										 |  |  |     if haveMarginals | 
					
						
							|  |  |  |         P = marginals.marginalCovariance(lastKey); | 
					
						
							|  |  |  |         gtsam.plotPose2(lastPose, 'g', P); | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         gtsam.plotPose2(lastPose, 'g', []); | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-07-22 08:57:39 +08:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-24 03:21:00 +08:00
										 |  |  | if ~holdstate | 
					
						
							|  |  |  |     hold off | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-22 08:57:39 +08:00
										 |  |  | end | 
					
						
							|  |  |  | 
 |