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); } } }
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 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); }
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)); } }
static void Main(string[] args) { //ComplexLens lens = ComplexLens.CreateDoubleGaussLens(Materials.Fixed.AIR, 4.0); //string lensName = "double_gauss"; ComplexLens lens = ComplexLens.CreatePetzvalLens(Materials.Fixed.AIR, 4.0); string lensName = "petzval"; //ComplexLens lens = ComplexLens.CreateBiconvexLens(150, 100, 0); //string lensName = "biconvex"; LensRayTransferFunction lrtf = new LensRayTransferFunction(lens); int sampleCount = 128; Stopwatch stopwatch = Stopwatch.StartNew(); var table = lrtf.SampleLrtf3D(sampleCount); stopwatch.Stop(); //for (int i = 0; i < sampleCount; i++) //{ // for (int j = 0; j < sampleCount; j++) // { // for (int k = 0; k < sampleCount; k++) // { // var value = new LensRayTransferFunction.Parameters(table.Table[i, j, k]); // Console.WriteLine((value != null) ? value.ToString() : "null"); // } // Console.WriteLine(); // } //} Console.WriteLine("Size: {0}x{0}x{0}, elapsed time: {1} ms", sampleCount, stopwatch.ElapsedMilliseconds); string filename = string.Format(@"data\lrtf_{0}_{1}.bin", lensName, sampleCount); stopwatch.Reset(); stopwatch.Start(); table.Save(filename); stopwatch.Stop(); Console.WriteLine("Saved sampled LRTF into file: {0}, elapsed time: {1} ms", filename, stopwatch.ElapsedMilliseconds); }
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"); }
public ComplexLensLrtfForm() { InitializeComponent(); SetDoubleBuffered(posThetaPanel); SetDoubleBuffered(posPhiPanel); SetDoubleBuffered(dirThetaPanel); SetDoubleBuffered(dirPhiPanel); variableParameterComboBox.DataSource = Enum.GetValues( typeof(LensRayTransferFunction.VariableParameter)); variableParameterComboBox.SelectedItem = LensRayTransferFunction.VariableParameter.DirectionTheta; complexLenses = CreateLenses(); lrtf = new LensRayTransferFunction(complexLenses[0]); lensComboBox.Items.AddRange(new[] { "Double Gauss", "Petzval", "Biconvex" }); lensComboBox.SelectedIndex = 0; sampleCountNumeric.Value = 256; initialized = true; Recompute(); }