예제 #1
0
        private TracedRay trace_ray_simple(OpticalSurface surface, RayTraceResults result, TracedRay incident,
                                           Vector3Pair local, Vector3Pair intersect)
        {
            bool   right_to_left = intersect.normal().z() > 0;
            Medium prev_mat      = surface.get_material(right_to_left ? 1 : 0);
            Medium next_mat      = surface.get_material(!right_to_left ? 1 : 0);

            // check ray didn't "escaped" from its material
            // std::cout << prev_mat->name << " " << next_mat->name <<
            //          " " << incident.get_material()->name << std::endl;

            if (prev_mat != incident.get_material())
            {
                return(null);
            }

            double wl    = incident.get_wavelen();
            double index = prev_mat.get_refractive_index(wl)
                           / next_mat.get_refractive_index(wl);

            // refracted ray direction
            Vector3 direction = refract(surface, local, intersect.normal(), index);

            if (direction == null)
            {
                // total internal reflection
                Vector3   o   = intersect.origin();
                Vector3   dir = reflect(surface, local, intersect.normal());
                TracedRay r   = result.newRay(o, dir);

                r.set_wavelen(wl);
                r.set_intensity(incident.get_intensity());
                r.set_material(prev_mat);

                r.set_creator(surface);
                incident.add_generated(r);

                return(r);
            }

            // transmit
            if (!next_mat.is_opaque())
            {
                Vector3   o = intersect.origin();
                TracedRay r = result.newRay(o, direction);

                r.set_wavelen(wl);
                r.set_intensity(incident.get_intensity());
                r.set_material(next_mat);

                r.set_creator(surface);
                incident.add_generated(r);
                return(r);
            }

            // reflect
            if (next_mat.is_reflecting())
            {
                Vector3 o   = intersect.origin();
                Vector3 dir = reflect(surface, local, intersect.normal());

                TracedRay r = result.newRay(o, dir);

                r.set_wavelen(wl);
                r.set_intensity(incident.get_intensity());
                r.set_material(prev_mat);
                r.set_creator(surface);
                incident.add_generated(r);
                return(r);
            }

            return(null);
        }
예제 #2
0
 public void set_measurement_medium(Medium medium)
 {
     _measurement_medium = medium;
 }
예제 #3
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);
        }
예제 #4
0
            /**
             * Add an optical surface
             *
             * @param curvature curvature of the surface, 1/r
             * @param radius    the radius of the disk
             * @param thickness the thickness after this surface
             * @param glass     the material after this surface
             */
            public Lens.Builder add_surface(double curvature, double radius, double thickness, Medium glass)
            {
                Curve curve;

                if (curvature == 0.0)
                {
                    curve = Flat.flat;
                }
                else
                {
                    curve = new Sphere(curvature);
                }
                return(add_surface(curve, new Disk(radius), thickness,
                                   glass));
            }
예제 #5
0
            public Lens.Builder add_surface(Curve curve, Shape shape, double thickness, Medium glass)
            {
                if (glass == null)
                {
                    glass = Air.air;
                }

                OpticalSurface.Builder surface = new OpticalSurface.Builder()
                                                 .position(new Vector3Pair(new Vector3(0, 0, _last_pos), Vector3.vector3_001))
                                                 .curve(curve)
                                                 .shape(shape)
                                                 .leftMaterial(_next_mat)
                                                 .rightMaterial(glass);
                _next_mat  = glass;
                _last_pos += thickness;
                add(surface);
                return(this);
            }
예제 #6
0
 /** Get material relative refractive index in given medium at specified
  * wavelen in @em nm. */
 public virtual double get_refractive_index(double wavelen, Medium env)
 {
     return(get_refractive_index(wavelen) / env.get_refractive_index(wavelen));
 }
예제 #7
0
 public void set_material(Medium mat)
 {
     _material = mat;
 }