public void setLightSourceConstructorParams(ShadowScientrace.ShadowLightSource shadowLS, XElement xel)
        {
            // STRUCTURE
            /* "dictionary name of the parameter"
             * Description of this parameters
             * used at: list of light source classes that use this parameter
             * nullable: yes if this field may be empty
             */

            /* "location"
             * The location of the light source
             * used at: all
             * nullable: no
             */
            Scientrace.Location location = this.X.getXLocation(xel, "Location", null);
            shadowLS.arguments.Add("location", location);

            /* "width" and "height"
             * The width of the light source
             * used at: random square light source
             * nullable: yes
             */
            Scientrace.Vector width = this.X.getXLocation(xel, "Width", null);
            Scientrace.Vector height = this.X.getXLocation(xel, "Height", null);
            shadowLS.arguments.Add("width", width);
            shadowLS.arguments.Add("height", height);

            /* "ray count"
             * The number of traces that will be initiated by the light source,
             		some of the rays may be split or absorbed during simulation
             * Previously called: BeamCount, but renamed to RayCount.
             * used at: SpiralLightSource
             * nullable: no
             */
            int ray_count = this.X.getXInt(xel, "RayCount", this.X.getXInt(xel, "BeamCount", 256));
            shadowLS.arguments.Add("ray_count", ray_count);

            /* "loops"
             * The number of loops the spiral makes
             * used at: SpiralLightSource
             * nullable: yes
             */
            if (this.X.hasAttribute(xel, "Loops")) {
            double? loops = this.X.getXNullDouble(xel, "Loops");
            /* MOVED TO SPIRALLIGHTSOURCE
            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")+"}.");
            } */
            shadowLS.arguments.Add("loops", loops);
            }

            /* "radius"
             * The radius for any circle shaped irradiating surface
             * used at: SpiralLightSource
             * nullable: no
             */
            double? radius = this.X.getXNullDouble(xel, "Radius");
            if (radius == null)
            radius = this.X.getXNullDouble(xel, "Diameter")/2;
            if (radius != null && radius < 0) {throw new ArgumentOutOfRangeException("Radius "+radius+" out of range");}
            shadowLS.arguments.Add("radius", radius);

            /* "distance"
             * In some cases the user might want to describe a surface/orientation where the
               rays to trace pass, but should they actually start a given distance up front.
               The distance parameter describes the distance to start "before" the given surface.
             * used at: SpiralLightSource
             * nullable: default = 0
             */
            shadowLS.arguments.Add("distance", this.X.getXDouble(xel, "Distance", 0));

            /* "weighted_intensity"
             * The intensity of the entire lightsource may be weighted/redefined by setting its intensity.
             * nullable: yes
             * used at: all
             */
            shadowLS.arguments.Add("weighted_intensity", this.X.getXNullDouble(xel, "Intensity"));

            /* "random_seed"
             * In order to make repreducable results, a randomized may be seeded
             * used at: RandomSquare
             * nullable: default = null
             */
            shadowLS.arguments.Add("random_seed", this.X.getXNullInt(xel, "RandomSeed"));

            /* "direction"
             * The direction in which the rays leave the (parallel) source
             * used at: SpiralLightSource, RandomSquare
             * nullable: no
             */
            shadowLS.arguments.Add("direction", this.X.getXUnitVectorByName(xel, "Direction", null));

            /* "orthogonal to plane in which the "circle of light" is created"
             * used at: RandomCircleLightSource
             * nullable: yes
             */
            shadowLS.arguments.Add("normal", this.X.getXUnitVectorByName(xel, "Normal", null));

            /* "orthogonal to plane about which spiral is created"
             * sued at: SpiralLightSource
             * nullable: yes
             */
            Scientrace.NonzeroVector spiral_axis = this.X.getXNzVectorByName(xel, "SpiralAxis", null);
            if (spiral_axis != null) {
            Scientrace.Plane spiralplane = Scientrace.Plane.newPlaneOrthogonalTo(location, spiral_axis);
            shadowLS.arguments.Add("spiral_plane", spiralplane);
            }

            /* "spectrum"
             * The wavelengths that are irradiated by the source with their relative intensities
             * used at: all except CustomTraces
             *
             */
            XMLSpectrumParser xsp = new XMLSpectrumParser();
            Scientrace.LightSpectrum spectrum = xsp.parseLightSpectrum(xel.Element("Spectrum"));
            //if (spectrum==null) { throw new Exception("LightSpectrum "+xel.Element("Spectrum").ToString()+" unknown"); }
            shadowLS.arguments.Add("spectrum", spectrum);

            /* "efficiency_characteristics"
             * If the performance of a cell depends on the angle of incidence or the wavelength of light, it can be defined
             * in efficiency_characteristics. The default fractions are "1" for both.
             * used at: all
             */
            XMLEfficiencyCharacteristicsParser xecp = new XMLEfficiencyCharacteristicsParser();
            Scientrace.OpticalEfficiencyCharacteristics oec = xecp.parseEfficiencyForLightSource(xel);
            shadowLS.arguments.Add("efficiency_characteristics", oec);

            /* "traces_list"
             * A generic List<Scientrace.Trace> with traces that are manually added to a lightsource.
             * used at: CustomTraces
             */
            shadowLS.arguments.Add("traces_list", this.getCustomTracesListFromXData(xel, shadowLS.env));
        }
