/// <summary> /// This must be called after any changes to the field. /// </summary> public void UpdateGradient() { if (_gradient == null || _gradient.Count != _field.Count) { _gradient = new GridVectorField3d(_field); } _field.GetGradient(_gradient); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { GH_Box box = null; if (!DA.GetData(0, ref box)) { return; } GH_Integer nx = null; if (!DA.GetData(1, ref nx)) { return; } GH_Integer ny = null; if (!DA.GetData(2, ref ny)) { return; } GH_Integer nz = null; DA.GetData(3, ref nz); List <GH_Vector> vals = new List <GH_Vector>(); DA.GetDataList(4, vals); if (nz == null) { var d = box.Value.BoundingBox.ToInterval2d(); var f = new GridVectorField2d(d, nx.Value, ny.Value, _wrapX, _wrapY, _sample); // set values if (vals != null) { if (vals.Count == 1) { var v = vals[0].Value; f.Set(new Vec2d(v.X, v.Y)); } else { f.Set(vals.Select(x => { var v = x.Value; return(new Vec2d(v.X, v.Y)); })); } } DA.SetData(0, new GH_ObjectWrapper(f)); } else { var d = box.Value.BoundingBox.ToInterval3d(); var f = new GridVectorField3d(d, nx.Value, ny.Value, nz.Value, _wrapX, _wrapY, _wrapZ, _sample); // set values if (vals != null) { if (vals.Count == 1) { f.Set(vals[0].Value.ToVec3d()); } else { f.Set(vals.Select(x => x.Value.ToVec3d())); } } DA.SetData(0, new GH_ObjectWrapper(f)); } }