Encapsulates the object placement queries of the understanding dll. These queries will not be valid until after scanning is finalized.
        /**
         * #Companion: Clean up unnecessary meshes and components.
         */
        public void Cleanup()
        {
            // Clear ShapeDetection
            if (CompanionMR.ShapeDetection.Instance != null)
            {
                CompanionMR.ShapeDetection.Instance.ClearGeometry();
            }
            if (CompanionMR.ShapeDefinition.IsInitialized)
            {
                CompanionMR.ShapeDefinition.Instance.Clear();
            }

            // Clear PlacementSolver
            SpatialUnderstandingDllObjectPlacement.Solver_RemoveAllObjects();
            if (CompanionMR.PlacementSolver.Instance != null)
            {
                CompanionMR.PlacementSolver.Instance.Clear();
            }

            // Clear Meshes
            if (SpatialMappingManager.IsInitialized)
            {
                SpatialMappingManager.Instance.CleanupObserver();
            }
            this.UnderstandingSourceMesh.Cleanup();     // cleanup mapping mesh copies
            this.UnderstandingDLL.UnpinAllObjects();    // cleanup intern meshes
            this.UnderstandingCustomMesh.Cleanup();     // cleanup understanding meshes

            // Clear DLL
            SpatialUnderstandingDll.Imports.SpatialUnderstanding_Term();
            SpatialUnderstandingDll.Imports.SpatialUnderstanding_Init();

            // Reset SpatialUnderstanding
            this.ScanState = ScanStates.None;
        }
Example #2
0
 /**
  * Remove all placement results.
  *
  * @param removeAllObjects  indicates whether all instantiated placement results should also be removed
  */
 public void ClearGeometry(bool removeAllObjects = false)
 {
     this.placementResults.Clear();
     if (removeAllObjects && SpatialUnderstanding.IsInitialized && SpatialUnderstanding.Instance.AllowSpatialUnderstanding)
     {
         SUDLLOP.Solver_RemoveAllObjects();
     }
 }
 public PlacementQuery(
     SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition,
     List<SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule> placementRules = null,
     List<SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint> placementConstraints = null)
 {
     PlacementDefinition = placementDefinition;
     PlacementRules = placementRules;
     PlacementConstraints = placementConstraints;
 }
Example #4
0
        /**
         * Process the given placement query.
         *
         * @param placementName         placement description
         * @param placementDefinition   placement definition
         * @param placementRules        list of placement rules
         * @param placementConstraints  list of placement constraints
         * @param clearObjectsFirst     should already detected placement results should be removed
         * @param isASync               indicates whether this query is handled asynchronously
         * @param drawBox               indicates whether an animated box should be drawn around the placement result
         * @param callback              callback method
         */
        private bool PlaceObject(string placementName, SUDLLOP.ObjectPlacementDefinition placementDefinition, List <SUDLLOP.ObjectPlacementRule> placementRules = null,
                                 List <SUDLLOP.ObjectPlacementConstraint> placementConstraints = null, bool clearObjectsFirst = false, bool isASync = true, bool drawBox = true, ResponseDelegate callback = null)
        {
            // Clear objects (if requested)
            if (!isASync && clearObjectsFirst)
            {
                this.ClearGeometry();
            }

            if (!SpatialUnderstanding.IsInitialized || !SpatialUnderstanding.Instance.AllowSpatialUnderstanding)
            {
                return(false);
            }

            // Query parameters
            int placementRuleCount = (placementRules != null) ? placementRules.Count : 0;

            System.IntPtr placementRulesPtr = ((placementRules != null) && (placementRules.Count > 0))
                ? SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementRules.ToArray()) : System.IntPtr.Zero;
            int constraintCount = (placementConstraints != null) ? placementConstraints.Count : 0;

            System.IntPtr placementConstraintsPtr = ((placementConstraints != null) && (placementConstraints.Count > 0))
                ? SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementConstraints.ToArray()) : System.IntPtr.Zero;
            System.IntPtr placementResultPtr = SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResultPtr();

            // New query
            int success = SUDLLOP.Solver_PlaceObject(placementName, SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementDefinition), placementRuleCount,
                                                     placementRulesPtr, constraintCount, placementConstraintsPtr, placementResultPtr);

            if (success > 0)
            {
                SUDLLOP.ObjectPlacementResult placementResult = SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResult();
                if (!isASync)
                {
                    // If not running async, we can just add the results to the draw list right now
                    Debug.Log(placementName + " (1)");
                    float timeDelay = this.placementResults.Count * AnimatedBox.DelayPerItem;
                    this.placementResults.Add(new PlacementResult(timeDelay, placementResult.Clone() as SUDLLOP.ObjectPlacementResult, drawBox, callback));
                }
                else
                {
                    this.queryStatus.queryResult.Add(placementResult.Clone() as SUDLLOP.ObjectPlacementResult);
                }
                return(true);
            }

            if (!isASync)
            {
                Debug.Log(placementName + " (0)");
            }

            return(false);
        }
