Log in or register to post comments

Activate a dataset that is already loaded

July 9, 2012 - 2:56am #1

How do you activate a data set that has already been loaded (checkboxed in camera)?

To activate a data set, do you need to specify the abs file directory and load it from scratch? 

Activate a dataset that is already loaded

July 11, 2012 - 7:11am #10

That's right. A Getter on DataSetLoadBehaviour would do the same internally.

Activate a dataset that is already loaded

July 11, 2012 - 2:46am #9

Hi ina,

At present there does not appear to be.

If you look at DataSetLoadBehaviour.cs

... you will see that the name of the dataset is used initially to load it into the mDatasets list variable within the ImageTracker class.
 
If you wanted to then it should not be too hard to create a lookup from the name to the index into the list if you want to avoid the iteration at run time.
 
HTH
 
N

Activate a dataset that is already loaded

July 9, 2012 - 9:37pm #8

Is the only way to reference the datasets to loop through them? ie no way to access data set directly by name? 

Activate a dataset that is already loaded

July 9, 2012 - 9:01am #7

You can obtain the set of loaded datasets from the ImageTracker, and then iterate through them to select the one that you want to activate.

 

e.g.

        ImageTracker imageTracker =
(ImageTracker)TrackerManager.Instance.GetTracker(
Tracker.Type.IMAGE_TRACKER);

int dcnt = imageTracker.GetNumDataSets();

Debug.Log("Found "+dcnt+" Loaded DataSets");

string active_path = imageTracker.GetActiveDataSet().Path;

Debug.Log( active_path +" is currently active");

string path = "";
string dataset_path_to_activate = "/DataSet/To/Activate";

DataSet dataSet;

for( int n=0; n < dcnt; n++ ){

dataSet = imageTracker.GetDataSet(n);
path = dataSet.Path;

// find the target dataset, but don't bother activating it if it's already active
if( path.Equals(dataset_path_to_activate) && !active_path.Equals(dataset_path_to_activate) ){

imageTracker.DeactivateDataSet( imageTracker.GetActiveDataSet() );

Debug.Log("Deactivating "+active_path+", Activating "+dataset_path_to_activate);

imageTracker.ActivateDataSet( dataSet );

}
}

* you can do the same by indices if you know their order.

Activate a dataset that is already loaded

July 9, 2012 - 8:44am #6

Hi ina

I think I mentioned that below as the code is in CameraDeviceMenu.cs.  Remember that in ImageTargets it shows how to do this as you can swap between the two datasets StonesAndChips and Tarmac that are specified at design time in Unity

Code is below.

Hope I have understood correctly and that this helps.

N

 

        // Swap data sets.

        if (GUILayout.Button("Toggle Data Set", buttonGroupStyle))

        {

            Debug.Log("Toggle data set");

            ImageTracker imageTracker = (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER);

 

            // Toggle between first two available data sets.

            if (imageTracker.GetNumDataSets() >= 2)

            {

                DataSet activeDataSet = imageTracker.GetActiveDataSet();

                if (activeDataSet == imageTracker.GetDataSet(0))

                {

                    imageTracker.DeactivateDataSet(activeDataSet);

                    imageTracker.ActivateDataSet(imageTracker.GetDataSet(1));

                    Debug.Log("swapping to dataset " + imageTracker.GetDataSet(1).Path);

                }

                else

                {

                    imageTracker.DeactivateDataSet(activeDataSet);

                    imageTracker.ActivateDataSet(imageTracker.GetDataSet(0));

                    Debug.Log("swapping to dataset " + imageTracker.GetDataSet(0).Path);

                }

            }

            else

            {

                Debug.LogWarning("Not enough data sets to toggle");

            }

        }

        

 

 

Activate a dataset that is already loaded

July 9, 2012 - 7:41am #5

In the example, it seems dataSet is created from a new data set, loaded from path..

 

It seems that when you import the .unitypackage and checkbox "load dataset" in the ARcamera, then it is loaded. How do you simply activate the already-loaded data set(s) at runtime? 

Activate a dataset that is already loaded

July 9, 2012 - 7:10am #4

hi ina,

Thanks for drawing this for our attention.

Below is the code snippet that itself was snipped ;) apologies for this.

Does this answer your question?

 

N

 

// Load and activate a data set at the given path.
private bool LoadDataSet(string dataSetPathDataSet.StorageType storageType)
{
    // Check if the data set exists at the given path.
    if (!DataSet.Exists(dataSetPathstorageType))
    {
        Debug.LogError("Data set " + dataSetPath + " does not exist.");
        return false;
    }
 
    // Request an ImageTracker instance from the TrackerManager.
    ImageTracker imageTracker =
        (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER);
 
    // Create a new empty data set.
    DataSet dataSet = imageTracker.CreateDataSet();
 
    // Load the data set from the given path.
    if (!dataSet.Load(dataSetPathstorageType))
    {
        Debug.LogError("Failed to load data set " + dataSetPath + ".");
        return false;
    }
 
    // (Optional) Activate the data set.
    imageTracker.ActivateDataSet(dataSet);
        
    return true;
}

 

Activate a dataset that is already loaded

July 9, 2012 - 6:25am #3

I guess my question is how do you reference the data set (without having to use the full path to load - and, it's loaded already, it seems), what's the parameter to pass into ActivateDataSet? You can't seem to just drag/drop the component in Unity... 

 

P.S. Similar info is avaialble https://ar.qualcomm.at/developer_guide ... for the Transition from Unity section, except the snippet is cut off. 

Activate a dataset that is already loaded

July 9, 2012 - 3:21am #2

hi ina

This is explained in detail here https://ar.qualcomm.at/sdk/ios

... but first you need to navigate to  Getting Started Unity Extension -> Step 3 Mastering advanced topics -> Swappable datasets

Basically you need to use the imageTracker instance to activate a dataset (remember that only a single dataset can be active at a time). 

ImageTracker.ActivateDataSet(DataSet dataset);

Also, if you load up the ImageTargets sample and look at the CameraDeviceMenu.cs and search for datasets you should find how to do it.

 

HTH

N

Log in or register to post comments