public RayTraceParameters(OpticalSystem system)
        {
            this._sequence         = new List <Element>();
            this._sequential_mode  = true;
            this._intensity_mode   = RayTracer.TraceIntensityMode.Simpletrace;
            this._propagation_mode = PropagationMode.RayPropagation;
            this._max_bounce       = 50;
            this._unobstructed     = false;
            this._lost_ray_length  = 1000;
            foreach (Element e in system.elements())
            {
                add(e);
            }

            _sequence.Sort((a, b) =>
            {
                double z1 = a.get_position().z();
                double z2 = b.get_position().z();
                if (z1 > z2)
                {
                    return(1);
                }
                else if (z1 < z2)
                {
                    return(-1);
                }
                else
                {
                    return(0);
                }
            });
            this._default_distribution = new Distribution(Pattern.MeridionalDist, 10, 0.999);
        }
Esempio n. 2
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;
            }
        }