Exemplo n.º 1
0
        public void testShapes()
        {
            for (int i = 0; i < st.Length; i++)
            {
                shape_test_s s = st[i];

                string fname = String.Format("test_shape_{0}.svg", s.name);

                RendererSvg      rsvg = new RendererSvg(800, 600, Rgb.rgb_black);
                RendererViewport r    = rsvg;

                r.set_window(Vector2.vector2_0, 70.0, true);

                {
                    ConsumerTriangle2 d = (Triangle2 t) => {
                        r.draw_triangle(t, true, new Rgb(.2, .2, .2, 1.0));
                        r.draw_triangle(t, false, Rgb.rgb_gray);
                    };
                    s.s.get_triangles(d, 10.0);
                }

                for (int c = 0; c < s.s.get_contour_count(); c++)
                {
                    List <Vector2>  poly = new ();
                    PatternConsumer d    = (Vector2 v) => {
                        poly.Add(v);
                    };
                    s.s.get_contour(c, d, 10.0);
                    r.draw_polygon(poly.ToArray(), Rgb.rgb_yellow, false, true);
                }

                for (double a = 0; a < 2.0 * Math.PI - 1e-8; a += 2.0 * Math.PI / 50.0)
                {
                    Vector2 d = new Vector2(Math.Cos(a), Math.Sin(a));

                    double ro = s.s.get_outter_radius(d);
                    r.draw_point(d.times(ro), Rgb.rgb_magenta, Renderer.PointStyle.PointStyleCross);
                    double rh = s.s.get_hole_radius(d);
                    r.draw_point(d.times(rh), Rgb.rgb_cyan, Renderer.PointStyle.PointStyleCross);
                }

                r.draw_circle(Vector2.vector2_0, s.s.max_radius(), Rgb.rgb_red, false);
                r.draw_circle(Vector2.vector2_0, s.s.min_radius(), Rgb.rgb_blue, false);

                r.draw_box(s.s.get_bounding_box(), Rgb.rgb_cyan);

                {
                    PatternConsumer d = (Vector2 v) => {
                        r.draw_point(v, Rgb.rgb_green, Renderer.PointStyle.PointStyleDot);
                    };
                    Distribution dist = new Distribution();
                    ((ShapeBase)s.s).get_base_pattern(d, dist, false);
                }

                Console.WriteLine(rsvg.write(new StringBuilder()).ToString());
            }
        }
Exemplo n.º 2
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());
        }
Exemplo n.º 3
0
        void draw_2d(RendererSvg r, OpticalSystem system)
        {
            // optical axis
            Vector3Pair b = system.get_bounding_box();

            r.draw_segment(new Vector2Pair(new Vector2(b.v0.z(), 0.0), new Vector2(b.v1.z(), 0.0)), Rgb.rgb_gray);

            foreach (Element e in system.elements())
            {
                draw_element_2d(r, e, null);
            }
        }
Exemplo n.º 4
0
 public void layout2d(RendererSvg r, OpticalSystem system)
 {
     draw_2d_fit(r, system);
     draw_2d(r, system);
 }
Exemplo n.º 5
0
 void draw_2d_fit(RendererSvg r, OpticalSystem system)
 {
     draw_2d_fit(r, system, true);
 }
Exemplo n.º 6
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());
            }
        }