Example #5
0
        /**
         * Initialize this placement solver.
         *
         * @return <code>true</code> if the solver was initialized successfully, <code>flase</code> otherwise
         */
        public bool InitializeSolver()
        {
            if (this.IsSolverInitialized || !SpatialUnderstanding.IsInitialized || !SpatialUnderstanding.Instance.AllowSpatialUnderstanding)
            {
                return(this.IsSolverInitialized);
            }

            if (SUDLLOP.Solver_Init() == 1)
            {
                this.IsSolverInitialized = true;
            }

            return(this.IsSolverInitialized);
        }
 public PlacementResult(float timeDelay, SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult result)
 {
     Box = new AnimatedBox(timeDelay, result.Position, Quaternion.LookRotation(result.Forward, result.Up), Color.blue, result.HalfDims);
     Result = result;
 }
    private bool PlaceObject(
        string placementName,
        SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition,
        List<SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule> placementRules = null,
        List<SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint> placementConstraints = null,
        bool clearObjectsFirst = true,
        bool isASync = false)
    {
        // Clear objects (if requested)
        if (!isASync && clearObjectsFirst)
        {
            ClearGeometry();
        }
        if (!SpatialUnderstanding.Instance.AllowSpatialUnderstanding)
        {
            return false;
        }

        // New query
        if (SpatialUnderstandingDllObjectPlacement.Solver_PlaceObject(
                placementName,
                SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementDefinition),
                (placementRules != null) ? placementRules.Count : 0,
                ((placementRules != null) && (placementRules.Count > 0)) ? SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementRules.ToArray()) : IntPtr.Zero,
                (placementConstraints != null) ? placementConstraints.Count : 0,
                ((placementConstraints != null) && (placementConstraints.Count > 0)) ? SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementConstraints.ToArray()) : IntPtr.Zero,
                SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResultPtr()) > 0)
        {
            SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult placementResult = SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResult();
            if (!isASync)
            {
                // If not running async, we can just add the results to the draw list right now
                AppState.Instance.ObjectPlacementDescription = placementName + " (1)";
                float timeDelay = (float)placementResults.Count * AnimatedBox.DelayPerItem;
                placementResults.Add(new PlacementResult(timeDelay, placementResult.Clone() as SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult));
            }
            else
            {
                queryStatus.QueryResult.Add(placementResult.Clone() as SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult);
            }
            return true;
        }
        if (!isASync)
        {
            AppState.Instance.ObjectPlacementDescription = placementName + " (0)";
        }
        return false;
    }
 private bool PlaceObjectAsync(
     string placementName,
     SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition,
     List<SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule> placementRules = null,
     List<SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint> placementConstraints = null,
     bool clearObjectsFirst = true)
 {
     return PlaceObjectAsync(
         placementName,
         new List<PlacementQuery>() { new PlacementQuery(placementDefinition, placementRules, placementConstraints) },
         clearObjectsFirst);
 }