Log in or register to post comments

Loading DataSet Dynamically ..

June 9, 2013 - 9:55pm #17

hi ,

 

   i am also doing same . i have to change data set dynamically  using  .........vuforia-unity-android-ios-2-0-32 SDK.

 for testing perpous i have change the code on  onclick of option menu  in imageTarget sample check out my code.

 

 
 
 // button to change to cont. auto focus:
              if (GUILayout.Button("Activate Cont. Auto Focus", buttonGroupStyle))
                  {
                        ImageTracker imageTracker = (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER);
 
                        IEnumerable<DataSet> dataSets = imageTracker.GetDataSets();
                        IEnumerable<DataSet> activeDataSets = imageTracker.GetActiveDataSets(); 
                        DataSet activeDataSet = activeDataSets.ElementAt(0);
                        imageTracker.DeactivateDataSet(activeDataSet);                ..............................deactivate lcurrent detaset.
 
                       //string datasetpath = Application.persistentDataPath + "/Tarmac.xml";
                       //string datasetpath = "StreamingAssets/QCAR/Tarmac.xml";
 
                       DataSet mDataSet;
                       mDataSet= imageTracker.CreateDataSet();
 
                       mDataSet.Load("StreamingAssets/QCAR/Tarmac.xml", DataSet.StorageType.STORAGE_ABSOLUTE);
 
                       imageTracker.ActivateDataSet(mDataSet);..............................................active new data set.
 
                       mMenuOpen = false;
                       mButtonPressed = true;
 
                   }
 Now my last activated dataset is become decative but new dataset  is not becone active .
it seems , i am doing some mistack to load or active new dataset . actully yesterday i installed the  unity .. help me OUT

Loading DataSet Dynamically ..

June 10, 2013 - 2:34am #16

Hi, the problem seems to be with the way you load the dataset;

actually you should not use STORAGE_ABSOLUTE

mDataSet.Load("StreamingAssets/QCAR/Tarmac.xml", DataSet.StorageType.STORAGE_ABSOLUTE);
 

because the StreamingAssets is a special directory; the assets located there will be packaged with your app;

you shoudl rather use STORAGE_APPRESOURCE, and the path should be just "QCAR/Tarlac.xml"...

 

Loading DataSet Dynamically ..

June 10, 2013 - 10:10pm #15

HI ,

 I did same , but still  my dataSet( Tarmac .xml) not activated .  once check my code.

else
                {
 
                    // button to change to cont. auto focus:
                    if (GUILayout.Button("Activate Cont. Auto Focus", buttonGroupStyle))
                    {
      ImageTracker imageTracker = (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER);
 
                       IEnumerable<DataSet> dataSets = imageTracker.GetDataSets();
                       IEnumerable<DataSet> activeDataSets = imageTracker.GetActiveDataSets();
 
                        DataSet activeDataSet = activeDataSets.ElementAt(0);
                        imageTracker.DeactivateDataSet(activeDataSet);
                     
 
DataSet mDataSet = imageTracker.CreateDataSet();
                        mDataSet.Load("QCAR/Tarmac.xml", DataSet.StorageType.STORAGE_APPRESOURCE);
imageTracker.ActivateDataSet(mDataSet);
 
 
mMenuOpen = false;
                        mButtonPressed = true;
 
                        }
                    }

                }

 
public bool LoadDataSet(string dataSetPath, DataSet.StorageType storageType)
{
    // Check if the data set exists at the given path.
    if (!DataSet.Exists(dataSetPath, storageType))
    {
        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(dataSetPath, storageType))
    {
        Debug.LogError("Failed to load data set " + dataSetPath + ".");
        return false;
    }
   
    // (Optional) Activate the data set.
    imageTracker.ActivateDataSet(dataSet);
      
return true;
         
}
 

 What i missed ? please chek it . 

and how to load model dynamiclly .suggest any link.

Loading DataSet Dynamically ..

June 13, 2013 - 12:03am #14

Hi dude ,

 

  Please check  my code if i am doing any mistake .

i am not able to activate dataset dynamically onclick of option minu.

Loading DataSet Dynamically ..

June 13, 2013 - 3:03am #13

One question: does this happen when running in PlayMode or on device ? 

 

Loading DataSet Dynamically ..

June 13, 2013 - 9:53pm #12

Hi,

   this happening when running  on device .

Loading DataSet Dynamically ..

June 28, 2013 - 7:08am #11

Similar problem, but for the native app on android and not for native app using unity for android.

Can you give some pointers as to how to dynamically load datasets for android/ios application.

I could not find STORAGE_ABSOLUTE mentioned in thread; within the sample code of ImageTargets for android.

Also I would like to know, if I can replace ".dat" and ".xml" file dynamically?

