Author Topic: How to count the number of points within the bounding box  (Read 2904 times)


  • Newbie
  • *
  • Posts: 19
    • View Profile
How to count the number of points within the bounding box
« on: October 14, 2016, 05:29:14 PM »

Is there any way to return the number of points within the bounding box? Agisoft clearly knows which are in and which are out for the later processing steps.

I suppose the time intensive way would be to calculate whether the coordinates of each point are in the bounding box as defined by its center, size, and rotation. I think my point coordinates are in a different reference frame than my bounding box, though. Perhaps I would need to transform them first.

Thank you,

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14965
    • View Profile
Re: How to count the number of points within the bounding box
« Reply #1 on: October 21, 2016, 06:42:21 PM »
Hello Rebecca,

If you are accessing and point.coord (for point in chunk.point_cloud.points) they are in the same coordinate space (internal chunk system), so for every point you can check if it is in the box or not (no need to convert it to geographic coordinates).

I think I was doing something like the following to solve the similar task:

Code: [Select]
import PhotoScan
chunk =
R = chunk.region.rot
C =
size = chunk.region.size
for point in chunk.point_cloud.points:
  if point.valid:
  v = point.coord
  v.size = 3
  v_c = v - C
  v_r = R.t() * v_c
  if abs(v_r.x) > abs(size.x / 2.):
  point.selected = True
  elif abs(v_r.z) > abs(size.z / 2.):
  point.selected = True
  elif abs(v_r.y) > abs(size.y / 2.):
  point.selected = True
The script selects all the points outside the box, but you can use point.valid = False to remove the point from the sparse cloud.
Best regards,
Alexey Pasumansky,
Agisoft LLC