Ejemplo n.º 1
0
        List <TracedRay> process_rays(Surface surface, TraceIntensityMode m, RayTraceResults result,
                                      List <TracedRay> input)
        {
            RayTraceParameters params_ = result._parameters;
            List <TracedRay>   rays    = new();

            foreach (TracedRay i in input)
            {
                TracedRay ray = i;

                Transform3 t
                    = ray.get_creator().get_transform_to(surface);
                Vector3Pair local1 = t.transform_line(ray.get_ray());

                Vector3Pair pt = surface is Stop
                    ? intersect((Stop)surface, params_, local1)
                    : intersect(surface, params_, local1);

                if (pt != null)
                {
                    result.add_intercepted(surface, ray);
                    TracedRay cray = trace_ray(surface, m, result, ray, local1, pt);
                    if (cray != null)
                    {
                        rays.Add(cray);
                    }
                }
            }

            return(rays);
        }
Ejemplo n.º 2
0
        private Vector3Pair intersect(Stop surface, RayTraceParameters params_, Vector3Pair ray)
        {
            Vector3 origin = surface.get_curve().intersect(ray);

            if (origin == null)
            {
                return(null);
            }

            Vector2 v = origin.project_xy();

            if (v.len() > surface.get_external_radius())
            {
                return(null);
            }

            bool ir = true; // FIXME _intercept_reemit || params.is_sequential ();

            if (!ir && surface.get_shape().inside(v))
            {
                return(null);
            }

            Vector3 normal = surface.get_curve().normal(origin);

            if (ray.direction().z() < 0)
            {
                normal = normal.negate();
            }

            return(new Vector3Pair(origin, normal));
        }
 public AnalysisPointImage(OpticalSystem system)
 {
     _system          = system;
     _tracer          = new RayTracer();
     _processed_trace = false;
     _image           = null;
     _intercepts      = new List <TracedRay>();
     _params          = new RayTraceParameters(system);
     _params.set_default_distribution(
         new Distribution(Pattern.HexaPolarDist, 20, 0.999));
     _params.get_default_distribution().set_uniform_pattern();
 }
Ejemplo n.º 4
0
        public List <TracedRay> generate_rays_simple(RayTraceResults result, RayTraceParameters parameters,
                                                     PointSource source, List <Element> targets)
        {
            List <TracedRay> rays = new();

            foreach (Element target in targets)
            {
                rays.AddRange(generate_rays(result, parameters, source, target, source.mode()));
            }

            return(rays);
        }
Ejemplo n.º 5
0
        public RayTraceResults trace(OpticalSystem system, RayTraceParameters parameters)
        {
            RayTraceResults result = new RayTraceResults(parameters);

            switch (parameters._intensity_mode)
            {
            case TraceIntensityMode.Simpletrace:
                if (!parameters._sequential_mode)
                {
                    //trace_template<Simpletrace> ();
                    throw new InvalidOperationException();
                }
                else
                {
                    trace_sequential(parameters._intensity_mode, parameters, result);
                }
                break;

            case TraceIntensityMode.Intensitytrace:
//                if (!parameters._sequential_mode)
//                    trace_template<Intensitytrace> ();
//                else
//                    trace_seq_template<Intensitytrace> ();
                throw new InvalidOperationException();
            //break;

            case TraceIntensityMode.Polarizedtrace:
//                if (!parameters._sequential_mode)
//                    trace_template<Polarizedtrace> ();
//                else
//                    trace_seq_template<Polarizedtrace> ();
                throw new InvalidOperationException();
                //break;
            }

            return(result);
        }
Ejemplo n.º 6
0
        private Vector3Pair intersect(Surface surface, RayTraceParameters params_, Vector3Pair ray)
        {
            Vector3 origin = surface.get_curve().intersect(ray);

            if (origin == null)
            {
                return(null);
            }

            if (!params_.get_unobstructed() &&
                !surface.get_shape().inside(origin.project_xy()))
            {
                return(null);
            }

            Vector3 normal = surface.get_curve().normal(origin);

            if (ray.direction().z() < 0)
            {
                normal = normal.negate();
            }

            return(new Vector3Pair(origin, normal));
        }
