public void ComputeLrtfForRandomInput()
        {
            ComplexLens             lens = ComplexLens.CreateDoubleGaussLens(Materials.Fixed.AIR, 4.0);
            LensRayTransferFunction lrtf = new LensRayTransferFunction(lens);
            Random random = new Random();

            for (int i = 0; i < 1000; i++)
            {
                var incomingParams = new LensRayTransferFunction.Parameters(
                    random.NextDouble(), random.NextDouble(),
                    random.NextDouble(), random.NextDouble()
                    );
                LensRayTransferFunction.Parameters outgoingParams = lrtf.ComputeLrtf(incomingParams);
                if (outgoingParams != null)
                {
                    if (outgoingParams.DirectionTheta < 0 || outgoingParams.DirectionTheta > 1 ||
                        outgoingParams.DirectionPhi < 0 || outgoingParams.DirectionPhi > 1 ||
                        outgoingParams.PositionTheta < 0 || outgoingParams.PositionTheta > 1 ||
                        outgoingParams.PositionPhi < 0 || outgoingParams.PositionPhi > 1)
                    {
                        Console.WriteLine("Warning: parameter outside [0; 1] interval.");
                        Console.WriteLine("incoming: {0}", incomingParams);
                        Console.WriteLine("outgoing: {0}", outgoingParams);
                        Console.WriteLine();
                    }
                    //Assert.InRange(outgoingParams.DirectionTheta, 0.0, 1.0);
                    //Assert.InRange(outgoingParams.DirectionPhi, 0.0, 1.0);
                    //Assert.InRange(outgoingParams.PositionTheta, 0.0, 1.0);
                    //Assert.InRange(outgoingParams.PositionPhi, 0.0, 1.0);
                }
            }
        }
Exemplo n.º 2
0
 private ComplexLens CreateLens()
 {
     //double curvatureRadius = 150;
     //double apertureRadius = 100;
     //return ComplexLens.CreateBiconvexLens(curvatureRadius, apertureRadius, 0);
     return(ComplexLens.CreateDoubleGaussLens(Materials.Fixed.AIR, 4.0));
     //return ComplexLens.CreatePetzvalLens(Materials.Fixed.AIR, 4.0);
 }
        public void ComputeLrtfResultInCorrectInterval()
        {
            ComplexLens             lens = ComplexLens.CreateDoubleGaussLens(Materials.Fixed.AIR, 4.0);
            LensRayTransferFunction lrtf = new LensRayTransferFunction(lens);
            var incomingParams           = new LensRayTransferFunction.Parameters(0.835057026164167, 0.375245163857585, 0.854223355117358, 0.000161428470239708);

            LensRayTransferFunction.Parameters outgoingParams = lrtf.ComputeLrtf(incomingParams);
            Console.WriteLine(outgoingParams);
        }
Exemplo n.º 4
0
 private IList <ComplexLens> CreateLenses()
 {
     return(new List <ComplexLens>(
                new[] {
         ComplexLens.CreateDoubleGaussLens(Materials.Fixed.AIR, 4.0),
         ComplexLens.CreatePetzvalLens(Materials.Fixed.AIR, 4.0),
         ComplexLens.CreateBiconvexLens(150, 100, 0)
     }
                ));
 }
        private static void ConvertParametersToRayAndBack(
            LensRayTransferFunction.Parameters inputParams,
            Func <LensRayTransferFunction.Parameters, ComplexLens, LensRayTransferFunction.Parameters> func)
        {
            ComplexLens lens         = ComplexLens.CreateDoubleGaussLens(Materials.Fixed.AIR, 4.0);
            var         outputParams = func(inputParams, lens);

            Assert.Equal(inputParams.PositionTheta, outputParams.PositionTheta, 5);
            Assert.Equal(inputParams.PositionPhi, outputParams.PositionPhi, 5);
            Assert.Equal(inputParams.DirectionTheta, outputParams.DirectionTheta, 5);
            Assert.Equal(inputParams.DirectionPhi, outputParams.DirectionPhi, 5);
        }
        public void ComputeLrtf()
        {
            ComplexLens             lens = ComplexLens.CreateDoubleGaussLens(Materials.Fixed.AIR, 4.0);
            LensRayTransferFunction lrtf = new LensRayTransferFunction(lens);
            var incomingParams           = new LensRayTransferFunction.Parameters(0.5, 0.5, 0.7000000000000004, 0.0);

            LensRayTransferFunction.Parameters outgoingParams = lrtf.ComputeLrtf(incomingParams);
            Console.WriteLine("IN: {0}", incomingParams);
            Console.WriteLine("OUT: {0}", outgoingParams);
            if (outgoingParams != null)
            {
                Console.WriteLine("  {0}", lens.ConvertParametersToFrontSurfaceRay(outgoingParams));
            }
        }
        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 SampleLrtf()
        {
            ComplexLens             lens = ComplexLens.CreateDoubleGaussLens(Materials.Fixed.AIR, 4.0);
            LensRayTransferFunction lrtf = new LensRayTransferFunction(lens);
            var defaultParameters        = new LensRayTransferFunction.Parameters(0.5, 0.5, 1.0, 0.5);
            var table = lrtf.SampleLrtf1D(defaultParameters,
                                          LensRayTransferFunction.VariableParameter.DirectionTheta, 101);

            //int i = 0;
            //foreach (LensRayTransferFunction.Parameters rayParams in table)
            //{
            //    Console.WriteLine("[{0}]: {1}", i, rayParams);
            //    if (rayParams != null)
            //    {
            //        //Console.WriteLine("  {0}", lens.ConvertParametersToFrontSurfaceRay(rayParams));
            //    }
            //    i++;
            //}
            Console.WriteLine("{{ {0} }}", string.Join(",\n", table.Select((item) => (item != null) ? item.ToString() : "Null").ToArray()));
        }
        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);
            }
        }
        public void SampleLrtfSaveLoadAndCompare()
        {
            ComplexLens             lens = ComplexLens.CreateDoubleGaussLens(Materials.Fixed.AIR, 4.0);
            LensRayTransferFunction lrtf = new LensRayTransferFunction(lens);

            int sampleCount = 16;

            var table = lrtf.SampleLrtf3D(sampleCount);

            Console.WriteLine("Size: {0}x{0}x{0}", sampleCount);

            string filename = string.Format("lrtf_double_gauss_{0}.bin", sampleCount);

            table.Save(filename);

            Console.WriteLine("Saved sampled LRTF into file: {0}", filename);

            Console.WriteLine("Trying to load sampled LRTF from file and compare...");

            var recoveredTable = LensRayTransferFunction.Table3d.Load(filename);

            Assert.Equal(sampleCount, recoveredTable.Size);

            for (int i = 0; i < sampleCount; i++)
            {
                for (int j = 0; j < sampleCount; j++)
                {
                    for (int k = 0; k < sampleCount; k++)
                    {
                        Vector4d orig      = table.Table[i, j, k];
                        Vector4d recovered = recoveredTable.Table[i, j, k];
                        AssertEqualVector4d(orig, recovered);
                    }
                }
            }

            Console.WriteLine("Compared OK");
        }