Exemple #1
0
        public DensityPoint getDensityPointFromCRS(double c, double r, double s, bool calcValue)
        {
            DensityPoint dp  = new DensityPoint(c, r, s, 0, "CRS");
            DensityPoint dp2 = getXYZFromCRS(c, r, s);

            dp.setXYZ(dp2.X, dp2.Y, dp2.Z);
            if (calcValue)
            {
                DensityPoint v = getCRSValue(dp.C, dp.R, dp.S);
                dp.v      = v.v;
                dp.values = v.values;
            }
            return(dp);
        }
Exemple #2
0
        private DensityPoint getInterpolatedDensity(DensityPoint centre)
        {
            //1. Build the points from which we will interpolate
            //Going to create the interpolated points from the perspective of 3 axes and average

            List <DensityPoint> pointsA = new List <DensityPoint>();
            List <DensityPoint> pointsB = new List <DensityPoint>();
            List <DensityPoint> pointsC = new List <DensityPoint>();

            int offset    = 1;
            int numPoints = 2 * offset;

            numPoints = 2;
            int clStart = Convert.ToInt16(Math.Floor(centre.C)) - offset + 1;
            int rlStart = Convert.ToInt16(Math.Floor(centre.R)) - offset + 1;
            int slStart = Convert.ToInt16(Math.Floor(centre.S)) - offset + 1;

            if (numPoints == 1)
            {
                clStart = Convert.ToInt16(Math.Round(centre.C));
                rlStart = Convert.ToInt16(Math.Round(centre.R));
                slStart = Convert.ToInt16(Math.Round(centre.S));
            }
            for (int i = 0; i < numPoints; ++i)
            {
                int cA = clStart + i;
                int rB = rlStart + i;
                int sC = slStart + i;
                for (int j = 0; j < numPoints; ++j)
                {
                    int rA = rlStart + j;
                    int sB = slStart + j;
                    int cC = clStart + j;
                    for (int k = 0; k < numPoints; ++k)
                    {
                        int sA = slStart + k;
                        int cB = clStart + k;
                        int rC = rlStart + k;
                        if (isValidCRS(cA, rA, sA))
                        {
                            Double       val = getCRSGridPoint(cA, rA, sA);
                            DensityPoint dp  = new DensityPoint(cA, rA, sA, val, "CRS");
                            pointsA.Add(dp);
                        }
                        else
                        {
                            DensityPoint dp = new DensityPoint(cA, rA, sA, MagicInvalid, "CRS");
                            dp.valid = false;
                            pointsA.Add(dp);
                        }
                    }
                }
            }
            MatrixInterpolator mi    = new MatrixInterpolator();
            List <int>         diffs = new List <int>();

            diffs.Add(0);
            DensityPoint A = mi.getSplinedDensity(pointsA, centre, diffs);

            List <DensityPoint> finals = new List <DensityPoint>();

            finals.Add(A);

            bool   isValid = true;
            double vAv     = 0;
            double xAv     = 0;
            double yAv     = 0;
            double zAv     = 0;
            double cAv     = 0;
            double rAv     = 0;
            double sAv     = 0;

            Dictionary <int, double> vals = new Dictionary <int, double>();

            foreach (DensityPoint dp in finals)
            {
                isValid = dp.valid ? isValid : false;
                vAv    += dp.V;
                xAv    += dp.X;
                yAv    += dp.Y;
                zAv    += dp.Z;
                cAv    += dp.C;
                rAv    += dp.R;
                sAv    += dp.S;

                foreach (var v in A.values)
                {
                    double vv = dp.values[v.Key]; // does a negative gradient mean anything for firsrt derivative from this perspective?
                    if (vals.ContainsKey(v.Key))
                    {
                        vals[v.Key] += vv;
                    }
                    else
                    {
                        vals[v.Key] = vv;
                    }
                }
            }
            vAv /= finals.Count;
            xAv /= finals.Count;
            yAv /= finals.Count;
            zAv /= finals.Count;
            cAv /= finals.Count;
            rAv /= finals.Count;
            sAv /= finals.Count;
            foreach (var v in A.values)
            {
                vals[v.Key] /= finals.Count;
            }

            if (!isValid)
            {
                DensityPoint interped = new DensityPoint(cAv, rAv, sAv, -1000, "CRS");
                interped.valid  = false;
                interped.values = A.values;
                return(interped);
            }
            else
            {
                A.v = vAv;
                A.setXYZ(xAv, yAv, zAv);
                A.setCRS(cAv, rAv, sAv);
                A.values = vals;
                return(A);
            }
        }