private void UpdateIntegration(List <GH_Point> points, List <GH_Vector> vectors, DynamicSettings settings) { // only integrate if we have a vector field to work with if (points.Count > 0) { // integration var bases = new List <Basis>(); for (int i = 0; i < points.Count; i++) { bases.Add(new Basis(points[i], vectors[i])); } var ptSampling = (points.Count != 0); var staticSettings = ConvertDynSettingsToStatic(settings); for (int i = 0; i < particles.Count; i++) { var p = particles[i]; var traveller = p.Current.Point; var startBasis = p.Start; var vecLast = p.Current.Vector; var outBasis = new Basis(); if (points.Count != 0 && !Algos.SampleForNextPoint(bases, traveller.Value, startBasis, vecLast, staticSettings, out outBasis)) { break; } p.Current.Point = outBasis.Point; p.Current.Vector = outBasis.Vector; } } }
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 reset = new GH_Boolean(); var settings = new GH_ObjectWrapper(); 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) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Vector list size mismatch with points list, they must be equal in length. Operation canceled."); return; } if (DA.GetDataList(2, startPoints) && startPoints == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid travelling points. Operation canceled."); return; } // spm parameters component is optional, we use its defaults if it is not available SPM_Parameters spm_settings = new SPM_Parameters(); if (DA.GetData(3, 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 = (SPM_Parameters)settings.Value; } if (DA.GetData(4, ref reset) && reset == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid reset input. Operation canceled."); return; } if (startBasis == null || reset.Value) { var count = startPoints.Count; startBasis = new Basis[count]; lastVecs = new GH_Vector[count]; xy = new double[count]; yz = new double[count]; xz = new double[count]; for (int i = 0; i < count; i++) { startBasis[i] = new Basis(startPoints[i]); lastVecs[i] = new GH_Vector(); xy[i] = 0; yz[i] = 0; xz[i] = 0; } } if (moving == null || reset.Value) { moving = startPoints; return; } int steps = spm_settings.steps; if (steps == 0) { steps = 1; } var bases = new List <Basis>(); for (int i = 0; i < points.Count; i++) { bases.Add(new Basis(points[i], vectors[i])); } // find each next point based on an averaging formula and iterate for (int i = 0; i < startPoints.Count; i++) { for (int j = 0; j < steps; j++) { bool add = false; var outBasis = new Basis(); bool working = Algos.SampleForNextPoint(bases, moving[i].Value, startBasis[i], lastVecs[i], spm_settings, out outBasis, out add); if (spm_settings.stop && spm_settings.windAngle != 0.0d) { if (!lastVecs[i].Value.IsZero) { double cxy = xy[i]; double cyz = yz[i]; double cxz = xz[i]; if (Algos.IsWoundPast(outBasis.Vector.Value, lastVecs[i].Value, spm_settings.windAngle, ref cxy, ref cyz, ref cxz)) { break; } xy[i] = cxy; yz[i] = cyz; xz[i] = cxz; } } lastVecs[i] = outBasis.Vector; if (working && startBasis[i].Vector.Value.IsZero) { startBasis[i].Vector.Value = moving[i].Value - startBasis[i].Point.Value; } if (add) { moving[i] = outBasis.Point; } if (!working) { moving[i] = startPoints[i]; } } } DA.SetDataList(0, moving); }
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); }