Copy Bounding Box.py

From Agisoft
Revision as of 14:36, 9 February 2015 by Alexey (Talk | contribs) (Created page with "<pre> #resizes all bounding boxes to Active chunk bounding box #creates Custom Menu item. #can be put to the autostart script folder #compatibility PhotoScan Pro 1.1.0 im...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
#resizes all bounding boxes to Active chunk bounding box

#creates Custom Menu item.
#can be put to the autostart script folder


#compatibility PhotoScan Pro 1.1.0 

import PhotoScan

def main():

	doc = PhotoScan.app.document

	chunk = doc.chunk
	T0 = chunk.transform.matrix

	region = chunk.region
	R0 = region.rot
	C0 = region.center
	s0 = region.size

	for chunk in doc.chunks:
	
		if chunk == doc.chunk:
			continue
		
		T = chunk.transform.matrix.inv() * T0
		
		R = PhotoScan.Matrix( [[T[0,0],T[0,1],T[0,2]], [T[1,0],T[1,1],T[1,2]], [T[2,0],T[2,1],T[2,2]]])
		
		scale = R.row(0).norm()
		R = R * (1/scale)
		
		region.rot = R * R0
		c = T.mulp(C0)
		region.center = c
		region.size = s0 * scale / 1.
		
		chunk.region = region
	
	print("Script finished. Bounding box copied.\n")
	
PhotoScan.app.addMenuItem("Custom menu/Copy bounding box", main)