Forum

Author Topic: Python Region Bug  (Read 1173 times)

aaronfhd

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Python Region Bug
« on: July 05, 2022, 10:50:19 PM »
Hi I am using Python to set my region and then save the file.

When I Open the file the region is not in the correct spot that it showed before saving it.

If I move it manually in to position and save it, it works.


Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14003
    • View Profile
Re: Python Region Bug
« Reply #1 on: July 06, 2022, 01:44:46 PM »
Hello aaronfhd,

Can you provide the lines that you are using to modify the region (probably, something simple also raises the same behavior, like chunk.region.size *= 10), and how the document save operation is called afterwards?

Also please specify, if you are running the script in headless mode or via Metashape GUI.
Best regards,
Alexey Pasumansky,
Agisoft LLC

aaronfhd

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Re: Python Region Bug
« Reply #2 on: July 06, 2022, 02:05:17 PM »
def placeRegion(center,size,angle):
   crs = chunk.crs
   T = chunk.transform.matrix
   center = Metashape.Vector((center[0],center[1],center[2]))
   center = T.inv().mulp(crs.unproject(center))
   m = crs.localframe(T.mulp(center)) * T
   R = m.rotation() * (1. / m.scale())
   size = Metashape.Vector((size[0],size[1],size[2])) / m.scale()  # scaling the size is required
   angle = numpy.radians(angle)
   rot = Metashape.Matrix([[numpy.cos(angle), -numpy.sin(angle), 0], [numpy.sin(angle), numpy.cos(angle), 0], [0, 0, 1]])
   rotation = R.t() * rot
   
   chunk.region.rot = rotation
   chunk.region.center = center
   chunk.region.size = size



 placeRegion(center,size,angle)
 doc.save()

aaronfhd

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Re: Python Region Bug
« Reply #3 on: July 07, 2022, 10:37:46 PM »
ok this seems to introduce a a bit of weird issues.

If you use the script above

Meshing takes forever and the mesh appears weird by the edge of the region.

Moving it manually does not.

aaronfhd

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Re: Python Region Bug
« Reply #4 on: July 08, 2022, 01:59:15 PM »
Ok  so very reproduceable using the script

and then after it seem the file is in a weird state unless you manually do the region.

Once you do that it fine.