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);
}
}
}
Here's an example of how to count and Get trackables using the current API. This code will switch between two loaded datasets.