From afed22056765a9e8d1f7187a5ab34c058b19b45a Mon Sep 17 00:00:00 2001 From: fstwn Date: Fri, 6 Aug 2021 12:16:37 +0200 Subject: [PATCH 1/8] add component for adding PointValues to the points of a pointcloud Unfortunately there is no constructor that allows to instantiate a PointCloud with PointValues but without Colors and/or Normals. So we have to use "Dummy" Normals and Colors to re-instantiate the PointCloud. Usually setting the values to individual points via the setter should work, unfortunately it doesn't at the moment. Another bug is, that ClearNormals and ClearColors won't work properly on PointClouds at the present time. So we'll need to wait for McNeel to fix that and then update this rather complicated procedure to a better one. --- .../PointCloudParam/CloudAddPointValues.cs | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 CockroachGH/PointCloudParam/CloudAddPointValues.cs diff --git a/CockroachGH/PointCloudParam/CloudAddPointValues.cs b/CockroachGH/PointCloudParam/CloudAddPointValues.cs new file mode 100644 index 0000000..f81a2b6 --- /dev/null +++ b/CockroachGH/PointCloudParam/CloudAddPointValues.cs @@ -0,0 +1,107 @@ +using Grasshopper.Kernel; +using Grasshopper.Kernel.Data; +using Grasshopper.Kernel.Types; +using Rhino.Geometry; +using System; +using System.Collections.Generic; + +namespace CockroachGH { + public class CloudAddPointValues : GH_Component { + + public CloudAddPointValues() + : base("CloudAddPointValues", "AddPointValues", + "Add extra values (i.e. for intensity) to the points of an existing PointCloud.", + "Cockroach", "Cloud") { + } + public override GH_Exposure Exposure => GH_Exposure.quarternary; + + protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager) { + pManager.AddParameter(new Param_Cloud(), "PointCloud", "C", "The PointCloud to add extra values to.", GH_ParamAccess.item); + pManager.AddNumberParameter("Values", "V", "The extra values to add to the points of the PointCloud (i.e. intensity). If the length of supplied values is less than the number of points in the cloud, it will be filled with zeros. If it exceeds the number of points, it will be truncated.", GH_ParamAccess.list); + } + + protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) { + pManager.AddParameter(new Param_Cloud(), "PointCloud", "C", "The PointCloud with extra values added to its points.", GH_ParamAccess.item); + } + + protected override void SolveInstance(IGH_DataAccess DA) { + + try + { + // retrieve PointCloud from input data + var cgh = new GH_Cloud(); + DA.GetData(0, ref cgh); + + var v = new List(); + DA.GetDataList(1, v); + + // create new PointCloud + PointCloud cloud = new PointCloud(); + + // get points, initialize numbers and colors + var p = cgh.Value.GetPoints(); + Vector3d[] n; + System.Drawing.Color[] c; + + // check and sanitize normals if necessary + n = cgh.Value.GetNormals(); + if (n.Length == 0) + { + n = System.Linq.Enumerable.ToArray(System.Linq.Enumerable.Repeat(Vector3d.Unset, p.Length)); + } + + // check and sanitize colors if necessary + c = cgh.Value.GetColors(); + if (c.Length == 0) + { + c = System.Linq.Enumerable.ToArray(System.Linq.Enumerable.Repeat(System.Drawing.Color.Black, p.Length)); + } + + // check length of list of input values + if (p.Length == v.Count) + { + // add everying to new cloud + cloud.AddRange(p, n, c, v); + } + else + { + // truncate / fill values list + double[] arrv = new double[p.Length]; + System.Threading.Tasks.Parallel.For(0, arrv.Length, i => + { + if (i < v.Count) arrv[i] = v[i]; + }); + // add everying to new cloud + cloud.AddRange(p, n, c, arrv); + } + + // clear normals if input cloud did not have them + if (!cgh.Value.ContainsNormals) + { + cloud.ClearNormals(); + } + // clear colors if input cloud did not have them + if (!cgh.Value.ContainsColors) + { + cloud.ClearNormals(); + } + + // prepare data for output + DA.SetData(0, new GH_Cloud(cloud)); + } + catch (Exception e) + { + Rhino.RhinoApp.WriteLine(e.ToString()); + } + } + + /// + /// Gets the unique ID for this component. Do not change this ID after release. + /// + public override Guid ComponentGuid { + get { return new Guid("88037ed0-5dda-483b-be15-e05ef45dcaf0"); } + } + + protected override System.Drawing.Bitmap Icon => Properties.Resources.Cloud; + } +} \ No newline at end of file From faf318fefac546d44cc1a9b20bc6d7373e8ee05d Mon Sep 17 00:00:00 2001 From: fstwn Date: Fri, 6 Aug 2021 12:18:29 +0200 Subject: [PATCH 2/8] add component for retrieving PointValues atached to the points of a PointCloud --- .../PointCloudParam/CloudPointValues.cs | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 CockroachGH/PointCloudParam/CloudPointValues.cs diff --git a/CockroachGH/PointCloudParam/CloudPointValues.cs b/CockroachGH/PointCloudParam/CloudPointValues.cs new file mode 100644 index 0000000..b211586 --- /dev/null +++ b/CockroachGH/PointCloudParam/CloudPointValues.cs @@ -0,0 +1,52 @@ +using Grasshopper.Kernel; +using Grasshopper.Kernel.Data; +using Grasshopper.Kernel.Types; +using Rhino.Geometry; +using System; +using System.Collections.Generic; + +namespace CockroachGH { + public class CloudPointValues : GH_Component { + + public CloudPointValues() + : base("CloudPointValues", "PointValues", + "Retrieve the extra PointValues attached to the points of a PointCloud.", + "Cockroach", "Cloud") { + } + public override GH_Exposure Exposure => GH_Exposure.quarternary; + + protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager) { + pManager.AddParameter(new Param_Cloud(), "PointCloud", "C", "The PointCloud to retrieve the extra PointValues from.", GH_ParamAccess.item); + } + + protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) { + pManager.AddNumberParameter("Values", "V", "The extra PointValues attached to the points of the PointCloud (i.e. for intensity).", GH_ParamAccess.list); + } + + protected override void SolveInstance(IGH_DataAccess DA) { + + // Input + try { + var cgh = new GH_Cloud(); + DA.GetData(0, ref cgh); + + DA.SetDataList(0, cgh.Value.GetPointValues()); + } + catch(Exception e) + { + Rhino.RhinoApp.WriteLine(e.ToString()); + } + + } + + + /// + /// Gets the unique ID for this component. Do not change this ID after release. + /// + public override Guid ComponentGuid { + get { return new Guid("686a4bfe-5c53-401d-be82-ecc0dd99e54a"); } + } + + protected override System.Drawing.Bitmap Icon => Properties.Resources.Cloud; + } +} \ No newline at end of file From 763a6a46f58f63b74242c8950be2809b87ddca5e Mon Sep 17 00:00:00 2001 From: fstwn Date: Fri, 6 Aug 2021 12:23:15 +0200 Subject: [PATCH 3/8] preserve extra PointValues through the box cropping, add description to component and parameters. --- CockroachGH/Cleaning/CloudBoxCrop.cs | 55 +++++++++++++--------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/CockroachGH/Cleaning/CloudBoxCrop.cs b/CockroachGH/Cleaning/CloudBoxCrop.cs index 41d563b..7004273 100644 --- a/CockroachGH/Cleaning/CloudBoxCrop.cs +++ b/CockroachGH/Cleaning/CloudBoxCrop.cs @@ -11,22 +11,20 @@ public class CloudBoxCrop : GH_Component { public CloudBoxCrop() : base("CloudBoxCrop", "CloudBoxCrop", - "CloudBoxCrop", - "Cockroach", "Crop") { + "Crop a PointCloud with one or many boxes, getting either the inside or the outside of the boxes as a new PointCloud.", + "Cockroach", "Crop") { } public override GH_Exposure Exposure => GH_Exposure.quarternary; protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager) { - pManager.AddParameter(new Param_Cloud(), "PointCloud", "C", "PointCloud", GH_ParamAccess.item); - pManager.AddBrepParameter("Boxes", "B", "Boxes",GH_ParamAccess.list); - pManager.AddBooleanParameter("Inverse","I","Get Outside part of box", GH_ParamAccess.item, false); + pManager.AddParameter(new Param_Cloud(), "PointCloud", "C", "The PointCloud to crop.", GH_ParamAccess.item); + pManager.AddBrepParameter("Boxes", "B", "The boxes to crop PointCloud with.",GH_ParamAccess.list); + pManager.AddBooleanParameter("Inverse","I","If set to True, will get the outside part of the box.", GH_ParamAccess.item, false); pManager[2].Optional = true; } protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) { - pManager.AddParameter(new Param_Cloud(), "PointCloud", "C", "PointCloud", GH_ParamAccess.item); - } protected override void SolveInstance(IGH_DataAccess DA) { @@ -43,21 +41,16 @@ protected override void SolveInstance(IGH_DataAccess DA) { PointCloud c = CropBox(cgh.Value, boxes, inverse, true); - DA.SetData(0, new GH_Cloud(c)); - - } - public PointCloud CropBox(PointCloud cloud, List boxes, bool inverse = false, bool parallel = false) { bool[] flags = new bool[cloud.Count]; - foreach (var brep in boxes) { - - + foreach (var brep in boxes) + { brep.Surfaces[0].TryGetPlane(out Plane plane); Box box = new Box(plane, brep); @@ -74,23 +67,22 @@ public PointCloud CropBox(PointCloud cloud, List boxes, bool inverse = fal Point3d Max = b.PointAt(1, 1, 1); //Rhino.RhinoDoc.ActiveDoc.Objects.AddBox(b); - System.Threading.Tasks.Parallel.For(0, cloudCopy.Count, i => { - + System.Threading.Tasks.Parallel.For(0, cloudCopy.Count, i => + { if (flags[i]) return; var p = cloudCopy[i].Location; bool flag = (Min.X < p.X) && (Max.X > p.X) && (Min.Y < p.Y) && (Max.Y > p.Y) && (Min.Z < p.Z) && (Max.Z > p.Z); if (flag) flags[i] = true; - }); } - - int count = 0; List idList = new List(); - for (int i = 0; i < cloud.Count; i++) { + for (int i = 0; i < cloud.Count; i++) + { bool f = inverse ? !flags[i] : flags[i]; - if (f) { + if (f) + { idList.Add(i); count++; } @@ -100,22 +92,28 @@ public PointCloud CropBox(PointCloud cloud, List boxes, bool inverse = fal Point3d[] points = new Point3d[count]; Vector3d[] normals = new Vector3d[count]; Color[] colors = new Color[count]; + double[] pvalues = new double[count]; - System.Threading.Tasks.Parallel.For(0, idArray.Length, i => { - - + System.Threading.Tasks.Parallel.For(0, idArray.Length, i => + { int id = idArray[i]; var p = cloud[(int)id]; points[i] = p.Location; normals[i] = p.Normal; colors[i] = p.Color; - + pvalues[i] = p.PointValue; }); PointCloud croppedCloud = new PointCloud(); - croppedCloud.AddRange(points, normals, colors); - - + if (cloud.ContainsPointValues) + { + croppedCloud.AddRange(points, normals, colors, pvalues); + } + else + { + croppedCloud.AddRange(points, normals, colors); + } + //for (int i = 0; i < cloud.Count; i++) { @@ -129,7 +127,6 @@ public PointCloud CropBox(PointCloud cloud, List boxes, bool inverse = fal // } //} return croppedCloud; - } //public void CropCloud(PointCloud cloud, ref bool[] flags, Box box, bool inverse = false, bool parallel = false) { From b5025c92d887a7d582a0655609c3c32f773c3aec Mon Sep 17 00:00:00 2001 From: fstwn Date: Fri, 6 Aug 2021 13:34:36 +0200 Subject: [PATCH 4/8] add support for PointValues in CloudBoxCrop, add description to component and parameters --- CockroachGH/Cleaning/CloudBoxCrop.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CockroachGH/Cleaning/CloudBoxCrop.cs b/CockroachGH/Cleaning/CloudBoxCrop.cs index 7004273..feb8d82 100644 --- a/CockroachGH/Cleaning/CloudBoxCrop.cs +++ b/CockroachGH/Cleaning/CloudBoxCrop.cs @@ -11,20 +11,20 @@ public class CloudBoxCrop : GH_Component { public CloudBoxCrop() : base("CloudBoxCrop", "CloudBoxCrop", - "Crop a PointCloud with one or many boxes, getting either the inside or the outside of the boxes as a new PointCloud.", + "Crop a PointCloud with one or multiple Boxes, returning either the inside or the outside of the Box(es) as a new PointCloud.", "Cockroach", "Crop") { } public override GH_Exposure Exposure => GH_Exposure.quarternary; protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager) { pManager.AddParameter(new Param_Cloud(), "PointCloud", "C", "The PointCloud to crop.", GH_ParamAccess.item); - pManager.AddBrepParameter("Boxes", "B", "The boxes to crop PointCloud with.",GH_ParamAccess.list); - pManager.AddBooleanParameter("Inverse","I","If set to True, will get the outside part of the box.", GH_ParamAccess.item, false); + pManager.AddBrepParameter("Boxes", "B", "The Box(es) to crop PointCloud with.",GH_ParamAccess.list); + pManager.AddBooleanParameter("Inverse","I","If set to True, will get the outside part of the Box.", GH_ParamAccess.item, false); pManager[2].Optional = true; } protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) { - pManager.AddParameter(new Param_Cloud(), "PointCloud", "C", "PointCloud", GH_ParamAccess.item); + pManager.AddParameter(new Param_Cloud(), "PointCloud", "C", "The cropped PointCloud.", GH_ParamAccess.item); } protected override void SolveInstance(IGH_DataAccess DA) { From 3f58ae8a70333c94e5fa2fa6a661b5ca0d4331cc Mon Sep 17 00:00:00 2001 From: fstwn Date: Fri, 6 Aug 2021 13:35:01 +0200 Subject: [PATCH 5/8] add support for PointValues in CloudMeshCrop, add description to component and parameters --- CockroachGH/Cleaning/CloudMeshCrop.cs | 56 +++++++++++++-------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/CockroachGH/Cleaning/CloudMeshCrop.cs b/CockroachGH/Cleaning/CloudMeshCrop.cs index b1a1226..c0e4bb9 100644 --- a/CockroachGH/Cleaning/CloudMeshCrop.cs +++ b/CockroachGH/Cleaning/CloudMeshCrop.cs @@ -11,22 +11,20 @@ public class CloudMeshCrop : GH_Component { public CloudMeshCrop() : base("CloudMeshCrop", "CloudMeshCrop", - "CloudMeshCrop", - "Cockroach", "Crop") { + "Crop a PointCloud with one or multiple Meshes, returning either the inside or the outside of the Mesh(es) as a new PointCloud.", + "Cockroach", "Crop") { } public override GH_Exposure Exposure => GH_Exposure.quarternary; protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager) { - pManager.AddParameter(new Param_Cloud(), "PointCloud", "C", "PointCloud", GH_ParamAccess.item); - pManager.AddMeshParameter("Meshes", "M", "Meshes", GH_ParamAccess.list); - pManager.AddBooleanParameter("Inverse","I","Get Outside part of box", GH_ParamAccess.item, false); + pManager.AddParameter(new Param_Cloud(), "PointCloud", "C", "The PointCloud to crop.", GH_ParamAccess.item); + pManager.AddMeshParameter("Meshes", "M", "The Mesh(es) to crop the PointCloud with.", GH_ParamAccess.list); + pManager.AddBooleanParameter("Inverse","I", "If set to True, will get the outside part of the Mesh.", GH_ParamAccess.item, false); pManager[2].Optional = true; } protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) { - - pManager.AddParameter(new Param_Cloud(), "PointCloud", "C", "PointCloud", GH_ParamAccess.item); - + pManager.AddParameter(new Param_Cloud(), "PointCloud", "C", "The cropped PointCloud.", GH_ParamAccess.item); } protected override void SolveInstance(IGH_DataAccess DA) { @@ -41,19 +39,15 @@ protected override void SolveInstance(IGH_DataAccess DA) { bool inverse = false; DA.GetData(2, ref inverse); - PointCloud c = CropCloud(cgh.Value, meshes,inverse); DA.SetData(0, new GH_Cloud(c)); - - } public PointCloud CropCloud(PointCloud cloud, List M, bool inverse = false) { RTree rTree = Rhino.Geometry.RTree.CreatePointCloudTree(cloud); - bool[] flags = new bool[cloud.Count]; @@ -64,9 +58,10 @@ public PointCloud CropCloud(PointCloud cloud, List M, bool inverse = false var boxSearchData = new BoxSearchData(); rTree.Search(bBox, BoundingBoxCallback, boxSearchData); - foreach (int id in boxSearchData.Ids) { - - if (m.IsPointInside(cloud[id].Location, 0, true)) { + foreach (int id in boxSearchData.Ids) + { + if (m.IsPointInside(cloud[id].Location, 0, true)) + { flags[id] = true; } } @@ -75,9 +70,11 @@ public PointCloud CropCloud(PointCloud cloud, List M, bool inverse = false int count = 0; List idList = new List(); - for (int i = 0; i < cloud.Count; i++) { + for (int i = 0; i < cloud.Count; i++) + { bool f = inverse ? !flags[i] : flags[i]; - if (f) { + if (f) + { idList.Add(i); count++; } @@ -87,21 +84,27 @@ public PointCloud CropCloud(PointCloud cloud, List M, bool inverse = false Point3d[] points = new Point3d[count]; Vector3d[] normals = new Vector3d[count]; Color[] colors = new Color[count]; + double[] pvalues = new double[count]; - System.Threading.Tasks.Parallel.For(0, idArray.Length, i => { - - + System.Threading.Tasks.Parallel.For(0, idArray.Length, i => + { int id = idArray[i]; var p = cloud[(int)id]; points[i] = p.Location; normals[i] = p.Normal; colors[i] = p.Color; - + pvalues[i] = p.PointValue; }); PointCloud croppedCloud = new PointCloud(); - croppedCloud.AddRange(points, normals, colors); - + if (cloud.ContainsPointValues) + { + croppedCloud.AddRange(points, normals, colors, pvalues); + } + else + { + croppedCloud.AddRange(points, normals, colors); + } //for (int i = 0; i < f.Length; i++) { // bool flag = inverse ? !f[i] : f[i]; @@ -132,13 +135,6 @@ public BoxSearchData() { public List Ids { get; set; } } - - - - - - - public override Guid ComponentGuid { get { return new Guid("98aaf1ed-7834-41c8-8fd6-edf88cd44ba1"); } } From 7161b672cfb554eabb2db39bbf3bad276555776d Mon Sep 17 00:00:00 2001 From: fstwn Date: Fri, 6 Aug 2021 13:35:13 +0200 Subject: [PATCH 6/8] add support for PointValues in CloudPolygonCrop, add description to component and parameters --- CockroachGH/Cleaning/CloudPolygonCrop.cs | 55 +++++++++++++----------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/CockroachGH/Cleaning/CloudPolygonCrop.cs b/CockroachGH/Cleaning/CloudPolygonCrop.cs index 1acff4f..4160c3d 100644 --- a/CockroachGH/Cleaning/CloudPolygonCrop.cs +++ b/CockroachGH/Cleaning/CloudPolygonCrop.cs @@ -12,21 +12,21 @@ public class CloudPolygonCrop : GH_Component { public CloudPolygonCrop() : base("CloudPolygonCrop", "CloudPolygonCrop", - "CloudPolygonCrop", - "Cockroach", "Crop") { + "Crop a PointCloud with one or multiple closed Polylines, returning either the inside or the outside of the Polyline(s) as a new PointCloud.", + "Cockroach", "Crop") { } public override GH_Exposure Exposure => GH_Exposure.quarternary; protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager) { - pManager.AddParameter(new Param_Cloud(), "PointCloud", "C", "PointCloud", GH_ParamAccess.item); - pManager.AddCurveParameter("Polylines", "P", "Closed Polylines",GH_ParamAccess.list); - pManager.AddBooleanParameter("Inverse","I","Get Outside part of box", GH_ParamAccess.item, false); + pManager.AddParameter(new Param_Cloud(), "PointCloud", "C", "The PointCloud to crop.", GH_ParamAccess.item); + pManager.AddCurveParameter("Polylines", "P", "Closed Polylines to crop the PointCloud with.",GH_ParamAccess.list); + pManager.AddBooleanParameter("Inverse","I", "If set to True, will get the outside part of the Polygon(s).", GH_ParamAccess.item, false); pManager[2].Optional = true; } protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) { - pManager.AddParameter(new Param_Cloud(), "PointCloud", "C", "PointCloud", GH_ParamAccess.item); + pManager.AddParameter(new Param_Cloud(), "PointCloud", "C", "The cropped PointCloud.", GH_ParamAccess.item); } @@ -72,55 +72,60 @@ public PointCloud CropCloud(PointCloud cloud, List curves, bool inverse = cloud_.Transform(xform); var input = Geometry.RhinClip.PolylineToIntPoint(polyline, scale); - System.Threading.Tasks.Parallel.For(0, cloud.Count, i => { - // for (int i = 0; i < cloud_.Count; i++) { - + System.Threading.Tasks.Parallel.For(0, cloud.Count, i => + { if (flags[i]) return; Point3d p = new Point3d(cloud_[i].Location); var inputP = new IntPoint(p.X * scale, p.Y * scale); bool flag = Clipper642.Clipper.PointInPolygon(inputP, input) != 0;//;: Clipper642.Clipper.PointInPolygon(inputP, input) == 0; - if (flag) - flags[i] = true; - // } + if (flag) flags[i] = true; }); } - int count = 0; List idList = new List(); //System.Threading.Tasks.Parallel.For(0, cloud.Count, i => { - for (int i = 0; i < cloud.Count; i++) { - bool f = inverse ? !flags[i] : flags[i]; - if (f) { - idList.Add(i); - count++; - } + for (int i = 0; i < cloud.Count; i++) + { + bool f = inverse ? !flags[i] : flags[i]; + if (f) + { + idList.Add(i); + count++; } + } //}); int[] idArray = idList.ToArray(); Point3d[] points = new Point3d[count]; Vector3d[] normals = new Vector3d[count]; Color[] colors = new Color[count]; + double[] pvalues = new double[count]; - System.Threading.Tasks.Parallel.For(0, idArray.Length, i => { - - + System.Threading.Tasks.Parallel.For(0, idArray.Length, i => + { int id = idArray[i]; var p = cloud[(int)id]; points[i] = p.Location; normals[i] = p.Normal; colors[i] = p.Color; - + pvalues[i] = p.PointValue; }); PointCloud croppedCloud = new PointCloud(); - croppedCloud.AddRange(points, normals, colors); + if (cloud.ContainsPointValues) + { + croppedCloud.AddRange(points, normals, colors, pvalues); + } + else + { + croppedCloud.AddRange(points, normals, colors); + } //PointCloud croppedCloud = new PointCloud(); //for (int i = 0; i < cloud.Count; i++) { @@ -133,8 +138,8 @@ public PointCloud CropCloud(PointCloud cloud, List curves, bool inverse = // } // } //} - return croppedCloud; + return croppedCloud; } From 865dde889e7a276d1c30484cc106e516943166ef Mon Sep 17 00:00:00 2001 From: fstwn Date: Fri, 6 Aug 2021 13:35:19 +0200 Subject: [PATCH 7/8] add support for PointValues in CloudSection, add description to component and parameters --- CockroachGH/Cleaning/CloudSection.cs | 53 ++++++++++++++-------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/CockroachGH/Cleaning/CloudSection.cs b/CockroachGH/Cleaning/CloudSection.cs index b8e824c..85b11ce 100644 --- a/CockroachGH/Cleaning/CloudSection.cs +++ b/CockroachGH/Cleaning/CloudSection.cs @@ -11,26 +11,22 @@ public class CloudSection : GH_Component { public CloudSection() : base("CloudSection", "CloudSection", - "CloudSection", - "Cockroach", "Crop") { + "Intersect a PointCloud with one or multiple Planes using a defined Tolerance, returning the section(s) as a new PointCloud.", + "Cockroach", "Crop") { } public override GH_Exposure Exposure => GH_Exposure.quarternary; protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager) { - pManager.AddParameter(new Param_Cloud(), "PointCloud", "C", "PointCloud", GH_ParamAccess.item); - pManager.AddPlaneParameter("Planes", "P", "Planes", GH_ParamAccess.list); - pManager.AddNumberParameter("Tolerance", "T", "Searches closest points to planes, if value is negative points are projected", GH_ParamAccess.item, 1); + pManager.AddParameter(new Param_Cloud(), "PointCloud", "C", "The PointCloud to the section(s) for.", GH_ParamAccess.item); + pManager.AddPlaneParameter("Planes", "P", "The section Planes", GH_ParamAccess.list); + pManager.AddNumberParameter("Tolerance", "T", "Searches closest points to planes, if value is negative points are projected.", GH_ParamAccess.item, 1); } protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) { - - //pManager.AddGenericParameter("PointCloud", "C", "PointCloud", GH_ParamAccess.item); - pManager.AddParameter(new Param_Cloud(), "PointCloud", "C", "PointCloud", GH_ParamAccess.item); - + pManager.AddParameter(new Param_Cloud(), "PointCloud", "C", "The section(s) of the PointCloud", GH_ParamAccess.item); } protected override void SolveInstance(IGH_DataAccess DA) { - // Input var cgh = new GH_Cloud(); DA.GetData(0, ref cgh); @@ -43,8 +39,6 @@ protected override void SolveInstance(IGH_DataAccess DA) { DA.SetData(0, new GH_Cloud(SectionCloud(cgh.Value,planes,Math.Abs(distance), distance < 0))); - - } public PointCloud SectionCloud(PointCloud cloud, List planes, double tol = 0.001, bool project = false) { @@ -52,8 +46,6 @@ public PointCloud SectionCloud(PointCloud cloud, List planes, double tol bool[] flags = new bool[cloud.Count]; int[] cID = new int[cloud.Count]; - - int count = 1; foreach (Plane plane in planes) { @@ -61,17 +53,15 @@ public PointCloud SectionCloud(PointCloud cloud, List planes, double tol double denom = 1 / Math.Sqrt(eq[0] * eq[0] + eq[1] * eq[1] + eq[2] * eq[2]); - System.Threading.Tasks.Parallel.For(0, cloud.Count, i => { - // for (int i = 0; i < cloud_.Count; i++) { - + System.Threading.Tasks.Parallel.For(0, cloud.Count, i => + { if (flags[i]) return; - if (Math.Abs(FastPlaneToPt(denom, eq[0], eq[1], eq[2], eq[3], cloud[i].Location)) <= tol) { + if (Math.Abs(FastPlaneToPt(denom, eq[0], eq[1], eq[2], eq[3], cloud[i].Location)) <= tol) + { flags[i] = true; cID[i] = count; } - - }); count++; @@ -79,9 +69,11 @@ public PointCloud SectionCloud(PointCloud cloud, List planes, double tol int cc = 0; List idList = new List(); - for (int i = 0; i < cloud.Count; i++) { + for (int i = 0; i < cloud.Count; i++) + { //bool f = inverse ? !flags[i] : flags[i]; - if (flags[i]) { + if (flags[i]) + { idList.Add(i); cc++; } @@ -91,20 +83,27 @@ public PointCloud SectionCloud(PointCloud cloud, List planes, double tol Point3d[] points = new Point3d[cc]; Vector3d[] normals = new Vector3d[cc]; Color[] colors = new Color[cc]; + double[] pvalues = new double[count]; - System.Threading.Tasks.Parallel.For(0, idArray.Length, i => { - - + System.Threading.Tasks.Parallel.For(0, idArray.Length, i => + { int id = idArray[i]; var p = cloud[(int)id]; points[i] = p.Location; normals[i] = p.Normal; colors[i] = p.Color; - + pvalues[i] = p.PointValue; }); PointCloud croppedCloud = new PointCloud(); - croppedCloud.AddRange(points, normals, colors); + if (cloud.ContainsPointValues) + { + croppedCloud.AddRange(points, normals, colors, pvalues); + } + else + { + croppedCloud.AddRange(points, normals, colors); + } //PointCloud croppedCloud = new PointCloud(); //for (int i = 0; i < cloud.Count; i++) { From ec51b06898168243d3d6c9cd9f87202dcf5a1580 Mon Sep 17 00:00:00 2001 From: fstwn Date: Fri, 6 Aug 2021 12:12:55 +0200 Subject: [PATCH 8/8] Add "HasPointValues" marker to ToString method --- CockroachGH/PointCloudParam/GH_Cloud.cs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/CockroachGH/PointCloudParam/GH_Cloud.cs b/CockroachGH/PointCloudParam/GH_Cloud.cs index 84a41c6..79301e0 100644 --- a/CockroachGH/PointCloudParam/GH_Cloud.cs +++ b/CockroachGH/PointCloudParam/GH_Cloud.cs @@ -37,17 +37,10 @@ public BoundingBox ClippingBox { } } - - - - - - public override bool IsGeometryLoaded { get { return base.m_value != null; } } - public override bool IsValid { get { bool flag; @@ -97,7 +90,6 @@ public GH_Cloud() { this.ReferenceGuid = Guid.Empty; this.ScanPos = Plane.WorldXY; } - public GH_Cloud(GH_Cloud other) { this.ScanPos = Plane.WorldXY; this.ReferenceGuid = Guid.Empty; @@ -326,8 +318,7 @@ private void ResolveDisplay() { } public override string ToString() { - return string.Format("PointCloud {0} HasNormals {1} HasColors {2}", this.m_value.Count, this.m_value.ContainsNormals, this.m_value.ContainsColors).ToString(); - + return string.Format("PointCloud {0} HasNormals {1} HasColors {2} HasPointValues {3}", this.m_value.Count, this.m_value.ContainsNormals, this.m_value.ContainsColors, this.m_value.ContainsPointValues).ToString(); } public override IGH_GeometricGoo Transform(Transform xform) {