/// <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) { //define i/o parameters GH_PointCloud pc = null; double resolution = 0.05; // read inputs if (!DA.GetData(0, ref pc)) { return; } if (!DA.GetData(1, ref resolution)) { return; } // Exceptions if (!pc.IsValid) { throw new Exception("Invalid Point Cloud"); } if (resolution <= 0.002) { throw new Exception("This resolution is to small "); } pc = pc.GenerateRandomCloud(resolution); // there is a problem here /// Output DA.SetData(0, pc); }
/// <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) { //define i/o parameters GH_PointCloud pc = null; List <Vector3d> eigenvectors = null; List <double> eigenvalues = null; // read inputs if (!DA.GetData(0, ref pc)) { return; } // some error catching here if (pc.Value.Count < 3) { throw new Exception("Pick a larger set"); } if (!pc.IsValid) { throw new Exception("Invalid Point Cloud"); } // method pc.ComputePrincipalComponents(out eigenvectors, out eigenvalues); /// Output DA.SetDataList(0, eigenvectors); DA.SetDataList(1, eigenvalues); }
/// <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) { //define i/o parameters GH_PointCloud pc = null; Double k = 6; // read inputs if (!DA.GetData(0, ref pc)) { return; } if (!DA.GetData("k", ref k)) { return; } // Exceptions if (pc.Value.Count <= k) { throw new Exception("Use point clouds with more than k points"); } if (k < 3) { throw new Exception("enter value k >=3"); } /// interal parameters if (!pc.Value.ContainsNormals) { pc.ComputeNormals((int)k); } /// Output DA.SetData(0, pc); }
/// <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) { // Define i/o parameters GH_PointCloud pc = null; Double k = 0.0; // Read inputs if (!DA.GetData(0, ref pc)) { return; } if (!DA.GetData("k", ref k)) { return; } // Exceptions if (!pc.IsValid) { throw new Exception("Invalid point cloud"); } if (k < 0 || k > 1) { throw new Exception("provide resolution between 0 and 1"); } if ((double)pc.Value.Count * k < 2) { throw new Exception("insufficient points in point cloud"); } // Output DA.SetData(0, pc.ComputeResolution(k)); }
/// <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) { //define i/o parameters GH_PointCloud pc = null; double nrPlanes = 1.0; double tolerance = 0.05; List <Brep> breps = null; List <double> rmse = new List <double>(); // read inputs if (!DA.GetData(0, ref pc)) { return; } if (!DA.GetData(1, ref nrPlanes)) { return; } if (!DA.GetData(2, ref tolerance)) { return; } // include some more error catching here if (tolerance < 0) { throw new Exception("Choose a value >0"); } if (!pc.IsValid || pc.Value.Count < 2) { throw new Exception("Invalid Point Cloud"); } try { pc.FitPlanarSurfaces(out breps, out rmse, (int)nrPlanes, tolerance); } catch { throw new Exception("Something went wrong with the planefitting."); } /// Output DA.SetDataList(0, breps); DA.SetDataList(1, rmse); }
/// <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) { //define i/o parameters GH_PointCloud pc = null; // read inputs if (!DA.GetData(0, ref pc)) { return; } // Exceptions if (pc.Value.Count < 4) { throw new Exception("Use point clouds with more than 3 points"); } Mesh mesh = pc.ComputeConvexHull3D(); /// Output DA.SetData(0, mesh); }
/// <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) { //define i/o parameters GH_PointCloud pc = null; Mesh mesh = new Mesh(); double resolution = 0.05; // read inputs if (!DA.GetData(0, ref mesh)) { return; } if (!DA.GetData(1, ref resolution)) { return; } // Exceptions if (!mesh.IsValid) { throw new Exception("Invalid mesh"); } var area = Math.Sqrt(AreaMassProperties.Compute(mesh).Area); if (area < resolution) { pc = mesh.GetVertexCloud(); /// this is incorrect } else { pc = mesh.GenerateSpatialCloud(resolution); } /// Output DA.SetData(0, pc); }
/// <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) { //define i/o parameters GH_PointCloud pc = null; Brep brep = new Brep(); // read inputs if (!DA.GetData(0, ref pc)) { return; } if (!DA.GetData(1, ref brep)) { return; } // Exceptions if (!pc.IsValid) { throw new Exception("Invalid Point Cloud"); } if (!brep.IsSolid) { throw new Exception("Provide a closed Brep"); } if (!brep.IsManifold) { throw new Exception("Provide a manifold Brep"); } GH_PointCloud pc_out = pc.CropPointCloud(brep); /// Output DA.SetData(0, pc_out); }
/// <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) { //define i/o parameters GH_PointCloud pc = new GH_PointCloud(); Object geometry = null; Interval interval = new Interval(0.0, 1.0); // read inputs if (!DA.GetData(0, ref pc)) { return; } if (!DA.GetData(1, ref geometry)) { return; } if (!DA.GetData(2, ref interval)) { return; } // Exceptions if (!pc.IsValid) { throw new Exception("Invalid Point Cloud"); } if (pc.ContainsDistances) { pc.ClearDistances(); } //typecasting => maybe some more types can be included? var type = geometry.GetType(); GH_PointCloud gH_PointCloud = null; GH_Mesh mesh = null; GH_Brep brep = null; if (type == typeof(GH_PointCloud)) { gH_PointCloud = (GH_PointCloud)geometry; pc.DistanceTo(gH_PointCloud); } else if (type == typeof(PointCloud)) { gH_PointCloud.Value = (PointCloud)geometry; pc.DistanceTo(gH_PointCloud); } else if (type == typeof(Brep)) { pc.DistanceTo((Brep)geometry); } else if (type == typeof(GH_Brep)) { brep = (GH_Brep)geometry; pc.DistanceTo(brep.Value); } else if (type == typeof(Mesh)) { pc.DistanceTo((Mesh)geometry); } else if (type == typeof(GH_Mesh)) { mesh = (GH_Mesh)geometry; pc.DistanceTo(mesh.Value); } else { throw new Exception("Only submit GH_PointCloud, PointCloud, Brep or Mesh geometry. \n If it's another type of point cloud (e.g. Volvox, Tarsier, etc.) \n just pass it through a normal Grasshopper cloud parameter first."); } // filter point cloud based on distance GH_PointCloud pc_out = null; if (!pc.ContainsDistances) { throw new Exception("Something went wrong with the distances"); } var indices = pc.Distances .Select((distance, index) => index) .Where(index => interval.IncludesParameter(pc.Distances[index], false)); // this is superfast pc_out = pc.GetSubsection(indices); // Output DA.SetData(0, pc_out); }
/// <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) { // Define i/o parameters GH_PointCloud pcA = null; GH_PointCloud pcB = null; double metric = 0.0, inlierRatio = 0.2, maxIterations = 20, downsamplingA = 1.0, downsamplingB = 1.0; // Read inputs if (!DA.GetData(0, ref pcA)) { return; } if (!DA.GetData(1, ref pcB)) { return; } if (!DA.GetData("Metric", ref metric)) { return; } if (!DA.GetData("InlierRatio", ref inlierRatio)) { return; } if (!DA.GetData("MaxIterations", ref maxIterations)) { return; } if (!DA.GetData("Downsample A", ref downsamplingA)) { return; } if (!DA.GetData("Downsample B", ref downsamplingB)) { return; } // Exceptions if (pcA.Value.Count <= 1 || pcB.Value.Count <= 1) { throw new Exception("Use point clouds with more than 1 point"); } if (downsamplingA < 0.01 || downsamplingA > 0.99) { throw new Exception("Use downsampling between 0.01 and 0.99 for point cloud A"); } if (downsamplingB < 0.01 || downsamplingB > 0.99) { throw new Exception("Use downsampling between 0.01 and 0.99 for point cloud A"); } if (metric == 1 && !pcA.Value.ContainsNormals) { pcA.ComputeNormals(); } SpatialTools.RegisterPointClouds(out Transform transform, out Double rmse, ref pcA, ref pcB, metric, inlierRatio, maxIterations, downsamplingA, downsamplingB); DA.SetData(0, transform); DA.SetData(1, rmse); }