And I would like to know, when is .dat file loaded/utilised/read, is it during compile time or during runtime. Can we save it to some other location than assets ? how to do that?

Regards

Loading DataSet Dynamically ..

June 28, 2013 - 7:18am #10

Hi katchdoze,

in Android you can look at the code in _LoadTrackerData() function in ImageTargets.cpp; that's where the datasets are loaded;

if you want to load from an absolute path, you need to call something like:

dataset->load("some_path_to_my_dataset_xml", QCAR::DataSet::STORAGE_ABSOLUTE);

for example, if your dataset is stored in the SD card of your device, the path could look like:

mnt/sdcard/my_dataset.xml

And yes, you can load datasets dynamically (i.e. at runtime), just calling the same dataset->load() method.

See also the API reference of the QCAR::DataSet class:

https://developer.vuforia.com/resources/api/class_q_c_a_r_1_1_data_set

Loading DataSet Dynamically ..

July 1, 2013 - 1:49pm #9

Hi Alessandro,

Thank you for the tip(s). I tried the api and here are my observations.

a) If the dataset is prepackaged with my application, I am able to load the dataset dynamically at runtime.
b) If the dataset is already on my local storage (/storage/emulated/0/Vuforia/mydataset.xml), I am unable to load the dataset dynamically.

Here is the code which tries to load dataset.

    LOG("Switching to Mydataset");
    if (!dataSetMyDS->exists(switch_path, QCAR::DataSet::STORAGE_ABSOLUTE))
        LOG(" DB Does not exist");
    else
        LOG (" DB exists at given location");

    if (!dataSetMyDS->load(switch_path, QCAR::DataSet::STORAGE_ABSOLUTE))
    {
        LOG("Failed to load MyDataset data set.");
    }

The logcat output is (condensed one for clarity)--

>> Switching to Mydataset
>> DB exists at given location
>> Failed to load dataset '/storage/emulated/0/Vuforia/mydataset.xml'.
>> Failed to load MyDataset data set.

Can you suggest what is it that I might be doing wrong?

Regards

Loading DataSet Dynamically ..

July 1, 2013 - 1:59pm #8

Hi, are you executing that code from the QCAR_onUpdate() function ? if not, that could be potentially the reason why it fails...

Loading DataSet Dynamically ..

July 1, 2013 - 2:13pm #7

Hi,

Thanks for quick response. Yes I am executing the code in OnUpdate.

Also noticed, the dataset->exists(), api does not fail, even if I make it point to some other file(which doesnot exists).

Is there some better way to test if the path of dataset is valid.

Regards

Loading DataSet Dynamically ..

July 1, 2013 - 2:25pm #6

You might need to change the path by adding the "mnt" prefix (as Android file system is a Linux one), something like

somthing like mnt/sdcard/mydataset.xml

also, what is the "emulated" directory ?

you should point to the actual sdcard of your device (see my example path above)

 

Loading DataSet Dynamically ..

July 1, 2013 - 2:29pm #5

Hi,

I am getting this path on my nexus 10 using following code on the java side --

File dir = Environment.getExternalStorageDirectory();

File myFile = new File(dir, "Vuforia/mydataset.xml");

switchDatasetAsap(switch_mode,myFile.getAbsolutePath());

So the emulated path is something that comes from the externalstorage api on the java side.

Regards

Loading DataSet Dynamically ..

July 2, 2013 - 1:01am #4

I see. In principle that should be correct; however I would suggest to try to use a hardcoded path like mnt/sdcard/..... I recall i tried this in the past and it worked without problems.

 

Loading DataSet Dynamically ..

July 3, 2013 - 2:14am #3

Hi Alessandro,

Sorry for the delay in response.

I haven't tried the /mnt/sdcard way but I would not prefer this approach, simply because there is huge disparity of devices out there. So even if it works with one, there are chances it will break on some other device.

But I did try to copy over the file in application's private directory and there dynamic loading worked fine.

So for now, I am happy with this approach, but would also prefer the other thing to work.

Also would help other developers, if the documentation reflects the potential limitation of api, unless I am the only one who is facing this issue ;).

Regards

Loading DataSet Dynamically ..

July 3, 2013 - 2:34am #2

Have you tried with:

getExternalStorageDirectory().getAbsolutePath()

This should be the correct way of accessing the directory on the sdcard;

as far as Vuforia is concerned, the loading should work, provided that the filepath is actually the correct one.

This thread also covers this subject:

http://stackoverflow.com/questions/5453708/android-how-to-use-environment-getexternalstoragedirectory

 

 

Loading DataSet Dynamically ..

July 21, 2017 - 1:32am #1

for android

save dataset at context.getFilesDir().

Change dataset.load("dataset.xml",STORAGE_TYPE.APPRESOURCE) to dataset.load("dataset.xml",STORAGE_TYPE.APP)

Log in or register to post comments