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; }
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); }