Exemplo n.º 1
0
        public NishitaInterp(Nishita skyColor, double h0,
                             double directLight, double ambiantLight,
                             double maxDist,
                             double latRadMin, double latRadMax, int numLat,
                             double lonRadMin, double lonRadMax, int numLon)
        {
            this.skyColor     = skyColor;
            this.h0           = h0;
            this.directLight  = directLight;
            this.ambientLight = ambiantLight;
            this.maxDist      = maxDist;
            this.latRadMin    = latRadMin;
            this.latRadMax    = latRadMax;
            this.numLat       = numLat;
            this.lonRadMin    = lonRadMin < lonRadMax ? lonRadMin : lonRadMax;
            this.lonRadMax    = lonRadMax > lonRadMin ? lonRadMax : lonRadMin;
            this.numLon       = numLon;
            this.intType      = InterpolatonType.Linear;

            // Fixup
            if (this.lonRadMin < 0.0)
            {
                this.lonRadMin = 0.0;
            }

            inters     = new Lazy <TwoDInterpolator[]>(() => GetInters());
            aerialPers = new Lazy <AerialPers>(() => GetAerialPers());
        }
Exemplo n.º 2
0
        public TwoDInterpolator(double[] xs, double[] ys, double[][] values, InterpolatonType type)
        {
            this.type = type;
            this.xs   = xs;
            this.ys   = ys;
            if (type == InterpolatonType.Nearest)
            {
                this.rawValues = values;
                if (xs[0] > xs[1])
                {
                    xsReversed = true;
                    this.xs    = xs.Reverse().ToArray();
                }

                if (ys[0] > ys[1])
                {
                    ysReversed = true;
                    this.ys    = ys.Reverse().ToArray();
                }
            }
            else
            {
                this.values = new OneDInterpolator[xs.Length];
                for (int j = 0; j < xs.Length; j++)
                {
                    this.values[j] = new OneDInterpolator(ys, values[j], type);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Given arrays x[0..n-1] and y[0..n-1] containing a tabulated function, i.e., y[i] = f(x[i]), with
        /// x sorted, this routine returns an array y2[1..n] that contains
        /// the second derivatives of the interpolating function at the tabulated points xi.The
        /// routine is signaled to set the corresponding boundary
        /// condition for a natural spline, with zero second derivative on that boundary.
        /// </summary>
        public OneDInterpolator(double[] x, double[] y, InterpolatonType type)
        {
            this.type = type;
            if (x[0] < x[x.Length - 1])
            {
                xa = x.ToArray();
                ya = y.ToArray();
            }
            else
            {
                xa = x.Reverse().ToArray();
                ya = y.Reverse().ToArray();
            }

            n = xa.Length;

            delta = Math.Abs(xa[0] - xa[n - 1]) / n;

            switch (type)
            {
            case InterpolatonType.Linear:
                // Nothing more to do
                break;

            case InterpolatonType.Cubic:
                y2a = new double[n];

                // The boundary conditions are set to be “natural”
                y2a[1] = 0.0;
                var u  = new double[n];
                var qn = 0.0;
                var un = 0.0;
                for (int i = 1; i <= n - 2; i++)
                {
                    // This is the decomposition loop of the tridiagonal algorithm.
                    // y2 and u are used for temporary storage of the decomposed factors.
                    var sig = (xa[i] - xa[i - 1]) / (xa[i + 1] - xa[i - 1]);
                    var p   = sig * y2a[i - 1] + 2;
                    y2a[i] = (sig - 1) / p;
                    u[i]   =
                        (ya[i + 1] - ya[i + 0]) / (xa[i + 1] - xa[i + 0]) -
                        (ya[i + 0] - ya[i - 1]) / (xa[i + 0] - xa[i - 1]);
                    u[i] = (6 * u[i] / (xa[i + 1] - xa[i - 1]) - sig * u[i - 1]) / p;
                }

                y2a[n - 1] = (un - qn * u[n - 2]) / (qn * y2a[n - 2] + 1);
                for (int k = n - 2; k >= 0; k--)
                {
                    // This is the backsubstitution loop of the tridiagonal algorithm.
                    y2a[k] = y2a[k] * y2a[k + 1] + u[k];
                }

                break;

            default:
                throw new ArgumentOutOfRangeException("type");
            }
        }
Exemplo n.º 4
0
        private InterpolatingChunk <T> ComputeInterpolation(
            Angle latLo, Angle lonLo,
            Angle latHi, Angle lonHi,
            Func <T, double>[] toDouble,
            Func <double[], T> fromDouble,
            InterpolatonType interpolatonType)
        {
            int iLo = GetLatIndex(latLo) - 2;
            int iHi = GetLatIndex(latHi) + 2;

            iLo = iLo < 0 ? 0 : iLo >= LatSteps ? LatSteps - 1 : iLo;
            iHi = iHi < 0 ? 0 : iHi >= LatSteps ? LatSteps - 1 : iHi;
            double areaLatLo = GetLat(iLo).DecimalDegree;
            double areaLatHi = GetLat(iHi).DecimalDegree;

            int jLo = GetLonIndex(lonHi) - 2;
            int jHi = GetLonIndex(lonLo) + 2;

            jLo = jLo < 0 ? 0 : jLo >= LonSteps ? LonSteps - 1 : jLo;
            jHi = jHi < 0 ? 0 : jHi >= LonSteps ? LonSteps - 1 : jHi;
            double areaLonLo = GetLon(jHi).DecimalDegree;
            double areaLonHi = GetLon(jLo).DecimalDegree;

            double[] lats = new double[iHi - iLo + 1];
            for (int i = 0; i < lats.Length; i++)
            {
                lats[i] = areaLatLo + i * (areaLatHi - areaLatLo) / (iHi - iLo);
            }

            double[] lons = new double[jHi - jLo + 1];
            for (int i = 0; i < lons.Length; i++)
            {
                lons[i] = areaLonHi + i * (areaLonLo - areaLonHi) / (jHi - jLo);
            }

            double[][][] values = new double[toDouble.Length][][];
            for (int k = 0; k < toDouble.Length; k++)
            {
                values[k] = new double[lats.Length][];
                for (int i = 0; i < lats.Length; i++)
                {
                    values[k][i] = new double[lons.Length];
                    for (int j = 0; j < lons.Length; j++)
                    {
                        values[k][i][j] = toDouble[k](Data[iLo + i][jLo + j]);
                    }
                }
            }

            return(new InterpolatingChunk <T>(lats, lons, values, fromDouble, interpolatonType));
        }
Exemplo n.º 5
0
        public OneDVectorInterpolator(double[] x, double[][] y, InterpolatonType type)
        {
            componentInterp = new OneDInterpolator[y[0].Length];
            var tempY = new double[y.Length];

            for (int i = 0; i < componentInterp.Length; i++)
            {
                for (int j = 0; j < y.Length; j++)
                {
                    tempY[j] = y[j][i];
                }

                componentInterp[i] = new OneDInterpolator(x, tempY, type);
            }
        }
Exemplo n.º 6
0
 public InterpolatingChunk(
     double[] lats,
     double[] lons,
     double[][][] values,
     Func <double[], T> fromDouble,
     InterpolatonType interpolatonType)
 {
     this.latLo      = lats.Min();
     this.lonLo      = lons.Min();
     this.latHi      = lats.Max();
     this.lonHi      = lons.Max();
     this.fromDouble = fromDouble;
     this.interp     = new TwoDInterpolator[values.Length];
     for (int i = 0; i < values.Length; i++)
     {
         this.interp[i] = new TwoDInterpolator(lats, lons, values[i], interpolatonType);
     }
 }
Exemplo n.º 7
0
            public AerialPers(int numDists, double maxDist, double h0, Nishita skyColor, InterpolatonType intType)
            {
                double[] dists = new double[numDists];
                for (int x = 0; x < numDists; x++)
                {
                    dists[x] = maxDist * x / (numDists + -1);
                }

                double[][] values = new double[numDists][];
                for (int k = 0; k < values.Length; k++)
                {
                    values[k] = new double[12];
                }

                for (int x = 0; x < dists.Length; x++)
                {
                    skyColor.SkyColorAtPointComputer(
                        h0, dists[x],
                        out MyDColor attenuation,
                        out MyDColor airColorR,
                        out MyDColor airColorM,
                        out MyDColor directPart);

                    for (int k = 0; k < 3; k++)
                    {
                        values[x][0]  = attenuation.R;
                        values[x][1]  = attenuation.G;
                        values[x][2]  = attenuation.B;
                        values[x][3]  = airColorR.R;
                        values[x][4]  = airColorR.G;
                        values[x][5]  = airColorR.B;
                        values[x][6]  = airColorM.R;
                        values[x][7]  = airColorM.G;
                        values[x][8]  = airColorM.B;
                        values[x][9]  = directPart.R;
                        values[x][10] = directPart.G;
                        values[x][11] = directPart.B;
                    }
                }

                inters = new OneDVectorInterpolator(dists, values, intType);
            }
Exemplo n.º 8
0
 public InterpolatingChunk <T> GetInterpolator(InterpolatonType interpolatonType)
 {
     return(ComputeInterpolation(LatLo, LonLo, LatHi, LonHi, toDouble, fromDouble, interpolatonType));
 }