Example #1
0
        public void AddShift(float[] cursor_position, Point shift)
        {
            var closest_shifts = cache.ClosestPoints;

            if (closest_shifts != null && closest_shifts[0].distance < calibration_mode.zone_size)
            {
                cache.SaveToCache(cursor_position, closest_shifts[0].index);
                Corrections[closest_shifts[0].index] = new UserCorrection(cursor_position, shift);
                if (closest_shifts.Count > 1 && closest_shifts[1].distance < calibration_mode.zone_size)
                {
                    cache.FreeIndex(closest_shifts[1].index);
                    Corrections.RemoveAt(closest_shifts[1].index);
                }
            }
            else if (Corrections.Count() < calibration_mode.max_zones_count)
            {
                if (cache.AllocateIndex() != Corrections.Count)
                {
                    throw new Exception("Logic error");
                }
                cache.SaveToCache(cursor_position, Corrections.Count);
                Corrections.Add(new UserCorrection(cursor_position, shift));
            }
            else
            {
                var highest_density_point = GetClosestPointOfHihestDensity();
                cache.SaveToCache(cursor_position, highest_density_point);
                Corrections[highest_density_point] = new UserCorrection(cursor_position, shift);
            }

            OnShiftsChanged();
        }
        public void AddShift(float[] cursor_position, Point shift)
        {
            if (!Helpers.AreCoordinatesSane(cursor_position))
            {
                return;
            }
            cache.ChangeCursorPosition(cursor_position);
            var closest_shifts = cache.ClosestPoints;

            if (closest_shifts != null && closest_shifts[0].distance < calibration_mode.zone_size)
            {
                cache.FreeIndex(closest_shifts[0].index);
                Corrections.RemoveAt(closest_shifts[0].index);
                if (closest_shifts.Count > 1 && closest_shifts[1].distance < calibration_mode.zone_size)
                {
                    Debug.Assert(closest_shifts[1].index != closest_shifts[0].index);
                    if (closest_shifts[1].index > closest_shifts[0].index)
                    {
                        closest_shifts[1].index--;
                    }
                    cache.FreeIndex(closest_shifts[1].index);
                    Corrections.RemoveAt(closest_shifts[1].index);
                }
            }
            else if (Corrections.Count >= calibration_mode.max_zones_count)
            {
                Debug.Assert(Corrections.Count == calibration_mode.max_zones_count);
                // Remove least recently used item from the front of |Corrections|.
                cache.FreeIndex(0);
                Corrections.RemoveAt(0);
            }

            if (cache.AllocateIndex() != Corrections.Count)
            {
                throw new Exception("Logic error");
            }
            cache.SaveToCache(cursor_position, Corrections.Count);
            Corrections.Add(new EyeTrackerErrorCorrection(cursor_position, shift));

            OnShiftsChanged();
        }