Example #1
0
// cleanup();
JNIEXPORT jboolean JNICALL JNIFUNCTION_NATIVE(nativeStop(JNIEnv* env, jobject object))
{
#ifdef DEBUG
    LOGI("nativeStop\n");
#endif
    int i, j;
    
	// Can't call arglCleanup() here, because nativeStop is not called on rendering thread.

    // NFT cleanup.
    if (trackingThreadHandle) {
#ifdef DEBUG
        LOGI("Stopping NFT2 tracking thread.");
#endif
        trackingInitQuit(&trackingThreadHandle);
        detectedPage = -2;
    }
    j = 0;
    for (i = 0; i < surfaceSetCount; i++) {
        if (surfaceSet[i]) {
#ifdef DEBUG
            if (j == 0) LOGI("Unloading NFT tracking surfaces.");
#endif
            ar2FreeSurfaceSet(&surfaceSet[i]); // Sets surfaceSet[i] to NULL.
            j++;
        }
    }
#ifdef DEBUG
    if (j > 0) LOGI("Unloaded %d NFT tracking surfaces.", j);
#endif
    surfaceSetCount = 0;
    nftDataLoaded = false;
#ifdef DEBUG
	LOGI("Cleaning up ARToolKit NFT handles.");
#endif
    ar2DeleteHandle(&ar2Handle);
    kpmDeleteHandle(&kpmHandle);
    arParamLTFree(&gCparamLT);
    
    // OpenGL cleanup -- not done here.
    
    // Video cleanup.
    if (gVideoFrame) {
        free(gVideoFrame);
        gVideoFrame = NULL;
        gVideoFrameSize = 0;
        pthread_mutex_destroy(&gVideoFrameLock);
    }
    ar2VideoClose(gVid);
    gVid = NULL;
    videoInited = false;

    return (true);
}
Example #2
0
void ofxArtool5::unloadNFTData(){
    int i,j;
    if(threadHandle){
        trackingInitQuit(&threadHandle);
    }
    j=0;
    for (i = 0; i < surfaceSetCount; i++) {
        ar2FreeSurfaceSet(&surfaceSet[i]);
        j++;
    }
    surfaceSetCount=0;
}
Example #3
0
// Modifies globals: threadHandle, surfaceSet[], surfaceSetCount
static int unloadNFTData(void)
{
    int i, j;
    
    if (threadHandle) {
        ARLOGi("Stopping NFT2 tracking thread.\n");
        trackingInitQuit(&threadHandle);
    }
    j = 0;
    for (i = 0; i < surfaceSetCount; i++) {
        if (j == 0) ARLOGi("Unloading NFT tracking surfaces.\n");
        ar2FreeSurfaceSet(&surfaceSet[i]); // Also sets surfaceSet[i] to NULL.
        j++;
    }
    if (j > 0) ARLOGi("Unloaded %d NFT tracking surfaces.\n", j);
    surfaceSetCount = 0;
    
    return 0;
}
Example #4
0
// References globals: markersNFTCount
// Modifies globals: trackingThreadHandle, surfaceSet[], surfaceSetCount, markersNFT[], markersNFTCount
static void *loadNFTDataAsync(THREAD_HANDLE_T *threadHandle)
{
    int i, j;
	KpmRefDataSet *refDataSet;
    
    while (threadStartWait(threadHandle) == 0) {
#ifdef DEBUG
        LOGE("Loading NFT data.\n");
#endif
    
        // If data was already loaded, stop KPM tracking thread and unload previously loaded data.
        if (trackingThreadHandle) {
            LOGE("NFT2 tracking thread is running. Stopping it first.\n");
            trackingInitQuit(&trackingThreadHandle);
            detectedPage = -2;
        }
        j = 0;
        for (i = 0; i < surfaceSetCount; i++) {
            if (j == 0) LOGE("Unloading NFT tracking surfaces.");
            ar2FreeSurfaceSet(&surfaceSet[i]); // Also sets surfaceSet[i] to NULL.
            j++;
        }
        if (j > 0) LOGE("Unloaded %d NFT tracking surfaces.\n", j);
        surfaceSetCount = 0;
    
        refDataSet = NULL;
    
        for (i = 0; i < markersNFTCount; i++) {
            // Load KPM data.
            KpmRefDataSet  *refDataSet2;
            LOGI("Reading %s.fset3\n", markersNFT[i].datasetPathname);
            if (kpmLoadRefDataSet(markersNFT[i].datasetPathname, "fset3", &refDataSet2) < 0 ) {
                LOGE("Error reading KPM data from %s.fset3\n", markersNFT[i].datasetPathname);
                markersNFT[i].pageNo = -1;
                continue;
            }
            markersNFT[i].pageNo = surfaceSetCount;
            LOGI("  Assigned page no. %d.\n", surfaceSetCount);
            if (kpmChangePageNoOfRefDataSet(refDataSet2, KpmChangePageNoAllPages, surfaceSetCount) < 0) {
                LOGE("Error: kpmChangePageNoOfRefDataSet\n");
                exit(-1);
            }
            if (kpmMergeRefDataSet(&refDataSet, &refDataSet2) < 0) {
                LOGE("Error: kpmMergeRefDataSet\n");
                exit(-1);
            }
            LOGI("  Done.\n");
        
            // Load AR2 data.
            LOGI("Reading %s.fset\n", markersNFT[i].datasetPathname);

            if ((surfaceSet[surfaceSetCount] = ar2ReadSurfaceSet(markersNFT[i].datasetPathname, "fset", NULL)) == NULL ) {
                LOGE("Error reading data from %s.fset\n", markersNFT[i].datasetPathname);
            }
            LOGI("  Done.\n");
        
            surfaceSetCount++;
            if (surfaceSetCount == PAGES_MAX) break;
        }
        if (kpmSetRefDataSet(kpmHandle, refDataSet) < 0) {
            LOGE("Error: kpmSetRefDataSet");
            exit(-1);
        }
        kpmDeleteRefDataSet(&refDataSet);
    
        // Start the KPM tracking thread.
        trackingThreadHandle = trackingInitInit(kpmHandle);
        if (!trackingThreadHandle) exit(-1);

#ifdef DEBUG
        LOGI("Loading of NFT data complete.");
#endif

        threadEndSignal(threadHandle); // Signal that we're done.
    }
    return (NULL); // Exit this thread.
}