public void ARLightEstimationData_TestIntensityConversion()
        {
            Dictionary <float, float> brightnessToLumensMapping = new Dictionary <float, float> {
                // {intensity in lumens (0 -> 2000), brightness (0 -> 1)}
                { 0f, 0f },
                { -100f, 0f },
                { 500f, 0.25f },
                { 1000f, 0.5f },
                { 1500f, 0.75f },
                { 2000f, 1f },
                { 2500f, 1f }
            };

            var obj = new ARLightEstimationData();

            foreach (var testPair in brightnessToLumensMapping)
            {
                // If brightness is not filled, expect it to be converted based on the intensity.
                obj.averageIntensityInLumens = testPair.Key;
                obj.averageBrightness        = null;
                Assert.AreEqual(obj.averageBrightness, testPair.Value, "Conversion from averageIntensityInLumens to averageBrightness failed.");
            }

            obj.averageBrightness        = 0.5f;
            obj.averageIntensityInLumens = 5000f;
            Assert.AreEqual(obj.averageIntensityInLumens, 5000f, "If averageIntensityInLumens is set, no conversion should be performed.");
        }
Example #2
0
        /// <summary>
        /// Invoke the camera frame received event packing the frame information into the event argument.
        /// <summary>
        /// <param name="frame">The camera frame raising the event.</param>
        void InvokeFrameReceivedEvent(XRCameraFrame frame)
        {
            var lightEstimation = new ARLightEstimationData();

            if (frame.hasAverageBrightness)
            {
                lightEstimation.averageBrightness = frame.averageBrightness;
            }

            if (frame.hasAverageIntensityInLumens)
            {
                lightEstimation.averageIntensityInLumens = frame.averageIntensityInLumens;
            }

            if (frame.hasAverageColorTemperature)
            {
                lightEstimation.averageColorTemperature = frame.averageColorTemperature;
            }

            if (frame.hasColorCorrection)
            {
                lightEstimation.colorCorrection = frame.colorCorrection;
            }

            var eventArgs = new ARCameraFrameEventArgs();

            eventArgs.lightEstimation = lightEstimation;

            if (frame.hasTimestamp)
            {
                eventArgs.timestampNs = frame.timestampNs;
            }

            if (frame.hasProjectionMatrix)
            {
                eventArgs.projectionMatrix = frame.projectionMatrix;
            }

            if (frame.hasDisplayMatrix)
            {
                eventArgs.displayMatrix = frame.displayMatrix;
            }

            s_Textures.Clear();
            s_PropertyIds.Clear();
            foreach (var textureInfo in m_TextureInfos)
            {
                s_Textures.Add(textureInfo.texture);
                s_PropertyIds.Add(textureInfo.descriptor.propertyNameId);
            }

            eventArgs.textures        = s_Textures;
            eventArgs.propertyNameIds = s_PropertyIds;

            frameReceived(eventArgs);
        }
        public void ARLightEstimationData_TestGetHashCode()
        {
            var obj1 = new ARLightEstimationData();
            var obj2 = new ARLightEstimationData();

            obj1.averageIntensityInLumens = 1115f;
            obj1.averageBrightness        = null;
            obj2.averageIntensityInLumens = 1233f;
            obj2.averageBrightness        = null;
            Assert.AreNotEqual(obj1.GetHashCode(), obj2.GetHashCode(), "Hash codes should differ when averageIntensityInLumens is different.");

            obj1.averageBrightness        = 0.5f;
            obj1.averageIntensityInLumens = null;
            obj2.averageBrightness        = 0.6f;
            obj2.averageIntensityInLumens = null;
            Assert.AreNotEqual(obj1.GetHashCode(), obj2.GetHashCode(), "Hash codes should differ when averageBrightness is different.");

            obj1.averageBrightness        = 0.5f;
            obj1.averageIntensityInLumens = null;
            obj2.averageBrightness        = 0.5f;
            obj2.averageIntensityInLumens = null;
            Assert.AreEqual(obj1.GetHashCode(), obj2.GetHashCode(), "Hash codes should match when averageBrightness is same.");
        }
        public void ARLightEstimationData_TestEquality()
        {
            var obj1 = new ARLightEstimationData();
            var obj2 = new ARLightEstimationData();

            Assert.AreEqual(obj1, obj2, "Freshly created ARLightEstimationData objects should match.");

            obj1.averageBrightness = 0.1f;
            obj2.averageBrightness = 0.5f;
            Assert.AreNotEqual(obj1, obj2, "ARLightEstimationData with different averageBrightness values should not match.");

            obj1.averageBrightness = 0.5f;
            obj2.averageBrightness = 0.5f;
            Assert.AreEqual(obj1, obj2, "ARLightEstimationData with same averageBrightness values should match.");

            obj1.averageBrightness = null;
            obj2.averageBrightness = 0.5f;
            Assert.AreNotEqual(obj1, obj2, "ARLightEstimationData with different averageBrightness values should not match.");

            obj1.averageIntensityInLumens = 1000;
            obj2.averageBrightness        = 0.5f;
            Assert.AreEqual(obj1, obj2, "ARLightEstimationData with same calculated brightness values should match.");

            obj1.averageIntensityInLumens = 2000;
            obj2.averageBrightness        = 0.5f;
            Assert.AreNotEqual(obj1, obj2, "ARLightEstimationData with different calculated brightness values should not match.");

            obj1.averageIntensityInLumens = null;
            obj1.averageBrightness        = null;
            obj1.colorCorrection          = new Color(1f, 0.5f, 0.5f, 1f);

            obj2.averageIntensityInLumens = null;
            obj2.averageBrightness        = null;
            obj2.colorCorrection          = new Color(1f, 0.5f, 0.5f, 1f);
            Assert.AreEqual(obj1, obj2, "ARLightEstimationData with same color correction should match.");

            obj1.averageIntensityInLumens = null;
            obj1.averageBrightness        = null;
            obj1.averageColorTemperature  = 5230f;

            obj2.averageIntensityInLumens = null;
            obj2.averageBrightness        = null;
            obj2.averageColorTemperature  = 5230f;
            Assert.AreEqual(obj1, obj2, "ARLightEstimationData with same color temperature should match.");

            obj1.averageIntensityInLumens = null;
            obj1.averageBrightness        = null;
            obj1.averageColorTemperature  = 5230f;
            obj1.colorCorrection          = new Color(1f, 0.5f, 0.5f, 1f);

            obj2.averageIntensityInLumens = null;
            obj2.averageBrightness        = null;
            obj2.averageColorTemperature  = 5230f;
            obj2.colorCorrection          = new Color(1f, 0.5f, 0.5f, 1f);
            Assert.AreEqual(obj1, obj2, "ARLightEstimationData with same properties should match.");

            obj1.averageIntensityInLumens = null;
            obj1.averageBrightness        = null;
            obj1.averageColorTemperature  = 5230f;
            obj1.colorCorrection          = new Color(1f, 0.5f, 0.5f, 1f);

            obj2.averageIntensityInLumens = 2300;
            obj2.averageBrightness        = 0.5f;
            obj2.averageColorTemperature  = 1222f;
            obj2.colorCorrection          = new Color(1f, 1f, 0.5f, 1f);
            Assert.AreNotEqual(obj1, obj2, "ARLightEstimationData with different properties should not match.");
        }