コード例 #1
0
void
MSTracker::addTrackableSource(QCAR::TrackableSource *t) {
    QCAR::TrackerManager& trackerManager =
        QCAR::TrackerManager::getInstance();
    QCAR::ImageTracker* imageTracker =
        static_cast<QCAR::ImageTracker*> (trackerManager.getTracker(
                QCAR::Tracker::IMAGE_TRACKER));
    // Deactivate current dataset
    imageTracker->deactivateDataSet(imageTracker->getActiveDataSet());

    // Replace the previously tracked target (if any) by the new one.
    if ( this->dataset->hasReachedTrackableLimit() ||
            this->dataset->getNumTrackables()) {
        delete static_cast<MSTargetInfo *>(this->dataset->getTrackable(0)->getUserData());
        this->dataset->destroy(this->dataset->getTrackable(0));
    }

    // Add new trackable source
    QCAR::Trackable *trackable = this->dataset->createTrackable(t);

    // Get its additionnal info from controller, and store it as userdata.
    MSTargetInfo *info = MSController::getNewTargetInfo();
    if (info) {
        trackable->setUserData(info);
    }

    // Reactivate current dataset
    imageTracker->activateDataSet(this->dataset);
}
コード例 #2
0
	    virtual void QCAR_onUpdate(QCAR::State& /*state*/)
	    {
	        if (switchDataSetAsap)
	        {
	            switchDataSetAsap = false;

	            // Get the image tracker:
	            QCAR::TrackerManager& trackerManager = QCAR::TrackerManager::getInstance();
	            QCAR::ImageTracker* imageTracker = static_cast<QCAR::ImageTracker*>(
	                trackerManager.getTracker(QCAR::ImageTracker::getClassType()));
	            if (imageTracker == 0 || dataSetStonesAndChips == 0 || dataSetTarmac == 0 || dataSetvmio_vuforial_dev == 0 ||
	                imageTracker->getActiveDataSet() == 0)
	            {
	                LOG("Failed to switch data set.");
	                return;
	            }

				switch( selectedDataset )
				{
					case STONES_AND_CHIPS_DATASET_ID:
						if (imageTracker->getActiveDataSet() != dataSetStonesAndChips)
						{
							imageTracker->deactivateDataSet(dataSetvmio_vuforial_dev);
							imageTracker->deactivateDataSet(dataSetTarmac);
							imageTracker->activateDataSet(dataSetStonesAndChips);
						}
						break;

					case TARMAC_DATASET_ID:
						if (imageTracker->getActiveDataSet() != dataSetTarmac)
						{
							imageTracker->deactivateDataSet(dataSetvmio_vuforial_dev);
							imageTracker->deactivateDataSet(dataSetStonesAndChips);
							imageTracker->activateDataSet(dataSetTarmac);
						}
						break;

					case vmio_vuforial_dev_ID:
						if (imageTracker->getActiveDataSet() != dataSetvmio_vuforial_dev)
						{
							imageTracker->deactivateDataSet(dataSetStonesAndChips);
							imageTracker->activateDataSet(dataSetTarmac);
							imageTracker->deactivateDataSet(dataSetvmio_vuforial_dev);
						}
						break;
				}

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

	        }
	    }
コード例 #3
0
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;
}
コード例 #4
0
ファイル: VirtualButtons.cpp プロジェクト: yaoyaowd/demo
    virtual void QCAR_onUpdate(QCAR::State& /*state*/)
    {
        if (updateBtns)
        {
            // Update runs in the tracking thread therefore it is guaranteed that the tracker is
            // not doing anything at this point. => Reconfiguration is possible.

            assert(QCAR::Tracker::getInstance().getNumTrackables() > 0);
            QCAR::Trackable* trackable = QCAR::Tracker::getInstance().getTrackable(0);
            
            assert(trackable);
            assert(trackable->getType() == QCAR::Trackable::IMAGE_TARGET);
            QCAR::ImageTarget* imageTarget = static_cast<QCAR::ImageTarget*>(trackable);
            

            if (buttonMask & BUTTON_1)
            {
                LOG("Toggle Button 1");
                
                toggleVirtualButton(imageTarget, virtualButtonColors[0],
                                    -108.68f, -53.52f, -75.75f, -65.87f);
                                    
            }
            if (buttonMask & BUTTON_2)
            {
                LOG("Toggle Button 2");
                
                toggleVirtualButton(imageTarget, virtualButtonColors[1], 
                                    -45.28f, -53.52f, -12.35f, -65.87f);
            }
            if (buttonMask & BUTTON_3)
            {
                LOG("Toggle Button 3");
                
                toggleVirtualButton(imageTarget, virtualButtonColors[2], 
                                    14.82f, -53.52f, 47.75f, -65.87f);
            }
            if (buttonMask & BUTTON_4)
            {
                LOG("Toggle Button 4");
                
                toggleVirtualButton(imageTarget, virtualButtonColors[3], 
                                    76.57f, -53.52f, 109.50f, -65.87f);
            }

            buttonMask = 0;
            updateBtns = false;
        }
    }
