protected override void SolveInstance(IGH_DataAccess DA) { var points = new List <GH_Point>(); var vectors = new List <GH_Vector>(); var surface = new GH_Surface(); var dynamicsWrapped = new List <GH_ObjectWrapper>(); if (DA.GetDataList(0, points) && points == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid point list. Operation canceled."); return; } if (DA.GetDataList(1, vectors) && vectors == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid vector list. Operation canceled."); return; } // if vec field is empty, create parallel list of 0 vectors if (vectors.Count == 0) { for (int i = 0; i < points.Count; i++) { vectors.Add(new GH_Vector()); } } if (DA.GetDataList(2, dynamicsWrapped) && dynamicsWrapped == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid dynamics list. Operation canceled."); return; } if (DA.GetData(3, ref surface) && surface == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid surface. Operation canceled."); return; } var dynamics = new List <IDynamic>(); foreach (var d in dynamicsWrapped) { dynamics.Add(d.Value as IDynamic); } Algos.SortDynamicsByPriority(dynamics); Algos.ClearDynamics(dynamics); foreach (var d in dynamics) { Algos.ProcessDynamics(d, points, vectors, surface); } Algos.RealignAccelerationVectors(dynamics, vectors); DA.SetDataList(0, points); DA.SetDataList(1, vectors); }
public void Process(List <GH_Point> points, List <GH_Vector> vectors, GH_Surface surface) { var dynamicsWrapped = Param["D"] as List <GH_ObjectWrapper>; var dynamics = new List <IDynamic>(); foreach (var d in dynamicsWrapped) { dynamics.Add(d.Value as IDynamic); } Algos.SortDynamicsByPriority(dynamics); foreach (var d in dynamics) { Algos.ProcessDynamics(d, points, vectors, surface); } }
protected override void SolveInstance(IGH_DataAccess DA) { // inputs var points = new List <GH_Point>(); var vectors = new List <GH_Vector>(); var startPoints = new List <GH_Point>(); var lifeTime = new GH_Integer(); var settings = new GH_ObjectWrapper(); var reset = new GH_Boolean(); var dynamicsWrapped = new List <GH_ObjectWrapper>(); var dynamics = new List <IDynamic>(); if (DA.GetDataList(0, points) && points == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid points list. Operation canceled."); return; } if (DA.GetDataList(1, vectors) && vectors == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid vector list. Operation canceled."); return; } if (vectors.Count != points.Count && vectors.Count != 0) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Vector list size mismatch with points list, they must be equal in length (or empty). Operation canceled."); return; } if (DA.GetDataList(2, startPoints) && startPoints == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid travelling points. Operation canceled."); return; } if (DA.GetData(3, ref lifeTime) && lifeTime == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid lifetime input. Operation canceled."); return; } if (DA.GetDataList(4, dynamicsWrapped) && dynamicsWrapped == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid dynamics list. Operation canceled."); return; } dynamics = (from d in dynamicsWrapped select d.Value as IDynamic).ToList(); Algos.SortDynamicsByPriority(dynamics); // if vectors list is empty we'll populate it with empty vectors to match each point if (vectors.Count == 0) { for (int i = 0; i < points.Count; i++) { vectors.Add(new GH_Vector()); } } // spm parameters component is optional, we use its defaults if it is not available var spm_settings = new DynamicSettings(); if (DA.GetData(5, ref settings)) { // if getdata succeeded but the settings var is null we had bad input if (settings == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid settings input. Operation canceled."); return; } // otherwise cast from gh_objectwrapper and continue spm_settings = (DynamicSettings)settings.Value; } if (DA.GetData(6, ref reset) && reset == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid reset input. Operation canceled."); return; } if (emitter == null || reset.Value) { emitter = new Emitter(startPoints, lifeTime.Value, spm_settings); DA.SetDataList(0, startPoints); var zv = new List <GH_Vector>(startPoints.Count); for (int i = 0; i < startPoints.Count; i++) { zv.Add(new GH_Vector()); } Algos.ClearDynamics(dynamics); DA.SetDataList(1, zv); return; } // emitter updates dynamics emitter.Update(dynamics, points, vectors, spm_settings); DA.SetDataList(0, emitter.Points); DA.SetDataList(1, emitter.Vectors); }
protected override void SolveInstance(IGH_DataAccess DA) { // inputs var points = new List <GH_Point>(); var planes = new List <GH_Plane>(); var vectors = new List <GH_Vector>(); var traveller = new GH_Point(); var settings = new GH_ObjectWrapper(); var dynamicsWrapped = new List <GH_ObjectWrapper>(); var dynamics = new List <IDynamic>(); // outputs var linePoints = new List <GH_Point>(); var lineVecs = new List <GH_Vector>(); // gather and validate inputs if (DA.GetDataList(0, points) && points == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid points list. Operation canceled."); return; } if (DA.GetData(2, ref traveller) && traveller == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid travelling point. Operation canceled."); return; } if (DA.GetDataList(3, dynamicsWrapped) && dynamicsWrapped == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid dynamics list. Operation canceled."); return; } dynamics = (from d in dynamicsWrapped select d.Value as IDynamic).ToList(); Algos.SortDynamicsByPriority(dynamics); // spm parameters component is optional, we use its defaults if it is not available StaticSettings spm_settings = new StaticSettings(); if (DA.GetData(4, ref settings)) { // if getdata succeeded but the settings var is null we had bad input if (settings == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid settings input. Operation canceled."); return; } // otherwise cast from gh_objectwrapper and continue spm_settings = (StaticSettings)settings.Value; } var bases = new List <Basis>(); var basesWrapper = new List <GH_ObjectWrapper>(); // we need to get the vector field information after settings, for tensor settings if (spm_settings.tensor && (spm_settings.tensorDir >= 0 && spm_settings.tensorDir <= 2)) { if (DA.GetDataList(1, basesWrapper) && basesWrapper == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid tensor field. Operation canceled."); return; } for (int i = 0; i < basesWrapper.Count; i++) { Basis b = basesWrapper[i].Value as Basis; bases.Add(new Basis(points[i], b.Vectors)); bases[i].Axes = spm_settings.tensorAxes; } } else { if (DA.GetDataList(1, vectors) && vectors == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid vector list. Operation canceled."); return; } if (vectors.Count != points.Count && vectors.Count != 0) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Vector list size mismatch with points list, they must be equal in length (or empty if you wish to integrate using just dynamics). Operation canceled."); return; } // if vectors list is empty we'll populate it with empty vectors to match each point if (vectors.Count == 0) { foreach (var i in Enumerable.Range(0, points.Count)) { vectors.Add(new GH_Vector()); } } for (int i = 0; i < points.Count; i++) { bases.Add(new Basis(points[i], vectors[i])); } } int steps = spm_settings.steps; if (steps == 0) { steps = MAX_ITERATIONS; } var startBasis = new Basis(traveller); var vecLast = new GH_Vector(); double xy = 0; double yz = 0; double xz = 0; // add start point to output linePoints.Add(startBasis.Point); Algos.ClearDynamics(dynamics); // find each next point based on an averaging formula and iterate for (int i = 0; i < steps; i++) { bool add = false; var outBasis = new Basis(); if (points.Count != 0 && !Algos.SampleForNextPoint(bases, traveller.Value, startBasis, vecLast, spm_settings, out outBasis)) { break; } if (dynamics.Count > 0) { traveller = Algos.GetPointModifiedByDynamics(traveller, outBasis, dynamics, spm_settings); outBasis.Point = traveller; } else { traveller = outBasis.Point; } // this step must be done oustide of the regular halting checks as we must store the axes rotations if (spm_settings.windAngle != 0.0d && !vecLast.Value.IsZero && Algos.IsWoundPast(outBasis.Vector.Value, vecLast.Value, spm_settings.windAngle, ref xy, ref yz, ref xz)) { break; } var working = Algos.CheckHaltingConditions(traveller, startBasis, outBasis, vecLast.Value, out add, spm_settings); traveller = outBasis.Point; vecLast = outBasis.Vector; // cache the vector between start and start+1 if (i == 0 && working) { startBasis.Vector.Value = traveller.Value - startBasis.Point.Value; } if (add) { linePoints.Add(traveller); lineVecs.Add(vecLast); } if (!working) { break; } } DA.SetDataList(0, linePoints); DA.SetDataList(1, lineVecs); }