Point cloud point selection


#1

Hi,

I need a fast way to select points of a pointcloud. In Rhino this can be done with the tool pointcloud -> remove points. Does anyone know how to do this in python / rhino common?

Thanks in advance!


#2

You can use PointCloud.PointAt if you want to get the coordinate of a point in a specific index of a point cloud:

import rhinoscriptsyntax as rs
pointCloud = rs.GetObject("Select point cloud", rs.filter.pointcloud)
pointCloud = rs.coercegeometry(pointCloud)
rs.AddPoint(pointCloud.PointAt(20))

powerpp.py (182 Bytes)


#3

Thanks Mahdiyar,
but what I am looking for is a fast way to get a point cloud subselection.
I need to know the indices or coordinates of the selected points (within selection rectangle)


(Graham) #4

Maybe using one of the RTree methods - there seem to be some dedicated specifically to point clouds. If I understand correctly they should be very fast :rocket:

https://developer.rhino3d.com/api/RhinoCommon/html/Methods_T_Rhino_Geometry_RTree.htm


#5

Also thank you Graham. Yes - RTree is a fast way to work on a pointcloud. The disadvantage is, that you first have to initialize all points to an rtree.
But I need a very quick way of selecting points from a pointcloud with a selection window. This can be done in rhino by using the tool for removing points from a pointcloud. I assume there is some openGL stuff behind this. Hopefully this is wrapped in some way in rhino common…

thanks,
Philip


#6

Are you looking for GetObjects with filter = 2?

https://developer.rhino3d.com/api/RhinoScriptSyntax/#collapse-GetObjects


#7

Thanks rgr, but this would select the entire pointcloud. I need a sub-selection as shown in the picture. This picture was taken while using the rhino tool for removing points of a pointcloud (yellow, selected points will be removed from the pointcloud and inserted as points in rhino after confirming the command)


#8

@powerpp, i figured, there could be multiple pointclouds (and points) in the window selection, so getting the selected pointcloud point indices required some stretching…

import Rhino
from collections import defaultdict

def DoSomething():
    # prompt for pointcloud points
    go = Rhino.Input.Custom.GetObject()
    go.SetCommandPrompt("Select pointcloud points")
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Point
    go.GetMultiple(1, 0)
    
    if go.CommandResult() != Rhino.Commands.Result.Success: return 
    if not go.Objects(): return 
    
    # dictionary: (key = cloud object guid, value = selected cloud pt indices)
    my_dict = defaultdict(lambda: [])
    
    for obj_ref in go.Objects():
        if isinstance(obj_ref.Object(), Rhino.DocObjects.PointCloudObject):
            my_dict[obj_ref.Object().Id].append(obj_ref.GeometryComponentIndex.Index)
    
    for cloud_id, indices in my_dict.iteritems():
        print "CloudId: {} >>> {} points selected".format(cloud_id, len(indices))

DoSomething()

_
c.