Example #1
0
        private float[,] MSpointSet3DToArray(MSPointSet3D mspointset, RegionSize PaintRegion)
        {
            RegionSize pointSetRegion = new RegionSize(mspointset.MinX, mspointset.MaxX, mspointset.MaxY, mspointset.MinY);

            float[,] Data    = new float[(int)PaintRegion.Width + 1, (int)PaintRegion.Height + 1];
            int[,] DataCount = new int[(int)PaintRegion.Width + 1, (int)PaintRegion.Height + 1];
            for (int i = 0; i < (int)PaintRegion.Width + 1; i++)
            {
                for (int j = 0; j < (int)PaintRegion.Height + 1; j++)
                {
                    Data[i, j]      = -1;
                    DataCount[i, j] = 0;
                }
            }

            //foreach (MSPoint3D point3D in mspointset.Points3D)
            for (int i = 0; i < mspointset.Count; i++)
            {
                if (DataCount[(int)Math.Round(CoordinateTrans.TimeToX(pointSetRegion, PaintRegion, mspointset.X(i))), (int)Math.Round(CoordinateTrans.MassToY(pointSetRegion, PaintRegion, mspointset.Y(i)))] == 0)
                {
                    Data[(int)Math.Round(CoordinateTrans.TimeToX(pointSetRegion, PaintRegion, mspointset.X(i))), (int)Math.Round(CoordinateTrans.MassToY(pointSetRegion, PaintRegion, mspointset.Y(i)))] = mspointset.Z(i);
                    DataCount[(int)Math.Round(CoordinateTrans.TimeToX(pointSetRegion, PaintRegion, mspointset.X(i))), (int)Math.Round(CoordinateTrans.MassToY(pointSetRegion, PaintRegion, mspointset.Y(i)))]++;
                }
                else
                {
                    Data[(int)Math.Round(CoordinateTrans.TimeToX(pointSetRegion, PaintRegion, mspointset.X(i))), (int)Math.Round(CoordinateTrans.MassToY(pointSetRegion, PaintRegion, mspointset.Y(i)))] += mspointset.Z(i);
                    DataCount[(int)Math.Round(CoordinateTrans.TimeToX(pointSetRegion, PaintRegion, mspointset.X(i))), (int)Math.Round(CoordinateTrans.MassToY(pointSetRegion, PaintRegion, mspointset.Y(i)))]++;
                }
            }
            for (int i = 0; i < (int)PaintRegion.Width + 1; i++)
            {
                for (int j = 0; j < (int)PaintRegion.Height + 1; j++)
                {
                    if (Data[i, j] != -1)
                    {
                        Data[i, j] = Data[i, j] / DataCount[i, j];
                    }
                }
            }
            return(Data);
        }
