| 
									
										
										
										
											2012-07-24 03:21:00 +08:00
										 |  |  | function plot3DTrajectory(values,linespec,frames,scale,marginals)
 | 
					
						
							| 
									
										
										
										
											2012-09-08 13:28:25 +08:00
										 |  |  | % plot3DTrajectory plots a 3D trajectory | 
					
						
							|  |  |  | % plot3DTrajectory(values,linespec,frames,scale,marginals) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-24 03:21:00 +08:00
										 |  |  | if ~exist('scale','var') || isempty(scale), scale=1; end | 
					
						
							|  |  |  | if ~exist('frames','var'), scale=[]; end | 
					
						
							| 
									
										
										
										
											2012-06-04 13:53:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-24 03:21:00 +08:00
										 |  |  | import gtsam.* | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | haveMarginals = exist('marginals', 'var'); | 
					
						
							|  |  |  | keys = KeyVector(values.keys); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | holdstate = ishold; | 
					
						
							|  |  |  | hold on | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | % Plot poses and covariance matrices | 
					
						
							|  |  |  | lastIndex = []; | 
					
						
							|  |  |  | for i = 0:keys.size-1 | 
					
						
							|  |  |  |     key = keys.at(i); | 
					
						
							| 
									
										
										
										
											2014-11-14 07:51:11 +08:00
										 |  |  |     try | 
					
						
							|  |  |  |         x = values.atPose3(key); | 
					
						
							| 
									
										
										
										
											2012-07-24 03:21:00 +08:00
										 |  |  |         if ~isempty(lastIndex) | 
					
						
							|  |  |  |             % Draw line from last pose then covariance ellipse on top of | 
					
						
							|  |  |  |             % last pose. | 
					
						
							|  |  |  |             lastKey = keys.at(lastIndex); | 
					
						
							| 
									
										
										
										
											2014-11-14 07:51:11 +08:00
										 |  |  |             try | 
					
						
							|  |  |  |                 lastPose = values.atPose3(lastKey); | 
					
						
							|  |  |  |                 plot3([ x.x; lastPose.x ], [ x.y; lastPose.y ], [ x.z; lastPose.z ], linespec); | 
					
						
							|  |  |  |                 if haveMarginals | 
					
						
							|  |  |  |                     P = marginals.marginalCovariance(lastKey); | 
					
						
							|  |  |  |                 else | 
					
						
							|  |  |  |                     P = []; | 
					
						
							|  |  |  |                 end | 
					
						
							|  |  |  |                 gtsam.plotPose3(lastPose, P, scale); | 
					
						
							|  |  |  |             catch err | 
					
						
							|  |  |  |                 warning(['no Pose3 at ' lastKey]); | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  |             lastIndex = i; | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |     catch | 
					
						
							|  |  |  |         warning(['no Pose3 at ' key]); | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     % Draw final pose | 
					
						
							|  |  |  |     if ~isempty(lastIndex) | 
					
						
							|  |  |  |         lastKey = keys.at(lastIndex); | 
					
						
							|  |  |  |         try | 
					
						
							|  |  |  |             lastPose = values.atPose3(lastKey); | 
					
						
							| 
									
										
										
										
											2012-07-24 03:21:00 +08:00
										 |  |  |             if haveMarginals | 
					
						
							|  |  |  |                 P = marginals.marginalCovariance(lastKey); | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |                 P = []; | 
					
						
							|  |  |  |             end | 
					
						
							| 
									
										
										
										
											2012-08-04 05:02:45 +08:00
										 |  |  |             gtsam.plotPose3(lastPose, P, scale); | 
					
						
							| 
									
										
										
										
											2014-11-14 07:51:11 +08:00
										 |  |  |         catch | 
					
						
							|  |  |  |             warning(['no Pose3 at ' lastIndex]); | 
					
						
							| 
									
										
										
										
											2012-07-24 03:21:00 +08:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2012-06-04 13:53:51 +08:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2014-11-14 07:51:11 +08:00
										 |  |  |      | 
					
						
							|  |  |  |     if ~holdstate | 
					
						
							|  |  |  |         hold off | 
					
						
							| 
									
										
										
										
											2012-07-24 03:21:00 +08:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2014-11-14 07:51:11 +08:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2012-06-04 13:53:51 +08:00
										 |  |  | end |