| 
									
										
										
										
											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) | 
					
						
							| 
									
										
										
										
											2014-11-14 07:51:11 +08:00
										 |  |  |     linespec = 'k*-'; | 
					
						
							| 
									
										
										
										
											2012-07-24 03:21:00 +08:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-22 08:57:39 +08:00
										 |  |  | haveMarginals = exist('marginals', 'var'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-24 03:21:00 +08:00
										 |  |  | holdstate = ishold; | 
					
						
							|  |  |  | hold on | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-26 05:46:30 +08:00
										 |  |  | % Do something very efficient to draw trajectory | 
					
						
							|  |  |  | poses = utilities.extractPose2(values); | 
					
						
							|  |  |  | X = poses(:,1); | 
					
						
							|  |  |  | Y = poses(:,2); | 
					
						
							|  |  |  | theta = poses(:,3); | 
					
						
							|  |  |  | plot(X,Y,linespec); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | % Quiver can also be vectorized if no marginals asked | 
					
						
							|  |  |  | if ~haveMarginals | 
					
						
							| 
									
										
										
										
											2014-11-14 07:51:11 +08:00
										 |  |  |     C = cos(theta); | 
					
						
							|  |  |  |     S = sin(theta); | 
					
						
							|  |  |  |     quiver(X,Y,C,S,0.1,linespec); | 
					
						
							| 
									
										
										
										
											2014-05-26 05:46:30 +08:00
										 |  |  | else | 
					
						
							| 
									
										
										
										
											2014-11-14 07:51:11 +08:00
										 |  |  |     % plotPose2 does both quiver and covariance matrix | 
					
						
							|  |  |  |     keys = KeyVector(values.keys); | 
					
						
							|  |  |  |     for i = 0:keys.size-1 | 
					
						
							|  |  |  |         key = keys.at(i); | 
					
						
							|  |  |  |         try | 
					
						
							|  |  |  |             x = values.atPose2(key); | 
					
						
							|  |  |  |             P = marginals.marginalCovariance(key); | 
					
						
							|  |  |  |             gtsam.plotPose2(x,linespec(1), P); | 
					
						
							|  |  |  |         catch err | 
					
						
							|  |  |  |             % I guess it's not a Pose2 | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2013-03-26 01:58:11 +08:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-07-22 08:57:39 +08:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-24 03:21:00 +08:00
										 |  |  | if ~holdstate | 
					
						
							| 
									
										
										
										
											2014-11-14 07:51:11 +08:00
										 |  |  |     hold off | 
					
						
							| 
									
										
										
										
											2012-07-24 03:21:00 +08:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-22 08:57:39 +08:00
										 |  |  | end | 
					
						
							|  |  |  | 
 |