Forum

Author Topic: Checking point cloud points inside bounding box  (Read 5388 times)

cwsullivan

  • Newbie
  • *
  • Posts: 1
    • View Profile
Checking point cloud points inside bounding box
« on: February 09, 2016, 04:36:07 AM »
Hi,

Sometimes my custom bounding box calculation gets messy, so I make a call to reset it with chunk.resetRegion(). As a sanity check, I've written a simple function to then check that all the points from the point cloud are now within that region even if they weren't before:

Code: [Select]
def fraction_of_points_inside_box(chunk):
    region_center = chunk.region.center
    region_size = chunk.region.size

    xmin = region_center[0] - region_size[0]/2
    xmax = region_center[0] + region_size[0]/2
    ymin = region_center[1] - region_size[1]/2
    ymax = region_center[1] + region_size[1]/2
    zmin = region_center[2] - region_size[2]/2
    zmax = region_center[2] + region_size[2]/2

    N = 0
    for point in chunk.point_cloud.points:
        x = point.coord[0]; y = point.coord[1]; z = point.coord[2]
        if x > xmin and x < xmax and y > ymin and y < ymax and z > zmin and z < zmax:
            N +=1

    fraction = N/float(len(chunk.point_cloud.points))
    return fraction

THRESHOLD_TO_RESET_BOUNDING_BOX = 0.1
fraction  = fraction_of_points_inside_box(chunk)
if fraction < THRESHOLD_TO_RESET_BOUNDING_BOX:
    chunk.resetRegion()
    new_fraction  = fraction_of_points_inside_box(chunk)
    print("Resetting bounding box, too many points lay outside it. Old fraction: {}, New Fraction: {}".format(fraction, new_fraction))

However, I get a result that suggests my checking function isn't working (majority of points still NOT in box). My first guess was that the bounding box coords must not be in the same coordinate frame as the point cloud, or not co-aligned with the coordinate system axes, but the more I look at it, the more it appears the bounding box after a resetRegion() call *should* be co-aligned with the chunk's coordinate system, no? Otherwise obviously my simple geometric check isn't valid.

Any ideas on an easy way to perform this check? (Because I also need it to know WHEN to resetRegion)

(PhotoScanPro 1.2.3)

reperry

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Checking point cloud points inside bounding box
« Reply #1 on: February 18, 2016, 12:37:00 AM »
I'm interested in this question too-- I'm suspecting multiple different coordinate systems at the root of a problem I have too. When I try to slide a bounding box along one axis (with a python script), it moves along all three axes.