Ejemplo n.º 7
0
        void trace_sequential(RayTracer.TraceIntensityMode m, RayTraceParameters parameters, RayTraceResults result)
        {
            // stack of rays to propagate
            RayCollection[] tmp          = new[] { new RayCollection(), new RayCollection() };
            RayGenerator    rayGenerator = new RayGenerator();

            int swaped = 0;
            List <TracedRay> generated;
            List <TracedRay> source_rays = tmp[1].rays;
            List <Element>   seq         = parameters._sequence;
            Element          entrance    = null;

            // find entry element (first non source)
            for (int i = 0; i < seq.Count; i++)
            {
                if (!(seq[i] is RaySource))
                {
                    entrance = seq[i];
                    break;
                }
            }

            for (int i = 0; i < seq.Count; i++)
            {
                Element element = seq[i];

//            if (!element->is_enabled ())
//                continue;

                RayTraceResults.RaysAtElement er = result.get_element_result(element);

                generated = er._generated != null ? er._generated : tmp[swaped].rays;
                generated.Clear();

                switch (element)
                {
                case PointSource source:
                {
                    result.add_source(source);
                    List <Element> elist = new();
                    if (entrance != null)
                    {
                        elist.Add(entrance);
                    }
                    List <TracedRay> rays = rayGenerator.generate_rays_simple(result, parameters, source, elist);
                    generated.AddRange(rays);
                    break;
                }

                default:
                {
                    List <TracedRay> rays = process_rays(element, m, result, source_rays);
                    // swap ray buffers
                    generated.AddRange(rays);
                    break;
                }
                }

                source_rays = generated;
                swaped     ^= 1;
            }
        }
Ejemplo n.º 8
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());
            }
        }
Ejemplo n.º 9
0
        List <TracedRay> generate_rays(
            RayTraceResults result,
            RayTraceParameters parameters,
            PointSource source,
            Element target,
            PointSource.SourceInfinityMode mode)
        {
            if (!(target is OpticalSurface))
            {
                return(new());
            }

            OpticalSurface   target_surface = (OpticalSurface)target;
            double           rlen           = parameters.get_lost_ray_length();
            Distribution     d    = parameters.get_distribution(target_surface);
            List <TracedRay> rays = new();
            ConsumerVector3  de   = (Vector3 v) =>
            {
                Vector3 r = target_surface.get_transform_to(source).transform(v); // pattern point on target surface
                Vector3 direction;
                Vector3 position;

                switch (mode)
                {
                case PointSource.SourceInfinityMode.SourceAtFiniteDistance:
                    position  = Vector3.vector3_0;
                    direction = r.normalize();
                    break;

                default:
                case PointSource.SourceInfinityMode.SourceAtInfinity:
                    direction = Vector3.vector3_001;
                    position  = new Vector3Pair(
                        target_surface.get_position(source).minus(Vector3.vector3_001.times(rlen)),
                        Vector3.vector3_001)
                                .pl_ln_intersect(new Vector3Pair(r, direction));
                    break;
                }

                foreach (SpectralLine l in source.spectrum())
                {
                    // generated rays use source coordinates
                    TracedRay ray = result.newRay(position, direction);
                    ray.set_creator(source);
                    ray.set_intensity(l.get_intensity()); // FIXME depends on distance from
                    // source and pattern density
                    ray.set_wavelen(l.get_wavelen());
                    Medium material = source.get_material();
                    if (material == null)
                    {
                        material = Air.air; // FIXME centralize as env - original uses env proxy.
                    }

                    ray.set_material(material);
                    rays.Add(ray);
                }
            };

            target_surface.get_pattern(de, d, parameters.get_unobstructed());
            return(rays);
        }