2012-06-11 06:32:24 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								function [data,truth] = VisualISAMGenerateData(options)
							 | 
						
					
						
							
								
									
										
										
										
											2012-09-08 13:28:25 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								% VisualISAMGenerateData creates data for viusalSLAM::iSAM examples
							 | 
						
					
						
							
								
									
										
										
										
											2012-06-10 11:31:09 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								% Authors: Duy Nguyen Ta and Frank Dellaert
							 | 
						
					
						
							
								
									
										
										
										
											2012-06-09 04:08:53 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2012-07-18 23:47:06 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import gtsam.*
							 | 
						
					
						
							
								
									
										
										
										
											2013-06-20 14:49:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								%% Generate simulated data
							 | 
						
					
						
							
								
									
										
										
										
											2012-06-10 12:25:05 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								if options.triangle % Create a triangle target, just 3 points on a plane
							 | 
						
					
						
							
								
									
										
										
										
											2012-06-11 06:32:24 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    nrPoints = 3;
							 | 
						
					
						
							
								
									
										
										
										
											2012-06-09 04:08:53 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    r = 10;
							 | 
						
					
						
							
								
									
										
										
										
											2012-06-11 06:32:24 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for j=1:nrPoints
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        theta = (j-1)*2*pi/nrPoints;
							 | 
						
					
						
							
								
									
										
										
										
											2012-07-18 23:47:06 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        truth.points{j} = Point3([r*cos(theta), r*sin(theta), 0]');
							 | 
						
					
						
							
								
									
										
										
										
											2012-06-09 04:08:53 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    end
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								else % 3D landmarks as vertices of a cube
							 | 
						
					
						
							
								
									
										
										
										
											2012-06-11 06:32:24 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    nrPoints = 8;
							 | 
						
					
						
							
								
									
										
										
										
											2012-07-18 23:47:06 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    truth.points = {Point3([10 10 10]'),...
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Point3([-10 10 10]'),...
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Point3([-10 -10 10]'),...
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Point3([10 -10 10]'),...
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Point3([10 10 -10]'),...
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Point3([-10 10 -10]'),...
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Point3([-10 -10 -10]'),...
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Point3([10 -10 -10]')};
							 | 
						
					
						
							
								
									
										
										
										
											2012-06-09 04:08:53 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								end
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								%% Create camera cameras on a circle around the triangle
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								height = 10; r = 40;
							 | 
						
					
						
							
								
									
										
										
										
											2012-07-18 23:47:06 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								truth.K = Cal3_S2(500,500,0,640/2,480/2);
							 | 
						
					
						
							
								
									
										
										
										
											2012-06-11 06:32:24 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								data.K = truth.K;
							 | 
						
					
						
							
								
									
										
										
										
											2012-06-10 12:25:05 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								for i=1:options.nrCameras
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    theta = (i-1)*2*pi/options.nrCameras;
							 | 
						
					
						
							
								
									
										
										
										
											2012-07-18 23:47:06 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    t = Point3([r*cos(theta), r*sin(theta), height]');
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-22 08:42:55 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    truth.cameras{i} = PinholeCameraCal3_S2.Lookat(t, Point3, Point3([0,0,1]'), truth.K);
							 | 
						
					
						
							
								
									
										
										
										
											2012-06-11 06:32:24 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    % Create measurements
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for j=1:nrPoints
							 | 
						
					
						
							
								
									
										
										
										
											2012-06-13 22:58:15 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        % All landmarks seen in every frame
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        data.Z{i}{j} = truth.cameras{i}.project(truth.points{j});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        data.J{i}{j} = j;
							 | 
						
					
						
							
								
									
										
										
										
											2012-06-11 06:32:24 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    end    
							 | 
						
					
						
							
								
									
										
										
										
											2012-06-10 12:25:05 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								end
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								%% show images if asked
							 | 
						
					
						
							
								
									
										
										
										
											2012-06-10 23:26:59 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								if options.showImages
							 | 
						
					
						
							
								
									
										
										
										
											2012-06-10 12:25:05 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    gui = gcf;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for i=1:options.nrCameras
							 | 
						
					
						
							
								
									
										
										
										
											2012-06-09 04:08:53 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        figure(2+i);clf;hold on
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        set(2+i,'NumberTitle','off','Name',sprintf('Camera %d',i));
							 | 
						
					
						
							
								
									
										
										
										
											2012-06-11 06:32:24 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        for j=1:nrPoints
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            zij = truth.cameras{i}.project(truth.points{j});
							 | 
						
					
						
							
								
									
										
										
										
											2012-06-09 04:08:53 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            plot(zij.x,zij.y,'*');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            axis([1 640 1 480]);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        end
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    end
							 | 
						
					
						
							
								
									
										
										
										
											2012-06-10 12:25:05 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    figure(gui);
							 | 
						
					
						
							
								
									
										
										
										
											2012-06-09 04:08:53 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								end
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2012-06-10 12:25:05 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								%% Calculate odometry between cameras
							 | 
						
					
						
							
								
									
										
										
										
											2012-06-11 06:32:24 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								odometry = truth.cameras{1}.pose.between(truth.cameras{2}.pose);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								for i=1:options.nrCameras-1
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    data.odometry{i}=odometry;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								end
							 |