Example #1
0
        public static void Main(string[] args)
        {
            OpticalSystem.Builder systemBuilder = new OpticalSystem.Builder();
            Lens.Builder          lensBuilder   = new Lens.Builder()
                                                  .position(Vector3Pair.position_000_001)
                                                  .add_surface(1 / 0.031186861, 14.934638, 4.627804137,
                                                               new Abbe(Abbe.AbbeFormula.AbbeVd, 1.607170, 59.5002, 0.0))
                                                  .add_surface(0, 14.934638, 5.417429465)
                                                  .add_surface(1 / -0.014065441, 12.766446, 3.728230979,
                                                               new Abbe(Abbe.AbbeFormula.AbbeVd, 1.575960, 41.2999, 0.0))
                                                  .add_surface(1 / 0.034678487, 11.918098, 4.417903733)
                                                  .add_stop(12.066273, 2.288913925)
                                                  .add_surface(0, 12.372318, 1.499288597,
                                                               new Abbe(Abbe.AbbeFormula.AbbeVd, 1.526480, 51.4000, 0.0))
                                                  .add_surface(1 / 0.035104369, 14.642815, 7.996205852,
                                                               new Abbe(Abbe.AbbeFormula.AbbeVd, 1.623770, 56.8998, 0.0))
                                                  .add_surface(1 / -0.021187519, 14.642815, 85.243965130);
            systemBuilder.add(lensBuilder);
            Image.Builder imagePlaneBuilder = new Image.Builder()
                                              .position(new Vector3Pair(new Vector3(0, 0, 125.596), Vector3.vector3_001))
                                              .curve(Flat.flat)
                                              .shape(new Rectangle(5.0 * 2));
            systemBuilder.add(imagePlaneBuilder);

            PointSource.Builder ps =
                new PointSource.Builder(PointSource.SourceInfinityMode.SourceAtInfinity, Vector3.vector3_001)
                .add_spectral_line(SpectralLine.d)
                .add_spectral_line(SpectralLine.C)
                .add_spectral_line(SpectralLine.F);
            systemBuilder.add(ps);

            RendererSvg   renderer = new RendererSvg(800, 400);
            OpticalSystem system   = systemBuilder.build();

            Console.WriteLine(system.ToString());
            SystemLayout2D systemLayout2D = new SystemLayout2D();

            // draw 2d system layout
//        system.draw_2d_fit(renderer);
//        system.draw_2d(renderer);
            systemLayout2D.layout2d(renderer, system);

            // RayTraceParameters parameters = new RayTraceParameters(system);
            //
            // RayTracer rayTracer = new RayTracer();
            // parameters.set_default_distribution (
            //         new Distribution(Pattern.MeridionalDist, 10, 0.999));
            // // TODO set save generated state on point source
            // System.out.println(parameters.sequenceToString(new StringBuilder()).toString());
            //
            // RayTraceResults result = rayTracer.trace(system, parameters);
            // RayTraceRenderer.draw_2d(renderer, result, false, null);
            //
            Console.WriteLine(renderer.write(new StringBuilder()).ToString());
        }
