Visual SLAM

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

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

Starting / Stopping the Tracker

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

SlamViewController.mm

- (void)resumeAR
{
    ...
    TrackerManager::getInstance()->startTracker(TRACKER_TYPE_SLAM);
}

- (void)pauseAR
{
    TrackerManager::getInstance()->stopTracker();
    ...
}

Starting / Stopping map generation, Saving map

  • To start a map generation, refer to the following code.
TrackerManager::getInstance()->findSurface();
  • To stop generating a map, refer to the following code.
TrackerManager::getInstance()->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 = maxstAR::BackgroundRenderer::getInstance();
    ...    backgroundRenderer->setRenderingOption(BackgroundRenderer::FEATURE_RENDERER|BackgroundRenderer::PROGRESS_RENDERER|BackgroundRenderer::SURFACE_MESH_RENDERER);
    ...
}

See ‘BackgroundRenderer.RenderingOption enum' for option settings.