Log in or register to post comments

Dataset Loading by Name

April 16, 2012 - 9:33pm #1

Hi,

I am trying to swap datasets at runtime and was wondering if there was to activate a dataset by name not id? I want to be able to load it on the fly from my server so I will already know the name of the dataset it needs to load. In the sample app it shows it loading by number, which doesn't do me much good if I don't know the ID it generates for it.

Code:
imageTracker.ActivateDataSet(imageTracker.GetDataSet(4));

Any help is greatly appreciated.

Dataset Loading by Name

September 8, 2013 - 12:18pm #6

Here's an example of how to count and Get trackables using the current API. This code will switch between two loaded datasets.

 

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

                    IEnumerable<DataSet> dataSets = imageTracker.GetDataSets();
                    IEnumerable<DataSet> activeDataSets = imageTracker.GetActiveDataSets();

                    // Changes current active dataset
                    if (dataSets.Count() >= 2 && activeDataSets.Count() >= 1)
                    {
                        DataSet activeDataSet = activeDataSets.ElementAt(0);
                        
                        if(mCurrentDataSetIndex == 0)
                        {
                            imageTracker.DeactivateDataSet(activeDataSet);
                            imageTracker.ActivateDataSet(dataSets.ElementAt(1));
                            mCurrentDataSetIndex = 1;
                            
                            
                        }else
                        {
                            imageTracker.DeactivateDataSet(activeDataSet);
                            imageTracker.ActivateDataSet(dataSets.ElementAt(0));
                            mCurrentDataSetIndex = 0;
                            
                            
                        }
                        
                    }
                    else
                    {
                        Debug.LogWarning("Not enough data sets to toggle");
                    }
                    

                    
                }
                

 

Dataset Loading by Name

September 7, 2013 - 4:25am #5

Hello,

I was wondering if the code is still valid in the current version of the Unity extension.

I tried to use it and I get problems with 

dataSet.GetNumTrackables()

Type 'DataSet' does not contain a definition for 'GetNumTrackables' and no extension methot 'GetNumTrackables' of type 'DataSet' could be found.

the same error pops up for

dataSet.GetTrackable(i)

Any idea what might cause that?

Best,

Stefan

Dataset Loading by Name

July 17, 2012 - 2:42am #4

Hi Pesche

The only available documentation at present is the sdk help:

https://ar.qualcomm.at/qdevnet/sdk/ios

...and the developer guide

https://ar.qualcomm.at/qdevnet/developer_guide

For the moment, the remainder you need to learn by going through all the samples, plus searching through the forums.

HTH

N

 

 

 

 

Dataset Loading by Name

July 17, 2012 - 1:03am #3

Thanks a lot for this post. That is exactly what I was searching for! :)

I had trouble finding any documentation for the following methods:

imageTracker.GetNumDataSets()
imageTracker.GetDataSet(int)

Where can I find a proper documentation? Are there better sources to get an overview of all available methods beside the incomplete official SDK documentation?

 

 

Re: Dataset Loading by Name

April 17, 2012 - 8:30am #2

Hi nssandhu,

I believe you are using Unity given the code snippet.

Here's a couple of functions from a test menu that we use that should give you enough ideas to implement whatever workflow you need:

    private void DrawDataSetLoadList()
    {
        // Show list of unloaded datasets in the document folder to select from
        ImageTracker imageTracker = (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER);

        // find path where datasets live, and find all candidate DataSets
        string filePath = Application.persistentDataPath + "/Documents/DataSets"; // iOS
        string[] fileList = System.IO.Directory.GetFiles(filePath, "*.xml");

        int areaHeight = (Screen.height / 8) * (fileList.Length + 1); // plus 1 for title
        if (areaHeight > Screen.height)
            areaHeight = Screen.height;

        GUIStyle optionListStyle = CreateOptionListStyle();
        GUIStyle toggleStyle = CreateToggleStyle();

        GUILayout.BeginArea(new Rect(0, Screen.height - areaHeight, Screen.width, areaHeight));
        GUILayout.BeginVertical(optionListStyle);

        GUILayout.Box("Load DataSet from " + filePath, optionListStyle);

        foreach (string path in fileList)
        {
            string name = NameFromPath(path);
            if (GUILayout.Toggle(false, name, toggleStyle))
            {
                DataSet dataSet = imageTracker.CreateDataSet();

                if (!dataSet.Load(path, DataSet.StorageType.STORAGE_ABSOLUTE))
                {
                    imageTracker.DestroyDataSet(dataSet, false);
                    Debug.LogError("Failed to load data set " + path + ".");
                    continue;
                }

                // Attach TrackableEventHandler
                for (int i = 0; i < dataSet.GetNumTrackables(); ++i)
                {
                    dataSet.GetTrackable(i).gameObject.AddComponent<DefaultTrackableEventHandler>();
                }
            }
        }

        GUILayout.EndVertical();
        GUILayout.EndArea();
    }

And to activate...

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

        int areaHeight = (Screen.height / 8) * (imageTracker.GetNumDataSets() + 1); // plus 1 for title
        if (areaHeight > Screen.height)
            areaHeight = Screen.height;

        GUIStyle optionListStyle = CreateOptionListStyle();
        GUIStyle toggleStyle = CreateToggleStyle();
        GUIStyle activeToggleStyle = CreateActiveToggleStyle();

        GUILayout.BeginArea(new Rect(0, Screen.height - areaHeight, Screen.width, areaHeight));
        GUILayout.BeginVertical(optionListStyle);

        GUILayout.Box("De-/Activate DataSet from List:", optionListStyle);

        DataSet activeDataSet = imageTracker.GetActiveDataSet();
        Debug.Log("DrawDataSetActivateList() Loop: Num DataSets = " + imageTracker.GetNumDataSets());
        for (int i = 0; i < imageTracker.GetNumDataSets(); i++)
        {
            DataSet dataSet = imageTracker.GetDataSet(i);
            String name = NameFromPath(dataSet.Path);
            if (dataSet == activeDataSet)
            {
                if (!GUILayout.Toggle(true, name, activeToggleStyle))
                {
                    imageTracker.DeactivateDataSet(activeDataSet);
                }
            }
            else
            {
                if (GUILayout.Toggle(false, name, toggleStyle))
                {
                    imageTracker.DeactivateDataSet(activeDataSet);
                    imageTracker.ActivateDataSet(dataSet);
                }
            }
        }
Log in or register to post comments