Forum

Author Topic: Python script  (Read 4548 times)

fabvin

  • Newbie
  • *
  • Posts: 22
    • View Profile
Python script
« on: June 02, 2016, 05:46:27 PM »
Dear all,
Based on previous scripts from posts "Topic: region box translation after re-oriented", I created a function to set a bounding box according to a sextuplet of coordinates in a given coordinate system (in my case the EPSG:2154):

Code: [Select]
def set_box(xmin,xmax,ymin,ymax,zmin,zmax):
        doc=PhotoScan.app.document
        chunk=doc.chunk
        region = chunk.region
        r_center = region.center
        r_rotate = region.rot
        r_size = region.size
        x_scale = (xmax-xmin)/2
        y_scale = (ymax-ymin)/2
        z_scale = (zmax-zmin)/2
        new_region = PhotoScan.Region()
        new_rot = r_rotate
        new_center = PhotoScan.Vector([xmin+x_scale,ymin+y_scale,zmin+z_scale])
        new_center = chunk.transform.matrix.inv().mulp(chunk.crs.unproject(new_center))
        new_size = PhotoScan.Vector([x_scale * 5, y_scale * 5, z_scale * 5])
        #new_size = PhotoScan.Vector([x_scale, y_scale, z_scale])
        #new_size = chunk.transform.matrix.inv().mulp(chunk.crs.unproject(new_size))
        new_region.size = new_size
        new_region.center = new_center
        new_region.rot = new_rot
        chunk.region = new_region

However, the commented lines didn't work! When I tried them instead of the two previous ones, the bounding box disappears... I really don't understand why it doesn't work, as the new_center position looks right...

That's why I changed the two commented lines to get a box, but of course the size of the box is not correct.
Any help on the correct code is appreciated.

Best regards,
Fabrice

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15650
    • View Profile
Re: Python script
« Reply #1 on: June 02, 2016, 05:51:14 PM »
Hello Fabrice,

The size of the region is vector and not a point, like it's center, so in the second commented line I suggest to use .mulv() instead of .mulp() method.
Best regards,
Alexey Pasumansky,
Agisoft LLC