Beispiel #1
0
        private double IntegralArea(MSPointSet argMSP)
        {
            double AreaOfCurve = 0.0;

            for (int i = 0; i < argMSP.Count - 1; i++)
            {
                AreaOfCurve = AreaOfCurve + ((argMSP.X(i + 1) - argMSP.X(i)) * ((argMSP.Y(i + 1) + argMSP.Y(i)) / 2));
            }
            return(AreaOfCurve);
        }
Beispiel #2
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;
        }
Beispiel #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;
        }
Beispiel #4
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;
        }
Beispiel #5
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);
        }
Beispiel #6
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);
        }
Beispiel #7
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);
        }
Beispiel #8
0
        private double IntegralArea(MSPointSet argMSP)
        {
            double AreaOfCurve = 0.0;

            for (int i = 0; i < argMSP.Count - 1; i++)
            {
                AreaOfCurve = AreaOfCurve + ((argMSP.X(i + 1) - argMSP.X(i)) * ((argMSP.Y(i + 1) + argMSP.Y(i)) / 2));

            }
            return AreaOfCurve;
        }