Topic locked

Understanding example ImageTarget

January 14, 2014 - 9:02am #1

Hi,

I'm now trying to modify the ImageTarget example, but I cannot understand some things in the code.

It's about these methods : 

    // Methods to load and destroy tracking data.
    @Override
    public boolean doLoadTrackersData()
    {
        TrackerManager tManager = TrackerManager.getInstance();
        ImageTracker imageTracker = (ImageTracker) tManager
            .getTracker(ImageTracker.getClassType());
        if (imageTracker == null)
            return false;
        
        if (mCurrentDataset == null)
            mCurrentDataset = imageTracker.createDataSet();
        
        if (mCurrentDataset == null)
            return false;
        
        if (!mCurrentDataset.load(
            mDatasetStrings.get(mCurrentDatasetSelectionIndex),
            DataSet.STORAGE_TYPE.STORAGE_APPRESOURCE))
            return false;
        
        if (!imageTracker.activateDataSet(mCurrentDataset))
            return false;
        
        int numTrackables = mCurrentDataset.getNumTrackables();
        for (int count = 0; count < numTrackables; count++)
        {
            Trackable trackable = mCurrentDataset.getTrackable(count);
            if(isExtendedTrackingActive())
            {
                trackable.startExtendedTracking();
            }
            
            String name = "Current Dataset : " + trackable.getName();
            trackable.setUserData(name);
            Log.d(LOGTAG, "UserData:Set the following user data "
                + (String) trackable.getUserData());
        }
        
        return true;
    }
    
    
    @Override
    public boolean doUnloadTrackersData()
    {
        // Indicate if the trackers were unloaded correctly
        boolean result = true;
        
        TrackerManager tManager = TrackerManager.getInstance();
        ImageTracker imageTracker = (ImageTracker) tManager
            .getTracker(ImageTracker.getClassType());
        if (imageTracker == null)
            return false;
        
        if (mCurrentDataset != null && mCurrentDataset.isActive())
        {
            if (imageTracker.getActiveDataSet().equals(mCurrentDataset)
                && !imageTracker.deactivateDataSet(mCurrentDataset))
            {
                result = false;
            } else if (!imageTracker.destroyDataSet(mCurrentDataset))
            {
                result = false;
            }
            
            mCurrentDataset = null;
        }
        
        return result;
    }

And more precisely this one : 

 

 @Override
    public void onQCARUpdate(State state)
    {
        if (mSwitchDatasetAsap)
        {
            mSwitchDatasetAsap = false;
            TrackerManager tm = TrackerManager.getInstance();
            ImageTracker it = (ImageTracker) tm.getTracker(ImageTracker
                .getClassType());
            if (it == null || mCurrentDataset == null
                || it.getActiveDataSet() == null)
            {
                Log.d(LOGTAG, "Failed to swap datasets");
                return;
            }
            
            doUnloadTrackersData();
            doLoadTrackersData();
        }
    }

 

I don't understand why the tracker data have to be unloaded and reloaded, and why we should switch the dataSet ?

A dataSet is a target description and settings if I'm right. Why and when do we switch it, for what ?

 

Thanks in advance.

 

Vince.

Understanding example ImageTarget

January 14, 2014 - 9:37am #3

Okay,

Thanks a lot :-)

Understanding example ImageTarget

January 14, 2014 - 9:15am #2

Each dataset can contain a certain number of image targets (up to 100).

The reason why we switch dataset in the sample is to show that you can use different Datasets in the same app;

for example, one Dataset may contain a certain number of Image Targets that you would use in a certain scenario , while you would use the other dataset in a different scenario.

Also, you cannot have more than 100 targets active at the same time, so you could for example have 2 datasets, with 100 targets each (so, 200 targets in total) stored on your device, but only use one of them (i.e. 100 targets) at a time.

Note however, that if you have just a few targets, you don;t need to worry about switching dataset; you can just put all your targets in one dataset and use that.

More information are on the developer guide, which I invite you to read.

 

Topic locked