Ejemplo n.º 1
0
        private void PrepareLrtf(ComplexLens lens, int sampleCount)
        {
            lrtf = new LensRayTransferFunction(lens);
            // load precomputed LRTF from a file or compute it and save to file
            string filename = string.Format(@"data\lrtf_double_gauss_{0}.bin", sampleCount);

            lrtfTable = lrtf.SampleLrtf3DCached(sampleCount, filename);
        }
        public void CompareEvaluationTime()
        {
            ComplexLens             lens = ComplexLens.CreateDoubleGaussLens(Materials.Fixed.AIR, 4.0);
            LensRayTransferFunction lrtf = new LensRayTransferFunction(lens);

            int sampleCount = 128;

            Console.WriteLine("LRTF table size: {0}x{0}x{0}", sampleCount);
            string filename = string.Format(@"data\lrtf_double_gauss_{0}.bin", sampleCount);
            var    table    = lrtf.SampleLrtf3DCached(sampleCount, filename);

            int valueCount = 1000000;

            Console.WriteLine("Number of values to evaluate: {0}", valueCount);

            Random random   = new Random();
            var    inParams = new List <LensRayTransferFunction.Parameters>();

            for (int i = 0; i < valueCount; i++)
            {
                inParams.Add(new LensRayTransferFunction.Parameters(
                                 random.NextDouble(), random.NextDouble(),
                                 random.NextDouble(), random.NextDouble()
                                 ));
            }
            Stopwatch stopwatch = Stopwatch.StartNew();

            foreach (var inParam in inParams)
            {
                lrtf.ComputeLrtf(inParam);
            }
            stopwatch.Stop();
            Console.WriteLine("Ray tracing: {0} ms", stopwatch.ElapsedMilliseconds);
            stopwatch.Reset();
            stopwatch.Start();
            foreach (var inParam in inParams)
            {
                table.EvaluateLrtf3D(inParam);
            }
            stopwatch.Stop();
            Console.WriteLine("LRTF table interpolation: {0} ms", stopwatch.ElapsedMilliseconds);
        }
        public void CompareInterpolatedLrtfValueWithOriginalOnes()
        {
            ComplexLens             lens = ComplexLens.CreateDoubleGaussLens(Materials.Fixed.AIR, 4.0);
            LensRayTransferFunction lrtf = new LensRayTransferFunction(lens);

            int    sampleCount = 128;
            string filename    = string.Format(@"data\lrtf_double_gauss_{0}.bin", sampleCount);
            var    table       = lrtf.SampleLrtf3DCached(sampleCount, filename);

            Random random = new Random();

            for (int i = 0; i < 1000; i++)
            {
                var incomingParams = new LensRayTransferFunction.Parameters(
                    random.NextDouble(), random.NextDouble(),
                    random.NextDouble(), random.NextDouble()
                    );
                var outgoingParamsOriginal     = lrtf.ComputeLrtf(incomingParams).ToVector4d();
                var outgoingParamsInterpolated = table.EvaluateLrtf3D(incomingParams).ToVector4d();
                //AssertEqualVector4d(outgoingParamsOriginal, outgoingParamsInterpolated);
            }
        }