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;
}