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
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        public LightSource(ShadowScientrace.ShadowLightSource aShadowLightSource)
        {
            this.setObjectEnvironment(aShadowLightSource.env);
            this.minimum_intensity_fraction = aShadowLightSource.getDouble("minimum_intensity_fraction", this.minimum_intensity_fraction);
            this.addTraceModifiers((IEnumerable<Scientrace.UniformTraceModifier>)aShadowLightSource.getObject("trace_modifiers", true));

            //AND it was put back like a normal ShadowClass object...
            //this.spectrum = aShadowLightSource.spectrum;
            this.spectrum = (Scientrace.LightSpectrum)aShadowLightSource.getObject("spectrum", !this.mandatory_spectrum);

            if (spectrum == null)
            Console.WriteLine("WARNING: No spectrum given.");
            this.efficiency_characteristics = (Scientrace.OpticalEfficiencyCharacteristics)aShadowLightSource.getObject("efficiency_characteristics");

            this.weighted_intensity = (double)(aShadowLightSource.getNDouble("weighted_intensity") ?? this.spectrum.total_intensity);
        }
예제 #4
0
        public SpiralLightSource(ShadowScientrace.ShadowLightSource shadowObject)
            : base(shadowObject)
        {
            int ray_count = (int)shadowObject.getObject("ray_count");
            double loops = shadowObject.getDouble("loops", -1);
            if (loops == -1) {
            loops = 1.0154 * Math.Pow(Math.PI*2*(1-Math.Sqrt(((double)ray_count - 1) / (double)ray_count)), -0.5);
            Console.WriteLine("Number of loops for "+ray_count+" beams set to: {"+loops.ToString("#,0.000")+"}.");
            }

            this.paramInit(
            (Scientrace.Location)shadowObject.getObject("location"), //center
            (Scientrace.UnitVector)shadowObject.getObject("direction"),//direction,
            (Scientrace.Plane)shadowObject.getObject("spiral_plane"),//plane,
            ray_count,//linecount,
            (double)shadowObject.getObject("radius"),//radius,
            loops,//loops,
            (double)shadowObject.getObject("distance")//distance,
            //(Scientrace.LightSpectrum)shadowObject.getObject("spectrum")//spectrum
            );
        }
예제 #5
0
        /// <summary>
        /// Required parameters:
        /// (Location) lens_plano_center, 
        /// (double) lens_radius
        /// (double) var_rings_count   double value instead of int, so the ring may end in a ring-fraction
        /// (NonzeroVector) focal_vector
        /// (double) refractive_index derived from SO3D at a given wavelength (600E-9 by default)
        /// </summary>
        /// <param name='shadowObject'>
        /// Shadow object containing parameters from summary.
        /// </param>
        protected void shadowFac_VariusRadii_and_EqualWidthRings(ShadowScientrace.ShadowObject3d ringTemplateSO3D)
        {
            //Console.WriteLine("CREATING EQUAL WIDTH RINGS");
            //User values(s)
            //NOT USED: Scientrace.Location lens_plano_center = (Scientrace.Location)shadowObject.getObject("lens_plano_center");

            //NOT USED: double lens_sphere_radius = (double)shadowObject.getObject("lens_sphere_radius");

            //NOT USED: Scientrace.UnitVector orientation_from_sphere_center = (Scientrace.UnitVector)shadowObject.getObject("orientation_from_sphere_center");

            double radius = ringTemplateSO3D.getDouble("lens_radius");

            double ring_count = ringTemplateSO3D.getDouble("var_rings_count");
            //construct by creating FresnelLensRing Object3D instances and adding them to collection

            double ring_width = radius/ring_count;

            double focal_length = ringTemplateSO3D.getDouble("focal_length");

            double focus_wavelength = ringTemplateSO3D.getDouble("focus_wavelength", 600E-9);
            double refindex = ringTemplateSO3D.materialprops.refractiveindex(focus_wavelength);

            for (double iring = 0; iring <= ring_count - 1; iring += 1) {
            double rmin = iring*ring_width;
            double rmax = Math.Min(iring+1, ring_count)*ring_width;
            double ravg = (rmin+rmax) / 2;

                        double ring_sphere_radius = FresnelLens.GetOptimalRingSphereRadius(focal_length, ravg, refindex, rmax);
            //Console.WriteLine("Radius "+iring+ ": {"+ring_sphere_radius+"}, rmin: {"+rmin+"}, rmax: {"+rmax+"}, xy_ratio: {"+xy_ratio+"}");

            ShadowScientrace.ShadowObject3d so3d = new ShadowScientrace.ShadowObject3d(ringTemplateSO3D);
            so3d.factory_id = "PlanoCenterAndRadians";
            so3d.arguments["lens_sphere_radians_min"] = FresnelLensRing.RadiansForRadii(ring_sphere_radius, rmin);
            so3d.arguments["lens_sphere_radians_max"] = FresnelLensRing.RadiansForRadii(ring_sphere_radius, rmax);
            so3d.arguments["lens_sphere_radius"] = ring_sphere_radius;
            so3d.parent = this;
            new FresnelLensRing(so3d);
            }
        }
예제 #6
0
        /// <summary>
        /// Required parameters:
        /// (double)focal_length
        /// (Location)lens_center
        /// (NonzeroVector)optical_axis
        /// (double)lens_diameter
        /// </summary>
        /// <param name='shadowObject'>
        /// Shadow object containing parameters from summary.
        /// </param>
        protected void shadowFac_FocalLength_and_Diameter(ShadowScientrace.ShadowObject3d shadowObject)
        {
            //User values(s)
            double focalLength = (double)shadowObject.getObject("focal_length");
            Scientrace.Location lensCenter = (Scientrace.Location)shadowObject.getObject("lens_center");
            Scientrace.NonzeroVector lensPlaneNormal = (Scientrace.NonzeroVector)shadowObject.getObject("optical_axis");
            double lensDiameter = (double)shadowObject.getObject("lens_diameter");

            //Derived value from 1/f = (n-1)(1/r1+1/r2)
            double focus_wavelength = shadowObject.getDouble("focus_wavelength", 600E-9);
            double sphereRadii = 2*focalLength*(shadowObject.materialprops.refractiveindex(focus_wavelength)-1);

            //construct!
            this.initWithLensDiameter(lensCenter, lensPlaneNormal, lensDiameter, sphereRadii, sphereRadii);
        }