1
Python and Java API / Re: Resizing the region
« on: June 20, 2014, 06:52:02 PM »Hello johndt6,
.activeChunk returns chunk variable or, in case of assignment, makes active the corresponding chunk, but could not be used for changing chunk contents.
So you should better use the following assignment:Code: [Select]chunk_orig = PhotoScan.app.document.activeChunk
Or to use chunk = PhotoScan.app.document.activeChunk from the beginning without using its duplicated copy.
chunk_orig.region = reg
Okay, thank you. I had just figured that out. I am now able to change the region, however, I am having trouble re-sizing it correctly. I wish to transform the region as follows:
1. Set the region to no rotation (so that it is square with the x, y, and z axes)
2. Set the size of the region to 2 meters wide on the X axis, 2 meters wide on the Z axis,
3 And, have the region extend 2.25 meters above the origin on the Y axis, and 5 centimeters below the origin on the Y axis.
My code to do so is as follows:
Code: [Select]
'''
Region resize test
'''
doc = PhotoScan.app.document
chunk = doc.activeChunk.copy()
reg = chunk.region
trans = chunk.transform
#<---- Rotation ---->
# Rotation matrix is equal to the identity matrix, because I want 0 Rotation, and Cos(0) = 1, Sin(0) = 0
rot_untransformed = PhotoScan.Matrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])
rot_temp = trans * rot_untransformed # This really isn't even necessary, as it is equal to 'trans'
# This is the scale factor. What does it do and why is it calculated in this way?
s = math.sqrt(rot_temp[0,0]**2 + rot_temp[0,1]**2 + rot_temp[0,2]**2)
R = PhotoScan.Matrix( [[rot_temp[0,0],rot_temp[0,1],rot_temp[0,2]], [rot_temp[1,0],rot_temp[1,1],rot_temp[1,2]], [rot_temp[2,0],rot_temp[2,1],rot_temp[2,2]]])
R = R * (1.0 / s)
#<---- Size ---->
geo_size = PhotoScan.Vector([2, 2.25 + .05, 2])
inter_size = trans.inv().mulp(geo_size) # mulp function is found no where in the docs, from what I can find!
#<---- Center ---->
geo_cen = PhotoScan.Vector([0, ((2.25 + .05) / 2) - .05, 0])
inter_cen = trans.inv().mulp(geo_cen)
reg.rot = R.t()
reg.size = inter_size
reg.center = inter_cen
chunk.region = reg
PhotoScan.app.document.chunks.add(chunk)
PhotoScan.app.document.chunks.remove(PhotoScan.app.document.activeChunk)
This does not yield expected results. The X and Z axes form a rectangle not equal to 2 by 2 meters. The rotation is correct. The size of the Y axis is also not expected, nor is the center. The worst part is that the size of this box is different for each project. So I have a few questions:
What exactly is the transform matrix besides a magical 4x4 matrix. Am I transforming everything correctly?
I have no crs, so what is the native geographic location? I would assume it would be meters. Or perhaps it is arbitrary for each project?
What is the scale factor, and why is it determined that way? Does my code keep the same scale, or is it changing it unexpectedly.
My company has been scripting Agisoft for some time now, but have had to manually change the bounding box for each project because no one has been able to figure this out. I've been messing around with it for a few days with no success.
Thanks so much for your help Alexey!