Forum

Author Topic: easy way to count number of selected points in sparse cloud?  (Read 2573 times)

andyroo

  • Sr. Member
  • ****
  • Posts: 440
    • View Profile
easy way to count number of selected points in sparse cloud?
« on: December 02, 2017, 01:31:10 AM »
I am trying to figure out how to get the number of selected points. Do I need to iterate through the whole cloud looking at the [selected] flag or can I query the cloud attributes like:
Code: [Select]
npoints =len(chunk.point_cloud.points)?

So far the only way I've found is to iterate:
Code: [Select]
chunk = doc.chunk
points = chunk.point_cloud.points
nselected = len([True for point in points if point.valid is True and point.selected is True])

Erik Holmlund

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: easy way to count number of selected points in sparse cloud?
« Reply #1 on: December 07, 2017, 10:48:52 AM »
You can solve it with a list comprehension, like you started on.

Code: [Select]
chunk = doc.chunk
points = chunk.point_cloud.points
nselected = len([p for p in points if p.selected])

or just
Code: [Select]
chunk = doc.chunk
nselected = len([p for p in chunk.point_cloud.points if p.selected])

It calculates it really quickly on my computer.