/// <summary>
        /// Begin querying for found objects.
        /// </summary>
        /// <param name="filter">Filter to use for this query.</param>
        /// <param name="callback">Callback used to report query results.</param>
        /// <returns>
        /// MLResult.Result will be <c>MLResult.Code.Ok</c> if successful.
        /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if failed due to invalid input parameter.
        /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to internal error.
        /// </returns>
        private MLResult BeginObjectQueryAsync(Query.Filter filter, QueryResultsDelegate callback)
        {
            try
            {
                if (!MagicLeapNativeBindings.MLHandleIsValid(_instance.handle))
                {
                    MLPluginLog.Error("MLFoundObjects.BeginObjectQuery failed to request found objects. Reason: Tracker handle is invalid");
                    return(MLResult.Create(MLResult.Code.InvalidParam));
                }

                NativeBindings.QueryFilterNative nativeQueryFilter = new NativeBindings.QueryFilterNative();
                nativeQueryFilter.Data = filter;

                MLResult.Code resultCode = NativeBindings.MLFoundObjectQuery(_instance.handle, ref nativeQueryFilter, out ulong queryHandle);
                MLResult      result     = MLResult.Create(resultCode);

                if (!result.IsOk)
                {
                    MLPluginLog.ErrorFormat("MLFoundObjects.BeginObjectQuery failed to request objects. Reason: {0}", resultCode);
                    return(result);
                }

                // Add query to the list of pendingQueries.
                Query query = Query.Create(callback, filter);
                MLFoundObjects._instance.pendingQueries.TryAdd(queryHandle, query);

                return(result);
            }
            catch (System.EntryPointNotFoundException)
            {
                MLPluginLog.Error("MLFoundObjects.BeginObjectQuery failed. Reason: API symbols not found");
                return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLFoundObjects.BeginObjectQuery failed. Reason: API symbols not found"));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Begin querying for found objects.
        /// </summary>
        /// <param name="callback">Callback used to report query results.</param>
        /// <returns>
        /// MLResult.Result will be <c>MLResult.Code.Ok</c> if successful.
        /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if failed due to invalid input parameter.
        /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to internal error.
        /// </returns>
        private MLResult BeginObjectQuery(QueryResultsDelegate callback)
        {
            try
            {
                if (!MagicLeapNativeBindings.MLHandleIsValid(_instance.tracker))
                {
                    MLPluginLog.Error("MLFoundObject.BeginObjectQuery failed to request found objects. Reason: Tracker handle is invalid");
                    return(MLResult.Create(MLResult.Code.InvalidParam));
                }

                NativeBindings.QueryFilterNative queryFilter = new NativeBindings.QueryFilterNative();

                MLResult.Code resultCode = NativeBindings.MLFoundObjectQuery(_instance.tracker, ref queryFilter, out ulong queryHandle);
                MLResult      result     = MLResult.Create(resultCode);

                if (!result.IsOk)
                {
                    MLPluginLog.ErrorFormat("MLFoundObject.BeginObjectQuery failed to request objects. Reason: {0}", resultCode);
                    return(result);
                }

                // Create query object to prepresent this newly registered found object query.
                NativeBindings.Query query = new NativeBindings.Query(callback, queryFilter, result);
                MLFoundObjects._instance.pendingQueries.Add(queryHandle, query);

                return(result);
            }
            catch (System.EntryPointNotFoundException)
            {
                MLPluginLog.Error("MLFoundObjects.BeginObjectQuery failed. Reason: API symbols not found");
                return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLFoundObjects.BeginObjectQuery failed. Reason: API symbols not found"));
            }
        }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Query"/> struct.
 /// </summary>
 /// <param name="callback">The callback that should be invoked.</param>
 /// <param name="queryFilter">The filter applied to the query.</param>
 /// <param name="result">The result of the query.</param>
 public Query(QueryResultsDelegate callback, NativeBindings.QueryFilterNative queryFilter, MLResult result)
 {
     this.Callback    = callback;
     this.QueryFilter = queryFilter;
     this.Result      = result;
 }
Beispiel #4
0
        /// <summary>
        /// Returns filtered list of PCFs based on the parameters of the given queryFilter.
        /// </summary>
        /// <param name="queryFilter">Parameters used to curate the returned values.</param>
        /// <param name="pcfList">Stores the resulting list of PCFs.</param>
        /// <param name="update">Determines if the PCFs should have their pose updated.</param>
        /// <returns>
        /// MLResult.Result will be <c>MLResult.Code.Ok</c> if all the PCFs from the current map have been found successfully.
        /// MLResult.Result will be <c>MLResult.Code.PrivilegeDenied</c> if necessary privilege is missing.
        /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to other internal error.
        /// MLResult.Result will be <c>MLResult.Code.PassableWorldLowMapQuality</c> if map quality is too low for content persistence. Continue building the map.
        /// MLResult.Result will be <c>MLResult.Code.PassableWorldUnableToLocalize</c> if currently unable to localize into any map. Continue building the map.
        /// </returns>
        public static MLResult FindPCFsByFilter(QueryFilter queryFilter, out List <PCF> pcfList, bool update = true)
        {
            pcfList = new List <PCF>();

            if (MLPersistentCoordinateFrames.IsValidInstance())
            {
                try
                {
                    uint          numPCFs    = 0;
                    MLResult.Code resultCode = NativeBindings.MLPersistentCoordinateFrameGetCount(_instance.nativeTracker, ref numPCFs);

                    if (MLResult.IsOK(resultCode) && numPCFs > 0)
                    {
                        MagicLeapNativeBindings.MLCoordinateFrameUID[] cfuidArray = new MagicLeapNativeBindings.MLCoordinateFrameUID[numPCFs];
                        NativeBindings.QueryFilterNative queryFilterNative        = NativeBindings.QueryFilterNative.Create();
                        queryFilterNative.Data = queryFilter;

                        uint cfuidCount = 0;

                        //// With these conditions the user is asking for all PCFs, no need to use the slower filtered query call.
                        if (queryFilter.TypesMask == (PCF.Types.SingleUserSingleSession | PCF.Types.SingleUserMultiSession | PCF.Types.MultiUserMultiSession) &&
                            queryFilter.Radius <= 0 && !queryFilter.Sorted)
                        {
                            resultCode = NativeBindings.MLPersistentCoordinateFrameGetAllEx(_instance.nativeTracker, numPCFs, cfuidArray);
                            cfuidCount = (uint)cfuidArray.Length;
                        }
                        else
                        {
                            resultCode = NativeBindings.MLPersistentCoordinateFrameQuery(_instance.nativeTracker, in queryFilterNative, cfuidArray, out cfuidCount);
                        }

                        if (MLResult.IsOK(resultCode))
                        {
                            for (int i = 0; i < cfuidCount; ++i)
                            {
                                MagicLeapNativeBindings.MLCoordinateFrameUID pcfCFUID = cfuidArray[i];
                                if (!pcfCFUID.Equals(MagicLeapNativeBindings.MLCoordinateFrameUID.EmptyFrame))
                                {
                                    PCF pcf = null;
                                    if (_instance.mapAllPCFs.ContainsKey(pcfCFUID))
                                    {
                                        pcf = _instance.mapAllPCFs[pcfCFUID];
                                    }
                                    else
                                    {
                                        pcf = new PCF(pcfCFUID);
                                        _instance.mapAllPCFs.Add(pcfCFUID, pcf);
                                    }

                                    pcfList.Add(pcf);

                                    if (update)
                                    {
                                        MLResult result = pcf.Update();
                                        if (!result.IsOk)
                                        {
                                            MLPluginLog.ErrorFormat("MLPersistentCoordinateFrames.FindPCFsByFilter failed to update the found PCF with CFUID {0}, Reason: {1}", pcf.CFUID, result);
                                        }
                                    }
                                }
                            }

                            return(MLResult.Create(MLResult.Code.Ok));
                        }
                        else
                        {
                            if (resultCode == MLResult.Code.PassableWorldLowMapQuality || resultCode == MLResult.Code.PassableWorldUnableToLocalize)
                            {
                                MLPluginLog.WarningFormat("Map quality not sufficient enough for MLPersistentCoordinateFrames.FindPCFsByFilter. Reason: {0}", MLResult.CodeToString(resultCode));
                            }
                            else
                            {
                                MLPluginLog.ErrorFormat("MLPersistentCoordinateFrames.FindPCFsByFilter failed. Reason: {0}", MLResult.CodeToString(resultCode));
                            }

                            return(MLResult.Create(resultCode, string.Format("MLPersistentCoordinateFrames.FindPCFsByFilter failed. Reason: {0}", MLResult.CodeToString(resultCode))));
                        }
                    }
                    else
                    {
                        if (resultCode == MLResult.Code.PassableWorldLowMapQuality || resultCode == MLResult.Code.PassableWorldUnableToLocalize)
                        {
                            MLPluginLog.WarningFormat("Map quality not sufficient enough for MLPersistentCoordinateFrames.FindPCFsByFilter. Reason: {0}", MLResult.CodeToString(resultCode));
                        }
                        else
                        {
                            MLPluginLog.ErrorFormat("MLPersistentCoordinateFrames.FindPCFsByFilter failed. Reason: {0}", MLResult.IsOK(resultCode) ? "No PCFs could be found." : MLResult.CodeToString(resultCode));
                        }

                        return(MLResult.Create(resultCode, string.Format("MLPersistentCoordinateFrames.FindPCFsByFilter failed. Reason: {0}", MLResult.IsOK(resultCode) ? "No PCFs could be found." : MLResult.CodeToString(resultCode))));
                    }
                }
                catch (EntryPointNotFoundException)
                {
                    MLPluginLog.Error("MLPersistentCoordinateFrames.FindPCFsByFilter failed. Reason: API symbols not found.");
                    return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLPersistentCoordinateFrames.FindPCFsByFilter failed. Reason: API symbols not found."));
                }
            }
            else
            {
                MLPluginLog.ErrorFormat("MLPersistentCoordinateFrames.FindPCFsByFilter failed. Reason: No Instance for MLPersistentCoordinateFrames.");
                return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLPersistentCoordinateFrames.FindPCFsByFilter failed. Reason: No Instance for MLPersistentCoordinateFrames."));
            }
        }