SDT压缩数据线性插值解压实现

public struct point
    {
        public point(double pointx, double pointy)
        {
            this.x = pointx;
            this.y = pointy;
        }
        private double x;
        private double y;
        public double X
        {
            get
            {
                return x;
            }

            set
            {
                x = value;
            }
        }
        public double Y
        {
            get
            {
                return y;
            }

            set
            {
                y = value;
            }
        }
    }
/// <summary>
        /// 线性插值解压 
        /// </summary>
        /// <param name="originData">原始数据</param>
        /// <param name="SDTData">压缩数据</param>
        /// <param name="progress">进度</param>
        /// <param name="cancel">取消</param>
        /// <returns></returns>
        public List<point> SDTUncompress(List<point> originData,List<point> SDTData,IProgress<int> progress, CancellationToken cancel)
        {
            List<point> UncompreeDate=new List<point>();
            point newPoint=new point();
            int num = 0;
            if (SDTData.Count <= 1)
                return null;
            for (int i = 0; i <SDTData.Count-1; i++)
            {
                double k = (SDTData[i + 1].Y - (SDTData[i].Y))/(SDTData[i + 1].X - (SDTData[i].X));
                int startIndex = FindIndex(originData, SDTData[i].X);
                int endIndex = FindIndex(originData, SDTData[i + 1].X);
                for (int j = startIndex; j < endIndex; j++)
                {
                    newPoint.X = originData[j].X;
                    newPoint.Y=k*(originData[j].X - SDTData[i].X)
                    +SDTData[i].Y;
                    UncompreeDate.Add(newPoint);
                    num++;
                    cancel.ThrowIfCancellationRequested();
                    progress?.Report((num * 100 / originData.Count));
                }
            }
            if(UncompreeDate.Count<originData.Count)
            {
                int startIndex1 = FindIndex(originData, SDTData.LastOrDefault().X);
                for (int j = startIndex1; j < originData.Count; j++)
                {
                    newPoint.X = originData[j].X;
                    double k = (SDTData[SDTData.Count - 1].Y - (SDTData[SDTData.Count - 2].Y)) / (SDTData[SDTData.Count - 1].X - (SDTData[SDTData.Count - 2].X));
                    newPoint.Y = k * (originData[j].X - SDTData[SDTData.Count - 1].X)
                        + SDTData[SDTData.Count - 1].Y;
                    UncompreeDate.Add(newPoint);
                    num++;
                    cancel.ThrowIfCancellationRequested();
                    progress?.Report(num * 100 / originData.Count );
                }
            }
           
            return UncompreeDate;
        }
        private int FindIndex(List<point> list,double value)
        {
            int index = list.FindIndex(s => s.X==value);
            return index;
        }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值