Forum

Author Topic: Rotate chunk  (Read 4549 times)

chr00t

  • Newbie
  • *
  • Posts: 12
    • View Profile
Rotate chunk
« on: August 23, 2016, 06:00:40 PM »
Hello,

Is it possible to rotate a chunk so a chosen camera gets at 0.0 for each omega kappa phi angles? Would you provide a snippet code?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15464
    • View Profile
Re: Rotate chunk
« Reply #1 on: August 24, 2016, 02:02:51 PM »
Hello chr00t,

You can use the following script to apply the defined rotations around each coordinate system axis:
Code: [Select]
import PhotoScan
from math import pi, cos, sin
from PySide import QtCore, QtGui


class RotateDlg(QtGui.QDialog):

def __init__ (self, parent):
QtGui.QDialog.__init__(self, parent)


self.setWindowTitle("Rotate Scene")

self.btnQuit = QtGui.QPushButton("&Exit")
self.btnQuit.setFixedSize(150,50)

self.btnP1 = QtGui.QPushButton("&Apply Rotation")
self.btnP1.setFixedSize(150,50)

self.xrotEdt = QtGui.QLineEdit()
self.xrotEdt.setPlaceholderText("OX rotation")
self.xrotEdt.setFixedSize(150, 25)

self.yrotEdt = QtGui.QLineEdit()
self.yrotEdt.setPlaceholderText("OY rotation")
self.yrotEdt.setFixedSize(150, 25)

self.zrotEdt = QtGui.QLineEdit()
self.zrotEdt.setPlaceholderText("OZ rotation")
self.zrotEdt.setFixedSize(150, 25)

layout = QtGui.QGridLayout()   #creating layout
layout.setSpacing(10)
layout.addWidget(self.xrotEdt, 0, 0)

layout.addWidget(self.yrotEdt, 1, 0)

layout.addWidget(self.zrotEdt, 2, 0)
layout.addWidget(self.btnP1, 2, 1)
layout.addWidget(self.btnQuit, 2, 2)
self.setLayout(layout) 

proc_values = lambda : self.procRotate()

QtCore.QObject.connect(self.btnP1, QtCore.SIGNAL("clicked()"), proc_values)
QtCore.QObject.connect(self.btnQuit, QtCore.SIGNAL("clicked()"), self, QtCore.SLOT("reject()"))

self.exec()

def procRotate(self):

chunk = doc.chunk

#xrot, yrot, zrot = 0, 0, 0

xrot = self.xrotEdt.text()
if xrot.isdigit():
xrot = int(xrot) * pi / 180.
else:
xrot = 0

yrot = self.yrotEdt.text()
if yrot.isdigit():
yrot = int(yrot) * pi / 180.
else:
yrot = 0

zrot = self.zrotEdt.text()
if zrot.isdigit():
zrot = int(zrot) * pi / 180.
else:
zrot = 0

print("Script started")

T = chunk.transform.matrix

A, B = cos(xrot), sin(xrot)
C, D = cos(yrot), sin(yrot)
E, F = cos(zrot), sin(zrot)

xm = PhotoScan.Matrix( [[1,0,0,0],[0,A,-B,0],[0,B,A,0],[0,0,0,1]] )
ym = PhotoScan.Matrix( [[C,0,-D,0],[0,1,0,0],[D,0,C,0],[0,0,0,1]] )
zm = PhotoScan.Matrix( [[E,-F,0,0],[F,E,0,0],[0,0,1,0],[0,0,0,1]] )

chunk.transform.matrix = xm * ym * zm * T

PhotoScan.app.update()
print("Script finished")

return 1

def main():

global doc
doc = PhotoScan.app.document
app = QtGui.QApplication.instance()
parent = app.activeWindow()
dlg = RotateDlg(parent)

PhotoScan.app.addMenuItem("Custom menu/Rotate Scene", main)

The order of rotation is Rx, Ry and Rz.
Best regards,
Alexey Pasumansky,
Agisoft LLC