Forum

Author Topic: Delete Points Outside of Bounding Box  (Read 6166 times)

Costas

  • Jr. Member
  • **
  • Posts: 72
  • Aerial Mapping
    • View Profile
Delete Points Outside of Bounding Box
« on: October 25, 2023, 10:12:02 AM »
I was using Metashape v1.8.2 and now i upgraded to v.2.0.3

I had a script to delete all points (tie points) that are Outside of the bounding box.
In the new version this script runs without giving me any error but it actually does nothing at all and it does not delete any points.

I do not know about scripting and i would like someone to help me convert this script to run properly in v.2.0.3

Code: [Select]
import Metashape
def main():
doc = Metashape.app.document
for i in range(len(doc.chunks)):
chunk = doc.chunks[i]
R = chunk.region.rot #Bounding box rotation matrix
C = chunk.region.center #Bounding box center vertor
size = chunk.region.size

if not (chunk.point_cloud and chunk.enabled):
continue
elif not len(chunk.point_cloud.points):
continue
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.valid = False
elif abs(v_r.y) > abs(size.y / 2.):
point.valid = False
elif abs(v_r.z) > abs(size.z / 2.):
point.valid = False
else:
continue

print("Script finished. Points outside the region were removed.")

Metashape.app.addMenuItem("Scripts/Delete Points Outside Bounding Box", main)

Paulo

  • Hero Member
  • *****
  • Posts: 1381
    • View Profile
Re: Delete Points Outside of Bounding Box
« Reply #1 on: October 25, 2023, 05:05:26 PM »
Hello,

Just change every instance of point_cloud to tie_points in your script and it should work...
Best Regards,
Paul Pelletier,
Surveyor

Costas

  • Jr. Member
  • **
  • Posts: 72
  • Aerial Mapping
    • View Profile
Re: Delete Points Outside of Bounding Box
« Reply #2 on: October 26, 2023, 09:02:46 AM »
Thank you Paulo.

Works like a charm.