/// <summary> /// remove the nodes in trajectory in order to for sure /// that the distance between any nodes are larger than threshold /// </summary> /// <param name="t"></param> /// <param name="threshhold"></param> /// <returns></returns> private Trajectory pruneTrajectory(Trajectory t, double threshhold = 0.1) { Trajectory xo = new Trajectory(); foreach (Point p in t) { if (xo.Count == 0) { xo.add_point(p); continue; } double mindis = 1e10; foreach (Point x in xo) { mindis = Math.Min(mindis, TBMath.distance(x, p)); } if (mindis > threshhold) xo.add_point(p); } return xo; }
private Trajectory backtrace(Point source, Point target) { int endx = d2i(target.x); int endy = d2i(target.y); int fx = 0, fy = 0; for (int step = 0; ; step++) { for (int i = -step; i <= step; i++) for (int j = -step; j <= step; j++) { if (endx + i < 0) return new Trajectory(); if (endy + j < 0) return new Trajectory(); if (endx + i >= WIDTH) return new Trajectory(); if (endy + j >= WIDTH) return new Trajectory(); if (visit[endx + i, endy + j]) { fx = endx + i; fy = endy + j; goto brk; } } } brk: Trajectory t = new Trajectory(); while (true) { if (fx == d2i(source.x) && fy == d2i(source.y)) break; t.add_point(new Point(i2d(fx), i2d(fy))); Tuple<int, int> pre = prev[fx, fy]; fx = pre.Item1; fy = pre.Item2; } Trajectory rt = new Trajectory(); for (int i = t.Count - 1; i >= 0; i--) { rt.add_point(t[i]); } return rt; }
private void loadTrajectory_obsolete() { using (StreamReader sr = new StreamReader(TBConst.trajectoryPath_obsolete + this.map_name + ".txt")) { int tot_point = 0; while (true) { if (sr.EndOfStream) break; Trajectory traj = new Trajectory(); string comment = sr.ReadLine(); //replay_id 19 user_id 1686 string line = sr.ReadLine(); // 9.8 93.15 9.9 93.0 10.05 92.8 ....... string[] sp = line.Split(' '); //for (int i = 0; i < sp.Length; i += 2) { int i = 0; double x = Convert.ToDouble(sp[i]); double y = Convert.ToDouble(sp[i + 1]); x = (x + 105) / 21 + 1; y = (y + 105) / 21 + 1; traj.add_point(new Point(x, y)); } traj.comment = comment; traj = pruneTrajectory(traj, 0.05); addToHeapmap_obsolete(traj); traj.reversed = false; trajs.Add(traj); Trajectory rev = new Trajectory(); foreach (Point p in traj) { rev.add_point(p); } rev.Reverse(); rev.reversed = true; trajs.Add(rev); tot_point += traj.Count * 2; } } }
/// <summary> /// add the trajectory to the WIDTH * WIDTH heat map /// </summary> /// <param name="traj"></param> private void addToHeapmap_obsolete(Trajectory traj) { for (int i = 1; i < traj.Count; i++) { Point p0 = traj[i - 1]; Point p1 = traj[i]; int x0 = d2i(p0.x); int y0 = d2i(p0.y); int x1 = d2i(p1.x); int y1 = d2i(p1.y); addToHeatmap(x0, y0, x1, y1); } }