Space Tracker Android Tutorial

1. Overview
2. Android Development
2.1 Start / Stop Tracker
2.2 Use Tracking Information
2.3 Set Map
2.4 Add / Replace Map
3. References
3.1 API Reference
3.2 Sample


1. Overview

Start developing MAXST ARSDK Space Tracker on Android Platform. Refer to Space Tracker Introduction for detailed information.

Generate 3D Mapfile of the target for Space Tracker via MAXSCAN. The 3D space. Space Tracker loads the map file and renders 3D object on it.

After target recognition and initial poses are acquired through the MAXST SDK, use AR Core for tracking.

Prerequisites
Space Tracker Introduction
MAXSCAN

2. Android Development

Start developing on Android Studio using Java. Please refer to Requirements & Supports to find out which devices are supported.

ARSDK has to properly integrate on Android Activity. Refer to Life Cycle documents for detail.


2.1 Start / Stop Tracker

TrackerManager.getInstance().IsFusionSupported()
This function checks whether or not your device supports Fusion.
Return value is bool type. If true, it supports the device in use. If it is false, it does not support the device.

TrackerManager.getInstance().GetFusionTrackingState ()
Pass the tracking status of the current Fusion.
The return value is an int of -1, which means that tracking isn't working properly, and 1 means that it's working properly.

To start / stop the tracker after loading the map, refer to the following code.

SpaceTrackerActivity.java

@Override
protected void onResume() {
    ...    TrackerManager.getInstance().startTracker(TrackerManager.TRACKER_TYPE_SPACE);
    TrackerManager.getInstance().addTrackerData("SpaceTarget/space_map.mmap", true);
    TrackerManager.getInstance().loadTrackerData();
    ...
}

@Override
protected void onPause() {
    ...
    TrackerManager.getInstance().stopTracker();
    ...
}

When calling addTrackerData(), you must pass the path to the mmap in the parameters.
Space_name is the filename of the mmap.

SpaceTrackerRenderer.java

@Override
Public void onSurfaceCreated(…){
   …
   …
   CameraDevice.getInstance().setARCoreTexture();
}

The setARCoreTexture () function call must be made from glThread. setARCoreTexture () must be executed. If the function is not executed, no screen is displayed.


2.2 Use Tracking Information

You can use 3D mesh processing software (such as MeshLab) to load a 3D spatial model as a 3D file(.obj) to get the desired vertices.

get_position

Using the found vertices and the setTranslate() function, you can augment the object to the desired location.

To use the tracking information, look at the following code.

SpaceTrackerRenderer.java

@Override
public void onDrawFrame(GL10 gl) {
    ...
    TrackingState state = TrackerManager.GetInstance().UpdateTrackingState();
    TrackingResult trackingResult = state.GetTrackingResult(); 
    if (trackingResult.getCount() > 0) {
        Trackable trackable = trackingResult.getTrackable(0);
        texturedCube.setTransform(trackable.getPoseMatrix());
        texturedCube.setTranslate(0, 0, -0.1f);
        texturedCube.setScale(0.4f, 0.4f, 0.2f);
        texturedCube.setProjectionMatrix(projectionMatrix);
        texturedCube.draw();
    }
}

2.3 Set Map

By callingaddTrackerData() to register the map file and callingloadTrackerData(), the space can be tracked. To set a map, refer to the following code.

SpaceTrackerActivity.Java

@Override
protected void onCreate(Bundle savedInstanceState) {
    ...
    TrackerManager.getInstance().addTrackerData(mapFileName, false);
    TrackerManager.getInstance().loadTrackerData();
}

*Note* - Map Compatibility Starting with MAXSCAN 1.1.0 or later, the file format for mmaps has changed. mmaps created in MAXSCAN 1.1.0 or later are supported by AR SDK 6.1.x or later.
In AR SDK 6.1, you can load both maps generated by Maxscan 1.0 and maps generated by Maxscan 1.1 and later. To recognize multiple targets, you must use maps generated by MAXSCAN 1.1.0 or later.
2.3.1 Set Package

If you are using multiple space maps, packaging them in a mmpkg file will greatly improve map loading speed and recognition speed.
Create a mmpkg with MapPackager, call addTrackerData() to register the package file, and call loadTrackerData() to track the target object.

onCreate() {
    ...    
    TrackerManager.getInstance().addTrackerData("SpaceTarget/package.mmpkg", true);
    TrackerManager.getInstance().loadTrackerData();
    ...
}

※ Space Package(mmpkg) is available from AR SDK 6.1.0.
※ Only mmaps created in MAXSCAN 1.1.0 or later can be packaged as mmpkg.
※ Only one mmpkg can be added to Object Tracker.

2.4 Add / Replace Map

  1. Create a map file refer to MAXSCAN.

  2. Copy the received map file to the desired path. The way to load map file in the assets folder and the external storage, is different.

  • When copying to the assets folder, set the second parameter to true to indicate that it is a relative path and a file in the assets folder.

    TrackerManager.getInstance().addTrackerData("space_map.mmap",true);
    
  • If copying to external storage, enter the full path and set the second parameter to false.

    TrackerManager.getInstance().addTrackerData(mapFile.getAbsolutePath(), false);
    
  1. You must call loadTrackerData() after calling addTrackerData().
  2. If you have an existing map file, call addTrackerData () and loadTrackerData () after calling TrackerManager.getInstance (). RemoveTrackerData ("").

3. References

These are additional references to develo Space Tracker.


3.1 API Reference

Following documents explain classes and functions used to run Space Tracker.

MaxstAR Class

TrackerManager Class

CameraDevice Class


3.2 Sample

For information regarding sample build and run of Space Tracker, refer to Sample.

SpaceTrackerActivity.java

SpaceTrackerRenderer.java