/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { Mesh mesh = null; List <Point3d> points = new List <Point3d>(); double iso = 0d; if (!DA.GetData(0, ref mesh)) { return; } if (!DA.GetDataList <Point3d>(1, points)) { return; } if (!DA.GetData(2, ref iso)) { return; } var hem = mesh.ToHeMesh(); var field = MeshField3d.Double.Create(hem); var vecs = points.Select(p => (SpatialSlur.Vector3d)p).ToList(); var kdTree = KdTree.CreateBalanced(vecs.Select(v => (v.XY).ToArray())); var nearest = hem.Vertices.Select(p => kdTree.NearestL2(new double[] { p.Position.X, p.Position.Y })).ToList(); List <double> val = new List <double>(); for (int i = 0; i < hem.Vertices.Count; i++) { double d = hem.Vertices[i].Position.DistanceTo(points[nearest[i]]); val.Add(d); } Interval interval = GetInterval(val); for (int i = 0; i < val.Count; i++) { val[i] = (SlurMath.Remap(val[i], interval.T0, interval.T1, -1, 1)) - iso; } field.Set(val); DA.SetData(0, Field3d.Create(v => field.ValueAt(v))); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { Mesh mesh = null; Mesh inputMesh = null; double iso = 0d; if (!DA.GetData(0, ref mesh)) { return; } if (!DA.GetData(1, ref inputMesh)) { return; } if (!DA.GetData(2, ref iso)) { return; } var hem = mesh.ToHeMesh(); var field = MeshField3d.Double.Create(hem); List <double> val = new List <double>(); foreach (Point3d v in mesh.Vertices) { Point3d closestPt = inputMesh.ClosestPoint(v); double dist = v.DistanceTo(closestPt); val.Add(dist); } Interval interval = GetInterval(val); for (int i = 0; i < val.Count; i++) { val[i] = (SlurMath.Remap(val[i], interval.T0, interval.T1, -1, 1)) - iso; } field.Set(val); DA.SetData(0, Field3d.Create(v => field.ValueAt(v))); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { Mesh mesh = null; List <Curve> curves = new List <Curve>(); double iso = 0d; if (!DA.GetData(0, ref mesh)) { return; } if (!DA.GetDataList <Curve>(1, curves)) { return; } if (!DA.GetData(2, ref iso)) { return; } var hem = mesh.ToHeMesh(); var field = MeshField3d.Double.Create(hem); List <Polyline> polys = new List <Polyline>(); for (int i = 0; i < curves.Count; i++) { Polyline poly; if (!curves[i].TryGetPolyline(out poly)) { throw new ArgumentException(); } else { polys.Add(poly); } } List <Mesh> poly_meshes = new List <Mesh>(); for (int i = 0; i < polys.Count; i++) { poly_meshes.Add(RhinoFactory.Mesh.CreateExtrusion(polys[i], new Rhino.Geometry.Vector3d(0, 0, 0))); } List <double> val = new List <double>(); foreach (Point3d v in mesh.Vertices) { int idClosestMesh = -1; double least = Math.Pow(10, 10); for (int i = 0; i < poly_meshes.Count; i++) { Point3d closestPt = poly_meshes[i].ClosestPoint(v); double dist = v.DistanceTo(closestPt); if (dist < least) { idClosestMesh = i; least = dist; } } Point3d point = poly_meshes[idClosestMesh].ClosestPoint(v); double d = v.DistanceTo(point); val.Add(d); } Interval interval = GetInterval(val); for (int i = 0; i < val.Count; i++) { val[i] = (SlurMath.Remap(val[i], interval.T0, interval.T1, -1, 1)) - iso; } field.Set(val); DA.SetData(0, Field3d.Create(v => field.ValueAt(v))); }