| 
									
										
										
										
											2012-06-04 02:20:48 +08:00
										 |  |  | function [graph,initial] = load2D(filename,model)
 | 
					
						
							|  |  |  | % load2D: read TORO pose graph | 
					
						
							|  |  |  | % cannot read noise model from file yet, uses specified model | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-24 03:21:00 +08:00
										 |  |  | import gtsam.* | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-04 02:20:48 +08:00
										 |  |  | fid = fopen(filename); | 
					
						
							|  |  |  | if fid < 0 | 
					
						
							|  |  |  |     error(['load2D: Cannot open file ' filename]); | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | % scan all lines into a cell array | 
					
						
							|  |  |  | columns=textscan(fid,'%s','delimiter','\n'); | 
					
						
							|  |  |  | fclose(fid); | 
					
						
							|  |  |  | lines=columns{1}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | % loop over lines and add vertices | 
					
						
							| 
									
										
										
										
											2012-07-24 03:21:00 +08:00
										 |  |  | graph = NonlinearFactorGraph; | 
					
						
							|  |  |  | initial = Values; | 
					
						
							| 
									
										
										
										
											2012-06-04 02:20:48 +08:00
										 |  |  | n=size(lines,1); | 
					
						
							|  |  |  | for i=1:n | 
					
						
							|  |  |  |     line_i=lines{i}; | 
					
						
							|  |  |  |     if strcmp('VERTEX2',line_i(1:7)) | 
					
						
							|  |  |  |         v = textscan(line_i,'%s %d %f %f %f',1); | 
					
						
							| 
									
										
										
										
											2012-07-24 03:21:00 +08:00
										 |  |  |         initial.insert(v{2}, Pose2(v{3}, v{4}, v{5})); | 
					
						
							| 
									
										
										
										
											2012-06-04 02:20:48 +08:00
										 |  |  |     elseif strcmp('EDGE2',line_i(1:5)) | 
					
						
							|  |  |  |         e = textscan(line_i,'%s %d %d %f %f %f',1); | 
					
						
							| 
									
										
										
										
											2012-07-24 03:21:00 +08:00
										 |  |  |         graph.add(BetweenFactorPose2(e{2}, e{3}, Pose2(e{4}, e{5}, e{6}), model)); | 
					
						
							| 
									
										
										
										
											2012-06-04 02:20:48 +08:00
										 |  |  |     end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 |