Visual SLAM

The Visual SLAM(Simultaneous Localization and Mapping) creates a map by scanning 3D space.

Create Instants
Starting / Stopping the Tracker
Starting / Stopping map generation, Saving map
Set Rendering Options

Create Instants

>SlamViewController.mm

- (void)viewDidLoad
{
    ...
    trackingManager = [[MasTrackerManager alloc] init];
    cameraDevice = [[MasCameraDevice alloc] init];
    sensorDevice = [[MasSensorDevice alloc] init];
    [MasMaxstAR onSurfaceCreated];
}

Starting / Stopping the Tracker

To start / stop Tracker, refer to the following code.

>SlamViewController.mm

- (void)resumeAR
{
    ...
    [trackingManager startTracker:TRACKER_TYPE_SLAM];
}

- (void)pauseAR
{
    [trackingManager stopTracker];
    ...
}

Starting / Stopping map generation, Saving map

  • To start a map generation, refer to the following code.
[trackingManager findSurface];
  • To stop generating a map, refer to the following code.
[trackingManager quitFindingSurface];
  • Saving map is only possible while tracking. When saving the generated map data to a file, refer to the following code for the file storage location.

>SlamViewController.mm

- (NSString *) getFilePath
{
 NSArray *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
 NSString *contentsPath = [[NSString alloc] initWithFormat:@"%@/3DMap", [documentPath objectAtIndex:0]];
 
 NSFileManager *filemanager = [NSFileManager defaultManager];
 BOOL isDir;
 BOOL exists = [filemanager fileExistsAtPath:contentsPath isDirectory:&isDir];

 if(exists == NO)
 {
  [filemanager createDirectoryAtPath:contentsPath withIntermediateDirectories:YES attributes:nil error:NULL];
 }
 
 NSString *filePath = [NSString stringWithFormat:@"%@/%@", contentsPath,[self GetDateForFileName]];
 return filePath;
}

Set Rendering Options

Feature points, SLAM initialization progress, Axis, and Surface mesh information can be displayed by option setting. Refer to the following code.

>SlamViewController.mm

- (void)viewDidLoad {
    ...
    backgroundRenderer = [[MasBackgroundRenderer alloc] init];
    [backgroundRenderer setRenderingOption:FEATURE_RENDERER|PROGRESS_RENDERER|SURFACE_MESH_RENDERER];
    ...
}

See ‘MasBackgroundRenderer.MasRenderingOption enum' for option settings.