public ParallelRandomSquareLightSource(ShadowScientrace.ShadowLightSource shadowObject)
            : base(shadowObject)
        {
            int? random_seed = shadowObject.getNInt("random_seed");
            Scientrace.Location location = shadowObject.getLocation("location"); //corner
            Scientrace.UnitVector direction = shadowObject.getUnitVector("direction");
            int ray_count = shadowObject.getInt("ray_count"); //linecount,
            this.distance = shadowObject.getDouble("distance", 0);//distance,

            //This line has been moved to the LightSource parent shadowconstructor
            //Scientrace.LightSpectrum spectrum = (Scientrace.LightSpectrum)shadowObject.getObject("spectrum"); //spectrum

            Scientrace.Vector width = shadowObject.getVector("width");//urange,
            Scientrace.Vector height = shadowObject.getVector("height");//vrange,

            Random randNum;
            if (random_seed == null || random_seed== -1)
            randNum = new Random();
            else
            randNum = new Random((int)random_seed);

            for (int iline = 0; iline < ray_count; iline++) {
            Scientrace.Line line = new Scientrace.Line(location+(width*randNum.NextDouble()+(height*randNum.NextDouble())).toLocation(), direction);
            // THIS IS BEING DONE BY THE PARENT LIGHTSOURCE CLASS ALREADY: line.startingpoint = line.startingpoint - (direction.toLocation()*distance);
            Scientrace.Trace newtrace = new Scientrace.Trace(spectrum.wl(iline), this, line, env, spectrum.it(iline), spectrum.it(iline));
            newtrace.traceid = "RS"+(random_seed==null?"r":random_seed.ToString())+"-"+iline;
            this.addTrace(newtrace);
            } //end for
        }
Esempio n. 2
0
        /*
        public FresnelLensRing(Object3dCollection parent, MaterialProperties mprops,
            Scientrace.Location lens_sphere_location, double lens_sphere_radius,
            double lens_sphere_radians_min, double lens_sphere_radians_max,
            Scientrace.UnitVector orientation_from_sphere_center) : base (parent, mprops) {
        this.paramInit(lens_sphere_location, lens_sphere_radius, lens_sphere_radians_min, lens_sphere_radians_max, orientation_from_sphere_center);
        }

        /// <summary>
        /// Factory method that creates a new FresnelLensRing based on the properties of another FresnelLensRing
        /// but mirrored about the flat plane (flatBottomBorder).
        /// </summary>
        /// <returns>
        /// The new FresnelLensRing
        /// </returns>
        /// <param name='aFresnelLensRing'>
        /// A FresnelLensRing to base the (copied) properties upon.
        /// </param>
        public static FresnelLensRing newOppositeDirectionRing(FresnelLensRing aFresnelLensRing) {
        Object3dCollection parent = aFresnelLensRing.parent;
        MaterialProperties mprops = aFresnelLensRing.materialproperties;
        Scientrace.Location lens_sphere_location = aFresnelLensRing.sphereLoc + (aFresnelLensRing.orientation*aFresnelLensRing.getDistanceToPlanoCenter()*2);
        double lens_sphere_radius = aFresnelLensRing.sphereRadius;
        double lens_sphere_radians_min = aFresnelLensRing.radiansMin;
        double lens_sphere_radians_max = aFresnelLensRing.radiansMax;
        Scientrace.UnitVector orientation_from_sphere_center = aFresnelLensRing.orientation.negative();
        return new FresnelLensRing(parent, mprops, lens_sphere_location, lens_sphere_radius, lens_sphere_radians_min, lens_sphere_radians_max, orientation_from_sphere_center);
        } */
        public FresnelLensRing(ShadowScientrace.ShadowObject3d shadowObject)
            : base(shadowObject)
        {
            switch (shadowObject.factory_id) {
            case "SphereCenterAndRadians": this.shadowFac_SphereCenter_And_Radians(shadowObject);
                break;
            case "PlanoCenterAndRadians": this.shadowFac_PlanoCenter_And_Radians(shadowObject);
                break;
            default:
                throw new ArgumentOutOfRangeException("Factory method {"+shadowObject.factory_id+"} not found for "+shadowObject.typeString());
            }

            //General stuff:
            this.x3dCurvedSegments = shadowObject.getInt("draw_3d_segment_linecount", this.x3dCurvedSegments);
        }
        public RandomCircleLightSource(ShadowScientrace.ShadowLightSource shadowObject)
            : base(shadowObject)
        {
            int? random_seed = shadowObject.getNInt("random_seed");
            Scientrace.Location location = shadowObject.getLocation("location"); //corner
            Scientrace.UnitVector direction = shadowObject.getUnitVector("direction");
            Scientrace.UnitVector normal = shadowObject.getUnitVector("normal");
            // if normal is not defined, use the beam direction as the surface normal.
            if (normal == null) normal = direction;
            int ray_count = shadowObject.getInt("ray_count"); //linecount,
            this.distance = shadowObject.getDouble("distance", 0);//distance,

            //This line has been moved to the LightSource parent shadowconstructor
            //Scientrace.LightSpectrum spectrum = (Scientrace.LightSpectrum)shadowObject.getObject("spectrum"); //spectrum

            double radius = shadowObject.getDouble("radius");//urange,

            Random randNum;
            if (random_seed == null || random_seed== -1)
            randNum = new Random();
            else
            randNum = new Random((int)random_seed);

            Scientrace.Plane plane = Scientrace.Plane.newPlaneOrthogonalTo(location, normal);
            Scientrace.UnitVector urange, vrange;
            double r1, r2;
            urange = plane.u.toUnitVector();
            vrange = plane.v.toUnitVector();
            Scientrace.Line line;
            for (int iline = 0; iline < ray_count; iline++) {
            r1 = 1-randNum.NextDouble()*2;
            r2 = 1-randNum.NextDouble()*2;
            if (Math.Pow(r1,2)+Math.Pow(r2,2)<1) {
                line = new Scientrace.Line(location+((urange*r1*radius)+(vrange*r2*radius)).toLocation(),direction);
                // THIS IS BEING DONE BY THE PARENT LIGHTSOURCE CLASS ALREADY: line.startingpoint = line.startingpoint - (direction.toLocation()*distance);
                } else {
                iline--;
                continue;
                }
            double wavelength = spectrum.wl(iline);
            double intensity = spectrum.it(iline);
            Scientrace.Trace newtrace = new Scientrace.Trace(wavelength, this, line, env, intensity, intensity);
            newtrace.traceid = "RS"+(random_seed==null?"r":random_seed.ToString())+"-"+iline;
            this.addTrace(newtrace);
            }
        }