bool
MSTracker::updateTexture(char *name, MSTexture *tex) {
    bool success = false;
    for (int i = 0; i < this->dataset->getNumTrackables(); ++i) {
        QCAR::Trackable *track = this->dataset->getTrackable(i);
        if (!strcmp(name, track->getName())) {
            MSTargetInfo *inf = static_cast<MSTargetInfo *>(track->getUserData());
            inf->updateTexture(tex);
            track->setUserData(inf);
            success = true;
        }
    }
    return success;
}
示例#2
0
    virtual void QCAR_onUpdate(QCAR::State& state)
    {
        // Get the tracker manager:
        QCAR::TrackerManager& trackerManager = QCAR::TrackerManager::getInstance();

        // Get the image tracker:
        QCAR::ImageTracker* imageTracker = static_cast<QCAR::ImageTracker*>(
                trackerManager.getTracker(QCAR::Tracker::IMAGE_TRACKER));

        // Get the target finder:
        QCAR::TargetFinder* finder = imageTracker->getTargetFinder();

        // Check if there are new results available:
        const int statusCode = finder->updateSearchResults();

        // Show a message if we encountered an error:
        if (statusCode < 0)
        {
            showErrorMessage(statusCode, state.getFrame().getTimeStamp());
        }
        else if (statusCode == QCAR::TargetFinder::UPDATE_RESULTS_AVAILABLE)
        {
            // Process new search results
            if (finder->getResultCount() > 0)
            {
                const QCAR::TargetSearchResult* result = finder->getResult(0);

                // Check if this target is suitable for tracking:
                if (result->getTrackingRating() > 0)
                {
                    // Create a new Trackable from the result:
                    QCAR::Trackable* newTrackable = finder->enableTracking(*result);
                    if (newTrackable != 0)
                    {
                        LOG("Successfully created new trackable '%s' with rating '%d'.",
                                newTrackable->getName(), result->getTrackingRating());
                                                
                        // Checks if the targets has changed
                        LOG( "Comparing Strings. currentTargetId: %s  lastTargetId: %s",
                                result->getUniqueTargetId(), lastTargetId);

                        if (strcmp(result->getUniqueTargetId(), lastTargetId) != 0)
                        {
                            // If the target has changed then regenerate the texture
                            // Cleaning this value indicates that the product Texture needs to be generated
                            // again in Java with the new Book data for the new target
                            deleteCurrentProductTexture = true;

                            // Starts the loading state for the product
                            renderState = RS_LOADING;

                            // Copies the new target Metadata
                            snprintf(targetMetadata, CONTENT_MAX, "%s", result->getMetaData());

                            // Calls the Java method with the current product texture
                            createProductTexture(targetMetadata);

                        }
                        else
                            renderState = RS_NORMAL;

                        // Initialize the frames to skip variable, used for waiting
                        // a few frames for getting the chance to tracking before
                        // starting the transition to 2D when there is no target
                        pthread_mutex_lock(&framesToSkipMutex);
                        framesToSkipBeforeRenderingTransition = 10;
                        pthread_mutex_unlock(&framesToSkipMutex);

                        // Initialize state variables
                        showAnimation3Dto2D = true;
                        trackingStarted = false;

                        // Updates the value of the current Target Id with the new target found
                        pthread_mutex_lock(&lastTargetIdMutex);
                        strcpy(lastTargetId, result->getUniqueTargetId());
                        pthread_mutex_unlock(&lastTargetIdMutex);

                        enterContentMode();
                    }
                    else
                        LOG("Failed to create new trackable.");
                }
            }
        }
    }
	virtual void QCAR_onUpdate(QCAR::State&) {

		if (dataSetToActivate != NULL) {
			QCAR::TrackerManager& trackerManager =
					QCAR::TrackerManager::getInstance();
			QCAR::ImageTracker* imageTracker =
					static_cast<QCAR::ImageTracker*>(trackerManager.getTracker(
							QCAR::ImageTracker::getClassType()));
			if (imageTracker == 0) {
				LOG("Failed to activate data set.");
				return;
			}
			imageTracker->activateDataSet(dataSetToActivate);

			if(isExtendedTrackingActivated)
			{
				for (int tIdx = 0; tIdx < dataSetToActivate->getNumTrackables(); tIdx++)
				{
					QCAR::Trackable* trackable = dataSetToActivate->getTrackable(tIdx);
					trackable->startExtendedTracking();
				}
			}

			dataSetToActivate = NULL;
		}

		if (scanningMode) {
			QCAR::TrackerManager& trackerManager =
					QCAR::TrackerManager::getInstance();
			QCAR::ImageTracker* imageTracker =
					static_cast<QCAR::ImageTracker*>(trackerManager.getTracker(
							QCAR::ImageTracker::getClassType()));

			// Get the target finder:
			QCAR::TargetFinder* targetFinder = imageTracker->getTargetFinder();

			// Check if there are new results available:
			const int statusCode = targetFinder->updateSearchResults();

			if (statusCode < 0) {
				char errorMessage[80];
				LOG(errorMessage, "Error with status code %d", statusCode);
			} else if (statusCode
					== QCAR::TargetFinder::UPDATE_RESULTS_AVAILABLE) {
				// Process new search results
				if (targetFinder->getResultCount() > 0) {
					const QCAR::TargetSearchResult* result =
							targetFinder->getResult(0);

					// Check if this target is suitable for tracking:
					if (result->getTrackingRating() > 0) {
						// Create a new Trackable from the result:
						QCAR::Trackable* newTrackable =
								targetFinder->enableTracking(*result);

						if (newTrackable != 0) {
							LOG(
									"Successfully created new trackable '%s' with rating '%d'.",

									newTrackable->getName(), result->getTrackingRating());

							if (strcmp(result->getUniqueTargetId(),
									lastTargetId) != 0) {
								// Copies the new target Metadata
								snprintf(targetMetadata, CONTENT_MAX, "%s",
										result->getMetaData());
								//LOG(targetMetadata);

							}

							strcpy(lastTargetId, result->getUniqueTargetId());

							// Stop Cloud Reco scanning
							targetFinder->stop();

							scanningMode = false;
						}
					}
				}
			}
		}
	}