Example #1
0
 public override TargetFinder.UpdateState Update()
 {
     QCARWrapper.Instance.TargetFinderUpdate(this.mTargetFinderStatePtr);
     this.mTargetFinderState = (TargetFinderState)Marshal.PtrToStructure(this.mTargetFinderStatePtr, typeof(TargetFinderState));
     if (this.mTargetFinderState.ResultCount > 0)
     {
         IntPtr searchResultArray = Marshal.AllocHGlobal((int)(Marshal.SizeOf(typeof(InternalTargetSearchResult)) * this.mTargetFinderState.ResultCount));
         if (QCARWrapper.Instance.TargetFinderGetResults(searchResultArray, this.mTargetFinderState.ResultCount) != 1)
         {
             Debug.LogError("TargetFinder: Could not retrieve new results!");
             return(TargetFinder.UpdateState.UPDATE_NO_MATCH);
         }
         this.mNewResults = new List <TargetFinder.TargetSearchResult>();
         for (int i = 0; i < this.mTargetFinderState.ResultCount; i++)
         {
             IntPtr ptr = new IntPtr(searchResultArray.ToInt32() + (i * Marshal.SizeOf(typeof(QCARManagerImpl.TrackableResultData))));
             InternalTargetSearchResult      result = (InternalTargetSearchResult)Marshal.PtrToStructure(ptr, typeof(InternalTargetSearchResult));
             TargetFinder.TargetSearchResult item   = new TargetFinder.TargetSearchResult {
                 TargetName            = Marshal.PtrToStringAnsi(result.TargetNamePtr),
                 UniqueTargetId        = Marshal.PtrToStringAnsi(result.UniqueTargetIdPtr),
                 TargetSize            = result.TargetSize,
                 MetaData              = Marshal.PtrToStringAnsi(result.MetaDataPtr),
                 TrackingRating        = result.TrackingRating,
                 TargetSearchResultPtr = result.TargetSearchResultPtr
             };
             this.mNewResults.Add(item);
         }
         Marshal.FreeHGlobal(searchResultArray);
     }
     return(this.mTargetFinderState.UpdateState);
 }
    public TargetFinderImpl()
    {
        mTargetFinderState = new TargetFinderState();

        // create the state pointer with the correct size
        mTargetFinderStatePtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TargetFinderState)));
        Marshal.StructureToPtr(mTargetFinderState, mTargetFinderStatePtr, false);
        mImageTargets = new Dictionary <int, ImageTarget>();
    }
    public TargetFinderImpl()
    {
        mTargetFinderState = new TargetFinderState();

        // create the state pointer with the correct size
        mTargetFinderStatePtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TargetFinderState)));
        Marshal.StructureToPtr(mTargetFinderState, mTargetFinderStatePtr, false);
        mImageTargets = new Dictionary<int, ImageTarget>();
    }
    /// <summary>
    /// Update cloud reco results
    ///
    /// Clears and rebuilds the list of target search results with results found
    /// since the last call to updateSearchResults().
    /// Also refreshes the IsRequesting flag.
    /// Returns the status code  UPDATE_RESULTS_AVAILABLE if new search results have been found.
    /// </summary>
    public override UpdateState Update()
    {
        // update the TargetFinder internally to find new results.
        QCARWrapper.Instance.TargetFinderUpdate(mTargetFinderStatePtr);
        mTargetFinderState = (TargetFinderState)Marshal.PtrToStructure(mTargetFinderStatePtr, typeof(TargetFinderState));

        if (mTargetFinderState.ResultCount > 0)
        {
            // there are new results, poll them from native and parse them.
            IntPtr newResultsPtr = Marshal.AllocHGlobal(Marshal.SizeOf(
                                                            typeof(InternalTargetSearchResult)) * mTargetFinderState.ResultCount);

            if (QCARWrapper.Instance.TargetFinderGetResults(newResultsPtr, mTargetFinderState.ResultCount) != 1)
            {
                Debug.LogError("TargetFinder: Could not retrieve new results!");
                return(UpdateState.UPDATE_NO_MATCH);
            }

            mNewResults = new List <TargetSearchResult>();
            for (int i = 0; i < mTargetFinderState.ResultCount; i++)
            {
                IntPtr resultPtr = new IntPtr(newResultsPtr.ToInt32() + i *
                                              Marshal.SizeOf(typeof(QCARManagerImpl.TrackableResultData)));
                InternalTargetSearchResult internalTargetSearchResult = (InternalTargetSearchResult)
                                                                        Marshal.PtrToStructure(resultPtr, typeof(InternalTargetSearchResult));

                // store the results in a nice format
                mNewResults.Add(new TargetSearchResult
                {
                    TargetName            = Marshal.PtrToStringAnsi(internalTargetSearchResult.TargetNamePtr),
                    UniqueTargetId        = Marshal.PtrToStringAnsi(internalTargetSearchResult.UniqueTargetIdPtr),
                    TargetSize            = internalTargetSearchResult.TargetSize,
                    MetaData              = Marshal.PtrToStringAnsi(internalTargetSearchResult.MetaDataPtr),
                    TrackingRating        = internalTargetSearchResult.TrackingRating,
                    TargetSearchResultPtr = internalTargetSearchResult.TargetSearchResultPtr
                });
            }

            Marshal.FreeHGlobal(newResultsPtr);
        }

        return(mTargetFinderState.UpdateState);
    }
    /// <summary>
    /// Update cloud reco results
    ///
    /// Clears and rebuilds the list of target search results with results found
    /// since the last call to updateSearchResults().
    /// Also refreshes the IsRequesting flag. 
    /// Returns the status code  UPDATE_RESULTS_AVAILABLE if new search results have been found.
    /// </summary>
    public override UpdateState Update()
    {
        // update the TargetFinder internally to find new results.
        QCARWrapper.Instance.TargetFinderUpdate(mTargetFinderStatePtr);
        mTargetFinderState = (TargetFinderState)Marshal.PtrToStructure(mTargetFinderStatePtr, typeof(TargetFinderState));

        if (mTargetFinderState.ResultCount>0)
        {
            // there are new results, poll them from native and parse them.
            IntPtr newResultsPtr  = Marshal.AllocHGlobal(Marshal.SizeOf(
                    typeof(InternalTargetSearchResult)) * mTargetFinderState.ResultCount);

            if (QCARWrapper.Instance.TargetFinderGetResults(newResultsPtr, mTargetFinderState.ResultCount) != 1)
            {
                Debug.LogError("TargetFinder: Could not retrieve new results!");
                return UpdateState.UPDATE_NO_MATCH;
            }

            mNewResults = new List<TargetSearchResult>();
            for (int i = 0; i < mTargetFinderState.ResultCount; i++)
            {
                IntPtr resultPtr = new IntPtr(newResultsPtr.ToInt32() + i *
                        Marshal.SizeOf(typeof(QCARManagerImpl.TrackableResultData)));
                InternalTargetSearchResult internalTargetSearchResult = (InternalTargetSearchResult)
                        Marshal.PtrToStructure(resultPtr, typeof(InternalTargetSearchResult));

                // store the results in a nice format
                mNewResults.Add(new TargetSearchResult
                {
                                        TargetName = Marshal.PtrToStringAnsi(internalTargetSearchResult.TargetNamePtr),
                                        UniqueTargetId = Marshal.PtrToStringAnsi(internalTargetSearchResult.UniqueTargetIdPtr),
                                        TargetSize = internalTargetSearchResult.TargetSize,
                                        MetaData = Marshal.PtrToStringAnsi(internalTargetSearchResult.MetaDataPtr),
                                        TrackingRating = internalTargetSearchResult.TrackingRating,
                                        TargetSearchResultPtr = internalTargetSearchResult.TargetSearchResultPtr
                                    });
            }

            Marshal.FreeHGlobal(newResultsPtr);
        }

        return mTargetFinderState.UpdateState;
    }