/// <summary> /// Adds new points to given polyline, and truncates to <see cref="maxLengthPath"/> /// if DiscreteLength flag is set. /// </summary> /// <param name="polyline"> /// Polyline to modify /// </param> /// <param name="validSamples"> /// A <see cref="List{PointF}"/> with the new samples /// to be added to the <see cref="VGPolyline"/>. /// </param> /// <param name="discreteLength"> /// <strong>True</strong>, if path should be truncated, /// otherwise <strong>false</strong>. /// </param> /// <param name="time"> /// The <see cref="Int64"/> with the last points time. /// </param> private void AddPtsToPolyline(VGPolyline polyline, List<PointF> validSamples, bool discreteLength, long time) { // Add Point to Polyline polyline.AddPts(validSamples); polyline.EndTime = time; // Switch to fixed length if choosen in UI if (discreteLength && (polyline.GetPointCount() > this.maxLengthPath)) { polyline.RemoveFirstPts(polyline.GetPointCount() - this.maxLengthPath); } }
/// <summary> /// This static method calculates the sum of fixation connections, /// which is a gaze path length. /// </summary> /// <param name="fixationTable">A <see cref="DataTable"/> with the fixations /// to use.</param> /// <returns>A <see cref="Single"/> with the path length in pixel.</returns> private static float CalcPathLengthOfFixationConnections(DataTable fixationTable) { // Fixation PathLength // no fixation available float pathLengthGaze = -1f; VGPolyline polylineGaze = new VGPolyline(ShapeDrawAction.Edge, Pens.Green); foreach (DataRow row in fixationTable.Rows) { float gazeX = !row.IsNull("PosX") ? Convert.ToSingle(row["PosX"]) : 0; float gazeY = !row.IsNull("PosY") ? Convert.ToSingle(row["PosY"]) : 0; if (gazeX != 0 || gazeY != 0) { polylineGaze.AddPt(new PointF(gazeX, gazeY)); } } if (polylineGaze.GetPointCount() >= 2) { // Connections available pathLengthGaze = polylineGaze.GetLength(); } else if (polylineGaze.GetPointCount() == 1) { // Only one fixation, so no connections pathLengthGaze = 0; } return pathLengthGaze; }
/// <summary> /// Adds new point to given polyline, and truncates to <see cref="maxLengthPath"/> /// if DiscreteLength flag is set. /// </summary> /// <param name="polyline"> /// Polyline to modify /// </param> /// <param name="currPt"> /// new Position /// </param> /// <param name="discreteLength"> /// <strong>True</strong>, if path should be truncated, /// otherwise <strong>false</strong>. /// </param> /// <param name="time"> /// The <see cref="Int64"/> with the points time. /// </param> private void AddPtToPolyline(VGPolyline polyline, PointF currPt, bool discreteLength, long time) { // Add Point to Polyline polyline.AddPt(currPt); polyline.EndTime = time; // Switch to fixed length if choosen in UI if (discreteLength && (polyline.GetPointCount() > this.maxLengthPath)) { polyline.RemoveFirstPt(); } }
/// <summary> /// This static method calculates the raw data related variables as there /// are distance of gaze and mouse path along with loss and out of /// monitor values. /// </summary> /// <param name="subjectName">A <see cref="string"/> with the subject name.</param> /// <param name="trialSequence">An <see cref="int"/> with the trial sequence number.</param> /// <param name="countBlinkLoss">Ref. Counts the samples the are lost due to blinks.</param> /// <param name="countOutOfMonitorLoss">Ref. Counts the samples the are lost due to out of monitor samples.</param> /// <param name="pathLengthMouse">Ref. Returns the path length of the mouse path.</param> /// <param name="averageDistance">Ref. Returns the average distance of gaze and mouse path in pixel.</param> /// <param name="countSamples">Ref. Counts the number of samples.</param> private static void CalcRawDataRelatedVariables( string subjectName, int trialSequence, ref int countBlinkLoss, ref int countOutOfMonitorLoss, ref float pathLengthMouse, ref float averageDistance, ref int countSamples) { // Get RawData DataTable rawDataTable = Queries.GetRawDataBySubjectAndTrialSequenceWithoutEvents(subjectName, trialSequence); // In this section only mouse polyline is created, // because the gaze path length is calculated as the // distance between fixations to avoid // including microsaccade movements. VGPolyline polylineMouse = new VGPolyline(ShapeDrawAction.Edge, Pens.Red); float sumDistance = 0; int distancesCount = 0; // Loop RawData and drawPolyline foreach (DataRow row in rawDataTable.Rows) { PointF? newGazePoint; SampleValidity isGazeValidData = Queries.GetGazeData( row, Document.ActiveDocument.PresentationSize, out newGazePoint); switch (isGazeValidData) { case SampleValidity.Valid: break; case SampleValidity.Empty: countBlinkLoss++; break; case SampleValidity.Null: countBlinkLoss++; break; case SampleValidity.OutOfStimulus: countOutOfMonitorLoss++; break; } PointF? newMousePoint; SampleValidity isMouseValidData = Queries.GetMouseData( row, Document.ActiveDocument.PresentationSize, out newMousePoint); switch (isMouseValidData) { case SampleValidity.Valid: case SampleValidity.Empty: case SampleValidity.OutOfStimulus: // mouse is always detected and never out of screen polylineMouse.AddPt(newMousePoint.Value); break; case SampleValidity.Null: break; } // Calculate Distance of Gaze And Mouse Path if (isGazeValidData == SampleValidity.Valid && (isMouseValidData == SampleValidity.Valid || isMouseValidData == SampleValidity.Empty)) { sumDistance += VGPolyline.Distance(newGazePoint.Value, newMousePoint.Value); distancesCount++; } } if (polylineMouse.GetPointCount() >= 2) { pathLengthMouse = polylineMouse.GetLength(); } else if (polylineMouse.GetPointCount() == 1) { pathLengthMouse = 0; // No Movement in MouseData } if (distancesCount > 0) { averageDistance = sumDistance / distancesCount; } else { averageDistance = -1; } countSamples = rawDataTable.Rows.Count; rawDataTable.Dispose(); }