Example #2
0
        //public MSPointSet Resize(float width, float height)
        //{
        //    MSPointSet mspoint = new MSPointSet();

        //    return mspoint;
        //}

        public void ImageDraw(Graphics g, RegionSize PictureBoxRegion)
        {
            if (PictureBoxRegion.Width * PictureBoxRegion.Height == 0)
            {
                //Message = "The data you selected aren't enough for drawing, please reselect again.";
                return;
            }
            //Plot Size
            X_start = 60;
            Y_start = PictureBoxRegion.TopBound - 40;
            X_end   = PictureBoxRegion.RightBound - 150;
            Y_end   = 60;

            X_max = MyCurrentPointSet3D.MaxXwWhiteBoarder;
            X_min = MyCurrentPointSet3D.MinXwWhiteBoarder;
            Y_max = MyCurrentPointSet3D.MaxYwWhiteBoarder;
            Y_min = MyCurrentPointSet3D.MinYwWhiteBoarder;
            Z_max = MyCurrentPointSet3D.MaxZ;
            Z_min = MyCurrentPointSet3D.MinZ;

            if (IsScaled)
            {
                Z_max = ScaleMax;
                Z_min = ScaleMin;
            }


            point_size = Math.Min(PictureBoxRegion.Width / 300, PictureBoxRegion.Height / 300);

            SolidBrush RedBrush   = new SolidBrush(Color.Red);
            SolidBrush BlackBrush = new SolidBrush(Color.Black);
            Pen        BlackPen   = new Pen(Color.Black);
            Pen        RedPen     = new Pen(Color.Red, 3);


            Pen PrecursorPen = null;

            if (IsGray)
            {
                PrecursorPen = new Pen(Color.FromArgb(90, 0, 0, 255));
            }
            if (IsColor)
            {
                PrecursorPen = new Pen(Color.Black);
            }
            Font font8Bold    = new Font("Time New Roman", 8, FontStyle.Bold);
            Font font8Regular = new Font("Time New Roman", 8, FontStyle.Regular);

            //PrecursorL = (float)(Y_start - ((MyChargeQuant.MyCharge.LightReagent.MsChart.PrecursorMZ - Y_min) * Math.Abs(Y_end - Y_start) / (Y_max - Y_min)));
            //PrecursorH = (float)(Y_start - ((MyChargeQuant.MyCharge.HeavyReagent.MsChart.PrecursorMZ - Y_min) * Math.Abs(Y_end - Y_start) / (Y_max - Y_min)));

            int X_tag_number = 10;
            int Y_tag_number = 10;

            int color_shift = 20;
            int Rc, Gc, Bc;

            Rc = Bc = Gc = 0;
            float[] X_tag = new float[X_tag_number];
            float[] Y_tag = new float[Y_tag_number];
            float[] X_co  = new float[X_tag_number];
            float[] Y_co  = new float[Y_tag_number];
            float[] Z_tag = new float[color_number];


            g.DrawLine(BlackPen, X_start, Y_start, X_end, Y_start);                                                                           //Draw X_axis
            g.DrawLine(BlackPen, X_start, Y_start, X_start, Y_end);                                                                           //Draw Y_axis
            g.DrawString("Elution time (Min)", font8Regular, BlackBrush, X_end, (Y_start + 5));                                               //Draw Text(X_axis)
            g.DrawString("m/z (Da)", font8Regular, BlackBrush, (X_start - 30), (Y_end - 20));                                                 //Draw Text(X_axis)
            g.DrawString("Intensity", font8Regular, BlackBrush, (X_end + 40), (Y_start - 50));                                                //Draw Text(X_axis)
            g.DrawString(Convert.ToString((int)Z_max), font8Regular, BlackBrush, (X_end + 80), (Y_start - 55 - (color_number * point_size))); // Intensity Max
            g.DrawString(Convert.ToString((int)Z_min), font8Regular, BlackBrush, (X_end + 80), (Y_start - 65));                               // Intensity Min
            // g.DrawString("Spectrum number: " + MyChargeQuant.MyCharge.MyPeptideIdentification.SpecNumber + ", " + MyChargeQuant.MyCharge.MyPeptideIdentification.ModifiedPeptideSequence, font8Regular, BlackBrush, 5, 5);
            //g.DrawString("Charge state: +" + MyChargeQuant.MyCharge.ChargeNo, font8Regular, BlackBrush, 5, 20);


            //Color Bar
            for (int i = 0; i < color_number; i++)
            {
                if (IsGray)
                {
                    Rc = color_number - 1 - i + color_shift;
                    Gc = color_number - 1 - i + color_shift;
                    Bc = color_number - 1 - i + color_shift;
                }
                if (IsColor)
                {
                    Rc = palette[(color_number - 1 - i), 0];
                    Gc = palette[(color_number - 1 - i), 1];
                    Bc = palette[(color_number - 1 - i), 2];
                }
                SolidBrush peletteBrush = new SolidBrush(Color.FromArgb(Rc, Gc, Bc));
                RectangleF Rt           = new RectangleF(X_end + 60, (Y_start - 55 - (i * point_size)), 15, point_size);
                g.FillRectangle(peletteBrush, Rt);
            }

            //X_axis number
            for (int i = 0; i < X_tag_number; i++)
            {
                X_tag[i] = (float)Math.Round((X_min + (((X_max - X_min) / X_tag_number) * i)), 2);
                X_co[i]  = (float)(X_start + ((Math.Abs((X_end - X_start)) / X_tag_number) * i));

                g.DrawString(Convert.ToString(X_tag[i]), font8Regular, BlackBrush, X_co[i] - 10, (Y_start + 15));//Draw Text(X_start)
            }

            //Y_axis number
            for (int i = 0; i < Y_tag_number; i++)
            {
                Y_tag[i] = (float)Math.Round((Y_min + (((Y_max - Y_min) / Y_tag_number) * i)), 2);
                Y_co[i]  = (float)(Y_start - ((Math.Abs((Y_end - Y_start)) / Y_tag_number) * i));
                g.DrawString(Convert.ToString(Y_tag[i]), font8Regular, BlackBrush, (X_start - 45), Y_co[i] - 10);
            }

            for (int i = 0; i < color_number; i++)
            {
                Z_tag[i] = (float)(Z_min + (((Z_max - Z_min) / color_number) * i));
            }

            if (renew_plot)
            {
                bitmap1 = new Bitmap((int)BmpRegion.RightBound + 1, (int)BmpRegion.TopBound + 1, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

                int temp_z = 0;

                Graphics bitmapG = Graphics.FromImage(bitmap1);
                bitmapG.Clear(Color.White);

                float temp_x, temp_y;
                temp_x = temp_y = temp_z = 0;

                RegionSize DataRegion = new RegionSize(MyCurrentPointSet3D.MinXwWhiteBoarder, MyCurrentPointSet3D.MaxXwWhiteBoarder, MyCurrentPointSet3D.MaxYwWhiteBoarder, MyCurrentPointSet3D.MinYwWhiteBoarder);

                if (DataRegion.Width * DataRegion.Height == 0)
                {
                    return;
                }
                //foreach (MSPoint3D p in MyCurrentPointSet3D.Points3D)
                for (int x = 0; x < MyCurrentPointSet3D.Count; x++)
                {
                    if (MyCurrentPointSet3D.Z(x) == -1)
                    {
                        Rc = 255;
                        Gc = 255;
                        Bc = 255;
                    }
                    else
                    {
                        for (int i = 0; i < color_number; i++)
                        {
                            if (MyCurrentPointSet3D.Z(x) >= Z_tag[i])
                            {
                                temp_z = i;
                            }
                            else
                            {
                                if (i == 0)
                                {
                                    temp_z = 0;
                                }
                                break;
                            }
                        }
                        if (IsGray)
                        {
                            IsColor = false;
                            Rc      = color_number - 1 - temp_z + color_shift;
                            Gc      = color_number - 1 - temp_z + color_shift;
                            Bc      = color_number - 1 - temp_z + color_shift;
                        }

                        if (IsColor)
                        {
                            Rc = palette[color_number - 1 - temp_z, 0];
                            Gc = palette[color_number - 1 - temp_z, 1];
                            Bc = palette[color_number - 1 - temp_z, 2];
                        }
                    }

                    bitmap1.SetPixel((int)Math.Round(CoordinateTrans.TimeToX(DataRegion, BmpRegion, MyCurrentPointSet3D.X(x))),
                                     (int)BmpRegion.Height - (int)Math.Round(CoordinateTrans.MassToY(DataRegion, BmpRegion, MyCurrentPointSet3D.Y(x))),
                                     Color.FromArgb(Rc, Gc, Bc));
                    renew_plot = false;
                }
            }

            g.DrawImage(bitmap1, X_start + 1, Y_end, X_end - X_start, Y_start - Y_end);


            for (int i = 0; i < X_tag_number; i++)
            {
                g.DrawLine(BlackPen, X_co[i], Y_start, X_co[i], Y_start - 5);
            }

            for (int i = 0; i < Y_tag_number; i++)
            {
                g.DrawLine(BlackPen, X_start, Y_co[i], X_start + 5, Y_co[i]);
            }

            //PrecursorPen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot;

            //g.DrawLine(PrecursorPen, X_start, PrecursorL, X_end, PrecursorL);
            //g.DrawLine(PrecursorPen, X_start, PrecursorH, X_end, PrecursorH);

            //SolidBrush Precursorbrush = new SolidBrush(Color.Red);
            //Font font2 = new Font("Time New Roman", 8, FontStyle.Bold);
            //g.DrawString("L: " + Math.Round(MyChargeQuant.MyCharge.LightReagent.MsChart.PrecursorMZ, 2)+" Da", font2, Precursorbrush, X_end + 5, PrecursorL - 10);
            //g.DrawString("H: " + Math.Round(MyChargeQuant.MyCharge.HeavyReagent.MsChart.PrecursorMZ, 2)+" Da", font2, Precursorbrush, X_end + 5, PrecursorH - 10);
            //if (MyChargeQuant.MyCharge.Heavy2Reagent != null)
            //{
            //    g.DrawString("H: " + Math.Round(MyChargeQuant.MyCharge.Heavy2Reagent.MsChart.PrecursorMZ, 2) + " Da", font2, Precursorbrush, X_end + 5, MyChargeQuant.MyCharge.Heavy2Reagent.MsChart.PrecursorMZ - 10);
            //}

            //Pen TimePen = new Pen(Color.Red);
            //SolidBrush brush3 = new SolidBrush(Color.Red);
            //TimePen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot;
            //float Time = (float)(X_start + ((MyChargeQuant.MyCharge.MyPeptideIdentification.ElutionTime - X_min) * Math.Abs(X_end - X_start) / (X_max - X_min)));
            //g.DrawLine(TimePen, Time, Y_start, Time, Y_end);

            //g.DrawString("" + Math.Round(MyChargeQuant.MyCharge.MyPeptideIdentification.ElutionTime, 2), font2, brush3, Time - 5, Y_end-15);
            //g.DrawString("Elution Time:", font2, brush3, Time-10, (Y_end - 25));
        }
Example #3
0
        public MSPointSet BSpline2D(MSPointSet argPointset2D, RegionSize argPointSetRegion, RegionSize argTargetRegion)
        {
            MSPointSet interpolatedPointSet = new MSPointSet();
            int        NoExist  = argPointset2D.Count;
            int        NoPoints = (int)(argTargetRegion.Width);

            int degree = 2;

            float[] Tk = new float[NoExist];
            float[,] point_exist = new float[NoExist, 2];
            float[] Uk  = new float[NoExist + degree + 1];
            float[] sum = new float[NoExist];
            float[,] Nk = new float[NoExist, NoExist];
            float[,] P  = new float[NoExist, 2];
            float[] P_temp = new float[NoExist];
            float[] points = new float[NoPoints + 1];

            for (int i = 0; i < NoPoints; i++)
            {
                points[i] = -1;
            }
            for (int i = 0; i < argPointset2D.Count; i++)
            {
                points[(int)Math.Round(CoordinateTrans.TimeToX(argPointSetRegion, argTargetRegion, argPointset2D.X(i)))] = argPointset2D.Y(i);
            }

            if (NoExist <= 3)
            {
                for (int i = 0; i < NoPoints; i++)
                {
                    if (points[i] == -1)
                    {
                        points[i] = 0;
                    }
                }
            }
            else
            {
                int cnt = 0;
                for (int i = 0; i < NoPoints; i++)
                {
                    if (points[i] != -1)
                    {
                        point_exist[cnt, 0] = i;
                        point_exist[cnt, 1] = points[i];
                        cnt++;
                    }
                }
                sum[0] = 0;
                for (int i = 1; i < NoExist; i++)
                {
                    sum[i] = sum[i - 1] + (float)Math.Pow((Math.Abs(point_exist[i, 0] - point_exist[i - 1, 0]) * Math.Abs(point_exist[i - 1, 0] - point_exist[i, 0]) + Math.Abs(point_exist[i - 1, 1] - point_exist[i, 1]) * Math.Abs(point_exist[i - 1, 1] - point_exist[i, 1])), 0.5);
                }
                Tk[0] = 0;
                for (int i = 1; i < NoExist; i++)
                {
                    Tk[i] = sum[i] / sum[NoExist - 1];
                }

                for (int i = 0; i < NoExist + degree + 1; i++)
                {
                    if (i <= degree)
                    {
                        Uk[i] = 0;
                    }
                    if (i > degree && i < NoExist)
                    {
                        Uk[i] = 0;
                        for (int j = i - degree; j < i; j++)
                        {
                            Uk[i] += Tk[j];
                        }
                        Uk[i] /= degree;
                    }
                    if (i >= NoExist)
                    {
                        Uk[i] = 1;
                    }
                }
                float[,] Temp = new float[NoExist, NoExist + 1];

                for (int i = 0; i < NoExist; i++)
                {
                    float[] Nk_temp = new float[NoExist];
                    for (int j = 0; j < NoExist; j++)
                    {
                        Nk_temp[j] = 0;
                    }
                    Compute_Nk_fast(Nk_temp, NoExist, degree, Tk[i], Uk);

                    for (int j = 0; j < NoExist; j++)
                    {
                        Nk[i, j] = Nk_temp[j];
                    }
                }

                for (int n = 0; n < 2; n++)
                {
                    for (int i = 0; i < NoExist; i++)
                    {
                        for (int j = 0; j < NoExist; j++)
                        {
                            Temp[i, j] = Nk[i, j];
                        }
                    }

                    for (int i = 0; i < NoExist; i++)
                    {
                        Temp[i, NoExist] = point_exist[i, n];
                        P_temp[i]        = 0;
                    }
                    Gaussian_eliminate(Temp, NoExist, ref P_temp);

                    for (int i = 0; i < NoExist; i++)
                    {
                        P[i, n] = P_temp[i];
                    }
                }

                int PredictNo = NoPoints * 10;
                float[,] points_temp = new float[NoPoints, 2];
                for (int i = 0; i < NoPoints; i++)
                {
                    points_temp[i, 0] = 0;
                    points_temp[i, 1] = 0;
                }
                for (int i = 0; i < PredictNo; i++)
                {
                    float   temp_x  = 0;
                    float   temp_y  = 0;
                    float[] Nk_temp = new float[NoExist];

                    for (int j = 0; j < NoExist; j++)
                    {
                        Nk_temp[j] = 0;
                    }
                    Compute_Nk_fast(Nk_temp, NoExist, degree, ((float)1 / PredictNo) * i, Uk);

                    for (int j = 0; j < NoExist; j++)
                    {
                        temp_x += Nk_temp[j] * P[j, 0];
                        temp_y += Nk_temp[j] * P[j, 1];
                    }


                    if (temp_x < 0)
                    {
                        temp_x = 0;
                    }
                    if (temp_y < 0)
                    {
                        temp_y = 0;
                    }
                    if ((int)Math.Round(temp_x) <= NoPoints - 1)
                    {
                        if (points[(int)Math.Round(temp_x)] == -1)
                        {
                            if (temp_y > points_temp[(int)Math.Round(temp_x), 0])
                            {
                                points_temp[(int)Math.Round(temp_x), 0] = temp_y;
                            }
                        }
                    }
                }

                points = linearInterpolation(points);
            }

            for (int i = 0; i < NoPoints; i++)
            {
                interpolatedPointSet.Add(CoordinateTrans.XToTime(argTargetRegion, argPointSetRegion, i), points[i]);
            }

            return(interpolatedPointSet);
        }
Example #4
0
        public MSPointSet3D BSpline3DofPepImage(MSPointSet3D mspointset, RegionSize PaintRegion)
        {
            MSPointSet3D interpolatedPointSet3D = new MSPointSet3D();
            RegionSize   pointSetRegion         = new RegionSize(mspointset.MinX, mspointset.MaxX, mspointset.MaxY, mspointset.MinY);

            if (pointSetRegion.Width * pointSetRegion.Height * PaintRegion.Width * PaintRegion.Height == 0)
            {
                return(mspointset);
            }
            float[,] Data;
            Data = MSpointSet3DToArray(mspointset, PaintRegion);

            for (int i = 0; i < (int)PaintRegion.Width + 1; i++)
            {
                MSPointSet pointset2D   = new MSPointSet();
                float      MaxIntensity = -1;
                bool       empty        = true;

                for (int j = 0; j < (int)PaintRegion.Height + 1; j++)
                {
                    if (Data[i, j] != -1)
                    {
                        empty = false;
                        if (Data[i, j] > MaxIntensity)
                        {
                            MaxIntensity = Data[i, j];
                        }
                    }
                }

                if (empty == false)
                {
                    for (int j = 0; j < (int)PaintRegion.Height + 1; j++)
                    {
                        if (Data[i, j] == -1)
                        {
                            Data[i, j] = 0;
                        }
                    }
                }
            }

            for (int i = 0; i < (int)PaintRegion.Height + 1; i++)
            {
                MSPointSet pointset2D   = new MSPointSet();
                float      MaxIntensity = 0;
                for (int j = 0; j < (int)PaintRegion.Width + 1; j++)
                {
                    if (Data[j, i] > MaxIntensity)
                    {
                        MaxIntensity = Data[j, i];
                    }
                }
                if (MaxIntensity > 0 /*mspointset.MaxZ/1*/)
                {
                    for (int j = 0; j < (int)PaintRegion.Width + 1; j++)
                    {
                        if (Data[j, i] != -1)
                        {
                            pointset2D.Add(CoordinateTrans.XToTime(PaintRegion, pointSetRegion, j), Data[j, i]);
                        }
                    }
                    pointset2D = BSpline2D(pointset2D, pointSetRegion, PaintRegion, "horizontal");

                    for (int x = 0; x < pointset2D.Count; x++)
                    {
                        if (Data[(int)Math.Round((CoordinateTrans.TimeToX(pointSetRegion, PaintRegion, pointset2D.X(x)))), i] == -1)
                        {
                            Data[(int)Math.Round((CoordinateTrans.TimeToX(pointSetRegion, PaintRegion, pointset2D.X(x)))), i] = pointset2D.Y(x);
                        }
                    }
                }
                else
                {
                    for (int j = 0; j < (int)PaintRegion.Width + 1; j++)
                    {
                        if (Data[j, i] == -1)
                        {
                            Data[j, i] = 0;
                        }
                    }
                }
            }

            Data = NoiseFiltering(Data, (int)PaintRegion.Height + 1, (int)PaintRegion.Width + 1);

            for (int i = 0; i < (int)PaintRegion.Width + 1; i++)
            {
                for (int j = 0; j < (int)PaintRegion.Height + 1; j++)
                {
                    if (Data[i, j] != -1)
                    {
                        interpolatedPointSet3D.Add(CoordinateTrans.XToTime(PaintRegion, pointSetRegion, i), CoordinateTrans.YToMass(PaintRegion, pointSetRegion, j), Data[i, j]);
                    }
                    else
                    {
                        interpolatedPointSet3D.Add(CoordinateTrans.XToTime(PaintRegion, pointSetRegion, i), CoordinateTrans.YToMass(PaintRegion, pointSetRegion, j), 0);
                    }
                }
            }
            return(interpolatedPointSet3D);
        }
Example #5
0
        public MSPointSet BSpline2D(MSPointSet pointset2D, RegionSize pointSetRegion, RegionSize targetRegion, string type)
        {
            MSPointSet interpolatedPointSet = new MSPointSet();
            int        NoExist  = pointset2D.Count;
            int        NoPoints = 0;

            if (type == "horizontal")
            {
                NoPoints = (int)(targetRegion.Width);
            }
            if (type == "vertical")
            {
                NoPoints = (int)(targetRegion.Height);
            }
            int degree = 2;

            float[] Tk = new float[NoExist];
            float[,] point_exist = new float[NoExist, 2];
            float[] Uk  = new float[NoExist + degree + 1];
            float[] sum = new float[NoExist];
            float[,] Nk = new float[NoExist, NoExist];
            float[,] P  = new float[NoExist, 2];
            float[] P_temp = new float[NoExist];
            float[] points = new float[NoPoints + 1];

            for (int i = 0; i < NoPoints; i++)
            {
                points[i] = -1;
            }
            for (int i = 0; i < pointset2D.Count; i++)
            {
                if (type == "horizontal")
                {
                    points[(int)Math.Round(CoordinateTrans.TimeToX(pointSetRegion, targetRegion, pointset2D.X(i)))] = pointset2D.Y(i);
                }
                if (type == "vertical")
                {
                    points[(int)Math.Round(CoordinateTrans.MassToY(pointSetRegion, targetRegion, pointset2D.X(i)))] = pointset2D.Y(i);
                }
            }

            if (NoExist <= 3)
            {
                for (int i = 0; i < NoPoints; i++)
                {
                    if (points[i] == -1)
                    {
                        points[i] = 0;
                    }
                }
            }
            else
            {
                int cnt = 0;
                for (int i = 0; i < NoPoints; i++)
                {
                    if (points[i] != -1)
                    {
                        point_exist[cnt, 0] = i;
                        point_exist[cnt, 1] = points[i];
                        cnt++;
                    }
                }
                sum[0] = 0;
                for (int i = 1; i < NoExist; i++)
                {
                    sum[i] = sum[i - 1] + (float)Math.Pow((Math.Abs(point_exist[i, 0] - point_exist[i - 1, 0]) * Math.Abs(point_exist[i - 1, 0] - point_exist[i, 0]) + Math.Abs(point_exist[i - 1, 1] - point_exist[i, 1]) * Math.Abs(point_exist[i - 1, 1] - point_exist[i, 1])), 0.5);
                }
                Tk[0] = 0;
                for (int i = 1; i < NoExist; i++)
                {
                    Tk[i] = sum[i] / sum[NoExist - 1];
                }

                for (int i = 0; i < NoExist + degree + 1; i++)
                {
                    if (i <= degree)
                    {
                        Uk[i] = 0;
                    }
                    if (i > degree && i < NoExist)
                    {
                        Uk[i] = 0;
                        for (int j = i - degree; j < i; j++)
                        {
                            Uk[i] += Tk[j];
                        }
                        Uk[i] /= degree;
                    }
                    if (i >= NoExist)
                    {
                        Uk[i] = 1;
                    }
                }
                float[,] Temp = new float[NoExist, NoExist + 1];

                for (int i = 0; i < NoExist; i++)
                {
                    float[] Nk_temp = new float[NoExist];
                    for (int j = 0; j < NoExist; j++)
                    {
                        Nk_temp[j] = 0;
                    }
                    Compute_Nk_fast(Nk_temp, NoExist, degree, Tk[i], Uk);

                    for (int j = 0; j < NoExist; j++)
                    {
                        Nk[i, j] = Nk_temp[j];
                    }
                }

                for (int n = 0; n < 2; n++)
                {
                    for (int i = 0; i < NoExist; i++)
                    {
                        for (int j = 0; j < NoExist; j++)
                        {
                            Temp[i, j] = Nk[i, j];
                        }
                    }

                    for (int i = 0; i < NoExist; i++)
                    {
                        Temp[i, NoExist] = point_exist[i, n];
                        P_temp[i]        = 0;
                    }
                    Gaussian_eliminate(Temp, NoExist, ref P_temp);

                    for (int i = 0; i < NoExist; i++)
                    {
                        P[i, n] = P_temp[i];
                    }
                }

                int PredictNo = NoPoints * 10;
                float[,] points_temp = new float[NoPoints, 2];
                for (int i = 0; i < NoPoints; i++)
                {
                    points_temp[i, 0] = 0;
                    points_temp[i, 1] = 0;
                }
                for (int i = 0; i < PredictNo; i++)
                {
                    float   temp_x  = 0;
                    float   temp_y  = 0;
                    float[] Nk_temp = new float[NoExist];

                    for (int j = 0; j < NoExist; j++)
                    {
                        Nk_temp[j] = 0;
                    }
                    Compute_Nk_fast(Nk_temp, NoExist, degree, ((float)1 / PredictNo) * i, Uk);

                    for (int j = 0; j < NoExist; j++)
                    {
                        temp_x += Nk_temp[j] * P[j, 0];
                        temp_y += Nk_temp[j] * P[j, 1];
                    }


                    if (temp_x < 0)
                    {
                        temp_x = 0;
                    }
                    if (temp_y < 0)
                    {
                        temp_y = 0;
                    }
                    if ((int)Math.Round(temp_x) <= NoPoints - 1)
                    {
                        if (points[(int)Math.Round(temp_x)] == -1)
                        {
                            if (temp_y > points_temp[(int)Math.Round(temp_x), 0])
                            {
                                points_temp[(int)Math.Round(temp_x), 0] = temp_y;
                            }
                        }
                    }
                }

                points = linearInterpolation(points);

                /*//use linear interpolation to prevent that the value was nonpredicted
                 * bool again = false;
                 * bool first = true;
                 * int pivot_start = 0;
                 * int pivot_end = 0;
                 * float value_start = 0;
                 * float value_end = 0;
                 * do
                 * {
                 *  again = false;
                 *  first = true;
                 *  for (int i = 0; i < NoPoints && again == false; i++)
                 *  {
                 *      if (points[i] == -1 && first == true)
                 *      {
                 *          if (i == 0)
                 *          {
                 *              points[i] = 0;
                 *          }
                 *          else
                 *          {
                 *              if (i == NoPoints - 1)
                 *              {
                 *                  points[NoPoints - 1] = points[NoPoints - 2];
                 *              }
                 *              else
                 *              {
                 *
                 *                  first = false;
                 *                  pivot_start = i - 1;
                 *                  value_start = points[i - 1];
                 *              }
                 *
                 *          }
                 *      }
                 *      if (points[i] != -1 && first == false)
                 *      {
                 *          pivot_end = i;
                 *          value_end = points[i];
                 *          points[(int)((pivot_start + pivot_end) / 2)] = (value_end + value_start) / 2;
                 *          again = true;
                 *      }
                 *      if (i == (NoPoints - 1) && first == false && again == false)
                 *      {
                 *          pivot_end = i;
                 *          value_end = 0;
                 *          points[(int)((pivot_start + pivot_end) / 2)] = (value_end + value_start) / 2;
                 *          again = true;
                 *      }
                 *  }
                 *
                 * } while (again);*/
            }

            for (int i = 0; i < NoPoints; i++)
            {
                if (type == "horizontal")
                {
                    interpolatedPointSet.Add(CoordinateTrans.XToTime(targetRegion, pointSetRegion, i), points[i]);
                }
                if (type == "vertical")
                {
                    interpolatedPointSet.Add(CoordinateTrans.YToMass(targetRegion, pointSetRegion, i), points[i]);
                }
            }

            return(interpolatedPointSet);
        }