Example #2
0
        public void testBasics()
        {
            OpticalSystem.Builder sys = new OpticalSystem.Builder();

            Group.Builder g1  = new Group.Builder().position(Vector3Pair.position_000_001);
            Group.Builder g21 = new Group.Builder().position(Vector3Pair.position_000_001);
            Group.Builder g22 = new Group.Builder().position(Vector3Pair.position_000_001);

            Surface.Builder s211 = new Surface.Builder().position(Vector3Pair.position_000_001)
                                   .curve(Flat.flat)
                                   .shape(Infinite.infinite);
            Surface.Builder s221 = new Surface.Builder().position(Vector3Pair.position_000_001)
                                   .curve(Flat.flat)
                                   .shape(Infinite.infinite);

            g22.add(s221);
            g1.add(g21);
            g1.add(g22);
            g21.add(s211);
            sys.add(g1);

            {
                OpticalSystem system1 = sys.build();
                Element       s211e   = system1.getGroup(0).getGroup(0).getSurface(0);
                Assert.IsTrue(s211e.local_position().isEqual(Vector3.vector3_0, 1e-10));
                Assert.IsTrue(system1.getPosition(s211e).isEqual(Vector3.vector3_0, 1e-10));
            }

            g21.localPosition(new Vector3(1, 2, 3));

            {
                OpticalSystem system1 = sys.build();
                Element       s211e   = system1.getGroup(0).getGroup(0).getSurface(0);
                Assert.IsTrue(s211e.local_position().isEqual(Vector3.vector3_0, 1e-10));
                Assert.IsTrue(system1.getPosition(s211e).isEqual(new Vector3(1, 2, 3), 1e-10));
            }

            g1.localPosition(new Vector3(3, 2, 1));

            {
                OpticalSystem system1 = sys.build();
                Element       s211e   = system1.getGroup(0).getGroup(0).getSurface(0);
                Assert.IsTrue(system1.getPosition(s211e).isEqual(new Vector3(4, 4, 4), 1e-10));
            }

            s211.localPosition(new Vector3(7, 7, 7));

            {
                OpticalSystem system1 = sys.build();
                Element       s211e   = system1.getGroup(0).getGroup(0).getSurface(0);
                Assert.IsTrue(system1.getPosition(s211e).isEqual(new Vector3(11, 11, 11), 1e-10));
            }

            {
                OpticalSystem system1 = sys.build();
                system1 = sys.updatePosition(s211, new Vector3(9, 9, 9));
                Element s211e = system1.getGroup(0).getGroup(0).getSurface(0);
                Assert.IsTrue(system1.getPosition(s211e).isEqual(new Vector3(9, 9, 9), 1e-10));
                Assert.IsTrue(s211e.local_position().isEqual(new Vector3(5, 5, 5), 1e-10));
            }

            g21.rotate(0, 0, -90);
            {
                OpticalSystem system1 = sys.build();
                Element       s211e   = system1.getGroup(0).getGroup(0).getSurface(0);
                Assert.IsTrue(system1.getPosition(s211e).isEqual(new Vector3(-1, 9, 9), 1e-10));
            }

            {
                OpticalSystem system1 = sys.build();
                system1 = sys.updatePosition(s211, new Vector3(3, 4, 5));
                Element s211e = system1.getGroup(0).getGroup(0).getSurface(0);
                Assert.IsTrue(s211e.local_position().isEqual(new Vector3(0, 1, 1), 1e-10));
            }

            g1.rotate(0, 0, 90);
            {
                OpticalSystem system1 = sys.build();
                Element       s211e   = system1.getGroup(0).getGroup(0).getSurface(0);
                Assert.IsTrue(system1.getPosition(s211e).isEqual(new Vector3(5, 2, 5), 1e-10));
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            Args arguments = Args.parseArguments(args);

            if (arguments.filename == null)
            {
                Console.WriteLine("Usage: --specfile inputfile [--scenario num] [--skew] [--output layout|spot] [--dump-system]");
                Environment.Exit(1);
            }
            OpticalBenchDataImporter.LensSpecifications specs = new OpticalBenchDataImporter.LensSpecifications();
            specs.parse_file(arguments.filename);
            OpticalSystem.Builder systemBuilder = OpticalBenchDataImporter.buildSystem(specs, arguments.scenario);
            double  angleOfView = OpticalBenchDataImporter.getAngleOfViewInRadians(specs, arguments.scenario);
            Vector3 direction   = Vector3.vector3_001;

            if (arguments.skewRays)
            {
                // Construct unit vector at an angle
                //      double z1 = cos (angleOfView);
                //      double y1 = sin (angleOfView);
                //      unit_vector = math::Vector3 (0, y1, z1);
                Matrix3 r = Matrix3.get_rotation_matrix(0, angleOfView);
                direction = r.times(direction);
            }

            PointSource.Builder ps = new PointSource.Builder(PointSource.SourceInfinityMode.SourceAtInfinity, direction)
                                     .add_spectral_line(SpectralLine.d)
                                     .add_spectral_line(SpectralLine.C)
                                     .add_spectral_line(SpectralLine.F);
            systemBuilder.add(ps);

            OpticalSystem system = systemBuilder.build();

            if (arguments.dumpSystem)
            {
                Console.WriteLine(system);
            }
            if (arguments.outputType.Equals("layout"))
            {
                RendererSvg renderer = new RendererSvg(800, 400);
                // draw 2d system layout
                SystemLayout2D systemLayout2D = new SystemLayout2D();
                systemLayout2D.layout2d(renderer, system);

                RayTraceParameters parameters = new RayTraceParameters(system);

                RayTracer rayTracer = new RayTracer();
                parameters.set_default_distribution(
                    new Distribution(Pattern.MeridionalDist, 10, 0.999));
                // TODO set save generated state on point source
                if (arguments.dumpSystem)
                {
                    Console.WriteLine(parameters.sequenceToString(new StringBuilder()).ToString());
                }
                RayTraceResults result = rayTracer.trace(system, parameters);
                RayTraceRenderer.draw_2d(renderer, result, false, null);
                Console.WriteLine(renderer.write(new StringBuilder()).ToString());
            }
            if (arguments.outputType.Equals("spot"))
            {
                RendererSvg renderer = new RendererSvg(300, 300, Rgb.rgb_black);
                renderer = new RendererSvg(300, 300, Rgb.rgb_black);
                AnalysisSpot spot = new AnalysisSpot(system);
                spot.draw_diagram(renderer, true);
                Console.WriteLine(renderer.write(new StringBuilder()).ToString());
            }
        }