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.swift

var cameraDevice:MasCameraDevice = MasCameraDevice()
var sensorDevice:MasSensorDevice = MasSensorDevice()
var backgroundRenderer:MasBackgroundRenderer = MasBackgroundRenderer()
var trackingManager:MasTrackerManager = MasTrackerManager()

Starting / Stopping the Tracker

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

>SlamViewController.swift

@objc func resumeAR()
{
    ...
    trackingManager.start(.TRACKER_TYPE_SLAM)
}

@objc func 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.swift

func getFilePath() -> String {
    let documentPaths:[String] = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
    let documentPath:String = documentPaths[0]
    let contentsPath:String = "\(documentPath)/3DMap"
    
    let fileManager:FileManager = FileManager.default
    
    var isDir:ObjCBool = false
    let exists = fileManager.fileExists(atPath: contentsPath, isDirectory: &isDir)
    
    if exists == false {
        try! fileManager.createDirectory(atPath: contentsPath, withIntermediateDirectories: true, attributes: [:])
    }
    
    let filePath:String = "\(contentsPath)/\(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.swift

func startEngin() {
    ...
    let renderingOptions:MasRenderingOption = [MasRenderingOption.FEATURE_RENDERER,MasRenderingOption.PROGRESS_RENDERER, MasRenderingOption.SURFACE_MESH_RENDERER]
        backgroundRenderer.setRenderingOption(renderingOptions)
    ...
}

See ‘MasBackgroundRenderer.MasRenderingOption enum' for option settings.