private void generateSmallestEnclosingCircles() { var equiDistantStrokePoints = interpolatedStrokes.Select(s => LinearInterpolation.getEquidistantPoints(s, nAreas)).ToArray(); Areas = Enumerable.Range(0, nAreas).Select( a => new SmallestEnclosingCircle(equiDistantStrokePoints.Select(points => points[a])) ).ToArray(); }
//public override bool strokeFitsMap(Stroke s) //{ // var areaPoints = LinearInterpolation.getPointsByDistance(new LinearInterpolation(s.Points), AreaPointDistance); // return !areaPoints.Zip(areas, // (p, a) => a.PointInToleranceArea(p.X, p.Y) // ).Any(b => !b); //} public override Observation[] getSymbolTrace(BaseTrajectory s) { var strokeInterpolation = (translationInvariant) ? new LinearInterpolation(s.getInvariantPoints()) : new LinearInterpolation(s.TrajectoryPoints); var areaPoints = LinearInterpolation.getPointsByDistance(strokeInterpolation, AreaPointDistance); //ToDo: tolerate longer inputs than trained? //if (areaPoints.Length > Areas.Length) return null; //ToDo: tolerate shorter inputs? if (areaPoints.Length < Areas.Length) { return(null); } var observations = new Observation[Areas.Length + 2]; //+ GS and GE int iObs = 1; string baseSym = "S" + ID + "_A"; string symbol; long time; for (int iArea = 0; iArea < Areas.Length; iArea++) { var area = Areas[iArea]; if (iArea >= areaPoints.Length) { break; } var point = areaPoints[iArea]; if (area.PointInArea(point.X, point.Y)) { symbol = baseSym + (iArea + 1) + "_Hit"; time = point.Time; } else if (area.PointInToleranceArea(point.X, point.Y)) { symbol = baseSym + (iArea + 1) + "_Tolerance"; time = point.Time; } else { return(null); } observations[iObs++] = new Observation(symbol, time); } //GestureStart symbol observations[0] = new Observation("GestureStart", s.TrajectoryPoints[0].Time); //GestureEnd symbol observations[observations.Length - 1] = new Observation("GestureEnd", s.TrajectoryPoints[s.TrajectoryPoints.Length - 1].Time); return(observations); }
public override Observation[] getSymbolTrace(BaseTrajectory s) { int current_stroke = s.TrajectoryPoints.First().StrokeNum; var accumulate = new List <TrajectoryPoint>(); var gesture_AreaPoints = new List <TrajectoryPoint[]>(); foreach (var point in s.TrajectoryPoints) { if (point.StrokeNum == current_stroke) { accumulate.Add(point); } else { var trajectory = new LinearInterpolation(accumulate.ToArray()); gesture_AreaPoints.Add(LinearInterpolation.getEquidistantPoints(trajectory, nAreas)); accumulate.Clear(); current_stroke = point.StrokeNum; } } gesture_AreaPoints.Add(LinearInterpolation.getEquidistantPoints(new LinearInterpolation(accumulate.ToArray()), nAreas)); var symbolTrace = new Observation[Areas.Length + gesture_AreaPoints.Count]; int counter = 0; int stroke_counter = 0; foreach (var fStroke in gesture_AreaPoints) { var Areas_fraction = Areas.Skip(stroke_counter * fStroke.Length).Take(nAreas); var query = fStroke.Zip(Areas_fraction, (p, a) => { var sym = a.CreateSymbol(p); if (sym == null) { return(null); } string symbol = "S" + ID + "_" + sym; return(new Observation(symbol, p.Time)); }); //GestureStart symbol var startO = new Observation("GestureStart", s.TrajectoryPoints[0].Time); foreach (var single_observation in SingleItemAsEnumerable(startO).Concat(query.TakeWhile(o => o != null)).ToArray()) { symbolTrace[counter] = single_observation; counter++; } stroke_counter++; } //wurden alle Areas erwischt? if (symbolTrace.Length < Areas.Length) { return(null); } return(symbolTrace); }
private void generateSmallestEnclosingCircles() { var areaPointsPerStroke = interpolatedStrokes.Select(s => LinearInterpolation.getPointsByDistance(s, AreaPointDistance)).ToArray(); //var maxNArea = areaPointsPerStroke.Max(areaPoints => areaPoints.Length); //Areas = Enumerable.Range(0, maxNArea).Select( // a => new SmallestEnclosingCircle(areaPointsPerStroke.Where(points => points.Length > a).Select(points => points[a])) //Where was added here due to different area counts // ).ToArray(); var minNArea = areaPointsPerStroke.Min(areaPoints => areaPoints.Length); Areas = Enumerable.Range(0, minNArea).Select( a => new SmallestEnclosingCircle(areaPointsPerStroke.Select(points => points[a])) ).ToArray(); }
public override Observation[] getSymbolTrace(BaseTrajectory s) { var strokeInterpolation = (translationInvariant) ? new LinearInterpolation(s.getInvariantPoints()) : new LinearInterpolation(s.TrajectoryPoints); var areaPoints = LinearInterpolation.getEquidistantPoints(strokeInterpolation, Areas.Length); int counter = 1; var query = areaPoints.Zip(Areas, (p, a) => { string sym = "S" + ID + "_A"; long time; if (a.PointInArea(p.X, p.Y)) { sym += counter++ + "_Hit"; time = p.Time; } else if (a.PointInToleranceArea(p.X, p.Y)) { sym += counter++ + "_Tolerance"; time = p.Time; } else { return(null); } return(new Observation(sym, time)); }); //GestureStart symbol var startO = new Observation("GestureStart", s.TrajectoryPoints[0].Time); var symbolTrace = SingleItemAsEnumerable(startO).Concat(query.TakeWhile(o => o != null)).ToArray(); //wurden alle Areas erwischt? if (symbolTrace.Length < Areas.Length) { return(null); } return(symbolTrace); }
public FixedAreaNumberStrokeMap(BaseTrajectory[] srcStrokes) : base(srcStrokes) { int current_stroke = 0; int total_strokes = srcStrokes.First().TrajectoryPoints.Last().StrokeNum; var accumulate = new List <TrajectoryPoint>(); var gesture = new List <TrajectoryPoint[][]>(); var gesture_equidistant = new List <TrajectoryPoint[]>(); foreach (var execution in srcStrokes) { foreach (var point in execution.TrajectoryPoints) { if (point.StrokeNum == current_stroke) { accumulate.Add(point); } else { var trajectory = new LinearInterpolation(accumulate.ToArray()); gesture_equidistant.Add(LinearInterpolation.getEquidistantPoints(trajectory, nAreas)); accumulate.Clear(); current_stroke++; if (current_stroke > total_strokes) { gesture.Add(gesture_equidistant.ToArray()); gesture_equidistant.Clear(); current_stroke = 0; } } } } gesture_equidistant.Add(LinearInterpolation.getEquidistantPoints(new LinearInterpolation(accumulate.ToArray()), nAreas)); gesture.Add(gesture_equidistant.ToArray()); int total_areas = nAreas * (total_strokes + 1); Areas = new Area[total_areas]; Strokes = total_strokes + 1; List <TrajectoryPoint>[] arrayList = new List <TrajectoryPoint> [total_areas]; for (int i = 0; i < total_areas; i++) { arrayList[i] = new List <TrajectoryPoint>(); } foreach (var gesture_stroke in gesture) { int counter = 0; for (int b = 0; b <= total_strokes; b++) { for (int a = 0; a < nAreas; a++) { arrayList[counter].Add(gesture_stroke[b][a]); counter++; } } } for (int a = 0; a < total_areas; a++) { Areas[a] = createArea(a, arrayList[a]); } }