public Eye(Eye other) { if (null != other) { RawCoordinates = new Point2D(other.RawCoordinates); SmoothedCoordinates = new Point2D(other.SmoothedCoordinates); PupilCenterCoordinates = new Point2D(other.PupilCenterCoordinates); PupilSize = other.PupilSize; } }
public GazeData(GazeData other) { if (null != other) { State = other.State; TimeStamp = other.TimeStamp; TimeStampString = other.TimeStampString; RawCoordinates = new Point2D(other.RawCoordinates); SmoothedCoordinates = new Point2D(other.SmoothedCoordinates); LeftEye = new Eye(other.LeftEye); RightEye = new Eye(other.RightEye); IsFixated = other.IsFixated; } }
public Point2D(Point2D other) : this(other.x, other.y) { }
public Point2D Subtract(Point2D p2) { return new Point2D(x - p2.x, y - p2.y); }
public Point2D Add(Point2D p2) { return new Point2D(x + p2.x, y + p2.y); }
private void Set(GazeData other) { State = other.State; TimeStamp = other.TimeStamp; TimeStampString = other.TimeStampString; RawCoordinates = new Point2D(other.RawCoordinates); SmoothedCoordinates = new Point2D(other.SmoothedCoordinates); LeftEye = new Eye(other.LeftEye); RightEye = new Eye(other.RightEye); IsFixated = other.IsFixated; }
/// <summary> /// Clamps a gaze points within the limits of the parameter rect. /// </summary> /// <param name="gaze">gaze data frame to base calculation upon</param> /// <param name="dimX">x coordinate of topleft rect anchor</param> /// <param name="dimY">y coordinate of topleft rect anchor</param> /// <param name="dimWidth">dimension width to base calculation upon</param> /// <param name="dimHeight">dimension height to base calculation upon</param> /// <param name="clampMargin">extra space surrounding rect to be included</param> /// <returns>clamped gaze point</returns> public static Point2D ClampGazeToRect(Point2D gaze, int dimWidth, int dimHeight, float clampMargin) { return ClampGazeToRect(gaze, 0, 0, dimWidth, dimHeight, clampMargin, clampMargin); }
/// <summary> /// Clamps a gaze points within the limits of the parameter rect. /// </summary> /// <param name="gaze">gaze data frame to base calculation upon</param> /// <param name="dimX">x coordinate of topleft rect anchor</param> /// <param name="dimY">y coordinate of topleft rect anchor</param> /// <param name="dimWidth">dimension width to base calculation upon</param> /// <param name="dimHeight">dimension height to base calculation upon</param> /// <param name="clampHorsMargin">extra hors space surrounding rect to be included</param> /// <param name="clampVertMargin">extra vert space surrounding rect to be included</param> /// <returns>clamped gaze point</returns> public static Point2D ClampGazeToRect(Point2D gaze, int dimX, int dimY, int dimWidth, int dimHeight, float clampHorsMargin, float clampVertMargin) { Point2D clamped = new Point2D(gaze); if (null != gaze) { if (gaze.X < dimX && gaze.X > dimX - clampHorsMargin) clamped.X = dimX + 1; if(gaze.X > dimX + dimWidth && gaze.X < (dimX + dimWidth + clampHorsMargin)) clamped.X = dimX + dimWidth - 1; if (gaze.Y < dimY && gaze.Y > dimY - clampVertMargin) clamped.Y = dimY + 1; if (gaze.Y > dimY + dimHeight && gaze.Y < (dimY + dimHeight + clampVertMargin)) clamped.Y = dimY + dimHeight - 1; } return clamped; }
/// <summary> /// Converts a 2d screen point in pixels to normalized relative values based on parameter dimensions. /// </summary> /// <param name="point">gaze point to base calculation upon</param> /// <param name="dimWidthPix">dimension width in pixels to base calculation upon</param> /// <param name="dimHeightPix">dimension height in pixels to base calculation upon</param> /// <returns>2D point in relative values</returns> public static Point2D GetScreenSpaceToRelative(Point2D point, int dimWidthPix, int dimHeightPix) { return new Point2D( point.X / GazeManager.Instance.ScreenResolutionWidth, point.Y / GazeManager.Instance.ScreenResolutionHeight ); }
/// <summary> /// Clamps a gaze points within the limits of the parameter rect. /// </summary> /// <param name="gaze">gaze data frame to base calculation upon</param> /// <param name="dimX">x coordinate of topleft rect anchor</param> /// <param name="dimY">y coordinate of topleft rect anchor</param> /// <param name="dimWidth">dimension width to base calculation upon</param> /// <param name="dimHeight">dimension height to base calculation upon</param> /// <returns>clamped gaze point</returns> public static Point2D ClampGazeToRect(Point2D gaze, int dimX, int dimY, int dimWidth, int dimHeight) { return ClampGazeToRect(gaze, dimX, dimY, dimWidth, dimHeight, 0, 0); }
/// <summary> /// Converts a 2d point in relative values to a coordinate within parameter dimensions. /// <para/> /// Use to map relative values [0f..1f] to screen coordinates. /// </summary> /// <param name="point">gaze point to base calculation upon</param> /// <param name="dimWidthPix">dimension width in pixels to base calculation upon</param> /// <param name="dimHeightPix">dimension height in pixels to base calculation upon</param> /// <returns>2D point in screen space</returns> public static Point2D GetRelativeToScreenSpace(Point2D point, int dimWidthPix, int dimHeightPix) { return new Point2D( point.X * dimWidthPix, point.Y * dimHeightPix ); }
/// <summary> /// Maps a 2d pixel point into normalized space [x: -1:1 , y: -1:1] /// </summary> /// <param name="point">point in pixels to normalize</param> /// <param name="screenWidth">the width value to base normalization upon</param> /// <param name="screenHeight">the height value to base normalization upon</param> /// <returns>normalized 2d point</returns> public static Point2D GetNormalizedMapping(Point2D point, int screenWidth, int screenHeight) { Point2D normMap = GetNormalizedCoords(point, screenWidth, screenHeight); //scale up and shift normMap.X *= 2f; normMap.X -= 1f; normMap.Y *= 2f; normMap.Y -= 1f; return normMap; }
/// <summary> /// Normalizes a pixel point based on screen dims /// </summary> /// <param name="point">point in pixels to normalize</param> /// <param name="screenWidth">the width value to base normalization upon</param> /// <param name="screenHeight">the height value to base normalization upon</param> /// <returns>normalized 2d point</returns> public static Point2D GetNormalizedCoords(Point2D point, int screenWidth, int screenHeight) { return new Point2D(point.X /= screenWidth, point.Y /= screenHeight); }
/// <summary> /// Find average pupil center of two eyes. /// </summary> /// <param name="leftEye"></param> /// <param name="rightEye"></param> /// <returns>the average center point in normalized values</returns> public static Point2D GetEyesCenterNormalized(Eye leftEye, Eye rightEye) { Point2D eyeCenter = Point2D.Zero; if (null != leftEye && null != rightEye) { eyeCenter = new Point2D( (leftEye.PupilCenterCoordinates.X + rightEye.PupilCenterCoordinates.X) / 2, (leftEye.PupilCenterCoordinates.Y + rightEye.PupilCenterCoordinates.Y) / 2 ); } else if (null != leftEye) { eyeCenter = leftEye.PupilCenterCoordinates; } else if (null != rightEye) { eyeCenter = rightEye.PupilCenterCoordinates; } return eyeCenter; }
/// <summary> /// Calculates distance between two points. /// </summary> public static double GetDistancePoint2D(Point2D a, Point2D b) { return Math.Sqrt(Math.Pow(a.X - b.X, 2) + Math.Pow(a.Y - b.Y, 2)); }