Forum

Author Topic: Script to match Z axis  (Read 4596 times)

nachogi73

  • Newbie
  • *
  • Posts: 39
    • View Profile
Script to match Z axis
« on: June 26, 2014, 05:43:46 PM »
Hi

I need to match the Z axis of my model (calculate via survey gpc) and the Region Box Z axis.

So I need to create the mesh in height field mode but the program uses the z axis of the Box and this is no the real vertical direction.

Does anyone know a script to do this action?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14099
    • View Profile
Re: Script to match Z axis
« Reply #1 on: June 26, 2014, 05:51:20 PM »
Hello nachogi73,

You can rotate the bounding box to align its Z-axis with the coordinate system vertical direction.

I think that the script has been posted somewhere here, but there's no problem to copy it once again:
Code: [Select]
import PhotoScan, math

doc = PhotoScan.app.document
chunk = doc.activeChunk

if chunk.transform:
       T = chunk.transform
else:
       T = PhotoScan.Matrix().diag([1,1,1,1])

v = PhotoScan.Vector( [0,0,0,1] )
v_t = T * v
v_t.size = 3

if chunk.crs:
m = chunk.crs.localframe(v_t)
else:
m = PhotoScan.Matrix().diag([1,1,1,1])
m = m * T

s = math.sqrt(m[0,0]*m[0,0] + m[0,1]*m[0,1] + m[0,2]*m[0,2]) #scale factor
R = PhotoScan.Matrix( [[m[0,0],m[0,1],m[0,2]], [m[1,0],m[1,1],m[1,2]], [m[2,0],m[2,1],m[2,2]]])
R = R * (1. / s)

reg = chunk.region
reg.rot = R.t()
chunk.region = reg
Best regards,
Alexey Pasumansky,
Agisoft LLC

nachogi73

  • Newbie
  • *
  • Posts: 39
    • View Profile
Re: Script to match Z axis
« Reply #2 on: April 07, 2015, 01:09:36 PM »
Hi again:

This script  seems not work in newer versions of Photoscan.

There is another solution for this issue.

Sorry I´m complete ignorant in scripting

Seb_B

  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Script to match Z axis
« Reply #3 on: April 07, 2015, 02:42:17 PM »
Hello,

the script to rotate the bounding box is written in the wiki:
http://wiki.agisoft.com/wiki/Python