コード例 #5
0
JNIEXPORT jboolean JNICALL
Java_rajawali_vuforia_RajawaliVuforiaActivity_stopExtendedTracking(JNIEnv*, jobject)
{
    QCAR::TrackerManager& trackerManager = QCAR::TrackerManager::getInstance();
    QCAR::ImageTracker* imageTracker = static_cast<QCAR::ImageTracker*>(
          trackerManager.getTracker(QCAR::ImageTracker::getClassType()));

    QCAR::DataSet* currentDataSet = imageTracker->getActiveDataSet();
    if (imageTracker == 0 || currentDataSet == 0)
    	return JNI_FALSE;

    for (int tIdx = 0; tIdx < currentDataSet->getNumTrackables(); tIdx++)
    {
    	QCAR::Trackable* trackable = currentDataSet->getTrackable(tIdx);
        if(!trackable->stopExtendedTracking())
        	return JNI_FALSE;
    }

    isExtendedTrackingActivated = false;
    return JNI_TRUE;
}
コード例 #6
0
	JNIEXPORT jboolean JNICALL
	Java_com_miosys_finder_ui_PfinderTargets_startExtendedTracking(JNIEnv*, jobject)
	{
	    QCAR::TrackerManager& trackerManager = QCAR::TrackerManager::getInstance();
	    QCAR::ImageTracker* imageTracker = static_cast<QCAR::ImageTracker*>(
	          trackerManager.getTracker(QCAR::ImageTracker::getClassType()));

	    QCAR::DataSet* currentDataSet = imageTracker->getActiveDataSet();
	    if (imageTracker == 0 || currentDataSet == 0)
	    	return JNI_FALSE;

	    for (int tIdx = 0; tIdx < currentDataSet->getNumTrackables(); tIdx++)
	    {
	        QCAR::Trackable* trackable = currentDataSet->getTrackable(tIdx);
	        if(!trackable->startExtendedTracking())
	        	return JNI_FALSE;
	    }

	    isExtendedTrackingActivated = true;
	    return JNI_TRUE;
	}
コード例 #7
0
MSTracker::~MSTracker() {
    QCAR::TrackerManager& trackerManager = QCAR::TrackerManager::getInstance();
    QCAR::ImageTracker* imageTracker = static_cast<QCAR::ImageTracker*>(
                                           trackerManager.getTracker(QCAR::Tracker::IMAGE_TRACKER));

    if (imageTracker != NULL && this->dataset != 0)
    {
        imageTracker->deactivateDataSet(this->dataset);
        int n = this->dataset->getNumTrackables();
        for (int i = 0; i < n; ++i) {
            QCAR::Trackable *t = this->dataset->getTrackable(i);
            if (t->getUserData()) {
                MSTargetInfo *info = static_cast<MSTargetInfo *>(t->getUserData());
                delete info;
                t->setUserData(NULL);
            }
        }
        imageTracker->destroyDataSet(this->dataset);
        this->dataset = NULL;
    }

    trackerManager.deinitTracker(QCAR::Tracker::IMAGE_TRACKER);
}
コード例 #8
0
ファイル: CloudReco.cpp プロジェクト: rxgranda/LumiV2
    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.");
                }
            }
        }
    }
コード例 #9
0
	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;
						}
					}
				}
			}
		}
	}