Forum

Author Topic: Correcting model's axis  (Read 4141 times)

Mfranquelo

  • Full Member
  • ***
  • Posts: 171
    • View Profile
Correcting model's axis
« on: June 11, 2015, 03:06:59 PM »
Dear all,

I can´t seem to be able to correct the model's axis. I am trying to do a turntable movie on zBrush -as of now i didn´t need to correct the axis- but it seems that zBrush uses the model's axis and not the global zBrush axis to rotate the model across time.

I dont have references to create scale bars for this particular model... so i can´t scale it nor orientate it.
I've tried using a .py script that i've found to match the bounding box axis. But it doesnt seem to work...

Any ideas? :-) 

« Last Edit: June 11, 2015, 03:32:49 PM by Mfranquelo »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14890
    • View Profile
Re: Correcting model's axis
« Reply #1 on: June 11, 2015, 03:09:38 PM »
Hello Mfranquelo,

The script is for the version 1.0, if you can post it here I will try to fix it for the version 1.1 as soon as possible.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Mfranquelo

  • Full Member
  • ***
  • Posts: 171
    • View Profile
Re: Correcting model's axis
« Reply #2 on: June 11, 2015, 03:12:22 PM »
Thank you Alex,

This is the scrypt:

#scale is kept
#compatibility: Agisoft PhotoScan Professional 0.9.0


import PhotoScan
import math

doc = PhotoScan.app.document

chunk = doc.activeChunk

R = chunk.region.rot      #Bounding box rotation matrix
C = chunk.region.center      #Bounding box center vector

if chunk.transform:
   T = chunk.transform
   s = math.sqrt(T[0,0]*T[0,0] + T[0,1]*T[0,1] + T[0,2]*T[0,2])       #scaling
   S = PhotoScan.Matrix( [[s, 0, 0, 0], [0, s, 0, 0], [0, 0, s, 0], [0, 0, 0, 1]] ) #scale matrix
else:
   S = PhotoScan.Matrix( [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]] )

T = PhotoScan.Matrix( [[R[0,0],R[0,1],R[0,2], C[0]], [R[1,0],R[1,1],R[1,2],C[1]], [R[2,0],R[2,1],R[2,2],C[2]], [0,0,0,1]])

chunk.transform = S * T.inv()      #resulting chunk transformation matrix

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14890
    • View Profile
Re: Correcting model's axis
« Reply #3 on: June 11, 2015, 03:23:57 PM »
Hello Mfranquelo,

Are you sure that this script copies the bounding box?

It should be a working modification for 1.1.6, but it seems to be orienting the coordinate system parallel to the bounding box sides.
Code: [Select]
#compatibility: Agisoft PhotoScan Professional 1.1.6

import PhotoScan
import math

doc = PhotoScan.app.document

chunk = doc.chunk

R = chunk.region.rot      #Bounding box rotation matrix
C = chunk.region.center      #Bounding box center vector

T = chunk.transform.matrix
s = math.sqrt(T[0,0]*T[0,0] + T[0,1]*T[0,1] + T[0,2]*T[0,2])       #scaling
S = PhotoScan.Matrix( [[s, 0, 0, 0], [0, s, 0, 0], [0, 0, s, 0], [0, 0, 0, 1]] ) #scale matrix

T = PhotoScan.Matrix( [[R[0,0],R[0,1],R[0,2], C[0]], [R[1,0],R[1,1],R[1,2],C[1]], [R[2,0],R[2,1],R[2,2],C[2]], [0,0,0,1]])

chunk.transform.matrix = S * T.inv()      #resulting chunk transformation matrix
Best regards,
Alexey Pasumansky,
Agisoft LLC

Mfranquelo

  • Full Member
  • ***
  • Posts: 171
    • View Profile
Re: Correcting model's axis
« Reply #4 on: June 11, 2015, 03:29:56 PM »
Yeah sorry, i've just got into the Wiki for the PY scripts and found the appropiate one for 1.1
Its this one: -i meant match the bounding box axis, not copy it-

#rotates model coordinate system in accordance of bounding box for active chunk
#scale is kept
#compatibility: Agisoft PhotoScan Professional 1.1.0

import PhotoScan
import math

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

R = chunk.region.rot      #Bounding box rotation matrix
C = chunk.region.center      #Bounding box center vector

if chunk.transform.matrix:
   T = chunk.transform.matrix
   s = math.sqrt(T[0,0] ** 2 + T[0,1] ** 2 + T[0,2] ** 2)       #scaling
   S = PhotoScan.Matrix( [[s, 0, 0, 0], [0, s, 0, 0], [0, 0, s, 0], [0, 0, 0, 1]] ) #scale matrix
else:
   S = PhotoScan.Matrix( [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]] )

T = PhotoScan.Matrix( [[R[0,0], R[0,1], R[0,2], C[0]], [R[1,0], R[1,1], R[1,2], C[1]], [R[2,0], R[2,1], R[2,2], C[2]], [0, 0, 0, 1]])

chunk.transform.matrix = S * T.inv()      #resulting chunk transformation matrix

Thanks!
« Last Edit: June 11, 2015, 03:33:21 PM by Mfranquelo »