Ejemplo n.º 2
0
        public Scientrace.SingleRaySource setSingleRayFromXData(XElement xlight, List<Scientrace.UniformTraceModifier> utms,
				Scientrace.Object3dEnvironment env)
        {
            double distance = this.X.getXDouble(xlight.Attribute("Distance"), 0);
            int beamcount = this.X.getXInt(xlight.Attribute("RayCount"), this.X.getXInt(xlight.Attribute("BeamCount"), 1));
            double minintensity = this.X.getXDouble(xlight, "MinIntensity", 0.01); //default minimum intensity for tracing set to 1%

            Scientrace.NonzeroVector light_direction = this.X.getXNzVector(xlight.Element("Direction"));
            Scientrace.Location centerloc = this.X.getXVector(xlight.Element("Location")).toLocation();
            Scientrace.Location locoffset = (light_direction.toVector().negative()*distance).toLocation(); //distance cm above surface
            Scientrace.Location loc = locoffset + centerloc;
                XMLSpectrumParser xsp = new XMLSpectrumParser();
            Scientrace.LightSpectrum spectrum = xsp.parseLightSpectrum(xlight.Element("Spectrum"));
            if (spectrum==null) { throw new Exception("LightSpectrum "+xlight.Element("Spectrum").ToString()+" unknown"); }

            Scientrace.SingleRaySource retlight = new Scientrace.SingleRaySource(new Scientrace.Line(loc, light_direction.toUnitVector()),
                beamcount, spectrum, env);

            retlight.minimum_intensity_fraction = minintensity;
            retlight.lightsource_modifiers.AddRange(utms);
            retlight.init();
            return retlight;
        }
