Delete points from a pointcloud in RhinoCommon?

I am using this code to have the user select specific points from a loaded point cloud. The idea is to allow them to manually prune the point cloud to get rid of any noise. However, I can’t find anywhere how these points could be deleted?

       {
           ObjRef[] obj_refs;
           var rc = Rhino.Input.RhinoGet.GetMultipleObjects("Select point", false, ObjectType.Point, out obj_refs);
           if (rc != Result.Success)
               return rc;
           foreach (var o_ref in obj_refs)
           {
              var point = o_ref.Point();
               RhinoApp.WriteLine("Point: x:{0}, y:{1}, z:{2}",
                 point.Location.X,
                 point.Location.Y,
                 point.Location.Z);

           }
           doc.Objects.UnselectAll();

           doc.Views.Redraw();
           return Result.Success;
       }

So far I am able to select the points and print out their coordinates, but I can not find a way to delete them. Thanks for the help!

Hello,

you need to find indicies of those points in point cloud. After that for one or multiple indicies you may delete that point from cloud:
https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_PointCloud_RemoveAt.htm
https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_PointCloud_RemoveRange.htm
To find index I would try
https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_GeometryBase_ComponentIndex.htm
or closest point if above idea fails (closest point may be slow for big clouds)
https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_PointCloud_ClosestPoint.htm

In the end I suggest to test free CloudCompare software for editing massive point clouds since it is way faster and efficient. After that cloud can be imported to Rhino.

Thank you for your answer.

I have now implemented this code:

            var rc = RhinoGet.GetOneObject("Select point cloud", false, ObjectType.PointSet, out var obj_ref);
            if (rc != Result.Success)
            {
                return rc;
            }

            var cloud = obj_ref.PointCloud();

            ObjRef[] obj_refs_p;
            rc = Rhino.Input.RhinoGet.GetMultipleObjects("Select points", false, ObjectType.Point, out obj_refs_p);
            if (rc != Result.Success)
            {
                return rc;
            }

                foreach (var o_ref in obj_refs_p)
                {
                    var point = o_ref.Point();
                    RhinoApp.WriteLine("Point: x:{0}, y:{1}, z:{2}",
                      point.Location.X,
                      point.Location.Y,
                      point.Location.Z);

                var index = o_ref.Point().ComponentIndex().Index;
                cloud.RemoveAt(index);

                }

In an attempt to get the index of each point and remove it that way. However, it seems the index is always -1, which according to the documentation means the object is not a sub-piece of a larger geometric entity. I’m not sure how that works, considering it is supposed to be part of the point cloud?