示例#1
0
        TracedRay trace_ray(Surface surface, TraceIntensityMode m,
                            RayTraceResults result, TracedRay incident,
                            Vector3Pair local,
                            Vector3Pair pt)
        {
            incident.set_len((pt.origin().minus(local.origin())).len());
            incident.set_intercept(surface, pt.origin());

            if (m == TraceIntensityMode.Simpletrace)
            {
                incident.set_intercept_intensity(1.0);
                return(trace_ray_simple(surface, result, incident, local, pt));
            }
            else
            {
                // apply absorbtion from current material
                double i_intensity
                    = incident.get_intensity()
                      * incident.get_material().get_internal_transmittance(
                          incident.get_wavelen(), incident.get_len());

                incident.set_intercept_intensity(i_intensity);

                // FIXME
//            if (i_intensity < _discard_intensity)
//                return;

                if (m == TraceIntensityMode.Intensitytrace)
                {
                    return(trace_ray_intensity(surface, result, incident, local, pt));
                }
                else if (m == TraceIntensityMode.Polarizedtrace)
                {
                    return(trace_ray_polarized(surface, result, incident, local, pt));
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }
        }
示例#2
0
        TracedRay trace_ray_simple(Stop surface, RayTraceResults result, TracedRay incident, Vector3Pair local,
                                   Vector3Pair intersect)
        {
            Vector2 v = intersect.origin().project_xy();

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

            if (ir && surface.get_shape().inside(v))
            {
                // re-emit incident ray
                TracedRay r = result.newRay(intersect.origin(), incident.get_ray().direction());

                r.set_wavelen(incident.get_wavelen());
                r.set_intensity(incident.get_intensity());
                r.set_material(incident.get_material());
                r.set_creator(surface);

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

            return(null);
        }
示例#3
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);
        }