Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: andyroo on December 02, 2017, 01:31:10 AM

Title: easy way to count number of selected points in sparse cloud?
Post by: andyroo 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])
Title: Re: easy way to count number of selected points in sparse cloud?
Post by: Erik Holmlund 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.