예제 #1
0
            /**
             * <inheritdoc />
             */
            public override double GetCCT()
            {
                if (DataSource is BlackBodySpectrum)
                {
                    return((DataSource as BlackBodySpectrum).CCT);
                }

                if (!double.IsNaN(CCT))
                {
                    return(CCT);
                }

                // Precomputing interpolation tables...
                if (TemperatureChromaticities == null)
                {
                    // Oversized to improve alignment (needs 302).
                    TemperatureChromaticities = new List <CIE1960> (512);

                    // From 1000º K to 20000º K
                    for (double t = 1000.0; t < 20001.0; t *= 1.01)
                    {
                        TemperatureChromaticities.Add(
                            new BlackBodySpectrum(t).ToCIEXYZ(Spd2ClrStrategy.Nm1Deg2).ToCIEUCS()
                            );
                    }
                }

                int bestI = 0;

                Duv = double.PositiveInfinity;

                // First gross grained search
                // TODO: This is a naive search, must be improved!
                for (int i = 0; i < TemperatureChromaticities.Count; i++)
                {
                    double tmpDuv = Math.Sqrt(
                        Math.Pow(u - TemperatureChromaticities [i].u, 2) +
                        Math.Pow(v - TemperatureChromaticities [i].v, 2)
                        );

                    if (Duv > tmpDuv)
                    {
                        Duv   = tmpDuv;
                        bestI = i;
                    }
                }
                CCT = TemperatureChromaticities [bestI].GetCCT();

                // Preparing the following fine grained search
                double tMin = TemperatureChromaticities [
                    (bestI > 0) ? bestI - 1 : bestI
                              ].GetCCT();
                double tMax = TemperatureChromaticities [
                    (bestI < TemperatureChromaticities.Count - 1) ? bestI + 1 : bestI
                              ].GetCCT();
                double tDiff = (tMax - tMin) / 100.0;

                // Second fine grained search
                for (double t = tMin; t < tMax; t += tDiff)
                {
                    var tmpUV = new BlackBodySpectrum(t).ToCIEXYZ(Spd2ClrStrategy.Nm1Deg2).ToCIEUCS();

                    double tmpDuv = Math.Sqrt(Math.Pow(u - tmpUV.u, 2) + Math.Pow(v - tmpUV.v, 2));

                    if (Duv > tmpDuv)
                    {
                        Duv = tmpDuv;
                        CCT = t;
                    }
                }

                return(CCT);
            }
예제 #2
0
        public static Vector3 ConvertTemperature(float colorTemperature)
        {
            var srgb = new BlackBodySpectrum(colorTemperature).ToSRGB();

            return(new Vector3((float)srgb.R, (float)srgb.G, (float)srgb.B));
        }
예제 #3
0
            /**
             * <inheritdoc />
             */
            public override double GetCCT()
            {
                if (DataSource is BlackBodySpectrum) {
                    return (DataSource as BlackBodySpectrum).CCT;
                }

                if (!double.IsNaN (CCT)) {
                    return CCT;
                }

                // Precomputing interpolation tables...
                if (TemperatureChromaticities == null) {
                    // Oversized to improve alignment (needs 302).
                    TemperatureChromaticities = new List<CIE1960> (512);

                    // From 1000º K to 20000º K
                    for (double t = 1000.0; t < 20001.0; t *= 1.01) {
                        TemperatureChromaticities.Add (
                            new BlackBodySpectrum (t).ToCIEXYZ (Spd2ClrStrategy.Nm1Deg2).ToCIEUCS ()
                        );
                    }
                }

                int bestI = 0;
                Duv = double.PositiveInfinity;

                // First gross grained search
                // TODO: This is a naive search, must be improved!
                for (int i = 0; i < TemperatureChromaticities.Count; i++) {
                    double tmpDuv = Math.Sqrt (
                        Math.Pow (u - TemperatureChromaticities [i].u, 2) +
                        Math.Pow (v - TemperatureChromaticities [i].v, 2)
                    );

                    if (Duv > tmpDuv) {
                        Duv = tmpDuv;
                        bestI = i;
                    }
                }
                CCT = TemperatureChromaticities [bestI].GetCCT ();

                // Preparing the following fine grained search
                double tMin = TemperatureChromaticities [
                    (bestI > 0) ? bestI - 1 : bestI
                ].GetCCT ();
                double tMax = TemperatureChromaticities [
                    (bestI < TemperatureChromaticities.Count - 1) ? bestI + 1 : bestI
                ].GetCCT ();
                double tDiff = (tMax - tMin) / 100.0;

                // Second fine grained search
                for (double t = tMin; t < tMax; t += tDiff) {
                    var tmpUV = new BlackBodySpectrum (t).ToCIEXYZ (Spd2ClrStrategy.Nm1Deg2).ToCIEUCS ();

                    double tmpDuv = Math.Sqrt (Math.Pow (u - tmpUV.u, 2) +	Math.Pow (v - tmpUV.v, 2));

                    if (Duv > tmpDuv) {
                        Duv = tmpDuv;
                        CCT = t;
                    }
                }

                return CCT;
            }
예제 #4
0
 public static Vector3 ConvertTemperature(float colorTemperature)
 {
     var srgb = new BlackBodySpectrum(colorTemperature).ToSRGB();
     return new Vector3((float)srgb.R, (float)srgb.G, (float)srgb.B);
 }