Exemplo n.º 1
0
 public void SampledSpectrumTest()
 {
     var src = new RgbSpectrum(0.5f, 0.5f, 0.5f);
     var ss = new SampledSpectrum(ref src, SpectrumType.Illuminant);
     var color = ss.ToRgb().ToColor();
     Assert.IsTrue(color.R < 129);
     Assert.IsTrue(color.G < 129);
     Assert.IsTrue(color.B < 129);
 }
Exemplo n.º 2
0
 public static RgbSpectrum Convert(ref SampledSpectrum ss)
 {
     return ss.ToRgb();
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {

            int itemCount = 1000;
            int iters = 100000;
            Random rand = new Random();
            int[] ints = Enumerable.Range(0, itemCount).Select(cc => rand.Next()).ToArray();
            HashSet<int> hs = new HashSet<int>(ints);
            List<int> lst = ints.ToList();
            bool contains = false;
            string result = string.Empty;
            result = PerformanceMeasurementController.Test(delegate
            {
                var index = rand.Next(0, itemCount - 1);
                contains = hs.Contains(index) != true;
            }, "HashSet search\r\n", iters);
            Console.WriteLine("Time "+result);

            result = PerformanceMeasurementController.Test(delegate
            {
                var index = rand.Next(0, itemCount - 1);
                contains = lst.BinarySearch(index) > 0;
            }, "List search\r\n", iters);
            Console.WriteLine("Time " + result);

            result = PerformanceMeasurementController.Test(delegate
            {
                var index = rand.Next(0, itemCount - 1);
                for (int j = 0; j < itemCount; j++)
                {
                    if (ints[j] == index)
                    {
                        contains = true;
                        break;
                    }
                }
            }, "Array enum search\r\n", iters);
            Console.WriteLine("Time " + result);

            return;

            IRandomProvider rp = new BaseQMCSequence();
            int i = 100;
            while (i!=0)
            {
                Console.WriteLine("{0}  {1:F6},  {2:F6},  {3:F6},  {4:F6}", i, rp.NextFloat(),rp.NextFloat(),rp.NextFloat(),rp.NextFloat());
                i--;
            }
            Console.WriteLine(rp.GetType().Name);
            return;
            /*
            RgbSpectrum c1 = new RgbSpectrum(0.5f, 0.7f, 1.55f);
            RgbSpectrum c2 = new RgbSpectrum(1.5f, 0.4f, 11f);
            RgbSpectrum c3 = new RgbSpectrum(0);

            
            SSE.MaddSse(ref c1, ref c2, 4f, ref c3);

            Console.WriteLine("SSE Version - {0}", c3);
            Console.WriteLine("CPU Version - {0}", (c1+c2)*4f);



            return;
            */

            v1();
            v1();
            v1();

            var res = new SampledSpectrum(1.9f);
            var rs = new SampledSpectrum(1.9f);

            var rgb_1 = ColorFactory.SSEToRgb(ref res);
            var rgb_2 = res.ToRgb();

            Console.WriteLine("SSE:{0} / Norm {1}", rgb_1, rgb_2);

            SSE.ClampSSE(ref res, ref rs);
            var maxIterations = 5;
            var testIterations = 1;
            var iterations = 100000000;
            var rnd = new FastRandom();

            var s1 = new SampledSpectrum(rnd.NextFloat());
            var s2 = new SampledSpectrum(rnd.NextFloat());
            var s3 = SampledSpectrum.UnitSpectrum();
            RgbSpectrum r3;
            float rx = 0f;
            float[][] rgb = Enumerable.Repeat(new[] {rnd.NextFloat(), rnd.NextFloat(), rnd.NextFloat()}, 1000).ToArray();

            var testActions = new[]
                {
                    //new Tuple<string, Action>("Spectral mul cpu", () =>
                    //{
                    //    s3 = s1*s2;
                    //}),

                    //new Tuple<string, Action>("Spectral mul sse", () =>
                    //{
                    //    SSE.MulSSE(ref s1, ref s2, ref s3);
                    //}),

                    new Tuple<string, Action>("Dot SSE", () =>
                    {
                        rx = SSE.Dot(ref s1, ref s2);
                    }),

                    new Tuple<string, Action>("Dot avx", () =>
                    {
                        rx = AVX.Dot(ref s1, ref s2);
                    }),

                    /*
                    new Tuple<string, Action>("to Rgb  cpu", () =>
                    {
                        r3 = s1.ToRgb();
                    }),

                    new Tuple<string, Action>("to Rgb  sse", () =>
                    {
                        r3 = ColorFactory.SSEToRgb(ref s1);
                    }),*/

                    //new Tuple<string, Action>("Rgb madd cpu", () =>
                    //{
                    //    var r1 = new RgbSpectrum(rnd.NextFloat());
                    //    var r2 = new RgbSpectrum(rnd.NextFloat());
                    //    var r4 = new RgbSpectrum(rnd.NextFloat());

                    //    r3 = (r1 + r2+r4+r1) * (1f / 3f);

                    //    //SSE.MaddSse(ref r1, ref c2, 4f, ref c3);

                    //}), 

                    //new Tuple<string, Action>("Rgb madd sse", () =>
                    //{
                    //    var r1 = new RgbSpectrum(rnd.NextFloat());
                    //    var r2 = new RgbSpectrum(rnd.NextFloat());
                    //    var r4 = new RgbSpectrum(rnd.NextFloat());


                    //    SSE.AverageSSE(ref r1, ref r2, ref r4,ref r1, ref r3);

                    //}), 

                    /*
                    new Tuple<string, Action>    (" SSE to rgb ", () =>
                        {
                            foreach (var f in rgb)
                            {
                                ColorFactory.SSEFromRgb(f, SpectrumType.Illuminant);
                                
                            }
                        }),
                         new Tuple<string, Action>    (" AVX to rgb ", () =>
                        {
                            foreach (var f in rgb)
                            {
                                ColorFactory.AVXFromRgb(f, SpectrumType.Illuminant);
                            }
                        }),
                        new Tuple<string, Action>(" CPU to rgb ", () =>
                        {
                            foreach (var f in rgb)
                            {
                                ColorFactory.BaseFromRgb(f, SpectrumType.Illuminant);

                            }
                        }),
                     */ 
/*

                          new Tuple<string, Action>    (" Normal sqrt ", () =>
                        {
                            for (int i = 0; i < 4; i++)
                            {
                                var f = rnd.NextFloat();
                                res[0] = MathLab.Sqrt(f);
                            }
                        }),
                        new Tuple<string, Action>(" SSE sqrt    ", () =>
                        {
                            SSE. VSqrt();
                        }),*/
                        /*
                    new Tuple<string, Action>("Current NextFloat :",  () =>
                        {
                            var rnd = new FastRandom();
                            rnd.NextFloat();
                            for (var i = 0; i < iterations; i++)
                            {
                                rnd.NextFloat();
                            }
                        }),
                    new Tuple<string, Action>("Halton : ",  () =>
                        {
                            var qmc = new HaltonSequence();
                            for (var i = 0; i < iterations; i++)
                            {
                                //rnd.NextDouble();
                                qmc.NextFloat();
                            }
                        }),
                    new Tuple<string, Action>("VanDerCorrupt : ",  () =>
                        {
                            var qmc = new BaseQMCSequence();
                            for (var i = 0; i < iterations; i++)
                            {
                                //rnd.NextDouble();
                                qmc.NextFloat();
                            }
                        }),*/

                };
        @test:

            Console.WriteLine("Converting 1000 float triplets to SampledSpectrum");
            Console.WriteLine("Running test for {0} iterations per test . {1} test iteration", iterations, testIterations);
            //TestExpressions();
            foreach (var testAction in testActions)
            {
                Tuple<string, Action> action = testAction;
                Console.WriteLine(PerformanceMeasurementController.Test(() => action.Item2(), 8,testAction.Item1, iterations));
            }
            testIterations++;
            if (testIterations > maxIterations)
                return;
            goto @test;


            /*
            QualitySettingsInfo qs = new QualitySettingsInfo() { SamplesPerPixel = 32, ShadowRaysPerLight = 1, TextureSamplingQuality = TextureSamplingQuality.Linear, SuperSamplingSize = 1 };
            OutputSettingsInfo os = new OutputSettingsInfo() { FilePath = @"G:\Git", Width = 640, Height = 480, GammaCorrection = true, BitsPerPixel = 32, ToneMap = false, ToneMapValue = 1.5f };

            var qs_s = SerializationService.Serialize(qs, typeof(QualitySettingsInfo), typeof(TextureSamplingQuality));
            var os_s = SerializationService.Serialize(os, typeof(OutputSettingsInfo));
            Console.WriteLine(qs_s);
            Console.WriteLine(os_s);*/

            /*
            var f = new [] {0.25f, 0.15f, 0.15f, 0.45f};
            float[] cdf = new float[f.Length+1];
            float c;
            MC.ComputeStep1dCDF(f, 4, cdf, out c);
            Console.WriteLine();
            return;
           */
            //CreateFrame(@"F:\Dev\Frames\RDF\", "cornell_service", @"F:\Dev\Scenes\OasisCornell\");
            //CreateFrame(@"F:\Dev\Frames\RDF\", "decostreet", @"F:\3D\Models\decostreet\");
            //            CreateFrame(@"F:\Dev\Frames\RDF\", "tmp", @"F:\3D\Models\decostreet\");
            /*
            GlobalConfiguration.Instance.OpenConfig(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Global.Config.xml");
            GlobalConfiguration.Instance.Add("TextureFindPaths", new string[3] { @"C:\Dev\", @"F:\3d\HDRi\", @"F:\3d\Textures\" });
            GlobalConfiguration.Instance.SaveConfig(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Global.Config.xml");


            //CreateFrame(@"F:\Dev\Frames\CompressedDataFrames\DecoStreet\", "decostreet", @"F:\Dev\Frames\CompressedDataFrames\DecoStreet\");
            return;
            //
            //CreateFrame(@"F:\Dev\Frames\RDF\", "cornell_service");
            using (var frame = ArchiveFrameService.OpenArchive(@"F:\Dev\Frames\CompressedDataFrames\OasisCornell\OasisCornell.cdf",
                                                @"F:\Temp\RayDenTemp\OasisCornell"))
                Console.WriteLine("Frame opened {0}", frame.Frame.FrameName);
             * */
        }