public Intersection intersectsObject(Trace trace, Object3d o3dWithThisBorder) { Intersection retIntersection = this.intersects(trace); retIntersection.object3d = o3dWithThisBorder; return(retIntersection); }
public Spot(Scientrace.Location loc, Object3d object3d, double intensity, double intensityFraction, Scientrace.Trace trace) { this.loc = loc; this.object3d = object3d; this.object3d.spotted(intensity); this.intensity = intensity; this.intensityFraction = intensityFraction; this.trace = trace; this.fillPolVecs(); }
public Spot(Scientrace.Spot copyFromSpot) { this.loc = new Scientrace.Location(copyFromSpot.loc); this.object3d = copyFromSpot.object3d; // do not spot again, so don't recall spotted from object3d this.intensity = copyFromSpot.intensity; this.trace = copyFromSpot.trace; this.intensityFraction = copyFromSpot.intensityFraction; this.fillPolVecs(); }
public List <ObjectLinePiece> toOLP(List <LinePiece> aList, string colour, Object3d anO3D) { List <ObjectLinePiece> olplist = new List <ObjectLinePiece>(); foreach (LinePiece anLP in aList) { ObjectLinePiece anOLP = new ObjectLinePiece(); anOLP.o3d = anO3D; anOLP.lp = anLP; anOLP.col = colour; olplist.Add(anOLP); } return(olplist); }
/* public void reflect(Scientrace.Trace trace, Scientrace.Intersection intrs) { * * }*/ public bool attachedTo(Object3d object3d) { if ((this.GetType() == typeof(AttachedObject3dCollection)) || object3d.GetType() == typeof(AttachedObject3dCollection)) { return(false); } AttachedObject3dCollection aoc = null; Object3d tobject1 = this; while (tobject1.parent != null) { if (typeof(AttachedObject3dCollection).IsAssignableFrom(tobject1.parent.GetType())) { //Console.WriteLine(tobject1.parent.GetType()+" is attacheble"); //if (tobject1.parent.GetType() == typeof(AttachedObject3dCollection)) { aoc = (AttachedObject3dCollection)tobject1.parent; //Console.WriteLine(tobject1.parent.GetType()); break; } else { tobject1 = tobject1.parent; } } //end while if (aoc == null) { return(false); } Object3d tobject2 = object3d; while (tobject2.parent != null) { if (typeof(AttachedObject3dCollection).IsAssignableFrom(tobject2.parent.GetType())) { //if (tobject2.parent.GetType() == typeof(AttachedObject3dCollection)) { //Console.WriteLine("********** ATTACHED OBJECTS "+this+" & "+object3d); return(tobject2.parent == aoc); } else { tobject2 = tobject2.parent; } } //end while return(false); }
/// <summary> /// Initializes a new instance of the <see cref="Scientrace.DielectricSurfaceInteraction"/> class. /// </summary> /// <param name="incoming_trace">Incoming trace.</param> /// <param name="interaction_loc">Interaction location.</param> /// <param name="surface_normal">Surface normal.</param> /// <param name="refindex_from">Refractive index for the current volume</param> /// <param name="refindex_to">Refractive index on the other side of the surface</param> /// <param name="static_absorption_fraction">If absorption at a surface occurs, this fraction is larger than 0.0. A black surface has full=1.0 absorption.</param> public DielectricSurfaceInteraction(Trace aTrace, Location interaction_loc, UnitVector surface_normal, double refindex_from, double refindex_to, Object3d object_to) { // Store all starting conditions this.trace_in = aTrace; this.intensity_in = aTrace.intensity; this.object_to = object_to; this.n_i = refindex_from; this.n_t = refindex_to; this.dir_i = aTrace.traceline.direction; // Make sure the surface normal is oriented in the right direction this.surface_normal = surface_normal.orientedAgainst(this.dir_i).tryToUnitVector(); this.interaction_loc = interaction_loc; // Define the "orthogonal to the plane - s" polarisation vector direction // Replaced "safeNormalised" method commented out below // At normal incidence, you want to retain the polarisation vectors of the trace for the best results Scientrace.Vector out_of_plane_vec = this.surface_normal.crossProduct(this.dir_i); if (out_of_plane_vec.length < 1E-9) out_of_plane_vec = new Vector(this.trace_in.getPolarisationDir1()); this.dir_s = out_of_plane_vec.tryToUnitVector(); //this.dir_s = this.surface_normal.safeNormalisedCrossProduct(this.dir_i); // Define the "in the plane - p" polarisation vector direction this.dir_ip = this.dir_s.crossProduct(this.dir_i).tryToUnitVector(); this.in_projection = this.dir_i.projectOnPlaneWithNormal(this.surface_normal); //First, calculate all properties concerning the incoming trace this.applySnellius(); this.calcIncomingAmplitudes(); //Before doing anything else, ABSORP the static surface absorption. this.subtractStaticAbsorption(); // If the trace has ended due to total absorption it ends here. if (this.total_absorption) return; //Now calculate all that other stuff. this.calcResultingAmplitudes(); this.calcResultingIntensities(); if (Math.Abs(1 - (this.intc_rp + this.intc_tp)) > 1E-9) throw new Exception("p-polarisation fractions don't add op to 1 (rp: "+this.intc_rp+" tp:"+this.intc_tp+")"); if (Math.Abs(1 - (this.intc_rs + this.intc_ts)) > 1E-9) throw new Exception("s-polarisation fractions don't add op to 1 (rs: "+this.intc_rs+" ts:"+this.intc_ts+")"); this.calcResultingDirections(); //this.debugOutput(); } //end of constructor
public Intersection intersectsObject(Trace trace, Object3d o3dWithThisBorder) { PlaneBorder aBorder = this; if (trace.traceline.direction.dotProduct(aBorder.getNormal()) == 0) { return(Intersection.notIntersect(o3dWithThisBorder)); //trace is parallel to plane, will not intersect. } Scientrace.Location intersectLoc = aBorder.intersectsAt(trace.traceline); if (intersectLoc == null) { return(Intersection.notIntersect(o3dWithThisBorder)); //trace is parallel to plane, will not intersect. } return(new Intersection(true, o3dWithThisBorder, intersectLoc, new Scientrace.FlatShape2d(this.tPlane), null, this.contains(trace.traceline.startingpoint))); }
public void addCommonObjectProperties(Scientrace.Object3d anObject, XElement xel) { XAttribute tag = xel.Attribute("Tag"); if (tag != null) { anObject.tag = tag.Value; //Console.WriteLine("TAG SET: "+anObject.tag); } XAttribute priority = xel.Attribute("ParseOrder"); if (priority != null) { anObject.parseOrder = Convert.ToDouble(priority.Value); //Console.WriteLine("ParseOrder adjusted: "+anObject.parseOrder); } }
public Object3dCollection getFirstNonVirtualParent() { Object3d tobject1 = this; while (tobject1.parent != null) { if (tobject1.parent.virtualCollection == false) { //Console.WriteLine(this.tag+" returns "+tobject1.parent.tag); return(tobject1.parent); } else { tobject1 = tobject1.parent; } } throw new Exception("The top parent (environment) should always be non-virtual"); }
/* * !!!!!!!!!!!!!!THIS METHOD IS DEPRECATED AS THE FORK METHOD SHOULD BE USED TO PREVENT INFINITE LOOPS!!!!!!!!!!! * /// <summary> * /// This constructor method clones the original trace parameters to a new trace instance but changes the traceline * /// value to the newLine values. * /// </summary> * /// <param name="aTrace"> * /// A <see cref="Scientrace.Trace"/> * /// </param> * /// <param name="newLine"> * /// A <see cref="Scientrace.Line"/> * /// </param> * public Trace(Scientrace.Trace aTrace, Scientrace.Line newLine) { * this.init(aTrace.wavelenght, aTrace.lightsource, newLine, aTrace.currentObject, aTrace.intensity, aTrace.original_intensity); * } */ /* public Trace(double wlength, LightSource lsource, Scientrace.Line line, Scientrace.Object3d currentObject) { * //default start-intensity of 1 * this.init(wlength, lsource, line, currentObject, 1); * } */ public void init(double wlength, LightSource lsource, Scientrace.Line line, Scientrace.Object3d currentObject, double intensity, double original_intensity) { this.intensity = intensity; this.original_intensity = original_intensity; if (original_intensity == 0) { throw new ArgumentOutOfRangeException("original_intensity", "wl: " + wlength.ToString() + ", currentobj:" + currentObject.tag); } this.wavelenght = wlength; this.interactionoffset = this.getMinDistinctionLength(); //CHANGED OFFSET FROM WL*100 TO WL TODO CHECK this.traceline = line; this.currentObject = currentObject; this.lightsource = lsource; if (lsource != null) { if (this.isEmpty()) { throw new Exception("An invisible beam (I=" + this.intensity + ") has been constructed"); } } }
public Intersection intersectsObject(Trace trace, Object3d o3dWithThisBorder) { PlaneBorder aBorder = this; if (trace.traceline.direction.dotProduct(aBorder.getNormal()) == 0) return Intersection.notIntersect(o3dWithThisBorder); //trace is parallel to plane, will not intersect. Scientrace.Location intersectLoc = aBorder.intersectsAt(trace.traceline); if (intersectLoc == null) return Intersection.notIntersect(o3dWithThisBorder); //trace is parallel to plane, will not intersect. return new Intersection(true, o3dWithThisBorder, intersectLoc, new Scientrace.FlatShape2d(this.tPlane), null, this.contains(trace.traceline.startingpoint)); }
public Trace trace_in; // set at construction #endregion Fields #region Constructors /// <summary> /// Initializes a new instance of the <see cref="Scientrace.DielectricSurfaceInteraction"/> class. /// </summary> /// <param name="incoming_trace">Incoming trace.</param> /// <param name="interaction_loc">Interaction location.</param> /// <param name="surface_normal">Surface normal.</param> /// <param name="refindex_from">Refractive index for the current volume</param> /// <param name="refindex_to">Refractive index on the other side of the surface</param> /// <param name="static_absorption_fraction">If absorption at a surface occurs, this fraction is larger than 0.0. A black surface has full=1.0 absorption.</param> public DielectricSurfaceInteraction(Trace aTrace, Location interaction_loc, UnitVector surface_normal, double refindex_from, double refindex_to, Object3d object_to) { // Store all starting conditions this.trace_in = aTrace; this.intensity_in = aTrace.intensity; this.object_to = object_to; this.n_i = refindex_from; this.n_t = refindex_to; this.dir_i = aTrace.traceline.direction; // Make sure the surface normal is oriented in the right direction this.surface_normal = surface_normal.orientedAgainst(this.dir_i).tryToUnitVector(); this.interaction_loc = interaction_loc; // Define the "orthogonal to the plane - s" polarisation vector direction // Replaced "safeNormalised" method commented out below // At normal incidence, you want to retain the polarisation vectors of the trace for the best results Scientrace.Vector out_of_plane_vec = this.surface_normal.crossProduct(this.dir_i); if (out_of_plane_vec.length < 1E-9) out_of_plane_vec = new Vector(this.trace_in.getPolarisationDir1()); this.dir_s = out_of_plane_vec.tryToUnitVector(); //this.dir_s = this.surface_normal.safeNormalisedCrossProduct(this.dir_i); // Define the "in the plane - p" polarisation vector direction this.dir_ip = this.dir_s.crossProduct(this.dir_i).tryToUnitVector(); this.in_projection = this.dir_i.projectOnPlaneWithNormal(this.surface_normal); //First, calculate all properties concerning the incoming trace this.applySnellius(); this.calcIncomingAmplitudes(); //Before doing anything else, ABSORP the static surface absorption. this.subtractStaticAbsorption(); // If the trace has ended due to total absorption it ends here. if (this.total_absorption) return; //Now calculate all that other stuff. this.calcResultingAmplitudes(); this.calcResultingIntensities(); if (Math.Abs(1 - (this.intc_rp + this.intc_tp)) > 1E-9) throw new Exception("p-polarisation fractions don't add op to 1 (rp: "+this.intc_rp+" tp:"+this.intc_tp+")"); if (Math.Abs(1 - (this.intc_rs + this.intc_ts)) > 1E-9) throw new Exception("s-polarisation fractions don't add op to 1 (rs: "+this.intc_rs+" ts:"+this.intc_ts+")"); this.calcResultingDirections(); //this.debugOutput(); }
public Intersection mergeToNewIntersectionWithinBorder(Intersection anotherIntersection, IBorder3d aBorder, Trace aTrace, Object3d intersectedObject3d) { //List<IntersectionPoint> allips = new List<IntersectionPoint>(new IntersectionPoint[]{this.enter, this.exit, anotherIntersection.enter, anotherIntersection.exit} ); List<IntersectionPoint> allips = new List<IntersectionPoint>(); allips.Add(this.enter); allips.Add(this.exit); allips.Add(anotherIntersection.enter); allips.Add(anotherIntersection.exit); List<IntersectionPoint> validips = new List<IntersectionPoint>(); foreach (IntersectionPoint ip in allips) if ((ip != null) && (aBorder.contains(ip.loc))) validips.Add(ip); return new Intersection(aTrace, validips.ToArray(), intersectedObject3d); }
public Intersection intersectsObject(Trace trace, Object3d o3dWithThisBorder) { Intersection retIntersection = this.intersects(trace); retIntersection.object3d = o3dWithThisBorder; return retIntersection; }
public override Intersection intersects(Trace trace) { Scientrace.Intersection firstIntersection = new Scientrace.Intersection(false, null); Scientrace.Intersection currentintersection = new Scientrace.Intersection(false, null); double?firstdistance = null; double currentdistance; SortedList slobjects = new SortedList(); //Console.WriteLine(this.tag+" HAS "+this.objects.Count+ " o3ds"); //copying (by reference of course) all objects to a sortedlist. foreach (Object3d iobject3d in this.objects) { //Console.WriteLine("POKING "+ iobject3d.tag); slobjects.Add(iobject3d.parseOrder, iobject3d); } foreach (DictionaryEntry deObject3d in slobjects) { Object3d iObject = (Object3d)deObject3d.Value; //validating currentintersection: currentintersection = iObject.intersectsBefore(trace, currentintersection); /*if (currentintersection==null) { continue; } * if (currentintersection.enter==null) { continue; } * if (currentintersection.exit==null) { continue; } */ //currentintersection = iObject.intersects(trace); /*foreach (Object3d iobject3d in this.objects) { * currentintersection = iobject3dl.intersects(trace);*/ REPARSE: if (!currentintersection.intersects) { continue; //no intersection with this object? Try next object in collection (continue) } if ((currentintersection.enter.loc - trace.traceline.startingpoint).dotProduct(trace.traceline.direction) < 0) { //Console.WriteLine("Found object lies in the past! Skipping "+iObject.tag); continue; } // else {Console.WriteLine("not in the past, but :"+(currentintersection.enter.loc-trace.traceline.startingpoint).dotProduct(trace.traceline.direction));} currentdistance = currentintersection.enter.loc.distanceTo(trace.traceline.startingpoint); if (currentintersection.object3d == trace.currentObject) { /* If you're inside an object and the beam meets the same object, * it should only have an "enterloc" which is where the beam "leaves" the object. */ if (currentintersection.exit != null) // .loc part after exit removed at 20131205 /* perhaps the intersection has found the object at the same starting point */ { if (currentintersection.enter.loc.distanceTo(trace.traceline.startingpoint) < trace.getMinDistinctionLength()) { Console.WriteLine("New functionality: removing exit for " + currentintersection.object3d.tag); currentintersection.removeExit(); goto REPARSE; } /* check this occuring warning out after internal reflections. Doesn't * seem to cause any problems though. */ if (currentintersection.object3d != trace.currentObject) // because if they are the same it seems like internal reflection { Console.WriteLine("WARNING @" + this.tag + ": Collision (" + currentintersection.object3d.tag + ")" + " with current object (" + trace.currentObject.tag + ")" + " without leaving first \n-----\n" + trace.ToCompactString() + "\nentering: " + currentintersection.enter.loc.trico() + "\nexit:" + currentintersection.exit.loc.tricon() + "-----"); } //endif (currentintersection.object3d != trace.currentObject) continue; /* else: if no exit location is set, we must be leaving the current object at "enter" */ } else // Leaving the current object should return to the parent collection (environment?). { currentintersection.leaving = true; } /* else: if the colliding object isn't the current object */ } else { // analogue as above but inverted: you cannot leave an object you're not inside. if (currentintersection.exit == null) // .loc part after exit removed at 20131205 //or can you? //continue; NO LONGER ABORT PARSING HERE, BECAUSE: //CONCLUSION: //YES YOU CAN, think about an object within an object or a reflective layer { if (currentintersection.object3d.hasVolume) { //Console.WriteLine("Leaving object with volume("+currentintersection.object3d.tag+"), but don't refract"); continue; } } } if (!firstIntersection.intersects) { firstIntersection = currentintersection; firstdistance = firstIntersection.enter.loc.distanceTo(trace.traceline.startingpoint); continue; } /* below a firstInteraction is already set */ currentdistance = currentintersection.enter.loc.distanceTo(trace.traceline.startingpoint); if (firstIntersection.leaving) { /* in order to make "attached objects" change into one another the * colliding object has to be found instead of the "leaving" border. */ /* object which are seperated from each other with less than the lights wavelength * will be treated as connected to each other. Not first leaving previous border */ if (currentdistance - firstdistance < trace.getMinDistinctionLength()) { firstIntersection = currentintersection; firstdistance = currentdistance; continue; } continue; } /* if (firstdistance == null) { * throw new NullReferenceException("firstdistance not set"); * } *///this shouldn't occur and doesn't, so not checking anymore if (firstdistance > currentdistance) { firstdistance = currentdistance; firstIntersection = currentintersection; continue; } /* TODO for optimization purposes: * find whether any "containing" object is intersected, find first and return an Intersection */ } /*if (firstIntersection.leaving) { * //Console.WriteLine("----------> leaving *** "+currentintersection.object3d); * }*/ return(firstIntersection); }
/* public void reflect(Scientrace.Trace trace, Scientrace.Intersection intrs) { }*/ public bool attachedTo(Object3d object3d) { if ((this.GetType() == typeof(AttachedObject3dCollection)) || object3d.GetType() == typeof(AttachedObject3dCollection)) { return false; } AttachedObject3dCollection aoc = null; Object3d tobject1 = this; while (tobject1.parent != null) { if (typeof(AttachedObject3dCollection).IsAssignableFrom(tobject1.parent.GetType())) { //Console.WriteLine(tobject1.parent.GetType()+" is attacheble"); //if (tobject1.parent.GetType() == typeof(AttachedObject3dCollection)) { aoc = (AttachedObject3dCollection)tobject1.parent; //Console.WriteLine(tobject1.parent.GetType()); break; } else { tobject1 = tobject1.parent; } } //end while if (aoc == null) { return false; } Object3d tobject2 = object3d; while (tobject2.parent != null) { if (typeof(AttachedObject3dCollection).IsAssignableFrom(tobject2.parent.GetType())) { //if (tobject2.parent.GetType() == typeof(AttachedObject3dCollection)) { //Console.WriteLine("********** ATTACHED OBJECTS "+this+" & "+object3d); return (tobject2.parent == aoc); } else { tobject2 = tobject2.parent; } } //end while return false; }
//Methods public void addObject3d(Object3d anObject3d) { //Console.WriteLine("ADDING OBJECT: "+anObject3d.tag); this.objects.Add(anObject3d); }
public double absorpByObject(Scientrace.Object3d anObject3d, Scientrace.UnitVector norm, Object3d previousObject) { double oldintensity = this.intensity; double oldintensityfraction = this.intensityFraction(); //EXTENDED 20150706 double absorption_fraction = anObject3d.materialproperties.absorption(this, norm, previousObject.materialproperties); double absorption = absorption_fraction * oldintensity; double absorptionIntensityFraction = absorption_fraction * oldintensityfraction; this.intensity = oldintensity - absorption; if (absorption > MainClass.SIGNIFICANTLY_SMALL) //don't write a spot at ~0 absorption. { TraceJournal.Instance.recordSpot(new Scientrace.Spot(this.traceline.startingpoint, anObject3d, absorption, absorptionIntensityFraction, this)); } if (this.intensityFraction() <= this.lightsource.minimum_intensity_fraction) { //Console.WriteLine("INTENSITY TOO LOW"+anObject3d.ToString()+"/"+anObject3d.materialproperties.absorption(this)); this.perish(this.traceline.startingpoint); } return(absorption_fraction); }
public double revenueForObject(Object3d object3d) { return this.objectRevenues[object3d]; }
public Intersection mergeToNewIntersectionWithinBorder(Intersection anotherIntersection, IBorder3d aBorder, Trace aTrace, Object3d intersectedObject3d) { //List<IntersectionPoint> allips = new List<IntersectionPoint>(new IntersectionPoint[]{this.enter, this.exit, anotherIntersection.enter, anotherIntersection.exit} ); List <IntersectionPoint> allips = new List <IntersectionPoint>(); allips.Add(this.enter); allips.Add(this.exit); allips.Add(anotherIntersection.enter); allips.Add(anotherIntersection.exit); List <IntersectionPoint> validips = new List <IntersectionPoint>(); foreach (IntersectionPoint ip in allips) { if ((ip != null) && (aBorder.contains(ip.loc))) { validips.Add(ip); } } return(new Intersection(aTrace, validips.ToArray(), intersectedObject3d)); }
public double revenueForObject(Object3d object3d) { return(this.objectRevenues[object3d]); }
public List<ObjectLinePiece> toOLP(List<LinePiece> aList, string colour, Object3d anO3D) { List<ObjectLinePiece> olplist = new List<ObjectLinePiece>(); foreach (LinePiece anLP in aList) { ObjectLinePiece anOLP = new ObjectLinePiece(); anOLP.o3d = anO3D; anOLP.lp = anLP; anOLP.col = colour; olplist.Add(anOLP); } return olplist; }