Ejemplo n.º 3
0
        public Scientrace.SpiralLightSource setSpiralLightFromXData(XElement xlight, List<Scientrace.UniformTraceModifier> utms,
				Scientrace.Object3dEnvironment env)
        {
            /* "Spiral"
             * d class.radius, d class.loops, d distance, i beamcount, i maxinteractions, d minintensity
             * i modulomultiplier, str spectrum, vec location, vec direction */
            double radius = this.X.getXDouble(xlight.Attribute("Radius"));
                if (radius < 0) {throw new ArgumentOutOfRangeException("Radius "+radius+" out of range");}
            double distance = this.X.getXDouble(xlight.Attribute("Distance"), 0);
            int beamcount = this.X.getXInt(xlight.Attribute("RayCount"), this.X.getXInt(xlight.Attribute("BeamCount")));
            //int maxinteractions = this.X.getXInt(xlight, "MaxInteractions", 8); //default value max_interactions -> 8
            double minintensity = this.X.getXDouble(xlight, "MinIntensity", 0.2); //default minimum intensity for tracing set to 1%
            //Spiralspecific

            double loops = this.X.getXDouble(xlight, "Loops", -1);
            if (loops == -1) {
                loops = 1.0154 * Math.Pow(Math.PI*2*(1-Math.Sqrt(((double)beamcount - 1) / (double)beamcount)), -0.5);
                Console.WriteLine("Number of loops for "+beamcount+" beams set to: {"+loops.ToString("#,0.000")+"}.");
                }

            Scientrace.NonzeroVector light_direction = this.X.getXNzVector(xlight.Element("Direction"));
            Scientrace.NonzeroVector spiral_axis = this.X.getXNzVector(xlight.Element("SpiralAxis"));
            Scientrace.Location centerloc = this.X.getXVector(xlight.Element("Location")).toLocation();
            /*Scientrace.Location locoffset = (light_direction.toVector().negative()*distance).toLocation(); //distance cm above surface
            Scientrace.Location loc = locoffset + centerloc; */
                XMLSpectrumParser xsp = new XMLSpectrumParser();
            Scientrace.LightSpectrum spectrum = xsp.parseLightSpectrum(xlight.Element("Spectrum"));
            if (spectrum==null) { throw new Exception("LightSpectrum "+xlight.Element("Spectrum").ToString()+" unknown"); }

            double divangle = 0;
            double divdistance = 0;
            Scientrace.NonzeroVector divpinvec = null; //=  new Scientrace.NonzeroVector(0,1,0);
            int divsteps = 1;
            bool divincludebase = true;
            this.getDivergence(xlight, ref divangle, ref divpinvec, ref divdistance, ref divincludebase, ref divsteps);
            if (divangle > 0) {
                if (divpinvec.crossProduct(light_direction).length == 0) {
                    throw new ArgumentOutOfRangeException("divpinvec", "Divergence Pinvector ("+divpinvec.trico()+") is parallel to light directon ("+
                        light_direction.trico()+")");
                    }
                }

            // INSERT OPERATION THAT MAKES BOTH SPIRAL PLANE VECTORS ORTHOGONAL TO DIRECTION
            Scientrace.Plane spiralplane = Scientrace.Plane.newPlaneOrthogonalTo(centerloc, spiral_axis);
            //Scientrace.NonzeroVector direction = light_direction.tryToUnitVector();

            Scientrace.SpiralLightSource retlight = new Scientrace.SpiralLightSource(env, centerloc, light_direction.toUnitVector(),
                spiralplane, beamcount, radius, loops, distance, spectrum);

            /* BEFORE REMOVAL OF DISPERSION_STEPS			Scientrace.LightSource retlight = new Scientrace.SpiralLightSource(env, loc, light_direction.toUnitVector(),
                spiralplane, beamcount, radius, loops, spectrum,
                divangle, divpinvec, divdistance, divincludebase, divsteps);  */
            //retlight.max_interactions = maxinteractions;
            retlight.minimum_intensity_fraction = minintensity;
            retlight.lightsource_modifiers.AddRange(utms);
            //retlight.createStartTraces();
            return retlight;
        }
Ejemplo n.º 4
0
        /* Classes supporthing the creation of the lightsource */
        public Scientrace.LightSource setRandomCylinderLightFromXData(XElement xlight, 
												Scientrace.Object3dEnvironment env)
        {
            //Reading LightSource parameters from XML-element

            /* "RandomCylinder"
             * d class.radius, d distance, i beamcount, i maxinteractions, d minintensity
             * str spectrum, vec location, vec direction */
            double radius = this.X.getXDouble(xlight.Attribute("Radius"));
                if (radius <= 0) {throw new ArgumentOutOfRangeException("Radius "+radius+" out of range");}
            double distance = this.X.getXDouble(xlight.Attribute("Distance"), 0);
            int beamcount = this.X.getXInt(xlight.Attribute("RayCount"), this.X.getXInt(xlight.Attribute("BeamCount")));
            //int maxinteractions = this.X.getXInt(xlight.Attribute("MaxInteractions"), 8); //default value max_interactions -> 8
            double minintensity = this.X.getXDouble(xlight.Attribute("MinIntensity"), 0.01); //default minimum intensity for tracing set to 1%

            Scientrace.Vector light_direction = this.X.getXVector(xlight.Element("Direction"));
            Scientrace.Location centerloc = this.X.getXVector(xlight.Element("Location")).toLocation();
            Scientrace.Location locoffset = (light_direction.negative()*distance).toLocation(); //distance cm above surface
            Scientrace.Location loc = locoffset + centerloc;
                XMLSpectrumParser xsp = new XMLSpectrumParser();
            Scientrace.LightSpectrum spectrum = xsp.parseLightSpectrum(xlight.Element("Spectrum"));

            Scientrace.LightSource retlight = new Scientrace.RandomCircleLightSource(env,
                loc, light_direction.tryToUnitVector(),
                new Scientrace.Plane(new Scientrace.Location(0,0,0),new Scientrace.NonzeroVector(1, 0, 0), new Scientrace.NonzeroVector(0,0,1)),
                radius, beamcount, spectrum);
            //retlight.max_interactions = maxinteractions;
            retlight.minimum_intensity_fraction = minintensity;
            return retlight;
        }