Beispiel #1
0

        
Beispiel #2
0
        public ProcessedObject GetObjectByGuid(Guid guid)
        {
            ProcessedObject o = null;

            foreach (var obj in detectedObjects)
            {
                if (obj.guid == guid)
                {
                    o = obj;
                }
            }
            if (o == null)
            {
                Debug.LogWarning("cannot find object with guid " + guid);
            }
            return(o);
        }
Beispiel #3
0
        void UpdateObjectList()
        {
            List <HKY.RawObject> newlyDetectedObjects = DetectObjects(croppedDistances, distanceConstrainList);

            //apply offset!===============
            if (useOffset)
            {
                foreach (var obj in newlyDetectedObjects)
                {
                    obj.position += positionOffset;
                }
            }
            //============================

            rawObjectList = new List <RawObject>(newlyDetectedObjects);

            lock (detectedObjects)
            {
                //update existing objects
                if (detectedObjects.Count != 0)
                {
                    foreach (var oldObj in detectedObjects)
                    {
                        Dictionary <RawObject, float> objectByDistance = new Dictionary <RawObject, float>();
                        //calculate all distance between existing objects and newly found objects
                        foreach (var newObj in newlyDetectedObjects)
                        {
                            float distance = Vector3.Distance(newObj.position, oldObj.position);
                            objectByDistance.Add(newObj, distance);
                        }

                        if (objectByDistance.Count <= 0)
                        {
                            oldObj.Update();
                        }
                        else
                        {
                            //find the closest new obj and check if the dist is smaller than distanceThresholdForMerge, if yes, then update oldObj's position to this newObj
                            var closest = objectByDistance.Aggregate((l, r) => l.Value < r.Value ? l : r);
                            if (closest.Value <= distanceThresholdForMerge)
                            {
                                oldObj.Update(closest.Key.position, closest.Key.size);
                                //remove the newObj that is being used
                                newlyDetectedObjects.Remove(closest.Key);
                            }
                            else
                            {
                                //this oldObj cannot find a new one that is close enough to it
                                oldObj.Update();
                            }
                        }
                    }

                    //remove all missed objects
                    for (int i = 0; i < detectedObjects.Count; i++)
                    {
                        var obj = detectedObjects[i];
                        if (obj.clear)
                        {
                            detectedObjects.RemoveAt(i);
                            if (OnLostObject != null)
                            {
                                OnLostObject(obj);
                            }
                        }
                    }

                    //create new object for those newobject that cannot find match from the old objects
                    foreach (var leftOverNewObject in newlyDetectedObjects)
                    {
                        var newbie = new ProcessedObject(leftOverNewObject.position, leftOverNewObject.size, objectPositionSmoothTime);
                        detectedObjects.Add(newbie);
                        if (OnNewObject != null)
                        {
                            OnNewObject(newbie);
                        }
                    }
                }
                else //add all raw objects into detectedObjects
                {
                    foreach (var obj in rawObjectList)
                    {
                        var newbie = new ProcessedObject(obj.position, obj.size, objectPositionSmoothTime);
                        detectedObjects.Add(newbie);
                        if (OnNewObject != null)
                        {
                            OnNewObject(newbie);
                        }
                    }
                }
            }
        }