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));
            }
        }
Пример #2
0
        private void DrawRays(Graphics g, Func <Vector3d, Point> projFunc)
        {
            // draw incoming ray
            if (incomingRay.Direction != Vector3d.Zero)
            {
                Point origin = projFunc(incomingRay.Origin);
                Point target;
                if (inputLensPosDirectly)
                {
                    if (outgoingRay != null)
                    {
                        target = projFunc(backLensPos);
                    }
                    else
                    {
                        target = projFunc(incomingRay.Origin + 1000 * Vector3d.Normalize(incomingRay.Direction));
                    }
                }
                else
                {
                    target = projFunc(incomingRay.Origin - 100 * Vector3d.Normalize(incomingRay.Direction));
                }
                g.DrawLine(Pens.Green, origin, target);

                //var parameters = complexLens.ConvertBackSurfaceRayToParameters(incomingRay);
                //var recoveredRay = complexLens.ConvertParametersToBackSurfaceRay(parameters);
                //if (recoveredRay.Direction != Vector3d.Zero)
                //{
                //    origin = projFunc(recoveredRay.Origin);
                //    target = projFunc(recoveredRay.Origin + 1000 * Vector3d.Normalize(recoveredRay.Direction));
                //    //g.DrawLine(Pens.Orange, origin, target);
                //}
            }

            if (backLensPos != Vector3d.Zero)
            {
                FillSquare(g, Brushes.Red, projFunc(backLensPos), 3);
            }

            // draw outgoing ray
            if ((outgoingRay != null) && (outgoingRay.Direction != Vector3d.Zero))
            {
                Point origin = projFunc(outgoingRay.Origin);
                Point target = projFunc(outgoingRay.Origin + 1000 * Vector3d.Normalize(outgoingRay.Direction));
                g.DrawLine(Pens.Brown, origin, target);
                //g.DrawLine(Pens.DarkGreen, projFunc(backLensPos), origin);

                //// draw normal
                //g.DrawLine(Pens.Purple, origin, projFunc(outgoingRay.Origin + 20 * -complexLens.ElementSurfaces.Last().SurfaceNormalField.GetNormal(outgoingRay.Origin)));

                //// draw normal
                //g.DrawLine(Pens.Purple, projFunc(backLensPos), projFunc(backLensPos + 20 * -complexLens.ElementSurfaces.First().SurfaceNormalField.GetNormal(backLensPos)));

                // test ray->parameters->ray:
                //var parameters = complexLens.ConvertFrontSurfaceRayToParameters(outgoingRay);
                //var recoveredRay = complexLens.ConvertParametersToFrontSurfaceRay(parameters);
                //if (recoveredRay.Direction != Vector3d.Zero)
                //{
                //    origin = projFunc(recoveredRay.Origin);
                //    target = projFunc(recoveredRay.Origin + 1000 * Vector3d.Normalize(recoveredRay.Direction));
                //    g.DrawLine(Pens.Orange, origin, target);
                //}

                // test LRTF without rotation:

                //var outgoingParams = lrtf.ComputeLrtf(GetIncomingParams());
                //var outgoingRayFromLrtf = complexLens.ConvertParametersToFrontSurfaceRay(outgoingParams);
                //if (outgoingRayFromLrtf.Direction != Vector3d.Zero)
                //{
                //    origin = projFunc(outgoingRayFromLrtf.Origin);
                //    target = projFunc(outgoingRayFromLrtf.Origin + 1000 * Vector3d.Normalize(outgoingRayFromLrtf.Direction));
                //    g.DrawLine(Pens.Orange, origin, target);
                //}

                var incomingParams = GetIncomingParams();

                // test LRTF with rotation:
                //var positionPhi = incomingParams.PositionPhi;
                //incomingParams.PositionPhi = 0;

                //var outgoingParams = lrtf.ComputeLrtf(incomingParams);

                //outgoingParams.PositionPhi += positionPhi;

                if (showAlsoLrtf)
                {
                    // test LRTF evaluated from a precomputed table
                    var outgoingParams = lrtfTable.EvaluateLrtf3D(incomingParams);

                    var outgoingRayFromLrtf = complexLens.ConvertParametersToFrontSurfaceRay(outgoingParams);
                    if (outgoingRayFromLrtf.Direction != Vector3d.Zero)
                    {
                        origin = projFunc(outgoingRayFromLrtf.Origin);
                        target = projFunc(outgoingRayFromLrtf.Origin + 1000 * Vector3d.Normalize(outgoingRayFromLrtf.Direction));
                        g.DrawLine(Pens.Orange, origin, target);
                    }
                }
            }

            // draw ray inside lens
            if (intersections != null)
            {
                for (int i = 0; i < intersections.Count - 1; i++)
                {
                    Point origin = projFunc(intersections[i]);
                    Point target = projFunc(intersections[i + 1]);
                    g.DrawLine(Pens.Brown, origin, target);
                }
            }
        }