Log in or register to post comments

problem with loading the dataset

March 12, 2012 - 2:13am #1

hi,

I am having problem with loading the dataset...

I download the dataset from url and write it to the Documents Dir
as follows:
the xml file,

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    
    NSString *documentsDir = [paths objectAtIndex:0];
    NSString *filePathxml = @"http://../../../tracker/tracker.xml";
    
    NSData *dataxml = [NSData dataWithContentsOfURL:[NSURL URLWithString:filePathxml]];
    [dataxml writeToFile:[NSString stringWithFormat:@"%@/tracker.xml",documentsDir] atomically:YES];

and the dat file, here the trackerdat.xml is actually a tracker.dat file which is just renamed so that i can download it..

 NSString *filePathdat = @"http://../../../tracker/trackerdat.xml";
    
    NSData *datadat = [NSData dataWithContentsOfURL:[NSURL URLWithString:filePathdat]];
    
    [datadat writeToFile:[NSString stringWithFormat:@"%@/tracker.dat",documentsDir] atomically:YES];

I can see both tracker.xml and tracker.dat file in organiser in doc dir.
but while loading the dataset in the - (BOOL)loadDataSet:(NSString *)dataSetPath method it does no loads the dataset, giving...

Failed to load data set. in here
QCARutils: Failed to load target

it was loading the dataset earlier when i had done the same thing... but now its just not loading the dataset which i download from server in docs dir.. please help..

Re: problem with loading the dataset

March 13, 2012 - 4:04am #5

Sorry, just noticed you've done 2) using the original non-downloaded files.

So it looks like you need to compare the contents of the files (and see what actually is inside the downloaded ones).

As a wild shot, because your .dat file is being referenced as an xml it is possible that something tries to do some manipulation of it along the line.

Re: problem with loading the dataset

March 13, 2012 - 3:59am #4

Okay - I had to make sure. :-)

So a number of things to try to eliminate possibilities:

1) Binary compare your downloaded tracker.xml/dat to the originals
2) Manually replace the tracker.xml/dat in the Documents folder with Tarmac.dat/xml, renamed, to eliminate any loading problems.

Re: problem with loading the dataset

March 12, 2012 - 11:10pm #3

Hi MoSR,

I know the difference between use of STORAGE_APPRESOURCE and STORAGE_ABSOLUTE.
and I am using it properly... u can chk it here...

- (QCAR::DataSet *)loadDataSet:(NSString *)dataSetPath
{
    QCAR::DataSet *theDataSet = nil;
        
    const char* msg;
    const char* msgNotInit = "Failed to load tracking data set because the ImageTracker has not been initialized.";
    const char* msgFailedToCreate = "Failed to create a new tracking data.";
    const char* msgFailedToLoad = "Failed to load data set.";
    
    // Get the image tracker:
    QCAR::TrackerManager& trackerManager = QCAR::TrackerManager::getInstance();
    QCAR::ImageTracker* imageTracker = static_cast<QCAR::ImageTracker*>(trackerManager.getTracker(QCAR::Tracker::IMAGE_TRACKER));
    
    if (imageTracker == NULL)
    {
        msg = msgNotInit;
        errorCode = QCAR_ERRCODE_INIT_TRACKER;
    }
    else
    {
        // Create the data sets:
        theDataSet = imageTracker->createDataSet();
        if (theDataSet == nil)
        {
            msg = msgFailedToCreate;
            errorCode = QCAR_ERRCODE_CREATE_DATASET;            
        }
        else
        {
            // Load the data set from the App Bundle
            // If the DataSet were in the Documents folder we'd use STORAGE_ABSOLUTE and the full path
            
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
            
            NSString *documentsDir = [paths objectAtIndex:0];
            NSString *pathfinal = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"tracker.xml"];
            NSLog(@"path of Documents Dir: %@", documentsDir);
            
            
            NSString *filePathxml = @"http://../../../tracker/tracker.xml";
            NSData *dataxml = [NSData dataWithContentsOfURL:[NSURL URLWithString:filePathxml]];
            
            [dataxml writeToFile:[NSString stringWithFormat:@"%@/tracker.xml",documentsDir] atomically:YES];
            NSLog(@"XML");
            
            
            NSString *filePathdat = @"http://../../../tracker/trackerdat.xml";
            NSData *datadat = [NSData dataWithContentsOfURL:[NSURL URLWithString:filePathdat]];
           
            [datadat writeToFile:[NSString stringWithFormat:@"%@/tracker.dat",documentsDir] atomically:YES];
            NSLog(@"DAT");
             

             const char *filename = [pathfinal cStringUsingEncoding:NSASCIIStringEncoding];
             
             
            
            
            if (!theDataSet->load(filename, QCAR::DataSet::STORAGE_ABSOLUTE))
            {
                msg = msgFailedToLoad;
                errorCode = QCAR_ERRCODE_LOAD_DATASET;            
                imageTracker->destroyDataSet(theDataSet);
                theDataSet = nil;
            }
            else
            {
                NSLog(@"Successfully loaded data set.");
            }
        }
    }
    
    if (theDataSet == nil)
    {
        NSString* nsMsg = [NSString stringWithUTF8String:msg];
        UIAlertView* alert = [[UIAlertView alloc] initWithTitle:DatasetErrorTitle message:nsMsg delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        NSLog(@"%@", nsMsg);
        [alert show];
        [alert release];
    }
    
    return theDataSet;
}

What my problem is that when i download the .xml and .dat from the url to docs dir then its not loading whereas to cross chk when i just copied the .xml and .dat from my apps resource bundle to docs dir then its loading thedataset from docs dir properly n the apps runs fine.

I think i am not downloading the .dat file correctly... is that the problem as i am renaming the tracker.dat file to trackerdat.xml from server and den downloading it to the docs dir as tracker.dat

n the loading from server used to work well before when the TMS used to give my trackable as config.xml n qcar-resources.dat

i think since there is some change coz of the release of 1-5-8 to the .dat format..

please can u help me with dis..

Re: problem with loading the dataset

March 12, 2012 - 8:10am #2

Hi ajinkyashelar,

I assume that it worked when your Tracker.xml/dat were in the app bundle, and not when they are in the Documents folder?

Take a look at QCARUtils:loadDataSet - it uses STORAGE_APPRESOURCE which looks in the app bundle for the given file.

If you use STORAGE_ABSOLUTE instead and pass in the full path of the .xml file (including the path to Documents) it should work.

I'd recommend making a clone of loadDataSet to do that and leave the original intact.

Log in or register to post comments