Ejemplo n.º 1
0
        /// <summary>
        /// Original version of compress
        /// The use of shortest path results in some drawbacks...
        /// </summary>
        /// <param name="trj"></param>
        /// <returns></returns>
        public VCompressedTrj Compress_v1(Trajectory trj)
        {
            if (trj.Count == 0)
            {
                return(null);
            }
            List <RefPoint> refPoints = getRefPoints(trj);
            VCompressedTrj  cTrj      = new VCompressedTrj();

            VCompressedTrj.Item item = new VCompressedTrj.Item();
            double dist = 0, appDist = 0;
            Edge   lastEdge = refPoints[0].e;

            item.RefPoint = refPoints[0];
            for (int i = 1; i < refPoints.Count; ++i)
            {
                RefPoint cur = refPoints[i], prev = refPoints[i - 1];
                double   distance = 0.0, v = 0;
                byte     roundV = 0, si = (byte)(cur.t - prev.t);
                if (cur.e == prev.e)
                {
                    distance = cur.distance - prev.distance;
                }
                else if (cur.e.Start == prev.e.End)
                {
                    distance = prev.e.Length - prev.distance + cur.distance;
                }
                else
                {
                    distance = prev.e.Length - prev.distance;
                    var path = _g.FindPath(prev.e.End, cur.e.Start);
                    foreach (var e in path)
                    {
                        distance += e.Length;
                    }
                    distance += cur.distance;
                }
                v        = distance / si;
                roundV   = (byte)(Math.Round(v) / _binSize);
                dist    += distance;
                appDist += roundV * si * _binSize;
                if (Math.Abs(dist - appDist) >= _maxDev)
                {
                    // insert the reference point
                    cTrj.Items.Add(item);
                    // clear
                    item          = new VCompressedTrj.Item();
                    item.RefPoint = cur;
                    dist          = 0;
                    appDist       = 0;
                }
                else
                {
                    item.Points.Add(new VCompressedMV(si, cur.eid, roundV));
                }
            }
            cTrj.Items.Add(item);
            return(cTrj);
        }
Ejemplo n.º 2
0
        public Trajectory Decompress(VCompressedTrj ctrj)
        {
            int size = ctrj.Items.Count;

            if (size <= 0)
            {
                return(null);
            }
            Trajectory trj = new Trajectory();

            // Add the first reference point
            for (int i = 0; i < size; ++i)
            {
                var    item = ctrj.Items[i];
                double dist = item.RefPoint.distance;    // distance from the start point the edge to the current point
                long   t    = item.RefPoint.t;
                // add the reference point first
                trj.Add(new MotionVector(item.RefPoint.Point, item.RefPoint.t));
                Edge lastEdge = item.RefPoint.e;
                // Calculate the position of each point
                for (int j = 0; j < item.Points.Count; ++j)
                {
                    var      cMV           = item.Points[j];
                    double   totalDistance = cMV.si * cMV.v * _binSize; // the distance covered during the interval
                    GeoPoint p             = GeoPoint.INVALID;
                    t += cMV.si;
                    if (cMV.rid == lastEdge.ID)
                    {
                        dist += totalDistance;
                        p     = lastEdge.Predict(lastEdge.Start.Point, dist);
                    }
                    else
                    {
                        Edge curEdge = _g.Edges[cMV.rid];
                        dist = totalDistance - (lastEdge.Length - dist);  // minus the distance left in the previous road
                        if (lastEdge.End == curEdge.Start)
                        {
                            p = curEdge.Predict(curEdge.Start.Point, dist);
                        }
                        else
                        {
                            var path = _g.FindPath(lastEdge.End, curEdge.Start);
                            if (path != null)
                            {
                                foreach (var e in path)
                                {
                                    dist -= e.Length;
                                }
                                p = curEdge.Predict(curEdge.Start.Point, dist);
                            }
                            else
                            {
                                Debug.Assert(false);
                            }
                        }
                        lastEdge = curEdge;
                    }
                    trj.Add(new MotionVector(p, t));
                }
            }
            return(trj);
        }